Class Clipping
java.lang.Object
com.eco.bio7.spatial.Clipping
Clipping of the volume and the iso surface in the 3D view (to make the
interior visible):
- A clipping box: the parts outside of the box are removed (relative positions 0 - 1 in the extent of the displayed data).
- A free cutting plane (azimuth, elevation and offset). The part on the front side of the plane is removed (flip removes the other side).
- A slice: the cross-section of the plane with the data (the colors of the volume, see VolumeRenderer) and the outline of the plane.
Voxels can be removed with a mask (cuts with an ImageJ selection, a mask image or an array, see cutRoi and setMask). The mask is applied to the volume and to the mesh of the iso surface.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThe removed voxels (immutable).static interfaceThe listener of the measurement tools: the mouse events with the window position (pixels of the OpenGL surface, y from the top) and the view ray through the data (relative positions, start and end, or null outside).static final classThe region of the clipping (the kept side of the box and the plane and the kept voxels of the mask) for relative positions (0 - 1, y = 0 is the first row like in ImageJ). -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMeasurement: an angle (three clicks, the second point is the vertex).static final intThe mouse removes voxels along the view direction (Shift: restores voxels).static final intMeasurement: a freehand area on the surface (drag).static final intThe mouse rotates the view (no tool).static final intA mouse click picks a point on the displayed data (see setPickListener): a line (ruler).static final intThe mouse moves the cutting plane (Shift: rotates the plane).static final intMeasurement: single points (position, value, object).static final intMeasurement: a polygon on the surface (clicks, a double-click closes it).static final intMeasurement: a straight line (two clicks or a drag).static final intThe surface eraser: a drag removes the visible triangles of the iso surface under the brush (cut open).static final intMeasurement: the volume of an object (click) or inside of an outline (drag). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChangeListener(Runnable listener) Adds a listener which is called after a change of the clipping (not in the user interface thread).voidbegin(com.jogamp.opengl.GL2 gl, double[] bounds) Enables the clip planes for the following rendering (the scene coordinates of the current model view matrix).booleanReturns true if a change of the mask can be undone.voidRemoves the mask (all cuts).booleancutRoi(ij.gui.Roi roi, int w, int h, int d, boolean inside, int firstSlice, int lastSlice) Removes the voxels inside (or outside) of a selection (in the pixel coordinates of a stack with the given size) in a range of slices.booleancutRoi(ij.ImagePlus imp, boolean inside) Removes the voxels inside (or outside) of the selection of the image in all slices (the cuts are combined, see undoCut and clearMask).booleancutRoi(ij.ImagePlus imp, boolean inside, int firstSlice, int lastSlice) Removes the voxels inside (or outside) of the selection of the image in a range of slices (the cuts are combined, see undoCut and clearMask).voiddrawOutline(com.jogamp.opengl.GL2 gl, double[] bounds) Draws the outline of the cutting plane (if enabled).voidend(com.jogamp.opengl.GL2 gl) Disables the clip planes.double[]getBox()Returns the box (xmin, xmax, ymin, ymax, zmin, zmax relative 0 - 1).intgetMask()Returns the mask of the removed voxels or null.double[]getPlane()List<double[]> getPlanes(double[] bounds) Returns the planes of the box and of the cutting plane (if enabled).getRegion(double[] extent, boolean flip) Returns the region of the clipping.intgetTool()voidInverts the mask (the removed voxels are kept and vice versa).booleanisActive()Returns true if a clipping is enabled.booleanbooleanbooleanisFlip()static booleanisMeasureTool(int tool) Returns true if the tool is a measurement tool (see setMeasureToolListener).booleanbooleanbooleanReturns true if the shift key was pressed with the last press of the mouse.booleanisSlice()List<double[]> planePolygon(double[] bounds) Returns the polygon of the cutting plane inside of the (clipped) box (the corners in scene coordinates, sorted around the center) or null.double[]projectToWindow(double[] relative) Returns the window position (pixels of the OpenGL surface, y from the top, like the mouse events of the tools) of a position of the data (relative 0 - 1, y = 0 is the first row) in the last drawn frame, or null.double[][]rayAt(double x, double y) Returns the view ray (start and end, relative positions 0 - 1 of the data) of a window position (pixels of the OpenGL surface, from the left and from the top, like the mouse events of the tools) in the last drawn frame, or null.voidremoveChangeListener(Runnable listener) voidreset()Resets the box, the plane (disabled), the mesh cut and removes the mask.voidsetBox(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) Sets the clipping box (relative positions 0 - 1 in the extent of the displayed data, y is the vertical axis).voidsetBoxEnabled(boolean enabled) voidsetBoxLimit(int axis, boolean max, double value) Sets the minimum or maximum of an axis (axis 0 = x, 1 = y, 2 = z).voidsetCutMesh(boolean cutMesh) Cuts the mesh of the iso surface with the box and the plane (computed again, the cut surface is closed with caps and is exported).voidsetDataSize(int w, int h, int d) Sets the size of the displayed data (the resolution of a new mask of the eraser).voidsetEraserSize(int size) Sets the radius of the eraser (in voxels of the mask).voidsetFlip(boolean flip) Removes the other side of the plane.voidsetMask(boolean[] keep, int w, int h, int d) Sets a mask (e.g., of a model): the voxels with false are removed.voidsetMask(ij.ImagePlus imp) Sets a mask image (a binary stack, e.g., of a segmentation): the voxels with the value 0 are removed (the current channel and frame).voidSets the listener of the measurement tools (see MeasureToolListener).voidsetOutline(boolean outline) Draws the outline of the cutting plane.voidsetPickListener(Consumer<double[][]> listener) Sets the listener of the pick tool (TOOL_PICK).voidsetPlane(double azimuth, double elevation, double offset) Sets the cutting plane.voidsetPlaneEnabled(boolean enabled) voidsetSlice(boolean slice) Displays the cross-section of the plane with the data (see VolumeRenderer).voidsetTool(int tool) Sets the mouse tool of the 3D view (the left mouse button): TOOL_NONE, TOOL_PLANE or TOOL_ERASER.voidsetView(com.jogamp.opengl.GL2 gl, double[] bounds, boolean flip) Stores the matrices of the view for the mouse tools (of each frame).voidtoolDragged(double x, double y) Continues the drag of the mouse tool (see toolPressed).voidtoolMoved(double x, double y) The mouse moved without a pressed button: sent to the measurement tools (e.g., the preview of the volume tool).booleantoolPressed(double x, double y, boolean shift) Starts a drag of the mouse tool.booleantoolPressed(double x, double y, boolean shift, int clickCount) Starts a drag of the mouse tool (see toolPressed(double, double, boolean)) with the click count of the mouse event (2 = a double-click, e.g., closes a polygon).voidEnds the drag of the mouse tool.voidtoolReleased(double x, double y) Ends the drag of the mouse tool at the window position (see toolPressed).voidundoCut()Undoes the last change of the mask (a cut, setMask, invertMask or clearMask).
-
Field Details
-
TOOL_NONE
public static final int TOOL_NONEThe mouse rotates the view (no tool).- See Also:
-
TOOL_PLANE
public static final int TOOL_PLANEThe mouse moves the cutting plane (Shift: rotates the plane).- See Also:
-
TOOL_ERASER
public static final int TOOL_ERASERThe mouse removes voxels along the view direction (Shift: restores voxels).- See Also:
-
TOOL_PICK
public static final int TOOL_PICKA mouse click picks a point on the displayed data (see setPickListener): a line (ruler).- See Also:
-
TOOL_POINT
public static final int TOOL_POINTMeasurement: single points (position, value, object).- See Also:
-
TOOL_POLYGON
public static final int TOOL_POLYGONMeasurement: a polygon on the surface (clicks, a double-click closes it).- See Also:
-
TOOL_FREEHAND
public static final int TOOL_FREEHANDMeasurement: a freehand area on the surface (drag).- See Also:
-
TOOL_VOLUME
public static final int TOOL_VOLUMEMeasurement: the volume of an object (click) or inside of an outline (drag).- See Also:
-
TOOL_STRAIGHT
public static final int TOOL_STRAIGHTMeasurement: a straight line (two clicks or a drag).- See Also:
-
TOOL_ANGLE
public static final int TOOL_ANGLEMeasurement: an angle (three clicks, the second point is the vertex).- See Also:
-
TOOL_SURFACE_ERASER
public static final int TOOL_SURFACE_ERASERThe surface eraser: a drag removes the visible triangles of the iso surface under the brush (cut open).- See Also:
-
-
Constructor Details
-
Clipping
public Clipping()
-
-
Method Details
-
isMeasureTool
public static boolean isMeasureTool(int tool) Returns true if the tool is a measurement tool (see setMeasureToolListener). -
setMeasureToolListener
Sets the listener of the measurement tools (see MeasureToolListener). -
isShiftPressed
public boolean isShiftPressed()Returns true if the shift key was pressed with the last press of the mouse. -
getRegion
Returns the region of the clipping.- Parameters:
extent- the displayed size of the data (width, height, depth with the z scale)flip- true if the first row of the data is at the bottom- Returns:
- the region
-
setPickListener
Sets the listener of the pick tool (TOOL_PICK). The listener gets the view ray through the data: the start and the end point (relative positions 0 - 1, y = 0 is the first row) and is not called in the user interface thread. -
addChangeListener
Adds a listener which is called after a change of the clipping (not in the user interface thread). -
removeChangeListener
-
isActive
public boolean isActive()Returns true if a clipping is enabled. -
isBoxEnabled
public boolean isBoxEnabled() -
setBoxEnabled
public void setBoxEnabled(boolean enabled) -
setBox
public void setBox(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax) Sets the clipping box (relative positions 0 - 1 in the extent of the displayed data, y is the vertical axis). -
getBox
public double[] getBox()Returns the box (xmin, xmax, ymin, ymax, zmin, zmax relative 0 - 1). -
setBoxLimit
public void setBoxLimit(int axis, boolean max, double value) Sets the minimum or maximum of an axis (axis 0 = x, 1 = y, 2 = z). -
isPlaneEnabled
public boolean isPlaneEnabled() -
setPlaneEnabled
public void setPlaneEnabled(boolean enabled) -
setPlane
public void setPlane(double azimuth, double elevation, double offset) Sets the cutting plane.- Parameters:
azimuth- the direction of the normal around the vertical axis (degree, 0 = +x)elevation- the elevation of the normal (degree, 90 = upwards)offset- the position along the normal (-1 - 1, 0 = the center)
-
getPlane
public double[] getPlane() -
isFlip
public boolean isFlip() -
setFlip
public void setFlip(boolean flip) Removes the other side of the plane. -
isOutline
public boolean isOutline() -
setOutline
public void setOutline(boolean outline) Draws the outline of the cutting plane. -
isSlice
public boolean isSlice() -
setSlice
public void setSlice(boolean slice) Displays the cross-section of the plane with the data (see VolumeRenderer). -
isCutMesh
public boolean isCutMesh() -
setCutMesh
public void setCutMesh(boolean cutMesh) Cuts the mesh of the iso surface with the box and the plane (computed again, the cut surface is closed with caps and is exported). Else only the display is clipped. -
getTool
public int getTool() -
setTool
public void setTool(int tool) Sets the mouse tool of the 3D view (the left mouse button): TOOL_NONE, TOOL_PLANE or TOOL_ERASER. -
getEraserSize
public int getEraserSize() -
setEraserSize
public void setEraserSize(int size) Sets the radius of the eraser (in voxels of the mask). -
setDataSize
public void setDataSize(int w, int h, int d) Sets the size of the displayed data (the resolution of a new mask of the eraser). -
setView
public void setView(com.jogamp.opengl.GL2 gl, double[] bounds, boolean flip) Stores the matrices of the view for the mouse tools (of each frame).- Parameters:
gl- the OpenGL context (the scene coordinates of the current model view matrix)bounds- the extent of the data (x0, x1, y0, y1, z0, z1) or nullflip- true if the first row of the data is at the bottom
-
toolPressed
public boolean toolPressed(double x, double y, boolean shift) Starts a drag of the mouse tool.- Parameters:
x- the x position (pixels of the OpenGL surface, from the left)y- the y position (pixels of the OpenGL surface, from the top)shift- true if the shift key is pressed- Returns:
- true if the tool handles the drag (else the view is rotated)
-
toolPressed
public boolean toolPressed(double x, double y, boolean shift, int clickCount) Starts a drag of the mouse tool (see toolPressed(double, double, boolean)) with the click count of the mouse event (2 = a double-click, e.g., closes a polygon). -
toolMoved
public void toolMoved(double x, double y) The mouse moved without a pressed button: sent to the measurement tools (e.g., the preview of the volume tool). -
toolDragged
public void toolDragged(double x, double y) Continues the drag of the mouse tool (see toolPressed). -
toolReleased
public void toolReleased()Ends the drag of the mouse tool. -
toolReleased
public void toolReleased(double x, double y) Ends the drag of the mouse tool at the window position (see toolPressed). -
rayAt
public double[][] rayAt(double x, double y) Returns the view ray (start and end, relative positions 0 - 1 of the data) of a window position (pixels of the OpenGL surface, from the left and from the top, like the mouse events of the tools) in the last drawn frame, or null. -
projectToWindow
public double[] projectToWindow(double[] relative) Returns the window position (pixels of the OpenGL surface, y from the top, like the mouse events of the tools) of a position of the data (relative 0 - 1, y = 0 is the first row) in the last drawn frame, or null. -
reset
public void reset()Resets the box, the plane (disabled), the mesh cut and removes the mask. -
getMask
Returns the mask of the removed voxels or null. -
cutRoi
public boolean cutRoi(ij.ImagePlus imp, boolean inside) Removes the voxels inside (or outside) of the selection of the image in all slices (the cuts are combined, see undoCut and clearMask).- Parameters:
imp- the image with the selection (the size of the stack of the volume or iso surface)inside- true removes the inside, false the outside of the selection- Returns:
- false if the image has no area selection
-
cutRoi
public boolean cutRoi(ij.ImagePlus imp, boolean inside, int firstSlice, int lastSlice) Removes the voxels inside (or outside) of the selection of the image in a range of slices (the cuts are combined, see undoCut and clearMask).- Parameters:
imp- the image with the selection (the size of the stack of the volume or iso surface)inside- true removes the inside, false the outside of the selectionfirstSlice- the first slice (1 - n)lastSlice- the last slice (1 - n, larger values are the last slice)- Returns:
- false if the image has no area selection
-
cutRoi
public boolean cutRoi(ij.gui.Roi roi, int w, int h, int d, boolean inside, int firstSlice, int lastSlice) Removes the voxels inside (or outside) of a selection (in the pixel coordinates of a stack with the given size) in a range of slices.- Parameters:
roi- the area selectionw- the width of the stackh- the height of the stackd- the number of slices of the stackinside- true removes the inside, false the outside of the selectionfirstSlice- the first slice (1 - n)lastSlice- the last slice (1 - n, larger values are the last slice)- Returns:
- false if the selection is not an area
-
setMask
public void setMask(ij.ImagePlus imp) Sets a mask image (a binary stack, e.g., of a segmentation): the voxels with the value 0 are removed (the current channel and frame). The previous cuts are replaced.- Parameters:
imp- the mask image (the size of the stack of the volume or iso surface)
-
setMask
public void setMask(boolean[] keep, int w, int h, int d) Sets a mask (e.g., of a model): the voxels with false are removed. The previous cuts are replaced.- Parameters:
keep- the kept voxels (index = (z * height + y) * width + x)w- the widthh- the heightd- the depth
-
invertMask
public void invertMask()Inverts the mask (the removed voxels are kept and vice versa). -
undoCut
public void undoCut()Undoes the last change of the mask (a cut, setMask, invertMask or clearMask). -
canUndoCut
public boolean canUndoCut()Returns true if a change of the mask can be undone. -
clearMask
public void clearMask()Removes the mask (all cuts). -
begin
public void begin(com.jogamp.opengl.GL2 gl, double[] bounds) Enables the clip planes for the following rendering (the scene coordinates of the current model view matrix).- Parameters:
gl- the OpenGL contextbounds- the extent of the data (x0, x1, y0, y1, z0, z1)
-
getPlanes
Returns the planes of the box and of the cutting plane (if enabled). Kept are the points with a x + b y + c z + d >= 0 (the normal (a, b, c) has the length 1, the distance is in the units of the bounds).- Parameters:
bounds- the extent of the data (x0, x1, y0, y1, z0, z1)- Returns:
- the planes (a, b, c, d)
-
end
public void end(com.jogamp.opengl.GL2 gl) Disables the clip planes. -
planePolygon
Returns the polygon of the cutting plane inside of the (clipped) box (the corners in scene coordinates, sorted around the center) or null.- Parameters:
bounds- the extent of the data (x0, x1, y0, y1, z0, z1)- Returns:
- the polygon or null
-
drawOutline
public void drawOutline(com.jogamp.opengl.GL2 gl, double[] bounds) Draws the outline of the cutting plane (if enabled).
-