Point.h
Go to the documentation of this file.
1 #ifndef WIRECELLUTIL_POINT_H
2 #define WIRECELLUTIL_POINT_H
3 
6 
7 #include <set>
8 #include <memory> // auto_ptr
9 #include <vector>
10 
11 namespace WireCell {
12 
13  /// A 3D Cartesian point in double precision.
14 
16 
17  /// An alias for Point.
18  typedef Point Vector;
19 
20  /// A line segment running from a first (tail) to a second (head) point.
21  typedef std::pair<Point, Point> Ray;
22 
23  // Pair of rays.
24  typedef std::pair<Ray,Ray> ray_pair_t;
25 
26  // A collection of ray pairs;
27  typedef std::vector<ray_pair_t> ray_pair_vector_t;
28 
29  /// PointVector - a collection of Points
30  typedef std::vector<Point> PointVector;
31 
32  /// A scalar + vector, eg charge at a point.
33  typedef std::pair<double, Vector> ScalarPoint;
34  typedef std::vector<ScalarPoint> ScalarField;
35 
36  /// PointValue - an association of a point and a value
37  typedef std::pair<Point, float> PointValue;
38 
39  /// PointValueVector - a collection of point-value associations
40  typedef std::vector<PointValue> PointValueVector;
41 
42  /// Return true if lhs<rhs w/in tolerance.
43  struct ComparePoints {
44  bool operator()(const Point& lhs, const Point& rhs) const;
45  };
46  typedef std::set<Point, ComparePoints> PointSet;
47 
48  /// PointF - a 3D Cartesian point in single precision for when
49  /// memory is constrained and double precision is not required.
51 
52 
53  /** Return true if point is contained in a rectangular solid
54  * described by the ray bounds running between diagonally opposed
55  * corners.*/
56  bool point_contained(const Point& point, const Ray& bounds);
57 
58  /** Return true if point is contained by the bounding box along
59  * the given axis (x=0, y=1, z=2) of the bounding box. */
60  bool point_contained(const Point& point, const Ray& bounds, int axis);
61 
62  /** Return the angle from axis vector to vector. This is just
63  * acos(dot).*/
64  double point_angle(const Vector& axis, const Vector& vector);
65 
66  /** Return a ray representing the points of closest approach
67  * between the two lines colinear with the two rays. */
68  Ray ray_pitch(const Ray& ray1, const Ray& ray2);
69 
70  /** Return the distance from the tail to the head of the ray. */
71  double ray_length(const Ray& ray);
72 
73  /** Return a vector going from ray's tail to ray's head. */
74  Vector ray_vector(const Ray& ray);
75 
76  /** Return a unit vector pointing in the direction from the tail
77  * to the head of the ray. */
78  Vector ray_unit(const Ray& ray);
79 
80  /** Return the distance from the tail of the ray to the point
81  * projected onto the ray's direction. */
82  double ray_dist(const Ray& ray, const Point& point);
83 
84  /** Return the volume of a box aligned with axes and with the ray
85  * at opposite corners. */
86  double ray_volume(const Ray& ray);
87 
88 
89  template<>
90  inline // fixme: ignores default
92  return Point(get<double>(cfg,"x"), get<double>(cfg,"y"), get<double>(cfg,"z"));
93  }
94  template<>
95  inline // fixme: ignores default
97  return Ray(get<WireCell::Point>(cfg,"tail"), get<WireCell::Point>(cfg,"head"));
98  }
99 
100 
101  //std::ostream& operator<<(std::ostream& os, const WireCell::Ray& ray);
102  inline
103  std::ostream& operator<<(std::ostream& os, const WireCell::Ray& ray)
104  {
105  os << "[" << ray.first << " --> " << ray.second << "]";
106  return os;
107  }
108 
109  inline
111  return WireCell::Ray(ray.first/scale, ray.second/scale);
112  }
113 
114 }//namespace WireCell
115 
116 // inline
117 // WireCell::Ray operator*(WireCell::Ray ray, const double& scale) {
118 // return WireCell::Ray(ray.first*scale, ray.second*scale);
119 // }
120 // inline
121 // WireCell::Ray operator*(double scale, const WireCell::Ray& ray) {
122 // return WireCell::Ray(ray.first*scale, ray.second*scale);
123 // }
124 
125 
126 #endif
127 
std::pair< Point, Point > Ray
A line segment running from a first (tail) to a second (head) point.
Definition: Point.h:21
D3Vector< double > Point
A 3D Cartesian point in double precision.
Definition: Point.h:15
bool operator()(const Point &lhs, const Point &rhs) const
Definition: Point.cxx:24
std::pair< double, Vector > ScalarPoint
A scalar + vector, eg charge at a point.
Definition: Point.h:33
std::pair< Point, float > PointValue
PointValue - an association of a point and a value.
Definition: Point.h:37
std::vector< PointValue > PointValueVector
PointValueVector - a collection of point-value associations.
Definition: Point.h:40
cfg
Definition: dbjson.py:29
Return true if lhs<rhs w/in tolerance.
Definition: Point.h:43
double ray_dist(const Ray &ray, const Point &point)
Definition: Point.cxx:95
WireCell::Point convert< WireCell::Point >(const Configuration &cfg, const WireCell::Point &def)
Definition: Point.h:91
double ray_volume(const Ray &ray)
Definition: Point.cxx:101
std::vector< ScalarPoint > ScalarField
Definition: Point.h:34
double ray_length(const Ray &ray)
Definition: Point.cxx:62
std::set< Point, ComparePoints > PointSet
Definition: Point.h:46
Vector ray_unit(const Ray &ray)
Definition: Point.cxx:71
Point Vector
An alias for Point.
Definition: Point.h:18
BoundingBox bounds(int x, int y, int w, int h)
Definition: main.cpp:37
D3Vector< T > operator/(const D3Vector< T > a, T s)
Definition: D3Vector.h:165
std::vector< ray_pair_t > ray_pair_vector_t
Definition: Point.h:27
std::vector< Point > PointVector
PointVector - a collection of Points.
Definition: Point.h:30
Definition: Main.h:22
Ray ray_pitch(const Ray &ray1, const Ray &ray2)
Definition: Point.cxx:76
void scale(Sequence< Val > &seq, Val scalar)
Scale (multiply) sequence values by scalar.
Definition: Waveform.h:146
std::ostream & operator<<(std::ostream &os, const WireCell::WirePlaneId &wpid)
Definition: WirePlaneId.cxx:83
Json::Value Configuration
Definition: Configuration.h:50
double point_angle(const Vector &axis, const Vector &vector)
Definition: Point.cxx:57
bool point_contained(const Point &point, const Ray &bounds)
Definition: Point.cxx:40
WireCell::Ray convert< WireCell::Ray >(const Configuration &cfg, const WireCell::Ray &def)
Definition: Point.h:96
Vector ray_vector(const Ray &ray)
Definition: Point.cxx:67
std::pair< Ray, Ray > ray_pair_t
Definition: Point.h:24
D3Vector< float > PointF
Definition: Point.h:50