|
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.algart.drawing3d.Drawer3D net.algart.drawing3d.SimpleDrawer3D
public class SimpleDrawer3D extends Drawer3D
Simple full implementation of Drawer3D
class, based on the traditional Z-buffer algorithm.
This implementation supports antialiasing scale α — some integer number in
1..MAX_ANTIALIASING_SCALE
range.
The size of the screen, where all 3D figures are drawn,
can be greater than the sizes of returned BufferedImage: namely,
screenWidth
= α * imageWidth,
screenHeight
= α * imageHeight,
where imageWidth=getImageWidth()
and imageHeight=getImageHeight()
are the sizes of the really built BufferedImage. The getImage()
method builds the
returned image by compression of the internal picture, stored in this object and drawn by
draw
method, in α times.
It is the simplest way provide antialiasing effect — better quality of the resulting picture,
if there is enough RAM and the speed of building result is suitable.
This class is not thread-safe, but is thread-compatible and can be synchronized manually if multithread access is necessary.
AlgART Laboratory 2010
Modifier and Type | Field and Description |
---|---|
static int |
MAX_ANTIALIASING_SCALE
The maximal allowed value of antialiasingScale argument of getSimpleDrawer3D method: 2048. |
Fields inherited from class net.algart.drawing3d.Drawer3D |
---|
screenHeight, screenWidth, zCut |
Modifier and Type | Method and Description |
---|---|
void |
clearRect(int left,
int top,
int width,
int height)
Clears (reinitialize) the rectangular area left≤x<left+width, top≤y<top+height. |
void |
drawPoint(int x,
int y,
double z,
double nx,
double ny,
double nz,
java.awt.Color color)
Draws 1 pixel (point) of the surface of some 3D figure. |
int |
getAntialiasingScale()
Returns the antialiasing scale α, specified while creating this object. |
java.awt.image.BufferedImage |
getImage()
Transforms the current picture, built on the virtual screen by this object, into a buffered image, and returns it. |
int |
getImageHeight()
Returns the height of the image, built by Drawer3D.getImage() method. |
int |
getImageWidth()
Returns the width of the image, built by Drawer3D.getImage() method. |
static SimpleDrawer3D |
getSimpleDrawer3D(int imageWidth,
int imageHeight,
int antialiasingScale,
java.awt.Color backgroundColor,
java.util.List<ShapingRule> shapingRules,
java.util.List<ColoringRule> coloringRules,
java.util.List<DrawingRule> drawingRules)
Creates new instance of this class. |
Methods inherited from class net.algart.drawing3d.Drawer3D |
---|
draw, draw, estimateContainingParallelepiped, gammaCorrection, getBackgroundColor, getColor, getColoringRules, getCoordinateSystem, getDrawingRule, getDrawingRules, getGamma, getScreenHeight, getScreenWidth, getShape, getShapingRules, getZCut, setBackgroundColor, setColoringRules, setColoringRules, setCoordinateSystem, setDrawingRules, setDrawingRules, setGamma, setShapingRules, setShapingRules, setZCut |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int MAX_ANTIALIASING_SCALE
getSimpleDrawer3D
method: 2048.
Method Detail |
---|
public static SimpleDrawer3D getSimpleDrawer3D(int imageWidth, int imageHeight, int antialiasingScale, java.awt.Color backgroundColor, java.util.List<ShapingRule> shapingRules, java.util.List<ColoringRule> coloringRules, java.util.List<DrawingRule> drawingRules)
The passed collections are copied into newly created lists: no references to them are maintained by the created object.
imageWidth
- the width of the image screen, returned by getImage()
method:
result of getImageWidth()
. Cannot be changed in future.imageHeight
- the height of the image screen, returned by getImage()
method:
result of getImageHeight()
. Cannot be changed in future.antialiasingScale
- the antialiasing scale α: the (virtual) screen, where this object will build
3D image, will have sizes
backgroundColor
- the background color
,
which will be used by clearRect(int, int, int, int)
method.
After creation, all screen is filled by this color.shapingRules
- the set of shaping rules, which will be used
by draw
method.coloringRules
- the set of coloring rules, which will be used
by draw
method.drawingRules
- the set of drawing rules, which will be used
by draw
method.java.lang.NullPointerException
- if some of the arguments is null, or
if one of rules in the passed collections is null.java.lang.IllegalArgumentException
- if imageWidth<0 or imageHeight<0,
or if antialiasingScale=α is out of
1..MAX_ANTIALIASING_SCALE
range,
or if one of products public int getAntialiasingScale()
public int getImageWidth()
Drawer3D
Drawer3D.getImage()
method.
getImageWidth
in class Drawer3D
Drawer3D.getImage()
method.public int getImageHeight()
Drawer3D
Drawer3D.getImage()
method.
getImageHeight
in class Drawer3D
Drawer3D.getImage()
method.public void clearRect(int left, int top, int width, int height)
Pixel3DDrawer
drawPoint
was never called for integer pairs (x,y) in this area,
and this area is filled by some default background color.
The implementation, provided by
SimpleDrawer3D.getSimpleDrawer3D
method, initializes Z-buffer
for this area by default −∞ values.
If the specified area is out of ranges of the screen (i.e. some coordinates are <0 or ≥width/height of the image, which should be built as a result), the extra pixels are ignored. In particular, you can specify left=top=0, width=height=MAX_VALUE to reinitialize all drawable area. If width≤0 or height≤0, this method does nothing.
clearRect
in interface Pixel3DDrawer
clearRect
in class Drawer3D
left
- the minimal x-coordinate of the cleared area.top
- the minimal y-coordinate of the cleared area.width
- the width of the cleared area.height
- the height of the cleared area.public void drawPoint(int x, int y, double z, double nx, double ny, double nz, java.awt.Color color)
Pixel3DDrawer
DrawingRule.draw
method is implemented.
The coordinates of the pixel are specified in the coordinate system of the computer screen: the x-axis is directed to the right (in the screen plane), the y-axis is directed downwards (in the screen plane) and the z-axis is directed from the screen to the user. The top left corner of the screen image, which should be built as a result, has coordinates x=0, y=0, z=+∞.
x and y coordinates, passed to this method, specify the pixel of the resulting image,
which should be built (from 0 to the image width−1 or height−1). The resulting color
of the pixel
z-coordinate, passed to this method, is compared with z-coordinates of
other points, which were probably drawn by this method at the same (x,y) coordinates.
The simplest implementation can just overwrite the color of this pixel, if the passed z
is greater than z-coordinates of all previous calls with same
(x,y), or preserve the previous color if not — it is the known "Z-buffer" algorithm.
But other implementations are also possible: for example, the new color can be combined
with the previous color at (x,y) position, to provide an effect of translucency.
The implementation, provided by
SimpleDrawer3D.getSimpleDrawer3D
method, uses the described
simple Z-buffer algorithm.
The color argument specifies the color of the drawn point of the 3D surface.
But this color is used directly only in a case, when the surface is perpendicular to the rays of the light.
In other case, the color should be made darker. To provide this behavior, this method has additional arguments
nx, ny, nz, equal to the components of the unit normal vector
SimpleDrawer3D.getSimpleDrawer3D
method, multiplies all
R, G, B components of the color by Math.abs(nz) —
it corresponds to the light rays, falling along z axis from the side of the user (observer).
Note: the normal vector is supposed to be unit, i.e.
The alpha component of the passed color affects the transparency. It is guaranteed,
that if SimpleDrawer3D.getSimpleDrawer3D
method, uses
1–254 values for mixing the passed color with previously drawn color, which partially emulates
translucency. But note that this feature does not really provide correct translucency, because
that implementation is based on a simple Z-buffer algorithm and does nothing if z argument
is less than z-coordinates of the previously drawn pixel.
If x or y arguments are out of ranges of the screen (i.e. <0 or
≥width/height of the image), this method does nothing.
Besides this, the object can support some zcut limit
and ignore calls with z>zcut: it
allows creating "cut sets" of a complex 3D configuration
(this limit is really supported by Drawer3D
class).
drawPoint
in interface Pixel3DDrawer
drawPoint
in class Drawer3D
x
- x-coordinate of the point.y
- y-coordinate of the point.z
- z-coordinate of the point.nx
- x-component of the unit normal vector of the drawn surface at this point.ny
- y-component of the unit normal vector of the drawn surface at this point.nz
- z-component of the unit normal vector of the drawn surface at this point.color
- the color of drawn surface point.public java.awt.image.BufferedImage getImage()
Drawer3D
clearRect
and drawPoint
methods of this object,
but some little transformation, like scaling, is possible:
for example, SimpleDrawer3D
implementation automatically compresses the image
in getAntialiasingScale()
times.
Further drawing in this object will not affect the returned image, but the further calls of
this method can change it. (For example, SimpleDrawer3D
implementation uses for building
a buffered image the separate memory, allocated only once, and does not reallocate it in this method.)
getImage
in class Drawer3D
Drawer3D.getImageWidth()
,
Drawer3D.getImageHeight()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |