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#endif
85
86class View2DSliceList;
87class View2DSlice;
88class SoView2D;
89
102
103//==============================================================
105//==============================================================
107{
108public:
111 View2DEvent(bool sh, bool ct, bool al,
112 bool pr, bool mo, bool re, bool dc,
113 bool b1, bool b2, bool b3,
114 int dpx, int dpy, bool ov,
115 int button,
116 bool isKP, bool isKR,
117 bool iVK, int kk,
118 bool iVSP, float spx, float spy, float spz,
119 long secs, long usecs, const SoEvent* event);
120
121 void setValues(bool sh, bool ct, bool al,
122 bool pr, bool mo, bool re, bool dc,
123 bool b1, bool b2, bool b3,
124 int dpx, int dpy, bool ov,
125 int button,
126 bool isKP, bool isKR,
127 bool iVK, int kk,
128 bool iVSP, float spx, float spy, float spz,
129 long secs, long usecs, const SoEvent* event);
130
132 void print();
133
135 bool sliceHit() { return isValidSlicePos; }
136
138
140 bool shift, ctrl, alt;
141
143 bool press;
145 bool motion;
150
153
156
165
170
179
181 long second;
183
185 const SoEvent* soevent;
186
191};
192
194#define EventContainer View2DEvent
195#define EventPhase View2DEventPhase
196
205
206#define VIEW2D_DEFINE_LINE_STYLE_ENUM \
207 SO_NODE_DEFINE_ENUM_VALUE(LineStyles, SOLID); \
208 SO_NODE_DEFINE_ENUM_VALUE(LineStyles, DASHED); \
209 SO_NODE_DEFINE_ENUM_VALUE(LineStyles, DOTTED); \
210 SO_NODE_DEFINE_ENUM_VALUE(LineStyles, LONG_DASHED);
211
212#define VIEW2D_ADD_LINE_STYLE_FIELD(lineStyleField) \
213 SO_NODE_ADD_FIELD(lineStyleField, (SOLID)); \
214 SO_NODE_SET_SF_ENUM_TYPE(lineStyleField, LineStyles);
215
216
217//=============================================================
221
222//=============================================================
224{
225 SO_NODE_HEADER(SoView2DExtension);
226
227public:
229 SoSFColor color;
231 SoSFBool drawingOn;
233 SoSFBool editingOn;
234
236 SoSFBool maskValid;
237
240
248
253
254
256 SoSFEnum button1;
258 SoSFEnum button2;
260 SoSFEnum button3;
262 SoSFEnum shift;
264 SoSFEnum control;
266 SoSFEnum alt;
267
270
272 SoSFBool renderOnSlab;
273
277
279 SoSFBool clipToSlice;
280
283 SoSFEnum cursorShape;
284
286
288 SoSFBool fixZOn;
289
291 static void initClass();
292
295
297 void init();
298
300 virtual void updateValues();
301
303
307 virtual void draw(View2DSliceList *slicelist,View2DSlice* slice, int sliceZ);
308
310
316 virtual bool evalEvent(SoView2D* view2d, View2DSliceList* slicelist,
317 View2DEvent* ec, View2DEventPhase phase);
318
321 virtual void startDrawing(View2DSliceList * /*slicelist*/){};
322
324 virtual void endDrawing(View2DSliceList * /*slicelist*/){};
325
327 virtual void overwriteDrawingSettings(SoView2DDrawingSettings& /*settings*/) {};
328
331
334
336 inline static float snapToPixelCenter(float coordinateComponent) { return floorf(coordinateComponent) + 0.5f; }
337
340 bool isPointInsideDeviceRect(float pointX, float pointY, float centerX, float centerY, float hitRectangleSize=0.0);
341
343 void drawMiniRect(float xp, float yp, float ext, float lineWidth = 1.f);
346 void drawDashedMiniRect(float xp, float yp, float ext, float lineWidth);
348 void drawFilledMiniRect(float xp, float yp, float ext, float lineWidth = 1.f);
349
351 void drawMiniTriangle(float xp, float yp, float ext, float lineWidth = 1.f);
353 void drawFilledMiniTriangle(float xp, float yp, float ext, float lineWidth = 1.f);
354
356 void drawMiniCircle(float xp, float yp, float ext, float lineWidth = 1.f);
358 void drawFilledMiniCircle(float xp, float yp, float ext, float lineWidth = 1.f);
360 void drawFixedSizeMiniCircleAt(float xp, float yp);
361
363 void drawVoxelBorder(View2DSlice* slice, float vx,float vy,float vz);
364
366 int getX();
367
369 int getY();
370
372 virtual bool isDrawingOn() { return drawingOn.getValue(); };
374 virtual bool isEditingOn() { return editingOn.getValue(); };
376 virtual bool isFixZOn() { return fixZOn.getValue(); };
378 virtual bool isClipToSlice() { return clipToSlice.getValue(); };
379
381 static void fieldChangedCB(void *data, SoSensor *sensor);
383 virtual void fieldChanged(SoSensor* sensor);
384
388 void setCreateNewMode(bool flag);
389
393 void setCreateNewModeRequest(bool flag);
394
396 virtual bool isActive();
397
399 virtual void deleteSelectedObject();
400
402 virtual void getStatusString(SbString& status);
403
405 static void enableLineStippling(const SoSFEnum& lineStyleField);
406 static void disableLineStippling(const SoSFEnum& lineStyleField);
408
410
415 static void getAxisOrientation(int axis, SbMatrix &matrix, char &negativeResult, char &positiveResult);
416
418 static float pointToLineDistance(SbVec3f point, SbVec3f line1, SbVec3f line2);
420 static float pointToLineDistance(SbVec2f point, SbVec2f line1, SbVec2f line2);
421
423 enum Sign { ZERO, NEGATIVE, POSITIVE };
424
426 static Sign edgeIntersectWithPlane(const SbVec3f &v1,
427 const SbVec3f &v2,
428 const SbPlane &plane,
429 SbVec3f &intersect);
430
432
437 virtual bool evaluateEvent(SoView2D *view2d, View2DEvent* ec);
438
440 static bool isImageParallel (SoSFMLImage* image, View2DSliceList *dsl);
441
443 virtual bool ignoreEvent(View2DEvent* ec);
444
446 bool wantsMouseOverUpdates() const { return _wantsMouseOverUpdateEvents; }
447
449 virtual void consumeEvent(View2DEvent* ec, bool handled = TRUE);
450
455
458
462 virtual bool implementsManagedInteractionAndClassicEventHandling() const { return false; }
463
464protected:
466 void GLRender(SoGLRenderAction *action) override;
467 void callback(SoCallbackAction *action) override;
468 void handleEvent(SoHandleEventAction *action) override;
469 void getMatrix(SoGetMatrixAction *action) override;
470 void getBoundingBox(SoGetBoundingBoxAction *action) override;
471 void pick(SoPickAction *action) override;
472 void doAction(SoAction *action) override;
474
476 virtual void editingOnChanged(SoField*) {}
477
479 virtual void buttonMaskChanged(SoField*) {}
480
482 virtual void createNewModeRequestTriggered(SoField*) { setCreateNewModeRequest(TRUE); }
483
485 SoNodeSensor* _nodeSensor;
486
488 float _rgbColor[4];
489
492
495
496private:
497
499 bool _active;
501 SoView2D* _activeView2D;
502
504 View2DEvent *_ec;
505
507 bool _createNewModeRequest;
508};
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
Drawing settings that can be overwritten by extensions.