Package mgui.geometry
Class Grid3D
java.lang.Object
mgui.geometry.Shape3D
mgui.geometry.Box3D
mgui.geometry.Grid3D
public class Grid3D extends Box3D
Holds a 3D array of values and a Box3D defining the distribution of these
values in R3. For use as a voxel set or volume 3D texture. Values are designated
in terms of their size in bytes using the function setDataSize
To avoid confusion, dimensions in a Grid3D
shape, following the Java3D convention,
are specified as S (analogous to X), T (analogous to Y), and R (analogous to Z).
Voxels are referred to as integer arrays: {s, t, r}; and with an absolute index, calculated as: r * s_size * t_size + t * s_size + s.
- Version:
- 1.0
- Author:
- Andrew Reid
-
Nested Class Summary
Nested classes/interfaces inherited from interface mgui.interfaces.xml.XMLObject
XMLObject.XMLEncoding, XMLObject.XMLType
-
Field Summary
Fields Modifier and Type Field Description protected int
r_size
protected int
s_size
protected int
t_size
protected int
v_size
Fields inherited from class mgui.geometry.Shape3D
xml_count, xml_current_block, xml_encoding, xml_itr, xml_vertices
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description java.lang.Object
clone()
int
getAbsoluteIndex(int[] voxel)
Returns the absolute index of the voxel specified by the integer array[s,t,r]
.int
getAbsoluteIndex(int i, int j, int k)
Returns absolute index of this coordinate, which is given by: k * xSize * ySize + j * xSize + i (x changes fastest)int[]
getDims()
Returns the S, T, R, V dimensions, as an int arrayint[]
getEnclosingVoxel(org.jogamp.vecmath.Point3f p)
Determines the voxel which encloses pointp
.float[]
getGeomDims()
Returns the geometric dimensions of this grid.float
getGeomR()
Returns the geometric dimension in the R-axis.float
getGeomS()
Returns the geometric dimension in the S-axis.float
getGeomT()
Returns the geometric dimension in the T-axis.org.jogamp.vecmath.Matrix4f
getGridBasisTransform()
Finds transform using the origin (center point of first voxel), rather than the base point.org.jogamp.vecmath.Point3f
getGridCoordinate(org.jogamp.vecmath.Point3f p)
Determines the grid coordinate of pointp
, expressed in world coordinates.int[]
getIndexAsVoxel(int index)
Returns a voxel as an integer array of the form {s, t, r}, from the absolute indexindex
.java.lang.String
getLocalName()
Returns the local name associated with this XML object.org.jogamp.vecmath.Point3f
getMaxVoxelMidPt()
org.jogamp.vecmath.Point3f
getMinVoxelMidPt()
int[]
getNeighbours(int idx)
Returns the immediate neighbours of the voxel atidx
.org.jogamp.vecmath.Point3f
getOrigin()
Returns the origin of this grid.org.jogamp.vecmath.Matrix4f
getScaledBasisTransform()
Returns a matrix which will transform a vector expressed in world (model) coordinates to one expressed with respect to this box's coordinate space.int
getSize()
Returns the total number of data elements in this grid.int
getSizeR()
Returns the data dimensions in the z (R) dimensionint
getSizeS()
Returns the data dimensions in the x (S) dimensionint
getSizeT()
Returns the data dimensions in the y (T) dimensionint
getSizeV()
int[]
getSubGrid(org.jogamp.vecmath.Point3f p1, org.jogamp.vecmath.Point3f p2)
Returns two points (min coords, max coords) which represent a subset of this grid which is bounded by the geometric box specified by p1 and p2 (i.e., a voxel must be contained within the box, or must enclose its boundary).org.jogamp.vecmath.Point3f
getVertex(int index)
Returns the midpoint of the voxel identified byi
, where i is determined by the order s < t < r.org.jogamp.vecmath.Point3f
getVoxelMidPoint(int idx)
Returns the grid coordinate at the absolute indexidx
org.jogamp.vecmath.Point3f
getVoxelMidPoint(int[] voxel)
Returns the geometric midpoint ofvoxel
org.jogamp.vecmath.Point3f
getVoxelMidPoint(int i, int j, int k)
Returns the geometric midpoint of the grid coordinate i, j, kint
getY(int y)
void
handleXMLElementStart(java.lang.String localName, org.xml.sax.Attributes attributes, XMLObject.XMLType type)
Handles the start of an XML element.void
setBounds(Box3D bounds)
void
setDims(int[] dims)
void
setFromGrid(Grid3D grid)
protected void
writeCoords(int tab, java.io.Writer writer, XMLOutputOptions options, ProgressUpdater progress_bar)
Writes this shape's coordinates, according the parameters inoptions
void
writeXML(int tab, java.io.Writer writer, XMLOutputOptions options, ProgressUpdater progress_bar)
Writes the XML representation of this object to file.Methods inherited from class mgui.geometry.Box3D
contains, getBasePt, getBasisTransform, getCenter, getCoords, getEdges, getMaxPt, getMinPt, getNonzeroAxes, getOppPt, getRAxis, getRDim, getSAxis, getSDim, getSide, getTAxis, getTDim, getVertices, setBasePt, setCoords, setFromBasisTransform, setFromBox, setRAxis, setRDim, setSAxis, setSDim, setTAxis, setTDim, setVertices, toString
Methods inherited from class mgui.geometry.Shape3D
getBoundBox, getDTD, getProximity, getProximityPoint, getShortXML, getXML, getXML, getXMLSchema, handleXMLElementEnd, handleXMLString, loadAsciiCoords, loadBinaryCoords, loadCoords, loadXMLCoord, setVertices, transform, transform, writeAsciiCoords, writeBinaryCoords, writeXML, writeXML
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Field Details
-
s_size
protected int s_size -
t_size
protected int t_size -
r_size
protected int r_size -
v_size
protected int v_size
-
-
Constructor Details
-
Grid3D
public Grid3D() -
Grid3D
-
Grid3D
-
Grid3D
-
-
Method Details
-
getDims
public int[] getDims()Returns the S, T, R, V dimensions, as an int array- Returns:
-
setDims
public void setDims(int[] dims) -
getVertex
public org.jogamp.vecmath.Point3f getVertex(int index)Returns the midpoint of the voxel identified byi
, where i is determined by the order s < t < r. I.e., -
getAbsoluteIndex
public int getAbsoluteIndex(int[] voxel)Returns the absolute index of the voxel specified by the integer array[s,t,r]
. Calculated as:r * s_size * t_size + t * s_size + s
.- Parameters:
voxel
-- Returns:
-
getNeighbours
public int[] getNeighbours(int idx)Returns the immediate neighbours of the voxel atidx
. Diagonal neighbours are not returned.- Parameters:
idx
-- Returns:
-
getIndexAsVoxel
public int[] getIndexAsVoxel(int index)Returns a voxel as an integer array of the form {s, t, r}, from the absolute indexindex
.A voxel {s, t, r} is determined by:
r = ceil(index / (s_size * t_size))
residual = index - (r - 1) * (s_size * t_size)
t = ceil(residual / (s_size))
s = residual - (t - 1) * (s_size)- Parameters:
index
- The absolute index of the voxel- Returns:
- the voxel as an integer array
-
getSizeS
public int getSizeS()Returns the data dimensions in the x (S) dimension- Returns:
-
getSizeT
public int getSizeT()Returns the data dimensions in the y (T) dimension- Returns:
-
getSizeR
public int getSizeR()Returns the data dimensions in the z (R) dimension- Returns:
-
getSizeV
public int getSizeV() -
getGeomS
public float getGeomS()Returns the geometric dimension in the S-axis. Note that this is not equivalent to the bounds dimension, but the displacement from the center-points of the voxels; i.e., the bounds dimension minus a voxel.- Returns:
-
getGeomT
public float getGeomT()Returns the geometric dimension in the T-axis. Note that this is not equivalent to the bounds dimension, but the displacement from the center-points of the voxels; i.e., the bounds dimension minus a voxel.- Returns:
-
getGeomR
public float getGeomR()Returns the geometric dimension in the R-axis. Note that this is not equivalent to the bounds dimension, but the displacement from the center-points of the voxels; i.e., the bounds dimension minus a voxel.- Returns:
-
getGeomDims
public float[] getGeomDims()Returns the geometric dimensions of this grid. Note that this is not equivalent to the bounds dimensions, but the displacement from the center-points of the voxels; i.e., the bounds dimensions minus a voxel.- Returns:
-
getSize
public int getSize()Returns the total number of data elements in this grid. -
getOrigin
public org.jogamp.vecmath.Point3f getOrigin()Returns the origin of this grid. Note that this is not equivalent to the base point of its bounds, but rather the center point of the origin voxel; i.e., the base point plus half a voxel.- Returns:
-
setFromGrid
-
clone
public java.lang.Object clone() -
getY
public int getY(int y) -
setBounds
-
getGridCoordinate
public org.jogamp.vecmath.Point3f getGridCoordinate(org.jogamp.vecmath.Point3f p)Determines the grid coordinate of pointp
, expressed in world coordinates.- Parameters:
p
-- Returns:
-
getScaledBasisTransform
public org.jogamp.vecmath.Matrix4f getScaledBasisTransform()Returns a matrix which will transform a vector expressed in world (model) coordinates to one expressed with respect to this box's coordinate space. Note that basis vectors must be orthonormal for this to return a valid coordinate. This function also applies a scale to the transformation, defined as the voxel size; thus scale_r = geom_r / size_r.- Returns:
-
getEnclosingVoxel
public int[] getEnclosingVoxel(org.jogamp.vecmath.Point3f p)Determines the voxel which encloses pointp
. Returns an array containing the coordinates of the voxel (i, j, k), ornull
ifp
is not contained by this volume.- Parameters:
p
-- Returns:
-
getVoxelMidPoint
public org.jogamp.vecmath.Point3f getVoxelMidPoint(int[] voxel)Returns the geometric midpoint ofvoxel
- Parameters:
i
-j
-k
-- Returns:
-
getVoxelMidPoint
public org.jogamp.vecmath.Point3f getVoxelMidPoint(int i, int j, int k)Returns the geometric midpoint of the grid coordinate i, j, k- Parameters:
i
-j
-k
-- Returns:
-
getVoxelMidPoint
public org.jogamp.vecmath.Point3f getVoxelMidPoint(int idx)Returns the grid coordinate at the absolute indexidx
- Parameters:
idx
-- Returns:
-
getGridBasisTransform
public org.jogamp.vecmath.Matrix4f getGridBasisTransform()Finds transform using the origin (center point of first voxel), rather than the base point.- Returns:
-
getSubGrid
public int[] getSubGrid(org.jogamp.vecmath.Point3f p1, org.jogamp.vecmath.Point3f p2)Returns two points (min coords, max coords) which represent a subset of this grid which is bounded by the geometric box specified by p1 and p2 (i.e., a voxel must be contained within the box, or must enclose its boundary). Adds 1 to the max indices, such that the includes indices are < max.- Parameters:
p1
- min pointp2
- max point- Returns:
-
getMinVoxelMidPt
public org.jogamp.vecmath.Point3f getMinVoxelMidPt() -
getMaxVoxelMidPt
public org.jogamp.vecmath.Point3f getMaxVoxelMidPt() -
getAbsoluteIndex
public int getAbsoluteIndex(int i, int j, int k)Returns absolute index of this coordinate, which is given by: k * xSize * ySize + j * xSize + i (x changes fastest)- Parameters:
i
-j
-k
-- Returns:
-
handleXMLElementStart
public void handleXMLElementStart(java.lang.String localName, org.xml.sax.Attributes attributes, XMLObject.XMLType type) throws org.xml.sax.SAXExceptionDescription copied from interface:XMLObject
Handles the start of an XML element.- Specified by:
handleXMLElementStart
in interfaceXMLObject
- Overrides:
handleXMLElementStart
in classShape3D
- Parameters:
localName
- Local name of the elementattributes
- Set of element attributestype
- TheXMLType
of this element- Throws:
org.xml.sax.SAXException
-
writeXML
public void writeXML(int tab, java.io.Writer writer, XMLOutputOptions options, ProgressUpdater progress_bar) throws java.io.IOExceptionDescription copied from interface:XMLObject
Writes the XML representation of this object to file. The basic contract for this method is that it should not write a newline character at its start or end. The default format ofXMLFormat.Ascii
will be used.- Specified by:
writeXML
in interfaceXMLObject
- Overrides:
writeXML
in classShape3D
- Parameters:
tab
- The number of tabs to place before the XML textwriter
- The writeroptions
- XMLOutputOptions defining the write parametersprogress_bar
- Optional progress updater (may benull
)- Throws:
java.io.IOException
-
writeCoords
protected void writeCoords(int tab, java.io.Writer writer, XMLOutputOptions options, ProgressUpdater progress_bar) throws java.io.IOExceptionDescription copied from class:Shape3D
Writes this shape's coordinates, according the parameters inoptions
- Overrides:
writeCoords
in classShape3D
- Throws:
java.io.IOException
-
getLocalName
public java.lang.String getLocalName()Description copied from interface:XMLObject
Returns the local name associated with this XML object.- Specified by:
getLocalName
in interfaceXMLObject
- Overrides:
getLocalName
in classBox3D
- Returns:
-