MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
SoView2DAnnotation.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 "SoView2DSystem.h"
20
21#include <Inventor/fields/SoSFString.h>
22#include <Inventor/fields/SoSFFloat.h>
23#include <Inventor/fields/SoSFDouble.h>
24#include <Inventor/fields/SoSFEnum.h>
25#include <Inventor/fields/SoSFInt32.h>
26#include <Inventor/fields/SoSFNode.h>
27#include <Inventor/nodes/SoSeparator.h>
28#include <DCMTree_Tag.h>
29#include <unordered_map>
30
31class SoView2D;
32class View2DFont;
34class SoMatrixTransform;
36
37// Constant name definitions
38
45
51
59
65
72
91
93{
94 int minx;
95 int maxx;
96 int miny;
97 int maxy;
98};
99
100//-------------------------------------------------------------------------
102
109{
110 SO_NODE_HEADER(SoView2DAnnotation);
111
112public:
122
124
130
136
142
148
155
157
165 // new fields to influence font selection:
166 SoSFString fontWidthDummyString; // fit this string into the target width instead of the real width if != ""
167 SoSFInt32 targetWidth; // assume this to be the target width if != 0
168 SoSFInt32 targetHeight; // assume this to be the target height if != 0
169
174
177
182
187
199
201
203
214
225
246
252
254
257
262
264 static void initClass();
265
268
270
272 void draw(View2DSliceList* dsl, View2DSlice* dslice, int slice) override;
273
275 bool evalEvent(SoView2D* view2d, View2DSliceList* slicelist, View2DEvent* ec, View2DEventPhase phase) override;
276
280
283 int limitToChars = -1);
284
286 void drawAnnotation(const char* string, const PixelBoundingBox& pixelBoundingBox, int fontsize, AlignPosition pos,
287 bool shouldDrawBox, int& outBoxWidth, int& outBoxHeight);
288
291
293 void drawVerticalRuler(View2DSliceList* dsl, View2DSlice* dslice, bool drawText, int marginRight,
295 void drawHorizontalRuler(View2DSliceList* dsl, View2DSlice* dslice, bool drawText, int marginBottom,
297
299 virtual bool drawVerticalRulerTextBelow() const
300 {
301 return false;
302 }
303
306 static void getExtOrientation(int axis, SbMatrix& matrix, float* orWeights, char* negOrientation,
307 char* posOrientation);
308
310 void drawOrientation(const char* string, float posX, float posY, float fontSize, View2DFont* font, float relOffX,
311 float relOffY, float* orWeights);
312
315 static SbVec2f getTargetSizeInScene(SoNode* scene, int width, int height);
316
318 struct Margins
319 {
321 {
322 top = 0;
323 bottom = 0;
324 left = 0;
325 right = 0;
326 }
327 Margins(int value)
328 {
329 top = value;
330 bottom = value;
331 left = value;
332 right = value;
333 }
334 Margins(int top, int right, int bottom, int left)
335 {
336 this->top = top;
337 this->right = right;
338 this->bottom = bottom;
339 this->left = left;
340 }
341 Margins& operator*=(int value)
342 {
343 top *= value;
344 bottom *= value;
345 left *= value;
346 right *= value;
347 return *this;
348 }
349
350 int top;
352 int left;
353 int right;
354 };
355
357 virtual Margins calculateTextMargins(int width, int height);
358
360 virtual Margins calculateCenterTextMargins(int width, int height);
361
363 virtual int calculateOrientationModelSize(int width, int height);
364
368
371
374 virtual void drawOrientationCube(const SbMatrix& rotationMatrix, int posX, int posY, int modelSize);
375
378 virtual void drawAndStoreCubePolygon(char letter, const SbMatrix& rotationMatrix, int posX, int posY, int modelSize,
379 int pass, const SbVec3f& pos0, const SbVec3f& pos1, const SbVec3f& pos2,
380 const SbVec3f& pos3);
381
385 int modelSize);
386
391
393 virtual bool implementsManagedInteraction() const
394 {
395 return true;
396 }
397
401 {
402 return true;
403 }
404
407 bool isSensitiveAt(const SoPointerPosition& pos) override;
408 void startPressAt(const SoPointerPosition& pos) override;
409 void dragMoveTo(const SoPointerPosition& pos) override;
410 SoPointingAction* endPress(int clickCount) override;
412
413
414protected:
416 virtual SbString restrict(const SbString& value, int maxLength) const;
417
420 virtual SbString asString(int value) const;
421 virtual SbString asString(double value, int precision) const;
422
425 virtual SbString getDicomTagValueAsString(DCMTree::Const_TagPtr tagPtr, unsigned int index,
426 unsigned int precision) const;
427
430
433 {
434 _lastViewerInfoCache.clear();
435 }
436
437private:
439 SoSFString* _inputs[10];
440 SoSFDouble* _numInputs[10];
441
442 SoSFString* _inputNames[10];
443 SoSFString* _inputValues[10];
444
446 long _lastEventSecs;
448 long _lastEventUSecs;
449
450 float _FLT_M_PI;
451
452 void clearLastViewerInfoCache([[maybe_unused]] SoField* field)
453 {
454 _lastViewerInfoCache.clear();
455 }
456
457 std::unordered_map<void*, LastViewerInfo> _lastViewerInfoCache;
458
459 struct OrientationCubePolygon
460 {
461 SbVec2f positions[4];
462 char orientationLetter;
463 };
464
465 std::vector<OrientationCubePolygon> _orientationCubePolygons;
466
468 bool isPointInPolygon(const SbVec2f& point, const SbVec2f& polygon0, const SbVec2f& polygon1, const SbVec2f& polygon2,
469 const SbVec2f& polygon3);
471 bool isSameSide(const SbVec2f& point0, const SbVec2f& point1, const SbVec2f& line0, const SbVec2f& line1) const;
473 bool isOverOrientationCube(const SbVec2f& position)
474 {
475 char letter;
476 return isOverOrientationCube(position, letter);
477 }
479 bool isOverOrientationCube(const SbVec2f& position, char& letter);
480
481 void _drawOrientationLetters(View2DSliceList* dsl, View2DSlice* dslice);
482 void _drawAnnotationStrings(SbString* resultString, const PixelBoundingBox& pixelBoundingBox,
484 void _drawTechnicalInfo(View2DSliceList* dsl, View2DSlice* dslice, const PixelBoundingBox& pixelBoundingBox);
486 void _drawOrientationModel(View2DSliceList* dsl, View2DSlice* dslice, const PixelBoundingBox& pixelBoundingBox,
487 int annotationBoxSize[5][2]);
488
489 int _getDefaultFontSize(int fontsize, int userfontsize);
490 bool _findFontSizeAndDetailLevel(View2DSliceList* dsl, View2DSlice* dslice, int& fontSize,
494 const SbString& bottomCenter);
495 bool _findFittingFontSize(int& fontsize, const PixelBoundingBox& pixelBoundingBox,
498 void _fillPixelBoundingBoxes(View2DSlice* dslice, PixelBoundingBox& pixelBoundingBox,
500 bool _isRulerSupported(View2DSliceList* dsl);
501 int _getAnnotationMode(View2DSliceList* dsl) const;
502 void _fillCornerStringsDependingOnAnnotationMode(View2DSliceList* dsl, SbString& topLeft, SbString& topRight,
504
505 bool _heightFits(int h1, int h2, int h3, int h4, int h5, int tHeight, int ctHeight) const
506 {
507 return (h1 + h3 <= tHeight) && (h2 + h4 <= tHeight) && (h5 <= ctHeight);
508 }
509 bool _dummyStringFitsIntoWidth(bool useDummyString, int w0, int tWidth) const
510 {
511 return useDummyString && (w0 < tWidth);
512 }
513 bool _actualTextFitsIntoWidth(bool useDummyString, int w1, int w2, int w3, int w4, int w5, int tWidth,
514 int ctWidth) const
515 {
516 return !useDummyString && (w1 + w2 <= tWidth) && (w3 + w4 <= tWidth) && (w5 <= ctWidth);
517 }
518
519 static SbString getStringForChar(char c)
520 {
521 return SbString(std::string(1, c).c_str());
522 }
523
524 SoRef<SoSeparator> _orientationModelScene;
525 SoSeparator* _orientationModelInnerScene;
526 SoOrthographicCamera* _orientationModelCamera;
527 SoDirectionalLight* _orientationModelHeadlight;
528
529 SoCommandAction* _toggleAnnotationAction;
530 SoCommandAction* _toggleTechnicalInfoAction;
531};
AnnotationOrientionModelPosition
@ ANNO_BOTTOM_LEFT
@ ANNO_BOTTOM_RIGHT
@ ANNO_TOP_LEFT
@ ANNO_TOP_RIGHT
AnnotationFontSize
@ ANNO_SIZE_SMALL
@ ANNO_SIZE_MEDIUM
@ ANNO_SIZE_AUTO
@ ANNO_SIZE_LARGE
@ ANNO_SIZE_USER
AnnotationMode
@ ANNO_MODE_CT
@ ANNO_MODE_MR
@ ANNO_MODE_AUTO
@ ANNO_MODE_USER
AnnotationOrientationMode
@ ANNO_ORIENTATION_SIZE_WEIGHTED
@ ANNO_ORIENTATION_SIZE_FIXED
@ ANNO_ORIENTATION_OFF
AnnotationShowMode
@ ANNO_SHOW_HIDE
@ ANNO_SHOW_DETAILED
@ ANNO_SHOW_SHORT
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.
SoCommandAction is the base class for instantaneous actions.
SoPointerPosition manages the current position of the mouse cursor.
SoPointingAction is the base class for any mouse based interaction.
Annotation extension for the SoView2D.
virtual void drawOrientationCubeLetter(char letter, int modelSize, bool shadowPass)
draw the given letters.
virtual int calculateOrientationModelOffset(int viewSize, const SoSFFloat &relativeOffset, const SoSFInt32 &minOffsetPixels, const SoSFInt32 &maxOffsetPixels)
calculates an offset for the orientation model position
SoView2DAnnotation()
Constructor.
SoSFString annotationCTBottomLeft
~SoView2DAnnotation() override
void drawOrientation(const char *string, float posX, float posY, float fontSize, View2DFont *font, float relOffX, float relOffY, float *orWeights)
Draw orientation letters.
SoSFInt32 orientationModelMinHorizontalOffset
void startPressAt(const SoPointerPosition &pos) override
void toggleAnnotation()
toggle displayed information
void drawAnnotation(const char *string, const PixelBoundingBox &pixelBoundingBox, int fontsize, AlignPosition pos, bool shouldDrawBox, int &outBoxWidth, int &outBoxHeight)
draws an AnnotationBox at the given position
SoSFString annotationUserBottomLeft
void toggleTechnicalInfo()
void editingOnChanged(SoField *field) override
called when editingOn field is touched:
SoSFFloat orientationModelRelativeVerticalOffset
static void getExtOrientation(int axis, SbMatrix &matrix, float *orWeights, char *negOrientation, char *posOrientation)
Return extended orientation letters (up to three letters for oblique views) and weights.
virtual void clearViewerCache(SoField *field)
called when any field is changed that affects cached changes
SoSFString annotationUserBottomCenter
bool implementsManagedInteractionAndClassicEventHandling() const override
this node is a hybrid module providing managed interaction and classic event handling
SoSFString annotationUserTopLeft
Fields.
void dragMoveTo(const SoPointerPosition &pos) override
SoSFInt32 orientationModelMaxHorizontalOffset
virtual Margins calculateCenterTextMargins(int width, int height)
margins for center text (horizontally) can be different
SoSFString annotationMRBottomCenter
static void initClass()
inventor runtime type system
SoSFInt32 horizontalRulerMarginBottom
SoSFString annotationMRBottomRight
virtual SbString asString(double value, int precision) const
virtual int calculateOrientationModelSize(int width, int height)
calculates the size of the orientation model
SbMatrix calculateOrientationModelRotationMatrix(View2DSlice *slice)
calculates the rotation matrix for the orientation model
SoSFString annotationUserTopRight
virtual Margins calculateTextMargins(int width, int height)
calculates the margin of the text annotations (to be reimplemented by a derived class)
virtual void drawAndStoreCubePolygon(char letter, const SbMatrix &rotationMatrix, int posX, int posY, int modelSize, int pass, const SbVec3f &pos0, const SbVec3f &pos1, const SbVec3f &pos2, const SbVec3f &pos3)
Draws an orientation cube polygon (a side of the cube) and stores the projected polygon in an interna...
bool evalEvent(SoView2D *view2d, View2DSliceList *slicelist, View2DEvent *ec, View2DEventPhase phase) override
handle keyboard events
virtual SbString getDicomTagValueAsString(DCMTree::Const_TagPtr tagPtr, unsigned int index, unsigned int precision) const
get the value of a dicom tag for display purposes; derived classes might e.g.
virtual void drawOrientationCube(const SbMatrix &rotationMatrix, int posX, int posY, int modelSize)
draws the annotation model for the given rotation matrix at the given position and size using the bui...
void draw(View2DSliceList *dsl, View2DSlice *dslice, int slice) override
draw annotations on slice
static SbVec2f getTargetSizeInScene(SoNode *scene, int width, int height)
Get the minimum view port size of all SoView2Ds in the given scene, provided the scene would be displ...
SoSFBool orientationAndScaleFromCamera
field that enables getting the orientation matrix from the Inventor scene instead of the input image
bool isSensitiveAt(const SoPointerPosition &pos) override
interface forwarded from SoPointingAction:
SoSFString annotationCTBottomCenter
SoSFFloat orientationModelRelativeSize
virtual bool implementsManagedInteraction() const
also implements managed interactions
virtual SbString restrict(const SbString &value, int maxLength) const
restrict string to maximum length, appending "..." if string was truncated
SoSFInt32 orientationModelMaxVerticalOffset
SoPointingAction * endPress(int clickCount) override
AlignPosition
Mode for alignment of text boxes on viewer.
SoSFString annotationUserBottomRight
void parseString(View2DSliceList *list, View2DSlice *slice, const SbString &string, SbString &resultString, int limitToChars=-1)
parses the given string and substitutes and
virtual void drawOrientationModelUsingInventor(SoAction *action, const SbMatrix &rotationMatrix, int posX, int posY, int modelSize)
draws the annotation model for the given rotation matrix at the given position and size using the inO...
SoSFFloat orientationModelRelativeHorizontalOffset
float decimalFloor(float number, SbString &result, int &divider)
returns the closest decimal floor and copies a printable string into the buffer
void drawHorizontalRuler(View2DSliceList *dsl, View2DSlice *dslice, bool drawText, int marginBottom, const PixelBoundingBox &pixelBoundingBox)
virtual bool drawVerticalRulerTextBelow() const
override this to draw the unit text below the vertical ruler instead of to the left of it.
SoSFInt32 orientationModelMinVerticalOffset
SoSFString annotationCTBottomRight
SoSFString annotationMRBottomLeft
virtual SbString asString(int value) const
return numeric value formatted as string derived classes might e.g.
void drawVerticalRuler(View2DSliceList *dsl, View2DSlice *dslice, bool drawText, int marginRight, const PixelBoundingBox &pixelBoundingBox)
draws an annotated ruler
SoView2DInteractionExtension is base class for all SoView2DExtensions that want to support the Manage...
SoView2D is a 2D viewer for image data.
Definition SoView2D.h:62
View2DEvent stores all information on an event on a SoView2D.
Abstract GL font drawing using FTGL.
Definition View2DFont.h:30
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.
boost::shared_ptr< const Tag > Const_TagPtr
Definition DCMTree_Lib.h:58
MLCSO_EXPORT bool isPointInPolygon(const std::vector< Vector3 > &points, const Vector3 &normal, const Vector3 &point)
Stores top/bottom/left/right margins.
Margins & operator*=(int value)
Margins(int top, int right, int bottom, int left)