LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
LocalTransformation.h
Go to the documentation of this file.
1 
10 #ifndef LARCOREALG_GEOMETRY_LOCALTRANSFORMATION_H
11 #define LARCOREALG_GEOMETRY_LOCALTRANSFORMATION_H
12 
13 // ROOT libraries
14 // (none)
15 
16 // C/C++ standard libraries
17 #include <cstdlib> // std::size_t
18 #include <type_traits> // std::enable_if_t<>, std::decay_t<>
19 #include <utility> // std::move(), std::forward()
20 #include <vector>
21 
22 // forward declarations
23 class TGeoNode;
24 
25 namespace geo {
26 
27  namespace details {
28  template <typename Dest, typename Src>
30  } // namespace details
31 
33 
35  template <typename StoredMatrix, typename ITER>
36  static StoredMatrix transformationFromPath(ITER begin, ITER end);
37 
39  template <typename StoredMatrix>
40  static StoredMatrix transformationFromPath(std::vector<TGeoNode const*> const& path,
41  size_t depth);
42  // { return transformationFromPath(path.begin(), path.begin() + depth); }
43 
58  template <typename StoredMatrix>
60  public:
62  using TransformationMatrix_t = StoredMatrix;
63 
65 
76  LocalTransformation(TransformationMatrix_t const& matrix) : fGeoMatrix(matrix) {}
77  LocalTransformation(TransformationMatrix_t&& matrix) : fGeoMatrix(std::move(matrix)) {}
79 
88  LocalTransformation(std::vector<TGeoNode const*> const& path, size_t depth)
89  : fGeoMatrix(transformationFromPath<StoredMatrix>(path.begin(), path.begin() + depth + 1))
90  {}
91 
99  LocalTransformation(std::vector<TGeoNode const*> const& path)
100  : LocalTransformation(path, path.size())
101  {}
102 
112  template <typename ITER>
114  : fGeoMatrix(transformationFromPath<StoredMatrix>(begin, end))
115  {}
116 
136  void LocalToWorld(double const* local, double* world) const;
137 
138  // @{
157  template <typename DestPoint,
158  typename SrcPoint,
160  DestPoint LocalToWorld(SrcPoint const& local) const
161  {
162  return LocalToWorldImpl<DestPoint>(local);
163  }
164  template <typename Point>
165  Point LocalToWorld(Point const& local) const
166  {
167  return LocalToWorldImpl<Point>(local);
168  }
169  // @}
170 
182  void LocalToWorldVect(double const* local, double* world) const;
183 
185 
195  template <typename DestVector,
196  typename SrcVector,
198  DestVector LocalToWorldVect(SrcVector const& local) const
199  {
200  return LocalToWorldVectImpl<DestVector>(local);
201  }
202  template <typename Vector>
203  Vector LocalToWorldVect(Vector const& local) const
204  {
205  return LocalToWorldVectImpl<Vector>(local);
206  }
208 
226  void WorldToLocal(double const* world, double* local) const;
227 
229 
245  template <typename DestPoint,
246  typename SrcPoint,
248  DestPoint WorldToLocal(SrcPoint const& world) const
249  {
250  return WorldToLocalImpl<DestPoint>(world);
251  }
252  template <typename Point>
253  Point WorldToLocal(Point const& world) const
254  {
255  return WorldToLocalImpl<Point>(world);
256  }
258 
270  void WorldToLocalVect(const double* world, double* local) const;
271 
273 
283  template <typename DestVector,
284  typename SrcVector,
286  DestVector WorldToLocalVect(SrcVector const& world) const
287  {
288  return WorldToLocalVectImpl<DestVector>(world);
289  }
290  template <typename Vector>
291  Vector WorldToLocalVect(Vector const& world) const
292  {
293  return WorldToLocalVectImpl<Vector>(world);
294  }
296 
298  TransformationMatrix_t const& Matrix() const { return fGeoMatrix; }
299 
300  protected:
302 
303  template <typename DestPoint, typename SrcPoint>
304  DestPoint LocalToWorldImpl(SrcPoint const& local) const;
305 
306  template <typename DestVector, typename SrcVector>
307  DestVector LocalToWorldVectImpl(SrcVector const& local) const;
308 
309  template <typename DestPoint, typename SrcPoint>
310  DestPoint WorldToLocalImpl(SrcPoint const& world) const;
311 
312  template <typename DestVector, typename SrcVector>
313  DestVector WorldToLocalVectImpl(SrcVector const& world) const;
314 
315  }; // class LocalTransformation<>
316 
318  template <typename Dest, typename Src>
319  decltype(auto) convertTransformationMatrix(Src&& trans)
320  {
321  return details::TransformationMatrixConverter<std::decay_t<Dest>, std::decay_t<Src>>::convert(
322  std::forward<Src>(trans));
323  }
324 
325 } // namespace geo
326 
327 //------------------------------------------------------------------------------
328 // template implementation
329 
330 #include "LocalTransformation.tcc"
331 
332 //------------------------------------------------------------------------------
333 
334 #endif // LARCOREALG_GEOMETRY_LOCALTRANSFORMATION_H
DestPoint WorldToLocal(SrcPoint const &world) const
Transforms a point from world frame to local frame.
decltype(auto) convertTransformationMatrix(Src &&trans)
Converts a transformation matrix into Dest format.
geo::TransformationMatrix TransformationMatrix_t
Type of transformation matrix.
TransformationMatrix_t const & Matrix() const
Direct access to the transformation matrix.
STL namespace.
DestVector LocalToWorldVect(SrcVector const &local) const
Transforms a vector from local frame to world frame.
intermediate_table::const_iterator const_iterator
Vector LocalToWorldVect(Vector const &local) const
Transforms a vector from local frame to world frame.
LocalTransformation(std::vector< TGeoNode const * > const &path)
Constructor: chains the transformations from all specified nodes.
DestVector WorldToLocalVect(SrcVector const &world) const
Transforms a vector from world frame to local frame.
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
LocalTransformation(std::vector< TGeoNode const * > const &path, size_t depth)
Constructor: chains the transformations from the specified nodes.
Class to transform between world and local coordinates.
TransformationMatrix_t fGeoMatrix
local to world transform
LocalTransformation(TransformationMatrix_t const &matrix)
Constructor: uses the specified local-to-world transformation.
LocalTransformation(ITER begin, ITER end)
Constructor: sequence of transformations from a node path.
double value
Definition: spectrum.C:18
static StoredMatrix transformationFromPath(ITER begin, ITER end)
Builds a matrix to go from local to world coordinates in one step.
DestPoint LocalToWorld(SrcPoint const &local) const
Transforms a point from local frame to world frame.
Vector WorldToLocalVect(Vector const &world) const
Transforms a vector from world frame to local frame.
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
Definition: DCEL.h:42
Point LocalToWorld(Point const &local) const
Transforms a point from local frame to world frame.
Point WorldToLocal(Point const &world) const
Transforms a point from world frame to local frame.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:69
LocalTransformation(TransformationMatrix_t &&matrix)
Constructor: uses the specified local-to-world transformation.
Namespace collecting geometry-related classes utilities.
std::vector< TGeoNode const * >::const_iterator GeoNodeIterator_t