NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
cxVtkHelperClasses.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 
13 #ifndef CXVTKHELPERCLASSES_H_
14 #define CXVTKHELPERCLASSES_H_
15 
16 #include "cxResourceVisualizationExport.h"
17 
18 #include "cxTransform3D.h"
19 #include "cxGraphicalPrimitives.h"
20 
21 #include "vtkForwardDeclarations.h"
22 
23 #include <QColor>
24 
25 // --------------------------------------------------------
26 namespace cx
27 {
28 // --------------------------------------------------------
29 
33 template <typename vtkPropertyOrProperty2DPtr>
34 void setColorAndOpacity(vtkPropertyOrProperty2DPtr property, QColor color)
35 {
36  property->SetColor(color.redF(), color.greenF(), color.blueF());
37  property->SetOpacity(color.alphaF());
38 }
39 
42 Vector3D getColorAsVector3D(QColor color) ;
43 
48 class cxResourceVisualization_EXPORT RGBColor : public boost::array<double,3>
49 {
50 public:
51  RGBColor();
52  RGBColor(double r, double g, double b);
53  explicit RGBColor(const double* rgb);
54  RGBColor(const RGBColor& t);
55  RGBColor& operator=(const RGBColor& t);
56  RGBColor(QColor c);
57  RGBColor& operator=(const QColor& c);
58  ~RGBColor() {}
59 };
60 
65 class cxResourceVisualization_EXPORT OffsetPoint
66 {
67  public:
68  OffsetPoint( vtkRendererPtr renderer );
69  ~OffsetPoint();
70  void setRadius ( int radius );
71  void setValue(Vector3D point, RGBColor color);
72  void setValue(Vector3D point, Vector3D color);
73  void update( const Vector3D& point );
74  vtkActor2DPtr getActor();
75  private:
76  vtkSphereSourcePtr source;
78  vtkActor2DPtr actor;
79  vtkRendererPtr mRenderer;
80 };
81 typedef boost::shared_ptr<OffsetPoint> OffsetPointPtr;
82 
87 class cxResourceVisualization_EXPORT LineSegment
88 {
89  public:
90  LineSegment(vtkRendererPtr renderer);
91  ~LineSegment();
92  void setPoints(Vector3D point1, Vector3D point2, RGBColor color, int stipplePattern = 0xFFFF);
93  void setResolution(int res);
94  void updatePosition(Vector3D point1, Vector3D point2);
95  vtkActor2DPtr getActor();
96  void setColor(RGBColor color);
97  void setPattern(int stipplePattern);
98  void setWidth(float width);
99 
100  private:
101  vtkPolyDataMapper2DPtr mapper2d;
102  vtkActor2DPtr actor2d;
103  vtkRendererPtr mRenderer;
104  vtkLineSourcePtr source;
105 };
106 
111 class cxResourceVisualization_EXPORT TextDisplay
112 {
113  public:
114  TextDisplay(const QString& text, const QColor& color, int fontsize);
115  ~TextDisplay();
116  void setRenderer( vtkRendererPtr renderer );
117  void setPosition( float x, float y);
118  void setPosition( const Vector3D& pos );
119  void setCentered();
120  void updateText(const QString& text );
121  void setColor(QColor color);
122  vtkTextProperty* textProperty();
123  vtkActor2DPtr getActor();
124  void setMaxWidth( int width, vtkViewport *vp );
125  int getMaxWidth();
126  int getWidth( vtkViewport *vp );
127  vtkTextMapperPtr getMapper() { return mapper; }
128 
129  static void forceUseVtkTextMapper();
130 
131  private:
132  vtkTextMapperPtr mapper;
133  vtkActor2DPtr actor;
134  vtkRendererPtr mRenderer;
135  int maxWidth;
136  QString text;
137 
138  static void verifyVtkTextMapper();
139 };
140 typedef boost::shared_ptr<class TextDisplay> TextDisplayPtr;
141 
142 
147 class cxResourceVisualization_EXPORT CrossHair2D
148 {
149  public:
150  CrossHair2D( vtkRendererPtr renderer);
151  ~CrossHair2D();
152  void setValue(const Vector3D& focalPoint, int width, int height, double bordarOffset, const RGBColor& color);
153  //void update( const Vector3D& crossPos );
154  void update( const Vector3D& crossPos, const DoubleBoundingBox3D& vp);
155  void updateRegCross( const Vector3D& crossPos );
156  vtkActor2DPtr getActor();
157  private:
158  vtkCursor2DPtr mCursor2D;
159  vtkPolyDataMapper2DPtr mapper;
160  vtkActor2DPtr actor;
161  vtkRendererPtr mRenderer;
162 };
163 typedef boost::shared_ptr<class CrossHair2D> CrossHair2DPtr;
164 
172 class cxResourceVisualization_EXPORT Axes3D
173 {
174 public:
175  Axes3D(vtkRendererPtr renderer = vtkRendererPtr());
176  ~Axes3D();
177  void setPosition(const Transform3D& pos);
178  vtkProp3DPtr getProp();
179 private:
180  void setCaption(vtkCaptionActor2D* captionActor, const QString& caption, RGBColor color);
181 
182  vtkAxesActorPtr mAxes;
183  vtkRendererPtr mRenderer;
184 };
185 typedef boost::shared_ptr<Axes3D> Axes3DPtr;
186 
187 // --------------------------------------------------------
188 }// namespace vm
189 // --------------------------------------------------------
190 
191 
192 #endif // CXVTKHELPERCLASSES_H_
193 
cx::LineSegment
Helper for drawing a line in 2D.
Definition: cxVtkHelperClasses.h:87
cx::Axes3D
Helper for drawing a coordinate axis in 3D.
Definition: cxVtkHelperClasses.h:172
vtkCursor2DPtr
vtkSmartPointer< class vtkCursor2D > vtkCursor2DPtr
Definition: vtkForwardDeclarations.h:47
cx::DoubleBoundingBox3D
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,...
Definition: cxBoundingBox3D.h:63
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::OffsetPointPtr
boost::shared_ptr< class OffsetPoint > OffsetPointPtr
Definition: cxForwardDeclarations.h:80
vtkAxesActorPtr
vtkSmartPointer< class vtkAxesActor > vtkAxesActorPtr
Definition: vtkForwardDeclarations.h:34
cxGraphicalPrimitives.h
cx::Axes3DPtr
boost::shared_ptr< class Axes3D > Axes3DPtr
Definition: cxForwardDeclarations.h:62
vtkActor2DPtr
vtkSmartPointer< class vtkActor2D > vtkActor2DPtr
Definition: vtkForwardDeclarations.h:30
cx::OffsetPoint
Helper for drawing a point in 2D.
Definition: cxVtkHelperClasses.h:65
cx::CrossHair2D
Helper for drawing a crosshair in 2D.
Definition: cxVtkHelperClasses.h:147
cx::setColorAndOpacity
void setColorAndOpacity(vtkPropertyOrProperty2DPtr property, QColor color)
Definition: cxVtkHelperClasses.h:34
cx::TextDisplayPtr
boost::shared_ptr< class TextDisplay > TextDisplayPtr
Definition: cxForwardDeclarations.h:102
vtkTextMapperPtr
vtkSmartPointer< class vtkTextMapper > vtkTextMapperPtr
Definition: vtkForwardDeclarations.h:135
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
cx::getColorAsVector3D
Vector3D getColorAsVector3D(QColor color)
Definition: cxVtkHelperClasses.cpp:40
cx::RGBColor::~RGBColor
~RGBColor()
Definition: cxVtkHelperClasses.h:58
vtkForwardDeclarations.h
vtkPolyDataMapper2DPtr
vtkSmartPointer< class vtkPolyDataMapper2D > vtkPolyDataMapper2DPtr
Definition: vtkForwardDeclarations.h:111
cx::TextDisplay::getMapper
vtkTextMapperPtr getMapper()
Definition: cxVtkHelperClasses.h:127
cx::RGBColor
RGB color data.
Definition: cxVtkHelperClasses.h:48
cxTransform3D.h
vtkProp3DPtr
vtkSmartPointer< class vtkProp3D > vtkProp3DPtr
Definition: vtkForwardDeclarations.h:119
vtkSphereSourcePtr
vtkSmartPointer< class vtkSphereSource > vtkSphereSourcePtr
Definition: vtkForwardDeclarations.h:130
cx::CrossHair2DPtr
boost::shared_ptr< class CrossHair2D > CrossHair2DPtr
Definition: cxForwardDeclarations.h:64
cx::Vector3D
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
vtkRendererPtr
vtkSmartPointer< class vtkRenderer > vtkRendererPtr
Definition: vtkForwardDeclarations.h:122
cx::TextDisplay
Helper for drawing text in 2D.
Definition: cxVtkHelperClasses.h:111
vtkLineSourcePtr
vtkSmartPointer< class vtkLineSource > vtkLineSourcePtr
Definition: vtkForwardDeclarations.h:87