Project
Loading...
Searching...
No Matches
ContourCreator.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#ifndef O2_MCH_CONTOUR_CONTOURCREATOR_H
16#define O2_MCH_CONTOUR_CONTOURCREATOR_H
17
18#include <memory>
19#include "ContourCreator.inl"
20
21namespace o2
22{
23namespace mch
24{
25namespace contour
26{
27
34template <typename T>
35Contour<T> createContour(const std::vector<Polygon<T>>& polygons)
36{
37 if (polygons.empty()) {
38 return {};
39 }
40
41 if (!isCounterClockwiseOriented(polygons)) {
42 throw std::invalid_argument("polygons should be oriented counterclockwise");
43 }
44
45 // trivial case : only one input polygon
46 if (polygons.size() == 1) {
47 Contour<T> trivialContour;
48 trivialContour.addPolygon(polygons.front());
49 return trivialContour;
50 }
51
52 std::vector<impl::VerticalEdge<T>> polygonVerticalEdges{impl::getVerticalEdges(polygons)};
53
54 sortVerticalEdges(polygonVerticalEdges);
55
56 // Initialize the segment tree that is used by the sweep() function
57 std::unique_ptr<impl::Node<T>> segmentTree{impl::createSegmentTree(impl::getYPositions(polygons))};
58
59 // Find the vertical edges of the merged contour. This is the meat of the algorithm...
60 std::vector<impl::VerticalEdge<T>> contourVerticalEdges{impl::sweep(segmentTree.get(), polygonVerticalEdges)};
61
62 // Deduce the horizontal edges from the vertical ones
63 std::vector<impl::HorizontalEdge<T>> contourHorizontalEdges{impl::verticalsToHorizontals(contourVerticalEdges)};
64
65 return impl::finalizeContour(contourVerticalEdges, contourHorizontalEdges);
66}
67
68template <typename T>
70{
72 std::vector<o2::mch::contour::Polygon<T>> polygons;
73 for (const auto& c : list) {
74 for (auto j = 0; j < c.size(); ++j) {
75 polygons.push_back(c[j]);
76 }
77 }
78 return createContour(polygons);
79}
80
81} // namespace contour
82} // namespace mch
83} // namespace o2
84
85#endif
uint32_t j
Definition RawData.h:0
uint32_t c
Definition RawData.h:2
Contour< T > & addPolygon(const Polygon< T > &polygon)
Definition Contour.h:78
std::vector< VerticalEdge< T > > sweep(Node< T > *segmentTree, const std::vector< VerticalEdge< T > > &polygonVerticalEdges)
std::vector< VerticalEdge< T > > getVerticalEdges(const Polygon< T > &polygon)
std::vector< HorizontalEdge< T > > verticalsToHorizontals(const std::vector< VerticalEdge< T > > &verticals)
Contour< T > finalizeContour(const std::vector< VerticalEdge< T > > &verticals, const std::vector< HorizontalEdge< T > > &horizontals)
std::vector< T > getYPositions(const std::vector< Polygon< T > > &polygons)
Node< T > * createSegmentTree(std::vector< T > values)
Contour< T > createContour(const std::vector< Polygon< T > > &polygons)
Contour< T > getEnvelop(const std::vector< Contour< T > > &list)
bool isCounterClockwiseOriented(const std::vector< T > &polygons)
Definition Contour.h:52
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Definition list.h:40