aimsalgo 6.0.0
Neuroimaging image processing
talBox.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_TALBOX_H
36#define AIMS_TALAIRACH_TALBOX_H
37
38#include <cstdlib>
39#include <cartodata/volume/volume.h>
41
42
43template< class T >
45{
46public:
48 inline virtual ~TalairachBox() {}
52
53 // Returns a motion from current subject to a normalized template, where
54 // AC (0, 0, 0) PC (0, 1, 0) and IHP (0, 1, cout0)
55};
56
57
58template< class T > inline
61{
62 int x, y, z, dx = d->getSizeX(), dy = d->getSizeY(), dz = d->getSizeZ();
63 Point3df dsize( d->getVoxelSize() );
64 Point3df boxmax( -10000.0f, -10000.0f, -10000.0f );
65 Point3df boxmin( 10000.0f, 10000.0f, 10000.0f );
66 Point3df pt, npt;
67
68 for ( z=0; z<dz; z++ )
69 for ( y=0; y<dy; y++ )
70 for ( x=0; x<dx; x++ )
71 if ( d->at( x, y, z ) )
72 {
73 pt = Point3df( float( x ), float( y ), float( z ) );
74 pt[ 0 ] *= dsize[ 0 ];
75 pt[ 1 ] *= dsize[ 1 ];
76 pt[ 2 ] *= dsize[ 2 ];
78
79 if ( npt[ 0 ] < boxmin[ 0 ] ) boxmin[ 0 ] = npt[ 0 ];
80 if ( npt[ 1 ] < boxmin[ 1 ] ) boxmin[ 1 ] = npt[ 1 ];
81 if ( npt[ 2 ] < boxmin[ 2 ] ) boxmin[ 2 ] = npt[ 2 ];
82 if ( npt[ 0 ] > boxmax[ 0 ] ) boxmax[ 0 ] = npt[ 0 ];
83 if ( npt[ 1 ] > boxmax[ 1 ] ) boxmax[ 1 ] = npt[ 1 ];
84 if ( npt[ 2 ] > boxmax[ 2 ] ) boxmax[ 2 ] = npt[ 2 ];
85 }
86
87 if ( fabs( boxmin[ 0 ] ) > fabs( boxmax[ 0 ] ) )
88 _scale[ 0 ] = 1.0f / fabs( boxmin[ 0 ] );
89 else _scale[ 0 ] = 1.0f / fabs( boxmax[ 0 ] );
90
91 std::cout << "Box Min : " << boxmin << "\tBox Max :" << boxmax << std::endl ;
92 _scale[ 1 ] = 1.0f / fabs( boxmax[ 1 ] );
93 // On peut ausi prendre
94 // _scale[ 1 ] = 1.0f/_ACPCVec.norm()
95 _scale[ 2 ] = 1.0f / fabs( boxmin[ 2 ] );
96}
97
98
99template< class T > inline
101 const TalairachPoints& pt, const carto::rc_ptr<carto::Volume< T > > & d )
102{
104 computeBox( d );
105
106 carto::VolumeRef<float> rotation(3, 3) ;
107 Point3df translation = -pt.ACmm() ;
108
109 rotation(0, 0) = -_crossVec[ 0 ];
110 rotation(0, 1) = -_crossVec[ 1 ];
111 rotation(0, 2) = -_crossVec[ 2 ];
112
113 rotation(1, 0) = _ACPCVec[ 0 ];
114 rotation(1, 1) = _ACPCVec[ 1 ];
115 rotation(1, 2) = _ACPCVec[ 2 ];
116
117 rotation(2, 0) = _hemiVec[ 0 ];
118 rotation(2, 1) = _hemiVec[ 1 ];
119 rotation(2, 2) = _hemiVec[ 2 ];
120
121 _transformation.setTranslation( Point3df(0., 0., 0.) );
122 _transformation.setMatrix(rotation);
123
124 std::cout << "Scale : " << _scale << std::endl ;
125 _transformation.scale( Point3df(1., 1., 1. ),
126 Point3df(1.0f/_scale[0], 1.0f/_scale[1], 1.0f/_scale[2] ) ) ;
127 _transformation.setTranslation( _transformation.transform(translation) );
128 return _transformation ;
129}
130
131#endif
Point3df _scale
Definition talBoxBase.h:53
void computeBox(const carto::rc_ptr< carto::Volume< T > > &)
Definition talBox.h:59
virtual ~TalairachBox()
Definition talBox.h:48
TalairachBox()
Definition talBox.h:47
aims::AffineTransformation3d computeTransformationAndBox(const TalairachPoints &, const carto::rc_ptr< carto::Volume< T > > &)
Definition talBox.h:100
Point3df & ACmm()
Definition talPoints.h:67
aims::AffineTransformation3d _transformation
Definition talairach.h:63
Point3df toTalairach(const Point3df &)
virtual aims::AffineTransformation3d computeTransformation(const TalairachPoints &)
AimsVector< float, 3 > Point3df