Class ModelTriangleMesh
- java.lang.Object
-
- javax.media.j3d.SceneGraphObject
-
- javax.media.j3d.NodeComponent
-
- javax.media.j3d.Geometry
-
- javax.media.j3d.GeometryArray
-
- javax.media.j3d.IndexedGeometryArray
-
- javax.media.j3d.IndexedTriangleArray
-
- gov.nih.mipav.view.renderer.J3D.model.structures.ModelTriangleMesh
-
public class ModelTriangleMesh extends javax.media.j3d.IndexedTriangleArray
A simple triangle mesh that represents a level surface. The mesh only stores vertex positions and vertex normals. The surface viewer creates a Shape3D object whose geometry is an object from ModelTriangleMesh. The surface color is provided by attaching to the Shape3D object an appearance that contains a material. The vertex normals in ModelTriangleMesh are used by the lighting system in conjunction with the surface material to produce the surface color.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
ModelTriangleMesh.Edge
A representation of an edge for the vertex-edge-triangle table.class
ModelTriangleMesh.UnorderedSetInt
DOCUMENT ME!
-
Field Summary
Fields Modifier and Type Field Description private static float[]
box
DOCUMENT ME!protected double[][]
cellData
support for vtkprivate java.util.HashSet[]
connections
used in smoothing.private static int[]
direction
DOCUMENT ME!(package private) java.lang.Integer
kInvalid
DOCUMENT ME!(package private) float[]
m_afCurvature
DOCUMENT ME!(package private) ModelTriangleMesh.UnorderedSetInt[]
m_akAdjacent
DOCUMENT ME!(package private) javax.vecmath.Vector3f[]
m_akSNormal
DOCUMENT ME!(package private) javax.vecmath.Vector3f[]
m_akSTangent
DOCUMENT ME!(package private) javax.vecmath.Vector3f[]
m_akVMean
DOCUMENT ME!(package private) javax.vecmath.Vector3f[]
m_akVNormal
DOCUMENT ME!(package private) float
m_fEParam
DOCUMENT ME!(package private) float
m_fFParam
DOCUMENT ME!(package private) float
m_fMeanEdgeLength
DOCUMENT ME!(package private) float
m_fStiffness
DOCUMENT ME!private float
m_fTransparency
store the mesh transparency:private javax.vecmath.Color4f[]
m_kColors
Store the mesh colors:private javax.vecmath.Vector3f
m_kE0
DOCUMENT ME!private javax.vecmath.Vector3f
m_kE1
DOCUMENT ME!(package private) java.util.HashMap
m_kEMap
DOCUMENT ME!private java.lang.Object
m_kGenerator
The ModelClodMesh object that generated the ModelTriangleMesh object, null otherwise.private javax.media.j3d.Material
m_kMaterial
store the Material properties of the mesh:private javax.vecmath.Vector3f
m_kN
DOCUMENT ME!private javax.vecmath.Point3f
m_kV0
temporary variables to avoid 'new' calls.private javax.vecmath.Point3f
m_kV1
temporary variables to avoid 'new' calls.private javax.vecmath.Point3f
m_kV2
temporary variables to avoid 'new' calls.private javax.vecmath.Point3f
m_kV3
temporary variables to avoid 'new' calls.private javax.vecmath.Color4f[]
perVertexColor
Per vertex color array, which store the color data saved in .sur file.private static float[]
startLocation
DOCUMENT ME!protected double[][]
vertexData
support for vtk-
Fields inherited from class javax.media.j3d.IndexedGeometryArray
ALLOW_COLOR_INDEX_READ, ALLOW_COLOR_INDEX_WRITE, ALLOW_COORDINATE_INDEX_READ, ALLOW_COORDINATE_INDEX_WRITE, ALLOW_NORMAL_INDEX_READ, ALLOW_NORMAL_INDEX_WRITE, ALLOW_TEXCOORD_INDEX_READ, ALLOW_TEXCOORD_INDEX_WRITE, ALLOW_VERTEX_ATTR_INDEX_READ, ALLOW_VERTEX_ATTR_INDEX_WRITE
-
Fields inherited from class javax.media.j3d.GeometryArray
ALLOW_COLOR_READ, ALLOW_COLOR_WRITE, ALLOW_COORDINATE_READ, ALLOW_COORDINATE_WRITE, ALLOW_COUNT_READ, ALLOW_COUNT_WRITE, ALLOW_FORMAT_READ, ALLOW_NORMAL_READ, ALLOW_NORMAL_WRITE, ALLOW_REF_DATA_READ, ALLOW_REF_DATA_WRITE, ALLOW_TEXCOORD_READ, ALLOW_TEXCOORD_WRITE, ALLOW_VERTEX_ATTR_READ, ALLOW_VERTEX_ATTR_WRITE, BY_REFERENCE, BY_REFERENCE_INDICES, COLOR_3, COLOR_4, COORDINATES, INTERLEAVED, NORMALS, TEXTURE_COORDINATE_2, TEXTURE_COORDINATE_3, TEXTURE_COORDINATE_4, USE_COORD_INDEX_ONLY, USE_NIO_BUFFER, VERTEX_ATTRIBUTES
-
-
Constructor Summary
Constructors Constructor Description ModelTriangleMesh(ModelTriangleMesh kMesh)
Copies a ModelTriangleMesh by copying it's components.ModelTriangleMesh(javax.vecmath.Point3f[] akVertex, int[] aiConnect)
A triangle mesh whose vertex normal vectors are computed from the geometry of the mesh itself.ModelTriangleMesh(javax.vecmath.Point3f[] akVertex, javax.vecmath.Vector3f[] akNormal, int[] aiConnect)
A triangle mesh whose vertex normal vectors have been precomputed.ModelTriangleMesh(javax.vecmath.Point3f[] akVertex, javax.vecmath.Vector3f[] akNormal, int[] aiConnect, javax.vecmath.Color4f[] vertexColor)
A triangle mesh whose vertex normal vectors have been precomputed.ModelTriangleMesh(javax.vecmath.Point3f[] akVertex, javax.vecmath.Vector3f[] akNormal, javax.vecmath.Color4f[] akColor, int[] aiConnect)
A triangle mesh whose vertex normal vectors have been precomputed.ModelTriangleMesh(javax.vecmath.Point3f[] akVertex, javax.vecmath.Vector3f[] akNormal, javax.vecmath.Color4f[] akColor, javax.vecmath.TexCoord3f[] akTexCoord, int[] aiConnect)
A triangle mesh whose vertex normal vectors have been precomputed.ModelTriangleMesh(javax.vecmath.Point3f[] akVertex, javax.vecmath.Vector3f[] akNormal, javax.vecmath.TexCoord3f[] akTexCoord, int[] aiConnect)
A triangle mesh whose vertex normal vectors have been precomputed.ModelTriangleMesh(WildMagic.LibFoundation.Mathematics.Vector3f[] akVertex, int[] aiConnect)
A triangle mesh whose vertex normal vectors are computed from the geometry of the mesh itself.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
affineTransform(double[][] aafH)
The input 4x4 homogeneous matrix H is assumed to multiply vectors V as H*V where V = (x,y,z,1).void
affineTransform(float[][] afRot, float[] afTrn, float[] afScale)
Rotation R is 3x3, translation T is 3x1, and scale S is 3x1.float
area()
Calculate the surface mesh area.private void
buildConnections()
Builds a list of cross-references, so that connections[i] contains all the verticies that are connected to vertex at i.javax.vecmath.Point3f
center()
Calculates and returns the center point of the Mesh:private void
computeMeanEdgeLength()
Compute the average length of all the edges in the triangle mesh.void
computeNormals()
A normal vector at a vertex is computed by averaging the triangle normals for all triangles sharing the vertex.private void
computeVertexInformation()
Let V[i] be a vertex in the triangle mesh.private void
computeVertexNormals()
Compute the vertex normals of the triangle mesh.double[][]
getCellData()
javax.vecmath.Color4f[]
getColorCopy()
Make a copy of the colors of a triangle mesh.void
getColorLocal(int index, javax.vecmath.Color4f kColor)
Gets the stored local color.ModelTriangleMesh[]
getComponents()
Construct the connected components of the triangle mesh.void
getConsistentComponents()
Construct the connected components of the triangle mesh.void
getCopies(javax.vecmath.Point3f[] akVertex, javax.vecmath.Vector3f[] akNormal, javax.vecmath.Color4f[] akColor, javax.vecmath.TexCoord3f[] akTexCoord)
Copies the components of a ModelTriangleMesh into the parameters.static int[]
getDirection()
DOCUMENT ME!java.lang.Object
getGenerator()
Support for regenerating an ModelTriangleMesh from an ModelClodMesh whenever the level of detail is changed for the ModelClodMesh.int[]
getIndexCopy()
Make a copy of the connectivity array of a triangle mesh.javax.media.j3d.Material
getMaterial()
Gets the material properties of the mesh:javax.vecmath.Vector3f[]
getNormalCopy()
Make a copy of the normals of a triangle mesh.javax.vecmath.Color4f[]
getPerVertexColor()
static float[]
getStartLocation()
DOCUMENT ME!javax.vecmath.TexCoord3f[]
getTexCoordCopy()
Make a copy of the texture coordinates of a triangle mesh.float
getTransparency()
Gets the mesh transparency.javax.vecmath.Point3f[]
getVertexCopy()
Make a copy of the vertices of a triangle mesh.WildMagic.LibFoundation.Mathematics.Vector3f[]
getVertexCopyAsVector3f()
Make a copy of the vertices of a triangle mesh.double[][]
getVertexData()
double[]
getVertexData(int i)
private void
init()
Initializes capabilities and temporary variables.void
invertMesh()
Invert the mesh z-coord, reorder the triangles, and recompute the normals:static ModelTriangleMesh
loadTMesh(java.io.RandomAccessFile kIn, ViewJProgressBar progress, int added, int total, boolean isVisible)
Load the triangle mesh from a binary file.static ModelTriangleMesh
loadTMesh(java.io.RandomAccessFile kIn, javax.swing.JProgressBar pBar, int added, int total)
Load the triangle mesh from a binary file.static ModelTriangleMesh
loadVRMLMesh(java.io.RandomAccessFile kIn, ViewJProgressBar progress, int added, int total, boolean flag)
Load the triangle mesh from a VRML file specifically written by MIPAV!.static ModelTriangleMesh
loadVTKLegacyMesh(java.io.RandomAccessFile kIn, ViewJProgressBar progress, int added, int total, boolean flag, java.lang.String fileName)
static ModelTriangleMesh
loadVTKXMLMesh(java.lang.String absPath, ViewJProgressBar progress, int added, int total, boolean flag, java.lang.String fileName, java.lang.String dir)
static int
parseVRMLMesh(java.io.RandomAccessFile kIn)
Parses the VRML to see how many surfaces there are.protected void
print(java.io.PrintWriter kOut)
Internal support for 'void print (String)' and 'void print (String, ModelTriangleMesh[])'.protected void
printSMFAscii(java.io.PrintWriter kOut)
protected void
printSTLAscii(java.io.PrintWriter kOut)
Print the STL file format in ASCII.protected void
printSTLBinary(java.io.RandomAccessFile kOut)
Print the STL file format in binary ( little endian ).protected void
save(java.io.RandomAccessFile kOut, boolean flip, int[] direction, float[] startLocation, float[] box, TransMatrix inverseDicomMatrix, javax.vecmath.Color4f[] perVertexColorArray)
Internal support for 'void save (String)' and 'void save (String, ModelTriangleMesh[])'.void
save(java.lang.String kName, boolean flip, int[] direction, float[] startLocation, float[] box, TransMatrix inverseDicomMatrix)
Save the triangle mesh to a binary file.static void
save(java.lang.String kName, ModelTriangleMesh[] akComponent, boolean flip, int[] direction, float[] startLocation, float[] box, TransMatrix inverseDicomMatrix, javax.vecmath.Color4f[][] perVertexColorArray)
Save an array of triangle meshes to a binary file.void
saveAsPlyFile(java.lang.String kName)
protected void
saveAsPortableVRML(java.io.PrintWriter kOut, boolean flip, int[] direction, float[] startLocation, float[] box, javax.vecmath.Color3f color)
Saves the triangle mesh in VRML97 (VRML 2.0) format.void
saveAsPortableVRML(java.io.PrintWriter kOut, boolean flip, int numberOfShapes, int[] direction, float[] startLocation, float[] box, javax.vecmath.Color3f color)
Saves the triangle mesh in VRML97 (VRML 2.0) format (text format).static void
saveAsPortableVRML(java.io.PrintWriter kOut, ModelTriangleMesh[] akComponent, boolean flip, int[] direction, float[] startLocation, float[] box, javax.vecmath.Color3f color)
Saves the triangle mesh in VRML97 (VRML 2.0) format (text format).void
saveAsSMFAsciiFile(java.lang.String kName)
Sate the SMF ACII file format.void
saveAsSTLAsciiFile(java.lang.String kName)
Sate the STIL ACII file format.void
saveAsSTLBinaryFile(java.lang.String kName)
Sate the STIL Binary file format.void
saveAsTextFile(java.lang.String kName)
Save the triangle mesh to a text file.static void
saveAsTextFile(java.lang.String kName, ModelTriangleMesh[] akComponent)
Save an array of triangle meshes to a text file.protected void
saveAsVRML(java.io.PrintWriter kOut, boolean flip, int[] direction, float[] startLocation, float[] box, javax.vecmath.Color3f color)
Saves the triangle mesh in VRML97 (VRML 2.0) format.void
saveAsVRML(java.lang.String kName, boolean flip, int numberOfShapes, int[] direction, float[] startLocation, float[] box, javax.vecmath.Color3f color)
Saves the triangle mesh in VRML97 (VRML 2.0) format (text format).static void
saveAsVRML(java.lang.String kName, ModelTriangleMesh[] akComponent, boolean flip, int[] direction, float[] startLocation, float[] box, javax.vecmath.Color3f color)
Saves the triangle mesh in VRML97 (VRML 2.0) format (text format).void
saveAsVTKLegacy(java.lang.String kName)
Saves the triangle mesh to VTK Legacy formatvoid
saveAsVTKXML(java.lang.String fileName)
saves thr triangle mesh to VTK XML formatprotected void
saveAsXML(java.lang.String fileName, int[] direction, float[] startLocation, float[] box)
Internal support for 'void save (String)' and 'void save (String, ModelTriangleMesh[])'.void
saveXMLHeader(java.lang.String kName)
void
setCellData(double[][] cellData)
void
setColor(int index, javax.vecmath.Color4f kColor)
Sets the color and stores the color update information in a local copy.void
setColorDelay(int index, javax.vecmath.Color4f kColor)
Used for fast color update while painting the triangle mesh, stores the color update information for later loading into the surface.void
setColorUpdate()
Used for fast color update while painting.void
setGenerator(java.lang.Object kGenerator)
Support for regenerating an ModelTriangleMesh from an ModelClodMesh whenever the level of detail is changed for the ModelClodMesh.void
setMaterial(javax.media.j3d.Material kMaterial)
Sets the material properties of the mesh.void
setTransparency(float transparency)
Sets the mesh transparency.void
setVertexData(double[][] data)
void
setVertexData(int i, double val)
void
setVertexData(int i, double[] array)
void
setVertexData(int i, int j, double val)
void
setVerticies(javax.vecmath.Point3f[] akVertex)
Replace the verticies with a new set.void
smoothMesh(int iteration, float alpha, boolean volumeLimit, float volumePercent, boolean pVisible)
Smooth mesh.void
smoothThree(int iteration, float lambda, float mu, boolean pVisible)
Smooth mesh.void
smoothTwo(int iterations, float m_fStiffness, boolean volumeLimit, float volumePercent, boolean pVisible)
Derived from the first 2 of the 3 components of AlgorithmBrainExtraction Note that m_fStiffness does not increase and then decrease as in AlgorithmBrainExtraction but instead remains constant.private float
update2(int i)
Compute the coefficient of the surface normal for the update of the mesh vertex V[i] in the SNormal[i] direction.private void
updateMesh()
The heart of the segmentation.float
volume()
Calculates volume of triangle mesh.-
Methods inherited from class javax.media.j3d.IndexedGeometryArray
getColorIndex, getColorIndices, getCoordinateIndex, getCoordinateIndices, getCoordIndicesRef, getIndexCount, getInitialIndexIndex, getNormalIndex, getNormalIndices, getTextureCoordinateIndex, getTextureCoordinateIndex, getTextureCoordinateIndices, getTextureCoordinateIndices, getValidIndexCount, getVertexAttrIndex, getVertexAttrIndices, setColorIndex, setColorIndices, setCoordinateIndex, setCoordinateIndices, setCoordIndicesRef, setInitialColorIndex, setInitialCoordIndex, setInitialIndexIndex, setInitialNormalIndex, setInitialTexCoordIndex, setInitialVertexAttrIndex, setInitialVertexIndex, setNormalIndex, setNormalIndices, setTextureCoordinateIndex, setTextureCoordinateIndex, setTextureCoordinateIndices, setTextureCoordinateIndices, setValidIndexCount, setValidVertexCount, setVertexAttrIndex, setVertexAttrIndices
-
Methods inherited from class javax.media.j3d.GeometryArray
getColor, getColor, getColor, getColor, getColor, getColor, getColorRef3b, getColorRef3f, getColorRef4b, getColorRef4f, getColorRefBuffer, getColorRefByte, getColorRefFloat, getColors, getColors, getColors, getColors, getColors, getColors, getCoordinate, getCoordinate, getCoordinate, getCoordinate, getCoordinates, getCoordinates, getCoordinates, getCoordinates, getCoordRef3d, getCoordRef3f, getCoordRefBuffer, getCoordRefDouble, getCoordRefFloat, getInitialColorIndex, getInitialCoordIndex, getInitialNormalIndex, getInitialTexCoordIndex, getInitialVertexAttrIndex, getInitialVertexIndex, getInterleavedVertexBuffer, getInterleavedVertices, getNormal, getNormal, getNormalRef3f, getNormalRefBuffer, getNormalRefFloat, getNormals, getNormals, getTexCoordRef2f, getTexCoordRef3f, getTexCoordRefBuffer, getTexCoordRefFloat, getTexCoordSetCount, getTexCoordSetMap, getTexCoordSetMapLength, getTextureCoordinate, getTextureCoordinate, getTextureCoordinate, getTextureCoordinate, getTextureCoordinate, getTextureCoordinate, getTextureCoordinate, getTextureCoordinates, getTextureCoordinates, getTextureCoordinates, getTextureCoordinates, getTextureCoordinates, getTextureCoordinates, getTextureCoordinates, getValidVertexCount, getVertexAttr, getVertexAttr, getVertexAttr, getVertexAttr, getVertexAttrCount, getVertexAttrRefBuffer, getVertexAttrRefFloat, getVertexAttrs, getVertexAttrs, getVertexAttrs, getVertexAttrs, getVertexAttrSizes, getVertexCount, getVertexFormat, setColor, setColor, setColor, setColor, setColor, setColorRef3b, setColorRef3f, setColorRef4b, setColorRef4f, setColorRefBuffer, setColorRefByte, setColorRefFloat, setColors, setColors, setColors, setColors, setColors, setColors, setColors, setColors, setColors, setColors, setColors, setColors, setCoordinate, setCoordinate, setCoordinate, setCoordinate, setCoordinates, setCoordinates, setCoordinates, setCoordinates, setCoordinates, setCoordinates, setCoordinates, setCoordinates, setCoordRef3d, setCoordRef3f, setCoordRefBuffer, setCoordRefDouble, setCoordRefFloat, setInterleavedVertexBuffer, setInterleavedVertices, setNormal, setNormal, setNormalRef3f, setNormalRefBuffer, setNormalRefFloat, setNormals, setNormals, setNormals, setNormals, setTexCoordRef2f, setTexCoordRef3f, setTexCoordRefBuffer, setTexCoordRefFloat, setTextureCoordinate, setTextureCoordinate, setTextureCoordinate, setTextureCoordinate, setTextureCoordinate, setTextureCoordinate, setTextureCoordinate, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setTextureCoordinates, setVertexAttr, setVertexAttr, setVertexAttr, setVertexAttr, setVertexAttrRefBuffer, setVertexAttrRefFloat, setVertexAttrs, setVertexAttrs, setVertexAttrs, setVertexAttrs, setVertexAttrs, setVertexAttrs, setVertexAttrs, setVertexAttrs, updateData
-
Methods inherited from class javax.media.j3d.NodeComponent
cloneNodeComponent, duplicateNodeComponent, duplicateNodeComponent, getDuplicateOnCloneTree, setDuplicateOnCloneTree
-
Methods inherited from class javax.media.j3d.SceneGraphObject
clearCapability, clearCapabilityIsFrequent, duplicateSceneGraphObject, getCapability, getCapabilityIsFrequent, getName, getUserData, isCompiled, isLive, setCapability, setCapabilityIsFrequent, setName, setUserData, toString, updateNodeReferences
-
-
-
-
Field Detail
-
direction
private static int[] direction
DOCUMENT ME!
-
startLocation
private static float[] startLocation
DOCUMENT ME!
-
box
private static float[] box
DOCUMENT ME!
-
kInvalid
java.lang.Integer kInvalid
DOCUMENT ME!
-
m_afCurvature
float[] m_afCurvature
DOCUMENT ME!
-
m_akAdjacent
ModelTriangleMesh.UnorderedSetInt[] m_akAdjacent
DOCUMENT ME!
-
m_akSNormal
javax.vecmath.Vector3f[] m_akSNormal
DOCUMENT ME!
-
m_akSTangent
javax.vecmath.Vector3f[] m_akSTangent
DOCUMENT ME!
-
m_akVMean
javax.vecmath.Vector3f[] m_akVMean
DOCUMENT ME!
-
m_akVNormal
javax.vecmath.Vector3f[] m_akVNormal
DOCUMENT ME!
-
m_fEParam
float m_fEParam
DOCUMENT ME!
-
m_fFParam
float m_fFParam
DOCUMENT ME!
-
m_fMeanEdgeLength
float m_fMeanEdgeLength
DOCUMENT ME!
-
m_fStiffness
float m_fStiffness
DOCUMENT ME!
-
m_kEMap
java.util.HashMap m_kEMap
DOCUMENT ME!
-
connections
private java.util.HashSet[] connections
used in smoothing.
-
m_kE0
private javax.vecmath.Vector3f m_kE0
DOCUMENT ME!
-
m_kE1
private javax.vecmath.Vector3f m_kE1
DOCUMENT ME!
-
m_kN
private javax.vecmath.Vector3f m_kN
DOCUMENT ME!
-
m_kGenerator
private java.lang.Object m_kGenerator
The ModelClodMesh object that generated the ModelTriangleMesh object, null otherwise.
-
m_kV0
private javax.vecmath.Point3f m_kV0
temporary variables to avoid 'new' calls.
-
m_kV1
private javax.vecmath.Point3f m_kV1
temporary variables to avoid 'new' calls.
-
m_kV2
private javax.vecmath.Point3f m_kV2
temporary variables to avoid 'new' calls.
-
m_kV3
private javax.vecmath.Point3f m_kV3
temporary variables to avoid 'new' calls.
-
m_kMaterial
private javax.media.j3d.Material m_kMaterial
store the Material properties of the mesh:
-
m_fTransparency
private float m_fTransparency
store the mesh transparency:
-
m_kColors
private javax.vecmath.Color4f[] m_kColors
Store the mesh colors:
-
perVertexColor
private javax.vecmath.Color4f[] perVertexColor
Per vertex color array, which store the color data saved in .sur file.
-
vertexData
protected double[][] vertexData
support for vtk
-
cellData
protected double[][] cellData
support for vtk
-
-
Constructor Detail
-
ModelTriangleMesh
public ModelTriangleMesh(javax.vecmath.Point3f[] akVertex, int[] aiConnect)
A triangle mesh whose vertex normal vectors are computed from the geometry of the mesh itself. The normal at a vertex is the normalized average of normals of the triangles that share the vertex.- Parameters:
akVertex
- array of vertices in the meshaiConnect
- Connectivity array for the triangles. Each triple of indices represents one triangle. The triangle is counterclockwise ordered as viewed by an observer outside the mesh.
-
ModelTriangleMesh
public ModelTriangleMesh(javax.vecmath.Point3f[] akVertex, javax.vecmath.Vector3f[] akNormal, int[] aiConnect)
A triangle mesh whose vertex normal vectors have been precomputed.- Parameters:
akVertex
- array of vertices in the meshakNormal
- array of vertex normals for the meshaiConnect
- Connectivity array for the triangles. Each triple of indices represents one triangle. The triangle is counterclockwise ordered as viewed by an observer outside the mesh.
-
ModelTriangleMesh
public ModelTriangleMesh(javax.vecmath.Point3f[] akVertex, javax.vecmath.Vector3f[] akNormal, int[] aiConnect, javax.vecmath.Color4f[] vertexColor)
A triangle mesh whose vertex normal vectors have been precomputed.- Parameters:
akVertex
- array of vertices in the meshakNormal
- array of vertex normals for the meshaiConnect
- Connectivity array for the triangles. Each triple of indices represents one triangle. The triangle is counterclockwise ordered as viewed by an observer outside the mesh.
-
ModelTriangleMesh
public ModelTriangleMesh(javax.vecmath.Point3f[] akVertex, javax.vecmath.Vector3f[] akNormal, javax.vecmath.Color4f[] akColor, int[] aiConnect)
A triangle mesh whose vertex normal vectors have been precomputed.- Parameters:
akVertex
- array of vertices in the meshakNormal
- array of vertex normals for the meshakColor
- array of vertex colorsaiConnect
- Connectivity array for the triangles. Each triple of indices represents one triangle. The triangle is counterclockwise ordered as viewed by an observer outside the mesh.
-
ModelTriangleMesh
public ModelTriangleMesh(javax.vecmath.Point3f[] akVertex, javax.vecmath.Vector3f[] akNormal, javax.vecmath.TexCoord3f[] akTexCoord, int[] aiConnect)
A triangle mesh whose vertex normal vectors have been precomputed.- Parameters:
akVertex
- array of vertices in the meshakNormal
- array of vertex normals for the meshakColor
- array of vertex colorsakTexCoord
- array of Texture CoordinatesaiConnect
- Connectivity array for the triangles. Each triple of indices represents one triangle. The triangle is counterclockwise ordered as viewed by an observer outside the mesh.
-
ModelTriangleMesh
public ModelTriangleMesh(javax.vecmath.Point3f[] akVertex, javax.vecmath.Vector3f[] akNormal, javax.vecmath.Color4f[] akColor, javax.vecmath.TexCoord3f[] akTexCoord, int[] aiConnect)
A triangle mesh whose vertex normal vectors have been precomputed.- Parameters:
akVertex
- array of vertices in the meshakNormal
- array of vertex normals for the meshakColor
- array of vertex colorsakTexCoord
- array of Texture CoordinatesaiConnect
- Connectivity array for the triangles. Each triple of indices represents one triangle. The triangle is counterclockwise ordered as viewed by an observer outside the mesh.
-
ModelTriangleMesh
public ModelTriangleMesh(ModelTriangleMesh kMesh)
Copies a ModelTriangleMesh by copying it's components.- Parameters:
ModelTriangleMesh
- ModelTriangleMesh to copy
-
ModelTriangleMesh
public ModelTriangleMesh(WildMagic.LibFoundation.Mathematics.Vector3f[] akVertex, int[] aiConnect)
A triangle mesh whose vertex normal vectors are computed from the geometry of the mesh itself. The normal at a vertex is the normalized average of normals of the triangles that share the vertex.- Parameters:
akVertex
- array of vertices in the meshaiConnect
- Connectivity array for the triangles. Each triple of indices represents one triangle. The triangle is counterclockwise ordered as viewed by an observer outside the mesh.
-
-
Method Detail
-
init
private void init()
Initializes capabilities and temporary variables.
-
getPerVertexColor
public javax.vecmath.Color4f[] getPerVertexColor()
-
getVertexData
public double[][] getVertexData()
-
getVertexData
public double[] getVertexData(int i)
-
setVertexData
public void setVertexData(double[][] data)
-
setVertexData
public void setVertexData(int i, double val)
-
setVertexData
public void setVertexData(int i, int j, double val)
-
setVertexData
public void setVertexData(int i, double[] array)
-
setCellData
public void setCellData(double[][] cellData)
-
getCellData
public double[][] getCellData()
-
getDirection
public static int[] getDirection()
DOCUMENT ME!- Returns:
- DOCUMENT ME!
-
getStartLocation
public static float[] getStartLocation()
DOCUMENT ME!- Returns:
- DOCUMENT ME!
-
loadTMesh
public static ModelTriangleMesh loadTMesh(java.io.RandomAccessFile kIn, javax.swing.JProgressBar pBar, int added, int total) throws java.io.IOException
Load the triangle mesh from a binary file. The caller must have already opened the file and read the mesh type (0 = ModelTriangleMesh, 1 = ModelClodMesh) and the number of meshes in the file. The caller then calls this function for each mesh. The format for a mesh isint vCount; // number of vertices Point3f vertices[vCount]; Point3f normals[vCount]; int iCount; // number of indices in the connectivity array int indices[iCount];
with 4-byte quantities stored in Big Endian format.- Parameters:
kIn
- the file from which the triangle mesh is loadedpBar
- DOCUMENT ME!added
- DOCUMENT ME!total
- DOCUMENT ME!- Returns:
- the loaded triangle mesh
- Throws:
java.io.IOException
- if there is an error reading from the file
-
loadTMesh
public static ModelTriangleMesh loadTMesh(java.io.RandomAccessFile kIn, ViewJProgressBar progress, int added, int total, boolean isVisible) throws java.io.IOException
Load the triangle mesh from a binary file. The caller must have already opened the file and read the mesh type (0 = ModelTriangleMesh, 1 = ModelClodMesh) and the number of meshes in the file. The caller then calls this function for each mesh. The format for a mesh isint vCount; // number of vertices Point3f vertices[vCount]; Point3f normals[vCount]; int iCount; // number of indices in the connectivity array int indices[iCount];
with 4-byte quantities stored in Big Endian format.- Parameters:
kIn
- the file from which the triangle mesh is loadedprogress
- DOCUMENT ME!added
- DOCUMENT ME!total
- DOCUMENT ME!isVisible
- DOCUMENT ME!- Returns:
- the loaded triangle mesh
- Throws:
java.io.IOException
- if there is an error reading from the file
-
save
public static void save(java.lang.String kName, ModelTriangleMesh[] akComponent, boolean flip, int[] direction, float[] startLocation, float[] box, TransMatrix inverseDicomMatrix, javax.vecmath.Color4f[][] perVertexColorArray) throws java.io.IOException
Save an array of triangle meshes to a binary file. The format for the file isint type; // 0 = ModelTriangleMesh, 1 = ModelClodMesh int aCount; // number of array elements array of 'aCount' meshes, each of the form: int vCount; // number of vertices Point3f vertices[vCount]; Point3f normals[vCount]; int iCount; // number of indices in the connectivity array int indices[iCount];
with 4-byte quantities stored in Big Endian format.- Parameters:
kName
- the name of the file to which the components are savedakComponent
- the array of mesh components to be savedflip
- if the y and z axes should be flipped - true in extract and in save of JDialogSurface To have proper orientations in surface file if flip is true flip y and z on reading.direction
- either 1 or -1 for each axisstartLocation
- DOCUMENT ME!box
- (dim-1)*resinverseDicomMatrix
- dicom transformperVertexColorArray
- color per vertex array.- Throws:
java.io.IOException
- if there is an error writing to the file
-
loadVRMLMesh
public static ModelTriangleMesh loadVRMLMesh(java.io.RandomAccessFile kIn, ViewJProgressBar progress, int added, int total, boolean flag) throws java.io.IOException
Load the triangle mesh from a VRML file specifically written by MIPAV!. The caller must have already opened the file. Must be made more robust to better parse the file. It only reads VRML 2.0 that MIPAV has written.- Parameters:
kIn
- the file from which the triangle mesh is loadedprogress
- DOCUMENT ME!added
- DOCUMENT ME!total
- DOCUMENT ME!flag
- DOCUMENT ME!- Returns:
- the loaded triangle mesh
- Throws:
java.io.IOException
- if there is an error reading from the file
-
loadVTKLegacyMesh
public static ModelTriangleMesh loadVTKLegacyMesh(java.io.RandomAccessFile kIn, ViewJProgressBar progress, int added, int total, boolean flag, java.lang.String fileName) throws java.io.IOException
- Parameters:
kIn
-progress
-added
-total
-flag
-- Returns:
- Throws:
java.io.IOException
-
loadVTKXMLMesh
public static ModelTriangleMesh loadVTKXMLMesh(java.lang.String absPath, ViewJProgressBar progress, int added, int total, boolean flag, java.lang.String fileName, java.lang.String dir) throws java.io.IOException
- Parameters:
kIn
-progress
-added
-total
-flag
-fileName
-- Returns:
- Throws:
java.io.IOException
-
parseVRMLMesh
public static int parseVRMLMesh(java.io.RandomAccessFile kIn) throws java.io.IOException, java.util.NoSuchElementException
Parses the VRML to see how many surfaces there are.- Parameters:
kIn
- the file to parse- Returns:
- DOCUMENT ME!
- Throws:
java.io.IOException
- DOCUMENT ME!java.util.NoSuchElementException
- DOCUMENT ME!
-
saveAsPortableVRML
public static void saveAsPortableVRML(java.io.PrintWriter kOut, ModelTriangleMesh[] akComponent, boolean flip, int[] direction, float[] startLocation, float[] box, javax.vecmath.Color3f color) throws java.io.IOException
Saves the triangle mesh in VRML97 (VRML 2.0) format (text format).- Parameters:
kOut
- the name of file to which the triangle mesh is savedakComponent
- DOCUMENT ME!flip
- if the y and z axes should be flipped - true in extract and in save of JDialogSurface To have proper orientations in surface file if flip is true flip y and z on reading.direction
- 1 or -1 for each axisstartLocation
- DOCUMENT ME!box
- (dim-1)*resolutioncolor
- DOCUMENT ME!- Throws:
java.io.IOException
- if the specified file could not be opened for writing
-
saveAsTextFile
public static void saveAsTextFile(java.lang.String kName, ModelTriangleMesh[] akComponent) throws java.io.IOException
Save an array of triangle meshes to a text file. The format for the file isint type; // 0 = ModelTriangleMesh, 1 = ModelClodMesh int aCount; // number of array elements array of 'aCount' meshes, each of the form: int vCount; // number of vertices vertex[0].x vertex[0].y vertex[0].z; : normal[0].x normal[0].y normal[0].z; : int tCount; // number of triangles index[0] index[1] index[2] : index[3*(tCount-1)] index[3*(tCount-1)+1] index[3*(tCount-1)+2]
- Parameters:
kName
- the name of the file to which the components are savedakComponent
- the array of mesh components to save- Throws:
java.io.IOException
- if the specified file could not be opened for writing
-
saveAsVRML
public static void saveAsVRML(java.lang.String kName, ModelTriangleMesh[] akComponent, boolean flip, int[] direction, float[] startLocation, float[] box, javax.vecmath.Color3f color) throws java.io.IOException
Saves the triangle mesh in VRML97 (VRML 2.0) format (text format).- Parameters:
kName
- the name of file to which the triangle mesh is savedakComponent
- DOCUMENT ME!flip
- if the y and z axes should be flipped - true in extract and in save of JDialogSurface To have proper orientations in surface file if flip is true flip y and z on reading. param direction 1 or -1 for each axis param startLocation param box (dim-1)*resolutiondirection
- DOCUMENT ME!startLocation
- DOCUMENT ME!box
- DOCUMENT ME!color
- DOCUMENT ME!- Throws:
java.io.IOException
- if the specified file could not be opened for writing
-
affineTransform
public void affineTransform(double[][] aafH)
The input 4x4 homogeneous matrix H is assumed to multiply vectors V as H*V where V = (x,y,z,1). Let the upper left 3x3 block of H be A. Let the upper right 3x1 block of H be B. The last row is [0 0 0 1]. Let the upper 3x1 block of V be X. The lower 1x1 block is 1. The product H*V = A*X + B.- Parameters:
aafH
- Affine transformation matrix.
-
affineTransform
public void affineTransform(float[][] afRot, float[] afTrn, float[] afScale)
Rotation R is 3x3, translation T is 3x1, and scale S is 3x1. The product with 3x1 vector X is Diag(S)*R*X + T where Diag(S) is the diagonal matrix whose diagonal entries are the values of S. As a homogeneous matrix (see notation above), A = diag(S)*R and B = T.- Parameters:
afRot
- Affine rotation matrix.afTrn
- Affine translation matrix.afScale
- Affine scale matrix.
-
area
public float area()
Calculate the surface mesh area. Each surface mesh is composed of triangles. Calculate the surface area from the summation of the each triangle area. Based on the Area by Stokes' Theorem. Area(S) = 1/2 * Normal dot ( Sum from i = 0 to n-1 of ( V1 cross V2) ) ==> Area(S) = 1/2 * ( Sum from i = 0 to n-1 of ( Normal dot ( V1 cross V2) ) )- Returns:
- float
-
center
public javax.vecmath.Point3f center()
Calculates and returns the center point of the Mesh:- Returns:
- DOCUMENT ME!
-
computeNormals
public void computeNormals()
A normal vector at a vertex is computed by averaging the triangle normals for all triangles sharing the vertex. This routine computes all vertex normals.
-
getComponents
public ModelTriangleMesh[] getComponents()
Construct the connected components of the triangle mesh.- Returns:
- An array of connected components of the triangle mesh. Each component has its own vertex and connectivity index arrays.
-
getConsistentComponents
public void getConsistentComponents()
Construct the connected components of the triangle mesh.
-
getGenerator
public java.lang.Object getGenerator()
Support for regenerating an ModelTriangleMesh from an ModelClodMesh whenever the level of detail is changed for the ModelClodMesh. If the mesh was generated from an ModelClodMesh, the generator member refers to that ModelClodMesh object. If the mesh was not generated from an ModelClodMesh, the generator member is null.- Returns:
- the generator of this mesh
-
getIndexCopy
public int[] getIndexCopy()
Make a copy of the connectivity array of a triangle mesh.- Returns:
- A copy of the array of connectivity indices of the triangle mesh.
-
getNormalCopy
public javax.vecmath.Vector3f[] getNormalCopy()
Make a copy of the normals of a triangle mesh.- Returns:
- A copy of the array of normals of the triangle mesh.
-
getVertexCopy
public javax.vecmath.Point3f[] getVertexCopy()
Make a copy of the vertices of a triangle mesh.- Returns:
- A copy of the array of vertices of the triangle mesh.
-
getVertexCopyAsVector3f
public WildMagic.LibFoundation.Mathematics.Vector3f[] getVertexCopyAsVector3f()
Make a copy of the vertices of a triangle mesh.- Returns:
- A copy of the array of vertices of the triangle mesh.
-
getColorCopy
public javax.vecmath.Color4f[] getColorCopy()
Make a copy of the colors of a triangle mesh.- Returns:
- A copy of the array of colors of the triangle mesh.
-
getCopies
public void getCopies(javax.vecmath.Point3f[] akVertex, javax.vecmath.Vector3f[] akNormal, javax.vecmath.Color4f[] akColor, javax.vecmath.TexCoord3f[] akTexCoord)
Copies the components of a ModelTriangleMesh into the parameters. More efficient than copying the components individually.- Parameters:
akVertex
- the array of coordinates to copy into.akNormal
- the array of normals to copy into.akColor
- the array of colors to copy into.akTexCoord
- the array of texture coordinates to copy into.
-
getTexCoordCopy
public javax.vecmath.TexCoord3f[] getTexCoordCopy()
Make a copy of the texture coordinates of a triangle mesh.- Returns:
- A copy of the array of texture coordinates of the triangle mesh.
-
setColorDelay
public void setColorDelay(int index, javax.vecmath.Color4f kColor)
Used for fast color update while painting the triangle mesh, stores the color update information for later loading into the surface.- Parameters:
index
- the vertex index to set the color forkColor
- the new color
-
setColor
public void setColor(int index, javax.vecmath.Color4f kColor)
Sets the color and stores the color update information in a local copy.- Overrides:
setColor
in classjavax.media.j3d.GeometryArray
- Parameters:
index
- the vertex index to set the color forkColor
- the new color
-
getColorLocal
public void getColorLocal(int index, javax.vecmath.Color4f kColor)
Gets the stored local color.- Parameters:
index
- the vertex index to get the color for.kColor
- the stored local color.
-
setColorUpdate
public void setColorUpdate()
Used for fast color update while painting. After paint operations, set the color of the triangle mesh with the stored colors.
-
save
public void save(java.lang.String kName, boolean flip, int[] direction, float[] startLocation, float[] box, TransMatrix inverseDicomMatrix) throws java.io.IOException
Save the triangle mesh to a binary file. The format for the file isint type; // 0 = ModelTriangleMesh, 1 = ModelClodMesh int aCount; // 1, write the entire mesh as a single component int vCount; // number of vertices Point3f vertices[vCount]; Point3f normals[vCount]; int iCount; // number of indices in the connectivity array int indices[iCount];
with 4-byte quantities stored in Big Endian format.- Parameters:
kName
- the name of the file to which the triangle mesh is savedflip
- if the y and z axes should be flipped - true in extract and in save of JDialogSurface To have proper orientations in surface file if flip is true flip y and z on reading.direction
- equal 1 or -1 for each axisstartLocation
- DOCUMENT ME!box
- (dim-1)*resinverseDicomMatrix
- DOCUMENT ME!- Throws:
java.io.IOException
- if the specified file could not be opened for writing
-
saveXMLHeader
public void saveXMLHeader(java.lang.String kName)
-
saveAsPortableVRML
public void saveAsPortableVRML(java.io.PrintWriter kOut, boolean flip, int numberOfShapes, int[] direction, float[] startLocation, float[] box, javax.vecmath.Color3f color) throws java.io.IOException
Saves the triangle mesh in VRML97 (VRML 2.0) format (text format).- Parameters:
kOut
- the name of file to which the triangle mesh is savedflip
- if the y and z axes should be flipped - true in extract and in save of JDialogSurface To have proper orientations in surface file if flip is true flip y and z on reading.numberOfShapes
- DOCUMENT ME!direction
- 1 or -1 for each axisstartLocation
- DOCUMENT ME!box
- (dimension-1)*resolutioncolor
- DOCUMENT ME!- Throws:
java.io.IOException
- if the specified file could not be opened for writing
-
saveAsVTKLegacy
public void saveAsVTKLegacy(java.lang.String kName) throws java.io.IOException
Saves the triangle mesh to VTK Legacy format- Parameters:
kName
-- Throws:
java.io.IOException
-
saveAsVTKXML
public void saveAsVTKXML(java.lang.String fileName) throws java.io.IOException
saves thr triangle mesh to VTK XML format- Parameters:
kName
-- Throws:
java.io.IOException
-
saveAsTextFile
public void saveAsTextFile(java.lang.String kName) throws java.io.IOException
Save the triangle mesh to a text file. The format for the file isint type; // 0 = ModelTriangleMesh, 1 = ModelClodMesh, 2 = ModelQuadMesh int aCount; // 1, write the entire mesh as a single component int vCount; // number of vertices vertex[0].x vertex[0].y vertex[0].z; : normal[0].x normal[0].y normal[0].z; : int tCount; // number of triangles index[0] index[1] index[2] : index[3*(tCount-1)] index[3*(tCount-1)+1] index[3*(tCount-1)+2]
- Parameters:
kName
- the name of file to which the triangle mesh is saved- Throws:
java.io.IOException
- if the specified file could not be opened for writing
-
saveAsPlyFile
public void saveAsPlyFile(java.lang.String kName) throws java.io.IOException
- Throws:
java.io.IOException
-
saveAsSMFAsciiFile
public void saveAsSMFAsciiFile(java.lang.String kName) throws java.io.IOException
Sate the SMF ACII file format.- Parameters:
kName
- file name- Throws:
java.io.IOException
-
saveAsSTLAsciiFile
public void saveAsSTLAsciiFile(java.lang.String kName) throws java.io.IOException
Sate the STIL ACII file format.- Parameters:
kName
- file name- Throws:
java.io.IOException
-
saveAsSTLBinaryFile
public void saveAsSTLBinaryFile(java.lang.String kName) throws java.io.IOException
Sate the STIL Binary file format.- Parameters:
kName
- file name- Throws:
java.io.IOException
-
saveAsVRML
public void saveAsVRML(java.lang.String kName, boolean flip, int numberOfShapes, int[] direction, float[] startLocation, float[] box, javax.vecmath.Color3f color) throws java.io.IOException
Saves the triangle mesh in VRML97 (VRML 2.0) format (text format).- Parameters:
kName
- the name of file to which the triangle mesh is savedflip
- if the y and z axes should be flipped - true in extract and in save of JDialogSurface To have proper orientations in surface file if flip is true flip y and z on reading.numberOfShapes
- DOCUMENT ME!direction
- 1 or -1 for each axisstartLocation
- DOCUMENT ME!box
- (dimension-1)*resolutioncolor
- DOCUMENT ME!- Throws:
java.io.IOException
- if the specified file could not be opened for writing
-
setGenerator
public void setGenerator(java.lang.Object kGenerator)
Support for regenerating an ModelTriangleMesh from an ModelClodMesh whenever the level of detail is changed for the ModelClodMesh. If the mesh was generated from an ModelClodMesh, the generator member refers to that ModelClodMesh object. If the mesh was not generated from an ModelClodMesh, the generator member is null.- Parameters:
kGenerator
- the generator of this mesh
-
setVerticies
public void setVerticies(javax.vecmath.Point3f[] akVertex)
Replace the verticies with a new set.- Parameters:
akVertex
- DOCUMENT ME!
-
smoothMesh
public void smoothMesh(int iteration, float alpha, boolean volumeLimit, float volumePercent, boolean pVisible)
Smooth mesh. The formula can be found in "The Visualization Toolkit" by Will Schoeder, Ken Martin, and Bill Lorensen, p. 389. Mesh smoothing moves the verticies of the mesh closer to an average of the points. Each point is moved so that it is the average of the points around it. The formula is:xi+1 = xi + (alpha * (Sum from j=0 to n of {xj - xi}))
where xi+1 is the new point, xi is the orginal point, and the xjs are points that are connected to xi. Alpha is some smoothing factor between .01 and .10. This formula is run for a number of iterations to obtain a smooth mesh. Usually the iterations will be between 50 and 100.- Parameters:
iteration
- Number of times to run smoothing formula on data set.alpha
- Smoothing factor.volumeLimit
- if true stop iterations when the present volume is volumePercent or more different from the initialvolumePercent
- percentage from initial volume for stopping iterationspVisible
- if true display progress bar
-
smoothThree
public void smoothThree(int iteration, float lambda, float mu, boolean pVisible)
Smooth mesh. This method smoothes without shrinking by 2 Gaussian smoothing steps. First, a Gaussian smoothing is performed with a positive scale factor lambda. Second, a Gaussian smoothing is performed with a negative scale factor mu, which is greater in magnitude than lambda. To produce a significant smoothing, these steps must be repeated a number of times. 3 references for this smoothing: 1.) Curve and Surface Smoothing Without Shrinkage by Gabriel Taubin, Technical Report RC-19536, IBM Research, April, 1994. (also in Proceedings, Fifth International Conference on Computer Vision, pages 852-857, June, 1995). 2.) A Signal Processing Approach to Fair Surface Design by Gabriel Taubin, Computer Graphics, pages 351-358, August, 1995 (Proceedings SIGGRAPH '95). 3.) Optimal Surface Smoothing as Filter Design by Gabriel Taubin, Tong Zhang, and Gene Golub, IBM Research Report RC-20404 (#90237). Usually the iterations will be between 30 and 100.- Parameters:
iteration
- Number of times to run smoothing formula on data set.lambda
- positive scale factormu
- negative scale factorpVisible
- if true display progress bar Require: 0 < lambda < -mu (1/lambda) + (1/mu) < 2
-
smoothTwo
public void smoothTwo(int iterations, float m_fStiffness, boolean volumeLimit, float volumePercent, boolean pVisible)
Derived from the first 2 of the 3 components of AlgorithmBrainExtraction Note that m_fStiffness does not increase and then decrease as in AlgorithmBrainExtraction but instead remains constant. This is because the change in m_fStiffness only applies to the third component of AlgorithmBrainExtraction which uses image intensities.- Parameters:
iterations
- DOCUMENT ME!m_fStiffness
- DOCUMENT ME!volumeLimit
- if true stop iterations when the present volume is volumePercent or more different from the initialvolumePercent
- percentage from initial volume for stopping iterationspVisible
- if true display progress bar
-
volume
public float volume()
Calculates volume of triangle mesh. The mesh consists of triangle faces and encloses a bounded region. Face j, 0 <= j <= n-1 has verticies P0, P1, and P2. The order of the verticies is counterclockwise as you view the face from outside the bounded region. The mesh is closed and manifold in the sense that each edge is shared by exactly two triangles. The volume of the bounded region is:
V = 1/6 (Sum from j=0 to n-1 of {P0 dot P1 cross P2})
The terms of the summation can be positive, negative, or zero. The term is positive if the face is counterclockwise when viewed from the zero vector, or zero if the face appears to be a line segment when viewed from the zero vector. NOTICE THAT THERE ARE 2 DIFFERENT DEFINITIONS OF COUNTERCLOCKWISE, COUNTERCLOCKWISE AS VIEWED FROM OUTSIDE THE BOUNDED REGION AND COUNTERCLOCKWISE AS VIEWED FROM THE ZERO VECTOR.A 3D image on a rectangular lattice contains points (i0, i1, i2) where 0 <= ik < Bk for specified dimension bounds Bk. These are just indicies. The actual physical measurements are provided by scaling factors Dk > 0. For example, a 256x256x256 MRI has B0 = B1 = B2 = 256. If each voxel is 1 mm in x, 1 mm in y, and 5 mm in z, then D0 = D1 = 1 and D2 = 5. The 3D image encloses a rectangular region [0,C0] x [0,C1] x [0,C2] in physical space where Ck = Dk*Bk. In the example, C0 = D0*B0 = 256 mm in x, C1 = D1*B1 = 256 mm in y, and C2 = D2*B2 = 1280 mm in z. Volume calculations are required to use physical measurements. In the example, volume will be in cubic millimeters.
The surface extraction is performed by mapping [0,C0] x [0,C1] x [0,C2] into [-1,1] x [-1,1] x [-1,1] using uniform scaling. This is done to keep the floating point values within order 1 to avoid the floating point errors that occur if you were to use the index values themselves. The topology of a level surface is invariant under any scaling (not just uniform), but the continuous level of detail algorithm for triangle decimation does edge collapses based on various geometric measurements of the mesh representing the level surface. The geometric measurements are not invariant under nonuniform scaling. Map the image into a cube using uniform scaling so that the triangle collapse order is invariant. The uniform scaling is done so that the largest image dimension [0,M] is mapped to [-1,1]. The other ranges are mapped to intervals of the form [-L,L) where L < 1. If (i0,i1,i2) is in [0,B0) x [0,B1) x [0,B2), the corresponding (x0,x1,x2) in [-1,1) is:
2*Dk*ik - Ck xk = ------------ max{C0,C1,C2}
However, we want to map from [0,Bk) to an inclusive interval [-Rk,Rk], where 0 < Rk < 1 and Rk = 1 - Dk/max{C0,C1,C2}. This ensures that surfaces begin in the center of a voxel rather than at the (0,0,0) corner of the voxel. The problem is easiest to see in the Z direction: a surface that should cover the full Z range will end before the last slice. Therefore, the formula should be:
2*Dk*ik - Ck + Dk xk = ----------------- max{C0,C1,C2}
Once a closed manifold triangle mesh is extracted, the problem is now to compute its volume in physical space. Note that ik are indicies in the original image, but the true physical length that is measured (relative to other index locations) is yk = Dk*ik. Any triangle mesh (x0,x1,x2) must be mapped to (y0,y1,y2) before the volume calculation. The mapping is:
max{C0,C1,C2}*xk + Ck - Dk yk = -------------------------- 2
The volume calculations use the previously mentioned formula where the P points are the (y0,y1,y2) values.
- Returns:
- The volume of the surface.
-
print
protected void print(java.io.PrintWriter kOut) throws java.io.IOException
Internal support for 'void print (String)' and 'void print (String, ModelTriangleMesh[])'. ModelTriangleMesh uses this function to print vertices, normals, and connectivity indices to the file. ModelClodMesh overrides this to additionally print collapse records to the file- Parameters:
kOut
- the file to which the triangle mesh is saved- Throws:
java.io.IOException
- if there is an error writing to the file
-
printSMFAscii
protected void printSMFAscii(java.io.PrintWriter kOut) throws java.io.IOException
- Throws:
java.io.IOException
-
printSTLAscii
protected void printSTLAscii(java.io.PrintWriter kOut) throws java.io.IOException
Print the STL file format in ASCII. STLA Examples: solid MYSOLID facet normal 0.4 0.4 0.2 outerloop vertex 1.0 2.1 3.2 vertex 2.1 3.7 4.5 vertex 3.1 4.5 6.7 endloop endfacet ... facet normal 0.2 0.2 0.4 outerloop vertex 2.0 2.3 3.4 vertex 3.1 3.2 6.5 vertex 4.1 5.5 9.0 endloop endfacet endsolid MYSOLID- Parameters:
kOut
-- Throws:
java.io.IOException
-
printSTLBinary
protected void printSTLBinary(java.io.RandomAccessFile kOut) throws java.io.IOException
Print the STL file format in binary ( little endian ). STLB Example: 80 byte string = header containing nothing in particular 4 byte int = number of faces For each face: 3 4-byte floats = components of normal vector to face; 3 4-byte floats = coordinates of first node; 3 4-byte floats = coordinates of second node; 3 4-byte floats = coordinates of third and final node; 2-byte int = attribute, whose value is 0.- Parameters:
kOut
- binary file output- Throws:
java.io.IOException
-
saveAsXML
protected void saveAsXML(java.lang.String fileName, int[] direction, float[] startLocation, float[] box)
Internal support for 'void save (String)' and 'void save (String, ModelTriangleMesh[])'. ModelTriangleMesh uses this function to write vertices, normals, and connectivity indices to the XML file. ModelClodMesh overrides this to additionally write collapse records to the file- Parameters:
fileName
- the file to which the triangle mesh is saveddirection
- either 1 or -1 for each axisstartLocation
- image origin coordinatebox
- (dim-1)*res- Throws:
java.io.IOException
- if there is an error writing to the file
-
save
protected void save(java.io.RandomAccessFile kOut, boolean flip, int[] direction, float[] startLocation, float[] box, TransMatrix inverseDicomMatrix, javax.vecmath.Color4f[] perVertexColorArray) throws java.io.IOException
Internal support for 'void save (String)' and 'void save (String, ModelTriangleMesh[])'. ModelTriangleMesh uses this function to write vertices, normals, and connectivity indices to the file. ModelClodMesh overrides this to additionally write collapse records to the file- Parameters:
kOut
- the file to which the triangle mesh is savedflip
- if the y and z axes should be flipped - true in extraction algorithms and in JDialogSurface. To have proper orientations in surface file if flip is true flip y and z on reading.direction
- either 1 or -1 for each axisstartLocation
- DOCUMENT ME!box
- (dim-1)*resinverseDicomArray
- DOCUMENT ME!perVertexColorArray
- color per vertex array.- Throws:
java.io.IOException
- if there is an error writing to the file
-
saveAsPortableVRML
protected void saveAsPortableVRML(java.io.PrintWriter kOut, boolean flip, int[] direction, float[] startLocation, float[] box, javax.vecmath.Color3f color) throws java.io.IOException
Saves the triangle mesh in VRML97 (VRML 2.0) format. File name should end with ".wrl"- Parameters:
kOut
- the file to which the triangle mesh is savedflip
- if the y and z axes should be flipped - true in extract and in save of JDialogSurface To have proper orientations in surface file if flip is true flip y and z on reading.direction
- 1 or -1 for each axisstartLocation
- DOCUMENT ME!box
- (dimension-1)*resolutioncolor
- DOCUMENT ME!- Throws:
java.io.IOException
- if there is an error writing to the file
-
saveAsVRML
protected void saveAsVRML(java.io.PrintWriter kOut, boolean flip, int[] direction, float[] startLocation, float[] box, javax.vecmath.Color3f color) throws java.io.IOException
Saves the triangle mesh in VRML97 (VRML 2.0) format. File name should end with ".wrl"- Parameters:
kOut
- the file to which the triangle mesh is savedflip
- if the y and z axes should be flipped - true in extract and in save of JDialogSurface To have proper orientations in surface file if flip is true flip y and z on reading.direction
- 1 or -1 for each axisstartLocation
- DOCUMENT ME!box
- (dimension-1)*resolutioncolor
- DOCUMENT ME!- Throws:
java.io.IOException
- if there is an error writing to the file
-
buildConnections
private void buildConnections()
Builds a list of cross-references, so that connections[i] contains all the verticies that are connected to vertex at i.
-
computeMeanEdgeLength
private void computeMeanEdgeLength()
Compute the average length of all the edges in the triangle mesh.
-
computeVertexInformation
private void computeVertexInformation()
Let V[i] be a vertex in the triangle mesh. This function computes VMean[i], the average of the immediate neighbors of V[i]. Define S[i] = VMean[i] - V[i]. The function also computes a surface normal SNormal[i], the component of S[i] in the vertex normal direction. STangent[i] = S[i] - SNormal[i] is computed as an approximation to a tangent to the surface. Finally, Curvature[i] is an approximation of the surface curvature at V[i].
-
computeVertexNormals
private void computeVertexNormals()
Compute the vertex normals of the triangle mesh. Each vertex normal is the unitized average of the non-unit triangle normals for those triangles sharing the vertex.
-
update2
private float update2(int i)
Compute the coefficient of the surface normal for the update of the mesh vertex V[i] in the SNormal[i] direction. See BrainExtraction.pdf for a description of the update.- Parameters:
i
- the index of the vertex to update- Returns:
- the coefficient of SNormal[i] for the update
-
updateMesh
private void updateMesh()
The heart of the segmentation. This function is responsible for the evolution of the triangle mesh that approximates the brain surface. The update has a tangential component, a surface normal component, and a vertex normal component for each vertex in the mesh. The first two components control the geometry of the mesh. The last component is based on the MRI data itself. See BrainExtraction.pdf for a detailed description of the update terms.
-
invertMesh
public void invertMesh()
Invert the mesh z-coord, reorder the triangles, and recompute the normals:
-
setMaterial
public void setMaterial(javax.media.j3d.Material kMaterial)
Sets the material properties of the mesh.- Parameters:
kMaterial
- new material properties.
-
getMaterial
public javax.media.j3d.Material getMaterial()
Gets the material properties of the mesh:- Returns:
- material properties.
-
setTransparency
public void setTransparency(float transparency)
Sets the mesh transparency.- Parameters:
transparency
- mesh transparency
-
getTransparency
public float getTransparency()
Gets the mesh transparency.- Returns:
- mesh transparency.
-
-