Fraxinus  16.5.0-fx-rc6
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
53 void setColorAndOpacity(vtkPropertyPtr property, QColor color);
56 Vector3D getColorAsVector3D(QColor color) ;
57 
62 class cxResourceVisualization_EXPORT RGBColor : public boost::array<double,3>
63 {
64 public:
65  RGBColor();
66  RGBColor(double r, double g, double b);
67  explicit RGBColor(const double* rgb);
68  RGBColor(const RGBColor& t);
69  RGBColor& operator=(const RGBColor& t);
70  RGBColor(QColor c);
71  RGBColor& operator=(const QColor& c);
72  ~RGBColor() {}
73 };
74 
79 class cxResourceVisualization_EXPORT OffsetPoint
80 {
81  public:
82  OffsetPoint( vtkRendererPtr renderer );
83  ~OffsetPoint();
84  void setRadius ( int radius );
85  void setValue(Vector3D point, RGBColor color);
86  void setValue(Vector3D point, Vector3D color);
87  void update( const Vector3D& point );
88  vtkActor2DPtr getActor();
89  private:
90  vtkSphereSourcePtr source;
92  vtkActor2DPtr actor;
93  vtkRendererPtr mRenderer;
94 };
95 typedef boost::shared_ptr<OffsetPoint> OffsetPointPtr;
96 
101 class cxResourceVisualization_EXPORT LineSegment
102 {
103  public:
104  LineSegment(vtkRendererPtr renderer);
105  ~LineSegment();
106  void setPoints(Vector3D point1, Vector3D point2, RGBColor color, int stipplePattern = 0xFFFF);
107  void setResolution(int res);
108  void updatePosition(Vector3D point1, Vector3D point2);
109  vtkActor2DPtr getActor();
110  void setColor(RGBColor color);
111  void setPattern(int stipplePattern);
112  void setWidth(float width);
113 
114  private:
115  vtkPolyDataMapper2DPtr mapper2d;
116  vtkActor2DPtr actor2d;
117  vtkRendererPtr mRenderer;
118  vtkLineSourcePtr source;
119 };
120 
125 class cxResourceVisualization_EXPORT TextDisplay
126 {
127  public:
128  TextDisplay(const QString& text, const QColor& color, int fontsize);
129  ~TextDisplay();
130  void setRenderer( vtkRendererPtr renderer );
131  void setPosition( float x, float y);
132  void setPosition( const Vector3D& pos );
133  void setCentered();
134  void updateText(const QString& text );
135  void setColor(QColor color);
136  vtkTextProperty* textProperty();
137  vtkActor2DPtr getActor();
138  void setMaxWidth( int width, vtkViewport *vp );
139  int getMaxWidth();
140  int getWidth( vtkViewport *vp );
141  vtkTextMapperPtr getMapper() { return mapper; }
142 
143  static void forceUseVtkTextMapper();
144 
145  private:
146  vtkTextMapperPtr mapper;
147  vtkActor2DPtr actor;
148  vtkRendererPtr mRenderer;
149  int maxWidth;
150  QString text;
151 
152  static void verifyVtkTextMapper();
153 };
154 typedef boost::shared_ptr<class TextDisplay> TextDisplayPtr;
155 
156 
161 class cxResourceVisualization_EXPORT CrossHair2D
162 {
163  public:
164  CrossHair2D( vtkRendererPtr renderer);
165  ~CrossHair2D();
166  void setValue(const Vector3D& focalPoint, int width, int height, double bordarOffset, const RGBColor& color);
167  //void update( const Vector3D& crossPos );
168  void update( const Vector3D& crossPos, const DoubleBoundingBox3D& vp);
169  void updateRegCross( const Vector3D& crossPos );
170  vtkActor2DPtr getActor();
171  private:
172  vtkCursor2DPtr mCursor2D;
173  vtkPolyDataMapper2DPtr mapper;
174  vtkActor2DPtr actor;
175  vtkRendererPtr mRenderer;
176 };
177 typedef boost::shared_ptr<class CrossHair2D> CrossHair2DPtr;
178 
186 class cxResourceVisualization_EXPORT Axes3D
187 {
188 public:
189  Axes3D(vtkRendererPtr renderer = vtkRendererPtr());
190  ~Axes3D();
191  void setPosition(const Transform3D& pos);
192  vtkProp3DPtr getProp();
193 private:
194  void setCaption(vtkCaptionActor2D* captionActor, const QString& caption, RGBColor color);
195 
196  vtkAxesActorPtr mAxes;
197  vtkRendererPtr mRenderer;
198 };
199 typedef boost::shared_ptr<Axes3D> Axes3DPtr;
200 
201 // --------------------------------------------------------
202 }// namespace vm
203 // --------------------------------------------------------
204 
205 
206 #endif // CXVTKHELPERCLASSES_H_
207 
Vector3D getColorAsVector3D(QColor color)
vtkSmartPointer< class vtkAxesActor > vtkAxesActorPtr
boost::shared_ptr< class Axes3D > Axes3DPtr
boost::shared_ptr< class CrossHair2D > CrossHair2DPtr
vtkSmartPointer< class vtkProperty > vtkPropertyPtr
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
void setColorAndOpacity(vtkPropertyPtr property, QColor color)
vtkTextMapperPtr getMapper()
Helper for drawing a crosshair in 2D.
vtkSmartPointer< class vtkPolyDataMapper2D > vtkPolyDataMapper2DPtr