Thea
CoordinateFrameN.hpp
1 //============================================================================
2 //
3 // This file is part of the Thea toolkit.
4 //
5 // This software is distributed under the BSD license, as detailed in the
6 // accompanying LICENSE.txt file. Portions are derived from other works:
7 // their respective licenses and copyright information are reproduced in
8 // LICENSE.txt and/or in the relevant source files.
9 //
10 // Author: Siddhartha Chaudhuri
11 // First version: 2011
12 //
13 //============================================================================
14 
15 #ifndef __Thea_CoordinateFrameN_hpp__
16 #define __Thea_CoordinateFrameN_hpp__
17 
18 #include "Common.hpp"
19 #include "RigidTransformN.hpp"
20 
21 namespace Thea {
22 
23 // Forward declarations
24 template <int N, typename T> class CoordinateFrameN;
25 
26 namespace Internal {
27 
33 template <int N, typename T>
34 class /* THEA_DLL_LOCAL */ CoordinateFrameNBase : public RigidTransformN<N, T>
35 {
36  public:
40  typedef typename RigidTransformT::VectorT VectorT;
41  typedef typename RigidTransformT::MatrixT MatrixT;
42 
43  THEA_DECL_SMART_POINTERS(CoordinateFrameT)
44 
45 
47 
49  CoordinateFrameNBase(RigidTransformT const & src) : RigidTransformT(src) {}
50 
55  static CoordinateFrameT _fromAffine(AffineTransformT const & aff_)
56  {
58  }
59 
61  VectorT getAxis(intx i) const { return this->getRotation().col(i); }
62 
64  CoordinateFrameT inverse() const
65  {
67  }
68 
70  CoordinateFrameT operator*(CoordinateFrameT const & rhs) const
71  {
72  return CoordinateFrameT(this->RigidTransformT::operator*(rhs));
73  }
74 
76  VectorT operator*(VectorT const & p) const
77  {
78  return this->RigidTransformT::operator*(p);
79  }
80 
82  VectorT pointToWorldSpace(VectorT const & p) const
83  {
84  return this->RigidTransformT::operator*(p);
85  }
86 
88  VectorT pointToObjectSpace(VectorT const & p) const
89  {
90  return (p - this->getTranslation()).transpose() * this->getRotation();
91  }
92 
94  VectorT vectorToWorldSpace(VectorT const & v) const
95  {
96  return this->getRotation() * v;
97  }
98 
100  VectorT vectorToObjectSpace(VectorT const & v) const
101  {
102  return v.transpose() * this->getRotation();
103  }
104 
106  VectorT normalToWorldSpace(VectorT const & n) const
107  {
108  return this->getRotation() * n;
109  }
110 
112  VectorT normalToObjectSpace(VectorT const & n) const
113  {
114  return n.transpose() * this->getRotation();
115  }
116 
118  static CoordinateFrameT const & identity()
119  {
120  static CoordinateFrameT const idty(RigidTransformT::identity());
121  return idty;
122  }
123 
124  private:
125  // Hide these functions from the default interface
126  RigidTransformT operator*(RigidTransformT const & rhs) const { return RigidTransformT(); }
127  static RigidTransformT translation(VectorT const & translation_) { return RigidTransformT(); }
128 
129 }; // class CoordinateFrameNBase
130 
131 } // namespace Internal
132 
134 template <int N, typename T = Real>
135 class /* THEA_API */ CoordinateFrameN : public Internal::CoordinateFrameNBase<N, T>
136 {
137  private:
139 
140  public:
141  typedef typename BaseT::RigidTransformT RigidTransformT;
142  typedef typename BaseT::VectorT VectorT;
143  typedef typename BaseT::MatrixT MatrixT;
144 
147 
149  CoordinateFrameN(RigidTransformT const & src) : BaseT(src) {}
150 
151 }; // class CoordinateFrameN
152 
154 template <int N, typename T>
155 std::ostream &
156 operator<<(std::ostream & os, CoordinateFrameN<N, T> const & cf)
157 {
158  return os << cf.toString();
159 }
160 
161 } // namespace Thea
162 
163 #include "CoordinateFrame2.hpp"
164 #include "CoordinateFrame3.hpp"
165 
166 #endif
static CoordinateFrameT const & identity()
Get the identity frame (same as the world frame).
AffineTransformN< N, T > AffineTransformT
N-dimensional affine transform.
CoordinateFrameN()
Default constructor.
[Internal] Base class for a coordinate frame in N-space, defined by N orthonormal vectors...
std::ptrdiff_t intx
A signed integer suitable for indexing a structure held in memory.
Definition: Platform.hpp:161
CoordinateFrameNBase(RigidTransformT const &src)
Construct from a rigid transform.
RigidTransformN< N, T > RigidTransformT
N-dimensional rigid transform.
Root namespace for the Thea library.
VectorT vectorToObjectSpace(VectorT const &v) const
Transform a direction vector from world space to the local space of the coordinate frame...
RigidTransformT inverse() const
Get the inverse transform.
static CoordinateFrameT _fromAffine(AffineTransformT const &aff_)
Construct from an affine transform, assuming it is rigid (use with caution since it can break the ort...
VectorT operator*(VectorT const &p) const
Transform a point from the local space of the coordinate frame to world space.
VectorT const & getTranslation() const
Get translation component.
Vector< N, T > VectorT
N-dimensional vector.
static RigidTransformT _fromAffine(AffineTransformT const &aff_)
Construct from an affine transform, assuming it is rigid (use with caution since it can break the rig...
CoordinateFrameN(RigidTransformT const &src)
Construct from a rigid transform.
MatrixT const & getRotation() const
Get rotation component.
CoordinateFrameT operator*(CoordinateFrameT const &rhs) const
Compose this frame, treated as a rigid transform, with another.
VectorT normalToObjectSpace(VectorT const &n) const
Transform a normal from world space to the local space of the coordinate frame.
CoordinateFrameT inverse() const
Get the inverse transform.
A rigid transformation in N-space, consisting of a rotation followed by a translation.
RigidTransformT operator*(RigidTransformT const &rhs) const
Compose this transform with another.
Matrix< N, N, T > MatrixT
NxN matrix.
CoordinateFrameN< N, T > CoordinateFrameT
N-dimensional coordinate frame type.
VectorT pointToWorldSpace(VectorT const &p) const
Transform a point from the local space of the coordinate frame to world space.
VectorT getAxis(intx i) const
Get an axis of the frame.
[Internal] Base class for a rigid transformation in N-space, consisting of a rotation followed by a t...
A coordinate frame in N-space, defined by N orthonormal vectors.
VectorT pointToObjectSpace(VectorT const &p) const
Transform a point from world space to the local space of the coordinate frame.
VectorT vectorToWorldSpace(VectorT const &v) const
Transform a direction vector from the local space of the coordinate frame to world space...
static RigidTransformT const & identity()
Get the identity transform.
VectorT normalToWorldSpace(VectorT const &n) const
Transform a normal from the local space of the coordinate frame to world space.
An affine transform in N-dimensional space, where N is any positive (non-zero) integer and T is a fie...