Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkSphereInterpolator.h
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef _SPHEREINTERPOLATOR
18 #define _SPHEREINTERPOLATOR
19 
20 #include <MitkFiberTrackingExports.h>
21 
22 #include <vnl/vnl_vector_fixed.h>
23 
24 #include <vector>
25 
26 using namespace std;
27 
28 
32 class MITKFIBERTRACKING_EXPORT SphereInterpolator
33 {
34 
35 public:
36 
37  int size; // size of LUT
38  int sN; // (sizeofLUT-1)/2
39  int nverts; // number of data vertices
40  float beta;
41  float inva;
42  float b;
44 
45  vector< float > barycoords;
46  vector< int > indices;
47  vnl_vector_fixed< int, 3 > idx;
48  vnl_vector_fixed< float, 3 > interpw;
49 
50  SphereInterpolator(const string& lutPath);
51 
52  inline bool IsInValidState() const
53  {
54  return m_ValidState;
55  }
56 
58 
59  inline void getInterpolation(const vnl_vector_fixed<float, 3>& N)
60  {
61  float nx = N[0];
62  float ny = N[1];
63  float nz = N[2];
64 
65  if (nz > 0.5)
66  {
67  int x = float2int(nx);
68  int y = float2int(ny);
69  int i = 3*6*(x+y*size); // (:,1,x,y)
70  idx[0] = indices[i];
71  idx[1] = indices[i+1];
72  idx[2] = indices[i+2];
73  interpw[0] = barycoords[i];
74  interpw[1] = barycoords[i+1];
75  interpw[2] = barycoords[i+2];
76  return;
77  }
78  if (nz < -0.5)
79  {
80  int x = float2int(nx);
81  int y = float2int(ny);
82  int i = 3*(1+6*(x+y*size)); // (:,2,x,y)
83  idx[0] = indices[i];
84  idx[1] = indices[i+1];
85  idx[2] = indices[i+2];
86  interpw[0] = barycoords[i];
87  interpw[1] = barycoords[i+1];
88  interpw[2] = barycoords[i+2];
89  return;
90  }
91  if (nx > 0.5)
92  {
93  int z = float2int(nz);
94  int y = float2int(ny);
95  int i = 3*(2+6*(z+y*size)); // (:,2,x,y)
96  idx[0] = indices[i];
97  idx[1] = indices[i+1];
98  idx[2] = indices[i+2];
99  interpw[0] = barycoords[i];
100  interpw[1] = barycoords[i+1];
101  interpw[2] = barycoords[i+2];
102  return;
103  }
104  if (nx < -0.5)
105  {
106  int z = float2int(nz);
107  int y = float2int(ny);
108  int i = 3*(3+6*(z+y*size)); // (:,2,x,y)
109  idx[0] = indices[i];
110  idx[1] = indices[i+1];
111  idx[2] = indices[i+2];
112  interpw[0] = barycoords[i];
113  interpw[1] = barycoords[i+1];
114  interpw[2] = barycoords[i+2];
115  return;
116  }
117  if (ny > 0)
118  {
119  int x = float2int(nx);
120  int z = float2int(nz);
121  int i = 3*(4+6*(x+z*size)); // (:,1,x,y)
122  idx[0] = indices[i];
123  idx[1] = indices[i+1];
124  idx[2] = indices[i+2];
125  interpw[0] = barycoords[i];
126  interpw[1] = barycoords[i+1];
127  interpw[2] = barycoords[i+2];
128  return;
129  }
130  else
131  {
132  int x = float2int(nx);
133  int z = float2int(nz);
134  int i = 3*(5+6*(x+z*size)); // (:,1,x,y)
135  idx[0] = indices[i];
136  idx[1] = indices[i+1];
137  idx[2] = indices[i+2];
138  interpw[0] = barycoords[i];
139  interpw[1] = barycoords[i+1];
140  interpw[2] = barycoords[i+2];
141  return;
142  }
143  }
144 
145 protected:
146 
147  bool LoadLookuptables(const string& lutPath);
148 
149  bool LoadLookuptables();
150 
151  bool LoadLookuptables(std::istream& BaryCoordsStream, std::istream& IndicesStream);
152 
153  inline float invrescale(float f) const
154  {
155  float x = (fabs(f)-b)*inva;
156  if (f>0)
157  return (x*x-beta);
158  else
159  return beta - x*x;
160  }
161 
162  inline int float2int(float x) const
163  {
164  return int((invrescale(x)+1)*sN-0.5);
165  }
166 
167 };
168 
169 #endif
vnl_vector_fixed< float, 3 > interpw
int float2int(float x) const
vector< float > barycoords
STL namespace.
vnl_vector_fixed< int, 3 > idx
Lookuptable based trilinear interpolation of spherically arranged scalar values.
void getInterpolation(const vnl_vector_fixed< float, 3 > &N)
float invrescale(float f) const