CustusX  2023.01.05-dev+develop.0da12
An IGT application
cxGraphicalPrimitives.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 #ifndef CXGRAPHICALPRIMITIVES_H_
13 #define CXGRAPHICALPRIMITIVES_H_
14 
15 #include "cxResourceVisualizationExport.h"
16 
17 #include <boost/shared_ptr.hpp>
18 #include "vtkForwardDeclarations.h"
19 #include "cxTransform3D.h"
20 #include "cxViewportListener.h"
21 #include <vtkPolyDataAlgorithm.h>
22 #include <vtkGlyph3DMapper.h>
23 #include <vtkColorSeries.h>
24 #include <vtkLookupTable.h>
25 #include <vtkMapper.h>
26 
27 class QColor;
28 typedef vtkSmartPointer<class vtkPolyDataAlgorithm> vtkPolyDataAlgorithmPtr;
29 typedef vtkSmartPointer<class vtkArcSource> vtkArcSourcePtr;
30 typedef vtkSmartPointer<class vtkArrowSource> vtkArrowSourcePtr;
31 
32 namespace cx
33 {
34 
35 
36 class cxResourceVisualization_EXPORT GraphicalGeometricBase
37 {
38 public:
40  vtkRendererPtr renderer = vtkRendererPtr());
42 
43  void setRenderer(vtkRendererPtr renderer = vtkRendererPtr());
44  void setSource(vtkPolyDataAlgorithmPtr source);
45  void setBackfaceCulling(bool val);
46  void setVisibility(bool visible);
47  void setFrontfaceCulling(bool val);
48  // void setRepresentation();
49  void setColor(double red, double green, double blue);
50  void setColor(Vector3D color);
51  void setPosition(Vector3D point);
52 
53 
54  void setOpacity(double val);
55  void setUserMatrix(vtkMatrix4x4 *matrix);
56  void setPointSize(int pointSize);
57  void setScalarVisibility(bool show);
58  void setScalarModeToUseCellData();
59 
60  vtkActorPtr getActor();
61  vtkPropertyPtr getProperty();
62  vtkPolyDataPtr getPolyData();
63  Vector3D getPosition() const;
64  vtkPolyDataAlgorithmPtr getSource();
65 
66 protected:
72  virtual vtkMapperPtr getMapper()=0;
73 };
74 
75 
83 class cxResourceVisualization_EXPORT GraphicalPolyData3D : public GraphicalGeometricBase
84 {
85 public:
87  vtkRendererPtr renderer = vtkRendererPtr());
88  void setIsWireFrame(bool val);
89  // void setRepresentation();
90  void setData(vtkPolyDataPtr data);
91  void setTexture(vtkTexturePtr texture);
92  vtkMapperPtr getMapper();
93 
94 private:
95  vtkPolyDataMapperPtr mMapper;
96 };
97 typedef boost::shared_ptr<GraphicalPolyData3D> GraphicalPolyData3DPtr;
98 
99 
102 class cxResourceVisualization_EXPORT GraphicalGlyph3DData : public GraphicalGeometricBase
103 {
104 public:
106  vtkRendererPtr renderer = vtkRendererPtr());
107  void setData(vtkPolyDataPtr data);
108  void setOrientationArray(const char* orientationArray);
109  void setColorArray(const char* colorArray);
110  void setLUT(const char* lut);
111  void setScaleFactor(double scaleFactor);
112  vtkMapperPtr getMapper();
113 
114 private:
115  vtkGlyph3DMapperPtr mMapper;
116 };
117 typedef boost::shared_ptr<GraphicalGlyph3DData> GraphicalGlyph3DDataPtr;
118 
119 
122 class cxResourceVisualization_EXPORT GraphicalPoint3D
123 {
124 public:
126  void setRenderer(vtkRendererPtr renderer = vtkRendererPtr());
127  ~GraphicalPoint3D();
128  void setRadius(double radius);
129  // void setColor(Vector3D color);
130  void setColor(QColor color);
131  void setValue(Vector3D point);
132  Vector3D getValue() const;
133  vtkActorPtr getActor();
134  vtkPolyDataPtr getPolyData();
135 
136 private:
137  vtkSphereSourcePtr source;
138  vtkPolyDataMapperPtr mapper;
139  vtkActorPtr actor;
140  vtkRendererPtr mRenderer;
141 };
142 typedef boost::shared_ptr<GraphicalPoint3D> GraphicalPoint3DPtr;
143 
146 class cxResourceVisualization_EXPORT GraphicalLine3D
147 {
148 public:
150  void setRenderer(vtkRendererPtr renderer = vtkRendererPtr());
151  ~GraphicalLine3D();
152  void setColor(QColor color);
153  void setValue(Vector3D point1, Vector3D point2);
154  void setStipple(int stipple);
155  vtkActorPtr getActor();
156 
157 private:
158  vtkPolyDataMapperPtr mapper;
159  vtkActorPtr actor;
160  vtkRendererPtr mRenderer;
161  vtkLineSourcePtr source;
162 };
163 typedef boost::shared_ptr<GraphicalLine3D> GraphicalLine3DPtr;
164 
167 class cxResourceVisualization_EXPORT GraphicalArc3D
168 {
169 public:
171  ~GraphicalArc3D();
172  void setColor(QColor color);
173  void setValue(Vector3D point1, Vector3D point2, Vector3D center);
174  void setStipple(int stipple);
175  vtkActorPtr getActor();
176 
177 private:
178  vtkPolyDataMapperPtr mapper;
179  vtkActorPtr actor;
180  vtkRendererPtr mRenderer;
181  vtkArcSourcePtr source;
182 };
183 typedef boost::shared_ptr<GraphicalArc3D> GraphicalArc3DPtr;
184 
187 class cxResourceVisualization_EXPORT GraphicalArrow3D
188 {
189 public:
191  ~GraphicalArrow3D();
192  void setColor(QColor color);
193  void setValue(Vector3D base, Vector3D normal, double length);
194 
195 private:
196  vtkPolyDataMapperPtr mapper;
197  vtkActorPtr actor;
198  vtkRendererPtr mRenderer;
199  vtkArrowSourcePtr source;
200 };
201 typedef boost::shared_ptr<GraphicalArrow3D> GraphicalArrow3DPtr;
202 
205 class cxResourceVisualization_EXPORT Rect3D
206 {
207 public:
208  Rect3D(vtkRendererPtr renderer, QColor color);
209  ~Rect3D();
210  void setColor(QColor color);
211  void updatePosition(const DoubleBoundingBox3D bb, const Transform3D& M);
212  void setLine(bool on, int width);
213  void setSurface(bool on);
214 
215 private:
216  vtkPolyDataMapperPtr mapper;
217  vtkActorPtr actor;
218  vtkRendererPtr mRenderer;
219  vtkPolyDataPtr mPolyData;
220  vtkPointsPtr mPoints;
221  vtkCellArrayPtr mSide;
222 };
223 typedef boost::shared_ptr<class Rect3D> Rect3DPtr;
224 
228 class cxResourceVisualization_EXPORT FollowerText3D
229 {
230 public:
232  void setRenderer(vtkRendererPtr renderer = vtkRendererPtr());
233 
234  ~FollowerText3D();
235  void setColor(QColor color);
236  void setText(QString text);
237  void setPosition(Vector3D pos);
238 
239  void setSize(double val);
240  void setSizeInNormalizedViewport(bool on, double size);
241  vtkFollowerPtr getActor();
242 
243  void scaleText();
244 
245 private:
246  vtkVectorTextPtr mText;
247  vtkFollowerPtr mFollower;
248  vtkRendererPtr mRenderer;
249  double mSize;
250 
251  ViewportListenerPtr mViewportListener;
252 };
253 typedef boost::shared_ptr<FollowerText3D> FollowerText3DPtr;
254 
258 class cxResourceVisualization_EXPORT CaptionText3D
259 {
260 public:
262  void setRenderer(vtkRendererPtr renderer = vtkRendererPtr());
263 
264  ~CaptionText3D();
265  void setColor(QColor color);
266  void setText(QString text);
267  void setPosition(Vector3D pos);
268 
269  void setSize(double val);
270  // void setSizeInNormalizedViewport(bool on, double size);
271  vtkCaptionActor2DPtr getActor();
272 
273  // void scaleText(); ///< internal method
274 
275  void placeBelowCenter();
276  void placeAboveCenter();
277  void setVisibility(bool visible);
278  Vector3D getPosition() const;
279 private:
280  vtkCaptionActor2DPtr mText;
281  // vtkFollowerPtr mFollower;
282  vtkRendererPtr mRenderer;
283  Vector3D mPos;
284 
285  // ViewportListenerPtr mViewportListener;
286 };
287 typedef boost::shared_ptr<CaptionText3D> CaptionText3DPtr;
288 
293 }
294 
295 #endif /*CXGRAPHICALPRIMITIVES_H_*/
vtkSmartPointer< class vtkTexture > vtkTexturePtr
vtkSmartPointer< class vtkActor > vtkActorPtr
boost::shared_ptr< class GraphicalPoint3D > GraphicalPoint3DPtr
vtkSmartPointer< class vtkPolyDataAlgorithm > vtkPolyDataAlgorithmPtr
PlainObject normal() const
vtkSmartPointer< class vtkPolyDataMapper > vtkPolyDataMapperPtr
boost::shared_ptr< class ViewportListener > ViewportListenerPtr
vtkSmartPointer< class vtkProperty > vtkPropertyPtr
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
vtkSmartPointer< class vtkCellArray > vtkCellArrayPtr
boost::shared_ptr< GraphicalGlyph3DData > GraphicalGlyph3DDataPtr
Helper for rendering a line in 3D.
vtkSmartPointer< vtkPoints > vtkPointsPtr
boost::shared_ptr< GraphicalArc3D > GraphicalArc3DPtr
vtkSmartPointer< class vtkLineSource > vtkLineSourcePtr
Helper for rendering a point in 3D.
Helper for rendering an arrow in 3D.
vtkSmartPointer< class vtkRenderer > vtkRendererPtr
vtkSmartPointer< class vtkFollower > vtkFollowerPtr
Helper for rendering a a polydata in 3D.
vtkSmartPointer< class vtkMapper > vtkMapperPtr
Helper for rendering a line in 3D.
vtkSmartPointer< class vtkCaptionActor2D > vtkCaptionActor2DPtr
Helper for rendering 3D text that faces the camera and has a constant viewed size, always on top.
vtkSmartPointer< class vtkSphereSource > vtkSphereSourcePtr
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,xmax,ymin,ymax,zmin,zmax}, in order to simplify communication with vtk.
Helper for rendering 3D text that faces the camera and has a constant viewed size.
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
vtkSmartPointer< class vtkVectorText > vtkVectorTextPtr
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
vtkSmartPointer< class vtkGlyph3DMapper > vtkGlyph3DMapperPtr
boost::shared_ptr< FollowerText3D > FollowerText3DPtr
vtkSmartPointer< class vtkArcSource > vtkArcSourcePtr
vtkSmartPointer< class vtkPolyDataAlgorithm > vtkPolyDataAlgorithmPtr
Definition: cxViewWrapper.h:29
RealScalar length() const
boost::shared_ptr< GraphicalPolyData3D > GraphicalPolyData3DPtr
boost::shared_ptr< class GraphicalLine3D > GraphicalLine3DPtr
vtkSmartPointer< class vtkArrowSource > vtkArrowSourcePtr
Helper for rendering a a glyph in 3D.
boost::shared_ptr< CaptionText3D > CaptionText3DPtr
vtkPolyDataAlgorithmPtr mSource
boost::shared_ptr< class Rect3D > Rect3DPtr
boost::shared_ptr< GraphicalArrow3D > GraphicalArrow3DPtr
Helper for drawing a rectangle in 3D.
Namespace for all CustusX production code.