MeVisLab Toolbox Reference
SoCSOEditorExtension.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 
16 
17 #pragma once
18 
19 #include <SoCSOSystem.h>
20 
22 #include "../SoCSOEditorTools.h"
23 
24 #include <ThirdPartyWarningsDisable.h>
25 #include <Inventor/nodes/SoNode.h>
26 #include <Inventor/sensors/SoFieldSensor.h>
27 #include <ThirdPartyWarningsRestore.h>
28 
29 #include <View2DPosition.h>
30 #include <SoView2D.h>
31 
33 
35 
38 class SOCSO_EXPORT SoCSOEditorExtension : public SoNode
39 {
40  SO_NODE_HEADER(SoCSOEditorExtension);
41 
42 protected:
47 
48 public:
49 
51  void setExtensibleEditor(SoView2DCSOExtensibleEditor* extensibleEditor) { _editor = extensibleEditor; }
52 
55  virtual void activate(SoView2DCSOExtensibleEditor* extensibleEditor) { setExtensibleEditor(extensibleEditor); }
58  virtual void deactivate() {}
61  virtual void buttonMaskChanged() {}
64  virtual void editingOnChanged() {}
65 
67  virtual void startDrawing(View2DSliceList* ) {}
69  virtual void drawingDone() {}
71  virtual void setVisibleCSOs(const std::vector<CSODrawCSOInfos>& drawCSOInformation,
72  const CSODrawView2DInfos& view2DInfos,
74 
76  virtual void draw(const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos, const CSODrawSliceInformation& sliceInfo, SoView2DCSOExtensibleEditor* editor);
78  virtual void drawSecondPass(const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos, const CSODrawSliceInformation& sliceInfo, SoView2DCSOExtensibleEditor* editor);
81  virtual void drawOverlay(const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos, const CSODrawSliceInformation& sliceInfo, SoView2DCSOExtensibleEditor* editor);
83  virtual void drawAdditionalGeometry(const CSODrawView2DInfos& view2DInfos, SoView2DCSOExtensibleEditor* editor);
84 
86  static void initClass();
87 
88  virtual void createStartPressAt(const SoPointerPosition& pos) = 0;
89  virtual void createDragMoveTo(const SoPointerPosition& pos) = 0;
90  // Returns whether to continue with this action.
91  virtual bool createEndPress(int clickCount) = 0;
95  virtual void pointerPositionIfAllowedAt(const SoPointerPosition& pos) = 0;
96 
97  virtual void selectAndMoveStartPressAt(const SoPointerPosition& pos) = 0;
98  virtual void selectAndMoveDragMoveTo(const SoPointerPosition& pos) = 0;
99  virtual SoPointingAction* selectAndMoveEndPress(int clickCount) = 0;
100 
103  virtual SoPointingAction* insertSeedPointEndPress(int ) { return nullptr; }
104 
105  virtual void bulgeStartPressAt(const SoPointerPosition& ) {}
106  virtual void bulgeDragMoveTo(const SoPointerPosition& ) {}
107  virtual SoPointingAction* bulgeEndPress(int ) { return nullptr; }
108 
110  virtual void pointerPosition(const SoPointerPosition&) {}
112  virtual void pointerLeftWindow() {}
113 
115  virtual bool isCreationAllowed() const { return allowCreation.getValue() == 1; }
117  virtual bool isCreationAllowedAt(const SoPointerPosition& /*pos*/) const { return isCreationAllowed(); }
119  virtual bool isModificationAllowed() const { return allowModification.getValue() == 1; }
121  virtual bool shouldRenderCSOs() const { return shouldRender.getValue(); }
123  virtual bool canCreateCSOs() const { return false; }
125  virtual ml::CSO* getActiveCSO() const { return _hitCSO; }
126 
129  virtual bool expectsToCreateCSO() { return false; }
130 
131  SbString getCreatorExtensionId() const { return extensionId.getValue(); }
132  void setActiveCSOList(ml::CSOList* hitCSOList);
133  void setSelectAndMoveInformation(ml::CSOList* hitCSOList, ml::CSO* hitCSO, ml::CSOSeedPoint* hitSeedPoint,
134  ml::CSOPathPoints* hitPathPoints, float hitDistance);
136  ml::CSO* getCSOUnderMouse() const { return _csoUnderMouse; }
137 
138  bool hasSelectedSeedPoint() const { return _hitSeedPoint != nullptr; }
139  bool hasSelectedCSO() const { return _hitCSO != nullptr; }
140 
142  virtual SbString getSubType() const { return _subType; }
144  virtual bool shouldRenderSpecific(ml::CSO* cso) const;
147  virtual bool shouldRenderGeneral(ml::CSO*) const { return false; }
149  virtual bool isDefaultRenderer() const { return false; }
151  virtual bool isModificationEditor() const { return false; }
153  virtual void resetCache() {}
154 
156  virtual void cancel() {}
158  virtual int cursorShape() const { return SoViewerProxy::CROSS_CURSOR; }
160  virtual bool deleteSeedPoint(ml::CSO* cso, ml::CSOSeedPoint* );
164 
166  SoSFString extensionId;
168  SoSFBool allowCreation;
174  SoSFBool shouldRender;
178 
179  SoSFEnum selectionCursor;
181 
184 
189  virtual void mouseWheelEventReceived(SoMouseWheelEvent::Orientation , int , View2DEvent* ) {}
190 
193  virtual bool evaluateHitPoint(const ml::Vector3& worldPosition, View2DSliceList* slicelist, ml::CSOList* csoList,
194  const ml::CSOBoundingBox& slabBB, SoView2DCSOExtensibleEditor* editor,
195  ml::CSO*& localHitCSO, ml::CSOSeedPoint*& localHitSeedPoint,
196  ml::CSOPathPoints*& localHitPathPoints, float& distance);
197 
198  void reset() { initMembers(); }
199 
203 
207 
210  virtual void sendCSOEventsOnCancel(ml::CSOList* csoList);
211 
212 
213 protected:
214 
215  virtual void initMembers();
216 
218 
220  ml::CSOListPtr _hitCSOList;
226 
239 
243  void setExtensionIdAsSubType() { _subType = extensionId.getValue().getString(); }
244 
246  virtual void setCreationData(const SoPointerPosition& pos, ml::CSO* newCSO);
247 
248  void extensionIdCB(SoField*);
249 
252 
257  SbString _subType;
258 
261 
264 
266  void drawPathPoints(const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos,
267  const CSODrawSliceInformation& drawSliceInfo, const SbVec2f& shadowOffsetDevice, SoView2DCSOExtensibleEditor* editor);
269  void renderPathPoints(const CSOPathPointsRenderSettings& renderSettings, const CSODrawCSOInfos& csoInfos,
270  const CSODrawView2DInfos& view2DInfos, const std::vector<CSOSliceCrossing>& pathPointsLists, GLint lineMode, const SbVec2f& shadowOffsetDevice);
271 
273  void drawPathAndCrossingPoints(const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos,
274  const SbVec2f& shadowOffsetDevice, const std::vector<CSOSliceCrossing>& pathAndCrossingPoints, GLint lineMode);
275 
277  void drawShape(int style, SoView2DCSOExtensibleEditor* editor, ml::CSOVisualizationSettings* visualizationSettings,
278  float deviceX, float deviceY, float size, float lineWidth = 1.f);
279 
281  void drawSeedPoints(const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos,
282  const CSODrawSliceInformation& drawSliceInfo, SoView2DCSOExtensibleEditor* editor);
283 
285  void drawFixedSizeCircleAt(float deviceX, float deviceY);
286 
288  bool isCSOVisible(const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos, const CSODrawSliceInformation& drawSliceInfo, SoView2DCSOExtensibleEditor* editor);
289 
292  ml::Vector3 getTransformedPosition(const CSODrawView2DInfos& view2DInfos, const ml::Vector3& position);
293 
295  void mapWorldToDevice(const SoPointerPosition& pos, const ml::Vector3& worldPosition, float& deviceX, float& deviceY);
297  void mapWorldToDevice(View2DSliceList* slicelist, const ml::Vector3& worldPosition, float& deviceX, float& deviceY);
299  ml::Vector3 mapDeviceToWorld(const SoPointerPosition& pos, float deviceX, float deviceY);
301  ml::Vector3 mapWorldToVoxel(const SoPointerPosition& pos, const ml::Vector3& worldPosition);
303  ml::Vector3 mapWorldToVoxel(const SoPointerPosition& pos, const SbVec3f& worldPosition);
305  ml::Vector3 mapVoxelToWorld(const SoPointerPosition& pos, const ml::Vector3& voxelPosition);
306 
308  SbVec2f nonShadowOffset() const { return SbVec2f(0,0); }
310  SbVec2f shadowOffset() const { return SbVec2f(1,1); }
312  GLint getLineMode(ml::CSO* cso);
314  void setupGLForCSO(const CSODrawCSOInfos& csoInfos);
316  void setupGLShadow(float generalAlpha=1.0f);
318  void glSetAlpha(float alpha);
320  float getDepthAlpha(int maxSliceDistance, int currentSliceDistance) const;
321 
324 };
325 
#define SOCSO_EXPORT
Header file for system independent resolution.
Definition: SoCSOSystem.h:21
Base class for an editor extension for the SoView2DCSOExtensibleEditor.
GLint getLineMode(ml::CSO *cso)
Returns the correct line mode for open and for closed CSOs.
virtual void drawSecondPass(const CSODrawCSOInfos &csoInfos, const CSODrawView2DInfos &view2DInfos, const CSODrawSliceInformation &sliceInfo, SoView2DCSOExtensibleEditor *editor)
Drawing routine that comes between 'main' and 'overlay'.
SoCSOEditorTools::LineRenderSettings getLineRenderSettingsOnSlice()
Creates a LineRenderSettings struct from the editors visualization settings "onSlice" section.
SoCSOEditorExtension()
Hidden constructor.
virtual void deactivate()
Is called when an extension is deactivated by the SoView2DExtensibleEditor.
SbVec2f shadowOffset() const
Returns the default offset for shadows in pixels.
virtual bool shouldRenderSpecific(ml::CSO *cso) const
Returns whether a given CSO should be rendered by this specific extension.
virtual void bulgeDragMoveTo(const SoPointerPosition &)
virtual void setVisibleCSOs(const std::vector< CSODrawCSOInfos > &drawCSOInformation, const CSODrawView2DInfos &view2DInfos, SoView2DCSOExtensibleEditor *editor)
Sets visible CSOs that have been determined in the extensible editor.
SoSFBool allowModification
Shall the editor allow modification of CSOs of its type?
void renderPathPoints(const CSOPathPointsRenderSettings &renderSettings, const CSODrawCSOInfos &csoInfos, const CSODrawView2DInfos &view2DInfos, const std::vector< CSOSliceCrossing > &pathPointsLists, GLint lineMode, const SbVec2f &shadowOffsetDevice)
Draws path points with given render settings.
virtual void drawAdditionalGeometry(const CSODrawView2DInfos &view2DInfos, SoView2DCSOExtensibleEditor *editor)
Routine for drawing additional geometry of the extension.
void drawShape(int style, SoView2DCSOExtensibleEditor *editor, ml::CSOVisualizationSettings *visualizationSettings, float deviceX, float deviceY, float size, float lineWidth=1.f)
Draws the shape with the given style with the given center and size.
virtual void draw(const CSODrawCSOInfos &csoInfos, const CSODrawView2DInfos &view2DInfos, const CSODrawSliceInformation &sliceInfo, SoView2DCSOExtensibleEditor *editor)
Main routine for drawing a CSO.
virtual void pointerLeftWindow()
Is called when mouse pointer leaves the window.
void setExtensibleEditor(SoView2DCSOExtensibleEditor *extensibleEditor)
Sets the pointer to the calling extensible editor.
virtual SbString getSubType() const
Returns the sub type string of the derived class.
virtual SoPointingAction * insertSeedPointEndPress(int)
SoSFInt32 csoIdUnderMouseCursor
The id of the CSO currently under the mouse (or -1 if no CSO is under the mouse).
~SoCSOEditorExtension() override
Hidden destructor.
void sendCSONotificationNewCSOStarted()
Sends a CSO notification on having started to create a new CSO.
ml::Vector3 mapWorldToVoxel(const SoPointerPosition &pos, const SbVec3f &worldPosition)
Returns a voxel position for a given world position.
void sendCSONotificationInsertSeedPoint()
Sends a CSO notification on inserting a seed point.
virtual ml::CSO * getActiveCSO() const
Returns the currently active CSO.
virtual void editingOnChanged()
Is called when the editingOn field of the SoView2DExtensibleEditor has changed.
virtual void mouseWheelEventReceived(SoMouseWheelEvent::Orientation, int, View2DEvent *)
Method is called when the extensible editor received a mouse wheel event.
ml::Vector3 getTransformedPosition(const CSODrawView2DInfos &view2DInfos, const ml::Vector3 &position)
If a SoCSOTransform exists, this method returns the transformed position.
SbVec2f nonShadowOffset() const
Returns the default offset for non-shadows in pixels.
SoView2DCSOExtensibleEditor * _editor
void setupGLForCSO(const CSODrawCSOInfos &csoInfos)
Sets up GL state for color, line width, and point size.
virtual bool isCreationAllowed() const
Returns whether the editor is allowed to create a new CSO.
virtual void activate(SoView2DCSOExtensibleEditor *extensibleEditor)
Is called when an extension is activated by the SoView2DExtensibleEditor.
virtual void startDrawing(View2DSliceList *)
Is called before drawing.
virtual void setCreationData(const SoPointerPosition &pos, ml::CSO *newCSO)
Sets creation data to a newly created CSO.
void sendCSONotificationRepaint()
Sends a CSO notification to repaint the CSOList.
virtual void createDragMoveTo(const SoPointerPosition &pos)=0
void sendCSOEventsOnCancel(ml::CSO *cso)
Sends CSO events for completing a creation or interaction when canceling it.
void drawPathPoints(const CSODrawCSOInfos &csoInfos, const CSODrawView2DInfos &view2DInfos, const CSODrawSliceInformation &drawSliceInfo, const SbVec2f &shadowOffsetDevice, SoView2DCSOExtensibleEditor *editor)
Draws the CSO by drawing lines between the path points. Renders different types of CSOs.
void sendCSONotificationResetInteractionState()
Sends a CSO notification on having the interaction state being reset.
void setupGLShadow(float generalAlpha=1.0f)
Sets up the GL state for shadow rendering (color and line width).
ml::Vector3 mapDeviceToWorld(const SoPointerPosition &pos, float deviceX, float deviceY)
Returns world coordinates for given device position.
void setExtensionIdAsSubType()
Sets the subtype member to the value of the extension id string.
virtual void drawingDone()
Is called when all drawing is done.
bool isCSOVisible(const CSODrawCSOInfos &csoInfos, const CSODrawView2DInfos &view2DInfos, const CSODrawSliceInformation &drawSliceInfo, SoView2DCSOExtensibleEditor *editor)
Returns whether the CSO is visible on the current slice.
void setCSOUnderMouse(ml::CSO *cso)
SoSFBool shouldRender
Shall the editor render its CSOs?
virtual void selectAndMoveStartPressAt(const SoPointerPosition &pos)=0
virtual void cancel()
Cancels an action like generating a CSO. Depends on concrete editor.
virtual void drawOverlay(const CSODrawCSOInfos &csoInfos, const CSODrawView2DInfos &view2DInfos, const CSODrawSliceInformation &sliceInfo, SoView2DCSOExtensibleEditor *editor)
Routine for drawing after the main routine has drawn.
void mapWorldToDevice(const SoPointerPosition &pos, const ml::Vector3 &worldPosition, float &deviceX, float &deviceY)
Returns device coordinates for a given world position.
virtual bool isModificationAllowed() const
Returns whether the editor is allowed to modify an existing CSO.
virtual bool canCreateCSOs() const
Returns whether the editor can create a CSO.
virtual bool isCreationAllowedAt(const SoPointerPosition &) const
Returns whether the editor is allowed to create a new CSO at the given position, by default calls the...
ml::CSOVisualizationSettings * getVisualizationSettings()
Returns a pointer to the visual settings that are either the default ones or the ones set to the exte...
void drawPathAndCrossingPoints(const CSODrawCSOInfos &csoInfos, const CSODrawView2DInfos &view2DInfos, const SbVec2f &shadowOffsetDevice, const std::vector< CSOSliceCrossing > &pathAndCrossingPoints, GLint lineMode)
Draws the path and crossing points.
ml::CSOVisualizationSettings _visualizationSettings
Default visual settings. Access them via the method getVisualSettings().
static void initClass()
init class in inventor runtime
virtual void insertSeedPointStartPressAt(const SoPointerPosition &)
SbString _subType
Member for subtype of generated CSOs.
bool doesCSOTimePointMatchCurrentTimePoint(const CSODrawView2DInfos &view2DInfos, ml::CSO *cso)
Returns true if the CSO's time point matches the (overwritten) current time point.
virtual void bulgeStartPressAt(const SoPointerPosition &)
virtual void createStartPressAt(const SoPointerPosition &pos)=0
SoCSOEditorTools::LineRenderSettings getLineRenderSettingsForCSO(ml::CSO *cso)
Creates a LineRenderSettings struct from the visualization attributes of the given CSO.
virtual bool deleteSeedPoint(ml::CSO *cso, ml::CSOSeedPoint *)
Removes the given seed point from the given CSO and returns whether that was successful.
SoSFBool allowSeedPointInteraction
Should the interaction with seed points be allowed?
SbString getCreatorExtensionId() const
SoSFBool allowCreation
Shall the editor allow creation?
ml::CSO * getCSOUnderMouse() const
ml::CSOPathPoints * _hitPathPoints
virtual void resetCache()
Resets internal module caches, if there are any.
SoSFMLBase inVisualizationSettings
Optionally attached visualization settings, overrides the vis.
void extensionIdCB(SoField *)
virtual SoPointingAction * selectAndMoveEndPress(int clickCount)=0
bool shouldShowCSOForCurrentTimePoint(const CSODrawView2DInfos &view2DInfos, ml::CSO *cso)
Returns whether the given CSO should be rendered for the current time point.
void sendCSONotificationFinishInteraction()
Sends a CSO notification on finishing an interaction with a CSO.
ml::CSOSeedPoint * _hitSeedPoint
virtual bool evaluateHitPoint(const ml::Vector3 &worldPosition, View2DSliceList *slicelist, ml::CSOList *csoList, const ml::CSOBoundingBox &slabBB, SoView2DCSOExtensibleEditor *editor, ml::CSO *&localHitCSO, ml::CSOSeedPoint *&localHitSeedPoint, ml::CSOPathPoints *&localHitPathPoints, float &distance)
Returns whether the given world position is within the selection distance set in the editor and fills...
virtual bool createEndPress(int clickCount)=0
virtual void buttonMaskChanged()
Is called when the button mask of the SoView2DExtensibleEditor has changed.
virtual void selectAndMoveDragMoveTo(const SoPointerPosition &pos)=0
virtual bool expectsToCreateCSO()
Returns whether an editor is awaiting to create a new CSO, depending on the requireMousemovement flag...
void drawFixedSizeCircleAt(float deviceX, float deviceY)
Renders a fixed size circle at the given position.
ml::Vector3 mapWorldToVoxel(const SoPointerPosition &pos, const ml::Vector3 &worldPosition)
Returns a voxel position for a given world position.
virtual bool shouldRenderGeneral(ml::CSO *) const
Returns whether a given CSO should be rendered by this general extension.
ml::Vector3 mapVoxelToWorld(const SoPointerPosition &pos, const ml::Vector3 &voxelPosition)
Returns a world position for a given voxel position.
void glSetAlpha(float alpha)
Sets an alpha value but retains the set color.
virtual void insertSeedPointDragMoveTo(const SoPointerPosition &)
void setActiveCSOList(ml::CSOList *hitCSOList)
void sendCSONotificationMove()
Sends a CSO notification on moving a CSO or seed point.
virtual void pointerPositionIfAllowedAt(const SoPointerPosition &pos)=0
Sets seed points while moving the mouse – but not while dragging.
virtual int cursorShape() const
Returns the cursor shape that indicates the next creation.
ml::CSOSeedPoint * getPreviousSeedPoint(ml::CSOSeedPoint *seedPoint) const
Returns the previous seed point of the given seed point for setting it as the next selected seed poin...
SoSFString extensionId
ID for a editor, needs to be unique per editor extension instance.
virtual void pointerPosition(const SoPointerPosition &)
Is called when the mouse moves over a viewer.
virtual SoPointingAction * bulgeEndPress(int)
void drawSeedPoints(const CSODrawCSOInfos &csoInfos, const CSODrawView2DInfos &view2DInfos, const CSODrawSliceInformation &drawSliceInfo, SoView2DCSOExtensibleEditor *editor)
Draws the seed points of the CSO.
void setSelectAndMoveInformation(ml::CSOList *hitCSOList, ml::CSO *hitCSO, ml::CSOSeedPoint *hitSeedPoint, ml::CSOPathPoints *hitPathPoints, float hitDistance)
virtual void sendCSOEventsOnCancel(ml::CSOList *csoList)
virtual bool isDefaultRenderer() const
Returns whether the editor is the default editor.
virtual bool shouldRenderCSOs() const
Returns whether the editor should render.
virtual void initMembers()
void mapWorldToDevice(View2DSliceList *slicelist, const ml::Vector3 &worldPosition, float &deviceX, float &deviceY)
Returns device coordinates for a given world position.
float getDepthAlpha(int maxSliceDistance, int currentSliceDistance) const
Returns an alpha factor based on the max distance and the current distance.
ml::CSOListPtr _hitCSOList
Pointer to internal/interactive states.
virtual bool isModificationEditor() const
Returns whether the editor is a modification editor.
SoPointerPosition manages the current position of the mouse cursor.
SoPointingAction is the base class for any mouse based interaction.
The SoSFMLBase field is the interface used by Inventor Nodes to output ML Base objects to the outside...
Definition: SoSFMLBase.h:45
View2DEvent stores all information on an event on a SoView2D.
a list that holds all View2DSlice objects (lazily created) of a SoView2D
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 for setting visualization parameters for CSO editors.