MeVisLab Toolbox Reference
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:
113
123
125
131
137
143
149
156
158
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
226 // field for definition of background box
232
234
237
242
244 static void initClass();
245
248
250
252 void draw(View2DSliceList *dsl, View2DSlice* dslice, int slice) override;
253
256 View2DEvent* ec, View2DEventPhase phase) override;
257
261
263 void parseString(View2DSliceList* list,View2DSlice* slice, const SbString &string , SbString &resultString, int limitToChars = -1);
264
266 void drawAnnotation(const char* string, const PixelBoundingBox& pixelBoundingBox,
267 int fontsize, AlignPosition pos, bool shouldDrawBox,
268 int& outBoxWidth, int& outBoxHeight);
269
272
276
278 virtual bool drawVerticalRulerTextBelow() const { return false; }
279
282 static void getExtOrientation (int axis, SbMatrix &matrix, float *orWeights,
283 char *negOrientation, char *posOrientation);
284
286 void drawOrientation (const char *string, float posX, float posY, float fontSize,
287 View2DFont* font, float relOffX, float relOffY, float *orWeights);
288
291 static SbVec2f getTargetSizeInScene (SoNode* scene, int width, int height);
292
294 struct Margins {
296 top = 0; bottom = 0; left = 0; right = 0;
297 }
298 Margins(int value) {
299 top = value; bottom = value; left = value; right = value;
300 }
301 Margins(int top, int right, int bottom, int left) {
302 this->top = top;
303 this->right = right;
304 this->bottom = bottom;
305 this->left = left;
306 }
307 Margins &operator *=(int value) {
308 top *= value; bottom *= value; left *= value; right *= value;
309 return *this;
310 }
311
312 int top;
314 int left;
315 int right;
316 };
317
319 virtual Margins calculateTextMargins(int width, int height);
320
322 virtual Margins calculateCenterTextMargins(int width, int height);
323
325 virtual int calculateOrientationModelSize(int width, int height);
326
330
333
336 virtual void drawOrientationCube(const SbMatrix &rotationMatrix, int posX, int posY, int modelSize);
337
340 virtual void drawAndStoreCubePolygon(char letter, const SbMatrix& rotationMatrix, int posX, int posY, int modelSize, int pass,
341 const SbVec3f& pos0, const SbVec3f& pos1, const SbVec3f& pos2, const SbVec3f& pos3);
342
345 virtual void drawOrientationModelUsingInventor(SoAction* action, const SbMatrix &rotationMatrix, int posX, int posY, int modelSize);
346
351
353 virtual bool implementsManagedInteraction() const { return true; }
354
357 bool implementsManagedInteractionAndClassicEventHandling() const override { return true; }
358
361 bool isSensitiveAt(const SoPointerPosition& pos) override;
362 void startPressAt(const SoPointerPosition& pos) override;
363 void dragMoveTo(const SoPointerPosition& pos) override;
364 SoPointingAction* endPress(int clickCount) override;
366
367
368protected:
370 virtual SbString restrict(const SbString& value, int maxLength) const;
371
374 virtual SbString asString(int value) const;
375 virtual SbString asString(double value, int precision) const;
376
379 virtual SbString getDicomTagValueAsString(DCMTree::Const_TagPtr tagPtr, unsigned int index, unsigned int precision) const;
380
383
385 virtual void clearViewerCache(SoField* field) { _lastViewerInfoCache.clear(); }
386
387private:
389 SoSFString* _inputs[10];
390 SoSFDouble* _numInputs[10];
391
393 long _lastEventSecs;
395 long _lastEventUSecs;
396
397 float _FLT_M_PI;
398
399 void clearLastViewerInfoCache(SoField* field) { _lastViewerInfoCache.clear(); }
400
401 std::unordered_map<void*, LastViewerInfo> _lastViewerInfoCache;
402
403 struct OrientationCubePolygon
404 {
405 SbVec2f positions[4];
406 char orientationLetter;
407 };
408
409 std::vector < OrientationCubePolygon > _orientationCubePolygons;
410
412 bool isPointInPolygon(const SbVec2f& point, const SbVec2f& polygon0, const SbVec2f& polygon1, const SbVec2f& polygon2, const SbVec2f& polygon3);
414 bool isSameSide(const SbVec2f& point0, const SbVec2f& point1, const SbVec2f& line0, const SbVec2f& line1) const;
416 bool isOverOrientationCube(const SbVec2f& position) { char letter; return isOverOrientationCube(position, letter); }
418 bool isOverOrientationCube(const SbVec2f& position, char& letter);
419
420 void _drawOrientationLetters(View2DSliceList* dsl, View2DSlice* dslice);
421 void _drawAnnotationStrings(SbString * resultString, const PixelBoundingBox& pixelBoundingBox, const PixelBoundingBox& centerBoundingBox, int fontsize, int annotationBoxSize[5][2]);
422 void _drawTechnicalInfo(View2DSliceList * dsl, View2DSlice* dslice, const PixelBoundingBox& pixelBoundingBox);
424 void _drawOrientationModel(View2DSliceList * dsl, View2DSlice* dslice, const PixelBoundingBox& pixelBoundingBox, int annotationBoxSize[5][2]);
425
426 int _getDefaultFontSize(int fontsize, int userfontsize);
430 bool _isRulerSupported(View2DSliceList * dsl);
431 int _getAnnotationMode(View2DSliceList * dsl) const;
432 void _fillCornerStringsDependingOnAnnotationMode(View2DSliceList * dsl, SbString &topLeft, SbString &topRight, SbString &bottomLeft, SbString &bottomRight, SbString &bottomCenter);
433
434 bool _heightFits(int h1, int h2, int h3, int h4, int h5, int tHeight, int ctHeight) const { return (h1 + h3 <= tHeight) && (h2 + h4 <= tHeight) && (h5 <= ctHeight); }
435 bool _dummyStringFitsIntoWidth(bool useDummyString, int w0, int tWidth) const { return useDummyString && (w0 < tWidth); }
436 bool _actualTextFitsIntoWidth(bool useDummyString, int w1, int w2, int w3, int w4, int w5, int tWidth, int ctWidth) const { return !useDummyString && (w1 + w2 <= tWidth) && (w3 + w4 <= tWidth) && (w5 <= ctWidth); }
437
438 static SbString getStringForChar(char c) { return SbString(std::string(1,c).c_str()); }
439
440 SoRef<SoSeparator> _orientationModelScene;
441 SoSeparator* _orientationModelInnerScene;
442 SoOrthographicCamera* _orientationModelCamera;
443 SoDirectionalLight* _orientationModelHeadlight;
444
445 SoCommandAction* _toggleAnnotationAction;
446 SoCommandAction* _toggleTechnicalInfoAction;
447};
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:63
MLCSO_EXPORT bool isPointInPolygon(const std::vector< Vector3 > &points, const Vector3 &normal, const Vector3 &point)
Stores top/bottom/left/right margins.
Margins(int top, int right, int bottom, int left)