MeVisLab Toolbox Reference
SoCSOTransformEditor.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
19
21
23class CSO;
25
27
30{
31 SO_NODE_HEADER(SoCSOTransformEditor);
32
33public:
34
39
42
44 static void initClass();
45
46 virtual bool evaluateHitPoint(const ml::Vector3& worldPosition, View2DSliceList* slicelist, ml::CSOList* csoList, ml::CSO*& cso,
53 ml::CSOPathPoints*& , float& ) override
54 {
55 return false;
56 }
57
58 bool isModificationEditor() const override { return true; }
59 void cancel() override;
60
63
66
68
69 void createStartPressAt(const SoPointerPosition& ) override {}
70 void createDragMoveTo(const SoPointerPosition& ) override {}
71 bool createEndPress(int ) override { return false; }
73
76 SoPointingAction* selectAndMoveEndPress(int ) override { return nullptr; }
77
78 int cursorShape() const override { return _cursorShape; }
79
80 bool shouldRenderSpecific(ml::CSO*) const override { return false; }
81 bool shouldRenderGeneral(ml::CSO*) const override { return true; }
82
84
88
91
93
96
105
107
108protected:
109
111
112 void initMembers() override;
113
114private:
115
117 enum ScaleDirection
118 {
119 UN = -1,
120 NW = 0,
121 N = 1,
122 NE = 2,
123 W = 3,
124 E = 4,
125 SW = 5,
126 S = 6,
127 SE = 7
128 };
129
130 void performScaling(const SoPointerPosition &pos);
131 void performRotation(const SoPointerPosition &pos);
132 void performTranslation(const SoPointerPosition &pos);
133
135 static void baseEventCB(void* userData, ml::BaseEvent* event);
138 void attachAsListenerTo(ml::CSOList* csoList);
140 ml::CSOList* _listenToCSOList;
141
143 bool isInSelectionDistance(const SbVec2f& pos1, const SbVec2f& pos2, float selectionDistance) const;
145 bool isInTranslationArea(const SbVec2f& mouseDevicePosition, const std::vector < SbVec2f >& translateHandlesPositions)const;
146
147
149 void clearHandlesPositions();
151 void setScaleCursorShape();
153 void limitScaleOffset(SbVec2f& scaleOffset);
155 void computeMoveAndScaleFactors(const SbVec3f& offsetX, const SbVec3f& offsetY, float voxelBBX, float voxelBBY,
156 float& voxelMoveX, float& voxelMoveY, float& voxelScaleX, float& voxelScaleY) const;
157
159 void computeMoveAndScaleFactorsForIsotropicScaling(const SbVec3f& bbVoxelCenterPoint, const SbVec3f& currentVoxelPosition, float& voxelScaleX, float& voxelScaleY);
161 void drawRotateIndicatorLine(ml::CSO* cso, const SbVec2f& rotateHandlePosition, float rotateHandleOffset);
162
163 boost::unordered_map < MatrixHashPair, std::vector < SbVec2f >, MatrixHashFunction > _scaleHandlesPositionsCache;
164 boost::unordered_map < MatrixHashPair, std::vector < SbVec2f >, MatrixHashFunction > _translateHandlesPositionsCache;
165
166 boost::unordered_map < MatrixHashPair, SbVec2f, MatrixHashFunction > _rotateHandlePositionCache;
167 boost::unordered_map < MatrixHashPair, SbVec2f, MatrixHashFunction > _rotateCenterCache;
168
170 void resetActiveHandleIndices()
171 {
172 _activeScaleHandleIndex = -1;
173 _activeTranslateHandleIndex = -1;
174 _activeRotateHandleIndex = -1;
175 }
176
178 bool shouldShowHandles() const;
179
180 bool _isInteracting;
181 bool _isRotating;
182
183 int _activeScaleHandleIndex;
184 int _activeTranslateHandleIndex;
185 int _activeRotateHandleIndex;
186
187 SbVec2f _startDevicePosition;
188 SbVec3f _startVoxelPositionForIsotropicScaling;
189 SbVec3f _lastWorldPosition;
190 SbVec3f _lastGoodCurrentWorldPosition;
191
192 int _cursorShape;
193
194 ml::CSO _originalCSO;
195
196 SbVec2f _rotationCenterDevice;
197 void setRotationCenter(View2DSliceList* slicelist);
198 ml::Matrix4 composeMLRotationMatrix(const SoPointerPosition& pos);
199
200 ml::Matrix4 convertInventorToMLMatrix(const SbMatrix& matrix);
201
202 ml::CSO* _selectedCSO;
203};
204
#define SOCSO_EXPORT
Header file for system independent resolution.
Definition SoCSOSystem.h:21
@ N
@ E
@ W
@ S
Base class for an editor extension for the SoView2DCSOExtensibleEditor.
Extension for transforming existing CSOs.
virtual bool evaluateHitPoint(const ml::Vector3 &worldPosition, View2DSliceList *slicelist, ml::CSOList *csoList, ml::CSO *&cso, SoView2DCSOExtensibleEditor *editor)
bool shouldRenderGeneral(ml::CSO *) const override
Returns whether a given CSO should be rendered by this general extension.
void transformStartPressAt(const SoPointerPosition &pos)
void createStartPressAt(const SoPointerPosition &) override
void selectAndMoveStartPressAt(const SoPointerPosition &) override
SoPointingAction * selectAndMoveEndPress(int) override
bool isEligibleForTransforming(ml::CSO *cso, View2DSliceList *slicelist, SoView2DCSOExtensibleEditor *editor)
Returns whether the given CSO is eligible for transforming by this editor.
SoCSOTransformEditor()
Standard constructor.
~SoCSOTransformEditor() override
Destructor.
int cursorShape() const override
Returns the cursor shape that indicates the next creation.
bool shouldRenderSpecific(ml::CSO *) const override
Returns whether a given CSO should be rendered by this specific extension.
bool isModificationEditor() const override
Returns whether the editor is a modification editor.
void selectAndMoveDragMoveTo(const SoPointerPosition &) override
void draw(const CSODrawCSOInfos &csoInfos, const CSODrawView2DInfos &view2DInfos, const CSODrawSliceInformation &drawSliceInfo, SoView2DCSOExtensibleEditor *editor) override
Drawing routine.
bool evaluateHitPoint(const ml::Vector3 &, View2DSliceList *, ml::CSOList *, const ml::CSOBoundingBox &, SoView2DCSOExtensibleEditor *, ml::CSO *&, ml::CSOSeedPoint *&, ml::CSOPathPoints *&, float &) override
Overload the method and always return false so no CSO can be picked.
void createDragMoveTo(const SoPointerPosition &) override
void drawInteractionHandleAsSeedPointAt(ml::CSO *cso, float deviceX, float deviceY)
void pointerPositionIfAllowedAt(const SoPointerPosition &) override
Sets seed points while moving the mouse – but not while dragging.
void initMembers() override
static void initClass()
init class in inventor runtime
void cancel() override
Cancels an action like generating a CSO. Depends on concrete editor.
bool createEndPress(int) override
SoPointingAction * transformEndPress(int clickCount)
void transformDragMoveTo(const SoPointerPosition &pos)
SoPointerPosition manages the current position of the mouse cursor.
SoPointingAction is the base class for any mouse based interaction.
a list that holds all View2DSlice objects (lazily created) of a SoView2D
BaseEvent is the base class for all events emitted from EventSourceBase.
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...
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.
Struct for retrieving a hash key for a Matrix4 which is used in the caches for voxel bounding boxes.