Fraxinus  17.12
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 
34 #ifndef CXVTKHELPERCLASSES_H_
35 #define CXVTKHELPERCLASSES_H_
36 
37 #include "cxResourceVisualizationExport.h"
38 
39 #include "cxTransform3D.h"
40 #include "cxGraphicalPrimitives.h"
41 
42 #include "vtkForwardDeclarations.h"
43 
44 #include <QColor>
45 
46 // --------------------------------------------------------
47 namespace cx
48 {
49 // --------------------------------------------------------
50 
54 template <typename vtkPropertyOrProperty2DPtr>
55 void setColorAndOpacity(vtkPropertyOrProperty2DPtr property, QColor color)
56 {
57  property->SetColor(color.redF(), color.greenF(), color.blueF());
58  property->SetOpacity(color.alphaF());
59 }
60 
63 Vector3D getColorAsVector3D(QColor color) ;
64 
69 class cxResourceVisualization_EXPORT RGBColor : public boost::array<double,3>
70 {
71 public:
72  RGBColor();
73  RGBColor(double r, double g, double b);
74  explicit RGBColor(const double* rgb);
75  RGBColor(const RGBColor& t);
76  RGBColor& operator=(const RGBColor& t);
77  RGBColor(QColor c);
78  RGBColor& operator=(const QColor& c);
79  ~RGBColor() {}
80 };
81 
86 class cxResourceVisualization_EXPORT OffsetPoint
87 {
88  public:
89  OffsetPoint( vtkRendererPtr renderer );
90  ~OffsetPoint();
91  void setRadius ( int radius );
92  void setValue(Vector3D point, RGBColor color);
93  void setValue(Vector3D point, Vector3D color);
94  void update( const Vector3D& point );
95  vtkActor2DPtr getActor();
96  private:
97  vtkSphereSourcePtr source;
99  vtkActor2DPtr actor;
100  vtkRendererPtr mRenderer;
101 };
102 typedef boost::shared_ptr<OffsetPoint> OffsetPointPtr;
103 
108 class cxResourceVisualization_EXPORT LineSegment
109 {
110  public:
111  LineSegment(vtkRendererPtr renderer);
112  ~LineSegment();
113  void setPoints(Vector3D point1, Vector3D point2, RGBColor color, int stipplePattern = 0xFFFF);
114  void setResolution(int res);
115  void updatePosition(Vector3D point1, Vector3D point2);
116  vtkActor2DPtr getActor();
117  void setColor(RGBColor color);
118  void setPattern(int stipplePattern);
119  void setWidth(float width);
120 
121  private:
122  vtkPolyDataMapper2DPtr mapper2d;
123  vtkActor2DPtr actor2d;
124  vtkRendererPtr mRenderer;
125  vtkLineSourcePtr source;
126 };
127 
132 class cxResourceVisualization_EXPORT TextDisplay
133 {
134  public:
135  TextDisplay(const QString& text, const QColor& color, int fontsize);
136  ~TextDisplay();
137  void setRenderer( vtkRendererPtr renderer );
138  void setPosition( float x, float y);
139  void setPosition( const Vector3D& pos );
140  void setCentered();
141  void updateText(const QString& text );
142  void setColor(QColor color);
143  vtkTextProperty* textProperty();
144  vtkActor2DPtr getActor();
145  void setMaxWidth( int width, vtkViewport *vp );
146  int getMaxWidth();
147  int getWidth( vtkViewport *vp );
148  vtkTextMapperPtr getMapper() { return mapper; }
149 
150  static void forceUseVtkTextMapper();
151 
152  private:
153  vtkTextMapperPtr mapper;
154  vtkActor2DPtr actor;
155  vtkRendererPtr mRenderer;
156  int maxWidth;
157  QString text;
158 
159  static void verifyVtkTextMapper();
160 };
161 typedef boost::shared_ptr<class TextDisplay> TextDisplayPtr;
162 
163 
168 class cxResourceVisualization_EXPORT CrossHair2D
169 {
170  public:
171  CrossHair2D( vtkRendererPtr renderer);
172  ~CrossHair2D();
173  void setValue(const Vector3D& focalPoint, int width, int height, double bordarOffset, const RGBColor& color);
174  //void update( const Vector3D& crossPos );
175  void update( const Vector3D& crossPos, const DoubleBoundingBox3D& vp);
176  void updateRegCross( const Vector3D& crossPos );
177  vtkActor2DPtr getActor();
178  private:
179  vtkCursor2DPtr mCursor2D;
180  vtkPolyDataMapper2DPtr mapper;
181  vtkActor2DPtr actor;
182  vtkRendererPtr mRenderer;
183 };
184 typedef boost::shared_ptr<class CrossHair2D> CrossHair2DPtr;
185 
193 class cxResourceVisualization_EXPORT Axes3D
194 {
195 public:
196  Axes3D(vtkRendererPtr renderer = vtkRendererPtr());
197  ~Axes3D();
198  void setPosition(const Transform3D& pos);
199  vtkProp3DPtr getProp();
200 private:
201  void setCaption(vtkCaptionActor2D* captionActor, const QString& caption, RGBColor color);
202 
203  vtkAxesActorPtr mAxes;
204  vtkRendererPtr mRenderer;
205 };
206 typedef boost::shared_ptr<Axes3D> Axes3DPtr;
207 
208 // --------------------------------------------------------
209 }// namespace vm
210 // --------------------------------------------------------
211 
212 
213 #endif // CXVTKHELPERCLASSES_H_
214 
Vector3D getColorAsVector3D(QColor color)
vtkSmartPointer< class vtkAxesActor > vtkAxesActorPtr
boost::shared_ptr< class Axes3D > Axes3DPtr
boost::shared_ptr< class CrossHair2D > CrossHair2DPtr
vtkSmartPointer< class vtkActor2D > vtkActor2DPtr
vtkSmartPointer< class vtkTextMapper > vtkTextMapperPtr
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
vtkSmartPointer< class vtkCursor2D > vtkCursor2DPtr
vtkSmartPointer< class vtkLineSource > vtkLineSourcePtr
Helper for drawing a point in 2D.
RGB color data.
vtkSmartPointer< class vtkRenderer > vtkRendererPtr
Helper for drawing a line in 2D.
Helper for drawing a coordinate axis in 3D.
Helper for drawing text in 2D.
boost::shared_ptr< class TextDisplay > TextDisplayPtr
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.
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:63
boost::shared_ptr< class OffsetPoint > OffsetPointPtr
vtkSmartPointer< class vtkProp3D > vtkProp3DPtr
vtkTextMapperPtr getMapper()
Helper for drawing a crosshair in 2D.
void setColorAndOpacity(vtkPropertyOrProperty2DPtr property, QColor color)
vtkSmartPointer< class vtkPolyDataMapper2D > vtkPolyDataMapper2DPtr
Namespace for all CustusX production code.