LocalTransformation.h
Go to the documentation of this file.
1 /**
2 * @file larcorealg/Geometry/LocalTransformation.h
3 * @brief Class containing local-to-world transformations
4 * @author Gianluca Petrillo (petrillo@fnal.gov)
5 * @date November 30, 2016
6 * @ingroup Geometry
7 *
8 */
9 
10 #ifndef GARSOFT_GEOMETRY_LOCALTRANSFORMATION_H
11 #define GARSOFT_GEOMETRY_LOCALTRANSFORMATION_H
12 
13 // ROOT libraries
14 // (none)
15 // C/C++ standard libraries
16 #include <vector>
17 #include <utility> // std::move()
18 #include <cstdlib> // std::size_t
19 
20 // forward declarations
21 class TGeoNode;
22 
23 namespace gar {
24  namespace geo {
25 
26  /**
27  * @brief Class to transform between world and local coordinates
28  * @tparam StoredMatrix type of transformation matrix internally stored
29  * @ingroup Geometry
30  *
31  * This class provides two directions of transformations (world to local and
32  * the other way around), for points and for vectors.
33  * The vector version of the transformation does not apply translation.
34  *
35  * @note In the class method examples, the following definition is assumed:
36  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
37  * using LocalTransformation_t = geo::LocalTransformation<TGeoHMatrix>;
38  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
39  */
40  template <typename StoredMatrix>
42  public:
43 
44  /// Type of transformation matrix
45  using TransformationMatrix_t = StoredMatrix;
46 
47  /**
48  * @brief Constructor
49  */
51  : fGeoMatrix(nullptr) {}
52 
53  //@{
54  /**
55  * @brief Constructor: uses the specified transformation matrix
56  * @param matrix the transformation matrix to be used
57  *
58  * The specified matrix is copied into a local copy.
59  */
61  : fGeoMatrix(matrix) {}
63  : fGeoMatrix(std::move(matrix)) {}
64  //@}
65 
66  /**
67  * @brief Constructor: uses the specified transformation matrix
68  * @param path the path of ROOT geometry nodes
69  * @param depth the index in the path of the last node to be considered
70  *
71  * The specified matrix is copied into a local copy.
72  */
73  LocalTransformation(std::vector<TGeoNode const*> const& path, size_t depth)
74  : fGeoMatrix(transformationFromPath(path, depth)) {}
75 
76  /**
77  * @brief Transforms a point from local frame to world frame
78  * @param local local coordinates: [0] x, [1] y, [2] z [cm]
79  * @param world (output) corresponding world coordinates [cm]
80  *
81  * The full transformation is applied. Fox example:
82  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
83  * LocalTransformation_t trans( ... ); // with proper initialisation
84  *
85  * std::array<double, 3U> origin, center;
86  * origin.fill(0.);
87  * trans.LocalToWorld(origin.data(), center.data());
88  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
89  * `center` will contain the world coordinates of the center of the volume,
90  * which is usually represented by the origin in the local coordinates.
91  *
92  * In-place replacement is *not* supported: `world` and `local` buffers are
93  * assumed not to, and must not, overlap.
94  */
95  void LocalToWorld(double const* local, double* world) const;
96 
97  /**
98  * @brief Transforms a vector from local frame to world frame
99  * @param local local coordinates: [0] x, [1] y, [2] z [cm]
100  * @param world (output) corresponding world coordinates [cm]
101  *
102  * The translation is not applied, since the argument is supposed to be a
103  * vector, relative difference between two points.
104  *
105  * In-place replacement is *not* supported: `world` and `local` buffers are
106  * assumed not to, and must not, overlap.
107  */
108  void LocalToWorldVect(double const* local, double* world) const;
109 
110  /**
111  * @brief Transforms a point from world frame to local frame
112  * @param world world coordinates: [0] x, [1] y, [2] z [cm]
113  * @param local (output) corresponding local coordinates [cm]
114  *
115  * The full transformation is applied. Fox example:
116  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
117  * LocalTransformation_t trans( ... ); // with proper initialisation
118  *
119  * std::array<double, 3U> world{ 4.0, 5.0, -2.5 }, local;
120  * trans.WorldToLocal(world.data(), local.data());
121  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
122  * `local` will contain the local coordinates of the specified point.
123  *
124  * In-place replacement is *not* supported: `world` and `local` buffers are
125  * assumed not to, and must not, overlap.
126  */
127  void WorldToLocal(double const* world, double* local) const;
128 
129  /**
130  * @brief Transforms a vector from world frame to local frame
131  * @param world world coordinates: [0] x, [1] y, [2] z [cm]
132  * @param local (output) corresponding local coordinates [cm]
133  *
134  * The translation is not applied, since the argument is supposed to be a
135  * vector, relative difference between two points.
136  *
137  * In-place replacement is *not* supported: `world` and `local` buffers are
138  * assumed not to, and must not, overlap.
139  */
140  void WorldToLocalVect(const double* world, double* local) const;
141 
142  /// Direct access to the transformation matrix
143  TransformationMatrix_t const& Matrix() const { return fGeoMatrix; }
144 
145  /// Builds a matrix to go from local to world coordinates in one step
147  (std::vector<TGeoNode const*> const& path, size_t depth);
148 
149  //Set the paths manually instead of constructor
150  void SetPath(std::vector<TGeoNode const*> const& path, size_t depth){
151  fGeoMatrix = transformationFromPath(path, depth);
152  for(size_t i = 0; i <= depth; i++) fNodeVec.push_back(path[i]);
153  }
154 
155  //Set the matrix
157  fGeoMatrix = matrix;
158  }
159 
160  std::vector<TGeoNode const*> GetNodes() const {return fNodeVec;}
161 
163 
164  protected:
165 
166  TransformationMatrix_t fGeoMatrix; ///< local to world transform
167  std::vector<TGeoNode const*> fNodeVec;
168 
169  }; // class LocalTransformation<>
170 
171 
172  } // namespace geo
173 } //namespace gar
174 
175 //------------------------------------------------------------------------------
176 // template implementation
177 #include "LocalTransformation.tcc"
178 //------------------------------------------------------------------------------
179 #endif // GARSOFT_GEOMETRY_LOCALTRANSFORMATION_H
LocalTransformation(TransformationMatrix_t &&matrix)
void SetMatrix(TransformationMatrix_t matrix)
void WorldToLocalVect(const double *world, double *local) const
Transforms a vector from world frame to local frame.
std::vector< TGeoNode const * > GetNodes() const
void LocalToWorldVect(double const *local, double *world) const
Transforms a vector from local frame to world frame.
LocalTransformation(TransformationMatrix_t const &matrix)
Constructor: uses the specified transformation matrix.
STL namespace.
TransformationMatrix_t fGeoMatrix
local to world transform
Class to transform between world and local coordinates.
TransformationMatrix_t const & Matrix() const
Direct access to the transformation matrix.
void WorldToLocal(double const *world, double *local) const
Transforms a point from world frame to local frame.
LocalTransformation(std::vector< TGeoNode const * > const &path, size_t depth)
Constructor: uses the specified transformation matrix.
StoredMatrix TransformationMatrix_t
Type of transformation matrix.
def move(depos, offset)
Definition: depos.py:107
static TransformationMatrix_t transformationFromPath(std::vector< TGeoNode const * > const &path, size_t depth)
Builds a matrix to go from local to world coordinates in one step.
General GArSoft Utilities.
TransformationMatrix_t GetMatrix() const
void SetPath(std::vector< TGeoNode const * > const &path, size_t depth)
std::vector< TGeoNode const * > fNodeVec
void LocalToWorld(double const *local, double *world) const
Transforms a point from local frame to world frame.
LArSoft geometry interface.
Definition: ChannelGeo.h:16