anatomist  5.0.5
3D neuroimaging data viewer
Transformation.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 ANA_REFERENCE_TRANSFORMATION_H
36 #define ANA_REFERENCE_TRANSFORMATION_H
37 
38 //--- header files ------------------------------------------------------------
39 
40 #include <aims/resampling/motion.h>
41 
42 
43 //--- class declarations ------------------------------------------------------
44 
45 namespace aims
46 {
47  class Quaternion;
48 }
49 
50 namespace anatomist
51 {
52 
53  class Referential;
54 
62  {
63  public:
64  Transformation( Referential *,Referential *, bool regist = false,
65  bool generated = false );
67  const Transformation & trans );
70  virtual ~Transformation();
71 
73  Transformation & operator = ( const Transformation & trans );
74  Transformation & operator *= ( const Transformation & trans );
75  // Transformation & operator += ( const Transformation & trans );
77  Motion & motion() { return _motion; }
78  const Motion & motion() const { return _motion; }
79 
80  void setRotation( float** r );
81  void setTranslation( float* t );
83  void setMatrix( float** m );
85  void setMatrixT( float m[4][3] );
87  void SetRotation(int , int , float );
89  void SetTranslation(int , float );
91  float Rotation(int ,int );
92  aims::Quaternion quaternion() const;
93  void setQuaternion( const aims::Quaternion & q );
95  float Translation(int );
96  Point3df translation() const;
97  Referential* source() const { return( _source ); }
98  Referential* destination() const { return( _dest ); }
100  void invert();
102  void invertReferentials();
104  bool isDirect() const;
105 
107  Point3df transform( const Point3df & pos ) const;
108  /* transforms cube (pmin1, pmin2) and builds the new bounding box
109  in the new ref */
110  void transformBoundingBox( const Point3df & pmin1, const Point3df & pmax1,
111  Point3df & pmin2, Point3df & pmax2 );
112 
114  void registerTrans();
115  void unregisterTrans();
116  bool isGenerated() const { return( _generated ); }
117  void setGenerated( bool x ) { _generated = x; }
118 
120  void addMotionToHistory(const Motion &);
122  void undo();
124  void redo();
126  std::size_t motionHistorySize() const
127  {
128  return _motionHistory.size();
129  }
131  int motionHistoryIndex() const
132  {
133  return _motionHistoryIndex;
134  }
135 
142  static Point3df transform( const Point3df & pos, const Transformation* tra,
143  const Point3df & voxSizeOrg,
144  const Point3df & voxSizeDst );
146  static Point3df transform( const Point3df & pos, const Referential* orgRef,
147  const Referential* dstRef,
148  const Point3df & voxSizeOrg,
149  const Point3df & voxSizeDst );
151  static Point3df transform( const Point3df & pos,
152  const Point3df & voxSizeOrg,
153  const Point3df & voxSizeDst );
155  static Point3df transform( const Point3df & pos, const Transformation* tra,
156  const Point3df & voxSizeDst );
158  static Point3df transform( const Point3df & pos,
159  const Point3df & voxSizeOrg,
160  const Transformation* tra );
162  static Point3df transform( const Point3df & pos,
163  const Point3df & voxSizeOrg );
166  static Point3df transformDG( const Point3df & pos,
167  const Point3df & voxSizeDst );
168  void notifyChange();
169 
170  protected:
175  std::vector <Motion> _motionHistory;
177  };
178 
179 
180  // inline functions
181 
182 
183  inline Point3df
184  Transformation::transform( const Point3df & pos, const Transformation* tra,
185  const Point3df & voxSizeOrg,
186  const Point3df & voxSizeDst )
187  {
188  Point3df pt = tra->transform( Point3df( pos[0] * voxSizeOrg[0],
189  pos[1] * voxSizeOrg[1],
190  pos[2] * voxSizeOrg[2] ) );
191  return( Point3df( pt[0] / voxSizeDst[0], pt[1] / voxSizeDst[1],
192  pt[2] / voxSizeDst[2] ) );
193  }
194 
195 
196  inline Point3df
197  Transformation::transform( const Point3df & pos,
198  const Point3df & voxSizeOrg,
199  const Point3df & voxSizeDst )
200  {
201  return( Point3df( pos[0] * voxSizeOrg[0] / voxSizeDst[0],
202  pos[1] * voxSizeOrg[1] / voxSizeDst[1],
203  pos[2] * voxSizeOrg[2] / voxSizeDst[2] ) );
204  }
205 
206 
207  inline Point3df
208  Transformation::transform( const Point3df & pos, const Point3df & voxSizeOrg,
209  const Transformation* tra )
210  {
211  return( tra->transform( Point3df( pos[0] * voxSizeOrg[0],
212  pos[1] * voxSizeOrg[1],
213  pos[2] * voxSizeOrg[2] ) ) );
214  }
215 
216 
217  inline Point3df
218  Transformation::transform( const Point3df & pos, const Transformation* tra,
219  const Point3df & voxSizeDst )
220  {
221  Point3df pt = tra->transform( pos );
222  return( Point3df( pt[0] / voxSizeDst[0], pt[1] / voxSizeDst[1],
223  pt[2] / voxSizeDst[2] ) );
224  }
225 
226 
227  inline Point3df
228  Transformation::transform( const Point3df & pos,
229  const Point3df & voxSizeOrg )
230  {
231  return( Point3df( pos[0] * voxSizeOrg[0], pos[1] * voxSizeOrg[1],
232  pos[2] * voxSizeOrg[2] ) );
233  }
234 
235 
236  inline Point3df
237  Transformation::transformDG( const Point3df & pos,
238  const Point3df & voxSizeDst )
239  {
240  return( Point3df( pos[0] / voxSizeDst[0], pos[1] / voxSizeDst[1],
241  pos[2] / voxSizeDst[2] ) );
242  }
243 
244  inline Point3df
245  Transformation::translation() const
246  {
247  return _motion.translation();
248  }
249 
250 }
251 
252 
253 namespace carto
254 {
256  DECLARE_GENERIC_OBJECT_TYPE( std::set<anatomist::Transformation *> )
257  DECLARE_GENERIC_OBJECT_TYPE( std::vector<anatomist::Transformation *> )
258  DECLARE_GENERIC_OBJECT_TYPE( std::list<anatomist::Transformation *> )
259 }
260 
261 #endif
#define DECLARE_GENERIC_OBJECT_TYPE(T)
int motionHistoryIndex() const
Returns the current motion history index.
Point3df transform(const Point3df &pos) const
Transforms a point.
Referential * source() const
std::size_t motionHistorySize() const
Returns the motion history size.
std::vector< Motion > _motionHistory
Referential * destination() const
aims::SparseMatrix operator-(const aims::SparseMatrix &thing)
void transformBoundingBox(const AffineTransformation3d &AffineTransformation3d, const Point3df &pmin1, const Point3df &pmax1, Point3df &pmin2, Point3df &pmax2)
Referential: marker for transformations, with an associated color.
Definition: Referential.h:54
Transformation between two referentials.
const Motion & motion() const