Class Projection
- Namespace
- CADability
- Assembly
- CADability.dll
A parallel or perspective projection which is used to convert the 3-dimensional world coordinate system to a 2-dimensional screen coordinate system or to a normalized 3-dimensional cube for the paint or rendering interface (IPaintTo3D). Contains also additional hints for the paint interface and the drawing plane.
public class Projection : ISerializable, IDeserializationCallback
- Inheritance
-
Projection
- Implements
- Inherited Members
Constructors
Projection(CoordSys)
Creates a new parallel projection to the provided coordinate system
public Projection(CoordSys ProjectTo)
Parameters
ProjectToCoordSysThe target system
Projection(GeoVector, GeoVector)
Creates a new parallel projection with the provided direction and the direction of the vector that should become the vertical direction.
public Projection(GeoVector Direction, GeoVector TopDirection)
Parameters
Projection(Projection)
Creates a clone of the provided projection
public Projection(Projection copyFrom)
Parameters
copyFromProjectionProjection being cloned
Projection(StandardProjection)
Creates a new standard projection according to Projection.StandardProjection
public Projection(Projection.StandardProjection Standard)
Parameters
StandardProjection.StandardProjectionWhich direction to use
Projection(SerializationInfo, StreamingContext)
Constructor required by deserialization
protected Projection(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInfoSerializationInfo
contextStreamingContextStreamingContext
Fields
LayoutFactor
Some Attributes refer to paper bound dimensions: e.g. the linewidth or textsize may be specified in mm on the paper. So we need the posibility to transform linear dimensions from layout to world. This is doune by the LayoutFactor;
public double LayoutFactor
Field Value
LineWidthFactor
A factor for the display line width
public double LineWidthFactor
Field Value
UseLineWidth
Flag indicating the use of line width
public bool UseLineWidth
Field Value
Properties
DeviceToWorldFactor
The length in units of the 2d world coordinate system that corresponds to one pixel; the reciprocal of WorldToDeviceFactor. Use it to give objects a fixed size on the screen regardless of the zoom.
public double DeviceToWorldFactor { get; }
Property Value
Direction
The view direction in model coordinates, pointing from the viewer into the model; for a parallel projection all points are projected along this direction. Setting the value has no effect; use SetDirection(GeoVector, GeoVector, BoundingCube) or SetPerspective(GeoPoint, GeoVector, Rectangle, BoundingCube) to change the direction.
public GeoVector Direction { get; set; }
Property Value
DrawingPlane
The drawing plane of the view: the plane in which objects are constructed when a mouse position is converted to a 3d point (see DrawingPlanePoint(Point)) and in which the Grid is displayed. Setting it does not raise ProjectionChangedEvent. When the view direction changes so that the drawing plane would be seen edge on, the plane is replaced by one perpendicular to the new direction.
public Plane DrawingPlane { get; set; }
Property Value
FromTop
Creates a new parallel projection looking down onto the xy-plane from above, with the y axis of the model pointing
upwards on the screen. Same as new Projection(StandardProjection.FromTop).
public static Projection FromTop { get; }
Property Value
Grid
The settings of the grid displayed in the drawing plane (spacing, appearance, visibility). The Grid object is shared with clones of this projection; modify its properties to change the grid.
public Grid Grid { get; }
Property Value
Height
The height in pixels of the client rectangle of the window this projection is displayed in (0 when it has not been set).
public int Height { get; }
Property Value
InverseProjection
The inverse of UnscaledProjection: maps points and vectors of the 2d world coordinate system (extended by a z component) back to model coordinates. E.g. the images of the x and y axis are the horizontal and vertical direction of the view in model coordinates. Not meaningful for a perspective projection.
public ModOp InverseProjection { get; }
Property Value
IsPerspective
Returns true if this projection is a perspective projection in contrast to a parallel projection
public bool IsPerspective { get; }
Property Value
PerspectiveProjection
The 4x4 matrix of the perspective projection without scaling and placement, which maps world coordinates to the normalized cube of the paint interface. Only valid when IsPerspective is true; it is computed by SetPerspective(GeoPoint, GeoVector, Rectangle, BoundingCube).
public Matrix4 PerspectiveProjection { get; }
Property Value
PlacementFactor
The scaling factor of the 2d placement, i.e. the number of pixels per unit of the 2d world coordinate system. Same as WorldToDeviceFactor.
public double PlacementFactor { get; }
Property Value
Precision
The precision in world units at which curved objects are approximated (triangulated) when they are displayed or picked with this projection, i.e. the maximum allowed distance between the approximation and the exact geometry. The views set it to a fraction of the model extent (typically 1/1000 of its size); 0.0 means that it has not been determined yet.
public double Precision { get; set; }
Property Value
ProjectionPlane
The plane whose 2d coordinate system is the "2d world coordinate system" of this projection. For a parallel projection it is the plane through the origin perpendicular to Direction, with its axes along the horizontal and vertical direction of the view. For a perspective projection it is the plane perpendicular to the view direction in the middle of the displayed frustum, its origin being the point where the line through the world origin in view direction hits it. Not to be confused with the DrawingPlane, in which objects are constructed.
public Plane ProjectionPlane { get; }
Property Value
ShowDrawingPlane
Display hint, whether to show the drawing plane
public bool ShowDrawingPlane { get; set; }
Property Value
ShowFaces
Display hint for the paint interface: true to display faces as filled (shaded) areas, false to display only their edges (wireframe display). The views expose it as a property of the view.
public bool ShowFaces { get; set; }
Property Value
UnscaledProjection
The parallel projection without scaling and placement as a ModOp: it maps world coordinates to a coordinate system whose x and y components are the 2d world coordinates of the projection plane and whose z component is the signed distance from that plane. Not meaningful for a perspective projection.
public ModOp UnscaledProjection { get; }
Property Value
Width
The width in pixels of the client rectangle of the window this projection is displayed in (0 when it has not been set).
public int Width { get; }
Property Value
WorldToDeviceFactor
The number of pixels that correspond to one unit of the 2d world coordinate system, i.e. the scaling of the 2d placement (same as PlacementFactor). The larger the value, the further the view is zoomed in.
public double WorldToDeviceFactor { get; }
Property Value
Methods
BoundingRectWorld2d(int, int, int, int)
Returns a BoundingRect in the 2d world coordinate system according to the provided view positions. The view coordinate system is the windows forms system. The 2d world coordinate system is for the parallel projection a plane perpendicular to the projection direction scaled the same way as the model. For the perspective projection it is the back plane of the displayed frustum of pyramid.
public BoundingRect BoundingRectWorld2d(int left, int right, int bottom, int top)
Parameters
leftintleft position in the view
rightintrechter Rand
bottomintunterer Rand
topintoberer Rand
Returns
Clone()
Returns a clone of this projection
public Projection Clone()
Returns
- Projection
The clone
DeviceRect(BoundingRect)
Converts a rectangle in the 2d world coordinate system of the projection plane to a rectangle in pixel coordinates (y growing downwards) by applying the 2d placement. The result is enlarged by two pixels on each side, which makes it suited for invalidating the area of an object. Only the placement is considered, so it is intended for parallel projections.
public Rectangle DeviceRect(BoundingRect r)
Parameters
rBoundingRectthe rectangle in the 2d world coordinate system
Returns
- Rectangle
the rectangle in pixel coordinates
DrawingPlanePoint(GeoPoint2D)
Returns the 3D world point for the given 2D world point according to the drawing plane (DrawingPlane)
public GeoPoint DrawingPlanePoint(GeoPoint2D w2d)
Parameters
w2dGeoPoint2Dthe 2D world point
Returns
- GeoPoint
3D world point
DrawingPlanePoint(Point)
Returns the point in the worldcoordinate system corresponding to the (mouse-) position p and the drawingplane
public GeoPoint DrawingPlanePoint(Point p)
Parameters
pPointPoint in window coordinates
Returns
- GeoPoint
Point in world coordinates
GetExtent(IGeoObject)
Returns the extent of the given object as seen in this projection, in the 2d world coordinate system of the projection plane. Same as GetExtent(Projection, ExtentPrecision) with Raw, so the result is a quick estimate that may be somewhat larger than the exact extent.
public BoundingRect GetExtent(IGeoObject go)
Parameters
goIGeoObjectthe object
Returns
- BoundingRect
the 2d extent of the object
GetObjectData(SerializationInfo, StreamingContext)
Writes the data of this object for the legacy binary serialization (ISerializable). Files are written in the JSON format (IJsonSerialize) now; the binary format is still read.
public void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInforeceives the data
contextStreamingContextthe destination of the serialization
GetOpenGLProjection(int, int, int, int, BoundingCube)
Returns the 4x4 projection matrix for the paint interface, which maps world coordinates to the normalized cube used by
OpenGL (x and y in the range [-1, 1], assuming a viewport that covers the whole window). The window size and the model
extent are stored in the projection; when they differ from the previous call, the projection is recomputed so that the
whole extend fits into the depth range, and ProjectionChangedEvent is raised.
public double[,] GetOpenGLProjection(int left, int right, int bottom, int top, BoundingCube extend)
Parameters
leftintleft edge of the viewport in pixels (usually 0)
rightintright edge of the viewport in pixels (usually the width of the window)
bottomintbottom edge of the viewport in pixels (usually 0)
topinttop edge of the viewport in pixels (usually the height of the window)
extendBoundingCubethe extent of the model in world coordinates
Returns
- double[,]
the projection matrix as a 4x4 array
GetPickSpace(BoundingRect)
Returns a PickArea, rectWorld2D is in 2-d world coordinates
public Projection.PickArea GetPickSpace(BoundingRect rectWorld2D)
Parameters
rectWorld2DBoundingRectThe defining rectangle
Returns
- Projection.PickArea
The area inside the rectangle
GetPickSpace(Rectangle)
Returns a PickArea, viewRect is in window coordinates
public Projection.PickArea GetPickSpace(Rectangle viewRect)
Parameters
viewRectRectangleThe defining rectangle
Returns
- Projection.PickArea
The area inside the rectangle
GetPickSpace(RectangleF)
Returns a PickArea, viewRect is in window coordinates
public Projection.PickArea GetPickSpace(RectangleF viewRect)
Parameters
viewRectRectangleFThe defining rectangle
Returns
- Projection.PickArea
The area inside the rectangle
GetPlacement(out double, out double, out double)
Returns the values of the 2d placement, which maps the unscaled 2d projection to pixel coordinates: x' = Factor * x + dx and y' = -Factor * y + dy. Note that the y values have to be multiplied with the negative factor, because the placement flips the y axis (pixel coordinates grow downwards).
public void GetPlacement(out double Factor, out double dx, out double dy)
Parameters
Factordoublethe scaling factor (to be used with a negative sign for y)
dxdoublethe offset in x (pixels)
dydoublethe offset in y (pixels)
MakeArrow(GeoPoint, GeoPoint, GeoPoint, GeoPoint, Plane, ArrowMode)
Make an dimension arrow between p1 and p2. Dimension help line connect to d1 and d2
public GeoObjectList MakeArrow(GeoPoint p1, GeoPoint p2, GeoPoint d1, GeoPoint d2, Plane plane, Projection.ArrowMode mode)
Parameters
Returns
MakeArrow(GeoPoint, GeoPoint, Plane, ArrowMode)
Makes the objects of a feedback arrow from p1 to p2, as used by interactive actions
to visualize a distance or an offset: a line, a circle at p1 and a triangular head at p2.
Circle and head are faces in the plane through the line that is oriented like plane; their size is
about 1% of the display size, so the arrow looks the same at any zoom level. Returns an empty list when
plane is invalid or the two points coincide.
public GeoObjectList MakeArrow(GeoPoint p1, GeoPoint p2, Plane plane, Projection.ArrowMode mode)
Parameters
p1GeoPointstart point of the arrow
p2GeoPointend point of the arrow (position of the head)
planePlanea plane that determines the orientation of the circle and the head, usually the ProjectionPlane or the DrawingPlane
modeProjection.ArrowModethe kind of arrow, see Projection.ArrowMode
Returns
- GeoObjectList
the objects of the arrow, ready to be displayed as feedback
MakeRotationArrow(Axis, GeoVector, GeoVector)
make an arrow showing a rotation operation. The rotation is around the axis
and goes from the vector fromHere to the vector toHere.
public GeoObjectList MakeRotationArrow(Axis axis, GeoVector fromHere, GeoVector toHere)
Parameters
Returns
MovePlacement(double, double)
Shifts the 2d placement by the given number of pixels, i.e. scrolls the view without changing the scaling. Raises ProjectionChangedEvent.
public void MovePlacement(double dx, double dy)
Parameters
dxdoublethe horizontal offset in pixels (positive moves the content to the right)
dydoublethe vertical offset in pixels (positive moves the content downwards)
PlanePoint(Plane, Point)
Gets the position of a given point (usually a mouse position in view coordinates) in a given plane.
public GeoPoint2D PlanePoint(Plane pln, Point p)
Parameters
Returns
- GeoPoint2D
Position of the point in the plane
PointBeam(Point)
Returns a beam corresponding to the 2-dimensional mouse position. The mouse position corresponds to a beam in the model which is seen as a point from the viewpoint. The result is in world coordinates of the model. Works for both parallel and perspective projection.
public Axis PointBeam(Point p)
Parameters
pPointPoint to which the corresponding beam is required
Returns
- Axis
The corresponding beam
PointWorld2D(Point)
Converts a position in pixel coordinates of the window (origin at the top left, y growing downwards) to the corresponding point in the 2d world coordinate system of the ProjectionPlane. Works for both parallel and perspective projection; inverse of World2DToWindow(GeoPoint2D).
public GeoPoint2D PointWorld2D(Point p)
Parameters
pPointthe position in pixel coordinates
Returns
- GeoPoint2D
the point in the 2d world coordinate system
PointWorld2D(PointF)
Same as PointWorld2D(Point) for a floating point pixel position; the position is truncated to whole pixels.
public GeoPoint2D PointWorld2D(PointF pf)
Parameters
pfPointFthe position in pixel coordinates
Returns
- GeoPoint2D
the point in the 2d world coordinate system
PrependModOp(ModOp)
Returns a new projection in which the modification ToPrepend is applied to the model before it is
projected, so that objects appear as if they were transformed by it. Only the 2d aspects (scaling and translation) of the
modification are handled correctly; it is used to display a block reference that is being dragged during drag and drop.
This projection is not modified.
public Projection PrependModOp(ModOp ToPrepend)
Parameters
ToPrependModOpThe modification to apply before the projection
Returns
- Projection
The combined projection
Project(GeoPoint)
Projects the given point into pixel coordinates of the view (origin at the top left, y growing downwards), including the scaling and the placement. Works for both parallel and perspective projection. Same as ProjectF(GeoPoint), but returns a GeoPoint2D.
public GeoPoint2D Project(GeoPoint p)
Parameters
pGeoPointthe point to project (model coordinates)
Returns
- GeoPoint2D
the projected point in pixel coordinates
Project2D(GeoPoint)
Projects the given point into pixel coordinates (y growing downwards) using the linear coefficients of the parallel projection combined with the placement. Faster than Project(GeoPoint), but valid for parallel projections only.
public GeoPoint2D Project2D(GeoPoint p)
Parameters
pGeoPointthe point to project (model coordinates)
Returns
- GeoPoint2D
the projected point in pixel coordinates
ProjectF(GeoPoint)
Projects the given point into 2d including the scaling and the placement, i.e. the result is in the pixel (paper) coordinate system of the view, with y growing downwards, and not in the 2d world coordinate system. Same as Project(GeoPoint), but returns a PointF.
public PointF ProjectF(GeoPoint p)
Parameters
pGeoPointthe point to project (model coordinates)
Returns
- PointF
the projected point in pixel coordinates
ProjectUnscaled(GeoPoint)
Projects the given point into 2d without applying the scaling and the placement, i.e. the result is in the 2d world coordinate system of the projection plane and not in the pixel (paper) coordinate system.
public GeoPoint2D ProjectUnscaled(GeoPoint p)
Parameters
pGeoPointthe point to project (model coordinates)
Returns
- GeoPoint2D
the projected point in the 2d world coordinate system
ProjectUnscaled(GeoVector)
Projects the given vector into 2d without applying the scaling and the placement, i.e. the result is in the 2d world coordinate system of the projection plane. Uses the parallel projection only.
public GeoVector2D ProjectUnscaled(GeoVector v)
Parameters
vGeoVectorthe vector to project (model coordinates)
Returns
- GeoVector2D
the projected vector in the 2d world coordinate system
SetClientRect(Rectangle)
Sets the client rectangle (in pixels) of the window this projection is displayed in, without recomputing the projection. Usually the client rectangle is provided by the paint interface via GetOpenGLProjection(int, int, int, int, BoundingCube).
public void SetClientRect(Rectangle clr)
Parameters
clrRectangleThe client rectangle of the window
SetDirection(GeoVector, GeoVector, BoundingCube)
Sets the view direction and the vertical direction of this projection.
public void SetDirection(GeoVector Direction, GeoVector TopDirection, BoundingCube extent)
Parameters
DirectionGeoVectorView direction
TopDirectionGeoVectorVertical direction
extentBoundingCubeExtend of the model in world coordinates
SetDirectionAnimated(GeoVector, GeoVector, Model, bool, ICanvas, GeoPoint)
Changes the view direction like SetDirection(GeoVector, GeoVector, BoundingCube), but animated: the projection
is interpolated from the current to the new direction over about half a second, repainting ctrl for each
step (the animation is driven by the OnPaintDone event and this method returns immediately).
At the end the view either shows the whole model (zoomTotal) or keeps
fixPoint at its current position on the screen. Used by the standard view commands of the frame.
public void SetDirectionAnimated(GeoVector viewDirection, GeoVector TopDirection, Model model, bool zoomTotal, ICanvas ctrl, GeoPoint fixPoint)
Parameters
viewDirectionGeoVectorThe new view direction
TopDirectionGeoVectorThe direction in the model that points upwards on the screen when the animation is finished
modelModelThe model shown in the view, needed to compute the extent for zoom total
zoomTotalbooltrue: zoom to the extent of the model at the end; false: keep
fixPointin placectrlICanvasThe canvas that displays the view and is repainted during the animation
fixPointGeoPointThe point in world coordinates that keeps its position on the screen; if invalid,
zoomTotalis assumed
SetPerspective(GeoPoint, GeoVector, Rectangle, BoundingCube)
Makes this a perspective (central) projection: the viewer is located at fromHere and looks in direction
dir. The near and far clipping planes are derived from modelExtent, the aspect ratio
from clientRect. The view direction is placed in the center of the window; the previous scaling (zoom)
is kept. Raises ProjectionChangedEvent.
public void SetPerspective(GeoPoint fromHere, GeoVector dir, Rectangle clientRect, BoundingCube modelExtent)
Parameters
fromHereGeoPointThe position of the viewer (center of the projection) in world coordinates
dirGeoVectorThe view direction
clientRectRectangleThe client rectangle of the window in pixels
modelExtentBoundingCubeThe extent of the model, used to determine the depth range of the view
SetPerspective(GeoPoint, GeoVector, Rectangle, BoundingCube, GeoPoint)
Makes this a perspective (central) projection like SetPerspective(GeoPoint, GeoVector, Rectangle, BoundingCube),
but shifts the placement so that fixPoint keeps the position on the screen it had before the call.
public void SetPerspective(GeoPoint fromHere, GeoVector dir, Rectangle clientRect, BoundingCube modelExtent, GeoPoint fixPoint)
Parameters
fromHereGeoPointThe position of the viewer (center of the projection) in world coordinates
dirGeoVectorThe view direction
clientRectRectangleThe client rectangle of the window in pixels
modelExtentBoundingCubeThe extent of the model, used to determine the depth range of the view
fixPointGeoPointThe point in world coordinates that keeps its position on the screen
SetPlacement(double, double, double)
Sets the 2d placement directly. The placement maps the unscaled 2d projection to pixel coordinates as x' = factor * x + dx and y' = -factor * y + dy (see GetPlacement(out double, out double, out double)). Raises ProjectionChangedEvent.
public void SetPlacement(double factor, double dx, double dy)
Parameters
factordoublethe scaling factor (pixels per unit of the 2d world coordinate system)
dxdoublethe offset in x (pixels)
dydoublethe offset in y (pixels)
SetPlacement(Rectangle, BoundingRect)
Sets the 2d placement (scaling and offset) of the projection so that the source rectangle fits into the destination rectangle and is centered in it. This is how a view zooms to a given extent.
public void SetPlacement(Rectangle Destination, BoundingRect Source)
Parameters
DestinationRectanglethe destination rectangle in pixels, usually the client rectangle of the control
SourceBoundingRectthe source rectangle in the 2d world coordinates of the projection plane
SetPlacement(RectangleF, BoundingRect)
Sets the 2d placement (scaling and offset) of the projection so that the Source rectangle fits into the
Destination rectangle and is centered in it; the aspect ratio is preserved. For a perspective projection
the source rectangle is taken in the 2d system of the ProjectionPlane and the current placement is adjusted
accordingly. Same as SetPlacement(Rectangle, BoundingRect) with a floating point destination.
Raises ProjectionChangedEvent.
public void SetPlacement(RectangleF Destination, BoundingRect Source)
Parameters
DestinationRectangleFthe destination rectangle in pixels, usually the client rectangle of the control
SourceBoundingRectthe source rectangle in the 2d world coordinates of the projection plane
SetUnscaledProjection(ModOp)
Replaces the unscaled parallel projection (the ModOp that maps world coordinates to the 2d coordinate system of the projection plane, see UnscaledProjection) and makes this a parallel projection. The placement (scaling and offset) is kept. Raises ProjectionChangedEvent.
public void SetUnscaledProjection(ModOp unscaledProjection)
Parameters
unscaledProjectionModOpThe new projection, usually derived from the current UnscaledProjection
UnProject(Point)
Converts a pixel position back to a 3d point on the plane through the origin that is perpendicular to the direction of the projection (the placement is reverted and the inverse projection is applied with z = 0). Not very useful on its own, because the information how far in front of or behind that plane the point should be is missing; see PointBeam(Point) and DrawingPlanePoint(Point) for the usual alternatives.
public GeoPoint UnProject(Point p)
Parameters
pPointthe position in pixel coordinates
Returns
- GeoPoint
the 3d point on the plane through the origin
UnProjectUnscaled(GeoPoint2D)
Returns the 3d point in the ProjectionPlane that corresponds to the given point of the 2d world coordinate system. This is the inverse of ProjectUnscaled(GeoPoint) for points in the projection plane.
public GeoPoint UnProjectUnscaled(GeoPoint2D p)
Parameters
pGeoPoint2Dthe point in the 2d world coordinate system
Returns
- GeoPoint
the point in model coordinates, located in the projection plane
UnProjectUnscaled(GeoVector2D)
Returns the 3d vector parallel to the ProjectionPlane that corresponds to the given vector of the 2d world coordinate system. This is the inverse of ProjectUnscaled(GeoVector) for vectors in the projection plane.
public GeoVector UnProjectUnscaled(GeoVector2D v)
Parameters
vGeoVector2Dthe vector in the 2d world coordinate system
Returns
- GeoVector
the vector in model coordinates, parallel to the projection plane
WindowToWorld(PointF)
Returns the provided point in the world coordinate system
public GeoPoint WindowToWorld(PointF windowPoint)
Parameters
windowPointPointFA point in the windows coordinate system
Returns
- GeoPoint
Result in world coordinate system
World2DToWindow(BoundingRect)
Converts a rectangle of the 2d world coordinate system of the ProjectionPlane to a rectangle in pixel coordinates of the window. Works for both parallel and perspective projection.
public RectangleF World2DToWindow(BoundingRect br)
Parameters
brBoundingRectthe rectangle in the 2d world coordinate system
Returns
- RectangleF
the rectangle in pixel coordinates
World2DToWindow(GeoPoint2D)
Converts a point of the 2d world coordinate system of the ProjectionPlane to pixel coordinates of the window (origin at the top left, y growing downwards). Works for both parallel and perspective projection; inverse of PointWorld2D(Point).
public GeoPoint2D World2DToWindow(GeoPoint2D p)
Parameters
pGeoPoint2Dthe point in the 2d world coordinate system
Returns
- GeoPoint2D
the position in pixel coordinates
WorldToWindow(GeoPoint)
Returns the window position of a point in the world coordiate system. Point (0,0) is the top left point of the window
public GeoPoint2D WorldToWindow(GeoPoint p)
Parameters
pGeoPointPoint in world coordinate system
Returns
Events
ProjectionChangedEvent
Event beeing issued when the projection changes
public event Projection.ProjectionChangedDelegate ProjectionChangedEvent