ATLAS Offline Software
Loading...
Searching...
No Matches
JetVoronoiDiagramHelpers.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5// JetVoronoiDiagramHelpers.h
6
7#ifndef JETMOMENTTOOLS_JETVORONOIDIAGRAMHELPERS_H
8#define JETMOMENTTOOLS_JETVORONOIDIAGRAMHELPERS_H
9
15
16// athena
17#include "AsgTools/AsgTool.h"
18
19//stl
20#include <string>
21#include <vector>
22//using std::vector;
23
24// boost polygon
25#include <boost/polygon/voronoi.hpp>
26
27typedef boost::polygon::voronoi_diagram<double> VoronoiBoost;
28typedef boost::polygon::voronoi_diagram<double>::vertex_type VoronoiVtxBoost;
29typedef boost::polygon::voronoi_diagram<double>::cell_type VoronoiCellBoost;
30typedef boost::polygon::voronoi_diagram<double>::edge_type VoronoiEdgeBoost;
31
32// boost geometry
33#include <boost/geometry.hpp>
34#include <boost/geometry/geometries/point_xy.hpp>
35#include <boost/geometry/geometries/polygon.hpp>
36
37typedef boost::geometry::model::d2::point_xy<double> VoronoiPointBoost;
38typedef boost::geometry::model::polygon<VoronoiPointBoost> VoronoiPolygonBoost;
39
43 typedef double coord;
44
45
48 struct Point{
49 Point(coord the_x=0, coord the_y=0): x(the_x), y(the_y){};
50 Point(const Point &a): x(a.x), y(a.y) {};
51 // data members
54 };
55
56 // operators *
57 Point operator*(double a, const Point &b);
58 Point operator*(const Point &b,double a);
59 double operator*(const Point &a, const Point &b);
60
61 // operators +
62 Point operator+(const Point &a, const Point &b);
63 Point operator+(double a, const Point &b);
64 Point operator+(const Point &b, double a);
65
66 // operators -
67 Point operator-(const Point &a, const Point &b);
68 Point operator-(const Point &b);
69
70 // logic operators
71 bool operator== (const Point &a, const Point &b);
72 bool operator!= (const Point &a, const Point &b);
73
74 // space functions
75 Point Center(const Point &a, const Point &b) ;
76 Point Norm(const Point &a);
77
78
81 struct Segment{
82 Segment(coord x1, coord y1, coord x2, coord y2) : p0(x1, y1), p1(x2, y2) {}
83 Segment(Point a, Point b) : p0(a), p1(b) {}
84 // data members
87 };
88
89
92 struct Polygon : public std::vector<Point> {
93 void Add(coord x, coord y){
94 push_back(Point(x,y));
95 }
97 if (empty()) return;
98 // add all
99 for ( const Point& p : *this ) out.outer().push_back(VoronoiPointBoost(p.x,p.y));
100 // add first again to close shape if necessary
101 if ( front() != back() ) out.outer().push_back(VoronoiPointBoost(front().x,front().y));
102 // correct geometry
103 boost::geometry::correct(out);
104 }
105 };
106
107
110 typedef std::vector<Polygon> PolygonList;
111
112
115 struct SegmentList : public std::vector<Segment> {
116 void Add(coord x1, coord y1, coord x2, coord y2) {
117 push_back(Segment(x1,y1,x2,y2));
118 }
119 };
120
121
124 struct Diagram : public asg::AsgTool {
125 Diagram ( const std::string & name);
126 // functions
127 StatusCode initialize();
128 float getCellArea( const coord x, const coord y) const;
129 size_t findPointIndex(const Point &a) const;
130 void clearDiagram();
131 StatusCode createVoronoiDiagram();
132 Point interpolateInfinityVertex(const int i_a, const int i_b);
133 bool checkSameNumber(double in, double out, const std::string & description);
134 StatusCode checkStatus(const VoronoiBoost &vd, size_t n_cells_processed);
136
137 // Data members
138 double m_x_min{};
139 double m_x_max{};
140 double m_y_min{};
141 double m_y_max{};
145 std::vector<double> m_area_cells;
147 // Polygon m_voro_cells; //!< needed for future implementation of "within"
148 size_t m_N_points{};
149 };
150} // JetVoronoiDiagramHelpers
151
152
153// interfacing Helpers to Boost
154//using JetVoronoiDiagramHelpers::coord;
155//using JetVoronoiDiagramHelpers::Point;
156//using JetVoronoiDiagramHelpers::Segment;
157//using JetVoronoiDiagramHelpers::SegmentList;
158//using JetVoronoiDiagramHelpers::Polygon;
159//using JetVoronoiDiagramHelpers::PolygonList;
160//using JetVoronoiDiagramHelpers::Diagram;
161
162namespace boost {
163 namespace polygon {
164 // Point concept
165 template <>
166 struct geometry_concept<JetVoronoiDiagramHelpers::Point> {
167 typedef point_concept type;
168 };
169 template <>
170 struct point_traits<JetVoronoiDiagramHelpers::Point> {
172 static inline coordinate_type get(
173 const JetVoronoiDiagramHelpers::Point& point, orientation_2d orient) {
174 return (orient == HORIZONTAL) ? point.x : point.y;
175 }
176 };
177 template <>
178 struct point_mutable_traits<JetVoronoiDiagramHelpers::Point> {
180 static inline void set(JetVoronoiDiagramHelpers::Point& point, orientation_2d orient, int value) {
181 if(orient == HORIZONTAL)
182 point.x = value;
183 else
184 point.y = value;
185 }
186 static inline JetVoronoiDiagramHelpers::Point construct(int x_value, int y_value) {
188 retval.x = x_value;
189 retval.y = y_value;
190 return retval;
191 }
192 };
193
194 // Segment concept
195 template <>
196 struct geometry_concept<JetVoronoiDiagramHelpers::Segment> {
197 typedef segment_concept type;
198 };
199 template <>
200 struct segment_traits<JetVoronoiDiagramHelpers::Segment> {
203 static inline point_type get(const JetVoronoiDiagramHelpers::Segment& segment, direction_1d dir) {
204 return dir.to_int() ? segment.p1 : segment.p0;
205 }
206 };
207 } // polygon
208} // boost
209
210#endif
211
ChargedTracksWeightFilter::Spline::Point Point
boost::geometry::model::d2::point_xy< double > VoronoiPointBoost
boost::polygon::voronoi_diagram< double >::cell_type VoronoiCellBoost
boost::polygon::voronoi_diagram< double >::edge_type VoronoiEdgeBoost
boost::polygon::voronoi_diagram< double >::vertex_type VoronoiVtxBoost
boost::polygon::voronoi_diagram< double > VoronoiBoost
Jakub Cuth May 2015.
boost::geometry::model::polygon< VoronoiPointBoost > VoronoiPolygonBoost
static Double_t a
#define y
#define x
static const Attributes_t empty
Diagram(const std::string &name)
Straight line in 2D space.
Base class for the dual-use tool implementation classes.
Definition AsgTool.h:47
std::string description
glabal timer - how long have I taken so far?
Definition hcg.cxx:93
std::vector< Polygon > PolygonList
List of polygons.
bool operator!=(const Point &a, const Point &b)
Point Center(const Point &a, const Point &b)
Point operator+(const Point &a, const Point &b)
Point operator-(const Point &a, const Point &b)
bool operator==(const Point &a, const Point &b)
double coord
Type of coordination system.
size_t findPointIndex(const Point &a) const
StatusCode checkStatus(const VoronoiBoost &vd, size_t n_cells_processed)
bool checkSameNumber(double in, double out, const std::string &description)
Point interpolateInfinityVertex(const int i_a, const int i_b)
float getCellArea(const coord x, const coord y) const
StatusCode initialize()
Dummy implementation of the initialisation function.
double intersectionAndArea(JetVoronoiDiagramHelpers::Polygon const &geo1, JetVoronoiDiagramHelpers::Polygon const &geo2, JetVoronoiDiagramHelpers::Polygon &out)
Point(coord the_x=0, coord the_y=0)
void FillVoroPolygon(VoronoiPolygonBoost &out) const
void Add(coord x1, coord y1, coord x2, coord y2)
Segment(coord x1, coord y1, coord x2, coord y2)
static void set(JetVoronoiDiagramHelpers::Point &point, orientation_2d orient, int value)
static JetVoronoiDiagramHelpers::Point construct(int x_value, int y_value)
static coordinate_type get(const JetVoronoiDiagramHelpers::Point &point, orientation_2d orient)
static point_type get(const JetVoronoiDiagramHelpers::Segment &segment, direction_1d dir)