public class VoxelArray extends java.lang.Object implements Field3DFloat
The convention for most graphics is that you should round real-valued points to their closest integer value.
Bits are stored in the BiggerBitSet
in Z-major order, then Y,
then X. This means that it's usually most efficient to iterate over the
z-axis in the outer loop for cache efficiency.
This is the main class for Frink's 3-D modeling routines. Most of its high-level modeling routines are here.
Modifier and Type | Field and Description |
---|---|
private long |
area
The area of the XY plane.
|
private int |
offX
The offset of the x axis.
|
private int |
offY
The offset of the y axis.
|
private int |
offZ
The offset of the z axis.
|
private int |
sizeX
The size of the x axis.
|
private int |
sizeY
The size of the y axis.
|
private int |
sizeZ
The size of the z axis.
|
private static double |
TWOPI
2 * pi
|
private BiggerBitSet |
voxels
The
BiggerBitSet that contains all of the bits. |
Constructor and Description |
---|
VoxelArray(int sizeX,
int sizeY,
int sizeZ)
Construct a VoxelArray with the specified size on each axis and each
element set to false.
|
VoxelArray(int sizeX,
int sizeY,
int sizeZ,
boolean value)
Construct a VoxelArray with the specified size on each axis and each
element set to the specified value.
|
VoxelArray(int minX,
int sizeX,
int minY,
int sizeY,
int minZ,
int sizeZ,
boolean value)
Construct a VoxelArray with the specified minimum value and size on
each axis and each element set to the specific value.
|
VoxelArray(VoxelArray other)
Copy constructor.
|
VoxelArray(VoxelArray other,
boolean value)
Copy the dimensions but set every voxel to the specified value.
|
Modifier and Type | Method and Description |
---|---|
void |
add(VoxelArray b)
Adds the pixels in this VoxelArray that are true in VoxelArray b,
modifying this VoxelArray in place.
|
void |
addAlongLine(VoxelArray b,
int x1,
int y1,
int z1,
int x2,
int y2,
int z2,
int xc,
int yc,
int zc)
Adds the pixels in this VoxelArray by moving the
VoxelArray b along a line and adding the points in VoxelArray b
that are true, modifying this VoxelArray in place.
|
Point3DDouble |
centerOfMass()
Calculate the center of mass of all set voxels (assuming each voxel has
the same density).
|
private void |
checkPoint(long x,
long y,
long z)
This method checks a point to see if it is within a valid range for
this VoxelArray and throws an
IndexOutOfBoundsException if it
doesn't. |
static VoxelArray |
construct(BoundingBox3DFloat bb,
boolean value)
Construct a new rectangular VoxelArray that encloses the specific
bounding box.
|
static VoxelArray |
construct(double x1,
double x2,
double y1,
double y2,
double z1,
double z2,
boolean value)
Construct a new rectangular VoxelArray that encloses the specific
min and max coordinates.
|
static VoxelArray |
construct(Point3DIntList points)
Construct a new rectangular VoxelArray that represents the points in
the Point3DIntList.
|
long |
countSetBits()
Counts the number of set bits.
|
static VoxelArray |
cube(double x1,
double x2,
double y1,
double y2,
double z1,
double z2,
boolean value)
Construct a new rectangular VoxelArray that is a cuboid with the
specified minimum and maximum values.
|
VoxelArray |
cylindricalEmboss(frink.graphics.FrinkImage img,
float cx,
float cy,
float cz,
double angleCenter,
double angleWidth,
float targetHeight,
float d0,
float d1,
VoxelArray tool,
int toolcx,
int toolcy,
int toolcz)
Embosses an image using a cylindrical mapping into the outer hull of an
object.
|
VoxelArray |
cylindricalEmboss(frink.graphics.FrinkImage img,
float cx,
float cy,
float cz,
double angleCenter,
double angleWidth,
float targetHeight,
int grayMin,
int grayMax,
float d0min,
float d0max,
float d1min,
float d1max,
VoxelArray tool,
int toolcx,
int toolcy,
int toolcz)
Embosses an image using a cylindrical mapping into the outer hull of an
object.
|
void |
drawCappedCylinder(float x1,
float y1,
float z1,
float x2,
float y2,
float z2,
float radius)
Draws a cylinder with spherical end caps with the specified endpoints
and radius into this VoxelArray, modifying it in place.
|
void |
drawCappedCylinder(Point3DFloat p1,
Point3DFloat p2,
float radius)
Draws a cylinder with spherical end caps with the specified endpoints
and radius into this VoxelArray, modifying it in place.
|
void |
drawCylinder(float x1,
float y1,
float z1,
float x2,
float y2,
float z2,
float radius)
Draws a cylinder with the specified endpoints
and radius into this VoxelArray, modifying it in place.
|
void |
drawCylinder(Point3DFloat p1,
Point3DFloat p2,
float radius)
Draws a cylinder with the specified endpoints
and radius into this VoxelArray, modifying it in place.
|
void |
drawTaperedCappedCylinder(float x1,
float y1,
float z1,
float x2,
float y2,
float z2,
float radius1,
float radius2)
Draws a cylinder with spherical end caps with the specified endpoints
and radius into this VoxelArray, modifying it in place.
|
void |
drawTaperedCappedCylinder(Point3DFloat p1,
Point3DFloat p2,
float radius1,
float radius2)
Draws a cylinder with spherical end caps with the specified endpoints
and radius into this VoxelArray, modifying it in place.
|
void |
drawTaperedCylinder(float x1,
float y1,
float z1,
float x2,
float y2,
float z2,
float radius1,
float radius2)
Draws a cylinder with the specified endpoints and radii into this
VoxelArray, modifying it in place.
|
void |
drawTaperedCylinder(Point3DFloat p1,
Point3DFloat p2,
float radius1,
float radius2)
Draws a cylinder with the specified endpoints
and radiii into this VoxelArray, modifying it in place.
|
Point3DIntList |
externalHullPoints()
Returns a list of points on the hull of the object.
|
static VoxelArray |
extrudeOnPlane(frink.graphics.FrinkImage img,
float x,
float y,
float z,
float u,
float v,
float w,
float depth,
double thetaZ)
Extrudes an image along a plane specified by a point on the plane
(x, ,y, z) and a normal vector to the plane specified by (u,v,w).
|
static VoxelArray |
extrudeTapered(Point2DFloatList polygon,
float x1,
float y1,
float z1,
float x2,
float y2,
float z2,
float cx,
float cy,
float scale1,
float scale2,
double thetaZ)
Extrudes a filled polygon along a line from p1 to p2 and returns a new
VoxelArray of it.
|
static VoxelArray |
extrudeTaperedRotated(Point2DFloatList polygon,
float x1,
float y1,
float z1,
float x2,
float y2,
float z2,
float cx,
float cy,
float scale1,
float scale2,
double angle1,
double angle2)
Extrudes a filled polygon along a line from p1 to p2 and returns a new
VoxelArray of it.
|
static VoxelArray |
extrudeZ(frink.graphics.FrinkImage img,
int heightZ)
Extrudes an image along the Z axis and returns a new VoxelArray of it.
|
static VoxelArray |
extrudeZ(frink.graphics.FrinkImage img,
int minZ,
int maxZ)
Extrudes an image along the Z axis and returns a new VoxelArray of it.
|
static VoxelArray |
extrudeZ(Point2DFloatList polygon,
float minZ,
float maxZ)
Extrudes a filled polygon along the Z axis and returns a new VoxelArray
of it.
|
static VoxelArray |
extrudeZTapered(Point2DFloatList polygon,
float minZ,
float maxZ,
float scale1,
float scale2)
Extrudes a filled polygon (centered around its centroid) along the Z
axis and returns a new VoxelArray of it.
|
static VoxelArray |
extrudeZTapered(Point2DFloatList polygon,
float minZ,
float maxZ,
float cx,
float cy,
float scale1,
float scale2)
Extrudes a filled polygon along the Z axis and returns a new VoxelArray
of it.
|
static VoxelArray |
extrudeZTapered(Point2DFloatList polygon,
float minZ,
float maxZ,
float cx,
float cy,
float scale1,
float scale2,
double angle1,
double angle2)
Extrudes a filled polygon along the Z axis and returns a new VoxelArray
of it.
|
Point3DInt |
farthestSetPoint(LineSegment3DFloat line)
Returns the farthest set point from the specified (infinite) line.
|
void |
fillCube(float minX,
float maxX,
float minY,
float maxY,
float minZ,
float maxZ,
boolean value)
Sets the values in the specified cube to a specific value (true or
false.) Coordinates are rounded to the nearest voxel.
|
VoxelArray |
floodFill(int minx,
int maxx,
int miny,
int maxy,
int minz,
int maxz,
int startx,
int starty,
int startz)
Performs a flood fill of the specified VoxelArray, filling only to the
specified bounds.
|
boolean |
get(int x,
int y,
int z)
Returns the value of the point at (x,y,z) (true or false)
|
Point3DFloat |
getCenter()
Returns a
Point3DFloat representing the center of this
VoxelArray. |
Point3DInt |
getMaximumSetPoints()
Find the maximum set pixels on the (x,y,z) axes in this VoxelArray and
returns a Point3DInt containing their coordinates.
|
int |
getMaxSetZ()
Quick function to obtain the highest set Z coordinate.
|
int |
getMaxX()
Returns the max value in the x dimension.
|
int |
getMaxY()
Returns the maximum value in the y dimension.
|
int |
getMaxZ()
Returns the maximum value in the z dimension.
|
Point3DInt |
getMinimumSetPoints()
Find the minimum set pixels on the (x,y,z) axes in this VoxelArray and
returns a Point3DInt containing their coordinates.
|
int |
getMinSetZ()
Quick function to obtain the lowest set Z coordinate.
|
int |
getMinX()
Returns the minimum value in the x dimension.
|
int |
getMinY()
Returns the minimum value in the y dimension.
|
int |
getMinZ()
Returns the minimum value in the z dimension.
|
long |
getNextSetBitIndex(long index)
Returns the index of the next set bit that occurs on or after ther
specified starting index.
|
private boolean |
getNoCheck(int x,
int y,
int z)
Returns the value of the point at (x,y,z) without doing any boundary
checks.
|
private boolean |
getNoCheck(Point3DInt p)
Returns the value of the point without doing any boundary
checks.
|
long |
getPreviousSetBitIndex(long index)
Returns the index of the previous set bit that occurs on or before the
specified starting index.
|
int |
getSizeX()
Returns the size in the x dimension.
|
int |
getSizeY()
Returns the size in the y dimension.
|
int |
getSizeZ()
Returns the size in the z dimension.
|
boolean |
hasSameBoundary(VoxelArray other)
Returns true if the bounds of the other VoxelArray is the same size and
location as this one.
|
Point3DIntList |
hullPoints()
Returns a list of points on the hull of the object.
|
void |
indexToXYZ(long index,
long[] coords)
Convert an index into the
BiggerBitSet into x,y,z coordinates. |
boolean |
intersectsWith(int xmin,
int ymin,
int zmin,
int xmax,
int ymax,
int zmax)
Returns true if the bounding box of this VoxelArray intersects with
a box containing the specified boundaries.
|
boolean |
intersectsWith(VoxelArray b)
Returns true if the bounding box of this VoxelArray intersects with the
other VoxelArray, false otherwise.
|
void |
invert()
Inverts all of the pixels in this VoxelArray.
|
boolean |
isInRange(long x,
long y,
long z)
This method checks a point to see if it is within a valid range for
this VoxelArray.
|
boolean |
isInRange(Point3DInt p)
This method checks a point to see if it is within a valid range for
this VoxelArray.
|
static VoxelArray |
makeCappedCylinder(float x1,
float y1,
float z1,
float x2,
float y2,
float z2,
float radius)
Makes a cylinder with spherical end caps with the specified endpoints
and radius.
|
static VoxelArray |
makeCappedCylinder(Point3DFloat p1,
Point3DFloat p2,
float radius)
Makes a cylinder with spherical end caps with the specified endpoints
and radius.
|
static VoxelArray |
makeCylinder(float x1,
float y1,
float z1,
float x2,
float y2,
float z2,
float radius)
Makes a cylinder with with the specified endpoints and radius.
|
static VoxelArray |
makeCylinder(Point3DFloat p1,
Point3DFloat p2,
float radius)
Makes a cylinder with with the specified endpoints and radius.
|
static VoxelArray |
makeRoundedCube(float x1,
float x2,
float y1,
float y2,
float z1,
float z2,
float radius)
Construct a new rounded cuboid VoxelArray that encloses the specific
min and max coordinates and with corner diameter radius.
|
static VoxelArray |
makeSphere(float radius)
Makes a new VoxelArray with a sphere centered at (0,0,0) with the
specified radius.
|
static VoxelArray |
makeSpheroid(float rx,
float ry,
float rz)
Makes a new VoxelArray with a spheroid centered at (0,0,0) with the
specified radius on each axis [rx, ry, rz]
TODO: Make a version of this centered at any specified point.
|
static VoxelArray |
makeSuperellipsoid(double rx,
double ry,
double rz,
double n1,
double n2)
Creates a "superellipsoid" which is a generalization of the ellipsoid
family which is a superset of the spheroid family.
|
static VoxelArray |
makeSupertoroid(double r,
double rx,
double ry,
double rz,
double e1,
double e2)
Creates a "supertoroid" which is a generalization of the toroid family.
|
static VoxelArray |
makeTaperedCappedCylinder(float x1,
float y1,
float z1,
float x2,
float y2,
float z2,
float radius1,
float radius2)
Makes a cylinder with spherical end caps with the specified endpoints
and radius.
|
static VoxelArray |
makeTaperedCappedCylinder(Point3DFloat p1,
Point3DFloat p2,
float radius1,
float radius2)
Makes a cylinder with spherical end caps with the specified endpoints
and radius.
|
static VoxelArray |
makeTaperedCylinder(float x1,
float y1,
float z1,
float x2,
float y2,
float z2,
float radius1,
float radius2)
Makes a tapered cylinder with with the specified endpoints and radius.
|
static VoxelArray |
makeTaperedCylinder(Point3DFloat p1,
Point3DFloat p2,
float radius1,
float radius2)
Makes a tapered cylinder with with the specified endpoints and radius.
|
private double |
mod(double x,
double y)
Define a modulus operator where x % y = x - y * floor[x/y] .
|
static VoxelArray |
paintAlongAllPoints(VoxelArray v1,
VoxelArray tool,
int cx,
int cy,
int cz)
Moves a tool along *all* set points in a VoxelArray and returns a new
VoxelArray of it.
|
VoxelArray |
paintAlongHull(VoxelArray tool,
int cx,
int cy,
int cz,
boolean add)
Moves a tool along a path of integer points and returns a new
VoxelArray of it, either adding to or removing points with the tool.
|
void |
paintAlongLine(VoxelArray tool,
int x1,
int y1,
int z1,
int x2,
int y2,
int z2,
int xc,
int yc,
int zc,
boolean add)
Modifies the pixels in this VoxelArray by moving the VoxelArray tool
along a line and adding or removing the points in VoxelArray tool that
are true, modifying this VoxelArray in place.
|
static VoxelArray |
paintAlongPath(Point3DIntList points,
VoxelArray tool,
int cx,
int cy,
int cz)
Moves a tool along a path of integer points and returns a new
VoxelArray of it.
|
VoxelArray |
planarEmboss(frink.graphics.FrinkImage img,
float cx,
float cy,
float xWidth,
float yHeight,
int grayMin,
int grayMax,
float d0min,
float d0max,
float d1min,
float d1max,
VoxelArray tool,
int toolcx,
int toolcy,
int toolcz)
Embosses an image using a planar mapping into the top of an object
(that is, downward on the Z-axis.) A tool will be used to
carve into the object.
|
frink.graphics.FrinkImageExpression |
projectX(frink.expr.Environment env)
Projects a silhouette image looking along the X axis.
|
frink.graphics.FrinkImageExpression |
projectY(frink.expr.Environment env)
Projects a silhouette image looking along the Y axis.
|
frink.graphics.FrinkImageExpression |
projectZ(frink.expr.Environment env)
Projects a silhouette image looking along the Z axis.
|
void |
remove(VoxelArray b)
Removes the pixels in this VoxelArray that are true in
VoxelArray b, modifying this VoxelArray in place.
|
void |
removeAlongLine(VoxelArray b,
int x1,
int y1,
int z1,
int x2,
int y2,
int z2,
int xc,
int yc,
int zc)
Removes the pixels in this VoxelArray by moving the
VoxelArray b along a line and removing the points in VoxelArray b
that are true, modifying this VoxelArray in place.
|
void |
removeOutside(Plane3DFloat plane)
Removes all the voxels on the "outside" of a plane.
|
void |
removeOutsideLine(float cx1,
float cy1,
float cz1,
float cx2,
float cy2,
float cz2,
float radius,
int minX,
int maxX,
int minY,
int maxY,
int minZ,
int maxZ)
Removes the points outside of a specified distance (radius) from an
infinite line.
|
void |
removeOutsideSphere(float cx,
float cy,
float cz,
float radius,
int minX,
int maxX,
int minY,
int maxY,
int minZ,
int maxZ)
Removes all of the points outside a sphere.
|
VoxelArray |
rotate(float a,
float b,
float c,
float u,
float v,
float w,
double theta)
Rotates this VoxelArray around a line through a point (a, b, c) parallel
to the vector [u,v,w] by the angle theta.
|
VoxelArray |
rotateXYZ(float a,
float b,
float c,
double thetaX,
double thetaY,
double thetaZ)
Performs three rotations around the point (a, b, c)
by performing 3 successive rotations about the x, y, and z axes in that
order.
|
boolean |
sampleBoolean(int x,
int y,
int z)
Sample the field at the specified 3-dimensional point and return its
value as true or false.
|
boolean |
sampleBoolean(Point3DInt p)
Sample the field at the specified 3-dimensional point and return its
value as true or false.
|
float |
sampleFloat(float x,
float y,
float z)
Sample the field at the specified 3-dimensional point and return its
value.
|
float |
sampleFloat(Point3DFloat p)
Sample the field at the specified 3-dimensional point and return its
value.
|
void |
set(int x,
int y,
int z,
boolean value)
Sets the voxel in the specific coordinate to the specific value.
|
void |
set(Point3DInt p,
boolean value)
Sets the voxel in the specific coordinate to the specific value.
|
private void |
setNoCheck(int x,
int y,
int z,
boolean value)
Sets the specific coordinate to the specific value, doing no checking
of the validity of the coordinates for speed.
|
private void |
setNoCheck(Point3DInt p,
boolean value)
Sets the specific coordinate to the specific value.
|
void |
setRange(int minX,
int maxX,
int minY,
int maxY,
int minZ,
int maxZ,
boolean value)
Sets the values in the specified range to the certain value.
|
VoxelArray |
solidOfRotation(float x,
float y,
float z,
float u,
float v,
float w,
double angle1,
double angle2)
Creates a solid of rotation by rotating this VoxelArray around
an axis going through point (x,y,z) and the normal (u,v,w).
|
VoxelArray |
solidOfRotation(LineSegment3DFloat axis,
double angle1,
double angle2)
Creates a solid of rotation by rotating this VoxelArray around
an axis specified by axis.
|
VoxelArray |
solidOfRotation(Point3DFloat point,
Point3DFloat axis,
double angle1,
double angle2)
Creates a solid of rotation by rotating this VoxelArray around
an axis going through point (x,y,z) and the normal (u,v,w).
|
VoxelArray |
sphericalEmboss(frink.graphics.FrinkImage img,
float cx,
float cy,
float cz,
double azCenter,
double azWidth,
double altCenter,
double altHeight,
float d0,
float d1,
VoxelArray tool,
int toolcx,
int toolcy,
int toolcz)
Embosses an image using a spherical mapping into the outer hull of an
object.
|
VoxelArray |
sphericalEmboss(frink.graphics.FrinkImage img,
float cx,
float cy,
float cz,
double azCenter,
double azWidth,
double altCenter,
double altHeight,
int grayMin,
int grayMax,
float d0min,
float d0max,
float d1min,
float d1max,
VoxelArray tool,
int toolcx,
int toolcy,
int toolcz)
Embosses an image using a spherical mapping into the outer hull of an
object.
|
static VoxelArray |
strokeZ(Point2DFloatList polygon,
float z1,
float z2,
float strokeRadius,
boolean closed)
Extrudes the stroke of a polygon (using a cylindrical "pen") along the
Z axis and returns a new VoxelArray of it.
|
static VoxelArray |
strokeZ(Point2DFloatList polygon,
VoxelArray tool,
float cx,
float cy,
float cz,
boolean closed)
Extrudes the stroke of a polygon (using a the specified VoxelArray as a
"tool") along the Z axis and returns a new VoxelArray of it.
|
static VoxelArray |
strokeZTapered(Point2DFloatList polygon,
float z1,
float z2,
float r1,
float r2,
boolean closed)
Extrudes the stroke of a polygon (using a tapered cylindrical "pen")
along the Z axis and returns a new VoxelArray of it.
|
long |
toIndex(long x,
long y,
long z)
Convert x,y,z coordinates to an index into the
BiggerBitSet . |
private long |
toIndexNoCheck(long x,
long y,
long z)
Convert x,y,z coordinates to an index into the
BiggerBitSet . |
java.lang.String |
toObjFormat(java.lang.String name)
This triangulates the external hull of this object and returns it as a
string in Wavefront .obj format that can be 3-D printed.
|
java.lang.String |
toObjFormat(java.lang.String name,
float scale)
This triangulates the external hull of this object and returns it as a
string in Wavefront .obj format that can be 3-D printed.
|
java.lang.String |
toSTLFormat(java.lang.String name)
This triangulates the external hull of this object and returns it as a
string in STL format that can be 3-D printed.
|
java.lang.String |
toSTLFormat(java.lang.String name,
float scale)
This triangulates the external hull of this object and returns it as a
string in STL format that can be 3-D printed.
|
VoxelArray |
transform(CoordinateTransformer3DFloat transform)
Transforms this VoxelArray (rotations, scalings, translations, etc.)
using an arbitrary
CoordinateTransformer3DFloat |
void |
translate(int x,
int y,
int z)
Translates this whole object by the specified amounts on each axis.
|
java.util.Vector<Triangle3DFloat> |
triangulateHull()
Triangulates the external hull of the voxels and returns a
Vector of triangles that represent its external hull. |
VoxelArray |
union(VoxelArray other)
Creates the union of this VoxelArray and another VoxelArray and returns
a new VoxelArray that is just big enough to contain their union.
|
static VoxelArray |
union(VoxelArray v1,
VoxelArray v2)
Returns the union of two VoxelArrays as a new VoxelArray that is just
big enough to hold both of them.
|
long |
volume()
Returns the volume of a VoxelArray in number of voxels.
|
private BiggerBitSet voxels
BiggerBitSet
that contains all of the bits.private int sizeX
private int sizeY
private int sizeZ
private int offX
private int offY
private int offZ
private long area
private static final double TWOPI
public VoxelArray(int sizeX, int sizeY, int sizeZ)
public VoxelArray(int sizeX, int sizeY, int sizeZ, boolean value)
public VoxelArray(int minX, int sizeX, int minY, int sizeY, int minZ, int sizeZ, boolean value)
public VoxelArray(VoxelArray other)
public VoxelArray(VoxelArray other, boolean value)
public static VoxelArray construct(double x1, double x2, double y1, double y2, double z1, double z2, boolean value)
public static VoxelArray cube(double x1, double x2, double y1, double y2, double z1, double z2, boolean value)
construct(double, double, double, double, double, double, boolean)
above in that it *rounds* to the nearest voxel coordinate instead of
doing the probably-erroneous ceil and floor of construct. This is
recommended instead of construct for rendering cuboids.public static VoxelArray construct(Point3DIntList points)
public static VoxelArray construct(BoundingBox3DFloat bb, boolean value)
public long toIndex(long x, long y, long z) throws java.lang.IndexOutOfBoundsException
BiggerBitSet
.java.lang.IndexOutOfBoundsException
private long toIndexNoCheck(long x, long y, long z)
BiggerBitSet
.
This is a private method that doesn't do any range checking, assuming
the ranges have already been checked in the calling function.public void indexToXYZ(long index, long[] coords)
BiggerBitSet
into x,y,z coordinates.
The array passed in should be able to hold 3 longs.public void setRange(int minX, int maxX, int minY, int maxY, int minZ, int maxZ, boolean value) throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsException
public void fillCube(float minX, float maxX, float minY, float maxY, float minZ, float maxZ, boolean value) throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsException
public void set(int x, int y, int z, boolean value) throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsException
public void set(Point3DInt p, boolean value) throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsException
private void setNoCheck(int x, int y, int z, boolean value)
private void setNoCheck(Point3DInt p, boolean value)
public boolean isInRange(long x, long y, long z)
public boolean isInRange(Point3DInt p)
private void checkPoint(long x, long y, long z) throws java.lang.IndexOutOfBoundsException
IndexOutOfBoundsException
if it
doesn't.java.lang.IndexOutOfBoundsException
public boolean get(int x, int y, int z) throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsException
private boolean getNoCheck(int x, int y, int z) throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsException
private boolean getNoCheck(Point3DInt p) throws java.lang.IndexOutOfBoundsException
java.lang.IndexOutOfBoundsException
public int getSizeX()
public int getSizeY()
public int getSizeZ()
public int getMinX()
public int getMinY()
public int getMinZ()
public int getMaxX()
public int getMaxY()
public int getMaxZ()
public Point3DFloat getCenter()
Point3DFloat
representing the center of this
VoxelArray. This is not the center of the set voxels, but the center
of the containing VoxelArray.public void translate(int x, int y, int z)
public float sampleFloat(float x, float y, float z)
sampleFloat
in interface Field3DFloat
public boolean sampleBoolean(int x, int y, int z)
public boolean sampleBoolean(Point3DInt p)
public float sampleFloat(Point3DFloat p)
public java.util.Vector<Triangle3DFloat> triangulateHull()
Vector
of triangles that represent its external hull.public java.lang.String toObjFormat(java.lang.String name)
name
- The name of the object in the obj file. This should be
text only.public java.lang.String toObjFormat(java.lang.String name, float scale)
name
- The name of the object in the obj file. This should be
text only.scale
- The scale to multiply each coordinate by.public java.lang.String toSTLFormat(java.lang.String name)
name
- The name of the object in the obj file. This should be text only.public java.lang.String toSTLFormat(java.lang.String name, float scale)
name
- The name of the object in the obj file. This should be
text only.scale
- A scaling factor to multiply by.public Point3DIntList hullPoints()
externalHullPoints()
method.
The resultant Point3DIntList
can be passed to
paintAlongPath(frink.graphics.Point3DIntList, frink.graphics.VoxelArray, int, int, int)
to extend (or erode) the hull of an object.public Point3DIntList externalHullPoints()
hullPoints()
method. The resultant
Point3DIntList
can be passed to paintAlongPath(frink.graphics.Point3DIntList, frink.graphics.VoxelArray, int, int, int)
to
extend (or erode) the hull of an object.public VoxelArray floodFill(int minx, int maxx, int miny, int maxy, int minz, int maxz, int startx, int starty, int startz)
add(frink.graphics.VoxelArray)
method.) Returning a new VoxelArray is useful because
then you can then determine the volume (number of set bits) in the
result by calling countSetBits()
. This can be used to
highly-accurately measure weird-shaped measuring cups or spoons, etc.public frink.graphics.FrinkImageExpression projectX(frink.expr.Environment env) throws frink.expr.NotSupportedException
frink.expr.NotSupportedException
public frink.graphics.FrinkImageExpression projectY(frink.expr.Environment env) throws frink.expr.NotSupportedException
frink.expr.NotSupportedException
public frink.graphics.FrinkImageExpression projectZ(frink.expr.Environment env) throws frink.expr.NotSupportedException
frink.expr.NotSupportedException
public void remove(VoxelArray b)
public void addAlongLine(VoxelArray b, int x1, int y1, int z1, int x2, int y2, int z2, int xc, int yc, int zc)
public void removeAlongLine(VoxelArray b, int x1, int y1, int z1, int x2, int y2, int z2, int xc, int yc, int zc)
public void paintAlongLine(VoxelArray tool, int x1, int y1, int z1, int x2, int y2, int z2, int xc, int yc, int zc, boolean add)
public void add(VoxelArray b)
public boolean intersectsWith(VoxelArray b)
public boolean intersectsWith(int xmin, int ymin, int zmin, int xmax, int ymax, int zmax)
public static VoxelArray union(VoxelArray v1, VoxelArray v2)
public VoxelArray union(VoxelArray other)
public void invert()
public long volume()
public boolean hasSameBoundary(VoxelArray other)
public static VoxelArray makeSphere(float radius)
public static VoxelArray makeSpheroid(float rx, float ry, float rz)
public static VoxelArray makeCylinder(Point3DFloat p1, Point3DFloat p2, float radius)
public static VoxelArray makeCylinder(float x1, float y1, float z1, float x2, float y2, float z2, float radius)
public void drawCylinder(Point3DFloat p1, Point3DFloat p2, float radius)
public void drawCylinder(float x1, float y1, float z1, float x2, float y2, float z2, float radius)
public static VoxelArray makeTaperedCylinder(Point3DFloat p1, Point3DFloat p2, float radius1, float radius2)
public static VoxelArray makeTaperedCylinder(float x1, float y1, float z1, float x2, float y2, float z2, float radius1, float radius2)
public void drawTaperedCylinder(Point3DFloat p1, Point3DFloat p2, float radius1, float radius2)
public void drawTaperedCylinder(float x1, float y1, float z1, float x2, float y2, float z2, float radius1, float radius2)
public static VoxelArray makeCappedCylinder(Point3DFloat p1, Point3DFloat p2, float radius)
public static VoxelArray makeCappedCylinder(float x1, float y1, float z1, float x2, float y2, float z2, float radius)
public void drawCappedCylinder(Point3DFloat p1, Point3DFloat p2, float radius)
public void drawCappedCylinder(float x1, float y1, float z1, float x2, float y2, float z2, float radius)
public static VoxelArray makeTaperedCappedCylinder(Point3DFloat p1, Point3DFloat p2, float radius1, float radius2)
public static VoxelArray makeTaperedCappedCylinder(float x1, float y1, float z1, float x2, float y2, float z2, float radius1, float radius2)
public void drawTaperedCappedCylinder(Point3DFloat p1, Point3DFloat p2, float radius1, float radius2)
public void drawTaperedCappedCylinder(float x1, float y1, float z1, float x2, float y2, float z2, float radius1, float radius2)
public void removeOutside(Plane3DFloat plane)
See Plane3DFloat
for definition of what "inside" and "outside"
of the plane means and how to construct a plane in a few different
ways.
TODO: This can probably be optimized a lot.
For each y and z, the point where x intersects the plane is x = - (D + B y + C z) / A
and the points to be removed can be quickly found along that x line. Note that if A == 0, this could cause a divide by zero. This means that line is entirely inside or outside the object.
For each x and z, the point where y intersects the plane is y = - (D + A x + C z) / B
For each x and y, the point where z intersects the plane is given by z = - (D + A x + B y) / C
public static VoxelArray extrudeZ(frink.graphics.FrinkImage img, int heightZ) throws frink.expr.NotSupportedException
frink.expr.NotSupportedException
public static VoxelArray extrudeZ(frink.graphics.FrinkImage img, int minZ, int maxZ) throws frink.expr.NotSupportedException
frink.expr.NotSupportedException
public static VoxelArray extrudeOnPlane(frink.graphics.FrinkImage img, float x, float y, float z, float u, float v, float w, float depth, double thetaZ) throws frink.expr.NotSupportedException, frink.expr.InvalidArgumentException
thetaZ
radians to orient it on
the plane.frink.expr.NotSupportedException
frink.expr.InvalidArgumentException
public static VoxelArray strokeZ(Point2DFloatList polygon, VoxelArray tool, float cx, float cy, float cz, boolean closed)
public static VoxelArray strokeZ(Point2DFloatList polygon, float z1, float z2, float strokeRadius, boolean closed)
public static VoxelArray strokeZTapered(Point2DFloatList polygon, float z1, float z2, float r1, float r2, boolean closed)
public static VoxelArray extrudeZ(Point2DFloatList polygon, float minZ, float maxZ)
public static VoxelArray extrudeZTapered(Point2DFloatList polygon, float minZ, float maxZ, float scale1, float scale2)
public static VoxelArray extrudeZTapered(Point2DFloatList polygon, float minZ, float maxZ, float cx, float cy, float scale1, float scale2)
public static VoxelArray extrudeZTapered(Point2DFloatList polygon, float minZ, float maxZ, float cx, float cy, float scale1, float scale2, double angle1, double angle2)
public static VoxelArray extrudeTapered(Point2DFloatList polygon, float x1, float y1, float z1, float x2, float y2, float z2, float cx, float cy, float scale1, float scale2, double thetaZ) throws frink.expr.InvalidArgumentException
frink.expr.InvalidArgumentException
public static VoxelArray extrudeTaperedRotated(Point2DFloatList polygon, float x1, float y1, float z1, float x2, float y2, float z2, float cx, float cy, float scale1, float scale2, double angle1, double angle2) throws frink.expr.InvalidArgumentException
frink.expr.InvalidArgumentException
public static VoxelArray makeRoundedCube(float x1, float x2, float y1, float y2, float z1, float z2, float radius)
public void removeOutsideSphere(float cx, float cy, float cz, float radius, int minX, int maxX, int minY, int maxY, int minZ, int maxZ)
public void removeOutsideLine(float cx1, float cy1, float cz1, float cx2, float cy2, float cz2, float radius, int minX, int maxX, int minY, int maxY, int minZ, int maxZ)
public static VoxelArray paintAlongPath(Point3DIntList points, VoxelArray tool, int cx, int cy, int cz)
public static VoxelArray paintAlongAllPoints(VoxelArray v1, VoxelArray tool, int cx, int cy, int cz)
public VoxelArray paintAlongHull(VoxelArray tool, int cx, int cy, int cz, boolean add)
public VoxelArray transform(CoordinateTransformer3DFloat transform) throws frink.expr.InvalidArgumentException
CoordinateTransformer3DFloat
transform
- A CoordinateTransformer3DFloat
that describes the transform.frink.expr.InvalidArgumentException
public VoxelArray rotate(float a, float b, float c, float u, float v, float w, double theta) throws frink.expr.InvalidArgumentException
a
- x-coordinate of a point on the line of rotation.b
- y-coordinate of a point on the line of rotation.c
- z-coordinate of a point on the line of rotation.u
- x-coordinate of the line's direction vector (unnormalized).v
- y-coordinate of the line's direction vector (unnormalized).w
- z-coordinate of the line's direction vector (unnormalized).theta
- The angle of rotation, in radians.frink.expr.InvalidArgumentException
public VoxelArray rotateXYZ(float a, float b, float c, double thetaX, double thetaY, double thetaZ) throws frink.expr.InvalidArgumentException
rotate(a=[0,180,0]) which is frequently simplified to rotate([0,180,0])
See: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#rotate
but is far more flexible because it allows rotation around an arbitrary point.
It is recommended to use this method when rotating around more than one axis, especially for a VoxelArray, because it intelligently composes a single tranformation matrix and performs only one transformation which can be reversed. (VoxelArray.transform actually computes and performs the *inverse* transform of the transform you give it, eliminating holes in the target VoxelArray space.)
a
- x-coordinate of a point on the line of rotation.b
- y-coordinate of a point on the line of rotation.c
- z-coordinate of a point on the line of rotation.thetaX
- The angle of rotation around a line parallel to the X
axis, in radians. Looking from a positive axis toward the origin, a
positive angle gives a counterclockwise rotation.thetaY
- The angle of rotation around a line parallel to the Y
axis, in radians. Looking from a positive axis toward the origin, a
positive angle gives a counterclockwise rotation.thetaZ
- The angle of rotation around a line parallel to the Z
axis, in radians. Looking from a positive axis toward the origin, a
positive angle gives a counterclockwise rotation.frink.expr.InvalidArgumentException
public static VoxelArray makeSupertoroid(double r, double rx, double ry, double rz, double e1, double e2)
See: https://cse.buffalo.edu/~jryde/cse673/files/superquadrics.pdf for the equation
See: http://paulbourke.net/geometry/toroidal/ for graphs of the equation families. The minimum bounding box is now calculated correctly if rx != ry.
r
- The major radius of the large circlerx
- The minor radius of the small circle in the x directionry
- The minor radius of the small circle in the y directionrz
- The minor radius of the small circle in the z directione1
- The eccentricity of the small circle (1=circle, 2=square,
less than 1 is puffy rounded square, greater than 2 is a
pinched diamond. )e2
- The eccentricity of the large circle (1=circle, 2=square,
less than 1 is puffy rounded square, greater than 2 is a
pinched diamond. )public static VoxelArray makeSuperellipsoid(double rx, double ry, double rz, double n1, double n2)
See: http://paulbourke.net/geometry/spherical/ for graphs of the equation families.
rx
- The radius in the x directionry
- The radius in the y directionrz
- The radius in the z directionn1
- The eccentricity around the z axis (1=circle, 2=square,
less than 1 is puffy rounded square, greater than 2 is a
pinched diamond. )n2
- The eccentricity around the x and y axes (1=circle, 2=square,
less than 1 is puffy rounded square, greater than 2 is a
pinched diamond. )public long getNextSetBitIndex(long index)
public long getPreviousSetBitIndex(long index)
public int getMinSetZ()
public int getMaxSetZ()
public Point3DInt getMinimumSetPoints()
public Point3DInt getMaximumSetPoints()
public Point3DInt farthestSetPoint(LineSegment3DFloat line)
public VoxelArray solidOfRotation(LineSegment3DFloat axis, double angle1, double angle2) throws frink.expr.InvalidArgumentException
frink.expr.InvalidArgumentException
public VoxelArray solidOfRotation(Point3DFloat point, Point3DFloat axis, double angle1, double angle2) throws frink.expr.InvalidArgumentException
frink.expr.InvalidArgumentException
public VoxelArray solidOfRotation(float x, float y, float z, float u, float v, float w, double angle1, double angle2) throws frink.expr.InvalidArgumentException
frink.expr.InvalidArgumentException
public VoxelArray cylindricalEmboss(frink.graphics.FrinkImage img, float cx, float cy, float cz, double angleCenter, double angleWidth, float targetHeight, float d0, float d1, VoxelArray tool, int toolcx, int toolcy, int toolcz)
img
- The image to be embossedcx
- The x-coordinate of the center of the projection.cy
- The y-coordinate of the center of the projection.cz
- The z-coordinate of the center of the projection.angleCenter
- The angle (in radians) of the center of the
projection reckoned counterclockwise from the y axis. (0 degrees is
toward the y axis, 270 degrees is toward the x axis)angleWidth
- The angle (in radians) wide to map the image. 2 pi
radians wraps around the entire cylinder.targetHeight
- The height (in voxels) to map the image.d0
- The depth to begin embossing from (in voxels). 0 is the
surface of the image. Negative numbers are allowed.d1
- The depth to end embossing into the object (in voxels). 0
is the surface of the image.tool
- A VoxelArray to use as the tool.toolcx
- The x coordinate of the center of the tool to move along
the path.toolcy
- The y coordinate of the center of the tool to move along
the path.toolcz
- The z coordinate of the center of the tool to move along
the path.public VoxelArray cylindricalEmboss(frink.graphics.FrinkImage img, float cx, float cy, float cz, double angleCenter, double angleWidth, float targetHeight, int grayMin, int grayMax, float d0min, float d0max, float d1min, float d1max, VoxelArray tool, int toolcx, int toolcy, int toolcz)
img
- The image to be embossedcx
- The x-coordinate of the center of the projection.cy
- The y-coordinate of the center of the projection.cz
- The z-coordinate of the center of the projection.angleCenter
- The angle (in radians) of the center of the
projection reckoned counterclockwise from the y axis. (0 degrees is
toward the y axis, 270 degrees is toward the x axis)angleWidth
- The angle (in radians) wide to map the image. 2 pi
radians wraps around the entire cylinder.targetHeight
- The height (in voxels) to map the image.grayMin
- A value from 0 (black) to 255 (white) indicating the
minimum pixel gray value from the image that will be embossed. Pixels
with values less than this will be ignored.grayMax
- A value from 0 (black) to 255 (white) indicating the
maximum pixel gray value from the image that will be embossed. Pixels
with values greater than this will be ignored.d0min
- The depth into the object to begin embossing from (in
voxels) when the color grayMin is encountered. 0 is the surface of the
image. Negative numbers are allowed.d0max
- The depth into the object to begin embossing from (in
voxels) when the color grayMax is encountered. 0 is the surface of the
image. Negative numbers are allowed.d1min
- The depth into the object to end embossing (in
voxels) when the color grayMin is encountered. 0 is the surface of the
image. Negative numbers are allowed.d1max
- The depth into the object to end embossing (in
voxels) when the color grayMax is encountered. 0 is the surface of the
image. Negative numbers are allowed.tool
- A VoxelArray to use as the tool.toolcx
- The x coordinate of the center of the tool to move along
the path.toolcy
- The y coordinate of the center of the tool to move along
the path.toolcz
- The z coordinate of the center of the tool to move along
the path.public VoxelArray sphericalEmboss(frink.graphics.FrinkImage img, float cx, float cy, float cz, double azCenter, double azWidth, double altCenter, double altHeight, float d0, float d1, VoxelArray tool, int toolcx, int toolcy, int toolcz)
img
- The image to be embossedcx
- The x-coordinate of the center of the projection.cy
- The y-coordinate of the center of the projection.cz
- The z-coordinate of the center of the projection.azCenter
- The angle (in radians) of the center azimuth of the
projection reckoned counterclockwise from the y axis. (0 degrees is
toward the y axis, 270 degrees is toward the x axis)azWidth
- The angle (in radians) wide to map the image. 2 pi
radians wraps around the entire cylinder.altCenter
- The center altitude angle (in radians) around which to
map the image. This should be between -pi/2 (south pole) and +pi/2
radians (north pole). 0 radians is centered on the equator.altHeight
- The angular height (in radians) to map the image. Pi
radians will cover the whole sphere.d0
- The depth to begin embossing from (in voxels). 0 is the
surface of the image. Negative numbers are allowed.d1
- The depth to end embossing into the object (in voxels). 0
is the surface of the image.tool
- A VoxelArray to use as the tool.toolcx
- The x coordinate of the center of the tool to move along
the path.toolcy
- The y coordinate of the center of the tool to move along
the path.toolcz
- The z coordinate of the center of the tool to move along
the path.public VoxelArray sphericalEmboss(frink.graphics.FrinkImage img, float cx, float cy, float cz, double azCenter, double azWidth, double altCenter, double altHeight, int grayMin, int grayMax, float d0min, float d0max, float d1min, float d1max, VoxelArray tool, int toolcx, int toolcy, int toolcz)
img
- The image to be embossedcx
- The x-coordinate of the center of the projection.cy
- The y-coordinate of the center of the projection.cz
- The z-coordinate of the center of the projection.azCenter
- The angle (in radians) of the center azimuth of the
projection reckoned counterclockwise from the y axis. (0 degrees is
toward the y axis, 270 degrees is toward the x axis)azWidth
- The angle (in radians) wide to map the image. 2 pi
radians wraps around the entire cylinder.altCenter
- The center altitude angle (in radians) around which to
map the image. This should be between -pi/2 (south pole) and +pi/2
radians (north pole). 0 radians is centered on the equator.altHeight
- The angular height (in radians) to map the image. Pi
radians will cover the whole sphere.grayMin
- A value from 0 (black) to 255 (white) indicating the
minimum pixel gray value from the image that will be embossed. Pixels
with values less than this will be ignored.grayMax
- A value from 0 (black) to 255 (white) indicating the
maximum pixel gray value from the image that will be embossed. Pixels
with values greater than this will be ignored.d0min
- The depth into the object to begin embossing from (in
voxels) when the color grayMin is encountered. 0 is the surface of the
image. Negative numbers are allowed.d0max
- The depth into the object to begin embossing from (in
voxels) when the color grayMax is encountered. 0 is the surface of the
image. Negative numbers are allowed.d1min
- The depth into the object to end embossing (in
voxels) when the color grayMin is encountered. 0 is the surface of the
image. Negative numbers are allowed.d1max
- The depth into the object to end embossing (in
voxels) when the color grayMax is encountered. 0 is the surface of the
image. Negative numbers are allowed.tool
- A VoxelArray to use as the tool.toolcx
- The x coordinate of the center of the tool to move along
the path.toolcy
- The y coordinate of the center of the tool to move along
the path.toolcz
- The z coordinate of the center of the tool to move along
the path.public VoxelArray planarEmboss(frink.graphics.FrinkImage img, float cx, float cy, float xWidth, float yHeight, int grayMin, int grayMax, float d0min, float d0max, float d1min, float d1max, VoxelArray tool, int toolcx, int toolcy, int toolcz)
img
- The image to be embossedcx
- The x-coordinate of the center of the projection.cy
- The y-coordinate of the center of the projection.xWidth
- The width (in voxels) of the x-axis of the projectionyHeight
- The height (in voxels) of the y-axis of the projectiongrayMin
- A value from 0 (black) to 255 (white) indicating the
minimum pixel gray value from the image that will be embossed. Pixels
with values less than this will be ignored.grayMax
- A value from 0 (black) to 255 (white) indicating the
maximum pixel gray value from the image that will be embossed. Pixels
with values greater than this will be ignored.d0min
- The depth into the object to begin embossing from (in
voxels) when the color grayMin is encountered. 0 is the surface of the
image. Negative numbers are allowed.d0max
- The depth into the object to begin embossing from (in
voxels) when the color grayMax is encountered. 0 is the surface of the
image. Negative numbers are allowed.d1min
- The depth into the object to end embossing (in
voxels) when the color grayMin is encountered. 0 is the surface of the
image. Negative numbers are allowed.d1max
- The depth into the object to end embossing (in
voxels) when the color grayMax is encountered. 0 is the surface of the
image. Negative numbers are allowed.tool
- A VoxelArray to use as the tool.toolcx
- The x coordinate of the center of the tool to move along
the path.toolcy
- The y coordinate of the center of the tool to move along
the path.toolcz
- The z coordinate of the center of the tool to move along
the path.public long countSetBits()
private double mod(double x, double y)
public Point3DDouble centerOfMass()
To convert from voxel coordinate v to original coordinate x,
x = xmin + v (xmax - xmin) / (vmax - vmin)
inverse:
v = (x - xmin) (vmax - vmin) / (xmax - xmin)