MeVisLab Toolbox Reference
SoView2DRigidRegistrationEditorBase.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2013, 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 // editor for setting a rigid registration
14 
15 #pragma once
16 
18 
19 // Wrap inventor includes into XVEnterScope and XVLeaveScope to avoid
20 // collisions between OpenInventor and Windows headers.
21 #include "XVEnterScope.h"
22 #include <Inventor/nodes/SoSubNode.h>
23 #include <View2DSlice.h>
24 #include <View2DSliceList.h>
25 #include <View2DIcons.h>
26 // include used fields
27 #include <Inventor/fields/SoSFTrigger.h>
28 #include <Inventor/fields/SoSFVec3f.h>
29 #include <Inventor/fields/SoSFColor.h>
30 #include <Inventor/fields/SoSFMatrix.h>
31 #include <Inventor/sensors/SoFieldSensor.h>
32 #include <Inventor/sensors/SoNodeSensor.h>
33 #include <Inventor/SbLinear.h>
34 #include "XVLeaveScope.h"
35 
36 
38 
39 
42 {
44  SO_NODE_ABSTRACT_HEADER(SoView2DRigidRegistrationEditorBase);
45 
46 public:
48  SoView2DRigidRegistrationEditorBase(const std::string& actionID);
49 
51  static void initClass();
52 
53  void draw(View2DSliceList *list, View2DSlice *slice, int z) override;
54 
56  SoSFMatrix outputMatrix;
57 
60 
62  SoSFMatrix defaultOutputMatrix;
64 
65  SoSFTrigger reset;
67 
71 
75 
76  SoSFColor inactiveColor;
77  SoSFColor highlightColor;
78  SoSFBool drawShadow;
79  SoSFColor shadowColor;
80  SoSFFloat alpha;
81 
86 
87  virtual void doReset();
88 
89 protected:
92 
93  bool implementsManagedInteractionAndClassicEventHandling() const override { return false; }
94 
97  bool isSensitiveAt(const SoPointerPosition&) override;
98  int getCurrentCursor(SoViewerProxy* viewerProxy) override;
99  void setHighlightAt(const SoPointerPosition& pos) override;
100  void unsetHighlight() override;
101  void startPressAt(const SoPointerPosition& pos) override;
102  void dragMoveTo(const SoPointerPosition& pos) override;
103  SoPointingAction* endPress(int clickCount) override;
105 
107  void doResetCallback(SoField*) { doReset(); }
108  void doResetRotationWheelCenterCallback(SoField*) { _calcRotationCenter = true; }
109  virtual void iconImagesChanged(SoField*) { _initializeImages(); }
110 
112  void pointerPosition(const SoPointerPosition& pos) override;
113  void pointerLeftWindow() override;
114 
116  {
118  RegistrationState(SbMatrix aMatrix, SbVec3f aCenter) : matrix(aMatrix), center(aCenter) {}
119 
120  SbMatrix matrix;
121  SbVec3f center;
122  };
123 
125  virtual void pushOldState(const RegistrationState& /*state*/) {}
126 
129 
130 private:
131 
133  enum Part {
134  OtherPart,
135  RotationCenter,
136  RotationWheel
137  };
138 
140  void _startDrag(const SbVec3f& voxelPos);
141  void _dragTo(View2DSliceList* sliceList, const SbVec3f& voxelPos);
142  void _endDrag();
144 
146  bool _pointerInViewer;
147 
149  bool _isDragging;
150 
152  void _drawIconAt(int index, const SbVec2f& p0, const SbVec2f& d1, const SbVec2f& d2, float size);
153 
155  void _drawTexture(View2DTexture* texture, const SbVec2f& p0, const SbVec2f& p1, const SbVec2f& p2);
157 
159  Part _getPart(View2DSlice *slice, const SbVec3f& worldPos) const;
160 
162  float _getWidgetSize(View2DSlice *slice) const;
163 
165  void _initializeImages();
166 
167  void _setUndoEnabled(bool enabled);
168  void _setRedoEnabled(bool enabled);
169 
171  View2DIcons* _images;
172 
174  View2DSlice* _currentInteractionSlice;
175 
177  SbVec3f _startingPointWorld;
178 
180  RegistrationState _startingState;
181 
183  Part _currentPart;
184 
186  bool _calcRotationCenter;
187 
189  class CommandAction : public SoCommandAction
190  {
191  public:
192  CommandAction(SoView2DRigidRegistrationEditorBase* owner, const std::string& id) : SoCommandAction(owner, id) {}
193 
194  inline SoView2DRigidRegistrationEditorBase* getWidget() const { return static_cast<SoView2DRigidRegistrationEditorBase*>(getOwner()); }
195  };
196 
197  class ResetAction : public CommandAction
198  {
199  public:
200  ResetAction(SoView2DRigidRegistrationEditorBase* owner) : CommandAction(owner, "ResetManualRegistration") {}
201 
202  void execute() override { getWidget()->doReset(); }
203  };
204 
205  ResetAction* _resetAction;
207 };
208 
#define SOVIEW2D_API
File to resolve system dependencies in View2D library.
SoCommandAction is the base class for instantaneous actions.
SoPointerPosition manages the current position of the mouse cursor.
SoPointingAction is the base class for any mouse based interaction.
SoView2DInteractionExtension is base class for all SoView2DExtensions that want to support the Manage...
interactive editor to accumulate a transformation matrix
void setRegistrationState(const RegistrationState &state)
void doResetCallback(SoField *)
field change callbacks:
void pointerPosition(const SoPointerPosition &pos) override
interface inherited from SoInteractionProvider
bool implementsManagedInteractionAndClassicEventHandling() const override
return true if this node is a hybrid module providing managed interaction and classic event handling ...
~SoView2DRigidRegistrationEditorBase() override
Protected destructor.
SoSFVec3f rotationCenterWorld
the current rotation center in world coordinates
SoPointingAction * endPress(int clickCount) override
int getCurrentCursor(SoViewerProxy *viewerProxy) override
interface forwarded from SoPointingAction:
void draw(View2DSliceList *list, View2DSlice *slice, int z) override
Called by the SoView2D for each slice that is rendered.
static void initClass()
Initializes this class (called on dll initialization).
bool getRegistrationState(RegistrationState &state) const
virtual void pushOldState(const RegistrationState &)
callback for undo system
SoSFString resolvedWheelImageFile
appearance configuration
void pointerLeftWindow() override
This is called when the mouse cursor leaves the window.
SoSFMatrix defaultOutputMatrix
default values for outputMatrix and rotationCenterWorld, these will propagate directly and reset the ...
void dragMoveTo(const SoPointerPosition &pos) override
void startPressAt(const SoPointerPosition &pos) override
void setHighlightAt(const SoPointerPosition &pos) override
bool isSensitiveAt(const SoPointerPosition &) override
interface forwarded from SoPointingAction:
SoSFMatrix outputMatrix
matrix with the current registration matrix
SoView2DRigidRegistrationEditorBase(const std::string &actionID)
Constructor.
This class gives access to state of a viewer during scene graph traversal.
Definition: SoViewerProxy.h:30
Defines and implements a class to store multiple images and draw them via OpenGL.
Definition: View2DIcons.h:24
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
A class to render images as OpenGL Textures.
Definition: View2DTexture.h:47