codac 2.0.0
Loading...
Searching...
No Matches
codac2_Subpaving.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include <unordered_set>
13#include <list>
14#include <memory>
15#include "codac2_assert.h"
17#include "codac2_Paving.h"
19
20namespace codac2
21{
22 template<typename P>
23 class PavingNode;
24
25 template<typename P>
26 class Subpaving : public std::list<IntervalVector>
27 {
28 public:
29
30 Subpaving(std::initializer_list<IntervalVector> l)
31 : std::list<IntervalVector>(l)
32 {
33 assert_release(!this->empty());
34 }
35
36 Subpaving(const std::list<IntervalVector>& l)
37 : std::list<IntervalVector>(l)
38 {
39 assert_release(!this->empty());
40 }
41
42 IntervalVector box() const
43 {
44 IntervalVector h = IntervalVector::empty(this->front().size());
45 for(const auto& bi : *this)
46 h |= bi;
47 return h;
48 }
49
50 std::list<IntervalVector> boxes() const
51 {
52 return *this;
53 }
54
55 #if 0
56 std::list<IntervalVector> contour(bool sort = false) const
57 {
58 if constexpr(std::is_same_v<PavingOut,P>)
59 return contour(PavingOut::outer_complem, sort);
60
61 else if constexpr(std::is_same_v<PavingInOut,P>)
62 return contour(PavingInOut::outer_complem, sort);
63
64 else
65 {
66 assert_release_constexpr(false &&
67 "cannot find a default complementary \"node value\" function for such Subaving class");
68 return { };
69 }
70 }
71
72 std::list<IntervalVector> contour(const P::NodeValue_& node_complementary_value = nullptr, bool sort = false) const
73 {
74 std::list<IntervalVector> l_bound;
75
76 for(const auto& xi : *this)
77 {
78 auto x_boxes = _node_value(xi);
79 auto neighb_nodes = this->front()->paving().neighbours(xi, _node_value, node_complementary_value);
80 std::list<IntervalVector> neighb_boxes;
81
82 for(const auto& neighb_ni : neighb_nodes)
83 neighb_boxes.splice(neighb_boxes.end(), node_complementary_value(neighb_ni));
84
85 for(const auto& x_bi : x_boxes)
86 for(const auto& neighb_bi : neighb_boxes)
87 {
88 auto inter = x_bi & neighb_bi;
89 if(!inter.is_empty() && !inter.is_degenerated())
90 l_bound.push_back(inter);
91 }
92 }
93
94 // Removing duplicates
95 remove_duplicates_from_list(l_bound);
96
97 assert([&]() -> bool { for(const auto& bi : l_bound) { if(!bi.is_flat()) return false; } return true; } ()
98 && "boundary boxes should be flat");
99 return sort ? sort_contour(l_bound) : l_bound;
100 }
101
102 static Vector next_pt(const IntervalVector& x, const Vector& pt)
103 {
104 assert(!x.is_degenerated());
105 assert(x.size() == 2 && pt.size() == 2);
106 assert(x.is_flat());
107 assert(x.lb() == pt || x.ub() == pt);
108 return pt == x.lb() ? x.ub() : x.lb();
109 }
110
111 std::list<IntervalVector> sort_contour(std::list<IntervalVector> l) const
112 {
113 assert_release(!l.empty());
114 assert_release(l.front().size() == 2 && "only 2d contours can be sorted");
115
116 const Index nl = l.size();
117
118 Vector current_pt = l.front().ub(), first_pt = current_pt;
119 std::list<IntervalVector> s { l.front() };
120 l.pop_front();
121
122 while(!l.empty())
123 {
124 std::list<IntervalVector>::iterator it = l.begin();
125 while(it != l.end())
126 {
127 if(it->contains(current_pt))
128 {
129 s.push_back(*it);
130 current_pt = Subpaving<P>::next_pt(*it, current_pt);
131 l.erase(it);
132 break;
133 }
134
135 else
136 ++it;
137 }
138
139 if(current_pt == first_pt)
140 break;
141 }
142
143 assert(nl == s.size());
144 return s;
145 }
146 #endif
147 };
148
149 using SubpavingOut = Subpaving<PavingOut>;
150 using SubpavingInOut = Subpaving<PavingInOut>;
151}
Eigen::Matrix< Interval,-1, 1 > IntervalVector
Alias for a dynamic-size column vector of intervals.
Definition codac2_IntervalVector.h:25
Eigen::Matrix< double,-1, 1 > Vector
Alias for a dynamically-sized column vector of doubles.
Definition codac2_Vector.h:24