MeVisLab Toolbox Reference
SoView2DExtension.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
16
17#pragma once
18
19#include "SoView2DSystem.h"
20
21#include <ThirdPartyWarningsDisable.h>
22
23#include <Inventor/nodes/SoNode.h>
24#include <Inventor/nodes/SoSubNode.h>
25#include <Inventor/fields/SoSFFloat.h>
26#include <Inventor/fields/SoSFBool.h>
27#include <Inventor/fields/SoSFTrigger.h>
28#include <Inventor/fields/SoSFEnum.h>
29#include <Inventor/fields/SoSFColor.h>
30#include <Inventor/sensors/SoNodeSensor.h>
31#include <Inventor/nodes/SoGroup.h>
32#include <Inventor/events/SoEvent.h>
33#include <Inventor/events/SoMouseButtonEvent.h>
34#include <Inventor/events/SoSpaceballButtonEvent.h>
35#include <Inventor/events/SoKeyboardEvent.h>
36#include <Inventor/events/SoLocation2Event.h>
37#include <Inventor/events/SoMotion3Event.h>
38
39#include <ThirdPartyWarningsRestore.h>
40
42#include <mlGLHiDPI.h>
43
44class SoSFMLImage;
45
48{
50 drawImageData = true;
51 applyLut = true;
52 }
53
56};
57
58#ifndef TRISTATE
59#define TRISTATE
62
64
74#define TEST_STATE(state,flag) (((state)==IGNORED)?TRUE:(((state)==PRESSED)==((flag)!=0)))
75
76#endif
77
78//--------- disable VC++ warnings---------
79#ifdef WIN32
80#pragma warning (disable : 4355)
81#pragma warning (disable : 4275)
82#pragma warning (disable : 4251)
83#pragma warning (disable : 4138)
84// Warning 4800 isn't defined for Visual Studio 2017
85#if (_MSC_VER < 1910)
86#pragma warning (disable : 4800)
87#endif
88#endif
89
90class View2DSliceList;
91class View2DSlice;
92class SoView2D;
93
106
107//==============================================================
109//==============================================================
111{
112public:
115 View2DEvent(bool sh, bool ct, bool al,
116 bool pr, bool mo, bool re, bool dc,
117 bool b1, bool b2, bool b3,
118 int dpx, int dpy, bool ov,
119 int button,
120 bool isKP, bool isKR,
121 bool iVK, int kk,
122 bool iVSP, float spx, float spy, float spz,
123 long secs, long usecs, const SoEvent* event);
124
125 void setValues(bool sh, bool ct, bool al,
126 bool pr, bool mo, bool re, bool dc,
127 bool b1, bool b2, bool b3,
128 int dpx, int dpy, bool ov,
129 int button,
130 bool isKP, bool isKR,
131 bool iVK, int kk,
132 bool iVSP, float spx, float spy, float spz,
133 long secs, long usecs, const SoEvent* event);
134
136 void print();
137
139 bool sliceHit() { return isValidSlicePos; }
140
142
144 bool shift, ctrl, alt;
145
147 bool press;
149 bool motion;
154
157
160
169
174
183
185 long second;
187
189 const SoEvent* soevent;
190
195};
196
198#define EventContainer View2DEvent
199#define EventPhase View2DEventPhase
200
209
210#define VIEW2D_DEFINE_LINE_STYLE_ENUM \
211 SO_NODE_DEFINE_ENUM_VALUE(LineStyles, SOLID); \
212 SO_NODE_DEFINE_ENUM_VALUE(LineStyles, DASHED); \
213 SO_NODE_DEFINE_ENUM_VALUE(LineStyles, DOTTED); \
214 SO_NODE_DEFINE_ENUM_VALUE(LineStyles, LONG_DASHED);
215
216#define VIEW2D_ADD_LINE_STYLE_FIELD(lineStyleField) \
217 SO_NODE_ADD_FIELD(lineStyleField, (SOLID)); \
218 SO_NODE_SET_SF_ENUM_TYPE(lineStyleField, LineStyles);
219
220
221//=============================================================
225
226//=============================================================
228{
229 SO_NODE_HEADER(SoView2DExtension);
230
231public:
238
241
244
252
257
258
271
274
277
281
284
288
290
293
295 static void initClass();
296
299
301 void init();
302
304 virtual void updateValues();
305
307
311 virtual void draw(View2DSliceList *slicelist,View2DSlice* slice, int sliceZ);
312
314
320 virtual bool evalEvent(SoView2D* view2d, View2DSliceList* slicelist,
321 View2DEvent* ec, View2DEventPhase phase);
322
325 virtual void startDrawing(View2DSliceList * /*slicelist*/){};
326
328 virtual void endDrawing(View2DSliceList * /*slicelist*/){};
329
331 virtual void overwriteDrawingSettings(SoView2DDrawingSettings& /*settings*/) {};
332
335
338
340 inline static float snapToPixelCenter(float coordinateComponent) { return floorf(coordinateComponent) + 0.5f; }
341
344 bool isPointInsideDeviceRect(float pointX, float pointY, float centerX, float centerY, float hitRectangleSize=0.0);
345
347 void drawMiniRect(float xp, float yp, float ext, float lineWidth = 1.f);
350 void drawDashedMiniRect(float xp, float yp, float ext, float lineWidth);
352 void drawFilledMiniRect(float xp, float yp, float ext, float lineWidth = 1.f);
353
355 void drawMiniTriangle(float xp, float yp, float ext, float lineWidth = 1.f);
357 void drawFilledMiniTriangle(float xp, float yp, float ext, float lineWidth = 1.f);
358
360 void drawMiniCircle(float xp, float yp, float ext, float lineWidth = 1.f);
362 void drawFilledMiniCircle(float xp, float yp, float ext, float lineWidth = 1.f);
364 void drawFixedSizeMiniCircleAt(float xp, float yp);
365
367 void drawVoxelBorder(View2DSlice* slice, float vx,float vy,float vz);
368
370 int getX();
371
373 int getY();
374
376 virtual bool isDrawingOn() { return drawingOn.getValue(); };
378 virtual bool isEditingOn() { return editingOn.getValue(); };
380 virtual bool isFixZOn() { return fixZOn.getValue(); };
382 virtual bool isClipToSlice() { return clipToSlice.getValue(); };
383
385 static void fieldChangedCB(void *data, SoSensor *sensor);
388
393
398
400 virtual bool isActive();
401
403 virtual void deleteSelectedObject();
404
406 virtual void getStatusString(SbString& status);
407
412
414
419 static void getAxisOrientation(int axis, SbMatrix &matrix, char &negativeResult, char &positiveResult);
420
425
427 enum Sign { ZERO, NEGATIVE, POSITIVE };
428
431 const SbVec3f &v2,
432 const SbPlane &plane,
433 SbVec3f &intersect);
434
436
442
445
447 virtual bool ignoreEvent(View2DEvent* ec);
448
450 bool wantsMouseOverUpdates() const { return _wantsMouseOverUpdateEvents; }
451
453 virtual void consumeEvent(View2DEvent* ec, bool handled = TRUE);
454
459
462
466 virtual bool implementsManagedInteractionAndClassicEventHandling() const { return false; }
467
468protected:
475 void pick(SoPickAction *action) override;
476 void doAction(SoAction *action) override;
478
480 virtual void editingOnChanged(SoField*) {}
481
483 virtual void buttonMaskChanged(SoField*) {}
484
486 virtual void createNewModeRequestTriggered(SoField*) { setCreateNewModeRequest(TRUE); }
487
490
492 float _rgbColor[4];
493
496
499
500private:
501
503 bool _active;
505 SoView2D* _activeView2D;
506
508 View2DEvent *_ec;
509
511 bool _createNewModeRequest;
512};
tristateType
mode used for event filter
@ PRESSED
@ IGNORED
@ RELEASED
View2DEventPhase
event phase for simple extensions that grab the focus, do something (motion) and are released afterwa...
@ EVENT_START
mouse mask of extension has become true (correct button+key combination)
@ EVENT_ANY
Event phase is undefined and has to be checked by getEvent() method.
@ EVENT_MOUSEOVER_UPDATE
An update was requested because a redraw is about to happen and the extension should show actual valu...
@ EVENT_MOTION
Motion while mask is still true.
@ EVENT_KEY_RELEASED
Key was released.
@ EVENT_RELEASE
Mask of extension has become false.
@ EVENT_KEY_PRESSED
Key was pressed.
@ EVENT_MOUSEWHEEL
Mouse wheel was turned.
LineStyles
Definition of line styles for stippling.
@ LONG_DASHED
#define SOVIEW2D_API
File to resolve system dependencies in View2D library.
Class ManagedMouseButtonTrigger encapsulates the combination of required and ignored mouse buttons an...
SoInteractionProviderNode is the base class for all interaction nodes in OpenInventor.
The SoSFMLImage field is the interface used by Inventor Nodes to access image data (in the current im...
Definition SoSFMLImage.h:70
SoView2DExtension Base class for all View2DExtensions used for drawing and event handling on the View...
void handleEvent(SoHandleEventAction *action) override
SoSFBool wantsMouseWheelEvents
flag if MouseWheel events should be passed to evalEvent()
int getX()
get the x device position of current event, only returns valid result when called inside of evalEvent...
virtual bool isActive()
returns if the extension is active (derive this method in child) (in createNewMode or with a selected...
static bool isImageParallel(SoSFMLImage *image, View2DSliceList *dsl)
Return true if image is parallel to the image of the slice list up to slice thickness.
SoSFBool needsValidVoxel
sets if a valid voxel must be hit to get evalEvent() calls
SoSFEnum control
shift control for mouse mask
void pick(SoPickAction *action) override
static float pointToLineDistance(SbVec3f point, SbVec3f line1, SbVec3f line2)
calculate 3D point to line distance
void setCreateNewMode(bool flag)
set this extension to create new objects
static void disableLineStippling(const SoSFEnum &lineStyleField)
void init()
setup internal state
void drawFixedSizeMiniCircleAt(float xp, float yp)
Draws a fixed size small circle at the given position.
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.
static void enableLineStippling(const SoSFEnum &lineStyleField)
Set/reset stippling pattern.
virtual bool ignoreEvent(View2DEvent *ec)
Return true if ec has been handled before and if ignoreHandledEvents is True.
int getY()
get the y device position of current event, only returns valid result when called inside of evalEvent...
static float snapToPixelCenter(float coordinateComponent)
Snaps the coordinate component to the pixel center.
SoSFEnum shift
shift modifier for mouse mask
SoSFBool editingOn
flag if the extension should edit objects on mouse events, needs to be checked inside of the evalEven...
void getMatrix(SoGetMatrixAction *action) override
virtual bool implementsManagedInteractionAndClassicEventHandling() const
return true if this node is a hybrid module providing managed interaction and classic event handling ...
bool wantsMouseOverUpdates() const
public access to _wantsMouseOverUpdateEvents
void drawFilledMiniRect(float xp, float yp, float ext, float lineWidth=1.f)
Draws a small filled rectangle with given half side length.
SoSFBool clipToSlice
Flag to clip drawing to slice.
bool _wantsMouseOverUpdateEvents
set this flag to receive mouse over events while the extension is active
SoSFEnum button1
mouse mask for button1
View2DEvent * getEvent()
get the current event (when inside of evalEvent)
SoSFTrigger createNewModeRequest
~SoView2DExtension() override
destructor
int getSelectedModifierMask()
Get compare and ignore mask for the currently selected button/modifier combination,...
bool isCreateNewMode()
check if extension is in createNewMode
virtual void createNewModeRequestTriggered(SoField *)
called when createNewModeRequest field ist touched:
SoPointingAction::Trigger getPointingActionTriggerFromFields()
Get the trigger that matches the button/modifier field state.
static void getAxisOrientation(int axis, SbMatrix &matrix, char &negativeResult, char &positiveResult)
Geometry helpers.
virtual bool isClipToSlice()
check if the image is clipped to slice
virtual void deleteSelectedObject()
deletes the currently active object (derive this method in child) (called by SoView2D)
bool isCreateNewModeRequest()
check if extension has a request for createNewMode
SoSFBool setEventHandled
Set event handled if it is indeed handled by this extension.
Sign
defines the sign of a number, with zero as an extra value
void setCreateNewModeRequest(bool flag)
set that extension want to become createNewMode
SoSFBool maskValid
flag if the event mask is valid.
static void initClass()
Initializes this class.
virtual bool evalEvent(SoView2D *view2d, View2DSliceList *slicelist, View2DEvent *ec, View2DEventPhase phase)
Called by the SoView2D for each event that happens on the viewer.
void drawDashedMiniRect(float xp, float yp, float ext, float lineWidth)
SoNodeSensor * _nodeSensor
node sensor that is used to notice field changes
void drawFilledMiniCircle(float xp, float yp, float ext, float lineWidth=1.f)
Draws a small filled circle with given center point and radius.
float getSelectDist()
Set the distance tolerance on hit checking in pixels.
SoView2DExtension()
Constructor.
virtual bool isDrawingOn()
check if drawing is on
void doAction(SoAction *action) override
SoSFBool wantsAllEvents
flag if ALL events should be passed to evalEvent(), if disabled, events are only passed to evalEvent ...
virtual void overwriteDrawingSettings(SoView2DDrawingSettings &)
virtual void endDrawing(View2DSliceList *)
virtual bool isEditingOn()
check if editing is on
SoSFBool wantsKeyEvents
flag if keyboard events should be passed to evalEvent()
virtual void fieldChanged(SoSensor *sensor)
handle if any field has changed
SoSFBool drawingOn
flag if the extension should draw, needs to be checked inside of the draw() method
void drawMiniTriangle(float xp, float yp, float ext, float lineWidth=1.f)
Draws a small triangle with given center point, half height and line width.
virtual void getStatusString(SbString &status)
get the current status of this extension
virtual void editingOnChanged(SoField *)
called when editingOn field is touched:
void callback(SoCallbackAction *action) override
virtual bool evaluateEvent(SoView2D *view2d, View2DEvent *ec)
void GLRender(SoGLRenderAction *action) override
Inventor actions.
SoSFEnum alt
shift alt for mouse mask
SoSFColor color
color that should be used for drawing
SoSFEnum button2
mouse mask for button2
int getSelectedIgnoreMask()
void drawMiniCircle(float xp, float yp, float ext, float lineWidth=1.f)
Draws a small circle with given center point and radius.
SoSFFloat selectionTolerance
the selection tolerance in pixels
static float pointToLineDistance(SbVec2f point, SbVec2f line1, SbVec2f line2)
calculate 2D point to line distance
virtual void draw(View2DSliceList *slicelist, View2DSlice *slice, int sliceZ)
Called by the SoView2D for each slice that is rendered.
SoSFBool fixZOn
DEPRECATED flag that indicates that the extension should fix the z value, only used in SoView2DRectan...
virtual void buttonMaskChanged(SoField *)
called when one of the button/modifier fields is touched:
SoSFBool renderOnSlab
defines if the extension should be rendered on all slab slices
SoSFEnum button3
mouse mask for button3
void drawFilledMiniTriangle(float xp, float yp, float ext, float lineWidth=1.f)
Draws a small filled triangle with given center point and half height.
virtual void consumeEvent(View2DEvent *ec, bool handled=TRUE)
Set handled-flag of ec to true (= consumed) if handled is True and setEventHandled is True.
void getBoundingBox(SoGetBoundingBoxAction *action) override
SoSFBool ignoreHandledEvents
Ignore events, that have been handled by previous extensions.
SoSFBool createNewMode
flag if extension is in createNewMode
virtual bool isFixZOn()
check if z should stay fixed
virtual void startDrawing(View2DSliceList *)
static Sign edgeIntersectWithPlane(const SbVec3f &v1, const SbVec3f &v2, const SbPlane &plane, SbVec3f &intersect)
intersect given edge from v1 to v2 with given plane, returns sign and intersect point
void drawMiniRect(float xp, float yp, float ext, float lineWidth=1.f)
Draws a small rectangle with given half side length and a line width.
virtual void updateValues()
Update fields to local variables, may be reimplemented if you want to update additional local vars.
void drawVoxelBorder(View2DSlice *slice, float vx, float vy, float vz)
surround the given voxel with a border
SoSFEnum cursorShape
Set cursor shape if the mouse mask fits and mouseEvents are effectively sent to evalEvent for editing...
static void fieldChangedCB(void *data, SoSensor *sensor)
inventor callbacks if any field has changed, calls fieldChanged
SoView2D is a 2D viewer for image data.
Definition SoView2D.h:62
View2DEvent stores all information on an event on a SoView2D.
int keyCode
key code
bool isOverViewer
is the device position on the viewer area
bool mouseOverUpdate
mouse over update
bool doubleclick
check if the event is a double click
bool handled
flag if the event was handled by someone
int button
index of button this event relates to
float slicePosX
voxel position if a slice was hit
bool button1
button1-3 currently down?
bool isKeyPressed
is key press event
void setValues(bool sh, bool ct, bool al, bool pr, bool mo, bool re, bool dc, bool b1, bool b2, bool b3, int dpx, int dpy, bool ov, int button, bool isKP, bool isKR, bool iVK, int kk, bool iVSP, float spx, float spy, float spz, long secs, long usecs, const SoEvent *event)
void print()
Method to get a string for coding/decoding the events.
bool press
mouse pressed
View2DEvent(bool sh, bool ct, bool al, bool pr, bool mo, bool re, bool dc, bool b1, bool b2, bool b3, int dpx, int dpy, bool ov, int button, bool isKP, bool isKR, bool iVK, int kk, bool iVSP, float spx, float spy, float spz, long secs, long usecs, const SoEvent *event)
bool isValidSlicePos
was a slice hit?
bool isValidKey
is a valid key code
bool shift
Public members to be read from user.
int devicePosY
device Y position on the viewport (can also be virtual coordinate when rendered in 3D)
bool release
mouse released
int devicePosX
device X position on the viewport (can also be a virtual coordinate when rendered in 3D)
bool motion
mouse motion
bool isKeyReleased
is key release event
long second
timestamp of event
View2DEvent()
Constructors to initialize the class.
const SoEvent * soevent
original soevent, you should not use this normally
bool sliceHit()
check if a slice was hit
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
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
Drawing settings that can be overwritten by extensions.