LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
LocalTransformation.tcc
Go to the documentation of this file.
1 /**
2  * @file larcorealg/Geometry/LocalTransformation.tcc
3  * @brief Class containing local-to-world transformations
4  * (template implementation)
5  * @author Gianluca Petrillo (petrillo@fnal.gov)
6  * @date November 30, 2016
7  * @see LocalTransformation.h
8  *
9  * This file is expected to be included directly in the header.
10  *
11  */
12 
13 #ifndef LARCOREALG_GEOMETRY_LOCALTRANSFORMATION_TCC
14 #define LARCOREALG_GEOMETRY_LOCALTRANSFORMATION_TCC
15 
16 // framework libraries
17 #include "cetlib_except/exception.h"
18 
19 // ROOT
20 #include "TGeoNode.h"
21 #include "TGeoMatrix.h"
22 
23 // CLHEP
24 #include "CLHEP/Geometry/Transform3D.h"
25 
26 // C standard library
27 #include <cassert>
28 
29 
30 //------------------------------------------------------------------------------
31 namespace geo {
32  namespace details {
33 
34  template <typename T, std::size_t SrcN = 3, std::size_t DestN = SrcN>
35  bool doBuffersOverlap(T const* src, T const* dest)
36  { return (dest < (src + SrcN)) && (src < (dest + DestN)); }
37 
38  template <typename T, std::size_t SrcN = 3, std::size_t DestN = SrcN>
39  void checkVectorBufferOverlap(T const* src, T const* dest) {
40  if (doBuffersOverlap<T, SrcN, DestN>(src, dest)) {
41  throw cet::exception("LocalTransformation")
42  << "source " << SrcN << "@[" << ((void*) src) << "]"
43  << " and destination " << DestN << "@[" << ((void*) dest) << "]"
44  << " buffers overlap!\n";
45  }
46  assert(!doBuffersOverlap(src, dest));
47  } // checkVectorBufferOverlap()
48 
49  } // namespace details
50 } // namespace geo
51 
52 
53 //------------------------------------------------------------------------------
54 template <typename Matrix>
55 void geo::LocalTransformation<Matrix>::LocalToWorld
56  (double const* local, double* world) const
57 {
58  details::checkVectorBufferOverlap(local, world);
59  fGeoMatrix.LocalToMaster(local, world);
60 } // geo::LocalTransformation::LocalToWorld()
61 
62 
63 //------------------------------------------------------------------------------
64 template <typename Matrix>
65 void geo::LocalTransformation<Matrix>::LocalToWorldVect
66  (double const* local, double* world) const
67 {
68  details::checkVectorBufferOverlap(local, world);
69  fGeoMatrix.LocalToMasterVect(local, world);
70 } // geo::LocalTransformation::LocalToWorldVect()
71 
72 
73 //------------------------------------------------------------------------------
74 template <typename Matrix>
75 void geo::LocalTransformation<Matrix>::WorldToLocal
76  (double const* world, double* local) const
77 {
78  details::checkVectorBufferOverlap(local, world);
79  fGeoMatrix.MasterToLocal(world, local);
80 } // geo::LocalTransformation::WorldToLocal()
81 
82 
83 //------------------------------------------------------------------------------
84 template <typename Matrix>
85 void geo::LocalTransformation<Matrix>::WorldToLocalVect
86  (const double* world, double* local) const
87 {
88  details::checkVectorBufferOverlap(local, world);
89  fGeoMatrix.MasterToLocalVect(world, local);
90 } // geo::LocalTransformation::WorldToLocalVect()
91 
92 
93 //------------------------------------------------------------------------------
94 template <typename Matrix>
95 template <typename DestPoint, typename SrcPoint>
96 DestPoint geo::LocalTransformation<Matrix>::WorldToLocalImpl
97  (SrcPoint const& world) const
98 {
99  double const worldArray[3] = { world.X(), world.Y(), world.Z() };
100  double localArray[3];
101  WorldToLocal(worldArray, localArray);
102  return { localArray[0], localArray[1], localArray[2] };
103 } // geo::LocalTransformation::WorldToLocal()
104 
105 
106 //......................................................................
107 template <typename Matrix>
108 template <typename DestVector, typename SrcVector>
109 DestVector geo::LocalTransformation<Matrix>::WorldToLocalVectImpl
110  (SrcVector const& world) const
111 {
112  double const worldArray[3] = { world.X(), world.Y(), world.Z() };
113  double localArray[3];
114  WorldToLocalVect(worldArray, localArray);
115  return { localArray[0], localArray[1], localArray[2] };
116 } // geo::LocalTransformation::WorldToLocalVect()
117 
118 
119 //......................................................................
120 template <typename Matrix>
121 template <typename DestPoint, typename SrcPoint>
122 DestPoint geo::LocalTransformation<Matrix>::LocalToWorldImpl
123  (SrcPoint const& local) const
124 {
125  double const localArray[3] = { local.X(), local.Y(), local.Z() };
126  double worldArray[3];
127  LocalToWorld(localArray, worldArray);
128  return { worldArray[0], worldArray[1], worldArray[2] };
129 } // geo::LocalTransformation::LocalToWorld()
130 
131 
132 //......................................................................
133 template <typename Matrix>
134 template <typename DestVector, typename SrcVector>
135 DestVector geo::LocalTransformation<Matrix>::LocalToWorldVectImpl
136  (SrcVector const& local) const
137 {
138  double const localArray[3] = { local.X(), local.Y(), local.Z() };
139  double worldArray[3];
140  LocalToWorldVect(localArray, worldArray);
141  return { worldArray[0], worldArray[1], worldArray[2] };
142 } // geo::LocalTransformation::LocalToWorldVect()
143 
144 
145 //------------------------------------------------------------------------------
146 // specialisations (forward declarations)
147 //
148 namespace geo {
149 
150  template <>
151  TGeoHMatrix LocalTransformation<TGeoHMatrix>::transformationFromPath
152  (std::vector<TGeoNode const*> const& path, size_t depth);
153 
154  template <>
155  HepGeom::Transform3D
156  LocalTransformation<HepGeom::Transform3D>::transformationFromPath
157  (std::vector<TGeoNode const*> const& path, size_t depth);
158 
159 } // namespace geo
160 
161 //------------------------------------------------------------------------------
162 
163 #endif // LARCOREALG_GEOMETRY_LOCALTRANSFORMATION_TCC