12#ifndef __CODAC2_PAVING_H__
13#define __CODAC2_PAVING_H__
23 template<
class P,
int N=Dynamic>
28 explicit PavingBase(
const IntervalVector_<N>& x)
34 virtual ~PavingBase() =
default;
36 const IntervalVector_<N>& box()
const
41 std::shared_ptr<P> left()
46 std::shared_ptr<P> right()
57 return (_left && _left->is_empty()) && (_right && _right->is_empty());
62 return not _left && not _right;
70 if(_left) v += _left->volume();
71 if(_right) v += _right->volume();
75 virtual void bisect(
float ratio = 0.49)
77 assert(Interval(0.,1.).interior_contains(ratio));
78 assert(is_leaf() &&
"only leaves can be bisected");
79 assert(_x.is_bisectable());
80 auto p = _x.bisect(ratio);
81 _left = std::make_shared<P>(p.first);
82 _right = std::make_shared<P>(p.second);
85 IntervalVector_<N> hull_box()
const
89 auto hull = IntervalVector_<N>::empty_set();
90 if(_left) hull |= _left->hull_box();
91 if(_right) hull |= _right->hull_box();
95 std::list<std::reference_wrapper<const IntervalVector_<N>>> boxes_list(
const IntervalVector_<N>& intersect = IntervalVector_<N>())
const
97 std::list<std::reference_wrapper<const IntervalVector_<N>>> l;
98 boxes_list_push(l, intersect);
102 std::list<P*> leaves_list()
111 void boxes_list_push(std::list<std::reference_wrapper<
const IntervalVector_<N>>>& l,
const IntervalVector_<N>& intersect = IntervalVector_<N>())
const
113 if(is_leaf() && !_x.is_empty() && _x.intersects(intersect))
114 l.push_back(std::cref(_x));
117 if(_left) _left->boxes_list_push(l);
118 if(_right) _right->boxes_list_push(l);
122 void leaves_list_push(std::list<P*>& l)
124 if(is_leaf() && !_x.is_empty())
125 l.push_back(
dynamic_cast<P*
>(
this));
128 if(_left) _left->leaves_list_push(l);
129 if(_right) _right->leaves_list_push(l);
135 IntervalVector_<N> _x;
136 std::shared_ptr<P> _left =
nullptr, _right =
nullptr;
140 class Paving :
public PavingBase<Paving<N>,N>
144 explicit Paving(
size_t n)
145 : PavingBase<Paving<N>,N>(IntervalVector_<N>(n))
148 explicit Paving(
const IntervalVector_<N>& x)
149 : PavingBase<Paving<N>,N>(x)