A.I.M.S algorithms


talBoundingBoxPoints.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 
35 #ifndef AIMS_TALAIRACH_TALBOUNDINGBOX_POINTS_H
36 #define AIMS_TALAIRACH_TALBOUNDINGBOX_POINTS_H
37 
38 #include <cstdlib>
39 #include <aims/data/data.h>
40 #include <cartobase/smart/rcptr.h>
42 #include <aims/roi/roiIterator.h>
43 #include <list>
44 
45 
47 {
48 public:
50  inline virtual ~TalairachBoundingBoxPoints() {}
54 
55  // Returns a motion from current subject to a normalized template, where
56  // AC (0, 0, 0) PC (0, 1, 0) and IHP (0, 1, cout0)
57 };
58 
59 
60 inline
62 {
63  //int x, y, z, dx = roiIt->volumeDimension()[0], dy = roiIt->volumeDimension()[1], dz = roiIt->volumeDimension()[2] ;
64  Point3df dsize( roiIt->voxelSize() );
65  Point3df boxmax( -10000.0f, -10000.0f, -10000.0f );
66  Point3df boxmin( 10000.0f, 10000.0f, 10000.0f );
67  Point3df pt, npt;
68 
69  roiIt->restart() ;
70  std::list<Point3d> points ;
71  while(roiIt->isValid() ){
73 
74  while( maskIt->isValid() ){
75  points.push_back( maskIt->value() ) ;
76 
77  maskIt->next() ;
78  }
79 
80  roiIt->next() ;
81  }
82 
83  for( std::list<Point3d>::iterator it = points.begin() ; it != points.end() ; ++it ){
84  pt = Point3df( float( (*it)[0] ), float( (*it)[1] ), float( (*it)[2] ) );
85  pt[ 0 ] *= dsize[ 0 ];
86  pt[ 1 ] *= dsize[ 1 ];
87  pt[ 2 ] *= dsize[ 2 ];
89 
90  if ( npt[ 0 ] < boxmin[ 0 ] ) boxmin[ 0 ] = npt[ 0 ];
91  if ( npt[ 1 ] < boxmin[ 1 ] ) boxmin[ 1 ] = npt[ 1 ];
92  if ( npt[ 2 ] < boxmin[ 2 ] ) boxmin[ 2 ] = npt[ 2 ];
93  if ( npt[ 0 ] > boxmax[ 0 ] ) boxmax[ 0 ] = npt[ 0 ];
94  if ( npt[ 1 ] > boxmax[ 1 ] ) boxmax[ 1 ] = npt[ 1 ];
95  if ( npt[ 2 ] > boxmax[ 2 ] ) boxmax[ 2 ] = npt[ 2 ];
96  }
97 
98  if ( fabs( boxmin[ 0 ] ) > fabs( boxmax[ 0 ] ) )
99  _scale[ 0 ] = 1.0f / fabs( boxmin[ 0 ] );
100  else _scale[ 0 ] = 1.0f / fabs( boxmax[ 0 ] );
101 
102  std::cout << "Box Min : " << boxmin << "\tBox Max :" << boxmax << std::endl ;
103  _scale[ 1 ] = 1.0f / fabs( boxmax[ 1 ] );
104  // On peut ausi prendre
105  // _scale[ 1 ] = 1.0f/_ACPCVec.norm()
106  _scale[ 2 ] = 1.0f / fabs( boxmin[ 2 ] );
107 }
108 
109 
110 inline
113 {
114  computeTransformation( pt );
115  computeBox( roiIt );
116 
117  AimsData<float> rotation(3, 3) ;
118  Point3df translation = -pt.ACmm() ;
119 
120  rotation(0, 0) = -_crossVec[ 0 ];
121  rotation(0, 1) = -_crossVec[ 1 ];
122  rotation(0, 2) = -_crossVec[ 2 ];
123 
124  rotation(1, 0) = _ACPCVec[ 0 ];
125  rotation(1, 1) = _ACPCVec[ 1 ];
126  rotation(1, 2) = _ACPCVec[ 2 ];
127 
128  rotation(2, 0) = _hemiVec[ 0 ];
129  rotation(2, 1) = _hemiVec[ 1 ];
130  rotation(2, 2) = _hemiVec[ 2 ];
131 
132  _transformation.translation() = Point3df(0., 0., 0.) ;
133  _transformation.rotation() = rotation ;
134 
135  std::cout << "Scale : " << _scale << std::endl ;
136  _transformation.scale( Point3df(1., 1., 1. ),
137  Point3df(1.0f/_scale[0], 1.0f/_scale[1], 1.0f/_scale[2] ) ) ;
139  return _transformation ;
140 }
141 
142 #endif
virtual Motion computeTransformation(const TalairachPoints &)
virtual void restart()=0
virtual void scale(const Point3df &sizeFrom, const Point3df &sizeTo)
virtual bool isValid() const =0
void computeBox(carto::rc_ptr< aims::RoiIterator > roiIt)
Motion computeTransformationAndBox(const TalairachPoints &, carto::rc_ptr< aims::RoiIterator > roiIt)
virtual bool isValid() const =0
Point3df _crossVec
Definition: talairach.h:60
virtual const Point3d & value() const =0
virtual void next()=0
Motion _transformation
Definition: talairach.h:65
Point3dd transform(double x, double y, double z) const
Point3df _scale
Definition: talBoxBase.h:54
Point3df & ACmm()
Definition: talPoints.h:67
AimsData< float > & rotation()
Point3df toTalairach(const Point3df &)
virtual void next()=0
virtual carto::rc_ptr< MaskIterator > maskIterator() const =0