soma-io  5.1.2
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 #include <cartobase/type/types.h>
47 
48 namespace soma
49 {
50 
57  class Transformation : public virtual carto::RCObject
58  {
59  public:
60  virtual ~Transformation();
61 
73  virtual bool isIdentity() const
74  {
75  return false;
76  }
77 
79  const carto::Object header() const { return _header; }
81 
82  protected:
84 
86  };
87 
88 
92  {
93  public:
94  virtual ~Transformation3d();
95 
96  Point3dd transform( double x, double y, double z ) const;
97  Point3dd transform( const Point3dd & pos ) const;
98  Point3df transform( const Point3df & dir ) const;
99  Point3df transform( float x, float y, float z ) const;
100  Point3d transform( const Point3d & p ) const;
101 
107  virtual bool invertible() const {
108  return false;
109  };
116  virtual std::unique_ptr<Transformation3d> getInverse() const {
117  throw std::logic_error("not implemented");
118  };
119 
120  protected:
122 
123  virtual Point3dd transformDouble( double x, double y, double z ) const = 0;
124  virtual Point3dd transformPoint3dd( const Point3dd & pos ) const;
125  virtual Point3df transformPoint3df( const Point3df & dir ) const;
126  virtual Point3d transformPoint3d( const Point3d & p ) const;
127  virtual Point3df transformFloat( float x, float y, float z ) const;
128  };
129 
130 
131  // --
132 
133  inline Point3dd
134  Transformation3d::transform( double x, double y, double z ) const
135  {
136  return transformDouble( x, y, z );
137  }
138 
139 
140  inline Point3df
141  Transformation3d::transform( float x, float y, float z ) const
142  {
143  return transformFloat( x, y, z );
144  }
145 
146 
147  inline Point3df Transformation3d::transform( const Point3df & pos ) const
148  {
149  return transformPoint3df( pos );
150  }
151 
152 
153  inline Point3dd
155  {
156  return transformPoint3dd( pos );
157  }
158 
159 
160  inline Point3d
162  {
163  return transformPoint3d( pos );
164  }
165 
166 
167  inline Point3df
169  {
170  Point3dd transformed = transform( (double) pos[0], (double) pos[1],
171  (double) pos[2] );
172  return Point3df( (float) transformed[0], (float) transformed[1],
173  (float) transformed[2] );
174  }
175 
176 
177  inline Point3dd
179  {
180  return transform( pos[0], pos[1], pos[2] );
181  }
182 
183 
184  inline Point3df
185  Transformation3d::transformFloat( float x, float y, float z ) const
186  {
187  Point3dd transformed = transform( (double) x, (double) y, (double) z );
188  return Point3df( (float) transformed[0], (float) transformed[1],
189  (float) transformed[2] );
190  }
191 
192 
194  {
195  Point3dd transformed = transform( (double) p[0], (double) p[1],
196  (double) p[2] );
197  return Point3d( (int16_t) rint( transformed[0] ),
198  (int16_t) rint( transformed[1] ),
199  (int16_t) rint( transformed[2] ) );
200  }
201 
202  // --
203 
204  template <> inline std::string DataTypeCode<Transformation3d>::objectType()
205  {
206  return "Transformation3d";
207  }
208 
209  template <> inline std::string DataTypeCode<Transformation3d>::dataType()
210  {
211  return "VOID";
212  }
213 
214  template <> inline std::string DataTypeCode<Transformation3d>::name()
215  {
216  return "Transformation3d";
217  }
218 
219 }
220 
221 #endif
The template class to implement basic vectors.
Definition: vector.h:137
Polymorphic base class for spatial transformations in 3D.
virtual Point3dd transformPoint3dd(const Point3dd &pos) const
virtual std::unique_ptr< Transformation3d > getInverse() const
Obtain the inverse transformation.
virtual Point3d transformPoint3d(const Point3d &p) const
Point3dd transform(double x, double y, double z) const
virtual Point3df transformPoint3df(const Point3df &dir) const
virtual Point3dd transformDouble(double x, double y, double z) const =0
virtual Point3df transformFloat(float x, float y, float z) const
virtual bool invertible() const
Test if the transformation can be inverted.
Polymorphic base class for spatial transformations.
carto::Object _header
carto::Object header()
virtual bool isIdentity() const
Test if the transformation can safely be omitted.
void setHeader(carto::Object ph)
const carto::Object header() const
virtual ~Transformation()
Definition: allocator.h:49
AimsVector< float, 3 > Point3df
Definition: vector.h:247
AimsVector< int16_t, 3 > Point3d
Definition: vector.h:222