MeVisLab Toolbox Reference
SoCSOEditorTools.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2012, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 
15 
16 #pragma once
17 
18 #include <CSOBase/CSOBoundingBox.h>
19 #include <mlLinearAlgebra.h>
20 #include <SoCSODefines.h>
21 
22 
23 class View2DSliceList;
24 class SoCSOTransform;
26 
27 namespace ml
28 {
29  class CSO;
30  class CSOVisualizationSettings;
31 }
32 
34 {
36  {
38  SLICE_IN = 1,
39  SLICE_ABOVE = 2
40  };
41 
43  {
46  };
47 
49  {
50  unsigned int csoID;
51 
61 
62  std::string imageModality;
65  };
66 
69  {
72  };
73 
75  struct vectorXSort
76  {
77  bool operator ()(const ml::Vector2& a, const ml::Vector2& b) const
78  {
79  return a[0] < b[0];
80  }
81  };
82 
84  {
86 
87  bool shouldUseStippling() const { return stipplePattern != 0xffff; }
89  unsigned short stipplePattern;
90  float width;
91 
92  SbColor color;
93  float alpha;
94 
95  SbColor outlineColor;
96  float outlineAlpha;
97  };
98 
99 
105  void setStatisticsToUserData(ml::CSO* cso, const ImageStatisticsForCSO& statistics, const std::string& viewerIdentifier="");
106 
107  void setUserDataWithViewerId(ml::CSO* cso, const std::string& userDataName, const std::string& viewerIdentifier, const ml::Variant& value);
108 
111  void fillCrossingsVector(std::vector< std::vector< ml::Vector2 > >& crossingsVector,
112  const std::vector< ml::Vector3 >& pathPoints,
113  const ml::Vector3& minBB, const ml::Vector3& maxBB);
114 
116  void retrieveDicomTagData(SoSFMLImage* image, std::string& modality, float& rescaleIntercept, float& rescaleSlope);
117 
118 
120  ml::CSOBoundingBox computeSlabBoundingBox(float deviceX, float deviceY, View2DSliceList* slicelist);
122  ml::CSOBoundingBox computeSlabBoundingBox(int voxelZ, View2DSliceList* slicelist, int voxelAugmentInZ=0);
124  bool isOnCurrentSlice(SoView2DCSOExtensibleEditor* editor, const CSODrawCSOInfos& csoDrawInfos, const CSODrawView2DInfos& view2DInfos);
126  bool isOnCurrentSlice(ml::CSO* cso, const CSODrawView2DInfos& view2DInfos);
128  bool isOnCurrentSlice(ml::CSO* cso, View2DSliceList* slicelist, const ml::Vector3& sliceNormalWorld, SoCSOTransform* csoTransform);
132  bool isApproximatelyParallel(ml::CSO*cso, View2DSliceList* slicelist, float epsilon=-1);
135  void fillWorldSliceCrossings(const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos,
136  std::vector<CSOSliceCrossing>& belowSlicePositions,
137  std::vector<CSOSliceCrossing>& inSlicePositions,
138  std::vector<CSOSliceCrossing>& aboveSlicePositions);
141  void getWorldSlicePlanes(const CSODrawView2DInfos& view2DInfos, ml::Plane& topPlane, ml::Plane& bottomPlane);
142 
144  void fillCrossingsOnePlaneCrossed(const ml::Plane& plane, const ml::Vector3& lastPosition, const ml::Vector3& currentPosition,
145  CSOSliceCrossing& sliceCrossings, std::vector<CSOSliceCrossing>* crossings[3],
146  int lastSlicePosition);
148  void fillCrossingsBothPlanesCrossed(const ml::Plane& topPlane, const ml::Plane& bottomPlane,
149  const ml::Vector3& lastPosition, const ml::Vector3& currentPosition, int relativePosition,
150  CSOSliceCrossing &sliceCrossings, std::vector<CSOSliceCrossing>* crossings[3]);
151 
153  void fillWorldToVoxelMatrix(const CSODrawView2DInfos& view2DInfos, ml::Matrix4& worldToVoxelMatrix);
155  void fillWorldToVoxelMatrix(const SoPointerPosition& pos, ml::Matrix4& worldToVoxelMatrix);
157  void fillWorldToVoxelMatrix(View2DSliceList* sliceList, ml::Matrix4& worldToVoxelMatrix);
159  void fillWorldToVoxelMatrix(const SbMatrix& inventorMatrix, ml::Matrix4& worldToVoxelMatrix);
160 
162  void fillVoxelToWorldMatrix(const CSODrawView2DInfos& view2DInfos, ml::Matrix4& voxelToWorldMatrix);
164  void fillVoxelToWorldMatrix(const SoPointerPosition& pos, ml::Matrix4& voxelToWorldMatrix);
166  void fillVoxelToWorldMatrix(View2DSliceList* sliceList, ml::Matrix4& voxelToWorldMatrix);
168  void fillVoxelToWorldMatrix(const SbMatrix& inventorMatrix, ml::Matrix4& voxelToWorldMatrix);
169 
171  bool isAbovePlane(const ml::Vector3& worldPosition, const ml::Plane& plane);
173  bool evaluateHitPoint(const ml::Vector3& worldPosition, View2DSliceList* slicelist, ml::CSOList* csoList,
174  const ml::CSOBoundingBox& slabBB, const std::string& subType, SoView2DCSOExtensibleEditor* editor,
175  bool testSeedPoints,
176  ml::CSO*& localHitCSO, ml::CSOSeedPoint*& localHitSeedPoint,
177  ml::CSOPathPoints*& localHitPathPoints, float& distanceToCSO);
178 
180  bool isEligibleForPicking(ml::CSO* cso, ml::CSOList* csoList, const std::string& subType, View2DSliceList* slicelist, SoView2DCSOExtensibleEditor* editor);
188  float getSquaredDeviceDistance(const ml::Vector3& worldPosition, View2DSliceList* slicelist, float dMouseX, float dMouseY);
190  void mapWorldToDevice(View2DSliceList* slicelist, const ml::Vector3& worldPosition, float& devX, float& devY);
192  float getSquaredDeviceLineDistance(const ml::Vector3& lineWorldStart, const ml::Vector3& lineWorldEnd, View2DSliceList* slicelist, float dMouseX, float dMouseY);
194  bool isOnSameSlab(const ml::CSOBoundingBox& slabBB, const ml::CSOBoundingBox& csoBB);
196  bool intersectsSlice(const ml::CSOBoundingBox& slabBB, const CSOVoxelSlab& csoBB);
198  bool areOnSamePlane(ml::CSO* cso1, ml::CSO* cso2, float epsilon=0.00001f);
200  bool areOnSamePlane(ml::CSO* cso, const ml::Vector3& position, const ml::Vector3& normal, float epsilon=0.00001f);
201 
204  void drawLines(GLint lineMode, const std::vector<ml::Vector3>& positions,
205  const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos,
206  const SbVec2f& deviceOffset);
207 
209  void getRightmostSeedPointPosition(const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos, float& deviceX, float& deviceY);
211  void getRightMostPathPointPositionOnCurrentSlice(const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos, float& deviceX, float& deviceY);
214  void getRightmostSeedPointPositionAndVector(const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos, float& deviceX, float& deviceY, float& deviceVX, float& deviceVY);
216  SbVec2f convertDevicePositionToRelativeViewerPosition(View2DSlice* slice, const SbVec2f& deviceVector);
218  SbVec2f convertRelativeViewerPositionToDevicePosition(View2DSlice* slice, const SbVec2f& relativeVector);
219 
222  bool mapWorldToDeviceViaVoxel(const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos,
223  const ml::Vector3& position, float& deviceX, float& deviceY);
224 
226  void setupGLAntiAlias(bool shouldUseAntiAliasing);
229 
231  bool enableGLStipplingIfNeeded(unsigned short pattern);
232 
234  bool isNearDeviceBoundingBox(View2DSliceList* slicelist, const ml::CSOBoundingBox &box, float selectionDistance, float dMouseX, float dMouseY);
235 
237  static std::vector<float> _lineBuffer;
238 }
Abstract Open Inventor base class for uniform shader parameter nodes.
SoPointerPosition manages the current position of the mouse cursor.
The SoSFMLImage field is the interface used by Inventor Nodes to access image data (in the current im...
Definition: SoSFMLImage.h:70
SoView2D is a 2D viewer for image data.
Definition: SoView2D.h:62
a list that holds all View2DSlice objects (lazily created) of a SoView2D
a single slice that is stored in a View2DSliceList, typically created by a View2DSliceList
Definition: View2DSlice.h:48
The CSOBoundingBox defines an axis parallel bounding box with double precision.
A CSOList comprises a number of CSOs and CSOGroups and is the central object for contour segmentation...
Definition: CSOList.h:61
The CSOPathPoints is a list of world coordinates which are interpolated by a certain interpolation sc...
Definition: CSOPathPoints.h:37
The CSOSeedPoint can be interactively set and modified and is the framework for contours.
Definition: CSOSeedPoint.h:35
The CSO represents a contour segmentation object.
Definition: CSO.h:44
Class defining a plane in 3D.
Definition: mlPlane.h:30
The Variant class stores different data types.
Definition: mlVariant.h:36
UINT64 MLuint64
Introduce platform independent 64 bit unsigned integer type.
Definition: mlTypeDefs.h:513
double MLdouble
Definition: mlTypeDefs.h:223
void fillVoxelToWorldMatrix(const CSODrawView2DInfos &view2DInfos, ml::Matrix4 &voxelToWorldMatrix)
Fills the given matrix with the slice's voxelToWorld matrix.
void drawLines(GLint lineMode, const std::vector< ml::Vector3 > &positions, const CSODrawCSOInfos &csoInfos, const CSODrawView2DInfos &view2DInfos, const SbVec2f &deviceOffset)
Draws the given points as a line strip or loop, depending on the lineMode.
float getSquaredDeviceDistance(const ml::Vector3 &worldPosition, View2DSliceList *slicelist, float dMouseX, float dMouseY)
Returns the squared distance in device coordinates from the given world position to the given device ...
void fillCrossingsOnePlaneCrossed(const ml::Plane &plane, const ml::Vector3 &lastPosition, const ml::Vector3 &currentPosition, CSOSliceCrossing &sliceCrossings, std::vector< CSOSliceCrossing > *crossings[3], int lastSlicePosition)
Fills the crossings vector.
SbVec2f convertRelativeViewerPositionToDevicePosition(View2DSlice *slice, const SbVec2f &relativeVector)
Converts the given position relative to the viewer's size to a device position.
void getRightMostPathPointPositionOnCurrentSlice(const CSODrawCSOInfos &csoInfos, const CSODrawView2DInfos &view2DInfos, float &deviceX, float &deviceY)
Fills the device coordinates with the right most path point position projected on the current slice o...
float getParallelThicknessAbsoluteValue(View2DSliceList *slicelist, ml::CSOVisualizationSettings *vSettings)
Returns the absolute value for the parallel thickness.
bool isEligibleForPicking(ml::CSO *cso, ml::CSOList *csoList, const std::string &subType, View2DSliceList *slicelist, SoView2DCSOExtensibleEditor *editor)
Returns whether the given CSO is eligible for picking.
bool enableGLStipplingIfNeeded(unsigned short pattern)
Enables/disables GL stippling if pattern requires stippling (if pattern == 0xffff,...
void retrieveDicomTagData(SoSFMLImage *image, std::string &modality, float &rescaleIntercept, float &rescaleSlope)
Fills the given variables with values obtained from DICOM tags.
void getWorldSlicePlanes(const CSODrawView2DInfos &view2DInfos, ml::Plane &topPlane, ml::Plane &bottomPlane)
Fills the given top/bottom planes with planes in world space that lies on top and on bottom of the cu...
void setStatisticsToUserData(ml::CSO *cso, const ImageStatisticsForCSO &statistics, const std::string &viewerIdentifier="")
Sets the given statistics to the CSO as user data.
bool isAbovePlane(const ml::Vector3 &worldPosition, const ml::Plane &plane)
Returns whether the given point is above the given plane.
void getRightmostSeedPointPositionAndVector(const CSODrawCSOInfos &csoInfos, const CSODrawView2DInfos &view2DInfos, float &deviceX, float &deviceY, float &deviceVX, float &deviceVY)
Fills the device coordinates with the right most seed point position of the CSO (assumed to be a Dist...
void mapWorldToDevice(View2DSliceList *slicelist, const ml::Vector3 &worldPosition, float &devX, float &devY)
Maps the given world position to device position.
void fillWorldToVoxelMatrix(const CSODrawView2DInfos &view2DInfos, ml::Matrix4 &worldToVoxelMatrix)
Fills the given matrix with the slice's worldToVoxel matrix.
bool areOnSamePlane(ml::CSO *cso1, ml::CSO *cso2, float epsilon=0.00001f)
Returns whether the two given CSOs are lying on the same plane.
ImageStatisticsForCSO performImageStatistics(ml::CSO *cso, SoSFMLImage *image)
Reads out the given image and performs image voxel value statistics for the given CSO.
void setUserDataWithViewerId(ml::CSO *cso, const std::string &userDataName, const std::string &viewerIdentifier, const ml::Variant &value)
bool hasTransformation(ml::CSO *cso, SoView2D *viewer, SoView2DCSOExtensibleEditor *editor)
Returns whether there exists a transformation between the CSO and the viewer.
bool isApproximatelyParallel(ml::CSO *cso, View2DSliceList *slicelist, float epsilon=-1)
Returns whether the given CSO is parallel to the current 2D image considering the allowed thickness.
bool shouldRenderCSODependingOnImageCreation(ml::CSO *cso, SoView2DCSOExtensibleEditor *editor, View2DSliceList *slicelist)
Returns whether the given CSO should be rendered on the image depending whether it was created on it.
bool isOnCurrentSlice(SoView2DCSOExtensibleEditor *editor, const CSODrawCSOInfos &csoDrawInfos, const CSODrawView2DInfos &view2DInfos)
Returns whether the given CSO is visible on the current slice.
static std::vector< float > _lineBuffer
Used to avoid reallocation on line rendering.
SbVec2f convertDevicePositionToRelativeViewerPosition(View2DSlice *slice, const SbVec2f &deviceVector)
Converts the given device position to a position relative to the viewer's size.
void fillCrossingsBothPlanesCrossed(const ml::Plane &topPlane, const ml::Plane &bottomPlane, const ml::Vector3 &lastPosition, const ml::Vector3 &currentPosition, int relativePosition, CSOSliceCrossing &sliceCrossings, std::vector< CSOSliceCrossing > *crossings[3])
Fills the crossings vector.
bool mapWorldToDeviceViaVoxel(const CSODrawCSOInfos &csoInfos, const CSODrawView2DInfos &view2DInfos, const ml::Vector3 &position, float &deviceX, float &deviceY)
Maps the given world position to device coordinates via voxel coordinate; z in voxel space is set to ...
ml::CSOBoundingBox computeSlabBoundingBox(float deviceX, float deviceY, View2DSliceList *slicelist)
Computes and returns the bounding box in voxel space of a slice at the given device position.
bool isOnSameSlab(const ml::CSOBoundingBox &slabBB, const ml::CSOBoundingBox &csoBB)
Returns whether the two given voxel bounding boxes lie on the same slab.
void getRightmostSeedPointPosition(const CSODrawCSOInfos &csoInfos, const CSODrawView2DInfos &view2DInfos, float &deviceX, float &deviceY)
Fills the device coordinates with the right most seed point position of the CSO in the viewer.
bool evaluateHitPoint(const ml::Vector3 &worldPosition, View2DSliceList *slicelist, ml::CSOList *csoList, const ml::CSOBoundingBox &slabBB, const std::string &subType, SoView2DCSOExtensibleEditor *editor, bool testSeedPoints, ml::CSO *&localHitCSO, ml::CSOSeedPoint *&localHitSeedPoint, ml::CSOPathPoints *&localHitPathPoints, float &distanceToCSO)
Returns whether a CSO was hit and fills the according structures. If subType is an empty string,...
float getSquaredDeviceLineDistance(const ml::Vector3 &lineWorldStart, const ml::Vector3 &lineWorldEnd, View2DSliceList *slicelist, float dMouseX, float dMouseY)
Returns the squared distance in device coordinates from the given line in world positions to the give...
bool isInteractionAllowedBecauseOfRegistration(ml::CSO *cso, SoView2D *viewer, SoView2DCSOExtensibleEditor *editor)
Returns whether any interaction is allowed because of registration information.
void fillWorldSliceCrossings(const CSODrawCSOInfos &csoInfos, const CSODrawView2DInfos &view2DInfos, std::vector< CSOSliceCrossing > &belowSlicePositions, std::vector< CSOSliceCrossing > &inSlicePositions, std::vector< CSOSliceCrossing > &aboveSlicePositions)
Fills the given vectors with positions below, in, and above the current slice.
void setupGLAntiAlias(bool shouldUseAntiAliasing)
Sets OpenGL antialiasing parameters.
void fillCrossingsVector(std::vector< std::vector< ml::Vector2 > > &crossingsVector, const std::vector< ml::Vector3 > &pathPoints, const ml::Vector3 &minBB, const ml::Vector3 &maxBB)
Fills the given crossingsVector with crossings of rays in x-direction with the path points segments.
bool isNearDeviceBoundingBox(View2DSliceList *slicelist, const ml::CSOBoundingBox &box, float selectionDistance, float dMouseX, float dMouseY)
Returns if the mouse device position is near the given voxel bounding box in device coords.
void restoreGLAntiAlias()
Undoes changes to OpenGL state applied by setupGLAntiAlias.
bool intersectsSlice(const ml::CSOBoundingBox &slabBB, const CSOVoxelSlab &csoBB)
Returns whether the two given voxel bounding boxes lie on the same slab.
Main documentation file for ML users and developers.
Definition: SoSFMLImage.h:51
Defines the z slab of a CSO bounding box in voxel coordinates.
Definition: SoCSODefines.h:112
Structure for handling path points segments.
For sorting Vector3s according to their x-component.
bool operator()(const ml::Vector2 &a, const ml::Vector2 &b) const