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>;
36 : Paving(IntervalVector(n))
38 assert_release(n > 0);
41 Paving(
const IntervalVector& x)
42 : _tree(std::make_shared<PavingNode<P>>(*static_cast<P*>(this), x))
47 return std::get<0>(_tree->boxes()).size();
50 std::shared_ptr<const PavingNode<P>> tree()
const
55 std::shared_ptr<PavingNode<P>> tree()
57 return std::const_pointer_cast<PavingNode<P>>(
const_cast<const Paving<P,X...
>*>(
this)->tree());
60 std::list<IntervalVector> intersecting_boxes(
const IntervalVector& x,
const NodeValue_& node_value)
const
62 std::list<IntervalVector> l;
64 this->tree()->visit([&]
67 for(
const auto& bi : node_value(n))
74 return n->hull().intersects(x);
80 std::list<ConnectedSubset_> connected_subsets(
const NodeValue_& node_value)
const
82 return connected_subsets(IntervalVector(size()), node_value);
85 std::list<ConnectedSubset_> connected_subsets(
const IntervalVector& x0,
const NodeValue_& node_value)
const
87 std::list<IntervalVector> l_boxes = intersecting_boxes(x0, node_value);
88 [[maybe_unused]] Index nb_boxes = l_boxes.size();
89 std::list<ConnectedSubset_> l_subsets;
91 while(!l_boxes.empty())
93 auto current_box = l_boxes.front();
94 l_subsets.push_back({ current_box });
97 std::list<IntervalVector> l_neighbouring_boxes_to_visit { current_box };
101 current_box = l_neighbouring_boxes_to_visit.front();
102 l_neighbouring_boxes_to_visit.pop_front();
104 for(
const auto& ni : intersecting_boxes(current_box, node_value))
106 if(std::find(l_boxes.begin(), l_boxes.end(), ni) != l_boxes.end())
109 l_neighbouring_boxes_to_visit.push_back(ni);
110 l_subsets.back().push_back(ni);
114 }
while(!l_neighbouring_boxes_to_visit.empty());
117 assert(l_boxes.empty() &&
"all the nodes should have been visited");
118 assert([&]() ->
bool { Index s = 0;
for(
const auto& si : l_subsets) s += si.size();
return s == nb_boxes; } ()
119 &&
"the total number of boxes should match the sum of number of boxes of each subset");
126 friend class PavingNode<P>;
128 static NodeTuple_ init_tuple(
const IntervalVector& x)
130 return std::make_tuple(((X)x)...);
133 std::shared_ptr<PavingNode<P>> _tree;
138 using PavingOut_Node = PavingNode<PavingOut>;
140 class PavingOut :
public Paving<PavingOut,IntervalVector>
145 PavingOut(
const IntervalVector& x);
147 std::list<PavingOut::ConnectedSubset_> connected_subsets(
const PavingOut::NodeValue_& node_value = PavingOut::outer)
const;
148 std::list<PavingOut::ConnectedSubset_> connected_subsets(
const IntervalVector& x0,
const PavingOut::NodeValue_& node_value = PavingOut::outer)
const;
150 static const NodeValue_ outer, outer_complem;
155 using PavingInOut_Node = PavingNode<PavingInOut>;
157 class PavingInOut :
public Paving<PavingInOut,IntervalVector,IntervalVector>
161 PavingInOut(Index n);
162 PavingInOut(
const IntervalVector& x);
164 std::list<PavingInOut::ConnectedSubset_> connected_subsets(
const PavingInOut::NodeValue_& node_value = PavingInOut::outer)
const;
165 std::list<PavingInOut::ConnectedSubset_> connected_subsets(
const IntervalVector& x0,
const PavingInOut::NodeValue_& node_value = PavingInOut::outer)
const;
167 static const NodeValue_ outer, outer_complem, inner, bound, all;