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:
133 
135  enum Part {
136  OtherPart,
137  RotationCenter,
138  RotationWheel
139  };
140 
142  void _startDrag(const SbVec3f& voxelPos);
143  void _dragTo(View2DSliceList* sliceList, const SbVec3f& voxelPos);
144  void _endDrag();
146 
148  bool _pointerInViewer;
149 
151  bool _isDragging;
152 
154  void _drawIconAt(int index, const SbVec2f& p0, const SbVec2f& d1, const SbVec2f& d2, float size);
155 
157  void _drawTexture(View2DTexture* texture, const SbVec2f& p0, const SbVec2f& p1, const SbVec2f& p2);
159 
161  Part _getPart(View2DSlice *slice, const SbVec3f& worldPos) const;
162 
164  float _getWidgetSize(View2DSlice *slice) const;
165 
167  void _initializeImages();
168 
169  void _setUndoEnabled(bool enabled);
170  void _setRedoEnabled(bool enabled);
171 
173  View2DIcons* _images;
174 
176  View2DSlice* _currentInteractionSlice;
177 
179  SbVec3f _startingPointWorld;
180 
182  RegistrationState _startingState;
183 
185  Part _currentPart;
186 
188  bool _calcRotationCenter;
189 
191  class CommandAction : public SoCommandAction
192  {
193  public:
194  CommandAction(SoView2DRigidRegistrationEditorBase* owner, const std::string& id) : SoCommandAction(owner, id) {}
195 
196  inline SoView2DRigidRegistrationEditorBase* getWidget() const { return static_cast<SoView2DRigidRegistrationEditorBase*>(getOwner()); }
197  };
198 
199  class ResetAction : public CommandAction
200  {
201  public:
202  ResetAction(SoView2DRigidRegistrationEditorBase* owner) : CommandAction(owner, "ResetManualRegistration") {}
203 
204  void execute() override { getWidget()->doReset(); }
205  };
206 
207  ResetAction* _resetAction;
209 };
210 
#define SOVIEW2D_API
File to resolve system dependencies in View2D library.
SoCommandAction is the base class for instantaneous actions.
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.
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