|
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.algart.drawing3d.Sphere3DDrawingRule
public class Sphere3DDrawingRule extends java.lang.Object implements DrawingRule
Algorithm of drawing 3D sphere (Sphere3D
object).
This algorithm visits all pixels Pixel3DDrawer.drawPoint
method for 2 points of intersection of the 3D sphere and the straight line
This class is immutable and thread-safe: there are no ways to modify settings of the created instance.
AlgART Laboratory 2010
Constructor and Description |
---|
Sphere3DDrawingRule()
|
Modifier and Type | Method and Description |
---|---|
void |
draw(Shape3D shape,
Pixel3DDrawer pixelDrawer,
CoordinateSystem3D coordinateSystemOfModel,
java.awt.geom.Rectangle2D screenArea,
double zCut,
java.awt.Color color)
Draws the specified 3D figure (shape), i.e. calls pixelDrawer. drawPoint
method for every screen pixel and all corresponding points of the surface ot this figure. |
void |
estimateContainingParallelepiped(double[] result,
Shape3D shape,
CoordinateSystem3D coordinateSystemOfModel)
Returns, in first 6 elements of result argument, the minimal and maximal x-coordinate, the minimal and maximal y-coordinate, the minimal and maximal z-coordinate of all drawable points of the specified 3D figure (shape), in the specified order. |
boolean |
isApplicable(Shape3D shape,
java.lang.Object item)
Checks whether this drawing rule is applicable to the given figure (shape), i.e. this drawing rule "knows" how to draw it. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Sphere3DDrawingRule()
Method Detail |
---|
public boolean isApplicable(Shape3D shape, java.lang.Object item)
DrawingRule
This method is used by Drawer3D.draw(java.util.Collection)
for choosing the algorithm
for drawing every object.
The item argument contains the reference to the source object (item), which was transformed
to Shape3D
by some shaping rule
for drawing by this algorithm.
It can be used to restrict the set of objects, to which this drawing algorithm should be applied:
this method can return false for some kind of items, so the draw
method
of this instance will not be called for them. The implementations of this interface,
provided by this package, ignore this argument.
Both arguments of this method can be null. If shape argument is null, this method returns false.
isApplicable
in interface DrawingRule
shape
- the 3D figure which you want to draw;
can be null, then this method returns false.item
- the source object which you want to draw as the given figure; can be null.public void draw(Shape3D shape, Pixel3DDrawer pixelDrawer, CoordinateSystem3D coordinateSystemOfModel, java.awt.geom.Rectangle2D screenArea, double zCut, java.awt.Color color)
DrawingRule
drawPoint
method for every screen pixel and all corresponding points of the surface ot this figure.
All coordinates, describing the real surface of the figure, are supposed to be given in the specified
coordinateSystemOfModel: see comments to the interface
.
While calling
drawPoint(int x, int y, double z, double nx, double ny, double nz, Color color)
method,
this method passes to it the coordinates drawPoint
at least 1 time (but maybe several times) for each such "piece" σk
with arguments
drawPoint
method can be not called
for the given (
The nx, ny, nz arguments of drawPoint
are equal to the components of the unit normal vector
drawPoint
is equal to the color argument of this method.
The described algorithm is the simplest way of drawing 3D surface.
A concrete way, how the surface will be drawn, for example, how the light falls to the surface,
depends on Pixel3DDrawer
implementation.
For example, the standard Z-buffer algorithm, offered by SimpleDrawer3D.getSimpleDrawer3D
method,
draws only the "top" part of the surface (nearest to the observer), i.e. from all points
with given integer X, Y only the one with maximal z-coordinate is really drawn,
and it is supposed that the light falls along z axis from the side of the user —
the color is multiplied by Math.abs(nz).
The drawn area is restricted by screenArea rectangle: only pixels, lying inside the area
This method must draw only the part of the 3D figure, lying (in terms of the screen coordinate system) "behind" the plane z=zcut (i.e. in area z≤zcut), specified by zCut argument. In other words, this argument allows to "dissect" drawn object by some plane and to see only parts "behind" this plane, and to hide (not to draw at all) the objects which are fully "in front of" this plane (z>zcut). Usually, this feature is used by GUI to allow seeing a cut set of a complex 3D configuration. You can specify zCut=Double.POSITIVE_INFINITY, if you don't want to use this feature.
The pixels of the "dissected" figure can be drawn with maximal brightness
(1.0 value of the brightness argument of drawPoint
method)
— it corresponds to showing a plane section of a solid 3D body.
But also the drawing rule can show the internal surface of the figure "behind" this place —
if corresponds to dissection of a hollow 3D body.
The first variant ("solid body") is used by Sphere3DDrawingRule
,
the second one (drawing surface only) is used by ConvexPlanePolygon3DDrawingRule
.
This method works normally, only if this object "knows", how to draw this kind of 3D figures.
You can be sure that it is true, if DrawingRule.isApplicable(Shape3D, Object)
method returns true
for this shape and some 2nd argument.
In this case, this method does not throw any exceptions, excepting NullPointerException
(when one of the arguments is null).
But if this object does not "know", how to draw this kind of 3D figures,
this method can throw ClassCastException or other unexpected runtime exceptions.
draw
in interface DrawingRule
shape
- the drawn 3D figure.pixelDrawer
- the object which will be used for drawing each pixel.coordinateSystemOfModel
- the coordinate system of the model, in which the passed 3D figure is represented.screenArea
- the screen area, inside which the figure should be drawn
(for optimization needs only).zCut
- z-coordinates of the section plane: only points with
z≤zCut should be drawn.color
- the color of the drawn figure.Drawer3D.draw(java.util.Collection)
public void estimateContainingParallelepiped(double[] result, Shape3D shape, CoordinateSystem3D coordinateSystemOfModel)
DrawingRule
comments to the interface
.
There is no guarantee that the returned coordinate limits will be precise: they can be just an estimation.
But, in any case, the returned parallelepiped fully contains the specified figure.
Usually, this method helps GUI modules to determine a suitable range of possible zCut
arguments for draw
method.
This method works normally, only if this object "knows", how to draw this kind of 3D figures.
You can be sure that it is true, if DrawingRule.isApplicable(Shape3D, Object)
method returns true
for this shape and some 2nd argument.
But if this object does not "know", how to draw this kind of 3D figures,
this method can throw ClassCastException or other unexpected runtime exceptions.
estimateContainingParallelepiped
in interface DrawingRule
result
- Java-array for storing results.shape
- the 3D figure (that should be probably drawn by draw
method).coordinateSystemOfModel
- the coordinate system in which the figure should be drawn.Drawer3D.estimateContainingParallelepiped(double[], java.util.Collection)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |