DCEL.h
Go to the documentation of this file.
1 /**
2  * @file DCEL2D.h
3  *
4  * @brief Definitions for a doubly connected edge list
5  * This will define a vertex, half edge and face
6  *
7  * @author usher@slac.stanford.edu
8  *
9  */
10 #ifndef DCEL2D_h
11 #define DCEL2D_h
12 
13 // std includes
14 #include <vector>
15 #include <list>
16 #include <algorithm>
17 
18 // Eigen
19 #ifdef __clang__
20 #else
21 #pragma GCC diagnostic push
22 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
23 #endif
24 #include <Eigen/Dense>
25 #ifdef __clang__
26 #else
27 #pragma GCC diagnostic pop
28 #endif
29 
30 //------------------------------------------------------------------------------------------------------------------------------------------
31 
32 namespace reco
33 {
34  class ClusterHit3D;
35 }
36 
37 namespace dcel2d
38 {
39 class HalfEdge; // Forward declaration
40 
41 /**
42  * @brief Definitions used by the VoronoiDiagram algorithm
43  */
44 using Point = std::tuple<double,double,const reco::ClusterHit3D*>;
45 using PointList = std::list<Point>;
46 using Coords = Eigen::Vector3f; //std::pair<double,double>;
47 
48 class Vertex
49 {
50  /**
51  * @brief Vertex class definition for use in a doubly connected edge list
52  * a Vertex will contain the coordinates of the point it represents
53  * and a pointer to one of the half edges that emanates from it
54  */
55 public:
56  /**
57  * @brief Constructor
58  */
59  Vertex() : fCoords(0.,0.,0.), fHalfEdge(NULL) {}
60 
61  Vertex(const double* coords, HalfEdge* half) : fHalfEdge(half)
62  {
63  setCoords(coords);
64  }
65 
66  Vertex(const Coords& coords, HalfEdge* half) : fCoords(coords), fHalfEdge(half)
67  {}
68 
69  const Coords& getCoords() const {return fCoords;}
70  const HalfEdge* getHalfEdge() const {return fHalfEdge;}
71 
72  void setCoords(const double* coords)
73  {
74  fCoords[0] = coords[0];
75  fCoords[1] = coords[1];
76  fCoords[2] = coords[2];
77  }
78 
79  void setCoords(const Coords& coords) {fCoords = coords;}
80 
81  void setHalfEdge(HalfEdge* half) {fHalfEdge = half;}
82 
83 private:
84  Coords fCoords; // x,y coordinates of this vertex
85  HalfEdge* fHalfEdge; // pointer to one of the half edges
86 };
87 
88 class Face
89 {
90  /**
91  * @brief Face class definition for use in a doubly connected edge list
92  * A Face represents the area enclosed by a set of half edges and
93  * vertices. It simply needs to store a pointer to one of the half
94  * edges to be able to recover all
95  */
96 public:
97  /**
98  * @brief Constructor
99  */
100 // Face() : fHalfEdge(NULL), fPoint(0.,0.,NULL) {}
101 
102  Face(HalfEdge* half, const Coords& coords, const reco::ClusterHit3D* clusterHit3D) :
103  fHalfEdge(half),
104  fConvexHull(false),
105  fCoords(coords),
106  fFaceArea(0.),
107  fClusterHit3D(clusterHit3D)
108  {}
109 
110  const HalfEdge* getHalfEdge() const {return fHalfEdge;}
111  const bool onConvexHull() const {return fConvexHull;}
112  const Coords& getCoords() const {return fCoords;}
113  const double getFaceArea() const {return fFaceArea;}
114  const reco::ClusterHit3D* getClusterHit3D() const {return fClusterHit3D;}
115 
116  void setHalfEdge(HalfEdge* half) {fHalfEdge = half;}
117  void setOnConvexHull() {fConvexHull = true;}
118  void setFaceArea(double area) {fFaceArea = area;}
119 
120 private:
121  HalfEdge* fHalfEdge; // pointer to one of the half edges
122  mutable bool fConvexHull; // This face on convex hull
123  Coords fCoords; // projected coordinates of associated point
124  double fFaceArea; // The area of the face once constructed
125  const reco::ClusterHit3D* fClusterHit3D; // The physical 3D hit this corresponds to
126 };
127 
128 class HalfEdge
129 {
130  /**
131  * @brief HalfEdge class definition for use in a doubly connected edge list
132  * The half edge class represents one connection from the vertex it
133  * emanates from and pointing to the next vertex. It is the workhorse
134  * of the doubly connected edge list and contains all necessary
135  * pointers to enable completely traverse of the list.
136  */
137 public:
138  /**
139  * @brief Constructor
140  */
142  m_targetVertex(NULL),
143  m_face(NULL),
144  m_twinHalfEdge(NULL),
145  m_nextHalfEdge(NULL),
146  m_lastHalfEdge(NULL)
147  {}
148 
150  Face* face,
151  HalfEdge* twin,
152  HalfEdge* next,
153  HalfEdge* last) :
154  m_targetVertex(vertex),
155  m_face(face),
156  m_twinHalfEdge(twin),
157  m_nextHalfEdge(next),
158  m_lastHalfEdge(last)
159  {}
160 
161  Vertex* getTargetVertex() const {return m_targetVertex;}
162  Face* getFace() const {return m_face;}
163  HalfEdge* getTwinHalfEdge() const {return m_twinHalfEdge;}
164  HalfEdge* getNextHalfEdge() const {return m_nextHalfEdge;}
165  HalfEdge* getLastHalfEdge() const {return m_lastHalfEdge;}
166 
167  void setTargetVertex(Vertex* vertex) {m_targetVertex = vertex;}
168  void setFace(Face* face) {m_face = face;}
169  void setTwinHalfEdge(HalfEdge* twin) {m_twinHalfEdge = twin;}
170  void setNextHalfEdge(HalfEdge* next) {m_nextHalfEdge = next;}
171  void setLastHalfEdge(HalfEdge* last) {m_lastHalfEdge = last;}
172 
173 private:
174  Vertex* m_targetVertex; // Pointer to the vertex we point to
175  Face* m_face; // Pointer to the face we are associated with
176  HalfEdge* m_twinHalfEdge; // Pointer to the twin half edge (pointing opposite)
177  HalfEdge* m_nextHalfEdge; // Pointer ot the next half edge
178  HalfEdge* m_lastHalfEdge; // Pointer to the previous half edge
179 };
180 
181 // Define containers to hold the above objects
182 using VertexList = std::list<Vertex>;
183 using FaceList = std::list<Face>;
184 using HalfEdgeList = std::list<HalfEdge>;
185 
186 } // namespace lar_cluster3d
187 #endif
void setFaceArea(double area)
Definition: DCEL.h:118
const reco::ClusterHit3D * getClusterHit3D() const
Definition: DCEL.h:114
Vertex()
Vertex class definition for use in a doubly connected edge list a Vertex will contain the coordinates...
Definition: DCEL.h:59
HalfEdge * getLastHalfEdge() const
Definition: DCEL.h:165
void setCoords(const Coords &coords)
Definition: DCEL.h:79
HalfEdge * getNextHalfEdge() const
Definition: DCEL.h:164
std::list< HalfEdge > HalfEdgeList
Definition: DCEL.h:184
void setHalfEdge(HalfEdge *half)
Definition: DCEL.h:81
const bool onConvexHull() const
Definition: DCEL.h:111
Face(HalfEdge *half, const Coords &coords, const reco::ClusterHit3D *clusterHit3D)
Face class definition for use in a doubly connected edge list A Face represents the area enclosed by ...
Definition: DCEL.h:102
HalfEdge * getTwinHalfEdge() const
Definition: DCEL.h:163
Face * getFace() const
Definition: DCEL.h:162
HalfEdge * fHalfEdge
Definition: DCEL.h:121
HalfEdge * m_lastHalfEdge
Definition: DCEL.h:178
HalfEdge * m_nextHalfEdge
Definition: DCEL.h:177
Vertex(const double *coords, HalfEdge *half)
Definition: DCEL.h:61
double fFaceArea
Definition: DCEL.h:124
Vertex(const Coords &coords, HalfEdge *half)
Definition: DCEL.h:66
Vertex * m_targetVertex
Definition: DCEL.h:174
Coords fCoords
Definition: DCEL.h:84
void setLastHalfEdge(HalfEdge *last)
Definition: DCEL.h:171
void setTwinHalfEdge(HalfEdge *twin)
Definition: DCEL.h:169
HalfEdge()
HalfEdge class definition for use in a doubly connected edge list The half edge class represents one ...
Definition: DCEL.h:141
std::list< Face > FaceList
Definition: DCEL.h:183
HalfEdge * fHalfEdge
Definition: DCEL.h:85
Coords fCoords
Definition: DCEL.h:123
const Coords & getCoords() const
Definition: DCEL.h:112
void setFace(Face *face)
Definition: DCEL.h:168
bool fConvexHull
Definition: DCEL.h:122
const HalfEdge * getHalfEdge() const
Definition: DCEL.h:110
void setNextHalfEdge(HalfEdge *next)
Definition: DCEL.h:170
void setCoords(const double *coords)
Definition: DCEL.h:72
HalfEdge(Vertex *vertex, Face *face, HalfEdge *twin, HalfEdge *next, HalfEdge *last)
Definition: DCEL.h:149
void setHalfEdge(HalfEdge *half)
Definition: DCEL.h:116
Face * m_face
Definition: DCEL.h:175
HalfEdge * m_twinHalfEdge
Definition: DCEL.h:176
std::list< Point > PointList
Definition: DCEL.h:45
Vertex * getTargetVertex() const
Definition: DCEL.h:161
Eigen::Vector3f Coords
Definition: DCEL.h:46
void setOnConvexHull()
Definition: DCEL.h:117
const HalfEdge * getHalfEdge() const
Definition: DCEL.h:70
const double getFaceArea() const
Definition: DCEL.h:113
const Coords & getCoords() const
Definition: DCEL.h:69
const reco::ClusterHit3D * fClusterHit3D
Definition: DCEL.h:125
std::list< Vertex > VertexList
Definition: DCEL.h:182
void setTargetVertex(Vertex *vertex)
Definition: DCEL.h:167
vertex reconstruction