aimsalgo  5.1.2
Neuroimaging image processing
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 <cartobase/smart/rcptr.h>
41 #include <aims/roi/roiIterator.h>
42 #include <list>
43 
44 
46 {
47 public:
49  inline virtual ~TalairachBoundingBoxPoints() {}
53 
54  // Returns a motion from current subject to a normalized template, where
55  // AC (0, 0, 0) PC (0, 1, 0) and IHP (0, 1, cout0)
56 };
57 
58 
59 inline
61 {
62  //int x, y, z, dx = roiIt->volumeDimension()[0], dy = roiIt->volumeDimension()[1], dz = roiIt->volumeDimension()[2] ;
63  Point3df dsize( roiIt->voxelSize() );
64  Point3df boxmax( -10000.0f, -10000.0f, -10000.0f );
65  Point3df boxmin( 10000.0f, 10000.0f, 10000.0f );
66  Point3df pt, npt;
67 
68  roiIt->restart() ;
69  std::list<Point3d> points ;
70  while(roiIt->isValid() ){
71  carto::rc_ptr<aims::MaskIterator> maskIt = roiIt->maskIterator() ;
72 
73  while( maskIt->isValid() ){
74  points.push_back( maskIt->value() ) ;
75 
76  maskIt->next() ;
77  }
78 
79  roiIt->next() ;
80  }
81 
82  for( std::list<Point3d>::iterator it = points.begin() ; it != points.end() ; ++it ){
83  pt = Point3df( float( (*it)[0] ), float( (*it)[1] ), float( (*it)[2] ) );
84  pt[ 0 ] *= dsize[ 0 ];
85  pt[ 1 ] *= dsize[ 1 ];
86  pt[ 2 ] *= dsize[ 2 ];
88 
89  if ( npt[ 0 ] < boxmin[ 0 ] ) boxmin[ 0 ] = npt[ 0 ];
90  if ( npt[ 1 ] < boxmin[ 1 ] ) boxmin[ 1 ] = npt[ 1 ];
91  if ( npt[ 2 ] < boxmin[ 2 ] ) boxmin[ 2 ] = npt[ 2 ];
92  if ( npt[ 0 ] > boxmax[ 0 ] ) boxmax[ 0 ] = npt[ 0 ];
93  if ( npt[ 1 ] > boxmax[ 1 ] ) boxmax[ 1 ] = npt[ 1 ];
94  if ( npt[ 2 ] > boxmax[ 2 ] ) boxmax[ 2 ] = npt[ 2 ];
95  }
96 
97  if ( fabs( boxmin[ 0 ] ) > fabs( boxmax[ 0 ] ) )
98  _scale[ 0 ] = 1.0f / fabs( boxmin[ 0 ] );
99  else _scale[ 0 ] = 1.0f / fabs( boxmax[ 0 ] );
100 
101  std::cout << "Box Min : " << boxmin << "\tBox Max :" << boxmax << std::endl ;
102  _scale[ 1 ] = 1.0f / fabs( boxmax[ 1 ] );
103  // On peut ausi prendre
104  // _scale[ 1 ] = 1.0f/_ACPCVec.norm()
105  _scale[ 2 ] = 1.0f / fabs( boxmin[ 2 ] );
106 }
107 
108 
109 inline
112 {
113  computeTransformation( pt );
114  computeBox( roiIt );
115 
116  carto::VolumeRef<float> rotation(3, 3) ;
117  Point3df translation = -pt.ACmm() ;
118 
119  rotation(0, 0) = -_crossVec[ 0 ];
120  rotation(0, 1) = -_crossVec[ 1 ];
121  rotation(0, 2) = -_crossVec[ 2 ];
122 
123  rotation(1, 0) = _ACPCVec[ 0 ];
124  rotation(1, 1) = _ACPCVec[ 1 ];
125  rotation(1, 2) = _ACPCVec[ 2 ];
126 
127  rotation(2, 0) = _hemiVec[ 0 ];
128  rotation(2, 1) = _hemiVec[ 1 ];
129  rotation(2, 2) = _hemiVec[ 2 ];
130 
132  _transformation.setMatrix(rotation);
133 
134  std::cout << "Scale : " << _scale << std::endl ;
135  _transformation.scale( Point3df(1., 1., 1. ),
136  Point3df(1.0f/_scale[0], 1.0f/_scale[1], 1.0f/_scale[2] ) ) ;
138  return _transformation ;
139 }
140 
141 #endif
void computeBox(carto::rc_ptr< aims::RoiIterator > roiIt)
Motion computeTransformationAndBox(const TalairachPoints &, carto::rc_ptr< aims::RoiIterator > roiIt)
Point3df _scale
Definition: talBoxBase.h:53
Point3df & ACmm()
Definition: talPoints.h:67
aims::AffineTransformation3d _transformation
Definition: talairach.h:63
Point3df _crossVec
Definition: talairach.h:61
Point3df toTalairach(const Point3df &)
virtual aims::AffineTransformation3d computeTransformation(const TalairachPoints &)
virtual void setMatrix(const carto::VolumeRef< float > &mat)
virtual void scale(const Point3df &sizeFrom, const Point3df &sizeTo)
void setTranslation(Point3df trans)
Point3dd transform(double x, double y, double z) const