ATLAS Offline Software
Loading...
Searching...
No Matches
JetVoronoiDiagramHelpers.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 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//using boost::polygon::voronoi_builder;
27//using boost::polygon::voronoi_diagram;
28typedef boost::polygon::voronoi_diagram<double> VoronoiBoost;
29typedef boost::polygon::voronoi_diagram<double>::vertex_type VoronoiVtxBoost;
30typedef boost::polygon::voronoi_diagram<double>::cell_type VoronoiCellBoost;
31typedef boost::polygon::voronoi_diagram<double>::edge_type VoronoiEdgeBoost;
32
33// boost geometry
34#include <boost/geometry.hpp>
35#include <boost/geometry/geometries/point_xy.hpp>
36#include <boost/geometry/geometries/polygon.hpp>
37//using boost::geometry::area;
38//using boost::geometry::intersection;
39typedef boost::geometry::model::d2::point_xy<double> VoronoiPointBoost;
40typedef boost::geometry::model::polygon<VoronoiPointBoost> VoronoiPolygonBoost;
41
45 typedef double coord;
46
47
50 struct Point{
51 Point(coord the_x=0, coord the_y=0): x(the_x), y(the_y){};
52 Point(const Point &a): x(a.x), y(a.y) {};
53 // data members
56 };
57
58 // operators *
59 Point operator*(double a, const Point &b);
60 Point operator*(const Point &b,double a);
61 double operator*(const Point &a, const Point &b);
62
63 // operators +
64 Point operator+(const Point &a, const Point &b);
65 Point operator+(double a, const Point &b);
66 Point operator+(const Point &b, double a);
67
68 // operators -
69 Point operator-(const Point &a, const Point &b);
70 Point operator-(const Point &b);
71
72 // logic operators
73 bool operator== (const Point &a, const Point &b);
74 bool operator!= (const Point &a, const Point &b);
75
76 // space functions
77 Point Center(const Point &a, const Point &b) ;
78 Point Norm(const Point &a);
79
80
83 struct Segment{
84 Segment(coord x1, coord y1, coord x2, coord y2) : p0(x1, y1), p1(x2, y2) {}
85 Segment(Point a, Point b) : p0(a), p1(b) {}
86 // data members
89 };
90
91
94 struct Polygon : public std::vector<Point> {
95 void Add(coord x, coord y){
96 push_back(Point(x,y));
97 }
99 if (empty()) return;
100 // add all
101 for ( const Point& p : *this ) out.outer().push_back(VoronoiPointBoost(p.x,p.y));
102 // add first again to close shape if necessary
103 if ( front() != back() ) out.outer().push_back(VoronoiPointBoost(front().x,front().y));
104 // correct geometry
105 boost::geometry::correct(out);
106 }
107 };
108
109
112 typedef std::vector<Polygon> PolygonList;
113
114
117 struct SegmentList : public std::vector<Segment> {
118 void Add(coord x1, coord y1, coord x2, coord y2) {
119 push_back(Segment(x1,y1,x2,y2));
120 }
121 };
122
123
126 struct Diagram : public asg::AsgTool {
127 Diagram ( const std::string & name);
128 // functions
129 StatusCode initialize();
130 float getCellArea( const coord x, const coord y) const;
131 size_t findPointIndex(const Point &a) const;
132 void clearDiagram();
133 StatusCode createVoronoiDiagram();
134 Point interpolateInfinityVertex(const int i_a, const int i_b);
135 bool checkSameNumber(double in, double out, const std::string & description);
136 StatusCode checkStatus(const VoronoiBoost &vd, size_t n_cells_processed);
138
139 // Data members
140 double m_x_min;
141 double m_x_max;
142 double m_y_min;
143 double m_y_max;
147 std::vector<double> m_area_cells;
149 // Polygon m_voro_cells; //!< needed for future implementation of "within"
151 };
152} // JetVoronoiDiagramHelpers
153
154
155// interfacing Helpers to Boost
156//using JetVoronoiDiagramHelpers::coord;
157//using JetVoronoiDiagramHelpers::Point;
158//using JetVoronoiDiagramHelpers::Segment;
159//using JetVoronoiDiagramHelpers::SegmentList;
160//using JetVoronoiDiagramHelpers::Polygon;
161//using JetVoronoiDiagramHelpers::PolygonList;
162//using JetVoronoiDiagramHelpers::Diagram;
163
164namespace boost {
165 namespace polygon {
166 // Point concept
167 template <>
168 struct geometry_concept<JetVoronoiDiagramHelpers::Point> {
169 typedef point_concept type;
170 };
171 template <>
172 struct point_traits<JetVoronoiDiagramHelpers::Point> {
174 static inline coordinate_type get(
175 const JetVoronoiDiagramHelpers::Point& point, orientation_2d orient) {
176 return (orient == HORIZONTAL) ? point.x : point.y;
177 }
178 };
179 template <>
180 struct point_mutable_traits<JetVoronoiDiagramHelpers::Point> {
182 static inline void set(JetVoronoiDiagramHelpers::Point& point, orientation_2d orient, int value) {
183 if(orient == HORIZONTAL)
184 point.x = value;
185 else
186 point.y = value;
187 }
188 static inline JetVoronoiDiagramHelpers::Point construct(int x_value, int y_value) {
190 retval.x = x_value;
191 retval.y = y_value;
192 return retval;
193 }
194 };
195
196 // Segment concept
197 template <>
198 struct geometry_concept<JetVoronoiDiagramHelpers::Segment> {
199 typedef segment_concept type;
200 };
201 template <>
202 struct segment_traits<JetVoronoiDiagramHelpers::Segment> {
205 static inline point_type get(const JetVoronoiDiagramHelpers::Segment& segment, direction_1d dir) {
206 return dir.to_int() ? segment.p1 : segment.p0;
207 }
208 };
209 } // polygon
210} // boost
211
212#endif
213
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:91
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)
Point operator*(double 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)