MeVisLab Toolbox Reference
SoView2DRectangle.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2007, 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 "SoView2D.h"
20#include "SoView2DLabel.h"
21#include "View2DSliceList.h"
22
23#include <Inventor/fields/SoSFInt32.h>
24#include <Inventor/fields/SoSFVec3f.h>
25
27{
28 void reset(View2DSliceList* slicelist, int slice)
29 {
30 hitID = 0;
31 currentSlice = slice;
32 viewer = slicelist->getOwner();
33 }
34 bool isDrawnOnViewer(View2DSliceList* slicelist, int slice) const
35 {
36 return (viewer == slicelist->getOwner() && currentSlice == slice);
37 }
40 uint8_t hitID{};
41};
42
43
46{
47 SO_NODE_HEADER(SoView2DRectangle);
48
49public:
51
53 SoSFVec3f startWorldPos;
55 SoSFVec3f endWorldPos;
56
58 SoSFFloat blendInside;
60 SoSFFloat blendOnto;
62 SoSFFloat blendOutside;
64 SoSFFloat lineBlendInside;
66 SoSFFloat lineBlendOnto;
69
75 SoSFColor handleColor;
77 SoSFColor sideLineColor;
78
80 SoSFBool resetToImage;
81
83 SoSFBool selectOutside;
84
86 SoSFBool allowDrag;
87
89 SoSFBool cooperative;
90
92 SoSFFloat shadeExterior;
96
98 SoSFEnum lineStyle;
99
101 SoSFBool isUnderMouse;
102
103 SoSFBool drawLabel;
104 SoSFString labelText;
105
112
114 SoSFColor labelColor;
116 SoSFBool labelShadow;
118 SoSFInt32 labelFontSize;
119
121
123 static void initClass();
124
127
129 void draw(View2DSliceList* dsl, View2DSlice* dslice, int slice) override;
130
132 void drawLabelText(float px, float py, float qx, float qy);
133
135 bool evalEvent(SoView2D* view2d, View2DSliceList* slicelist, View2DEvent* ec, View2DEventPhase phase) override;
136
138 bool ignoreEvent(View2DEvent* ec) override;
139
140protected:
142 enum DragMode { DragNothing, DragAnyPoint, DragRect, DragCreateRect };
143
145 DragMode performHitTest(float dx, float dy, const SbVec3f& voxelPos, View2DSliceList* sliceList);
147
149 void performDrag(const SoPointerPosition& pos, bool setStart);
150 void performDrag(const SbVec3f& voxelPos, bool setStart, View2DSliceList* sliceList);
151
154 bool isSensitiveAt(const SoPointerPosition& pos) override;
155 void startPressAt(const SoPointerPosition& pos) override;
156 void dragMoveTo(const SoPointerPosition& pos) override;
157 SoPointingAction* endPress(int clickCount) override;
158 void pointerPosition(SoState*, const SoPointerPosition& pos) override;
159 void pointerLeftWindow(SoState*) override;
161
162 bool isPointInsideDeviceCornerHandle(const SbVec2f& cornerHandlePosition, const SbVec2f& mousePosition)
163 {
164 const float hitRectangleSize = GLHiDPIScale(getSelectDist());
165 return isPointInsideDeviceRect(cornerHandlePosition[0], cornerHandlePosition[1], mousePosition[0], mousePosition[1],
166 hitRectangleSize);
167 }
168
169 bool isMouseInsideRectangle(const SbVec2f& mousePosition, const SbVec2f& upperLeft, const SbVec2f& lowerRight)
170 {
171 const float x = mousePosition[0];
172 const float y = mousePosition[1];
173
174 const float minX = std::min(upperLeft[0], lowerRight[0]);
175 const float maxX = std::max(upperLeft[0], lowerRight[0]);
176 const float minY = std::min(upperLeft[1], lowerRight[1]);
177 const float maxY = std::max(upperLeft[1], lowerRight[1]);
178
179 return (x > minX && x < maxX && y > minY && y < maxY);
180 }
181
182 void drawHitSideLine(float startX, float startY, float endX, float endY, View2DSliceList* sliceList, int slice) const;
183 void drawThickLine(float startX, float startY, float endX, float endY) const;
184 void drawThinLine(float startX, float startY, float endX, float endY) const;
185
188
192 bool _startDeviceXHigher{};
194 bool _startDeviceYHigher{};
195
196 bool _swappedDeviceX{};
197 bool _swappedDeviceY{};
198
200 bool _dragx{};
202 bool _dragy{};
203
206
207 bool isSliceInMiddleOfRectangleExcludingTopAndBottom(int slice, float vz1, float vz2) const;
208 bool isSliceIntersectingRectangle(int slice, float vz1, float vz2) const;
209
212
214 bool _draggingInCooperativeMode{};
215
216private:
219};
View2DEventPhase
event phase for simple extensions that grab the focus, do something (motion) and are released afterwa...
#define SOVIEW2D_API
File to resolve system dependencies in View2D library.
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.
bool isPointInsideDeviceRect(float pointX, float pointY, float centerX, float centerY, float hitRectangleSize=0.0)
returns whether the given point is inside a rectangle around the given center.
float getSelectDist()
Set the distance tolerance on hit checking in pixels.
SoView2DInteractionExtension is base class for all SoView2DExtensions that want to support the Manage...
allows drawing and editing of a rectangle on a SoView2D
SoView2DRectangle()
Constructor.
bool isSensitiveAt(const SoPointerPosition &pos) override
interface forwarded from SoPointingAction:
SoSFFloat lineBlendOnto
line blend factor when on border of rectangle
DragMode performHitTest(const SoPointerPosition &pos)
bool isSliceIntersectingRectangle(int slice, float vz1, float vz2) const
void drawThinLine(float startX, float startY, float endX, float endY) const
SoSFInt32 labelFontSize
font size of text
SoSFFloat labelHorizontalOffset
void drawLabelText(float px, float py, float qx, float qy)
draws the label (given top-left/bottom-right positions of the rectangle on the slice)
SoSFBool selectOutside
allow selection outside of rectangle
void performDrag(const SoPointerPosition &pos, bool setStart)
perform drag operation (this uses members set by performHitTest)
void dragMoveTo(const SoPointerPosition &pos) override
SoSFBool shadeAllExterior
shade all exterior, also there where the slice does not cross the box.
void draw(View2DSliceList *dsl, View2DSlice *dslice, int slice) override
reimplemented from SoView2DExtension
DragMode _dragMode
specify drag mode
void startPressAt(const SoPointerPosition &pos) override
DragMode
type for specifying dragging mode
SoSFFloat blendInside
blend factor inside of rectangle
SbVec3f _lastWorldPos
last world position
bool evalEvent(SoView2D *view2d, View2DSliceList *slicelist, View2DEvent *ec, View2DEventPhase phase) override
reimplemented from SoView2DExtension
SoSFFloat blendOutside
blend factor outside of rectangle
bool isMouseInsideRectangle(const SbVec2f &mousePosition, const SbVec2f &upperLeft, const SbVec2f &lowerRight)
void pointerPosition(SoState *, const SoPointerPosition &pos) override
Same as below, with additional SoState argument. By default, simply calls the below version.
SoSFBool isUnderMouse
flag that indicated is the rectangle is under the mouse
SoSFBool cooperative
enable cooperative mode
SoSFFloat shadeExterior
shade the exterior of the rectangle
void drawHitSideLine(float startX, float startY, float endX, float endY, View2DSliceList *sliceList, int slice) const
SoSFEnum labelVerticalBoxPosition
SoSFBool useSideLineColor
Should the side lines have their own color?
SoSFVec3f endWorldPos
end world position of rectangle
bool isSliceInMiddleOfRectangleExcludingTopAndBottom(int slice, float vz1, float vz2) const
SoSFEnum lineStyle
line style
SoSFColor sideLineColor
Optional side line color.
SoSFColor handleColor
Optional handle color.
SoSFFloat lineBlendInside
line blend factor when inside of rectangle
SoPointingAction * endPress(int clickCount) override
SoSFBool resetToImage
reset to 80 percent of the original image
void performDrag(const SbVec3f &voxelPos, bool setStart, View2DSliceList *sliceList)
SoSFFloat lineBlendOutside
line blend factor when outside of rectangle
static void initClass()
inventor runtime type system
SoSFFloat blendOnto
blend factor on border of rectangle
SoSFBool useHandleColor
Should the handles have their own color?
SoSFEnum labelHorizontalBoxPosition
void drawThickLine(float startX, float startY, float endX, float endY) const
bool isPointInsideDeviceCornerHandle(const SbVec2f &cornerHandlePosition, const SbVec2f &mousePosition)
bool ignoreEvent(View2DEvent *ec) override
Overwrite ignoreEvent -> ignore the "ignoreHandledEvents"-Field.
DragMode performHitTest(float dx, float dy, const SbVec3f &voxelPos, View2DSliceList *sliceList)
perform hit test where the rectangle is hit, returns the possible drag mode
SoSFColor labelColor
text color to use
SoSFBool labelShadow
flag if text shadow should be drawn
SoSFVec3f startWorldPos
Fields.
SoSFBool allowDrag
allow dragging of the rectangle
void pointerLeftWindow(SoState *) override
Same as below, with additional SoState argument. By defaults, simply calls the below version.
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
SoView2D * getOwner()
Get the owning SoView2D.
a single slice that is stored in a View2DSliceList, typically created by a View2DSliceList
Definition View2DSlice.h:48
ML_OPENGL_END_NAMESPACE T GLHiDPIScale(T x)
Convenience template function to scale a value.
Definition mlGLHiDPI.h:68
Allows drawing and editing of a rectangle on a SoView2D.
bool isDrawnOnViewer(View2DSliceList *slicelist, int slice) const
SoView2D * viewer
void reset(View2DSliceList *slicelist, int slice)