Package mgui.geometry

Class Grid3D

java.lang.Object
All Implemented Interfaces:
java.lang.Cloneable, Shape, XMLObject

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
  • 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

      public Grid3D​(Grid3D grid)
    • Grid3D

      public Grid3D​(int s_size, int t_size, int r_size, Box3D box)
    • Grid3D

      public Grid3D​(int s_size, int t_size, int r_size, int v_size, Box3D box)
  • 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 by i, where i is determined by the order s < t < r. I.e.,
      Overrides:
      getVertex in class Box3D
      Parameters:
      index - The absolute index of the voxel
      Returns:
    • 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 at idx. 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 index index.

      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.
      Specified by:
      getSize in interface Shape
      Overrides:
      getSize in class Shape3D
      Returns:
    • 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

      public void setFromGrid​(Grid3D grid)
    • clone

      public java.lang.Object clone()
      Overrides:
      clone in class Box3D
    • getY

      public int getY​(int y)
    • setBounds

      public void setBounds​(Box3D bounds)
    • getGridCoordinate

      public org.jogamp.vecmath.Point3f getGridCoordinate​(org.jogamp.vecmath.Point3f p)
      Determines the grid coordinate of point p, 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 point p. Returns an array containing the coordinates of the voxel (i, j, k), or null if p is not contained by this volume.
      Parameters:
      p -
      Returns:
    • getVoxelMidPoint

      public org.jogamp.vecmath.Point3f getVoxelMidPoint​(int[] voxel)
      Returns the geometric midpoint of voxel
      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 index idx
      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 point
      p2 - 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.SAXException
      Description copied from interface: XMLObject
      Handles the start of an XML element.
      Specified by:
      handleXMLElementStart in interface XMLObject
      Overrides:
      handleXMLElementStart in class Shape3D
      Parameters:
      localName - Local name of the element
      attributes - Set of element attributes
      type - The XMLType 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.IOException
      Description 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 of XMLFormat.Ascii will be used.
      Specified by:
      writeXML in interface XMLObject
      Overrides:
      writeXML in class Shape3D
      Parameters:
      tab - The number of tabs to place before the XML text
      writer - The writer
      options - XMLOutputOptions defining the write parameters
      progress_bar - Optional progress updater (may be null)
      Throws:
      java.io.IOException
    • writeCoords

      protected void writeCoords​(int tab, java.io.Writer writer, XMLOutputOptions options, ProgressUpdater progress_bar) throws java.io.IOException
      Description copied from class: Shape3D
      Writes this shape's coordinates, according the parameters in options
      Overrides:
      writeCoords in class Shape3D
      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 interface XMLObject
      Overrides:
      getLocalName in class Box3D
      Returns: