MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
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
40#include <mlGLHiDPI.h>
41
42class SoSFMLImage;
43
46{
48 {
49 drawImageData = true;
50 applyLut = true;
51 }
52
55};
56
57#ifndef TRISTATE
58#define TRISTATE
65
67
77#define TEST_STATE(state, flag) (((state) == IGNORED) ? TRUE : (((state) == PRESSED) == ((flag) != 0)))
78
79#endif
80
81//--------- disable VC++ warnings---------
82#ifdef WIN32
83#pragma warning(disable : 4355)
84#pragma warning(disable : 4275)
85#pragma warning(disable : 4251)
86#pragma warning(disable : 4138)
87#endif
88
89class View2DSliceList;
90class View2DSlice;
91class SoView2D;
92
106
107//==============================================================
109//==============================================================
111{
112public:
115 View2DEvent(bool sh, bool ct, bool al, bool pr, bool mo, bool re, bool dc, bool b1, bool b2, bool b3, int dpx,
116 int dpy, bool ov, int button, bool isKP, bool isKR, bool iVK, int kk, bool iVSP, float spx, float spy,
117 float spz, long secs, long usecs, const SoEvent* event);
118
119 void setValues(bool sh, bool ct, bool al, bool pr, bool mo, bool re, bool dc, bool b1, bool b2, bool b3, int dpx,
120 int dpy, bool ov, int button, bool isKP, bool isKR, bool iVK, int kk, bool iVSP, float spx, float spy,
121 float spz, long secs, long usecs, const SoEvent* event);
122
124 void print();
125
127 bool sliceHit()
128 {
129 return isValidSlicePos;
130 }
131
133
135 bool shift, ctrl, alt;
136
138 bool press;
140 bool motion;
145
148
151
160
165
174
176 long second;
178
181
186};
187
195
196#define VIEW2D_DEFINE_LINE_STYLE_ENUM \
197 SO_NODE_DEFINE_ENUM_VALUE(LineStyles, SOLID); \
198 SO_NODE_DEFINE_ENUM_VALUE(LineStyles, DASHED); \
199 SO_NODE_DEFINE_ENUM_VALUE(LineStyles, DOTTED); \
200 SO_NODE_DEFINE_ENUM_VALUE(LineStyles, LONG_DASHED);
201
202#define VIEW2D_ADD_LINE_STYLE_FIELD(lineStyleField) \
203 SO_NODE_ADD_FIELD(lineStyleField, (SOLID)); \
204 SO_NODE_SET_SF_ENUM_TYPE(lineStyleField, LineStyles);
205
206
207//=============================================================
211
212//=============================================================
214{
215 SO_NODE_HEADER(SoView2DExtension);
216
217public:
224
227
230
238
243
244
257
260
263
267
270
274
276
278 static void initClass();
279
282
284 void init();
285
287 virtual void updateValues();
288
290
294 virtual void draw(View2DSliceList* slicelist, View2DSlice* slice, int sliceZ);
295
297
304 virtual bool evalEvent(SoView2D* view2d, View2DSliceList* slicelist, View2DEvent* ec, View2DEventPhase phase);
305
308 virtual void startDrawing(View2DSliceList* /*slicelist*/) {};
309
311 virtual void endDrawing(View2DSliceList* /*slicelist*/) {};
312
314 virtual void overwriteDrawingSettings(SoView2DDrawingSettings& /*settings*/) {};
315
318
321
323 inline static float snapToPixelCenter(float coordinateComponent)
324 {
325 return floorf(coordinateComponent) + 0.5f;
326 }
327
330 bool isPointInsideDeviceRect(float pointX, float pointY, float centerX, float centerY, float hitRectangleSize = 0.0);
331
333 void drawMiniRect(float xp, float yp, float ext, float lineWidth = 1.f);
336 void drawDashedMiniRect(float xp, float yp, float ext, float lineWidth);
338 void drawFilledMiniRect(float xp, float yp, float ext, float lineWidth = 1.f);
339
341 void drawMiniTriangle(float xp, float yp, float ext, float lineWidth = 1.f);
343 void drawFilledMiniTriangle(float xp, float yp, float ext, float lineWidth = 1.f);
344
346 void drawMiniCircle(float xp, float yp, float ext, float lineWidth = 1.f);
348 void drawFilledMiniCircle(float xp, float yp, float ext, float lineWidth = 1.f);
350 void drawFixedSizeMiniCircleAt(float xp, float yp);
351
353 void drawVoxelBorder(View2DSlice* slice, float vx, float vy, float vz);
354
356 int getX();
357
359 int getY();
360
362 virtual bool isDrawingOn()
363 {
364 return drawingOn.getValue();
365 };
367 virtual bool isEditingOn()
368 {
369 return editingOn.getValue();
370 };
372 virtual bool isClipToSlice()
373 {
374 return clipToSlice.getValue();
375 };
376
378 static void fieldChangedCB(void* data, SoSensor* sensor);
381
386
391
394 virtual bool isActive();
395
397 virtual void deleteSelectedObject();
398
400 virtual void getStatusString(SbString& status);
401
406
408
413 static void getAxisOrientation(int axis, SbMatrix& matrix, char& negativeResult, char& positiveResult);
414
419
421 enum Sign {
424 POSITIVE
425 };
426
428 static Sign edgeIntersectWithPlane(const SbVec3f& v1, const SbVec3f& v2, const SbPlane& plane, SbVec3f& intersect);
429
431
437
440
442 virtual bool ignoreEvent(View2DEvent* ec);
443
446 {
447 return _wantsMouseOverUpdateEvents;
448 }
449
451 virtual void consumeEvent(View2DEvent* ec, bool handled = TRUE);
452
457
460
465 {
466 return false;
467 }
468
469protected:
476 void pick(SoPickAction* action) override;
477 void doAction(SoAction* action) override;
479
482 {}
483
486 {}
487
490 {
491 setCreateNewModeRequest(TRUE);
492 }
493
496
498 float _rgbColor[4];
499
502
505
506private:
508 bool _active;
510 SoView2D* _activeView2D;
511
513 View2DEvent* _ec;
514
516 bool _createNewModeRequest;
517};
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:84
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.
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 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.