Statismo  0.10.1
 All Classes Namespaces Functions Typedefs
vtkHelper.h
1 /*
2  * This file is part of the statismo library.
3  *
4  * Author: Marcel Luethi (marcel.luethi@unibas.ch)
5  *
6  * Copyright (c) 2011 University of Basel
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  *
16  * Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in the
18  * documentation and/or other materials provided with the distribution.
19  *
20  * Neither the name of the project's author nor the names of its
21  * contributors may be used to endorse or promote products derived from
22  * this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
30  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  *
36  */
37 
38 #ifndef __VTK_HELPER_H
39 #define __VTK_HELPER_H
40 
41 
42 #include <iostream>
43 #include <sstream>
44 
45 #include "CommonTypes.h"
46 #include "Exceptions.h"
47 
48 namespace statismo {
49 
55 class vtkNDPixel {
56  public:
57 
58  vtkNDPixel(unsigned dimensions) : m_pixel(new double[dimensions]), m_dimensions(dimensions) { }
59  ~vtkNDPixel() {
60  delete[] m_pixel;
61  }
62 
63  vtkNDPixel(double* x, unsigned dimensions) : m_pixel(new double[dimensions]), m_dimensions(dimensions) {
64  for (unsigned d = 0; d < dimensions; d++)
65  m_pixel[d] = x[d];
66 
67  }
68 
69  double& operator[](unsigned i) {
70  if (i >= m_dimensions) {
71  std::ostringstream os;
72  os << "Invalid index for vtkPixel (index = " << i << ")";
73  throw statismo::StatisticalModelException(os.str().c_str());
74  } else {
75  return m_pixel[i];
76  }
77  }
78 
79  const double& operator[](unsigned i) const {
80  if (i >= m_dimensions) {
81  std::ostringstream os;
82  os << "Invalid index for vtkPixel (index = " << i << ")";
83  throw statismo::StatisticalModelException(os.str().c_str());
84  } else {
85  return m_pixel[i];
86  }
87  }
88 
89 
90  vtkNDPixel & operator=(const vtkNDPixel& rhs) {
91  if (this != &rhs) {
92  m_dimensions = rhs.m_dimensions;
93  m_pixel = new double[rhs.m_dimensions];
94  for (unsigned d = 0; d < rhs.m_dimensions; d++) {
95  m_pixel[d] = rhs.m_pixel[d];
96  }
97 
98  }
99  return *this;
100  }
101 
102  vtkNDPixel(const vtkNDPixel& orig) {
103  operator=(orig);
104  }
105 
106  private:
107  double* m_pixel;
108  unsigned m_dimensions;
109 };
110 
111 
112 
119 class vtkPoint {
120  public:
121  vtkPoint() {
122  m_pt[0] = 0;
123  m_pt[1] = 0;
124  m_pt[2] = 0;
125  }
126 
127  vtkPoint(double x, double y, double z) {
128  m_pt[0] = x;
129  m_pt[1] = y;
130  m_pt[2] = z;
131  }
132 
133  vtkPoint(double* d) {
134  m_pt[0] = d[0];
135  m_pt[1] = d[1];
136  m_pt[2] = d[2];
137  }
138 
139  double& operator[](unsigned i) {
140  return m_pt[i];
141  }
142  const double& operator[](unsigned i) const {
143  return m_pt[i];
144  }
145 
146  const double* data() const {
147  return m_pt;
148  }
149 
150 
151  vtkPoint& operator=(const vtkPoint& rhs) {
152  if (this != &rhs) {
153  m_pt[0] = rhs.m_pt[0];
154  m_pt[1] = rhs.m_pt[1];
155  m_pt[2] = rhs.m_pt[2];
156  }
157  return *this;
158  }
159 
160  vtkPoint(const vtkPoint& orig) {
161  operator=(orig);
162  }
163 
164 
165  private:
166  double m_pt[3];
167 };
168 
169 class vtkHelper {
170  public:
171  static int vtkDataTypeIdToStatismoDataTypeId(int vtkDataTypeId) {
172 
173  int dataType = statismo::Void;
174  switch(vtkDataTypeId) {
175  case VTK_UNSIGNED_CHAR:
176  dataType = statismo::UNSIGNED_CHAR;
177  break;
178  case VTK_SIGNED_CHAR:
179  dataType = statismo::SIGNED_CHAR;
180  break;
181  case VTK_FLOAT:
182  dataType = statismo::FLOAT;
183  break;
184  case VTK_DOUBLE:
185  dataType = statismo::DOUBLE;
186  break;
187  case VTK_UNSIGNED_INT:
188  dataType = statismo::UNSIGNED_INT;
189  break;
190  case VTK_INT:
191  dataType = statismo::SIGNED_INT;
192  break;
193  case VTK_UNSIGNED_SHORT:
194  dataType = statismo::UNSIGNED_SHORT;
195  break;
196  case VTK_SHORT:
197  dataType = statismo::SIGNED_SHORT;
198  break;
199  case VTK_UNSIGNED_LONG:
200  dataType = statismo::UNSIGNED_LONG;
201  break;
202  case VTK_LONG:
203  dataType = statismo::SIGNED_LONG;
204  break;
205  default:
206  throw statismo::StatisticalModelException("Unsupported data type for dataArray in vtkStandardMeshRepresenter::GetAsDataArray.");
207  }
208  return dataType;
209  }
210 };
211 
212 } // namespace statismo
213 #endif // __VTK_HELPER_H
Helper class that represents a vtkPixel or arbitrary type and dimension In vtk a pixel is just of typ...
Definition: vtkHelper.h:55
Generic Exception class for the statismo Library.
Definition: Exceptions.h:68
Helper class that represents a vtkPoint. In vtk a point is just of type T*. The statismo library reli...
Definition: vtkHelper.h:119