Class Sculptor_WM

  • All Implemented Interfaces:
    java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.util.EventListener

    public class Sculptor_WM
    extends java.lang.Object
    implements java.awt.event.MouseMotionListener, java.awt.event.MouseListener
    Volume Sculpturing allows the user to draw a region on the screen in the volume render view, and to remove the parts of the volume covered by that region. The user outlines a region by holding the left mouse button down and drawing directly on the screen.

    The user draws an outline on the screen, and defines the cut-away or sculpture region. If the user chooses to apply the sculpture region to the volume, the voxels defined by an extruded volume of the cut-away region are removed. This is done by projecting the voxels in the volume into screen space and determining which voxels fall inside the sculpture region. Voxels that are inside the sculpture region are set to the minimum voxel value, which is rendered as transparent. The user may also undo volume sculpturing, returning the volume data to its original values.

    Drawing the Sculpt Region on the Screen

    The VolumeSculptor class implements both MouseListener and MouseMotionListener interfaces. Drawing is done through the mousePressed, mouseReleased, and mouseDragged functions.

    When sculpting is enabled, the viewing transformations (rotation, scale, translation) are disabled, so the left mouse button can be used for drawing on the screen instead of rotating the volume. Second, the view canvas is captured and stored. When the left mouse button is pressed, the VolumeSculptor class captures and stores all subsequent mouse positions, and draws them directly into the canvas image, connecting the mouse positions by drawing 2D lines on the image. On a mouseReleased event the outline is closed by connecting the first and last recorded mouse positions and the outline region is filled in. The line drawing and polygon filling functions are implemented as 2D scan-conversion algorithms and are drawn directly by the VolumeSculptor onto the canvas image. This implementation allows concave and self-intersecting outlines.

    Multiple outlines may be drawn on the canvas image before applying the sculpt regions to the volume. Because the sculpt regions are in image space, to apply the sculpt region to the volume, it is simply necessary to project the volume voxels onto the canvas image. Voxels that project onto blue pixels in the canvas image are removed, and voxels that project to non-masked pixels are unaltered.

    Author:
    Alexandra Bokinsky, Ph.D. Under contract from GeometricTools, Inc.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int drawShape
      Shape of the drawing rectangle.
      static int LINES
      Free-hand sculpting
      protected int[] m_aiColorSculpt
      The sculpt region color.
      protected int[] m_aiXPoints
      Mouse positions in x,y for drawing the sculpt region:.
      protected int[] m_aiYPoints
      Mouse positions in x,y for drawing the sculpt region:.
      protected byte[] m_aucSavedImage
      Backup image
      protected byte[] m_aucSculptImage
      m_kSculptImage is a screen shot of the canvas image.
      private byte[] m_aucTextureImageDataA
      Texture data for ModelImage A in byte
      private byte[] m_aucTextureImageDataB
      Texture data for ModelImage B in byte
      protected boolean m_bMousePressed
      m_bMousePressed is set to true when the mousePressed callback is activated and the left mouse button is down.
      protected boolean m_bSculptDrawn
      True when a sculpt region has been drawn.
      protected boolean m_bSculptEnabled
      m_bSculptEnabled is turned on when the user presses the "Draw Sculpt Outline" button.
      protected int m_iFirstX
      First x mouse position
      protected int m_iFirstY
      First y mouse position
      protected int m_iLastX
      Last x mouse position
      protected int m_iLastY
      Last y mouse position
      protected int m_iNumberPoints
      Number of points in the free-hand line.
      protected int m_iPreviousX
      Previous and first mouse positions:.
      protected int m_iPreviousY
      Previous and first mouse positions:.
      protected int m_iSculptImageHeight
      sculpt image height
      protected int m_iSculptImageWidth
      sculpt image width
      protected int m_iXMax
      The min and max x,y mouse values
      protected int m_iXMin
      The min and max x,y mouse values
      protected int m_iYMax
      The min and max x,y mouse values
      protected int m_iYMin
      The min and max x,y mouse values
      protected com.jogamp.opengl.awt.GLCanvas m_kCanvas
      Canvas reference for drawing :.
      private ModelImage m_kImageA
      ModelImage A
      private ModelImage m_kImageB
      ModelImage B
      private ModelImage m_kImageBackupA
      Backup of ModelImage A
      private ModelImage m_kImageBackupB
      Backup of ModelImage B
      private WildMagic.LibFoundation.Mathematics.Matrix4f m_kWVPMatrix
      World-view-project matrix for applying the sculpt to the volume.
      static int RECTANGLE
      rectangle sculpt
    • Constructor Summary

      Constructors 
      Constructor Description
      Sculptor_WM​(com.jogamp.opengl.awt.GLCanvas kCanvas)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean applySculpt​(int iTSlice)
      Apply the sculpt region to the volume data.
      private void backupData​(ModelImage kImage, ModelImage kImageBackup, int iDataIndex)
      Backup ModelImage data.
      private void backupSculptImage()
      Backup the sculpt image.
      void clearSculpt()
      Clears the sculpt image.
      void disposeLocal()
      Memory cleanup.
      protected void drawRectangleArea()
      Draw rectangle shape object.
      void enableSculpt​(boolean bEnabled)
      Turn sculpt drawing on/off.
      protected void fill​(int[][] aaiCrossingPoints, int[] aiNumCrossings)
      fill: fill the sculpt outline drawn by the user.
      boolean getEnable()
      Return the sculpt enabled status.
      private boolean getSculpt​(int iX, int iY)
      Get the sculpt on/off at the position.
      byte[] getSculptImage()
      Return sculpt image for display.
      void initVolumeSculptor()
      Initialize the Mouse listener.
      void invertSculpt()
      Inverts the sculpt image.
      private void invertSculpt​(int iX, int iY, int[] aiColors)
      Invert the sculpt image at the position
      boolean IsSculptDrawn()
      Return true if the sculpt image has been drawn.
      protected void line​(int iX0, int iY0, int iX1, int iY1, int[] aiColors)
      This function draws a 2D line on the canvas image -- on top of the currently rendered image.
      void mouseClicked​(java.awt.event.MouseEvent kEvent)  
      void mouseDragged​(java.awt.event.MouseEvent kEvent)
      Invoked when the mouse is dragged while a button is held down.
      void mouseEntered​(java.awt.event.MouseEvent kEvent)  
      void mouseExited​(java.awt.event.MouseEvent kEvent)
      Invoked when the mouse leaves a component.
      void mouseMoved​(java.awt.event.MouseEvent kEvent)  
      void mousePressed​(java.awt.event.MouseEvent kEvent)
      Invoked when a mouse button is pressed.
      void mouseReleased​(java.awt.event.MouseEvent kEvent)
      Invoked when a mouse button is released.
      protected void outlineRegion​(int[][] aaiCrossingPoints, int[] aiNumCrossings)
      This function computes the set of spans indicated by column crossings for the sculpt outline drawn by the user, by doing a polygon scan conversion in gridded space.
      protected void processMouseReleased​(int iX, int iY)
      Called when the left mouse button is released, indicating that the sculpt outline is complete, or when the outline is being drawn and the mouse is dragged outside the canvas area.
      boolean save​(FileWriteOptions options, int filterType)
      Creates save dialog so that the image can be saved // This should be moved to imageModel.save();
      private void sculptData​(ModelImage kImage, int iDataIndex, int iTextureIndex, byte[] aucTextureImageData)
      Sculpt the ModelImage and Textures at the index.
      void setDrawingShape​(int shape)
      Set the shape of the drawing sculptor.
      void setImage​(ModelImage kImageA, ModelImage kImageB)
      Set the ModelImage data
      private void setSculpt​(int iX, int iY, int[] aiColors)
      Set the sculpt image
      void setSculptDrawn​(boolean value)  
      void setSculptImage​(byte[] abImage)  
      void setTextureImageDataA​(byte[] data)
      Set the texture data byte[] for ModelImage A
      void setTextureImageDataB​(byte[] data)
      Set the texture data byte[] for ModelImage B
      void setWVPMatrix​(WildMagic.LibFoundation.Mathematics.Matrix4f kMatrix)
      Set the World-view-projection matrix from the renderer.
      protected void sortCrossingPoints​(int[] aiList, int iNumElements)
      Sorts the edge crossing points in place.
      void undoSculpt​(int iTSlice)
      Undo the sculpt.
      • Methods inherited from class java.lang.Object

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

      • LINES

        public static int LINES
        Free-hand sculpting
      • RECTANGLE

        public static int RECTANGLE
        rectangle sculpt
      • m_aiXPoints

        protected int[] m_aiXPoints
        Mouse positions in x,y for drawing the sculpt region:.
      • m_aiYPoints

        protected int[] m_aiYPoints
        Mouse positions in x,y for drawing the sculpt region:.
      • m_bMousePressed

        protected boolean m_bMousePressed
        m_bMousePressed is set to true when the mousePressed callback is activated and the left mouse button is down.
      • m_bSculptDrawn

        protected boolean m_bSculptDrawn
        True when a sculpt region has been drawn.
      • m_bSculptEnabled

        protected boolean m_bSculptEnabled
        m_bSculptEnabled is turned on when the user presses the "Draw Sculpt Outline" button.
      • m_aiColorSculpt

        protected int[] m_aiColorSculpt
        The sculpt region color.
      • m_iFirstX

        protected int m_iFirstX
        First x mouse position
      • m_iFirstY

        protected int m_iFirstY
        First y mouse position
      • m_iLastX

        protected int m_iLastX
        Last x mouse position
      • m_iLastY

        protected int m_iLastY
        Last y mouse position
      • m_iNumberPoints

        protected int m_iNumberPoints
        Number of points in the free-hand line.
      • m_iPreviousX

        protected int m_iPreviousX
        Previous and first mouse positions:.
      • m_iPreviousY

        protected int m_iPreviousY
        Previous and first mouse positions:.
      • m_iSculptImageHeight

        protected int m_iSculptImageHeight
        sculpt image height
      • m_iSculptImageWidth

        protected int m_iSculptImageWidth
        sculpt image width
      • m_iXMax

        protected int m_iXMax
        The min and max x,y mouse values
      • m_iXMin

        protected int m_iXMin
        The min and max x,y mouse values
      • m_iYMax

        protected int m_iYMax
        The min and max x,y mouse values
      • m_iYMin

        protected int m_iYMin
        The min and max x,y mouse values
      • m_kCanvas

        protected com.jogamp.opengl.awt.GLCanvas m_kCanvas
        Canvas reference for drawing :.
      • m_aucSavedImage

        protected byte[] m_aucSavedImage
        Backup image
      • m_aucSculptImage

        protected byte[] m_aucSculptImage
        m_kSculptImage is a screen shot of the canvas image. The sculpt region is drawn directly into m_kSculptImage. The outline is filled by alpha-blending the Sculpt region color with the m_kSculptImage backgound image.
      • drawShape

        private int drawShape
        Shape of the drawing rectangle.
      • m_kImageA

        private ModelImage m_kImageA
        ModelImage A
      • m_kImageBackupA

        private ModelImage m_kImageBackupA
        Backup of ModelImage A
      • m_kImageB

        private ModelImage m_kImageB
        ModelImage B
      • m_kImageBackupB

        private ModelImage m_kImageBackupB
        Backup of ModelImage B
      • m_kWVPMatrix

        private WildMagic.LibFoundation.Mathematics.Matrix4f m_kWVPMatrix
        World-view-project matrix for applying the sculpt to the volume.
      • m_aucTextureImageDataA

        private byte[] m_aucTextureImageDataA
        Texture data for ModelImage A in byte
      • m_aucTextureImageDataB

        private byte[] m_aucTextureImageDataB
        Texture data for ModelImage B in byte
    • Constructor Detail

      • Sculptor_WM

        public Sculptor_WM​(com.jogamp.opengl.awt.GLCanvas kCanvas)
        Constructor.
        Parameters:
        kCanvas - the canvas to draw the sculpt image on.
    • Method Detail

      • applySculpt

        public boolean applySculpt​(int iTSlice)
        Apply the sculpt region to the volume data.
        Returns:
        true if the volume has changed, false indicates no change.
      • clearSculpt

        public void clearSculpt()
        Clears the sculpt image.
      • disposeLocal

        public void disposeLocal()
        Memory cleanup.
      • enableSculpt

        public void enableSculpt​(boolean bEnabled)
        Turn sculpt drawing on/off.
        Parameters:
        bEnabled - turns sculpting on/off.
      • getEnable

        public boolean getEnable()
        Return the sculpt enabled status.
        Returns:
        sculpt enabled status.
      • getSculptImage

        public byte[] getSculptImage()
        Return sculpt image for display.
        Returns:
        byte[] containing the sculpt image.
      • initVolumeSculptor

        public void initVolumeSculptor()
        Initialize the Mouse listener. Note - this function should be called once per instance only, as it sets up the MouseMotionListener and MouseListener.
      • invertSculpt

        public void invertSculpt()
        Inverts the sculpt image.
      • IsSculptDrawn

        public boolean IsSculptDrawn()
        Return true if the sculpt image has been drawn.
        Returns:
        true if the sculpt image has been drawn.
      • mouseClicked

        public void mouseClicked​(java.awt.event.MouseEvent kEvent)
        Specified by:
        mouseClicked in interface java.awt.event.MouseListener
      • mouseDragged

        public void mouseDragged​(java.awt.event.MouseEvent kEvent)
        Invoked when the mouse is dragged while a button is held down. If this occurs while sculpting is enabled, then the mouse positions are stored and the sculpt outline is drawn on the canvas, using the previously recorded mouse position and the current mouse position as the start and end points of a 2D line on the canvas.
        Specified by:
        mouseDragged in interface java.awt.event.MouseMotionListener
        Parameters:
        kEvent - the mouse event generated by a mouse drag
      • mouseEntered

        public void mouseEntered​(java.awt.event.MouseEvent kEvent)
        Specified by:
        mouseEntered in interface java.awt.event.MouseListener
      • mouseExited

        public void mouseExited​(java.awt.event.MouseEvent kEvent)
        Invoked when the mouse leaves a component. This function captures the mouseExited event when the button is pressed and the sculpt outline is being drawn, so that the outline is contained within the bounds of the canvas.
        Specified by:
        mouseExited in interface java.awt.event.MouseListener
        Parameters:
        kEvent - the mouse event generated by a mouse exit
      • mouseMoved

        public void mouseMoved​(java.awt.event.MouseEvent kEvent)
        Specified by:
        mouseMoved in interface java.awt.event.MouseMotionListener
      • mousePressed

        public void mousePressed​(java.awt.event.MouseEvent kEvent)
        Invoked when a mouse button is pressed. When the left mouse button is pressed, and sculpting is enabled, then the user is beginning to outline the sculpt region. This function initializes the outline drawing, and stores the first point(x,y) so the outline can be closed on mouseReleased. The first and following mouse positions are drawn in outline form using current and previously (last recorded) positions as the start and end points of a 2D line on the canvas.
        Specified by:
        mousePressed in interface java.awt.event.MouseListener
        Parameters:
        kEvent - the mouse event generated by a mouse press
      • mouseReleased

        public void mouseReleased​(java.awt.event.MouseEvent kEvent)
        Invoked when a mouse button is released. If this happens while drawing the sculpt outline, the mouse release indicates that the outline is complete. The function closes the outline by connecting the first and last points, and then calls processMouseReleased(), which fills the outline.
        Specified by:
        mouseReleased in interface java.awt.event.MouseListener
        Parameters:
        kEvent - the mouse event generated by a mouse release
      • save

        public boolean save​(FileWriteOptions options,
                            int filterType)
        Creates save dialog so that the image can be saved // This should be moved to imageModel.save();
        Parameters:
        options - File-write options.
        filterType - only used if >= 0
        Returns:
        true on successful write, false otherwise.
      • setDrawingShape

        public void setDrawingShape​(int shape)
        Set the shape of the drawing sculptor.
        Parameters:
        shape - 0 for LINES, 1 for RECTANGLE
      • setImage

        public void setImage​(ModelImage kImageA,
                             ModelImage kImageB)
        Set the ModelImage data
        Parameters:
        kImageA - ModelImage A
        kImageB - ModelImage B (or null)
      • setSculptDrawn

        public void setSculptDrawn​(boolean value)
      • setSculptImage

        public void setSculptImage​(byte[] abImage)
      • setTextureImageDataA

        public void setTextureImageDataA​(byte[] data)
        Set the texture data byte[] for ModelImage A
        Parameters:
        data - the texture data byte[] for ModelImage A
      • setTextureImageDataB

        public void setTextureImageDataB​(byte[] data)
        Set the texture data byte[] for ModelImage B
        Parameters:
        data - the texture data byte[] for ModelImage B
      • setWVPMatrix

        public void setWVPMatrix​(WildMagic.LibFoundation.Mathematics.Matrix4f kMatrix)
        Set the World-view-projection matrix from the renderer. Used to apply the sculpt image to the volume data.
        Parameters:
        kMatrix - World-view-projection matrix
      • undoSculpt

        public void undoSculpt​(int iTSlice)
        Undo the sculpt.
      • backupData

        private void backupData​(ModelImage kImage,
                                ModelImage kImageBackup,
                                int iDataIndex)
        Backup ModelImage data.
        Parameters:
        kImage - original ModelImage
        kImageBackup - backup of ModelImage
        iDataIndex - index of the position in the ModelImage to backup
      • backupSculptImage

        private void backupSculptImage()
        Backup the sculpt image.
      • getSculpt

        private boolean getSculpt​(int iX,
                                  int iY)
        Get the sculpt on/off at the position.
        Parameters:
        iX - x-position
        iY - y-position
        Returns:
        true if the position should be sculpted, false otherwise.
      • invertSculpt

        private void invertSculpt​(int iX,
                                  int iY,
                                  int[] aiColors)
        Invert the sculpt image at the position
        Parameters:
        iX - x-position
        iY - y-position
        aiColors - sculpt color.
      • sculptData

        private void sculptData​(ModelImage kImage,
                                int iDataIndex,
                                int iTextureIndex,
                                byte[] aucTextureImageData)
        Sculpt the ModelImage and Textures at the index.
        Parameters:
        kImage - ModelImage
        iDataIndex - index to sculpt
        aucTextureImageData - byte[] Texture
        afTextureImageData - float[] Texture
      • setSculpt

        private void setSculpt​(int iX,
                               int iY,
                               int[] aiColors)
        Set the sculpt image
        Parameters:
        iX - x-position
        iY - y-position
        aiColors - sculpt color
      • drawRectangleArea

        protected void drawRectangleArea()
        Draw rectangle shape object.
      • fill

        protected void fill​(int[][] aaiCrossingPoints,
                            int[] aiNumCrossings)
        fill: fill the sculpt outline drawn by the user. Pixels are determined to be inside or outside the sculpt region based on the parameters, aaiCrossingPoints and aiNumCrossings, using a scan-conversion algorithm that traverses each row and column of the bounding box of the sculpt region coloring inside points as it goes.
        Parameters:
        aaiCrossingPoints - DOCUMENT ME!
        aiNumCrossings - DOCUMENT ME!
      • line

        protected void line​(int iX0,
                            int iY0,
                            int iX1,
                            int iY1,
                            int[] aiColors)
        This function draws a 2D line on the canvas image -- on top of the currently rendered image. To implement the line drawing I use the midpoint line algorithm, in Foley and van Dam, originally Bresenham's algorithm. The first part of the function sets up the step sizes for x and y depending on what type of line is being drawn. The second part loops over the line, drawing pixels into the canvas image.
        Parameters:
        iX0 - mouse x0
        iY0 - mouse y0
        iX1 - mouse x1
        iY1 - mouse y1
        aiColors - line color.
      • outlineRegion

        protected void outlineRegion​(int[][] aaiCrossingPoints,
                                     int[] aiNumCrossings)
        This function computes the set of spans indicated by column crossings for the sculpt outline drawn by the user, by doing a polygon scan conversion in gridded space. The outline must be closed with last point = first point.
        Parameters:
        aaiCrossingPoints - DOCUMENT ME!
        aiNumCrossings - DOCUMENT ME!
      • processMouseReleased

        protected void processMouseReleased​(int iX,
                                            int iY)
        Called when the left mouse button is released, indicating that the sculpt outline is complete, or when the outline is being drawn and the mouse is dragged outside the canvas area. The function closes the outline, using the first and last recorded mouse positions. It then fills the outline, by blending the fill color with the background data on the canvas. Filling is done as a 2D polygon scan conversion so that any closed loop, including concave and self-intersecting loops, can be processed accurately.
        Parameters:
        iX - int, the x position of the mouse recorded when the mouse button was released.
        iY - int, the y position of the mouse recorded when the mouse button was released.
      • sortCrossingPoints

        protected void sortCrossingPoints​(int[] aiList,
                                          int iNumElements)
        Sorts the edge crossing points in place.
        Parameters:
        aiList - list of positions
        iNumElements - number of positions.