Medical Imaging Interaction Toolkit  2024.06.00
Medical Imaging Interaction Toolkit
mitkPlanarFigureMapper2D.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef mitkPlanarFigureMapper2D_h
14 #define mitkPlanarFigureMapper2D_h
15 
16 #include "mitkCommon.h"
17 #include "mitkMapper.h"
18 #include "mitkPlanarFigure.h"
21 #include "vtkNew.h"
22 #include "vtkPen.h"
23 
24 class vtkContext2D;
25 
26 namespace mitk
27 {
28  class BaseRenderer;
29  class Contour;
30 
109  {
110  public:
112 
113  itkFactorylessNewMacro(Self);
114 
115  itkCloneMacro(Self);
116 
120  void MitkRender(mitk::BaseRenderer *renderer, mitk::VtkPropRenderer::RenderType type) override;
121 
122  static void SetDefaultProperties(mitk::DataNode *node, mitk::BaseRenderer *renderer = nullptr, bool overwrite = false);
123 
127  void ApplyColorAndOpacityProperties(mitk::BaseRenderer *renderer, vtkActor *actor = nullptr) override;
128 
129  protected:
131  {
132  PF_DEFAULT = 0,
133  PF_HOVER = 1,
134  PF_SELECTED = 2,
135 
136  PF_COUNT = 3 // helper variable
137  };
138 
140 
141  ~PlanarFigureMapper2D() override;
142 
154  void RenderLines(const PlanarFigureDisplayMode lineDisplayMode,
155  mitk::PlanarFigure *planarFigure,
156  mitk::Point2D &anchorPoint,
157  const mitk::PlaneGeometry *planarFigurePlaneGeometry,
158  const mitk::PlaneGeometry *rendererPlaneGeometry,
159  const mitk::BaseRenderer *renderer);
160 
164  void RenderQuantities(const mitk::PlanarFigure *planarFigure,
165  mitk::BaseRenderer *renderer,
166  const mitk::Point2D anchorPoint,
167  double &annotationOffset,
168  float globalOpacity,
169  const PlanarFigureDisplayMode lineDisplayMode);
170 
174  void RenderAnnotations(mitk::BaseRenderer *renderer,
175  const std::string name,
176  const mitk::Point2D anchorPoint,
177  float globalOpacity,
178  const PlanarFigureDisplayMode lineDisplayMode,
179  double &annotationOffset);
180 
184  void RenderControlPoints(const mitk::PlanarFigure *planarFigure,
185  const PlanarFigureDisplayMode lineDisplayMode,
186  const mitk::PlaneGeometry *planarFigurePlaneGeometry,
187  const mitk::PlaneGeometry *rendererPlaneGeometry,
188  mitk::BaseRenderer *renderer);
189 
190  void TransformObjectToDisplay(const mitk::Point2D &point2D,
191  mitk::Point2D &displayPoint,
192  const mitk::PlaneGeometry *objectGeometry,
193  const mitk::PlaneGeometry *,
194  const mitk::BaseRenderer *renderer);
195 
196  void DrawMarker(const mitk::Point2D &point,
197  float *lineColor,
198  float lineOpacity,
199  float *markerColor,
200  float markerOpacity,
201  float lineWidth,
203  const mitk::PlaneGeometry *objectGeometry,
204  const mitk::PlaneGeometry *rendererGeometry,
205  const mitk::BaseRenderer *renderer);
206 
210  void PaintPolyLine(const mitk::PlanarFigure::PolyLineType vertices,
211  bool closed,
212  Point2D &anchorPoint,
213  const PlaneGeometry *planarFigurePlaneGeometry,
214  const PlaneGeometry *rendererPlaneGeometry,
215  const mitk::BaseRenderer *renderer);
216 
221  void DrawMainLines(mitk::PlanarFigure *figure,
222  Point2D &anchorPoint,
223  const PlaneGeometry *planarFigurePlaneGeometry,
224  const PlaneGeometry *rendererPlaneGeometry,
225  const mitk::BaseRenderer *renderer);
226 
231  void DrawHelperLines(mitk::PlanarFigure *figure,
232  Point2D &anchorPoint,
233  const PlaneGeometry *planarFigurePlaneGeometry,
234  const PlaneGeometry *rendererPlaneGeometry,
235  const mitk::BaseRenderer *renderer);
236 
237  void InitializeDefaultPlanarFigureProperties();
238 
239  void InitializePlanarFigurePropertiesFromDataNode(const mitk::DataNode *node);
240 
241  void SetColorProperty(float property[3][3], PlanarFigureDisplayMode mode, float red, float green, float blue)
242  {
243  property[mode][0] = red;
244  property[mode][1] = green;
245  property[mode][2] = blue;
246  }
247 
248  void SetFloatProperty(float *property, PlanarFigureDisplayMode mode, float value) { property[mode] = value; }
256  void OnNodeModified();
257 
258  void Initialize(mitk::BaseRenderer *renderer);
259 
260  private:
261 
262  bool m_IsSelected;
263  bool m_IsHovering;
264  bool m_DrawOutline;
265  bool m_DrawQuantities;
266  bool m_DrawShadow;
267  bool m_DrawControlPoints;
268  bool m_DrawName;
269  bool m_DrawDashed;
270  bool m_DrawHelperDashed;
271  bool m_AnnotationsShadow;
272 
273  std::string m_AnnotationFontFamily;
274  bool m_DrawAnnotationBold;
275  bool m_DrawAnnotationItalic;
276  int m_AnnotationSize;
277 
278  // the width of the shadow is defined as 'm_LineWidth * m_ShadowWidthFactor'
279  float m_LineWidth;
280  float m_ShadowWidthFactor;
281  float m_OutlineWidth;
282  float m_HelperlineWidth;
283  // float m_PointWidth;
284 
285  float m_DevicePixelRatio;
286 
288 
289  float m_LineColor[3][3];
290  float m_LineOpacity[3];
291  float m_OutlineColor[3][3];
292  float m_OutlineOpacity[3];
293  float m_HelperlineColor[3][3];
294  float m_HelperlineOpacity[3];
295  float m_MarkerlineColor[3][3];
296  float m_MarkerlineOpacity[3];
297  float m_MarkerColor[3][3];
298  float m_MarkerOpacity[3];
299  float m_AnnotationColor[3][3];
300 
301  // Bool flag that represents whether or not the DataNode has been modified.
302  bool m_NodeModified;
303 
304  // Observer-tag for listening to itk::ModifiedEvents on the DataNode
305  unsigned long m_NodeModifiedObserverTag;
306 
307  // Bool flag that indicates if a node modified observer was added
308  bool m_NodeModifiedObserverAdded;
309 
310  bool m_Initialized;
311 
312  vtkNew<vtkContext2D> m_Context;
314  };
315 
316 } // namespace mitk
317 
318 #endif
mitk::PlanarFigureMapper2D::SetFloatProperty
void SetFloatProperty(float *property, PlanarFigureDisplayMode mode, float value)
Definition: mitkPlanarFigureMapper2D.h:248
mitk::VtkPropRenderer::RenderType
RenderType
Definition: mitkVtkPropRenderer.h:71
MitkPlanarFigureExports.h
mitk::PlaneGeometry
Describes a two-dimensional, rectangular plane.
Definition: mitkPlaneGeometry.h:78
mitk::PlanarFigure
Base-class for geometric planar (2D) figures, such as lines, circles, rectangles, polygons,...
Definition: mitkPlanarFigure.h:50
MITKPLANARFIGURE_EXPORT
#define MITKPLANARFIGURE_EXPORT
Definition: MitkPlanarFigureExports.h:15
vtkSmartPointer< vtkPen >
mitkPlanarFigure.h
mitk::PlanarFigureControlPointStyleProperty::Shape
Shape
Definition: mitkPlanarFigureControlPointStyleProperty.h:47
mitk::PlanarFigureMapper2D::PlanarFigureDisplayMode
PlanarFigureDisplayMode
Definition: mitkPlanarFigureMapper2D.h:130
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitkMapper.h
mitk::Mapper
Base class of all mappers, Vtk as well as OpenGL mappers.
Definition: mitkMapper.h:46
mitk::Point< ScalarType, 2 >
mitkCommon.h
mitk::PlanarFigureMapper2D::SetColorProperty
void SetColorProperty(float property[3][3], PlanarFigureDisplayMode mode, float red, float green, float blue)
Definition: mitkPlanarFigureMapper2D.h:241
mitk::PlanarFigure::PolyLineType
std::vector< PolyLineElement > PolyLineType
Definition: mitkPlanarFigure.h:61
mitkPlanarFigureControlPointStyleProperty.h
mitk::PlanarFigureMapper2D
OpenGL-based mapper to render display sub-class instances of mitk::PlanarFigure.
Definition: mitkPlanarFigureMapper2D.h:108
mitkClassMacro
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:36
mitk::BaseRenderer
Definition: mitkBaseRenderer.h:56
mitk::DataNode
Class for nodes of the DataTree.
Definition: mitkDataNode.h:63
mitk::ROIMapperHelper::SetDefaultProperties
void SetDefaultProperties(DataNode *node, BaseRenderer *renderer, bool override)
Set common default properties for both 2-d and 3-d ROI mappers.