soma-io  5.0.5
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 #ifndef SOMAIO_TRANSFORMATION_TRANSFORMATION_H
35 #define SOMAIO_TRANSFORMATION_TRANSFORMATION_H
36 /*
37  * These classes used to be in aimsdata, but they are used in Transformation
38  * classes, which are needed in IO, so they have been moved to soma-io
39  * in AIMS 4.7.
40  */
41 
42 #include <stdexcept>
43 
44 #include <soma-io/vector/vector.h>
45 #include <cartobase/smart/rcptr.h>
46 
47 namespace soma
48 {
49 
52  class Transformation : public virtual carto::RCObject
53  {
54  public:
55  virtual ~Transformation();
56 
68  virtual bool isIdentity() const
69  {
70  return false;
71  }
72 
73  protected:
75  };
76 
77 
81  {
82  public:
83  virtual ~Transformation3d();
84 
85  Point3dd transform( double x, double y, double z ) const;
86  Point3dd transform( const Point3dd & pos ) const;
87  Point3df transform( const Point3df & dir ) const;
88  Point3df transform( float x, float y, float z ) const;
89  Point3d transform( const Point3d & p ) const;
90 
96  virtual bool invertible() const {
97  return false;
98  };
105  virtual std::unique_ptr<Transformation3d> getInverse() const {
106  throw std::logic_error("not implemented");
107  };
108 
109  protected:
111 
112  virtual Point3dd transformDouble( double x, double y, double z ) const = 0;
113  virtual Point3dd transformPoint3dd( const Point3dd & pos ) const;
114  virtual Point3df transformPoint3df( const Point3df & dir ) const;
115  virtual Point3d transformPoint3d( const Point3d & p ) const;
116  virtual Point3df transformFloat( float x, float y, float z ) const;
117  };
118 
119 
120  // --
121 
122  inline Point3dd
123  Transformation3d::transform( double x, double y, double z ) const
124  {
125  return transformDouble( x, y, z );
126  }
127 
128 
129  inline Point3df
130  Transformation3d::transform( float x, float y, float z ) const
131  {
132  return transformFloat( x, y, z );
133  }
134 
135 
136  inline Point3df Transformation3d::transform( const Point3df & pos ) const
137  {
138  return transformPoint3df( pos );
139  }
140 
141 
142  inline Point3dd
144  {
145  return transformPoint3dd( pos );
146  }
147 
148 
149  inline Point3d
151  {
152  return transformPoint3d( pos );
153  }
154 
155 
156  inline Point3df
158  {
159  Point3dd transformed = transform( (double) pos[0], (double) pos[1],
160  (double) pos[2] );
161  return Point3df( (float) transformed[0], (float) transformed[1],
162  (float) transformed[2] );
163  }
164 
165 
166  inline Point3dd
168  {
169  return transform( pos[0], pos[1], pos[2] );
170  }
171 
172 
173  inline Point3df
174  Transformation3d::transformFloat( float x, float y, float z ) const
175  {
176  Point3dd transformed = transform( (double) x, (double) y, (double) z );
177  return Point3df( (float) transformed[0], (float) transformed[1],
178  (float) transformed[2] );
179  }
180 
181 
183  {
184  Point3dd transformed = transform( (double) p[0], (double) p[1],
185  (double) p[2] );
186  return Point3d( (int16_t) rint( transformed[0] ),
187  (int16_t) rint( transformed[1] ),
188  (int16_t) rint( transformed[2] ) );
189  }
190 
191 }
192 
193 #endif
virtual Point3df transformPoint3df(const Point3df &dir) const
The template class to implement basic vectors.
Definition: vector.h:53
Point3dd transform(double x, double y, double z) const
virtual Point3d transformPoint3d(const Point3d &p) const
Polymorphic base class for spatial transformations.
virtual std::unique_ptr< Transformation3d > getInverse() const
Obtain the inverse transformation.
Definition: allocator.h:48
AimsVector< float, 3 > Point3df
Definition: vector.h:245
virtual bool isIdentity() const
Test if the transformation can safely be omitted.
virtual Point3dd transformPoint3dd(const Point3dd &pos) const
AimsVector< int16_t, 3 > Point3d
Definition: vector.h:220
virtual Point3df transformFloat(float x, float y, float z) const
virtual ~Transformation()
virtual bool invertible() const
Test if the transformation can be inverted.
Polymorphic base class for spatial transformations in 3D.