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 
31 class SoView2D;
32 class View2DFont;
33 class SoOrthographicCamera;
34 class SoMatrixTransform;
35 class SoDirectionalLight;
36 
37 // Constant name definitions
38 
44 };
45 
50 };
51 
57  ANNO_SIZE_USER = 3
58 };
59 
64 };
65 
71 };
72 
74 {
76  {
77  spaceX = -1;
78  spaceY = -1;
79  lastFontSize = -1;
83  }
84  int spaceX;
85  int spaceY;
90 };
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 
112 public:
113 
121  CENTER_CENTER
122  };
123 
125 
131 
137 
143 
144  SoSFString shortTopLeft;
145  SoSFString shortTopRight;
146  SoSFString shortBottomLeft;
147  SoSFString shortBottomRight;
148  SoSFString shortBottomCenter;
149 
150  SoSFInt32 minDetailFontSize;
151  SoSFInt32 maxDetailFontSize;
152  SoSFInt32 minShortFontSize;
153  SoSFInt32 maxShortFontSize;
155  SoSFInt32 userShortFontSize;
156 
157  SoSFInt32 rulerFontSize;
158 
159  SoSFEnum annotationMode;
160  SoSFEnum showAnnotation;
162  SoSFBool textShadow;
163  SoSFColor textShadowColor;
164  SoSFBool rulerShadow;
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 
170  SoSFInt32 marginTop;
171  SoSFInt32 marginLeft;
172  SoSFInt32 marginBottom;
173  SoSFInt32 marginRight;
174 
175  SoSFInt32 abreviateChars;
177 
178  SoSFEnum showOrientation;
181  SoSFColor orientationColor;
182 
183  SoSFBool verticalRuler;
184  SoSFBool horizontalRuler;
187 
199 
201 
203 
204  SoSFString input00;
205  SoSFString input01;
206  SoSFString input02;
207  SoSFString input03;
208  SoSFString input04;
209  SoSFString input05;
210  SoSFString input06;
211  SoSFString input07;
212  SoSFString input08;
213  SoSFString input09;
214 
215  SoSFDouble numInput00;
216  SoSFDouble numInput01;
217  SoSFDouble numInput02;
218  SoSFDouble numInput03;
219  SoSFDouble numInput04;
220  SoSFDouble numInput05;
221  SoSFDouble numInput06;
222  SoSFDouble numInput07;
223  SoSFDouble numInput08;
224  SoSFDouble numInput09;
225 
226  // field for definition of background box
228  SoSFColor backgroundColor;
229  SoSFFloat backgroundOpacity;
232 
234 
235  SoSFBool isMouseOverCube;
237 
242 
244  static void initClass();
245 
248 
250 
252  void draw(View2DSliceList *dsl, View2DSlice* dslice, int slice) override;
253 
255  bool evalEvent(SoView2D* view2d, View2DSliceList* slicelist,
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 
271  float decimalFloor(float number, SbString& result, int &divider);
272 
274  void drawVerticalRuler(View2DSliceList* dsl, View2DSlice* dslice, bool drawText, int marginRight, const PixelBoundingBox& pixelBoundingBox);
275  void drawHorizontalRuler(View2DSliceList* dsl, View2DSlice* dslice, bool drawText, int marginBottom, const PixelBoundingBox& pixelBoundingBox);
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;
313  int bottom;
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 
328  virtual int calculateOrientationModelOffset(int viewSize, const SoSFFloat& relativeOffset,
329  const SoSFInt32& minOffsetPixels, const SoSFInt32& maxOffsetPixels);
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 
350  virtual void drawOrientationCubeLetter(char letter, int modelSize, bool shadowPass);
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 
368 protected:
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 
382  void editingOnChanged(SoField* field) override;
383 
385  virtual void clearViewerCache(SoField* field) { _lastViewerInfoCache.clear(); }
386 
387 private:
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);
423  void _drawRulers(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);
427  bool _findFontSizeAndDetailLevel(View2DSliceList * dsl, View2DSlice* dslice, int& fontSize, const PixelBoundingBox& pixelBoundingBox, const PixelBoundingBox& centerBoundingBox, SbString* resultString, const SbString& topLeft, const SbString& topRight, const SbString& bottomLeft, const SbString& bottomRight, const SbString& bottomCenter);
428  bool _findFittingFontSize(int& fontsize, const PixelBoundingBox& pixelBoundingBox, const PixelBoundingBox& centerBoundingBox, int minfontsize, int maxfontsize, SbString * resultString);
429  void _fillPixelBoundingBoxes(View2DSlice* dslice, PixelBoundingBox &pixelBoundingBox, PixelBoundingBox &centerBoundingBox);
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
SoSFString fontWidthDummyString
SoSFInt32 orientationModelMaxHorizontalOffset
virtual Margins calculateCenterTextMargins(int width, int height)
margins for center text (horizontally) can be different
SoSFString hitOrientationLetter
SoSFString annotationCTTopRight
SoSFString annotationMRBottomCenter
static void initClass()
inventor runtime type system
SoSFInt32 horizontalRulerMarginBottom
SoSFString annotationMRBottomRight
SoSFInt32 verticalRulerMarginRight
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...
SoSFInt32 orientationModelMinSize
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 annotationMRTopLeft
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
AlignPosition
Mode for alignment of text boxes on viewer.
SoSFInt32 orientationModelMaxSize
SoSFString annotationUserBottomRight
void parseString(View2DSliceList *list, View2DSlice *slice, const SbString &string, SbString &resultString, int limitToChars=-1)
parses the given string and substitutes and
SoSFString annotationMRTopRight
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.
SoPointingAction * endPress(int clickCount) override
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
SoSFString annotationCTTopLeft
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
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)
FloatingPointVector< T, size, DataContainer > & operator*=(FloatingPointVector< T, size, DataContainer > &op1, MLdouble value)
Arithmetic assignment: Component wise multiplication *this with specialized MLdouble scalar value.
Stores top/bottom/left/right margins.
Margins(int top, int right, int bottom, int left)