Decomposer.h
Go to the documentation of this file.
1 /**
2  * @file Decomposer.h
3  * @brief Classes to project and compose a vector on a plane
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date December 1, 2016
6  * @ingroup Geometry
7  *
8  */
9 
10 #ifndef LARCOREALG_GEOMETRY_DECOMPOSER_H
11 #define LARCOREALG_GEOMETRY_DECOMPOSER_H
12 
13 // LArSoft libraries
14 #include "larcorealg/Geometry/geo_vectors_utils.h" // geo::vect
15 
16 // C/C++ standard libraries
17 #include <cmath> // std::abs()
18 #include <utility> // std::move()
19 #include <type_traits> // std::declval()
20 
21 
22 namespace geo {
23 
24  // --- BEGIN Decomposition objects -------------------------------------------
25  /// @name Decomposition objects
26  /// @ingroup Geometry
27  /// @{
28 
29  /** **************************************************************************
30  * @brief A base for a plane in space
31  *
32  * The base contains the two axes, a "main" one (@f$ \hat{u} @f$) and a
33  * "secondary" one (@f$ \hat{v} @f$).
34  * It also defines a normal (@f$ \hat{n} @f$) to the plane so that the base
35  * is positive defined ((@f$ \hat{u} \times \hat{v} \cdot \hat{m} = +1 @f$).
36  *
37  */
38  template <typename Vector>
39  class PlaneBase {
40  public:
41  using Vector_t = Vector; ///< Type for the vector in space
42 
43  /// Rounding threshold for vectors
44  static constexpr double RoundingTol = 1e-4;
45 
46  /// Constructor: assigns the axes
47  PlaneBase(Vector_t const& main, Vector_t const& secondary)
48  : fMain(PastorizeUnitVector(main))
49  , fSecondary(PastorizeUnitVector(secondary))
51  {}
52 
53  /// Returns the main axis direction
54  Vector_t const& MainDir() const { return fMain; }
55 
56  /// Returns the secondary axis direction
57  Vector_t const& SecondaryDir() const { return fSecondary; }
58 
59  /// Returns the axis normal to the plane
60  Vector_t const& NormalDir() const { return fNormal; }
61 
62  /// Change the main direction of the projection base
63  void SetMainDir(Vector_t const& dir) { fMain = dir; ResetNormal(); }
64 
65  /// Change the secondary direction of the projection base
67  { fSecondary = dir; ResetNormal(); }
68 
69 
70  /// Normalizes and rounds a direction vector
72  { return geo::vect::rounded01(geo::vect::normalize(dir), RoundingTol); }
73 
74  private:
75  Vector_t fMain; ///< Main axis on the plane
76  Vector_t fSecondary; ///< Secondary axis on the plane
77  Vector_t fNormal; ///< Axis normal to the plane
78 
79  /// Computes the normal to the plane
81  { return PastorizeUnitVector(MainDir().Cross(SecondaryDir())); }
82 
83  /// Reset normal to the plane
84  void ResetNormal() { fNormal = ComputeNormal(); }
85 
86  }; // class PlaneBase<>
87 
88 
89  /// A base for a plane in space, with a coordinate system
90  /// @tparam Vector type to represent 3D vectors
91  /// @tparam Point type to represent 3D points (same as Vector by default)
92  template <typename Vector, typename Point = Vector>
95 
96  public:
97  using Vector_t = typename PlaneBase_t::Vector_t; ///< Vector in space
98  using Point_t = Point; ///< Point in space
99 
100  /// Constructor: assigns the origin of the system and the axes
102  (Point_t const& origin, Vector_t const& main, Vector_t const& secondary)
103  : fOrigin(origin)
104  , fBase(main, secondary)
105  {}
106 
107  /// Returns the main axis direction
108  Vector_t const& MainDir() const { return fBase.MainDir(); }
109 
110  /// Returns the secondary axis direction
111  Vector_t const& SecondaryDir() const { return fBase.SecondaryDir(); }
112 
113  /// Returns the secondary axis direction
114  Vector_t const& NormalDir() const { return fBase.NormalDir(); }
115 
116  /// Returns the origin of the coordinate system in world coordinates
117  Point_t Origin() const { return fOrigin; }
118 
119  /// Returns the vector representing the specified point in the affine space
120  Vector_t ToVector(Point_t const& point) const { return point - Origin(); }
121 
122 
123  /// Change the 3D point of the reference frame origin
124  void SetOrigin(Point_t const& point) { fOrigin = point; }
125 
126  /// Change the main direction of the projection base
127  void SetMainDir(Vector_t const& dir) { fBase.SetMainDir(dir); }
128 
129  /// Change the secondary direction of the projection base
130  void SetSecondaryDir(Vector_t const& dir) { fBase.SetSecondaryDir(dir); }
131 
132  private:
133 
134  Point_t fOrigin; ///< Origin of the coordinate system
135  PlaneBase_t fBase; ///< Base
136 
137  }; // class AffinePlaneBase<>
138 
139 
140  /// Structure hosting projections of a 3D vector (or point ) on the plane
141  /// @tparam ProjVector type for 2D vector projection
142  template <typename ProjVector>
144 
145  using Projection_t = ProjVector; ///< Type for 2D projection
146 
147  /// Type for distance from plane
148  using Distance_t = decltype(geo::vect::mag2(std::declval<Projection_t>()));
149 
150 
151  Projection_t projection; ///< Projection of the vector on the plane
152  Distance_t distance; ///< Distance of the vector from the plane
153 
154 
155  DecomposedVector() = default;
156 
157  DecomposedVector(Projection_t const& projection, Distance_t distance)
158  : projection(projection), distance(distance) {}
159 
160  DecomposedVector(Distance_t distance, Projection_t const& projection)
161  : projection(projection), distance(distance) {}
162 
163  }; // struct DecomposedVector
164 
165 
166 
167  /** **************************************************************************
168  * @brief Class with methods for projection of vectors on a plane
169  * @tparam Vector type to represent 3D vectors
170  * @tparam Point type to represent 3D points
171  * @tparam ProjVector type to represent 2D projection on plane
172  *
173  * These methods deal with projection of points and vectors on a plane.
174  *
175  * The plane is defined in a 3D space, with two axes, the "main" and the
176  * "auxiliary" one, which are orthogonal.
177  */
178  template <typename Vector, typename Point, typename ProjVector>
180 
181  public:
182 
184 
185  /// Type of decomposed vector
187 
188  /// Type for a point
190 
191  /// Type for a vector
193 
194  /// Type representing the projection vector
196 
197  /// Type representing the signed distance from the projection plane
199 
200 
201  /// Default constructor: projection on (x,y) with origin (0, 0, 0)
203  : fPlaneBase(
204  { 0.0, 0.0, 0.0 }, // origin
205  { 1.0, 0.0, 0.0 }, // x axis
206  { 0.0, 1.0, 0.0 } // y axis
207  )
208  {}
209 
210  /// Constructor: specifies a base (an origin and two direction vectors)
212 
213  /// Constructor: specifies a base (an origin and two direction vectors)
214  PlaneDecomposer(AffinePlaneBase_t const& base): fPlaneBase(base) {}
215 
216  /// @{
217  /// @name Setters
218 
219  /// Change projection base
220  void SetBase(AffinePlaneBase_t&& base) { fPlaneBase = std::move(base); }
221 
222  /// Change projection base
223  void SetBase(AffinePlaneBase_t const& base) { fPlaneBase = base; }
224 
225  /// Change the 3D point of the reference frame origin
226  void SetOrigin(Point_t const& point) { fPlaneBase.SetOrigin(point); }
227 
228  /// Change the main direction of the projection base
229  void SetMainDir(Vector_t const& dir) { fPlaneBase.SetMainDir(dir); }
230 
231  /// Change the secondary direction of the projection base
233  { fPlaneBase.SetSecondaryDir(dir); }
234 
235  /// @}
236 
237  /// @{
238  /// @name Reference point and base
239 
240  /// Returns the reference point for the plane coordinate, as a 3D point
241  Point_t ReferencePoint() const { return Base().Origin(); }
242 
243  /// Returns the plane main axis direction
244  Vector_t const& MainDir() const { return Base().MainDir(); }
245 
246  /// Returns the plane secondary axis direction
247  Vector_t const& SecondaryDir() const { return Base().SecondaryDir(); }
248 
249  /// Returns the complete base representation
250  AffinePlaneBase_t const& Base() const { return fPlaneBase; }
251 
252  /// @}
253 
254 
255  /// @{
256  /// @name Projection coordinate access
257  ///
258  /// These methods act on 2D (vector) projections.
259  ///
260 
261  /// Returns the main component of a projection vector
262  auto MainComponent(Projection_t const& v) const { return v.X(); }
263 
264  /// Returns the secondary component of a projection vector
265  auto SecondaryComponent(Projection_t const& v) const { return v.Y(); }
266 
267  /// @}
268 
269 
270  /// @{
271  /// @name Projection on plane
272 
273  /// Returns the main component of a 3D point
274  auto PointMainComponent(Point_t const& point) const
275  { return VectorMainComponent(Base().ToVector(point)); }
276 
277  /// Returns the secondary component of a 3D point
278  auto PointSecondaryComponent(Point_t const& point) const
279  { return VectorSecondaryComponent(Base().ToVector(point)); }
280 
281  /**
282  * @brief Returns the projection of the specified point on the plane
283  * @param point the 3D point to be projected, in world coordinates
284  * @return a 2D vector representing the projection of point on the plane
285  *
286  * The returned vector is a 2D vector expressing the projection of the point
287  * (from world coordinates) on the plane.
288  * The vector is expressed as @f$ ( m, s ) @f$, components following the
289  * main and the secondary direction, respectively.
290  * The origin point is the one returned by `ReferencePoint()`.
291  */
293  { return VectorProjection(Base().ToVector(point)); }
294 
295 
296  /// Returns the main component of a projection vector
297  auto VectorMainComponent(Vector_t const& v) const
298  { return geo::vect::dot(v, MainDir()); }
299 
300  /// Returns the secondary component of a projection vector
301  auto VectorSecondaryComponent(Vector_t const& v) const
302  { return geo::vect::dot(v, SecondaryDir()); }
303 
304  /**
305  * @brief Returns the projection of the specified vector on the plane
306  * @param v the 3D vector to be projected, in world units
307  * @return a 2D vector representing the projection of v on the plane
308  *
309  * The returned vector is a 2D vector expressing the projection of the
310  * vector (from world units) on the plane.
311  * The vector is expressed as @f$ ( m, s ) @f$, components following the
312  * main and the secondary direction, respectively.
313  */
315  { return { VectorMainComponent(v), VectorSecondaryComponent(v) }; }
316 
317  /**
318  * @brief Returns the angle of the projection from main direction.
319  * @param v vector to get the angle of
320  * @return the angle of the projection from main direction, in radians
321  *
322  * The projection on the plane is taken, and its angle from the main
323  * direction is returned. That angle is defined in the range
324  * @f$ \left[ -\pi, \pi \right] @f$, so that it is 0 for a projection
325  * matching the main direction and @f$ \pi/2 @f$ for one matching the
326  * secondary direction.
327  */
328  double Angle(Vector_t const& v) const
329  {
330  double const a
331  = std::atan2(VectorSecondaryComponent(v), VectorMainComponent(v));
332  return (a >= M_PI)? -M_PI: a;
333  }
334 
335  /// @}
336 
337 
338  /// @{
339  /// @name Composition from plane to 3D
340 
341  /**
342  * @brief Returns the 3D vector from the specified projection
343  * @param projection the projection vector on the plane
344  * @return the 3D vector representing the projection vector in world space
345  * @see Projection()
346  *
347  * The returned vector is the 3D representation in space of the point of
348  * the plane described by the specified projection.
349  * The null projection is composed into a null vector.
350  */
351  Vector_t ComposeVector(Projection_t const& projection) const
352  {
353  return MainComponent(projection) * MainDir()
354  + SecondaryComponent(projection) * SecondaryDir()
355  ;
356  }
357 
358  /**
359  * @brief Returns the 3D point from the specified projection
360  * @param projection the projection vector on the plane
361  * @return the 3D point representing the projection vector in world space
362  * @see Projection(), ReferencePoint()
363  *
364  * The returned point is the 3D representation in space of the point of
365  * the plane described by the specified projection.
366  * The null projection is composed into the reference point returned by
367  * ReferencePoint().
368  */
369  Point_t ComposePoint(Projection_t const& projection) const
370  { return ReferencePoint() + ComposeVector(projection); }
371 
372  /// @}
373 
374  private:
375  AffinePlaneBase_t fPlaneBase; ///< Reference base.
376 
377  }; // class PlaneDecomposer<>
378 
379 
380 
381  /** **************************************************************************
382  * @brief Class with methods to decompose and compose back vectors
383  * @tparam Vector type to represent 3D vectors
384  * @tparam Point type to represent 3D points
385  * @tparam ProjVector type to represent 2D projection on plane
386  *
387  * These methods deal with projection of points and vectors on a plane
388  * and the axis orthogonal to it.
389  */
390  template <typename Vector, typename Point, typename ProjVector>
391  class Decomposer {
392 
394 
395  PlaneDecomposer_t fPlaneDecomp; ///< Manages the projection on the plane
396 
397  /// Returns the plane decomposer
398  PlaneDecomposer_t const& Plane() const { return fPlaneDecomp; }
399 
400  public:
401  /// Type for a point
402  using Point_t = typename PlaneDecomposer_t::Point_t;
403 
404  ///< Type for a vector
406 
407  /// Type representing the projection vector
409 
410  /// Type representing the signed distance from the projection plane
412 
413  /// Type representing a decomposition on the plane
415 
416  /// Type of vector base for the space
418 
419 
420  /// Default constructor: projection on (x,y) with origin (0, 0, 0)
421  Decomposer() = default;
422 
423  /// Constructor: specifies a base (an origin and two direction vectors)
424  Decomposer(AffinePlaneBase_t&& base): fPlaneDecomp(std::move(base)) {}
425 
426  /// Constructor: specifies a base (an origin and two direction vectors)
427  Decomposer(AffinePlaneBase_t const& base): fPlaneDecomp(base) {}
428 
429  /// @{
430  /// @name Setters
431 
432  /// Change projection base
434  { fPlaneDecomp.SetBase(std::move(base)); }
435 
436  /// Change projection base
438  { fPlaneDecomp.SetBase(base); }
439 
440  /// Change the 3D point of the reference frame origin
441  void SetOrigin(Point_t const& point) { fPlaneDecomp.SetOrigin(point); }
442 
443  /// Change the main direction of the projection base
444  void SetMainDir(Vector_t const& dir) { fPlaneDecomp.SetMainDir(dir); }
445 
446  /// Change the secondary direction of the projection base
448  { fPlaneDecomp.SetSecondaryDir(dir); }
449 
450  /// @}
451 
452 
453  /// @{
454  /// @name Reference directions and point
455 
456  /// Returns the reference point for the plane coordinate, as a 3D point
457  Point_t ReferencePoint() const { return Plane().ReferencePoint(); }
458 
459  /// Returns the base of the decomposition
460  AffinePlaneBase_t const& Base() const { return Plane().Base(); }
461 
462  /// Returns the plane main axis direction
463  Vector_t const& MainDir() const { return Plane().MainDir(); }
464 
465  /// Returns the plane secondary axis direction
466  Vector_t const& SecondaryDir() const { return Plane().SecondaryDir(); }
467 
468  /// Returns the plane normal axis direction
469  Vector_t const& NormalDir() const { return Base().NormalDir(); }
470 
471  /// @}
472 
473 
474  /// @{
475  /// @name Decomposition of a 3D point
476 
477  /// Returns the main component of a point
478  auto PointMainComponent(Point_t const& point) const
479  { return VectorMainComponent(Base().ToVector(point)); }
480 
481  /// Returns the secondary component of a point
482  auto PointSecondaryComponent(Point_t const& point) const
483  { return VectorSecondaryComponent(Base().ToVector(point)); }
484 
485  /// Returns the secondary component of a point
486  auto PointNormalComponent(Point_t const& point) const
487  { return VectorNormalComponent(Base().ToVector(point)); }
488 
489  /**
490  * @brief Returns the projection of the specified point on the plane
491  * @param point the 3D point to be projected, in world coordinates
492  * @return a 2D vector representing the projection of point on the plane
493  *
494  * The returned vector is a 2D vector expressing the projection of the point
495  * (from world coordinates) on the plane.
496  * The vector is expressed as @f$ ( m, s ) @f$, components following the
497  * main direction (`MainDir()`) and the secondary one (`SecondaryDir()`)
498  * respectively. The origin point is the one from ReferencePoint().
499  */
501  { return Plane().PointProjection(point); }
502 
503  /**
504  * @brief Decomposes a 3D point in two components
505  * @param point the point to be decomposed
506  * @return the two components of point, on the plane and orthogonal to it
507  *
508  * The point is decomposed in:
509  *
510  * 1. a component orthogonal to the plane, expressed as a signed real number
511  * 2. a component lying on the plane, expressed as a 2D vector
512  *
513  * The distance is obtained as by PointNormalComponent().
514  * The projection on the plane is obtained following the same convention
515  * as ProjectPointOnPlane().
516  */
518  { return DecomposeVector(Base().ToVector(point)); }
519 
520  /// @}
521 
522 
523  /// @{
524  /// @name Decomposition of a 3D vector
525 
526  /// Returns the main component of a vector
527  auto VectorMainComponent(Vector_t const& v) const
528  { return Plane().VectorMainComponent(v); }
529 
530  /// Returns the secondary component of a vector
531  auto VectorSecondaryComponent(Vector_t const& v) const
532  { return Plane().VectorSecondaryComponent(v); }
533 
534  /// Returns the secondary component of a vector
535  auto VectorNormalComponent(Vector_t const& v) const
536  { return geo::vect::dot(v, NormalDir()); }
537 
538  /**
539  * @brief Returns the projection of the specified vector on the plane
540  * @param v the 3D vector to be projected, in world units
541  * @return a 2D vector representing the projection of v on the plane
542  *
543  * The returned vector is a 2D vector expressing the projection of the
544  * vector (from world units) on the wire plane.
545  * The vector is expressed as @f$ ( m, s ) @f$, components following the
546  * main direction (`MainDir()`) and the secondary one (`SecondaryDir()`)
547  * respectively.
548  */
550  { return Plane().VectorProjection(v); }
551 
552  /**
553  * @brief Decomposes a 3D vector in two components
554  * @param v the vector to be decomposed
555  * @return the two components of vector, on the plane and orthogonal to it
556  *
557  * The vector is decomposed in:
558  *
559  * 1. a component orthogonal to the plane, expressed as a signed real number
560  * 2. a component lying on the plane, expressed as a 2D vector
561  *
562  * The distance is obtained as by VectorNormalComponent().
563  * The projection on the plane is obtained following the same convention
564  * as ProjectVectorOnPlane().
565  */
567  { return { VectorNormalComponent(v), ProjectVectorOnPlane(v) }; }
568 
569  /**
570  * @brief Returns the angle of the projection from main direction.
571  * @param v vector to get the angle of
572  * @return the angle of the projection from main direction, in radians
573  *
574  * The projection on the plane is taken, and its angle from the main
575  * direction is returned. That angle is defined in the range
576  * @f$ \left[ -\pi, \pi \right] @f$, so that it is 0 for a projection
577  * matching the main direction and @f$ \pi/2 @f$ for one matching the
578  * secondary direction.
579  */
580  double Angle(Vector_t const& v) const
581  { return Plane().Angle(v); }
582 
583  /// @}
584 
585 
586  /// @{
587  /// @name Decomposition of a projection vector
588 
589  /// Returns the main component of a projection vector
590  auto MainComponent(Projection_t const& v) const
591  { return Plane().MainComponent(v); }
592 
593  /// Returns the secondary component of a projection vector
594  auto SecondaryComponent(Projection_t const& v) const
595  { return Plane().SecondaryComponent(v); }
596 
597  /// @}
598 
599 
600  /// @{
601  /// @name Composition of a point
602 
603  /**
604  * @brief Returns the 3D point from composition of projection and distance
605  * @param decomp decomposed point
606  * @return the 3D point from composition of projection and distance
607  * @see DecomposePoint(), ComposePoint(double, Projection_t const&)
608  *
609  * See `ComposePoint(double, Projection_t const&)` for details.
610  */
612  { return ComposePoint(decomp.distance, decomp.projection); }
613 
614  /**
615  * @brief Returns the 3D point from composition of projection and distance
616  * @param distance distance of the target point from the wire plane
617  * @param proj projection of the target point on the wire plane
618  * @return the 3D point from composition of projection and distance
619  * @see DecomposePoint()
620  *
621  * The returned point is the sum of two 3D contributions:
622  *
623  * 1. a vector parallel to the plane normal, with norm the input distance
624  * 2. a vector lying on the plane, whose projection via
625  * `ProjectPointOnPlane()` gives the input projection
626  *
627  * Given the arbitrary definition of the projection reference, it is assumed
628  * that the same convention is used as in ProjectPointOnPlane() and
629  * PointNormalComponent().
630  *
631  */
632  Point_t ComposePoint(double distance, Projection_t const& proj) const
633  { return ReferencePoint() + ComposeVector(distance, proj); }
634 
635  /// @}
636 
637  /// @{
638  /// @name Composition of a vector
639 
640  /**
641  * @brief Returns the 3D vector from composition of projection and distance
642  * @param decomp decomposed vector
643  * @return the 3D vector from composition of projection and distance
644  * @see DecomposeVector(), ComposeVector(double, Projection_t const&)
645  *
646  * See `ComposeVector(double, Projection_t const&)` for details.
647  */
649  { return ComposeVector(decomp.distance, decomp.projection); }
650 
651  /**
652  * @brief Returns the 3D vector from composition of projection and distance
653  * @param distance distance of the target point from the wire plane
654  * @param proj projection of the target point on the wire plane
655  * @return the 3D vector from composition of projection and distance
656  * @see DecomposeVector()
657  *
658  * The returned vector is the sum of two 3D vectors:
659  *
660  * 1. a vector parallel to the plane normal, with norm the input distance
661  * 2. a vector lying on the plane, whose projection via
662  * `ProjectVectorOnPlane()` gives the input projection
663  *
664  * Given the arbitrary definition of the projection reference, it is assumed
665  * that the same convention is used as in ProjectVectorOnPlane() and
666  * VectorNormalComponent().
667  *
668  */
669  Vector_t ComposeVector(double distance, Projection_t const& proj) const
670  { return Plane().ComposeVector(proj) + distance * NormalDir(); }
671 
672  /// @}
673 
674 
675  }; // class Decomposer<>
676 
677  /// @}
678  // --- END Decomposition objects ---------------------------------------------
679 
680 } // namespace geo
681 
682 
683 #endif // LARCOREALG_GEOMETRY_DECOMPOSER_H
Point_t ComposePoint(DecomposedVector_t const &decomp) const
Returns the 3D point from composition of projection and distance.
Definition: Decomposer.h:611
void SetBase(AffinePlaneBase_t const &base)
Change projection base.
Definition: Decomposer.h:223
Utilities to extend the interface of geometry vectors.
auto VectorSecondaryComponent(Vector_t const &v) const
Returns the secondary component of a vector.
Definition: Decomposer.h:531
Vector_t fSecondary
Secondary axis on the plane.
Definition: Decomposer.h:76
Projection_t projection
Projection of the vector on the plane.
Definition: Decomposer.h:151
typename PlaneDecomposer_t::Distance_t Distance_t
Type representing the signed distance from the projection plane.
Definition: Decomposer.h:411
vector< T > Vector
constexpr auto dot(Vector const &a, Vector const &b)
Return cross product of two vectors.
Distance_t distance
Distance of the vector from the plane.
Definition: Decomposer.h:152
auto PointNormalComponent(Point_t const &point) const
Returns the secondary component of a point.
Definition: Decomposer.h:486
Point_t ComposePoint(double distance, Projection_t const &proj) const
Returns the 3D point from composition of projection and distance.
Definition: Decomposer.h:632
Vector_t fNormal
Axis normal to the plane.
Definition: Decomposer.h:77
void SetSecondaryDir(Vector_t const &dir)
Change the secondary direction of the projection base.
Definition: Decomposer.h:447
Vector_t const & SecondaryDir() const
Returns the secondary axis direction.
Definition: Decomposer.h:111
auto VectorMainComponent(Vector_t const &v) const
Returns the main component of a projection vector.
Definition: Decomposer.h:297
Vector_t const & NormalDir() const
Returns the plane normal axis direction.
Definition: Decomposer.h:469
PlaneBase(Vector_t const &main, Vector_t const &secondary)
Constructor: assigns the axes.
Definition: Decomposer.h:47
void SetMainDir(Vector_t const &dir)
Change the main direction of the projection base.
Definition: Decomposer.h:229
Vector_t ToVector(Point_t const &point) const
Returns the vector representing the specified point in the affine space.
Definition: Decomposer.h:120
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >> Point_t
auto SecondaryComponent(Projection_t const &v) const
Returns the secondary component of a projection vector.
Definition: Decomposer.h:265
Vector_t const & NormalDir() const
Returns the axis normal to the plane.
Definition: Decomposer.h:60
Point_t fOrigin
Origin of the coordinate system.
Definition: Decomposer.h:134
PlaneBase_t fBase
Base.
Definition: Decomposer.h:135
Vector_t ComposeVector(DecomposedVector_t const &decomp) const
Returns the 3D vector from composition of projection and distance.
Definition: Decomposer.h:648
void SetSecondaryDir(Vector_t const &dir)
Change the secondary direction of the projection base.
Definition: Decomposer.h:232
auto PointMainComponent(Point_t const &point) const
Returns the main component of a point.
Definition: Decomposer.h:478
Point_t Origin() const
Returns the origin of the coordinate system in world coordinates.
Definition: Decomposer.h:117
Class with methods to decompose and compose back vectors.
Definition: Decomposer.h:391
DecomposedVector_t DecomposeVector(Vector_t const &v) const
Decomposes a 3D vector in two components.
Definition: Decomposer.h:566
STL namespace.
Vector_t const & MainDir() const
Returns the plane main axis direction.
Definition: Decomposer.h:244
Projection_t VectorProjection(Vector_t const &v) const
Returns the projection of the specified vector on the plane.
Definition: Decomposer.h:314
string dir
typename AffinePlaneBase_t::Point_t Point_t
Type for a point.
Definition: Decomposer.h:189
Vector_t const & MainDir() const
Returns the main axis direction.
Definition: Decomposer.h:54
void SetBase(AffinePlaneBase_t &&base)
Change projection base.
Definition: Decomposer.h:433
PlaneDecomposer(AffinePlaneBase_t &&base)
Constructor: specifies a base (an origin and two direction vectors)
Definition: Decomposer.h:211
DecomposedVector(Distance_t distance, Projection_t const &projection)
Definition: Decomposer.h:160
auto VectorNormalComponent(Vector_t const &v) const
Returns the secondary component of a vector.
Definition: Decomposer.h:535
Projection_t PointProjection(Point_t const &point) const
Returns the projection of the specified point on the plane.
Definition: Decomposer.h:292
static Vector_t PastorizeUnitVector(Vector_t dir)
Normalizes and rounds a direction vector.
Definition: Decomposer.h:71
Projection_t ProjectPointOnPlane(Point_t const &point) const
Returns the projection of the specified point on the plane.
Definition: Decomposer.h:500
PlaneDecomposer_t const & Plane() const
Returns the plane decomposer.
Definition: Decomposer.h:398
void SetOrigin(Point_t const &point)
Change the 3D point of the reference frame origin.
Definition: Decomposer.h:124
typename PlaneDecomposer_t::Projection_t Projection_t
Type representing the projection vector.
Definition: Decomposer.h:408
typename PlaneBase_t::Vector_t Vector_t
Vector in space.
Definition: Decomposer.h:97
Vector_t ComposeVector(double distance, Projection_t const &proj) const
Returns the 3D vector from composition of projection and distance.
Definition: Decomposer.h:669
auto MainComponent(Projection_t const &v) const
Returns the main component of a projection vector.
Definition: Decomposer.h:262
const double e
auto SecondaryComponent(Projection_t const &v) const
Returns the secondary component of a projection vector.
Definition: Decomposer.h:594
AffinePlaneBase_t const & Base() const
Returns the complete base representation.
Definition: Decomposer.h:250
auto PointSecondaryComponent(Point_t const &point) const
Returns the secondary component of a 3D point.
Definition: Decomposer.h:278
Decomposer(AffinePlaneBase_t &&base)
Constructor: specifies a base (an origin and two direction vectors)
Definition: Decomposer.h:424
typename PlaneDecomposer_t::AffinePlaneBase_t AffinePlaneBase_t
Type of vector base for the space.
Definition: Decomposer.h:417
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
Definition: DCEL.h:44
const double a
AffinePlaneBase_t const & Base() const
Returns the base of the decomposition.
Definition: Decomposer.h:460
def move(depos, offset)
Definition: depos.py:107
PlaneDecomposer()
Default constructor: projection on (x,y) with origin (0, 0, 0)
Definition: Decomposer.h:202
auto MainComponent(Projection_t const &v) const
Returns the main component of a projection vector.
Definition: Decomposer.h:590
DecomposedVector(Projection_t const &projection, Distance_t distance)
Definition: Decomposer.h:157
decltype(geo::vect::mag2(std::declval< Projection_t >())) Distance_t
Type for distance from plane.
Definition: Decomposer.h:148
DecomposedVector_t DecomposePoint(Point_t const &point) const
Decomposes a 3D point in two components.
Definition: Decomposer.h:517
double Angle(Vector_t const &v) const
Returns the angle of the projection from main direction.
Definition: Decomposer.h:328
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
void SetBase(AffinePlaneBase_t const &base)
Change projection base.
Definition: Decomposer.h:437
void SetOrigin(Point_t const &point)
Change the 3D point of the reference frame origin.
Definition: Decomposer.h:226
Vector_t ComposeVector(Projection_t const &projection) const
Returns the 3D vector from the specified projection.
Definition: Decomposer.h:351
void ResetNormal()
Reset normal to the plane.
Definition: Decomposer.h:84
double Angle(Vector_t const &v) const
Returns the angle of the projection from main direction.
Definition: Decomposer.h:580
typename DecomposedVector_t::Projection_t Projection_t
Type representing the projection vector.
Definition: Decomposer.h:195
Point_t ReferencePoint() const
Returns the reference point for the plane coordinate, as a 3D point.
Definition: Decomposer.h:457
Vector rounded01(Vector const &v, Scalar tol)
Returns a vector with all components rounded if close to 0, -1 or +1.
auto mag2(Vector const &v)
Return norm of the specified vector.
typename PlaneDecomposer_t::DecomposedVector_t DecomposedVector_t
Type representing a decomposition on the plane.
Definition: Decomposer.h:414
typename AffinePlaneBase_t::Vector_t Vector_t
Type for a vector.
Definition: Decomposer.h:192
#define M_PI
Definition: includeROOT.h:54
auto VectorMainComponent(Vector_t const &v) const
Returns the main component of a vector.
Definition: Decomposer.h:527
void SetOrigin(Point_t const &point)
Change the 3D point of the reference frame origin.
Definition: Decomposer.h:441
Vector_t const & SecondaryDir() const
Returns the plane secondary axis direction.
Definition: Decomposer.h:466
Vector_t const & MainDir() const
Returns the plane main axis direction.
Definition: Decomposer.h:463
PlaneDecomposer_t fPlaneDecomp
Manages the projection on the plane.
Definition: Decomposer.h:395
void SetBase(AffinePlaneBase_t &&base)
Change projection base.
Definition: Decomposer.h:220
auto PointSecondaryComponent(Point_t const &point) const
Returns the secondary component of a point.
Definition: Decomposer.h:482
Projection_t ProjectVectorOnPlane(Vector_t const &v) const
Returns the projection of the specified vector on the plane.
Definition: Decomposer.h:549
auto VectorSecondaryComponent(Vector_t const &v) const
Returns the secondary component of a projection vector.
Definition: Decomposer.h:301
Class with methods for projection of vectors on a plane.
Definition: Decomposer.h:179
Point_t ReferencePoint() const
Returns the reference point for the plane coordinate, as a 3D point.
Definition: Decomposer.h:241
static constexpr double RoundingTol
Rounding threshold for vectors.
Definition: Decomposer.h:44
geo::Vector_t Vector_t
Type for the vector in space.
Definition: Decomposer.h:41
AffinePlaneBase_t fPlaneBase
Reference base.
Definition: Decomposer.h:375
auto PointMainComponent(Point_t const &point) const
Returns the main component of a 3D point.
Definition: Decomposer.h:274
void SetMainDir(Vector_t const &dir)
Change the main direction of the projection base.
Definition: Decomposer.h:127
A base for a plane in space.
Definition: Decomposer.h:39
Point_t ComposePoint(Projection_t const &projection) const
Returns the 3D point from the specified projection.
Definition: Decomposer.h:369
ProjVector Projection_t
Type for 2D projection.
Definition: Decomposer.h:145
Vector_t ComputeNormal() const
Computes the normal to the plane.
Definition: Decomposer.h:80
Vector_t const & NormalDir() const
Returns the secondary axis direction.
Definition: Decomposer.h:114
PlaneDecomposer(AffinePlaneBase_t const &base)
Constructor: specifies a base (an origin and two direction vectors)
Definition: Decomposer.h:214
Vector normalize(Vector const &v)
Returns a vector parallel to v and with norm 1.
void SetSecondaryDir(Vector_t const &dir)
Change the secondary direction of the projection base.
Definition: Decomposer.h:66
recob::tracking::Plane Plane
Definition: TrackState.h:17
typename PlaneDecomposer_t::Point_t Point_t
Type for a vector.
Definition: Decomposer.h:404
Vector_t const & SecondaryDir() const
Returns the secondary axis direction.
Definition: Decomposer.h:57
LArSoft geometry interface.
Definition: ChannelGeo.h:16
Vector_t fMain
Main axis on the plane.
Definition: Decomposer.h:75
recob::tracking::Vector_t Vector_t
Vector_t const & MainDir() const
Returns the main axis direction.
Definition: Decomposer.h:108
Vector_t const & SecondaryDir() const
Returns the plane secondary axis direction.
Definition: Decomposer.h:247
constexpr Point origin()
Returns a origin position with a point of the specified type.
Definition: geo_vectors.h:227
typename PlaneDecomposer_t::Vector_t Vector_t
Definition: Decomposer.h:405
Decomposer(AffinePlaneBase_t const &base)
Constructor: specifies a base (an origin and two direction vectors)
Definition: Decomposer.h:427
void SetSecondaryDir(Vector_t const &dir)
Change the secondary direction of the projection base.
Definition: Decomposer.h:130
typename DecomposedVector_t::Distance_t Distance_t
Type representing the signed distance from the projection plane.
Definition: Decomposer.h:198
void SetMainDir(Vector_t const &dir)
Change the main direction of the projection base.
Definition: Decomposer.h:63
void SetMainDir(Vector_t const &dir)
Change the main direction of the projection base.
Definition: Decomposer.h:444