NifTK  16.4.1 - 0798f20
CMIC's Translational Medical Imaging Platform
niftkVLUtils.h
Go to the documentation of this file.
1 /*=============================================================================
2 
3  NifTK: A software platform for medical image computing.
4 
5  Copyright (c) University College London (UCL). All rights reserved.
6 
7  This software is distributed WITHOUT ANY WARRANTY; without even
8  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9  PURPOSE.
10 
11  See LICENSE.txt in the top level directory for details.
12 
13 =============================================================================*/
14 
15 #ifndef niftkVLUtils_h
16 #define niftkVLUtils_h
17 
18 #include <niftkVLExports.h>
19 #include <vlCore/Vector3.hpp>
20 #include <vlCore/Vector4.hpp>
21 #include <vlCore/vlnamespace.hpp>
22 #include <vlCore/Image.hpp>
23 #include <vlGraphics/Geometry.hpp>
24 #include <vtkSmartPointer.h>
25 #include <vtkMatrix4x4.h>
26 #include <itkMatrix.h>
27 #include <mitkEnumerationProperty.h>
28 
29 // NOTE:
30 // In production you may want to review these checks and handle them as gracefully as possible.
31 #if defined(_MSC_VER)
32  #define VIVID_TRAP() { if (IsDebuggerPresent()) { __debugbreak(); } else ::vl::abort_vl(); }
33 #elif defined(__GNUG__) || defined(__MINGW32__)
34  #define VIVID_TRAP() { fflush(stdout); fflush(stderr); asm("int $0x3"); }
35 #else
36  #define VIVID_TRAP() { ::vl::abort_vl(); }
37 #endif
38 #if 1
39  // This is better for debugging
40  #define VIVID_CHECK(expr) { if ( ! ( expr ) ) { ::vl::log_failed_check( #expr, __FILE__, __LINE__ ); VIVID_TRAP(); } }
41 #else
42  // This allows the user to ignore the exception while giving full info about the error
43  #define STRINGIZE_DETAIL(x) #x
44  #define STRINGIZE(x) STRINGIZE_DETAIL(x)
45  #define VIVID_CHECK(expr) { if ( ! (expr) ) { throw std::runtime_error( __FILE__ " line " STRINGIZE(__LINE__) ": " #expr ); } }
46 #endif
47 
48 class vtkPolyData;
49 
50 namespace mitk
51 {
52  class BaseData;
53  class DataNode;
54  class Image;
55 }
56 
57 namespace vl
58 {
59  class VividVolume;
60  class Effect;
61 }
62 
63 namespace niftk
64 {
65 
66 //-----------------------------------------------------------------------------
67 // mitk::EnumerationProperty wrapper classes
68 //-----------------------------------------------------------------------------
69 
70 class NIFTKVL_EXPORT VL_Render_Mode_Property: public mitk::EnumerationProperty
71 {
72 public:
73  mitkClassMacro( VL_Render_Mode_Property, EnumerationProperty );
75 protected:
77  AddEnum("DepthPeeling", 0);
78  AddEnum("FastRender", 1);
79  AddEnum("StencilRender", 2);
80  }
81 };
82 
83 //-----------------------------------------------------------------------------
84 
85 class NIFTKVL_EXPORT VL_Volume_Mode_Property: public mitk::EnumerationProperty
86 {
87 public:
88  mitkClassMacro( VL_Volume_Mode_Property, EnumerationProperty );
90 protected:
92  AddEnum("Direct", 0);
93  AddEnum("Isosurface", 1);
94  AddEnum("MIP", 2);
95  }
96 };
97 
98 //-----------------------------------------------------------------------------
99 
100 class NIFTKVL_EXPORT VL_Point_Mode_Property: public mitk::EnumerationProperty
101 {
102 public:
103  mitkClassMacro( VL_Point_Mode_Property, EnumerationProperty );
105 protected:
107  AddEnum("3D", 0);
108  AddEnum("2D", 1);
109  }
110 };
111 
112 //-----------------------------------------------------------------------------
113 
114 class NIFTKVL_EXPORT VL_Smart_Target_Property: public mitk::EnumerationProperty
115 {
116 public:
117  mitkClassMacro( VL_Smart_Target_Property, EnumerationProperty );
119 protected:
121  AddEnum("Color", 0);
122  AddEnum("Alpha", 1);
123  AddEnum("Saturation", 2);
124  }
125 };
126 
127 //-----------------------------------------------------------------------------
128 
129 class NIFTKVL_EXPORT VL_Fog_Mode_Property: public mitk::EnumerationProperty
130 {
131 public:
132  mitkClassMacro( VL_Fog_Mode_Property, EnumerationProperty );
134 protected:
136  AddEnum("Off", 0);
137  AddEnum("Linear", 1);
138  AddEnum("Exp", 2);
139  AddEnum("Exp2", 3);
140  }
141 };
142 
143 //-----------------------------------------------------------------------------
144 
145 class NIFTKVL_EXPORT VL_Clip_Mode_Property: public mitk::EnumerationProperty
146 {
147 public:
148  mitkClassMacro( VL_Clip_Mode_Property, EnumerationProperty );
150 protected:
152  AddEnum("Off", 0);
153  AddEnum("Sphere", 1);
154  AddEnum("Box", 2);
155  AddEnum("Plane", 3);
156  }
157 };
158 
159 //-----------------------------------------------------------------------------
160 
161 class NIFTKVL_EXPORT VL_Surface_Mode_Property: public mitk::EnumerationProperty
162 {
163 public:
164  mitkClassMacro( VL_Surface_Mode_Property, EnumerationProperty );
166 protected:
168  AddEnum("Polys", 0);
169  AddEnum("Outline3D", 1);
170  AddEnum("Polys+Outline3D", 2);
171  AddEnum("Slice", 3);
172  AddEnum("Outline2D", 4);
173  AddEnum("Polys+Outline2D", 5);
174  }
175 };
176 
177 class NIFTKVL_EXPORT VLUserData: public vl::Object
178 {
179 public:
180  VLUserData(): m_TransformModifiedTime(0), m_ImageModifiedTime(0) { }
181  itk::ModifiedTimeType m_TransformModifiedTime;
182  itk::ModifiedTimeType m_ImageModifiedTime;
183 };
184 
185 class NIFTKVL_EXPORT VLUtils
186 {
187 public:
188  static vl::vec3 getVector3DProp( const mitk::DataNode* node, const char* prop_name, vl::vec3 defval );
189 
190  static vl::vec3 getPoint3DProp( const mitk::DataNode* node, const char* prop_name, vl::vec3 defval );
191 
192  static vl::vec4 getPoint4DProp( const mitk::DataNode* node, const char* prop_name, vl::vec4 defval );
193 
194  static int getEnumProp( const mitk::DataNode* node, const char* prop_name, int defval = 0 );
195 
196  static bool getBoolProp( const mitk::DataNode* node, const char* prop_name, bool defval );
197 
198  static bool setBoolProp( mitk::DataNode* node, const char* prop_name, bool val );
199 
200  static float getFloatProp( const mitk::DataNode* node, const char* prop_name, float defval = 0 );
201 
202  static int getIntProp( const mitk::DataNode* node, const char* prop_name, int defval = 0 );
203 
204  static vl::vec4 getColorProp( const mitk::DataNode* node, const char* prop_name, vl::vec4 defval = vl::white );
205 
206  static void initGlobalProps( mitk::DataNode* node );
207 
208  static void initVolumeProps( mitk::DataNode* node );
209 
210  static void updateVolumeProps( vl::VividVolume* vol, const mitk::DataNode* node );
211 
212  static void initMaterialProps( mitk::DataNode* node );
213 
214  static void updateMaterialProps( vl::Effect* fx, const mitk::DataNode* node );
215 
216  static void initFogProps( mitk::DataNode* node );
217 
218  static void updateFogProps( vl::Effect* fx, const mitk::DataNode* node );
219 
220  static void initClipProps( mitk::DataNode* node );
221 
222  static void updateClipProps( vl::Effect* fx, const mitk::DataNode* node );
223 
224  static void initRenderModeProps( mitk::DataNode* node );
225 
226  static void updateRenderModeProps( vl::Effect* fx, const mitk::DataNode* node );
227 
228  static vl::EImageType mapITKPixelTypeToVL(int itkComponentType);
229 
230  static vl::EImageFormat mapComponentsToVLColourFormat(int components);
231 
232  static vl::ref<vl::Image> wrapMitk2DImage( const mitk::Image* mitk_image );
233 
234  static VLUserData* getUserData(vl::Actor* actor);
235 
236  static vl::mat4 getVLMatrix(const itk::Matrix<float, 4, 4>& itkmat);
237 
238  // Returns null matrix if no vtk matrix is found
239  static vl::mat4 getVLMatrix(vtkSmartPointer<vtkMatrix4x4> vtkmat);
240 
241  // Returns null matrix if no vtk matrix is found
242  static vl::mat4 getVLMatrix(const mitk::BaseData* data);
243 
244  static void updateTransform(vl::Transform* tr, const mitk::BaseData* data);
245 
246  static void updateTransform(vl::Transform* txf, const mitk::DataNode* node);
247 
248  static vl::ref<vl::Geometry> make2DImageGeometry(int width, int height);
249 
250  static vl::ref<vl::Geometry> getVLGeometry(vtkPolyData* vtkPoly);
251 
252  static void dumpNodeInfo( const std::string& prefix, const mitk::DataNode* node );
253 
254  static void dumpNodeInfo( const std::string& prefix, const mitk::BaseData* data );
255 };
256 
257 }
258 
259 #endif
260 
itkFactorylessNewMacro(Self) protected
Definition: niftkVLUtils.h:165
Definition: niftkVLUtils.h:100
itk::ModifiedTimeType m_TransformModifiedTime
Definition: niftkVLUtils.h:181
Definition: niftkVLUtils.h:161
itkFactorylessNewMacro(Self) protected
Definition: niftkVLUtils.h:89
itkFactorylessNewMacro(Self) protected
Definition: niftkVLUtils.h:149
GLuint const GLfloat * val
Definition: glew.h:2691
itk::ModifiedTimeType m_ImageModifiedTime
Definition: niftkVLUtils.h:182
Definition: ReceptorMemberCommandTest.cxx:25
Definition: niftkVLUtils.h:177
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definition: glew.h:1363
Definition: niftkVLUtils.h:57
itkFactorylessNewMacro(Self) protected
Definition: niftkVLUtils.h:104
itkFactorylessNewMacro(Self) protected
Definition: niftkVLUtils.h:74
GLenum GLenum GLuint components
Definition: glew.h:10201
Definition: niftkVLUtils.h:129
itkFactorylessNewMacro(Self) protected
Definition: niftkVLUtils.h:118
itkFactorylessNewMacro(Self) protected
Definition: niftkVLUtils.h:133
VLUserData()
Definition: niftkVLUtils.h:180
Definition: niftkVLUtils.h:185
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
Definition: glew.h:1236
Definition: niftkVLUtils.h:85
Simultaneous itk::Image and itk::Array (and hence vnl_vector) class.
Definition: niftkVLUtils.h:145
GLint GLint GLint GLint GLint GLint GLsizei width
Definition: glew.h:1236
Definition: niftkVLUtils.h:70
Definition: niftkExceptionObject.h:21
GLsizei const GLcharARB ** string
Definition: glew.h:5194
Definition: niftkVLUtils.h:114