model.Viewer
drafting: model.Viewer
A window showing a solid or a triangle mesh, in which edges, faces and coordinate systems can be picked.
Assigning a solid.Shape to the Shape of a viewer opens its
window, or redraws it in place, keeping the camera where it was; each
solid is drawn in its colour, grey where it has none. Nothing
else redraws it. A polymesh.Mesh is shown the same way, shaded
facet by facet, however many triangles it has, in its faces’ colours
where it has them, else in its vertices’, blended across each facet,
else in grey. The show method of a shape or a mesh keeps a
viewer for each variable and is the usual way in; a viewer of your own
is for when you want to hold it yourself.
The window is drawn by Open CASCADE in a process of its own, so a complex model turns smoothly and never holds up the Octave prompt. The world axes are drawn in the lower right corner, turning with the view, x red, y green and z blue. The left mouse button rotates, the middle one pans and the wheel zooms. The view turns about the centre of the window, wherever it has been panned to, or about a point of the shape chosen by double-clicking it; a double click that misses the shape, or fitting the view, returns to the centre of the window. During a pick a double click is a click like any other. Keys:
F | fit the shape to the window, and turn about the centre of the window again |
0 | isometric view |
1 | front view, looking along +y |
2 | top view, looking down z |
3 | right view, looking along -x |
C | on a mesh, the next of the colourings it has: its faces’ colours, its vertices’, grey |
E | on a mesh, its triangle edges drawn or not, not at first |
What C and E choose holds for every mesh the viewer shows
after, where the mesh has that colouring.
Closing the window ends the viewer; assigning a shape again opens a new one. The window closes with Octave.
The viewer needs a display to run. It runs on Linux.
See also: solid.Shape.show, polymesh.Mesh.show, model.Viewer.pick
Source Code: model.Viewer
The model.Viewer class contains the following properties:
The solid.Shape or the polymesh.Mesh shown. Assigning
either opens the window if it is not open and redraws it in place if it
is. The empty shape opens the window empty, or clears
it if it is open; the first shape shown after it is fitted to the
window.
The name of the variable holding the shape shown. Setting it titles
the window with the name, so that several viewers can be told apart,
and the queries model.Viewer.pick prints use it. Until it is set
the window is titled drafting and the queries use 'S'.
The model.Viewer class offers the following public methods:
model.Viewer: V = model.Viewer ()
model.Viewer: V = model.Viewer ('Hidden', TF)
V = model.Viewer () returns a viewer that shows nothing
yet; its window opens when a shape, even the empty one, is assigned to
its Shape:
V = model.Viewer (); V.Shape = solid.box (80, 40, 12); V.Shape = hole (V.Shape, [20, 20, 12], 8, Inf); |
V = model.Viewer ( never shows its
window. It draws and picks all the same, which is how the viewer is
tested.
'Hidden', true)
model.Viewer: [E, F] = pick (V)
model.Viewer: [E, F, ECODE, FCODE] = pick (V)
model.Viewer: [E, CODE] = pick (V, 'edge')
model.Viewer: [F, CODE] = pick (V, 'face')
model.Viewer: [P, F] = pick (V)
[E, F] = pick (V) waits while you click edges
and faces in the viewer’s window, then returns the indices of the edges
in E and of the faces in F, in the numbering
solid.Shape.edges and solid.Shape.faces use. A click
selects what is under the pointer, which stays drawn in orange, a
selected edge thick and a selected face filled, and a second click on
it lets it go; the shape can still be turned between clicks.
Enter finishes and Escape cancels, returning nothing. With
'edge' or 'face' only that kind can be picked, and its
indices are the first output.
Indices belong to the shape they were picked on, and a script that holds
them breaks as soon as an earlier step adds a feature. So pick
also returns, as a character vector, the code that selects the same
items by kind, direction and position: CODE for one kind, and
ECODE and FCODE for edges and faces picked together, empty
where none was picked. The code selects exactly the items picked: one
query where what they share finds them alone, else one query for each,
joined, and their indices only where an item cannot be told apart from
the others by any query. It names the shape by the variable the viewer
shows, and eval (CODE) gives the indices again. Put it in
the script in place of the numbers:
## Four upright edges picked on a block 80 by 40 by 12
[E, CODE] = pick (V, 'edge');
## CODE holds the query for the script
E = edges (part, 'Type', 'line', 'Direction', [0, 0, 1], ...
'Within', [0, 0, 0, 80, 40, 12]);
part = fillet (part, E, 3);
|
When the viewer shows a polymesh.Mesh, [P, F]
= pick (V) waits while you click points on it, each marked
where it lands, and returns them in P, an N-by-3 matrix of
the points where the clicks hit the mesh, and in F an
N-by-4 matrix: for each point the index of the triangle it lies
on, a row of the mesh’s Faces, and the triangle’s unit normal,
turned as its corners run. A click that misses the mesh adds nothing.
Enter finishes and Escape cancels, returning nothing. A
mesh has no edges or faces in the sense of a solid, so 'edge'
and 'face' are refused.
See also: solid.Shape.edges, solid.Shape.faces, solid.Shape.show
model.Viewer: U = pickucs (V)
model.Viewer: U = pickucs (V, MODE)
model.Viewer: [U, CODE] = pickucs (…)
U = pickucs (V) returns the geom.UCS you
pick on the shape in the viewer’s window, in two steps, each prompted at
the foot of the window. geom.UCS (V) does the same.
The axes come first. Click a flat face, which gives the plane and its
outward normal, then two points: the direction from the first to the
second, laid in the face, is +x. The points can be anywhere on
the part, two corners along an edge for instance. With MODE
'points' no face is picked; three points give the axes instead,
+x from the first to the second and the third on the +y
side, as for geom.UCS.threepoint. MODE is
'face' by default.
The origin comes second. Click one point and the origin is there, laid
in the plane. Click a second and the origin takes its x from the
first point and its y from the second, which puts a datum corner
where a fillet or chamfer leaves no vertex to click. Press Enter
at once to keep the origin at the first point of the axes.
Every point snaps to what it lands on: a corner to its vertex, a
circular edge to its centre, another edge to its midpoint, a face to
the point clicked. Each is marked in the window. On a triangle mesh
the face clicked is a triangle, which gives the plane where the mesh is
flat, and a point snaps to a corner of the triangle under it or the
middle of one of its sides when the click is near, or else lies where
it was clicked. The shape can be
turned between clicks, and Escape cancels with an error.
A pick depends on the shape it was made on, so
[U, CODE] = pickucs (…) also returns
CODE, the expression that makes the same UCS from coordinates, as
a character vector to put in the script in place of the pick.
eval (CODE) gives the UCS again, to the ten significant
digits CODE carries.
[U, CODE] = pickucs (V); CODE ⇒ CODE = geom.UCS ([0, 0, 1], [20, 20, 12], [21, 20, 12]) R.UCS = geom.UCS ([0, 0, 1], [20, 20, 12], [21, 20, 12]); |
See also: geom.UCS, model.Viewer.pick
model.Viewer: view (V, AZ, EL)
model.Viewer: [AZ, EL] = view (V)
view (V, AZ, EL) turns the view to look at the
shape from azimuth AZ and elevation EL, in degrees, and fits
the shape to the window. The angles are those Octave’s view
takes for a plot: AZ turns anticlockwise about z, seen from
above, starting from the negative y axis, and EL rises from
the x-y plane, from -90 looking straight up to 90 looking
straight down. The z axis points up the window; looking
straight down or up, the y axis does, turned by AZ. The
mouse still turns the view afterwards.
[AZ, EL] = view (V) returns the angles the
view looks from now, however it got there, AZ from -180 to 180,
so that a view found with the mouse can be kept in a script. A turn
about the line of sight, which the mouse can give, is not part of them.
The keys of the window give four of these views: 0 is
view (V, 45, 35.26), near enough, the isometric view the
window opens with, 1 is view (V, 0, 0), 2 is
view (V, 0, 90) and 3 is
view (V, 90, 0).
## A shallow part looks deeper than it is from the isometric view; ## look from higher up part = solid.box (80, 40, 4); V = show (part); view (V, 30, 60); ## Keep a view found with the mouse [az, el] = view (V); |
See also: solid.Shape.show
model.Viewer: close (V)
Assigning a shape afterwards opens a new window.
model.Viewer: TF = isopen (V)