LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
Voronoi.h
Go to the documentation of this file.
1 
9 #ifndef VoronoiDiagram_h
10 #define VoronoiDiagram_h
11 
12 // std includes
13 #include <list>
14 #include <algorithm>
15 #include <queue>
16 
17 // LArSoft includes
21 
22 #include <boost/polygon/voronoi.hpp>
23 
24 // Algorithm includes
26 //------------------------------------------------------------------------------------------------------------------------------------------
27 
28 namespace voronoi2d
29 {
34 {
35 public:
36  using PointPair = std::pair<dcel2d::Point,dcel2d::Point>;
37  using MinMaxPointPair = std::pair<PointPair,PointPair>;
38 
45 
49  virtual ~VoronoiDiagram();
50 
57 
59 
63  const dcel2d::FaceList& getFaceList() const {return fFaceList;}
64 
68  const dcel2d::VertexList& getVertexList() const {return fVertexList;}
69 
73  double getVoronoiDiagramArea() const {return fVoronoiDiagramArea;}
74 
79 
84 
88  PointPair findNearestEdge(const dcel2d::Point&, double&) const;
89 
93  double findNearestDistance(const dcel2d::Point&) const;
94 
95 private:
96 
97  using EventQueue = std::priority_queue<IEvent*, std::vector<IEvent*>, bool(*)(const IEvent*,const IEvent*)>;
98 
102  void handleSiteEvents(BeachLine&, EventQueue&, IEvent*);
103 
107  void handleCircleEvents(BeachLine&, EventQueue&, IEvent*);
108 
109  void makeLeftCircleEvent(EventQueue&, BSTNode*, double);
110  void makeRightCircleEvent(EventQueue&, BSTNode*, double);
111 
115  IEvent* makeCircleEvent(BSTNode*, BSTNode*, BSTNode*, double);
116 
117  bool computeCircleCenter(const dcel2d::Coords&, const dcel2d::Coords&, const dcel2d::Coords&, dcel2d::Coords&, double&, double&) const;
118 
119  bool computeCircleCenter2(const dcel2d::Coords&, const dcel2d::Coords&, const dcel2d::Coords&, dcel2d::Coords&, double&, double&) const;
120 
121  bool computeCircleCenter3(const dcel2d::Coords&, const dcel2d::Coords&, const dcel2d::Coords&, dcel2d::Coords&, double&, double&) const;
122 
126  void getConvexHull(const BSTNode*);
127 
131  void terminateInfiniteEdges(BeachLine&, double);
132 
136  bool isInsideConvexHull(const dcel2d::Vertex&) const;
137 
142 
146  void findBoundingBox(const dcel2d::VertexList&);
147 
151  using BoostEdgeToEdgeMap = std::map<const boost::polygon::voronoi_edge<double>*, dcel2d::HalfEdge*>;
152  using BoostVertexToVertexMap = std::map<const boost::polygon::voronoi_vertex<double>*, dcel2d::Vertex*>;
153  using BoostCellToFaceMap = std::map<const boost::polygon::voronoi_cell<double>*, dcel2d::Face*>;
154 
156  const boost::polygon::voronoi_edge<double>*,
157  const boost::polygon::voronoi_edge<double>*,
161 
166 
170  double ComputeFaceArea();
171 
175  double crossProduct(const dcel2d::Point& p0, const dcel2d::Point& p1, const dcel2d::Point& p2) const;
176 
180  double Area() const;
181 
185  bool isLeft(const dcel2d::Point& p0, const dcel2d::Point& p1, const dcel2d::Point& pCheck) const;
186 
190 
192  SiteEventList fSiteEventList; //< Container for site events
193  CircleEventList fCircleEventList; //< Container for circle events
194  BSTNodeList fCircleNodeList; //< Container for the circle "nodes"
195 
196  dcel2d::PointList fConvexHullList; //< Points representing the convex hull
197  dcel2d::Coords fConvexHullCenter; //< Center of the convex hull
198 
199  double fXMin; //< Bounding box min value x
200  double fXMax; //< Bounding box max value x
201  double fYMin; //< Bounding box min value y
202  double fYMax; //< Bounding box max value y
203  mutable int fNumBadCircles; //< Number bad circles
205 
206  EventUtilities fUtilities; //< Handy functions to operate on arcs
207 
208 };
209 
210 } // namespace lar_cluster3d
211 #endif
std::pair< PointPair, PointPair > MinMaxPointPair
Definition: Voronoi.h:37
double getVoronoiDiagramArea() const
recover the area of the convex hull
Definition: Voronoi.h:73
This defines the actual beach line. The idea is to implement this as a self balancing binary search t...
Definition: BeachLine.h:129
bool computeCircleCenter2(const dcel2d::Coords &, const dcel2d::Coords &, const dcel2d::Coords &, dcel2d::Coords &, double &, double &) const
Definition: Voronoi.cxx:764
std::list< SiteEvent > SiteEventList
Definition: SweepEvent.h:99
dcel2d::HalfEdgeList & fHalfEdgeList
Definition: Voronoi.h:187
std::list< HalfEdge > HalfEdgeList
Definition: DCEL.h:180
std::list< CircleEvent > CircleEventList
Definition: SweepEvent.h:100
Provides some basic functions operating in IEvent class objects.
BSTNode class definiton specifically for use in constructing Voronoi diagrams. We are trying to follo...
Definition: BeachLine.h:32
bool isInsideConvexHull(const dcel2d::Vertex &) const
Is a vertex inside the convex hull - meant to be a fast check.
Definition: Voronoi.cxx:1104
double Area() const
Computes the area of the enclosed convext hull.
Definition: Voronoi.cxx:106
dcel2d::FaceList & fFaceList
Definition: Voronoi.h:189
std::list< BSTNode > BSTNodeList
Definition: BeachLine.h:122
Internal class definitions to facilitate construction of diagram.
Represents the beachline implemented as a self balancing binary search tree.
virtual ~VoronoiDiagram()
Destructor.
Definition: Voronoi.cxx:78
void makeLeftCircleEvent(EventQueue &, BSTNode *, double)
Definition: Voronoi.cxx:559
bool computeCircleCenter(const dcel2d::Coords &, const dcel2d::Coords &, const dcel2d::Coords &, dcel2d::Coords &, double &, double &) const
Definition: Voronoi.cxx:692
BSTNodeList fCircleNodeList
Definition: Voronoi.h:194
IEvent * makeCircleEvent(BSTNode *, BSTNode *, BSTNode *, double)
There are two types of events in the queue, here we handle circle events.
Definition: Voronoi.cxx:655
void handleCircleEvents(BeachLine &, EventQueue &, IEvent *)
There are two types of events in the queue, here we handle circle events.
Definition: Voronoi.cxx:474
VoronoiDiagram class definiton.
Definition: Voronoi.h:33
intermediate_table::const_iterator const_iterator
std::list< Face > FaceList
Definition: DCEL.h:179
CircleEventList fCircleEventList
Definition: Voronoi.h:193
SiteEventList fSiteEventList
Definition: Voronoi.h:192
EventUtilities fUtilities
Definition: Voronoi.h:206
double ComputeFaceArea()
Compute the area of the faces.
Definition: Voronoi.cxx:1217
std::priority_queue< IEvent *, std::vector< IEvent * >, bool(*)(const IEvent *, const IEvent *)> EventQueue
Definition: Voronoi.h:97
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
Definition: DCEL.h:34
void buildVoronoiDiagram(const dcel2d::PointList &)
Given an input set of 2D points construct a 2D voronoi diagram.
Definition: Voronoi.cxx:135
double findNearestDistance(const dcel2d::Point &) const
Given an input point, find the distance to the nearest edge/point.
Definition: Voronoi.cxx:1426
void findBoundingBox(const dcel2d::VertexList &)
Find the min/max values in x-y to use as a bounding box.
Definition: Voronoi.cxx:1348
dcel2d::VertexList & fVertexList
Definition: Voronoi.h:188
void mergeDegenerateVertices()
merge degenerate vertices (found by zero length edges)
Definition: Voronoi.cxx:1189
dcel2d::Coords fConvexHullCenter
Definition: Voronoi.h:197
void makeRightCircleEvent(EventQueue &, BSTNode *, double)
Definition: Voronoi.cxx:608
dcel2d::PointList fPointList
Definition: Voronoi.h:191
double crossProduct(const dcel2d::Point &p0, const dcel2d::Point &p1, const dcel2d::Point &p2) const
Gets the cross product of line from p0 to p1 and p0 to p2.
Definition: Voronoi.cxx:93
PointPair findNearestEdge(const dcel2d::Point &, double &) const
Given an input Point, find the nearest edge.
Definition: Voronoi.cxx:1365
dcel2d::PointList fConvexHullList
Definition: Voronoi.h:196
std::pair< dcel2d::Point, dcel2d::Point > PointPair
Definition: Voronoi.h:36
const dcel2d::PointList & getConvexHull() const
recover the point list representing the convex hull
Definition: Voronoi.h:78
void boostTranslation(const dcel2d::PointList &, const boost::polygon::voronoi_edge< double > *, const boost::polygon::voronoi_edge< double > *, BoostEdgeToEdgeMap &, BoostVertexToVertexMap &, BoostCellToFaceMap &)
Definition: Voronoi.cxx:323
PointPair getExtremePoints() const
Given an input Point, find the nearest edge.
Definition: Voronoi.cxx:1042
std::map< const boost::polygon::voronoi_edge< double > *, dcel2d::HalfEdge * > BoostEdgeToEdgeMap
Translate boost to dcel.
Definition: Voronoi.h:151
std::map< const boost::polygon::voronoi_vertex< double > *, dcel2d::Vertex * > BoostVertexToVertexMap
Definition: Voronoi.h:152
bool computeCircleCenter3(const dcel2d::Coords &, const dcel2d::Coords &, const dcel2d::Coords &, dcel2d::Coords &, double &, double &) const
Definition: Voronoi.cxx:795
void terminateInfiniteEdges(BeachLine &, double)
this aims to process remaining elements in the beachline after the event queue has been depleted ...
Definition: Voronoi.cxx:831
std::list< Point > PointList
Definition: DCEL.h:35
void buildVoronoiDiagramBoost(const dcel2d::PointList &)
Definition: Voronoi.cxx:267
Eigen::Vector3f Coords
Definition: DCEL.h:36
const dcel2d::VertexList & getVertexList() const
Recover the list of vertices.
Definition: Voronoi.h:68
const dcel2d::FaceList & getFaceList() const
Recover the list of faces.
Definition: Voronoi.h:63
std::list< Vertex > VertexList
Definition: DCEL.h:178
std::map< const boost::polygon::voronoi_cell< double > *, dcel2d::Face * > BoostCellToFaceMap
Definition: Voronoi.h:153
VoronoiDiagram(dcel2d::HalfEdgeList &, dcel2d::VertexList &, dcel2d::FaceList &)
Constructor.
Definition: Voronoi.cxx:53
bool isOutsideConvexHull(const dcel2d::Vertex &, dcel2d::PointList::const_iterator, dcel2d::Coords &, double &) const
is vertex outside the convex hull and if so return some useful information
Definition: Voronoi.cxx:1133
bool isLeft(const dcel2d::Point &p0, const dcel2d::Point &p1, const dcel2d::Point &pCheck) const
Determines whether a point is to the left, right or on line specifiec by p0 and p1.
Definition: Voronoi.cxx:84
void handleSiteEvents(BeachLine &, EventQueue &, IEvent *)
There are two types of events in the queue, here we handle site events.
Definition: Voronoi.cxx:417