codac 2.0.0
Loading...
Searching...
No Matches
codac2_Figure3D.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include <string>
13#include <memory>
14#include <fstream>
15#include <functional>
16#include <utility>
17#include <vector>
20#include "codac2_Vector.h"
21#include "codac2_Matrix.h"
23
24namespace codac2
25{
26 class Ellipsoid;
27 class Parallelepiped;
28 class Zonotope;
29 class PavingOut;
30 class PavingInOut;
31 template<typename P> class Subpaving;
32
40 {
41 public:
42
48 Figure3D(const std::string& name);
49
54
60 const std::string& name() const;
61
66 Figure3D& set_projection(std::function<Vector(const Vector&)> projection);
67
68
69 // Geometric shapes
70
81 void draw_triangle(const Vector &c, const Matrix &A,
82 const Vector &p1, const Vector &p2, const Vector &p3,
83 const StyleProperties& style = { Color::dark_gray(0.5) });
84
93 void draw_triangle(const Vector &p1, const Vector &p2, const Vector &p3,
94 const StyleProperties& style = { Color::dark_gray(0.5) });
95
105 void draw_polygon(const Vector &c, const Matrix &A, const std::vector<Vector> &l,
106 const StyleProperties& style = { Color::dark_gray(0.5) });
107
118 void draw_parallelogram(const Vector &c, const Matrix &A,
119 const Vector &p, const Vector &v1, const Vector &v2,
120 const StyleProperties& style = { Color::dark_gray(0.5) });
121
128 void draw_parallelepiped(const Parallelepiped& p, const StyleProperties& style = { Color::dark_gray(0.5) });
129
136 void draw_zonotope(const Zonotope& z, const StyleProperties& style = { Color::dark_gray(0.5) });
137
144 void draw_box(const IntervalVector& x, const StyleProperties& style = { Color::dark_gray(0.5) });
145
146
155 void draw_arrow(const Vector &c, const Matrix& A, const StyleProperties& style = { Color::dark_gray(0.5) });
156
163 void draw_axes(double size = 1.0, const Vector& origin = Vector::Zero(3));
164
177 void draw_surface(const Vector &c, const Matrix &A,
178 const Interval &Ip1, double dp1,
179 const Interval &Ip2, double dp2,
180 std::function<Vector(double,double)> f,
181 const StyleProperties& style = { Color::dark_gray(0.5) });
182
190 void draw_sphere(const Vector &c, const Matrix &A,
191 const StyleProperties& style = { Color::dark_gray(0.5) });
192
200 const StyleProperties& style = { Color::dark_gray(0.5) });
201
209 void draw_car(const Vector &c, const Matrix &A,
210 const StyleProperties& style = { Color::yellow(0.5) });
211
220 void draw_plane(const Vector &c, const Matrix &A, bool yaw_is_up=true,
221 const StyleProperties& style = { Color::dark_gray(0.8f) });
222
223
224 // Pavings
225
232 void draw_paving(const PavingOut& p,
233 const StyleProperties& bound_style = { Color::yellow(0.5) });
234
242 void draw_paving(const PavingInOut& p,
243 const StyleProperties& bound_style = { Color::yellow(0.3f), "paving_bound" },
244 const StyleProperties& in_style = { Color::green(0.5) , "paving_in" });
245
252 template<typename P>
253 inline void draw_subpaving(const Subpaving<P>& p, const StyleProperties& style = StyleProperties())
254 {
255 for(const auto& pi : p.boxes())
256 draw_box(pi, style);
257 }
258
259 private:
268 size_t move_write_v(const Vector &c, const Matrix &A, const Vector &p);
269
275 void set_color_internal(const Color &c);
276
284 void set_style_internal(const StyleProperties& style);
285
286 protected:
287
288 const std::string _name;
289 std::ofstream _file;
290 std::function<Vector(const Vector&)> _projection;
291 size_t vertex_count = 0;
292 bool lock_style=false;
293 };
294}
Ellipsoid representation.
Definition codac2_Ellipsoid.h:47
void draw_sphere(const Vector &c, const Matrix &A, const StyleProperties &style={ Color::dark_gray(0.5) })
Draws a sphere (ellipsoid).
void draw_box(const IntervalVector &x, const StyleProperties &style={ Color::dark_gray(0.5) })
Draws a box on the figure.
void draw_polygon(const Vector &c, const Matrix &A, const std::vector< Vector > &l, const StyleProperties &style={ Color::dark_gray(0.5) })
Draws a star-shaped polygon as a sequence of adjacent triangles (l[0],l[k],l[k+1]) with k>=1.
void draw_triangle(const Vector &p1, const Vector &p2, const Vector &p3, const StyleProperties &style={ Color::dark_gray(0.5) })
Draws a triangle, shorter version.
void draw_triangle(const Vector &c, const Matrix &A, const Vector &p1, const Vector &p2, const Vector &p3, const StyleProperties &style={ Color::dark_gray(0.5) })
Draws a triangle.
void draw_surface(const Vector &c, const Matrix &A, const Interval &Ip1, double dp1, const Interval &Ip2, double dp2, std::function< Vector(double, double)> f, const StyleProperties &style={ Color::dark_gray(0.5) })
Draws a parametric surface.
const std::string & name() const
Getter for the name of the figure.
void draw_ellipsoid(const Ellipsoid &e, const StyleProperties &style={ Color::dark_gray(0.5) })
Draws an ellipsoid (from the Ellipsoid class).
void draw_plane(const Vector &c, const Matrix &A, bool yaw_is_up=true, const StyleProperties &style={ Color::dark_gray(0.8f) })
Draws a (paper) plane.
void draw_paving(const PavingInOut &p, const StyleProperties &bound_style={ Color::yellow(0.3f), "paving_bound" }, const StyleProperties &in_style={ Color::green(0.5), "paving_in" })
Draws a paving on the figure (Only the boundary and the inside is drawn).
~Figure3D()
Destructor for the Figure3D class.
void draw_axes(double size=1.0, const Vector &origin=Vector::Zero(3))
Draws the (x,y,z) axes on the figure in red, green and blue.
Figure3D(const std::string &name)
Creates a new Figure3D object, with a given name.
void draw_zonotope(const Zonotope &z, const StyleProperties &style={ Color::dark_gray(0.5) })
Draws a zonotope c+sum_i [-1,1] A_i on the figure.
void draw_paving(const PavingOut &p, const StyleProperties &bound_style={ Color::yellow(0.5) })
Draws a paving on the figure (Only the boundary is drawn).
void draw_parallelepiped(const Parallelepiped &p, const StyleProperties &style={ Color::dark_gray(0.5) })
Draws a parallelepiped z+A*[-1,1]^3 on the figure.
void draw_car(const Vector &c, const Matrix &A, const StyleProperties &style={ Color::yellow(0.5) })
Draws a car, with blue windscreen.
void draw_subpaving(const Subpaving< P > &p, const StyleProperties &style=StyleProperties())
Draws a subpaving on the figure.
Definition codac2_Figure3D.h:253
void draw_arrow(const Vector &c, const Matrix &A, const StyleProperties &style={ Color::dark_gray(0.5) })
Draws an arrow (box c + A * ([0,1],[-0.01,0.01],[-0.01,0.01]) and a tip at the end).
Figure3D & set_projection(std::function< Vector(const Vector &)> projection)
Defines an optional coordinate projection applied to OBJ vertices. Pass an empty projection to restor...
void draw_parallelogram(const Vector &c, const Matrix &A, const Vector &p, const Vector &v1, const Vector &v2, const StyleProperties &style={ Color::dark_gray(0.5) })
Draws a parallelogram c + A (p + [-1,1]*v1 + [-1,1]*v2).
Interval class, for representing closed and connected subsets of .
Definition codac2_Interval.h:50
Class representing a parallelepiped .
Definition codac2_Parallelepiped.h:31
Class representing a zonotope .
Definition codac2_Zonotope.h:29
Definition codac2_OctaSym.h:21
Eigen::Matrix< double,-1, 1 > Vector
Alias for a dynamically-sized column vector of doubles.
Definition codac2_Vector.h:24
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 > Matrix
Alias for a dynamic-size matrix of doubles.
Definition codac2_Matrix.h:26
Color structure, in RGBA or HSVA format.
Definition codac2_Color.h:44
Style properties structure, to specify the style of a shape.
Definition codac2_StyleProperties.h:27