Class FileSurface_WM


  • public class FileSurface_WM
    extends java.lang.Object
    FileSurface. Reads and writes surface files for the JPanelSurface class. When surface files are loaded by the user in the JPanelSurface.java class through the "Add" button, when surfaces are loaded as surfaces attached to .xml image files, or surfaces loaded through the FlyThruRender class. Any time a surface file is read from disk for display in the JPanelSurface (SurfaceRender) class the FileSurface.java class is used to provide the interface. Loaded surfaces are returned in an array of SurfaceAttributes[] which are then used to add the surfaces to the SurfaceRender scene graph.

    This class also handles saving files from the JPanelSurface class. Surfaces are saved as surface files (.sur), single-level (.wrl), multi-level (.wrl) or XML surfaces (.xml).

    See Also:
    JPanelSurface.java, SurfaceRender.java, SurfaceAttributes.java, FileSurfaceXML.java
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static float[] box
      image volume bounding box.
      private static float[] coord
      coordinate used to transform data point from image coordinate to dicom coordinate
      private javax.vecmath.Point3f[] coordArray  
      private static boolean dicom
      flag indicates to read dicom matrix or not.
      private static java.io.File dicomMatrixFile
      dicom matrix file.
      private static int[] direction
      image x, y, z orientation.
      private static boolean flip
      flag indicates to flip y, z coordinate or not.
      private static double[][] inverseDicomArray
      inverse dicom matrix array.
      private static TransMatrix inverseDicomMatrix
      inverset dicom matrix.
      private WildMagic.LibFoundation.Mathematics.Vector3f[] normArray  
      private static float[] startLocation
      image start location.
      private int[] stripCounts  
      private static float[] tCoord
      coordinate used to transform data point from image coordinate to dicom coordinate.
    • Constructor Summary

      Constructors 
      Constructor Description
      FileSurface_WM()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static WildMagic.LibGraphics.SceneGraph.VertexBuffer convertVertex​(ModelImage kImage, WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
      Convert the vertex from display space to dicom space.
      private static java.lang.String getFileName​(boolean bLoad)
      Calls a dialog to get a file name.
      private static WildMagic.LibGraphics.Detail.CollapseRecord load​(java.io.RandomAccessFile kIn)
      Support for loading the collapse records from a binary file.
      static WildMagic.LibGraphics.Detail.ClodMesh loadCMesh​(java.io.RandomAccessFile kIn, ViewJProgressBar pBar, int added, int piece)
      Load the clod mesh from a binary file.
      private static WildMagic.LibGraphics.SceneGraph.TriMesh loadGiftiXMLMesh​(java.lang.String absPath, java.lang.String fileName, java.lang.String dir)
      Read Gifti mesh from file.
      private static WildMagic.LibGraphics.SceneGraph.TriMesh loadPlyAsciiMesh​(java.io.File file, ModelImage kImage, boolean isFileCoords)
      Read a TriMesh from a Ply ascii file.
      private static WildMagic.LibGraphics.SceneGraph.TriMesh loadSTLAsciiMesh​(java.io.File file, ModelImage kImage)
      Load the STL ASCII file.
      private static WildMagic.LibGraphics.SceneGraph.TriMesh loadSTLBinaryMesh​(java.io.File file, ModelImage kImage)
      Load the STL ASCII file.
      static WildMagic.LibGraphics.SceneGraph.TriMesh loadTMesh​(java.io.RandomAccessFile kIn, ViewJProgressBar progress, int added, int total, boolean isVisible, WildMagic.LibGraphics.Rendering.MaterialState kMaterial, float[] startLocation, float[] direction, float[] box)
      Load the TriMesh from a binary file.
      static WildMagic.LibGraphics.SceneGraph.TriMesh loadVRMLMesh​(java.io.RandomAccessFile kIn, ViewJProgressBar progress, int added, int total, boolean flag, float[] startLocation, float[] direction, float[] box)
      Load the triangle mesh from a VRML file specifically written by MIPAV.
      private static WildMagic.LibGraphics.SceneGraph.TriMesh loadVTKLegacyMesh​(java.io.RandomAccessFile kIn, ViewJProgressBar progress, int added, int total, java.lang.String fileName)
      Load legacy VTK mesh.
      private static WildMagic.LibGraphics.SceneGraph.TriMesh loadVTKXMLMesh​(java.lang.String absPath, java.lang.String fileName, java.lang.String dir)
      Read VTK mesh from file.
      private static java.io.File openDicomMatrixFiles​(boolean bLoad)
      Returns a dicomMatrix file objects, based on the user-selected filed from the FileChooser dialog.
      static java.io.File[] openFiles​(boolean bLoad)
      Returns an array of File objects, based on the user-selected files from the FileChooser dialog.
      static WildMagic.LibGraphics.SceneGraph.TriMesh[] openSurfaces​(ModelImage kImage)
      The action taken when the Add button is clicked in the JPanelSurface class.
      static WildMagic.LibGraphics.SceneGraph.TriMesh[] openSurfaces​(ModelImage kImage, boolean isFileCoords)
      The action taken when the Add button is clicked in the JPanelSurface class.
      static int parseVRMLMesh​(java.io.RandomAccessFile kIn)
      Parses the VRML to see how many surfaces there are.
      private static void printAscii​(java.io.PrintWriter kOut, WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
      Print the contents of the TriMesh in ascii format.
      private static void printProstateSTLAscii​(java.io.PrintWriter kOut, ModelImage kImage, WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
      Print the contents of the TriMesh in STL ascii format.
      private static void printSTLAscii​(java.io.PrintWriter kOut, ModelImage kImage, WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
      Print the contents of the TriMesh in STL ascii format.
      private static WildMagic.LibGraphics.SceneGraph.TriMesh readAscii​(java.io.File kFile)
      Read a TriMesh from an ascii file.
      private void readFacetB​(java.nio.ByteBuffer in, int index)
      Method that reads a face in binary files All binary versions of the methods end by 'B' As in binary files we can read the number of faces, we don't need to use coordArray and normArray (reading binary files should be faster)
      private static java.lang.String readLine​(java.io.InputStream in)
      Read a line of ASCII text from the input stream.
      private static WildMagic.LibFoundation.Mathematics.Vector3f readPoint​(java.io.StreamTokenizer tokenizer, java.lang.String label)
      Find the given label in the tokenizer stream and then return the next three numbers as a point.
      private static WildMagic.LibGraphics.SceneGraph.TriMesh readSTLAscii​(java.io.StreamTokenizer tokenizer, ModelImage kImage)
      Read the STL ASCII file as a single stream tokenizer.
      private static WildMagic.LibGraphics.SceneGraph.TriMesh readSTLBinary​(java.io.FileInputStream data, ModelImage kImage)
      Method for reading binary files Execution is completly different It uses ByteBuffer for reading data and ByteOrder for retrieving the machine's endian (Needs JDK 1.4) TO-DO: 1.
      static WildMagic.LibGraphics.SceneGraph.TriMesh readSurface​(ModelImage kImage, java.io.File file, WildMagic.LibGraphics.Rendering.MaterialState kMaterial)
      Load a triangle mesh from the specified file and assign to it the MaterialState.
      static WildMagic.LibGraphics.SceneGraph.TriMesh readSurface​(ModelImage kImage, java.io.File file, WildMagic.LibGraphics.Rendering.MaterialState kMaterial, boolean isFileCoords)
      Load a triangle mesh from the specified file and assign to it the MaterialState.
      static void save​(java.lang.String kName, WildMagic.LibGraphics.SceneGraph.TriMesh kMesh, int iType, WildMagic.LibGraphics.SceneGraph.VertexBuffer kVBuffer, boolean flip, int[] direction, float[] startLocation, float[] box, TransMatrix inverseDicomMatrix)
      Save a TriMesh to disk
      static void save​(java.lang.String kName, WildMagic.LibGraphics.SceneGraph.TriMesh kMesh, ModelImage image, boolean transform)  
      private static void saveAsGiftiXML​(java.lang.String fileName, WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
      Save the TriMesh in Gifti format.
      private static void saveAsTextFile​(java.lang.String kName, WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
      Save the TriMesh as an ascii text file.
      protected static void saveAsVRML​(java.io.PrintWriter kOut, WildMagic.LibGraphics.SceneGraph.TriMesh kMesh, WildMagic.LibGraphics.SceneGraph.VertexBuffer kVBuffer, boolean flip, int[] direction, float[] startLocation, float[] box)
      Saves the triangle mesh in VRML97 (VRML 2.0) format.
      private static void saveAsVRML​(java.lang.String kName, WildMagic.LibGraphics.SceneGraph.TriMesh kMesh, WildMagic.LibGraphics.SceneGraph.VertexBuffer kVBuffer, boolean flip, int[] direction, float[] startLocation, float[] box)
      Saves the triangle mesh in VRML97 (VRML 2.0) format (text format).
      private static void saveAsVTKLegacy​(java.lang.String kName, WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
      Save the TriMesh in VTK legacy format.
      private static void saveAsVTKXML​(java.lang.String fileName, WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
      Save the TriMesh in VTK format.
      static void saveClodMesh​(java.lang.String kName, WildMagic.LibGraphics.Detail.ClodMesh[] akComponent, boolean flip, int[] direction, float[] startLocation, float[] box, TransMatrix inverseDicomMatrix)
      Save ClodMesh to disk
      private static void saveCollapseRecord​(java.io.RandomAccessFile kOut, WildMagic.LibGraphics.Detail.CollapseRecord kRecord)
      Support for saving the collapse records to a binary file.
      private static void saveProstatePlyMesh​(java.lang.String kName, ModelImage kImage, WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
      Saves a single level of detail to a STL mesh file.
      private static void saveProstateSTLMesh​(java.lang.String kName, ModelImage kImage, WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
      Saves a single level of detail to a STL ascii mesh file.
      static void saveProstateSurface​(java.lang.String kName, WildMagic.LibGraphics.SceneGraph.TriMesh kMesh, ModelImage keyImage)
      Save a TriMesh to disk
      private static void saveSingleMesh​(ModelImage kImage, boolean isSur, WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
      Saves a single level of detail to a mesh file.
      private static void saveSingleMesh​(java.lang.String name, ModelImage kImage, boolean isSur, WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
      Saves a single level of detail to a mesh file.
      private static void saveSinglePlyMesh​(java.lang.String kName, ModelImage kImage, WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
      Saves a single level of detail to a STL mesh file.
      private static void saveSingleSTLMesh​(java.lang.String kName, ModelImage kImage, WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
      Saves a single level of detail to a STL mesh file.
      private static void saveSur​(java.lang.String kName, WildMagic.LibGraphics.SceneGraph.TriMesh kMesh, int iType, WildMagic.LibGraphics.SceneGraph.VertexBuffer kVBuffer, boolean flip, int[] direction, float[] startLocation, float[] box, TransMatrix inverseDicomMatrix)
      Write the TriMesh to disk in the .sur format.
      static void saveSurfaces​(ModelImage kImage, WildMagic.LibGraphics.SceneGraph.TriMesh[] akSurfaces, java.lang.String kCommand)
      The action taken when the one of the save surface buttons is pressed in the JPanelSurface class.
      private static void writeTriangleMeshXML​(java.lang.String kName, ModelImage kImage, WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
      Writes a TriMesh to disk in the xml format, based on surface.xsd.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • flip

        private static boolean flip
        flag indicates to flip y, z coordinate or not.
      • dicom

        private static boolean dicom
        flag indicates to read dicom matrix or not.
      • inverseDicomArray

        private static double[][] inverseDicomArray
        inverse dicom matrix array.
      • inverseDicomMatrix

        private static TransMatrix inverseDicomMatrix
        inverset dicom matrix.
      • direction

        private static int[] direction
        image x, y, z orientation.
      • startLocation

        private static float[] startLocation
        image start location.
      • box

        private static float[] box
        image volume bounding box.
      • tCoord

        private static float[] tCoord
        coordinate used to transform data point from image coordinate to dicom coordinate.
      • coord

        private static float[] coord
        coordinate used to transform data point from image coordinate to dicom coordinate
      • dicomMatrixFile

        private static java.io.File dicomMatrixFile
        dicom matrix file.
      • coordArray

        private javax.vecmath.Point3f[] coordArray
      • normArray

        private WildMagic.LibFoundation.Mathematics.Vector3f[] normArray
      • stripCounts

        private int[] stripCounts
    • Constructor Detail

      • FileSurface_WM

        public FileSurface_WM()
    • Method Detail

      • loadCMesh

        public static WildMagic.LibGraphics.Detail.ClodMesh loadCMesh​(java.io.RandomAccessFile kIn,
                                                                      ViewJProgressBar pBar,
                                                                      int added,
                                                                      int piece)
        Load the clod mesh from a binary file. The caller must have already opened the file and read the mesh type (0 = TriMesh, 1 = ModelClodMesh) and the number of meshes in the file. The caller then calls this function for each mesh. The format for a mesh is
                 int vCount;  // number of vertices
                 Point3f vertices[vCount];
                 Point3f normals[vCount];
                 int iCount;  // number of indices in the connectivity array
                 int indices[iCount];
                 int rCount;
                 ModelCollapseRecord collapses[rCount];
         
        with 4-byte quantities stored in Big Endian format.
        Parameters:
        kIn - the file from which the triangle mesh is loaded
        pBar - DOCUMENT ME!
        added - DOCUMENT ME!
        piece - DOCUMENT ME!
        Returns:
        the loaded triangle mesh
        Throws:
        java.io.IOException - if there is an error reading from the file
      • loadTMesh

        public static WildMagic.LibGraphics.SceneGraph.TriMesh loadTMesh​(java.io.RandomAccessFile kIn,
                                                                         ViewJProgressBar progress,
                                                                         int added,
                                                                         int total,
                                                                         boolean isVisible,
                                                                         WildMagic.LibGraphics.Rendering.MaterialState kMaterial,
                                                                         float[] startLocation,
                                                                         float[] direction,
                                                                         float[] box)
        Load the TriMesh from a binary file. The caller must have already opened the file and read the mesh type (0 = TriMesh, 1 = ClodMesh) and the number of meshes in the file. The caller then calls this function for each mesh. The format for a mesh is
         int vCount; // number of vertices Point3f vertices[vCount]; Point3f
         normals[vCount]; int iCount; // number of indices in the connectivity array
         int indices[iCount];
        Parameters:
        kIn - file containing TriMesh data
        progress - progress bar
        added - number of meshes added so far
        total - total number of meshes to add
        isVisible - sets the visibility of the progress bar
        kMaterial - MaterialState for the new mesh
        startLocation - 3D location of the mesh
        direction - 3D orientation of the mesh
        box - mesh bounding box
        Returns:
        new TriMesh
      • loadVRMLMesh

        public static WildMagic.LibGraphics.SceneGraph.TriMesh loadVRMLMesh​(java.io.RandomAccessFile kIn,
                                                                            ViewJProgressBar progress,
                                                                            int added,
                                                                            int total,
                                                                            boolean flag,
                                                                            float[] startLocation,
                                                                            float[] direction,
                                                                            float[] box)
        Load the triangle mesh from a VRML file specifically written by MIPAV. The caller must have already opened the file.
        Parameters:
        kIn - the file from which the triangle mesh is loaded
        progress - progress bar
        added - number of meshes added so far
        total - number of meshes to add
        flag - when true this is the first mesh, read header info.
        startLocation - 3D location of mesh
        direction - 3D orientation of mesh
        box - mesh bounding box
        Returns:
        new TriMesh
      • openSurfaces

        public static WildMagic.LibGraphics.SceneGraph.TriMesh[] openSurfaces​(ModelImage kImage)
        The action taken when the Add button is clicked in the JPanelSurface class. A file dialog is launched that allows the user to select new surfaces to load from disk.
        Parameters:
        kImage - ModelImage for location/orientation and scale information.
        Returns:
        array of TriMesh objects.
      • openSurfaces

        public static WildMagic.LibGraphics.SceneGraph.TriMesh[] openSurfaces​(ModelImage kImage,
                                                                              boolean isFileCoords)
        The action taken when the Add button is clicked in the JPanelSurface class. A file dialog is launched that allows the user to select new surfaces to load from disk.
        Parameters:
        kImage - ModelImage for location/orientation and scale information.
        Returns:
        array of TriMesh objects.
      • 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:
        int value for the number of surfaces in the file.
        Throws:
        java.io.IOException
        java.util.NoSuchElementException
      • save

        public static void save​(java.lang.String kName,
                                WildMagic.LibGraphics.SceneGraph.TriMesh kMesh,
                                ModelImage image,
                                boolean transform)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • save

        public static void save​(java.lang.String kName,
                                WildMagic.LibGraphics.SceneGraph.TriMesh kMesh,
                                int iType,
                                WildMagic.LibGraphics.SceneGraph.VertexBuffer kVBuffer,
                                boolean flip,
                                int[] direction,
                                float[] startLocation,
                                float[] box,
                                TransMatrix inverseDicomMatrix)
                         throws java.io.IOException
        Save a TriMesh to disk
        Parameters:
        kName - file name
        kMesh - TriMesh
        iType - type of mesh TriMesh or ClodMesh
        kVBuffer - VertexBuffer
        flip - invert y,z values
        direction - 3D orientation of mesh
        startLocation - 3D location of mesh
        box - 3D bounding box
        inverseDicomMatrix - dicom matrix
        Throws:
        java.io.IOException - file I/O exception
      • saveProstateSurface

        public static void saveProstateSurface​(java.lang.String kName,
                                               WildMagic.LibGraphics.SceneGraph.TriMesh kMesh,
                                               ModelImage keyImage)
                                        throws java.io.IOException
        Save a TriMesh to disk
        Parameters:
        kName - file name
        kMesh - TriMesh
        keyImage - image
        Throws:
        java.io.IOException - file I/O exception
      • saveClodMesh

        public static void saveClodMesh​(java.lang.String kName,
                                        WildMagic.LibGraphics.Detail.ClodMesh[] akComponent,
                                        boolean flip,
                                        int[] direction,
                                        float[] startLocation,
                                        float[] box,
                                        TransMatrix inverseDicomMatrix)
        Save ClodMesh to disk
        Parameters:
        kName - file name
        akComponent - array of ClodMesh to save
        flip - invert y,z values
        direction - 3D mesh orientation
        startLocation - 3D mesh location
        box - mesh bounding box
        inverseDicomMatrix - dicom matrix
      • saveSurfaces

        public static void saveSurfaces​(ModelImage kImage,
                                        WildMagic.LibGraphics.SceneGraph.TriMesh[] akSurfaces,
                                        java.lang.String kCommand)
        The action taken when the one of the save surface buttons is pressed in the JPanelSurface class. A file dialog is launched that allows the user to select where to save the surfaces.
        Parameters:
        kImage - the ModelImage displayed in the SurfaceRender class
        akSurfaces - an array of surfaces described by their SurfaceAttributes, containing information that is saved with the TriMesh
        kCommand - the type of save operation to perform
      • saveAsVRML

        protected static void saveAsVRML​(java.io.PrintWriter kOut,
                                         WildMagic.LibGraphics.SceneGraph.TriMesh kMesh,
                                         WildMagic.LibGraphics.SceneGraph.VertexBuffer kVBuffer,
                                         boolean flip,
                                         int[] direction,
                                         float[] startLocation,
                                         float[] box)
        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 saved
        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 axis
        startLocation - DOCUMENT ME!
        box - (dimension-1)*resolution
        color - DOCUMENT ME!
        Throws:
        java.io.IOException - if there is an error writing to the file
      • getFileName

        private static java.lang.String getFileName​(boolean bLoad)
        Calls a dialog to get a file name.
        Parameters:
        bLoad - if true, make it a load dialog.
        Returns:
        File name.
      • load

        private static WildMagic.LibGraphics.Detail.CollapseRecord load​(java.io.RandomAccessFile kIn)
        Support for loading the collapse records from a binary file.
        Parameters:
        kIn - the file from which the records are loaded
        Returns:
        CollapseRecord
        Throws:
        java.io.IOException - if the there is an error reading from the file
      • loadPlyAsciiMesh

        private static WildMagic.LibGraphics.SceneGraph.TriMesh loadPlyAsciiMesh​(java.io.File file,
                                                                                 ModelImage kImage,
                                                                                 boolean isFileCoords)
        Read a TriMesh from a Ply ascii file.
        Parameters:
        file - file storing the mesh
        Returns:
        TriMesh
      • loadSTLAsciiMesh

        private static WildMagic.LibGraphics.SceneGraph.TriMesh loadSTLAsciiMesh​(java.io.File file,
                                                                                 ModelImage kImage)
        Load the STL ASCII file.
        Parameters:
        file - STL surface file reference
        source - image
        Returns:
        TriMesh
      • loadVTKLegacyMesh

        private static WildMagic.LibGraphics.SceneGraph.TriMesh loadVTKLegacyMesh​(java.io.RandomAccessFile kIn,
                                                                                  ViewJProgressBar progress,
                                                                                  int added,
                                                                                  int total,
                                                                                  java.lang.String fileName)
        Load legacy VTK mesh.
        Parameters:
        kIn - file containing mesh
        progress - progress bar
        added - number of meshes read from file so far
        total - total number of meshes in file
        flag - invert y,z values
        Returns:
        TriMesh
        Throws:
        java.io.IOException
      • loadVTKXMLMesh

        private static WildMagic.LibGraphics.SceneGraph.TriMesh loadVTKXMLMesh​(java.lang.String absPath,
                                                                               java.lang.String fileName,
                                                                               java.lang.String dir)
        Read VTK mesh from file.
        Parameters:
        absPath - file path
        fileName - file name
        dir - file directory
        Returns:
        TriMesh
      • loadGiftiXMLMesh

        private static WildMagic.LibGraphics.SceneGraph.TriMesh loadGiftiXMLMesh​(java.lang.String absPath,
                                                                                 java.lang.String fileName,
                                                                                 java.lang.String dir)
        Read Gifti mesh from file.
        Parameters:
        absPath - file path
        fileName - file name
        dir - file directory
        Returns:
        TriMesh
      • openFiles

        public static java.io.File[] openFiles​(boolean bLoad)
        Returns an array of File objects, based on the user-selected files from the FileChooser dialog.
        Parameters:
        bLoad - whether the files are opened for reading (bLoad = true) or writing (bLoad = false)
        Returns:
        File[] array of opened files.
      • openDicomMatrixFiles

        private static java.io.File openDicomMatrixFiles​(boolean bLoad)
        Returns a dicomMatrix file objects, based on the user-selected filed from the FileChooser dialog.
        Parameters:
        bLoad - whether the files are opened for reading (bLoad = true) or writing (bLoad = false)
        Returns:
        File of opened file.
      • printAscii

        private static void printAscii​(java.io.PrintWriter kOut,
                                       WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
        Print the contents of the TriMesh in ascii format.
        Parameters:
        kOut - output
        kMesh - TriMesh
      • printSTLAscii

        private static void printSTLAscii​(java.io.PrintWriter kOut,
                                          ModelImage kImage,
                                          WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
        Print the contents of the TriMesh in STL ascii format.
        Parameters:
        kOut - output
        kMesh - TriMesh
      • printProstateSTLAscii

        private static void printProstateSTLAscii​(java.io.PrintWriter kOut,
                                                  ModelImage kImage,
                                                  WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
        Print the contents of the TriMesh in STL ascii format.
        Parameters:
        kOut - output
        kMesh - TriMesh
      • readAscii

        private static WildMagic.LibGraphics.SceneGraph.TriMesh readAscii​(java.io.File kFile)
                                                                   throws java.io.IOException
        Read a TriMesh from an ascii file.
        Parameters:
        kFile - file containing TriMesh
        Returns:
        TriMesh
        Throws:
        java.io.IOException - I/O exception
      • readLine

        private static java.lang.String readLine​(java.io.InputStream in)
                                          throws java.io.IOException
        Read a line of ASCII text from the input stream.
        Parameters:
        in - InputStream
        Returns:
        line of the ascii file as a String
        Throws:
        java.io.IOException - I/O exception
      • readPoint

        private static WildMagic.LibFoundation.Mathematics.Vector3f readPoint​(java.io.StreamTokenizer tokenizer,
                                                                              java.lang.String label)
                                                                       throws java.io.IOException
        Find the given label in the tokenizer stream and then return the next three numbers as a point. Return null if end of stream
        Parameters:
        tokenizer - stream in
        label - string label (vertex, normal ) in the STL ASCII file.
        Returns:
        Vector3f point coordinate.
        Throws:
        java.io.IOException
      • readSTLAscii

        private static WildMagic.LibGraphics.SceneGraph.TriMesh readSTLAscii​(java.io.StreamTokenizer tokenizer,
                                                                             ModelImage kImage)
                                                                      throws java.io.IOException
        Read the STL ASCII file as a single stream tokenizer.
        Parameters:
        tokenizer - stream in
        Returns:
        Triangle mesh
        Throws:
        java.io.IOException
      • loadSTLBinaryMesh

        private static WildMagic.LibGraphics.SceneGraph.TriMesh loadSTLBinaryMesh​(java.io.File file,
                                                                                  ModelImage kImage)
        Load the STL ASCII file.
        Parameters:
        file - STL surface file reference
        source - image
        Returns:
        TriMesh
      • readSTLBinary

        private static WildMagic.LibGraphics.SceneGraph.TriMesh readSTLBinary​(java.io.FileInputStream data,
                                                                              ModelImage kImage)
                                                                       throws java.io.IOException
        Method for reading binary files Execution is completly different It uses ByteBuffer for reading data and ByteOrder for retrieving the machine's endian (Needs JDK 1.4) TO-DO: 1.-Be able to read files over Internet 2.-If the amount of data expected is bigger than what is on the file then the program will block forever
        Parameters:
        file - The name of the file
        Throws:
        java.io.IOException
      • readFacetB

        private void readFacetB​(java.nio.ByteBuffer in,
                                int index)
                         throws java.io.IOException
        Method that reads a face in binary files All binary versions of the methods end by 'B' As in binary files we can read the number of faces, we don't need to use coordArray and normArray (reading binary files should be faster)
        Parameters:
        in - The ByteBuffer with the data of the object.
        index - The facet index
        Throws:
        java.io.IOException
      • readSurface

        public static WildMagic.LibGraphics.SceneGraph.TriMesh readSurface​(ModelImage kImage,
                                                                           java.io.File file,
                                                                           WildMagic.LibGraphics.Rendering.MaterialState kMaterial)
        Load a triangle mesh from the specified file and assign to it the MaterialState.
        Parameters:
        kImage - ModelImage displayed in the SurfaceRender class
        file - The triangle mesh file to load.
        kMaterial - The Material for the surface.
        Returns:
        TriMesh
      • readSurface

        public static WildMagic.LibGraphics.SceneGraph.TriMesh readSurface​(ModelImage kImage,
                                                                           java.io.File file,
                                                                           WildMagic.LibGraphics.Rendering.MaterialState kMaterial,
                                                                           boolean isFileCoords)
        Load a triangle mesh from the specified file and assign to it the MaterialState.
        Parameters:
        kImage - ModelImage displayed in the SurfaceRender class
        file - The triangle mesh file to load.
        kMaterial - The Material for the surface.
        Returns:
        TriMesh
      • saveAsTextFile

        private static void saveAsTextFile​(java.lang.String kName,
                                           WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
                                    throws java.io.IOException
        Save the TriMesh as an ascii text file.
        Parameters:
        kName - file name
        kMesh - TriMesh
        Throws:
        java.io.IOException - I/O exception
      • saveAsVRML

        private static void saveAsVRML​(java.lang.String kName,
                                       WildMagic.LibGraphics.SceneGraph.TriMesh kMesh,
                                       WildMagic.LibGraphics.SceneGraph.VertexBuffer kVBuffer,
                                       boolean flip,
                                       int[] direction,
                                       float[] startLocation,
                                       float[] box)
                                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 saved
        kMesh - TriMesh to save.
        kVBuffer - TriMesh VertexBuffer
        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)*resolution
        direction - 3D mesh orientation
        startLocation - 3D mesh location
        box - 3D mesh bounding box
        Throws:
        java.io.IOException - if the specified file could not be opened for writing
      • saveAsVTKLegacy

        private static void saveAsVTKLegacy​(java.lang.String kName,
                                            WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
                                     throws java.io.IOException
        Save the TriMesh in VTK legacy format.
        Parameters:
        kName - file name
        kMesh - TriMesh
        Throws:
        java.io.IOException - I/O exception
      • saveAsVTKXML

        private static void saveAsVTKXML​(java.lang.String fileName,
                                         WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
        Save the TriMesh in VTK format.
        Parameters:
        fileName - file name
        kMesh - TriMesh
      • saveAsGiftiXML

        private static void saveAsGiftiXML​(java.lang.String fileName,
                                           WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
        Save the TriMesh in Gifti format.
        Parameters:
        fileName - file name
        kMesh - TriMesh
      • saveCollapseRecord

        private static void saveCollapseRecord​(java.io.RandomAccessFile kOut,
                                               WildMagic.LibGraphics.Detail.CollapseRecord kRecord)
                                        throws java.io.IOException
        Support for saving the collapse records to a binary file.
        Parameters:
        kOut - the file to which the records are saved
        kRecord - CollapseRecord to save.
        Throws:
        java.io.IOException - if the there is an error writing to the file
      • saveSingleMesh

        private static void saveSingleMesh​(ModelImage kImage,
                                           boolean isSur,
                                           WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
        Saves a single level of detail to a mesh file. Opens a file dialog to get the output file name from the user.
        Parameters:
        kImage - ModelImage displayed in the SurfaceRender object
        isSur - true if .sur file, otherwise .wrl file
        kMesh - TruNesg
      • saveSingleMesh

        private static void saveSingleMesh​(java.lang.String name,
                                           ModelImage kImage,
                                           boolean isSur,
                                           WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
        Saves a single level of detail to a mesh file. The file name is passed as a parameter.
        Parameters:
        name - the file name
        kImage - ModelImage displayed in the SurfaceRender object
        isSur - true if .sur file, otherwise .wrl file
        kMesh - TriMesh
      • saveSinglePlyMesh

        private static void saveSinglePlyMesh​(java.lang.String kName,
                                              ModelImage kImage,
                                              WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
        Saves a single level of detail to a STL mesh file.
        Parameters:
        kName - file name.
        kMesh - Triangle mesh
      • saveProstatePlyMesh

        private static void saveProstatePlyMesh​(java.lang.String kName,
                                                ModelImage kImage,
                                                WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
        Saves a single level of detail to a STL mesh file.
        Parameters:
        kName - file name.
        kMesh - Triangle mesh
      • saveSingleSTLMesh

        private static void saveSingleSTLMesh​(java.lang.String kName,
                                              ModelImage kImage,
                                              WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
        Saves a single level of detail to a STL mesh file.
        Parameters:
        kName - file name.
        kMesh - Triangle mesh
      • saveProstateSTLMesh

        private static void saveProstateSTLMesh​(java.lang.String kName,
                                                ModelImage kImage,
                                                WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
        Saves a single level of detail to a STL ascii mesh file.
        Parameters:
        kName - file name.
        kMesh - Triangle mesh
      • saveSur

        private static void saveSur​(java.lang.String kName,
                                    WildMagic.LibGraphics.SceneGraph.TriMesh kMesh,
                                    int iType,
                                    WildMagic.LibGraphics.SceneGraph.VertexBuffer kVBuffer,
                                    boolean flip,
                                    int[] direction,
                                    float[] startLocation,
                                    float[] box,
                                    TransMatrix inverseDicomMatrix)
                             throws java.io.IOException
        Write the TriMesh to disk in the .sur format.
        Parameters:
        kName - file name.
        kMesh - TriMesh.
        iType - type == 0 for TriMesh, type == 1 for ClodMesh
        kVBuffer - TriMesh VertexBuffer
        flip - flag for inverting the y,z values
        direction - 3D mesh direction
        startLocation - 3D mesh location
        box - 3D mesh bounding box
        inverseDicomMatrix - dicom matrix information.
        Throws:
        java.io.IOException - if there is an error writing to the file
      • writeTriangleMeshXML

        private static void writeTriangleMeshXML​(java.lang.String kName,
                                                 ModelImage kImage,
                                                 WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
        Writes a TriMesh to disk in the xml format, based on surface.xsd.
        Parameters:
        kName - file name.
        kImage - ModelImage associated with the TriMesh.
        kMesh - TriMesh surface mesh.
      • convertVertex

        private static WildMagic.LibGraphics.SceneGraph.VertexBuffer convertVertex​(ModelImage kImage,
                                                                                   WildMagic.LibGraphics.SceneGraph.TriMesh kMesh)
        Convert the vertex from display space to dicom space.
        Parameters:
        kImage - ModelImage
        kMesh - Triangle mesh
        Returns:
        kVBuffer Converted vertex buffer