Draw_3D_API
Dr3D_gnuplot_api.hh
Go to the documentation of this file.
1 /*
2 Copyright 2020 Arkadiusz Mielczarek
3 
4 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 
6 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 
8 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 */
10 
11 #ifndef DR3D_GPLT_API_HH
12 #define DR3D_GPLT_API_HH
13 
14 #include "Draw3D_api_interface.hh"
15 #include <list>
16 #include <map>
17 #include <utility>
18 #include <memory>
19 #include <mutex>
20 #include <thread>
21 
22 using shape_and_color = std::pair<std::list<std::list<drawNS::Point3D> >,std::string>;
23 
24 namespace drawNS {
25 
40  int pipe_fd[2];
44  std::unique_ptr<std::thread> refresh_thread_ptr;
48  std::mutex gnuplot_pipe_mutex;
52  int gnuplot_pid;
56  std::string intro;
61  std::string command;
65  uint last_shape;
69  std::map<uint,shape_and_color> shapes;
70  void send2gnuplot(const std::string & command_arg);
71  void replot_loop();
72  uint add2shape_list(const std::list<std::list<Point3D> > & _list, const std::string & color);
73  void draw_all_shapes();
74  std::string translate_color(const std::string & color) const;
75  void stop_drawing_proces();
76 public:
80  APIGnuPlot3D() = delete;
91  APIGnuPlot3D(double minX, double maxX, double minY, double maxY, double minZ, double maxZ, int ref_time_ms = 0);
95  ~APIGnuPlot3D() {stop_drawing_proces();}
96  uint draw_line(const Point3D & point1, const Point3D & point2, const std::string & color = "black") override;
97  uint draw_polygonal_chain(const std::vector<Point3D> & points, const std::string & color = "black") override;
98  uint draw_polyhedron(const std::vector<std::vector<Point3D> > & points_map, const std::string & color = "black") override;
99  uint draw_surface(const std::vector<std::vector<Point3D> > & points_map, const std::string & color = "black") override;
100  void erase_shape(uint id) override;
101  void change_shape_color(uint id, const std::string & color) override;
102  void change_ref_time_ms(int ref_time_ms) override;
103  void redraw() override;
104 };
105 
106 }
107 
108 #endif
uint draw_polyhedron(const std::vector< std::vector< Point3D > > &points_map, const std::string &color="black") override
draws polyhedron described by its apexs
Definition: Dr3D_gnuplot_api.cpp:156
void redraw() override
replot all shapes Replots all shapes, works only in negative refresh_rate_ms value mode...
Definition: Dr3D_gnuplot_api.cpp:214
~APIGnuPlot3D()
destructor, also stops gnuplot proces.
Definition: Dr3D_gnuplot_api.hh:95
void change_shape_color(uint id, const std::string &color) override
change color of shape
Definition: Dr3D_gnuplot_api.cpp:188
void change_ref_time_ms(int ref_time_ms) override
change mode for ploting and/or time between auto-replots
Definition: Dr3D_gnuplot_api.cpp:204
Implementation drawing 3D class using gnuplot Class implements proxy between gnuplot and C++ code...
Definition: Dr3D_gnuplot_api.hh:36
APIGnuPlot3D()=delete
deleted non-parametric constructor to force using parametric.
uint draw_surface(const std::vector< std::vector< Point3D > > &points_map, const std::string &color="black") override
draws surface described by its points
Definition: Dr3D_gnuplot_api.cpp:167
Abstract interface for drawing class Abstract class used as interface for 3D drawing class implementa...
Definition: Draw3D_api_interface.hh:87
std::pair< std::list< std::list< drawNS::Point3D > >, std::string > shape_and_color
Definition: Dr3D_gnuplot_api.hh:22
void erase_shape(uint id) override
erase shape by id
Definition: Dr3D_gnuplot_api.cpp:181
uint draw_polygonal_chain(const std::vector< Point3D > &points, const std::string &color="black") override
draws polygonal_chain between n points
Definition: Dr3D_gnuplot_api.cpp:148
Point in 3D Class represents point in 3D.
Definition: Draw3D_api_interface.hh:35
uint draw_line(const Point3D &point1, const Point3D &point2, const std::string &color="black") override
draws line between 2 points
Definition: Dr3D_gnuplot_api.cpp:140
Namespace for drawing tools - abstract interface and 3D point Namespace for drawing tools - abstract ...
Definition: Dr3D_gnuplot_api.hh:24