24 template<
typename P,
typename... X>
25 requires (std::is_same_v<X,IntervalVector> && ...)
26 class Paving :
public Domain
30 using Node_ = std::shared_ptr<const PavingNode<P>>;
31 using NodeTuple_ = std::tuple<X...>;
32 using NodeValue_ = std::function<std::list<IntervalVector>(Node_)>;
33 using ConnectedSubset_ = Subpaving<P>;
38 assert_release(n > 0);
42 : _tree(std::make_shared<PavingNode<P>>(*static_cast<P*>(this), x))
45 inline Index size()
const
47 return std::get<0>(_tree->boxes()).size();
50 inline std::shared_ptr<const PavingNode<P>> tree()
const
55 inline std::shared_ptr<PavingNode<P>> tree()
57 return std::const_pointer_cast<PavingNode<P>>(
const_cast<const Paving<P,X...
>*>(
this)->tree());
60 inline std::list<IntervalVector> boxes(
const NodeValue_& node_value)
const
65 inline std::list<IntervalVector> boxes(
const NodeValue_& node_value,
const IntervalVector& intersecting_box)
const
67 std::list<IntervalVector> l;
69 this->tree()->visit([&]
72 for(
const auto& bi : node_value(n))
73 if(bi.intersects(intersecting_box))
75 return n->hull().intersects(intersecting_box);
79 l.push_back(IntervalVector::empty(this->size()));
83 inline std::list<ConnectedSubset_> connected_subsets(
const NodeValue_& node_value)
const
88 inline std::list<ConnectedSubset_> connected_subsets(
const IntervalVector& x0,
const NodeValue_& node_value)
const
90 std::list<IntervalVector> l_boxes = boxes(node_value, x0);
91 [[maybe_unused]] Index nb_boxes = l_boxes.size();
92 std::list<ConnectedSubset_> l_subsets;
94 while(!l_boxes.empty())
96 auto current_box = l_boxes.front();
97 l_subsets.push_back({ current_box });
100 std::list<IntervalVector> l_neighbouring_boxes_to_visit { current_box };
104 current_box = l_neighbouring_boxes_to_visit.front();
105 l_neighbouring_boxes_to_visit.pop_front();
107 for(
const auto& ni : boxes(node_value, current_box))
109 if(std::find(l_boxes.begin(), l_boxes.end(), ni) != l_boxes.end())
112 l_neighbouring_boxes_to_visit.push_back(ni);
113 l_subsets.back().push_back(ni);
117 }
while(!l_neighbouring_boxes_to_visit.empty());
120 assert(l_boxes.empty() &&
"all the nodes should have been visited");
121 assert([&]() ->
bool { Index s = 0;
for(
const auto& si : l_subsets) s += si.size();
return s == nb_boxes; } ()
122 &&
"the total number of boxes should match the sum of number of boxes of each subset");
129 friend class PavingNode<P>;
133 return std::make_tuple(((X)x)...);
136 std::shared_ptr<PavingNode<P>> _tree;
141 using PavingOut_Node = PavingNode<PavingOut>;
143 class PavingOut :
public Paving<PavingOut,IntervalVector>
150 std::list<PavingOut::ConnectedSubset_> connected_subsets(
const PavingOut::NodeValue_& node_value = PavingOut::outer)
const;
151 std::list<PavingOut::ConnectedSubset_> connected_subsets(
const IntervalVector& x0,
const PavingOut::NodeValue_& node_value = PavingOut::outer)
const;
155 assert_release(x.size() == this->size());
162 this->tree()->visit([&]
165 for(
const auto& bi : PavingOut::outer(n))
167 return n->hull().intersects(x);
169 assert(x_.is_subset(x));
173 static const NodeValue_ outer, outer_complem;
178 using PavingInOut_Node = PavingNode<PavingInOut>;
180 class PavingInOut :
public Paving<PavingInOut,IntervalVector,IntervalVector>
184 PavingInOut(Index n);
187 std::list<PavingInOut::ConnectedSubset_> connected_subsets(
const PavingInOut::NodeValue_& node_value = PavingInOut::outer)
const;
188 std::list<PavingInOut::ConnectedSubset_> connected_subsets(
const IntervalVector& x0,
const PavingInOut::NodeValue_& node_value = PavingInOut::outer)
const;
190 static const NodeValue_ outer, outer_complem, inner, bound, all;
Definition codac2_OctaSym.h:21
Eigen::Matrix< Interval,-1, 1 > IntervalVector
Alias for a dynamic-size column vector of intervals.
Definition codac2_IntervalVector.h:25