MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
SoView2DCSOExtensibleEditor.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 <SoView2DExtension.h>
21
22#include <Inventor/misc/SoRef.h>
23
24#include <mlMatrix4.h>
25#include <deque>
26
27typedef std::vector<SoRef<SoCSOEditorExtension>> ExtensionList;
28
30class CSO;
31class CSOList;
33
34class SoCSOTransform;
35
36
37class CSOCreateAction;
38class CSOBulgeAction;
44
48
51
54
56
58
60class CSOVisualizationSettings;
62
69
71
73{
74public:
78 static void initClass();
79
117
129
136 std::string getDefaultCreatorString() const
137 {
138 return std::string("__default");
139 }
140
142 void pointerLeftWindow() override;
144 void pointerPosition(const SoPointerPosition& pos) override;
148
151
164 {
165 _interactionMode = mode;
166 }
169 {
170 return _interactionMode;
171 }
172
177
186 const CSODrawView2DInfos& view2DInfos, ml::CSO* cso);
188 bool shouldShowCSOBeyondSlice(const CSODrawSliceInformation& sliceInfo, const CSODrawView2DInfos& view2DInfos,
189 ml::CSO* cso);
197 ml::AbstractTransformationPtr getRegistrationInformation(const SoPointerPosition& pos, ml::CSO* cso);
200 ml::CoordinateSystemReference getCoordinateSystemReference(ml::CSO* cso);
201 ml::CoordinateSystemReference getCoordinateSystemReference(SoView2D* viewer);
202 ml::CoordinateSystemReference getCoordinateSystemReference(const CSODrawView2DInfos& view2DInfos);
203 ml::CoordinateSystemReference getCoordinateSystemReference(const SoPointerPosition& pos);
207 {
208 return _transformationProvider != nullptr;
209 }
211 ml::AbstractTransformationPtr getTransformation(const ml::CoordinateSystemReference& from,
212 const ml::CoordinateSystemReference& to);
214 bool isSameImage(const ml::CoordinateSystemReference& from, const ml::CoordinateSystemReference& to);
215
218 void transformCSO(ml::CSO* cso, const ml::AbstractTransformationPtr& transformation);
219
221 void fillCSOSliceInformation(const CSODrawCSOInfos& csoInfos, const CSODrawView2DInfos& view2DInfos,
222 CSODrawSliceInformation& sliceInfo, const ml::Matrix4& worldToVoxelMatrix,
223 const CSOVoxelSlab& csoSlab);
224
230
234 ON_ALL_IMAGES = 0,
235 ONLY_ON_IMAGES_THEY_WERE_CREATED_ON =
236 1,
237 ONLY_ON_IMAGES_THEY_WERE_NOT_CREATED_ON = 2,
238 ONLY_ON_IMAGES_THEY_CAN_BE_TRANSFORMED_TO = 3
239 };
240
244
247 {
248 return allowSelectionWithDefaultRenderer.getValue();
249 }
250
255
260
262 void cancel();
263
264protected:
267
269 void startDrawing(View2DSliceList* slicelist) override;
270
272 void draw(View2DSliceList* slicelist, View2DSlice* slice, int sliceZ) override;
273
274 bool evalEvent(SoView2D* view2d, View2DSliceList* slicelist, View2DEvent* ec, View2DEventPhase phase) override;
275
276 void notifyEditorsOfMouseWheelEvent(SoMouseWheelEvent::Orientation orientation, int turn, View2DEvent* ec);
277
279 static void csoListNotificationCB(void* userData, int notificationFlag);
280
282 void editingOnChanged(SoField*) override;
283 void buttonMaskChanged(SoField*) override;
284
291
293 void doAction(SoAction* action) override;
295 std::vector<SoCSOTransform*> _csoTransforms;
296
297private:
300
301 ml::CSOVisualizationSettings _dummyVisualizationSettings;
302 SoRef<SoCSODefaultRenderer> _defaultRenderer;
303
304 bool _activeCreatorEditorDirty;
305
306 void _inCSOListCB(SoField*);
307
308 SbVec3f _currentPointerWorldPosition;
309 SbVec3f _startPointerWorldPosition;
310 int _currentTimePointIndex;
311
312 void storeCopiedCSOGroupInformation();
313
314 void setActiveEditor(const ExtensionList& extensions);
315 void setActionsEnabled();
316 void setKeyboardActionsEnabled();
317 void setTriggerFieldsToActions();
318
319 void toggleCancelCommandIsActive();
320 void togglePasteCommandIsActive();
321 void toggleCutCopyCommandIsActive();
322 void toggleUndoCommandIsActive();
323 void toggleRedoCommandIsActive();
324 void toggleDeleteCSOCommandIsActive();
325 void toggleDeleteSeedPointCommandIsActive();
326 void toggleRemoveAllCommandIsActive();
327
328 bool areKeyboardCommandsActive()
329 {
330 return isEditingOn() && keyCommandsEnabled.getValue();
331 }
332
333 bool isInteracting();
334
335 void copySelectedCSOs();
336
337 void copySelectedCSOsToInternalList(ml::CSOList* csoList);
338 void cutSelectedCSOs();
339 void pasteCSOs();
340
341 void deleteSelectedCSOs();
342 void deleteSelectedSeedPoint();
343
344 void undo();
345 void redo();
346
347 void removeAllCSOsAndGroups();
348
349 SbVec3f getMidPointSelectedCSOs();
350
351 void getNonActiveEditorExtensionIds(std::vector<std::string>& nonActiveEditorExtensions);
352
353 // Returns whether the given CSO should be rendered.
354 bool shouldRenderCSO(ml::CSO* cso, const CSODrawView2DInfos& view2DInfos, const CSODrawSliceInformation& sliceInfo);
355
356 void resetCreatingAndEditingFields();
357 void resetAllExtensionCaches();
358 void resetAllEditorsAndCaches();
359
360 SoCSOEditorExtension* getExtensionForCSO(ml::CSO* cso);
361 bool doesCSOTimePointMatchCurrentTimePoint(const CSODrawView2DInfos& view2DInfos, ml::CSO* cso);
362
363 ml::TransformationProvider* _transformationProvider;
364
365 // this is the editor active for creating new CSOs
366 SoRef<SoCSOEditorExtension> _activeEditor;
367 SoRef<SoCSOEditorExtension> _lastActiveEditor;
368
369 CSOLabelResizeAction* _labelResizeAction;
370 CSOLabelMoveAction* _labelMoveAction;
371 CSOTransformAction* _transformAction;
372 CSOInsertSeedPointIntoPathPointListAction* _insertSeedPointAction;
373 CSOSelectAndMoveAction* _selectAndMoveAction;
374 CSOCreateAction* _createAction;
375 CSOBulgeAction* _bulgeAction;
376
377 int _interactionMode;
378
379 CSOCopyCommandAction* _copyCommandAction;
380 CSOCutCommandAction* _cutCommandAction;
381 CSOPasteCommandAction* _pasteCommandAction;
382
383 CSODeleteSeedPointCommandAction* _deleteSeedPointCommandAction;
384 CSODeleteCSOCommandAction* _deleteCSOCommandAction;
385
386 CSOUndoCommandAction* _undoCommandAction;
387 CSORedoCommandAction* _redoCommandAction;
388
389 CSOCancelCommandAction* _cancelCommandAction;
390
391 CSORemoveAllCommandAction* _removeAllCommandAction;
392
393 std::vector<ml::CSO*> _copiedCSOs;
394 std::map<int, std::vector<int>> _copiedCSOGroupIds;
395
396
397 unsigned int _prevWheelCode;
398 int _sumWheel;
399
400 friend bool SoCSOEditorTools::evaluateHitPoint(const ml::Vector3& worldPosition, View2DSliceList* slicelist,
401 ml::CSOList* csoList, const ml::CSOBoundingBox& slabBB,
402 const std::string& subType, SoView2DCSOExtensibleEditor* editor,
405 ml::CSOPathPoints*& localHitPathPoints, float& distance, int sliceZ);
406
407 // Stores a list of voxel slabs for a given cso list
408 // for given world matrix and cso change id.
409 struct SlabCacheEntry
410 {
411 SlabCacheEntry()
412 {
413 csoList = nullptr;
414 csoListGeometryChangeId = 0;
415 }
416 void clear()
417 {
418 csoList = nullptr;
419 csoListGeometryChangeId = 0;
420 csoSlabs.clear();
421 }
422
423 void* csoList;
424 MLuint64 csoListGeometryChangeId;
425 ml::Matrix4 worldToVoxelMatrix;
426 std::vector<CSOVoxelSlab> csoSlabs;
427 };
428
429 // Stores N cache entries.
430 std::deque<SlabCacheEntry*> _csoSlabCache;
431
432 const SlabCacheEntry& findOrCreateSlabCache(const ml::Matrix4& worldToVoxelMatrix, size_t matrixHashKey,
433 ml::CSOList* list);
434
435
436 void notifyCSOListObservers(ml::CSOList* csoList);
437
438 // make the keyboard commands friends so they
439 // can access private/protected methods.
443
446
449
451
452 SO_NODE_HEADER(SoView2DCSOExtensibleEditor);
453};
454
#define SOCSO_EXPORT
Header file for system independent resolution.
Definition SoCSOSystem.h:21
std::vector< SoRef< SoCSOEditorExtension > > ExtensionList
Extensible editor for CSOs.
View2DEventPhase
event phase for simple extensions that grab the focus, do something (motion) and are released afterwa...
Action for creating CSOs.
Class ManagedMouseButtonTrigger encapsulates the combination of required and ignored mouse buttons an...
Extension for rendering CSOs.
Base class for an editor extension for the SoView2DCSOExtensibleEditor.
Abstract Open Inventor base class for uniform shader parameter nodes.
void pointerPosition(SoState *state, const SoPointerPosition &pos) override
Same as below, with additional SoState argument. By default, simply calls the below version.
virtual void pointerLeftWindow()
This is called when the mouse cursor leaves the window.
SoPointerPosition manages the current position of the mouse cursor.
The SoSFMLBase field is the interface used by Inventor nodes to output ML Base objects to the outside...
Definition SoSFMLBase.h:46
void inTransformationProviderChanged(SoField *)
ml::CSOVisualizationSettings * getVisualizationSettings()
Returns the pointer to a optionally attached CSOVisualizationSettings object.
SoSFBool updateGhostedCSOIdUnderMouseCursor
Shall the cso id of a ghosted CSO under the mouse cursor be updated?
void transformCSO(ml::CSO *cso, const ml::AbstractTransformationPtr &transformation)
Transforms the given CSO on base of registration information.
void draw(View2DSliceList *slicelist, View2DSlice *slice, int sliceZ) override
Renders by calling the draw-method of all attached extensions.
ml::CoordinateSystemReference getCoordinateSystemReference(const CSODrawView2DInfos &view2DInfos)
bool shouldShowCSOForCurrentTimePoint(const CSODrawView2DInfos &view2DInfos, ml::CSO *cso)
Returns whether the given CSO should be rendered for the current time point.
ml::AbstractTransformationPtr getRegistrationInformation(const SoPointerPosition &pos, ml::CSO *cso)
Returns a registration if it exists for the given CSO on the given image (as a SoPointerPosition),...
int getCSOIdUnderCursor(const SoPointerPosition &pos, bool checkGhostedCSOs)
Return the CSO id under the mouse cursor.
bool hasRegistrationInformation(const SoPointerPosition &pos, ml::CSO *cso)
Returns whether a registration exists.
SoSFBool isCreatingNewCSO
Flag shows whether any editor is currently creating a new CSO.
ml::CSOList * getInputCSOList()
Returns a pointer to the input CSOList or NULL if nothing valid is attached.
SoSFBool renderLeftOverCSOsWithDefaultRenderer
Shall the CSOs that were not rendered by an attached editor be rendered by a default renderer?
SoSFString creatorExtensionId
The unique id of an editor extension that receives the create events.
SoSFBool alwaysModifyExistingCSOs
Shall always be selected and modified and never created?
SoCSODefaultRenderer * getDefaultRenderer()
Returns the default renderer.
int getInteractionModifier() const
Returns the interaction mode as determined by a pointing action.
void toggleCancelCommandIsActiveForModifications(bool isActive)
Toggles the activation of the cancel command without any additional checks; to be used with care and ...
void isCreatingOrEditingChanged(SoField *)
bool shouldShowCSORegardingParallelState(const CSODrawSliceInformation &sliceInfo, const CSODrawView2DInfos &view2DInfos, ml::CSO *cso)
Returns whether the given CSO should be rendered regarding its parallel state.
SoCSOEditorExtension * getActiveEditor() const
Returns the attached editor that is active for creating new CSOs (or NULL if there is not any).
bool shouldShowCSOBeyondSlice(const CSODrawSliceInformation &sliceInfo, const CSODrawView2DInfos &view2DInfos, ml::CSO *cso)
Returns whether the given CSO should be rendered beyond the current slice.
SoSFBool accumulateTransformations
Flag to decide whether CSOTransform modules in the secene graph should be accumulated (or the last on...
SoSFBool keyCommandsEnabled
Shall the key commands be enabled?
void resetLastActiveEditor()
Resets the active editor to the last active editor if it was set.
void startDrawing(View2DSliceList *slicelist) override
Is called before drawing to initialize editors.
SoSFBool enableRemoveAll
Shall the removeAll-key command be available?
SoSFInt32 ghostedCSOIdUnderMouseCursor
The id of the ghosted CSO currently under the mouse (or -1 if no CSO is under the mouse).
void setInteractionModifier(int mode)
Sets the interaction mode as determined by a pointing action.
void pointerPosition(const SoPointerPosition &pos) override
Is called on moving the mouse, sets the CSO id under the cursor.
SoSFBool interactOnlyWithSelectedCSO
Shall only a selected CSO be allow to be interacted with?
void notifyEditorsOfMouseWheelEvent(SoMouseWheelEvent::Orientation orientation, int turn, View2DEvent *ec)
bool isSelectionAllowedWithDefaultRenderer() const
Returns whether a CSO can be selected by the internal default renderer.
static void csoListNotificationCB(void *userData, int notificationFlag)
Is called by CSOList notifications.
SoSFNode inExtensions
Input field for extensions.
void setActiveEditor(SoCSOEditorExtension *editor, bool storeLastEditor=true)
Sets the active editor, use this only to temporarily set a modification editor.
SoSFBool isEditingExistingCSO
Flag shows whether any editor is currently editing/modifying an existing CSO.
SoSFMLBase inCSOList
Input field for CSOList.
SoSFEnum renderCSOsOnImagesDependingOnCreationMode
Defines on which images the CSOs should be rendered on, depending on where they have been created.
ml::CoordinateSystemReference getCoordinateSystemReference(ml::CSO *cso)
bool shouldShowCSOOnImageWithId(const CSODrawView2DInfos &view2DInfos, ml::CSO *cso)
Returns whether the given CSO should be rendered on a particular image, identified by its DICOM Serie...
void cancel()
Cancels the current interaction.
bool hasTransformationProvider() const
Returns if the editor has a transformation provider.
SoSFBool updateImageStatisticsOnFinishInteraction
Should the image statistics be updated for the currently active CSO on finishing an interaction (mous...
SoSFInt32 csoIdUnderMouseCursor
The id of the CSO currently under the mouse (or -1 if no CSO is under the mouse).
void buttonMaskChanged(SoField *) override
called when one of the button/modifier fields is touched:
void setCSOUnderTheMouseId(int id)
Sets the csoUnderTheMouseId field only if the id changes.
void fillCSOSliceInformation(const CSODrawCSOInfos &csoInfos, const CSODrawView2DInfos &view2DInfos, CSODrawSliceInformation &sliceInfo, const ml::Matrix4 &worldToVoxelMatrix, const CSOVoxelSlab &csoSlab)
Fills the relation of the given CSO to the current slice.
SoView2DCSOExtensibleEditor()
Constructor.
void setGhostedCSOUnderTheMouseId(int id)
Sets the ghostedCSOUnderTheMouseId field only if the id changes.
ml::CoordinateSystemReference getCoordinateSystemReference(SoView2D *viewer)
bool isSameImage(const ml::CoordinateSystemReference &from, const ml::CoordinateSystemReference &to)
Returns whether the given coordinate references reference the same image.
void interactOnlyWithSelectedCSOChanged(SoField *)
SoSFBool allowSelectionWithDefaultRenderer
Shall the CSOs be selectable by the internal default renderer?
SoSFBool updateCSOIdUnderMouseCursor
Shall the cso id under the mouse cursor be updated?
void doAction(SoAction *action) override
Overloading to obtain and set the SoCSOTransform.
bool evalEvent(SoView2D *view2d, View2DSliceList *slicelist, View2DEvent *ec, View2DEventPhase phase) override
Called by the SoView2D for each event that happens on the viewer.
bool shouldShowCSOAtAll(ml::CSO *cso)
Returns whether the given CSO should be rendered at all, that is whether its shows state is true and ...
std::vector< SoCSOTransform * > _csoTransforms
Global transformation for visualization.
ml::CoordinateSystemReference getCoordinateSystemReference(const SoPointerPosition &pos)
bool shouldShowCSOOnViewerWithId(const CSODrawView2DInfos &view2DInfos, ml::CSO *cso)
Return whether the given CSO should be rendered on a particular viewer, identified by its viewerId.
void stopEditingCSO()
Sets the isEditingExistingCSO field to FALSE.
void cancelGenerationChanged(SoField *)
void setCreateActionTrigger(const SoPointingAction::Trigger &trigger)
Sets the CSOCreateAction trigger.
SoSFBool alwaysCreateNewCSOs
Shall always be created and never selected and modified?
void getExtensions(ExtensionList &extensions)
Collects attached extensions to the given list.
void extensionChanged(SoField *)
New field change callbacks:
CSORenderOnImagesDependingOnCreationModes
Modes to control the rendering of CSOs depending on the images they were created on.
std::string getDefaultCreatorString() const
Returns a default creator id string that indicates that the first found editor should create CSOs.
void setCreateActionTriggerToDefault()
Sets the CSOCreateAction trigger to its default, according to the trigger fields.
SoSFMLBase inVisualizationSettings
Input of visualization settings.
void startEditingCSO(const SoPointerPosition &pos, ml::CSO *cso)
Sets the isEditingExistingCSO field to TRUE and stores the current viewer's name in the CSO's userDat...
void pointerLeftWindow() override
Is called when mouse pointer leaves the window.
void editingOnChanged(SoField *) override
Inherited from SoView2DExtension:
SoSFMLBase inTransformationProvider
Input of provided transformations.
static void initClass()
Initialization of inventor stuff.
SoSFTrigger cancelGeneration
Triggers the cancellation of the current generation.
ml::AbstractTransformationPtr getTransformation(const ml::CoordinateSystemReference &from, const ml::CoordinateSystemReference &to)
Returns a transformation if existing, NULL otherwise.
~SoView2DCSOExtensibleEditor() override
Destructor.
SoView2DExtension Base class for all View2DExtensions used for drawing and event handling on the View...
virtual bool isEditingOn()
check if editing is on
SoView2D is a 2D viewer for image data.
Definition SoView2D.h:62
View2DEvent stores all information on an event on a SoView2D.
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 that are interpolated by a certain interpolation sch...
The CSOSeedPoint can be interactively set and modified, and is the framework for contours.
The CSO represents a contour segmentation object.
Definition CSO.h:44
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
UINT64 MLuint64
Introduce platform-independent 64-bit unsigned integer type.
Definition mlTypeDefs.h:424
SOCSO_EXPORT 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, int sliceZ=-1)
Returns whether a CSO was hit and fills the according structures.
Defines the z slab of a CSO bounding box in voxel coordinates.