OpenWalnut  1.5.0dev
WTalairachConverter.cpp
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #include "WTalairachConverter.h"
26 #include "core/common/math/WLinearAlgebraFunctions.h"
27 
29  m_rotMat( 3, 3 ),
30  m_rotMatInvert( 3, 3 ),
31  m_ac( ac ),
32  m_pc( pc ),
33  m_ihp( ihp )
34 {
35  // initalize the bounding box of the head with some arbitrary values, these have to be set to real values
36  // before any coordinate conversion
37  // the point of origin in the canonical system is the right inferior posterior corner
38 
39  m_ap = WVector3d( 255, 0, 0 );
40  m_pp = WVector3d( 0, 0, 0 );
41 
42  m_lp = WVector3d( 0, 255, 0 );
43  m_rp = WVector3d( 0, 0, 0 );
44 
45  m_ip = WVector3d( 0, 0, 0 );
46  m_sp = WVector3d( 0, 0, 255 );
47 
49 }
50 
52 {
53 }
54 
56 {
57  WVector3d rpoint = point - m_ac;
58  return multMatrixWithVector3D( m_rotMat, rpoint );
59 }
60 
62 {
63  WVector3d rpoint = multMatrixWithVector3D( m_rotMatInvert, point );
64  return rpoint + m_ac;
65 }
66 
68 {
69  return ACPC2Talairach( Canonical2ACPC( point ) );
70 }
71 
73 {
74  return ACPC2Canonical( Talairach2ACPC( point ) );
75 }
76 
78 {
79  // declare some variables for readability
80  double x = point[0];
81  double y = point[1];
82  double z = point[2];
83 
84 // double X1 = length( m_pp - m_pc );
85 // double X2 = length( m_ac - m_pc );
86 // double X3 = length( m_ap - m_ac );
87 // double Y1 = length( m_ac - m_rp );
88 // double Y2 = length( m_lp - m_ac );
89 // double Z1 = length( m_ac - m_ip );
90 // double Z2 = length( m_sp - m_ac );
91 
92  double X1 = fabs( m_pp[0] - m_pc[0] );
93  double X2 = fabs( m_ac[0] - m_pc[0] );
94  double X3 = fabs( m_ap[0] - m_ac[0] );
95  double Y1 = fabs( m_ac[1] - m_rp[1] );
96  double Y2 = fabs( m_lp[1] - m_ac[1] );
97  double Z1 = fabs( m_ac[2] - m_ip[2] );
98  double Z2 = fabs( m_sp[2] - m_ac[2] );
99 
100  double X1T = 79.0;
101  double X2T = 23.0;
102  double X3T = 70.0;
103  double Y1T = 68.0;
104  double Y2T = 68.0;
105  double Z1T = 42.0;
106  double Z2T = 74.0;
107 
108  double xt = 0;
109  double yt = 0;
110  double zt = 0;
111 
112  if( x < -X2 ) // posterior to PC
113  {
114  xt = ( X1T / X1 ) * ( x + X2 ) - X2T;
115  }
116  else if( x >= 0 ) // anterior to AC
117  {
118  xt = ( X3T / X3 ) * x;
119  }
120  else // between AC and PC
121  {
122  xt = ( X2T / X2 ) * x;
123  }
124 
125  if( y < 0 ) // right hemisphere
126  {
127  yt = ( Y1T / Y1 ) * y;
128  }
129  else // left hemisphere
130  {
131  yt = ( Y2T / Y2 ) * y;
132  }
133 
134  if( z < 0 ) // inferior to AC-PC
135  {
136  zt = ( Z1T / Z1 ) * z;
137  }
138  else // superior to AC-PC
139  {
140  zt = ( Z2T / Z2 ) * z;
141  }
142 
143  return WVector3d( xt, yt, zt );
144 }
145 
147 {
148  // declare some variables for readability
149  double xt = point[0];
150  double yt = point[1];
151  double zt = point[2];
152 
153 // double X1 = length( m_pp - m_pc );
154 // double X2 = length( m_ac - m_pc );
155 // double X3 = length( m_ap - m_ac );
156 // double Y1 = length( m_ac - m_rp );
157 // double Y2 = length( m_lp - m_ac );
158 // double Z1 = length( m_ac - m_ip );
159 // double Z2 = length( m_sp - m_ac );
160 
161  double X1 = fabs( m_pp[0] - m_pc[0] );
162  double X2 = fabs( m_ac[0] - m_pc[0] );
163  double X3 = fabs( m_ap[0] - m_ac[0] );
164  double Y1 = fabs( m_ac[1] - m_rp[1] );
165  double Y2 = fabs( m_lp[1] - m_ac[1] );
166  double Z1 = fabs( m_ac[2] - m_ip[2] );
167  double Z2 = fabs( m_sp[2] - m_ac[2] );
168 
169 
170  double X1T = 79.0;
171  double X2T = 23.0;
172  double X3T = 70.0;
173  double Y1T = 68.0;
174  double Y2T = 68.0;
175  double Z1T = 42.0;
176  double Z2T = 74.0;
177 
178  double x = 0;
179  double y = 0;
180  double z = 0;
181 
182  if( xt < -X2T ) // posterior to PC
183  {
184  x = ( X1 / X1T ) * ( xt + X2T ) - X2;
185  }
186  else if( xt >= 0 ) // anterior to AC
187  {
188  x = ( X3 / X3T ) * xt;
189  }
190  else // between AC and PC
191  {
192  x = ( X2 / X2T ) * xt;
193  }
194 
195  if( yt < 0 ) // right hemisphere
196  {
197  y = ( Y1 / Y1T ) * yt;
198  }
199  else // left hemisphere
200  {
201  y = ( Y2 / Y2T ) * yt;
202  }
203 
204  if( zt < 0 ) // inferior to AC-PC
205  {
206  z = ( Z1 / Z1T ) * zt;
207  }
208  else // superior to AC-PC
209  {
210  z = ( Z2 / Z2T ) * zt;
211  }
212 
213  return WVector3d( x, y, z );
214 }
215 
216 
218 {
219  //WVector3d ihp_proj( ( ( ( m_ac - m_ihp ) * ( m_pc - m_ac ) ) * ( m_pc - m_ac ) / length2( m_pc - m_as ) ) + m_ihp );
220  WVector3d v1 = m_pc - m_ac;
221  float apnorm = v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2];
222 
223  WVector3d v2 = m_ac - m_ihp;
224  float dist = v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2];
225 
226 
227  WVector3d ihp_proj( dist * ( m_pc - m_ac ) / apnorm + m_ihp );
228 
229  m_ihp_proj = ihp_proj;
230  WVector3d ex( m_ac - m_pc );
231  ex = normalize( ex );
232  WVector3d ez( ihp_proj - m_ac );
233  ez = normalize( ez );
234  WVector3d ey = cross( ez, ex );
235 
236  m_rotMat( 0, 0 ) = ex[0];
237  m_rotMat( 0, 1 ) = ex[1];
238  m_rotMat( 0, 2 ) = ex[2];
239  m_rotMat( 1, 0 ) = ey[0];
240  m_rotMat( 1, 1 ) = ey[1];
241  m_rotMat( 1, 2 ) = ey[2];
242  m_rotMat( 2, 0 ) = ez[0];
243  m_rotMat( 2, 1 ) = ez[1];
244  m_rotMat( 2, 2 ) = ez[2];
245 
246  m_rotMatInvert = invertMatrix3x3( m_rotMat );
247 }
248 
250 {
251  return m_ac;
252 }
253 
255 {
256  m_ac = ac;
258 }
259 
261 {
262  return m_pc;
263 }
264 
266 {
267  m_pc = pc;
269 }
270 
272 {
273  return m_ihp;
274 }
275 
277 {
278  m_ihp = ihp;
280 }
281 
283 {
284  return m_ap;
285 }
286 
288 {
289  m_ap = ap;
290 }
291 
293 {
294  return m_pp;
295 }
296 
298 {
299  m_pp = pp;
300 }
301 
303 {
304  return m_sp;
305 }
306 
308 {
309  m_sp = sp;
310 }
311 
313 {
314  return m_ip;
315 }
316 
318 {
319  m_ip = ip;
320 }
321 
323 {
324  return m_rp;
325 }
326 
328 {
329  m_rp = rp;
330 }
331 
333 {
334  return m_lp;
335 }
336 
338 {
339  m_lp = lp;
340 }
341 
343 {
344  return m_rotMat;
345 }
346 
348 {
349  return m_rotMatInvert;
350 }
WVector3d getRp() const
getter for rp
WVector3d m_ihp_proj
projected interhemispherical point
void setLp(WVector3d lp)
setter for lp
WVector3d getLp() const
getter for lp
WVector3d m_ac
anterior commisure
WVector3d m_pc
inferior commisure
void setPp(WVector3d pp)
setter for pp
WVector3d ACPC2Talairach(const WVector3d point)
ACPC2Talairach.
void setRp(WVector3d rp)
setter for rp
virtual ~WTalairachConverter()
destructor
void setPc(WVector3d pc)
setter for pc
WVector3d getPc() const
getter for pc
WVector3d getIhp() const
getter for ihp
WVector3d m_rp
right point
WVector3d Canonical2ACPC(const WVector3d point)
Canonical2ACPC.
WVector3d m_ap
anterior point
WVector3d m_ip
inferior point
WMatrix< double > getRotMat()
getter for the rotation matrix
WVector3d getIp() const
getter for ip
WMatrix< double > m_rotMatInvert
the inverted rotation matrix
WVector3d getAc() const
getter for ac
void setSp(WVector3d sp)
setter for sp
WVector3d m_sp
superior point
WVector3d m_ihp
inter hemispherical point
WVector3d Canonical2Talairach(const WVector3d point)
Canonical2Talairach.
WVector3d Talairach2ACPC(const WVector3d point)
Talairach2ACPC.
void defineRotationMatrix()
helper routine to create the rotation matrix from the given points
void setIp(WVector3d ip)
setter for ip
WMatrix< double > getInvRotMat()
getter for the inverted rotation matrix
WMatrix< double > m_rotMat
the rotation matrix
void setIhp(WVector3d ihp)
setter for ihp
WTalairachConverter(WVector3d ac, WVector3d pc, WVector3d ihp)
constructor
WVector3d ACPC2Canonical(const WVector3d point)
ACPC2Canonical.
WVector3d getSp() const
getter for sp
WVector3d m_lp
left point
void setAc(WVector3d ac)
setter for ac
WVector3d Talairach2Canonical(const WVector3d point)
Talairach2Canonical.
void setAp(WVector3d ap)
setter for ap
WVector3d m_pp
posterior point
WVector3d getAp() const
getter for ap
WVector3d getPp() const
getter for pp