codac 2.0.0
Loading...
Searching...
No Matches
codac2_Figure2D_pave.h
Go to the documentation of this file.
1
9
10#pragma once
11
13
14namespace codac2
15{
16 inline std::function<void(Figure2D&,const IntervalVector&,const StyleProperties&)> cartesian_drawing()
17 {
18 return [](Figure2D& fig, const IntervalVector& x, const StyleProperties& s) {
19 fig.draw_box(x,s);
20 };
21 }
22
23 inline std::function<void(Figure2D&,const IntervalVector&,const StyleProperties&)> polar_drawing()
24 {
25 return [](Figure2D& fig, const IntervalVector& x, const StyleProperties& s) {
26 fig.draw_pie({0,0},x[0],x[1],s);
27 };
28 }
29
30 template<typename C>
31 requires IsCtcBaseOrPtr<C,IntervalVector>
32 inline void Figure2D::pave(const IntervalVector& x0, const C& c, double eps,
33 const std::function<void(Figure2D&,const IntervalVector&,const StyleProperties&)>& draw_box,
34 const PavingStyle& style)
35 {
36 assert_release(eps > 0.);
37 assert_release(c.size() >= 2 && "cannot reveal 1d contractors");
38
39 if(x0.size() > 2)
40 draw_box(*this, x0, style.outside);
41
42 clock_t t_start = clock();
43 std::list<IntervalVector> l { x0 };
44 Index n = 0;
45
46 while(!l.empty())
47 {
48 IntervalVector x = l.front(), prev_x = x;
49 l.pop_front();
50
51 ctc(c).contract(x);
52
53 if(x0.size() == 2)
54 for(const auto& bi : prev_x.diff(x))
55 draw_box(*this, bi, style.outside);
56
57 if(!x.is_empty())
58 {
59 if(x.max_diam() < eps)
60 {
61 n++;
62 draw_box(*this, x, style.boundary);
63 }
64
65 else
66 {
67 auto p = x.bisect_largest();
68 l.push_back(p.first); l.push_back(p.second);
69 }
70 }
71 }
72
73 printf("Computation time: %.4fs, %ld boxes\n", (double)(clock()-t_start)/CLOCKS_PER_SEC, n);
74 }
75
76 template<typename C>
77 requires IsCtcBaseOrPtr<C,IntervalVector>
78 inline void Figure2D::pave(const IntervalVector& x0, const C& c, double eps, const PavingStyle& style)
79 {
80 return pave(x0, c, eps, cartesian_drawing(), style);
81 }
82
83 template<typename S>
84 requires IsSepBaseOrPtr<S>
85 inline void Figure2D::pave(const IntervalVector& x0, const S& s, double eps,
86 const std::function<void(Figure2D&,const IntervalVector&,const StyleProperties&)>& draw_box,
87 const PavingStyle& style)
88 {
89 assert_release(eps > 0.);
90 assert_release(size_of(s) >= 2 && "cannot reveal 1d separators");
91
92 clock_t t_start = clock();
93 std::list<IntervalVector> l { x0 };
94
95 while(!l.empty())
96 {
97 IntervalVector x = l.front();
98 l.pop_front();
99
100 auto x_sep = sep(s).separate(x);
101 auto boundary = x_sep.inner & x_sep.outer;
102
103 for(const auto& bi : x.diff(x_sep.inner))
104 draw_box(*this, bi, style.inside);
105
106 for(const auto& bi : x.diff(x_sep.outer))
107 draw_box(*this, bi, style.outside);
108
109 if(!boundary.is_empty())
110 {
111 if(boundary.max_diam() <= eps)
112 draw_box(*this, boundary, style.boundary);
113
114 else
115 {
116 auto p = boundary.bisect_largest();
117 l.push_back(p.first); l.push_back(p.second);
118 }
119 }
120 }
121
122 printf("Computation time: %.4fs\n", (double)(clock()-t_start)/CLOCKS_PER_SEC);
123 }
124
125 template<typename S>
126 requires IsSepBaseOrPtr<S>
127 inline void Figure2D::pave(const IntervalVector& x0, const S& s, double eps,
128 const PavingStyle& style)
129 {
130 return pave(x0, s, eps, cartesian_drawing(), style);
131 }
132}
Figure2D class, used for 2D display.
Definition codac2_Figure2D.h:83
void draw_box(const IntervalVector &x, const StyleProperties &s=StyleProperties())
Draws a box on the figure.
void pave(const IntervalVector &x0, const C &c, double eps, const PavingStyle &style=PavingStyle::default_style())
Draws a paving from a contractor while it is being computed.
Definition codac2_Figure2D_pave.h:78
Figure2D(const std::string &name, GraphicOutput o, bool set_as_default=false)
Creates a new Figure2D object, with a given name and output.
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
Style properties structure, to specify the style of a shape.
Definition codac2_StyleProperties.h:26