Class Sculptor
- java.lang.Object
-
- gov.nih.mipav.view.renderer.J3D.volumeview.Sculptor
-
- All Implemented Interfaces:
java.awt.event.MouseListener,java.awt.event.MouseMotionListener,java.util.EventListener
- Direct Known Subclasses:
TextureSculptor,VolumeSculptor
public abstract class Sculptor extends java.lang.Object implements java.awt.event.MouseMotionListener, java.awt.event.MouseListenerVolume 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. Volume Sculpturing works in both the Raycast and Shearwarp volume render views through the VolumeSculptor.java implementation and on the VolumeTexture render views through the TextureSculptor.java implemetation.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.
Removing Sculpted Voxels
The process of applying the sculpt region to the volume data and removing the voxels that fall inside the sculpt region is broken down into three steps. First, the ModelImage data is retrieved and the center and spacing of the data is determined. Second, the viewing transformations are calculated. Third, the voxels are mapped into screen space and the location of the voxel is compared to the corresponding pixel. If the voxel maps to a pixel inside the sculpt region its value is set to the minimum voxel value.
- Author:
- Alexandra Bokinsky, Ph.D. Under contract from Magic Software.
- See Also:
ViewJFrameVolumeView,RayCastVolumeRenderer,ShearWarpVolumeRenderer
-
-
Field Summary
Fields Modifier and Type Field Description protected doubledAMinAlphaDOCUMENT ME!protected doubledAMinBlueDOCUMENT ME!protected doubledAMinGreenDOCUMENT ME!protected doubledAMinRedDOCUMENT ME!protected doubledBMinAlphaDOCUMENT ME!protected doubledBMinBlueDOCUMENT ME!protected doubledBMinGreenDOCUMENT ME!protected doubledBMinRedDOCUMENT ME!private intdrawShapeShape of the drawing rectangle.protected floatfImageBMinDOCUMENT ME!protected floatfImageMinMin and Max image intensity and color values:.static intLINESDOCUMENT ME!protected int[]m_aiImageA_backupBackup of the data for undo:.protected int[]m_aiImageB_backupDOCUMENT ME!protected int[]m_aiXPointsMouse positions in x,y for drawing the sculpt region:.protected int[]m_aiYPointsDOCUMENT ME!protected booleanm_bMousePressedm_bMousePressed is set to true when the mousePressed callback is activated and the left mouse button is down.protected booleanm_bSculptDrawnDOCUMENT ME!protected booleanm_bSculptEnabledm_bSculptEnabled is turned on when the user presses the "Draw Sculpt Outline" button.protected intm_iColorSculptThe sculpt region color.protected intm_iFirstXDOCUMENT ME!protected intm_iFirstYDOCUMENT ME!protected intm_iLastXDOCUMENT ME!protected intm_iLastYDOCUMENT ME!protected intm_iNumberPointsDOCUMENT ME!protected intm_iOriginalHeightDOCUMENT ME!protected intm_iOriginalWidthThe original canvas size.protected intm_iPreviousXPrevious and first mouse positions:.protected intm_iPreviousYDOCUMENT ME!protected intm_iSculptImageHeightDOCUMENT ME!protected intm_iSculptImageWidthSize of the m_kSculptImage, when it is captured.protected intm_iXMaxDOCUMENT ME!protected intm_iXMinThe min and max x,y mouse values:.protected intm_iYMaxDOCUMENT ME!protected intm_iYMinDOCUMENT ME!protected javax.media.j3d.Canvas3Dm_kCanvas3DCanvas3D reference for drawing :.protected javax.swing.JProgressBarm_kProgressGreen Progress bar at the top right hand corner of the ViewJFrameVolumeView window.protected java.awt.image.BufferedImagem_kSavedImageDOCUMENT ME!protected java.awt.image.BufferedImagem_kSculptImagem_kSculptImage is a screen shot of the canvas image.protected java.awt.image.BufferedImagem_kSculptImageOpaqueDOCUMENT ME!static intRECTANGLEDOCUMENT ME!
-
Constructor Summary
Constructors Constructor Description Sculptor()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract booleanapplySculpt()applySculpt: abstract function, implementation depends on whether the instance is VolumeTextureSculptor or VolumeSculptor.protected voidbackupImage(ModelImage kImageA, ModelImage kImageB)Called by the TextureSculptor or VolumeSculptor objects.protected voidbackupImage(ModelImage kImageA, ModelImage kImageB, int iIndex)Called by the TextureSculptor or VolumeSculptor objects.protected intblendColor(int iImageColor, int iBlendColor)blendColor: blends two colors in ARGB format from the BufferedImage class, using an alpha value of 0.5.protected voidcalculateMinMaxValues(ModelImage kImageA, ModelImage kImageB)Called by the TextureSculptor or VolumeSculptor objects.voidclearSculpt()clearSculpt: called by ViewJFrameVolumeView when the user presses the "Clear Ouline" button, clearing the sculpt outline from the canvas image.voiddisposeLocal(boolean flag)Sets all variables to null, disposes, and garbage collects.protected voiddrawRectangleArea()Draw rectangle shape object.voidenableSculpt(boolean bEnabled)enableSculpt: called by the ViewJFrameVolumeView object when the Draw Sculpt button is pressed.protected voidfill(int[][] aaiCrossingPoints, int[] aiNumCrossings)fill: fill the sculpt outline drawn by the user.protected voidfinalize()Calls disposeLocal.booleangetEnable()DOCUMENT ME!protected booleangetFrameBuffer()Grab the canvas image, and copy into the m_kSculptImage data members.voidinitVolumeSculptor(int iSculptWidth, int iSculptHeight)Initialize the Mouse events, store the progress bar, and get the original canvas widths.voidinvertSculpt()invertSculpt: called by ViewJFrameVolumeView when the user presses the "Invert Sculpt Region" button, inverting the sculpt region.protected voidline(int iX0, int iY0, int iX1, int iY1)This function draws a 2D line on the canvas image -- ontop of the currently rendered image.voidmouseClicked(java.awt.event.MouseEvent kEvent)One of the overrides necessary to be a MouseListener.voidmouseDragged(java.awt.event.MouseEvent kEvent)Invoked when the mouse is dragged while a button is held down.voidmouseEntered(java.awt.event.MouseEvent kEvent)One of the overrides necessary to be a MouseListener.voidmouseExited(java.awt.event.MouseEvent kEvent)Invoked when the mouse leaves a component.voidmouseMoved(java.awt.event.MouseEvent kEvent)One of the overrides necessary to be a MouseMotionListener.voidmousePressed(java.awt.event.MouseEvent kEvent)Invoked when a mouse button is pressed.voidmouseReleased(java.awt.event.MouseEvent kEvent)Invoked when a mouse button is released.protected voidoutlineRegion(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 voidprocessMouseReleased(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 fragged outside the canvas area.protected voidsculptImage(ModelImage kImageA, ModelImage kImageB, int iIndex)Called by the TextureSculptor or VolumeSculptor objects.voidsetDrawingShape(int shape)Set the shape of the drawing sculptor.protected voidsortCrossingPoints(int[] aiList, int iNumElements)Sorts the edge crossing points in place.abstract voidundoSculpt()undoSculpt: abstract function, implementation depends on whether the instance is VolumeTextureSculptor or VolumeSculptor.protected voidundoSculpt(ModelImage kImageA, ModelImage kImageB)Called by the TextureSculptor or VolumeSculptor objects.abstract voidupdate()DOCUMENT ME!
-
-
-
Field Detail
-
LINES
public static int LINES
DOCUMENT ME!
-
RECTANGLE
public static int RECTANGLE
DOCUMENT ME!
-
dAMinAlpha
protected double dAMinAlpha
DOCUMENT ME!
-
dAMinBlue
protected double dAMinBlue
DOCUMENT ME!
-
dAMinGreen
protected double dAMinGreen
DOCUMENT ME!
-
dAMinRed
protected double dAMinRed
DOCUMENT ME!
-
dBMinAlpha
protected double dBMinAlpha
DOCUMENT ME!
-
dBMinBlue
protected double dBMinBlue
DOCUMENT ME!
-
dBMinGreen
protected double dBMinGreen
DOCUMENT ME!
-
dBMinRed
protected double dBMinRed
DOCUMENT ME!
-
fImageBMin
protected float fImageBMin
DOCUMENT ME!
-
fImageMin
protected float fImageMin
Min and Max image intensity and color values:.
-
m_aiImageA_backup
protected int[] m_aiImageA_backup
Backup of the data for undo:.
-
m_aiImageB_backup
protected int[] m_aiImageB_backup
DOCUMENT ME!
-
m_aiXPoints
protected int[] m_aiXPoints
Mouse positions in x,y for drawing the sculpt region:.
-
m_aiYPoints
protected int[] m_aiYPoints
DOCUMENT ME!
-
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
DOCUMENT ME!
-
m_bSculptEnabled
protected boolean m_bSculptEnabled
m_bSculptEnabled is turned on when the user presses the "Draw Sculpt Outline" button.
-
m_iColorSculpt
protected int m_iColorSculpt
The sculpt region color.
-
m_iFirstX
protected int m_iFirstX
DOCUMENT ME!
-
m_iFirstY
protected int m_iFirstY
DOCUMENT ME!
-
m_iLastX
protected int m_iLastX
DOCUMENT ME!
-
m_iLastY
protected int m_iLastY
DOCUMENT ME!
-
m_iNumberPoints
protected int m_iNumberPoints
DOCUMENT ME!
-
m_iOriginalHeight
protected int m_iOriginalHeight
DOCUMENT ME!
-
m_iOriginalWidth
protected int m_iOriginalWidth
The original canvas size. This is used if the ViewJFrameVolumeView window is resized by the user.
-
m_iPreviousX
protected int m_iPreviousX
Previous and first mouse positions:.
-
m_iPreviousY
protected int m_iPreviousY
DOCUMENT ME!
-
m_iSculptImageHeight
protected int m_iSculptImageHeight
DOCUMENT ME!
-
m_iSculptImageWidth
protected int m_iSculptImageWidth
Size of the m_kSculptImage, when it is captured.
-
m_iXMax
protected int m_iXMax
DOCUMENT ME!
-
m_iXMin
protected int m_iXMin
The min and max x,y mouse values:.
-
m_iYMax
protected int m_iYMax
DOCUMENT ME!
-
m_iYMin
protected int m_iYMin
DOCUMENT ME!
-
m_kCanvas3D
protected javax.media.j3d.Canvas3D m_kCanvas3D
Canvas3D reference for drawing :.
-
m_kProgress
protected javax.swing.JProgressBar m_kProgress
Green Progress bar at the top right hand corner of the ViewJFrameVolumeView window.
-
m_kSavedImage
protected java.awt.image.BufferedImage m_kSavedImage
DOCUMENT ME!
-
m_kSculptImage
protected java.awt.image.BufferedImage m_kSculptImage
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. m_kSculptImageOpaque is filled with solid color, but not displayed, it is used to test whether voxels are inside the sculpt region.
-
m_kSculptImageOpaque
protected java.awt.image.BufferedImage m_kSculptImageOpaque
DOCUMENT ME!
-
drawShape
private int drawShape
Shape of the drawing rectangle.
-
-
Method Detail
-
applySculpt
public abstract boolean applySculpt()
applySculpt: abstract function, implementation depends on whether the instance is VolumeTextureSculptor or VolumeSculptor.- Returns:
- DOCUMENT ME!
-
undoSculpt
public abstract void undoSculpt()
undoSculpt: abstract function, implementation depends on whether the instance is VolumeTextureSculptor or VolumeSculptor.
-
update
public abstract void update()
DOCUMENT ME!
-
clearSculpt
public void clearSculpt()
clearSculpt: called by ViewJFrameVolumeView when the user presses the "Clear Ouline" button, clearing the sculpt outline from the canvas image. The function disables sculpting and reactivates the mouse events for the m_kVolumeRenderer.
-
disposeLocal
public void disposeLocal(boolean flag)
Sets all variables to null, disposes, and garbage collects.- Parameters:
flag- DOCUMENT ME!
-
enableSculpt
public void enableSculpt(boolean bEnabled)
enableSculpt: called by the ViewJFrameVolumeView object when the Draw Sculpt button is pressed. This function deactivates the m_kVolumeRenderer's mouse response, so the mouse can be used to draw the sculpt outline. It also allocates and initializes the m_iSculptImage buffer for drawing.- Parameters:
bEnabled- DOCUMENT ME!
-
getEnable
public boolean getEnable()
DOCUMENT ME!- Returns:
- DOCUMENT ME!
-
initVolumeSculptor
public void initVolumeSculptor(int iSculptWidth, int iSculptHeight)Initialize the Mouse events, store the progress bar, and get the original canvas widths. Disable sculpting and drawing with the mouse. Note - this function should be called once per instance only, as it sets up the MouseMotionListener and MouseListener.- Parameters:
iSculptWidth- DOCUMENT ME!iSculptHeight- DOCUMENT ME!
-
invertSculpt
public void invertSculpt()
invertSculpt: called by ViewJFrameVolumeView when the user presses the "Invert Sculpt Region" button, inverting the sculpt region.
-
mouseClicked
public void mouseClicked(java.awt.event.MouseEvent kEvent)
One of the overrides necessary to be a MouseListener. This function is invoked when a button has been pressed and released.- Specified by:
mouseClickedin interfacejava.awt.event.MouseListener- Parameters:
kEvent- the mouse event generated by a mouse clicked
-
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:
mouseDraggedin interfacejava.awt.event.MouseMotionListener- Parameters:
kEvent- the mouse event generated by a mouse drag
-
mouseEntered
public void mouseEntered(java.awt.event.MouseEvent kEvent)
One of the overrides necessary to be a MouseListener. Invoked when the mouse enters a component.- Specified by:
mouseEnteredin interfacejava.awt.event.MouseListener- Parameters:
kEvent- the mouse event generated by a mouse entered
-
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:
mouseExitedin interfacejava.awt.event.MouseListener- Parameters:
kEvent- the mouse event generated by a mouse exit
-
mouseMoved
public void mouseMoved(java.awt.event.MouseEvent kEvent)
One of the overrides necessary to be a MouseMotionListener. Invoked when the mouse is moved, but no buttons are pressed.- Specified by:
mouseMovedin interfacejava.awt.event.MouseMotionListener- Parameters:
kEvent- the event generated by a mouse movement
-
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:
mousePressedin interfacejava.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:
mouseReleasedin interfacejava.awt.event.MouseListener- Parameters:
kEvent- the mouse event generated by a mouse release
-
setDrawingShape
public void setDrawingShape(int shape)
Set the shape of the drawing sculptor.- Parameters:
shape- 0 for LINES, 1 for RECTANGLE
-
backupImage
protected void backupImage(ModelImage kImageA, ModelImage kImageB)
Called by the TextureSculptor or VolumeSculptor objects. The function stores the original volume data back to the original values in the m_aiImage_backup data members.- Parameters:
kImageA- DOCUMENT ME!kImageB- DOCUMENT ME!
-
backupImage
protected void backupImage(ModelImage kImageA, ModelImage kImageB, int iIndex)
Called by the TextureSculptor or VolumeSculptor objects. The function stores the original volume data back to the original values in the m_aiImage_backup data members.- Parameters:
kImageA- DOCUMENT ME!kImageB- DOCUMENT ME!iIndex- DOCUMENT ME!
-
blendColor
protected int blendColor(int iImageColor, int iBlendColor)blendColor: blends two colors in ARGB format from the BufferedImage class, using an alpha value of 0.5.- Parameters:
iImageColor- DOCUMENT ME!iBlendColor- DOCUMENT ME!- Returns:
- DOCUMENT ME!
-
calculateMinMaxValues
protected void calculateMinMaxValues(ModelImage kImageA, ModelImage kImageB)
Called by the TextureSculptor or VolumeSculptor objects. The function calculates the mimumum and maximum intensity and color values in the images.- Parameters:
kImageA- DOCUMENT ME!kImageB- DOCUMENT ME!
-
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!
-
finalize
protected void finalize() throws java.lang.ThrowableCalls disposeLocal.- Overrides:
finalizein classjava.lang.Object- Throws:
java.lang.Throwable- DOCUMENT ME!
-
getFrameBuffer
protected boolean getFrameBuffer()
Grab the canvas image, and copy into the m_kSculptImage data members.- Returns:
- DOCUMENT ME!
-
line
protected void line(int iX0, int iY0, int iX1, int iY1)This function draws a 2D line on the canvas image -- ontop 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- DOCUMENT ME!iY0- DOCUMENT ME!iX1- DOCUMENT ME!iY1- DOCUMENT ME!
-
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 fragged 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.
-
sculptImage
protected void sculptImage(ModelImage kImageA, ModelImage kImageB, int iIndex)
Called by the TextureSculptor or VolumeSculptor objects. The function sculpts the original volume data by setting the value at input iIndex to the mimimum values calculated in CalculateMinMaxValues.- Parameters:
kImageA- DOCUMENT ME!kImageB- DOCUMENT ME!iIndex- DOCUMENT ME!
-
sortCrossingPoints
protected void sortCrossingPoints(int[] aiList, int iNumElements)Sorts the edge crossing points in place.- Parameters:
aiList- DOCUMENT ME!iNumElements- DOCUMENT ME!
-
undoSculpt
protected void undoSculpt(ModelImage kImageA, ModelImage kImageB)
Called by the TextureSculptor or VolumeSculptor objects. The function resets the volume data back to the original values, using the data stored in the m_aiImage_backup data members.- Parameters:
kImageA- DOCUMENT ME!kImageB- DOCUMENT ME!
-
-