Bayeux  3.4.1
Core Foundation library for SuperNEMO
gnuplot_drawer.h
Go to the documentation of this file.
1 /* Author(s) : Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date: 2010-02-20
4  * Last modified: 2014-07-16
5  *
6  * License:
7  *
8  * Description:
9  *
10  * Algorithm to recursively draw the geometry using gnuplot.
11  *
12  * History:
13  *
14  */
15 
16 #ifndef GEOMTOOLS_GNUPLOT_DRAWER_H
17 #define GEOMTOOLS_GNUPLOT_DRAWER_H 1
18 
19 // Standard library:
20 #include <iostream>
21 #include <string>
22 #include <sstream>
23 
24 // Third party:
25 // - Bayeux/datatools:
26 #include <datatools/properties.h>
27 
28 // This project:
29 #include <geomtools/placement.h>
30 
31 namespace geomtools {
32 
33  // Forward declarations:
34  class model_factory;
35  class logical_volume;
36  class display_data;
37  class geom_id;
38  class mapping;
39  class manager;
40 
43  {
44  public:
45 
46  static const int DISPLAY_LEVEL_NO_LIMIT = 1000;
47 
48  static int display_level_no_limit();
49  static const std::string & view_key();
50  static const std::string & view_2d_xy();
51  static const std::string & view_2d_xz();
52  static const std::string & view_2d_yz();
53  static const std::string & view_3d();
54  static const std::string & view_3d_free_scale();
55  static const std::string & default_view();
56  static bool check_view(const std::string & view_label_);
57  static const std::string & mode_wired();
58  static const std::string & mode_solid();
59  static const std::string & default_mode();
60  static const std::string & force_show_property_name();
61  static const std::string & force_show_envelope_property_name();
62  static const std::string & force_show_children_property_name();
63  static const std::string & force_hide_envelope_property_name();
64  static const std::string & force_hide_children_property_name();
65  static const std::string & world_name_key();
66 
68  static void wait_for_key ();
69 
71  struct cstream
72  {
73  std::string label;
74  std::string filename;
75  std::ostringstream * oss;
76  int color;
77 
78  cstream ();
79  };
80 
82  typedef std::map<std::string, cstream> cstreams_col_type;
83 
85  class dd_entry
86  {
87  public:
88  dd_entry();
89  void reset();
90  void set_placement(const placement &);
91  void set_display_data(const display_data &);
92  const placement & get_placement() const;
93  const display_data & get_display_data() const;
94  bool is_valid() const;
95  private:
96  placement _pl_;
97  const display_data * _dd_address_;
98  };
99 
102  {
103  public:
104  has_dd_addr(const display_data &);
105  bool operator()(const dd_entry & dde_) const;
106  private:
107  const display_data * _dd_address_;
108  };
109 
111  typedef std::vector<dd_entry> dd_col_type;
112 
116  void reset();
117  public:
118  bool active;
123  std::string color;
124  };
125 
126  public:
127 
128  // Set the Gnuplot output
129  void set_output (const std::string & output_);
130 
131  // Reset the Gnuplot output
132  void reset_output ();
133 
135  void set_terminal (const std::string & terminal_ = "",
136  const std::string & terminal_options_ = "");
137 
139  void reset_terminal ();
140 
141  // Set the Gnuplot output medium
142  int set_output_medium (const std::string & file_ = "",
143  const std::string & terminal_ = "",
144  const std::string & terminal_options_ = "");
145 
147  void set_view (const std::string & view_);
148 
150  const std::string & get_view () const;
151 
153  void set_mode (const std::string & mode_);
154 
156  const std::string & get_mode () const;
157 
159  void set_labels (bool labels_);
160 
162  bool use_labels () const;
163 
165  void set_using_title (bool);
166 
168  bool use_title () const;
169 
171  bool is_view_2d () const;
172 
174  bool is_view_3d () const;
175 
177  bool is_solid () const;
178 
180  bool is_wired () const;
181 
183  bool is_initialized () const;
184 
185  // visibility_rules & grab_vis_rules();
186 
187  // const visibility_rules & grab_vis_rules() const;
188 
191 
193  const datatools::properties & get_properties () const;
194 
196  gnuplot_drawer ();
197 
199  virtual ~gnuplot_drawer ();
200 
202  void reset ();
203 
205  void reset_cstreams ();
206 
208  void print (std::ostream & out_) const;
209 
211  int draw (const manager & mgr_,
212  const std::string & what_ = "",
213  int max_display_level_ = 0);
214 
216  void draw_logical (const logical_volume & log_,
217  const placement & p_,
218  int max_display_level_,
219  const std::string & title_,
220  bool drawing_display_data_ = false);
221 
223  void draw_model (const model_factory & mf_,
224  const std::string & model_name_,
225  const placement & p_,
226  int max_display_level_);
227 
229  void draw_physical_from_gid (const model_factory & mf_,
230  const geom_id & gid_,
231  const mapping & mapping_,
232  int max_display_level_);
233 
235  void draw_logical (const model_factory & mf_,
236  const std::string & logical_name_,
237  const placement & p_,
238  int max_display_level_);
239 
241  void set_drawing_display_data(bool);
242 
244  bool is_drawing_display_data() const;
245 
247  void add_display_data(const display_data & dd_);
248 
250  void add_display_data(const display_data & dd_, const placement & pl_);
251 
253  void reset_display_data();
254 
256  void set_rendering_options_current(uint32_t flags_);
257 
260 
262  void set_rendering_options_depth(int32_t depth_);
263 
266 
267  protected:
268 
269  void _draw_display_data(const model_factory & mf_,
270  const placement & p_);
271 
272  void _draw_display_data(const placement & p_);
273 
274  std::ostringstream & _get_stream(const std::string & section_);
275 
276  private:
277 
278  void _draw_(const logical_volume & log_,
279  const placement & p_,
280  int max_display_level_ = 0);
281 
282  /*
283  // Future : enrich the interface of the '_draw_' method...
284  void _draw_ (const logical_volume & log_,
285  const placement & p_,
286  const visibility_rules & vis_rules_);
287  */
288 
289  public:
290 
291  struct range
292  {
293  char axis;
294  double min;
295  double max;
296  range (char axis_ = 0);
297  void reset ();
298  void set_axis (char axis_);
299  void print (std::ostream & out_) const;
300  };
301 
302  private:
303 
304  bool _initialized_;
305  cstreams_col_type _cstreams_;
306  datatools::properties _props_;
307  std::string _view_;
308  bool _using_title_;
309  bool _labels_;
310  std::string _mode_;
311  range _xrange_;
312  range _yrange_;
313  range _zrange_;
314  //visibility_rules _vis_rules_;
315  bool _drawing_display_data_;
316  dd_col_type _display_data_;
317  std::string _terminal_;
318  std::string _terminal_options_;
319  std::string _output_;
320  int _max_display_level_; // XXX
321  uint32_t _rendering_options_current_;
322  int32_t _rendering_options_depth_;
323 
324  }; // class gnuplot_drawer
325 
326 } // end of namespace snemo
327 
328 #endif // GEOMTOOLS_GNUPLOT_DRAWER_H
329 
330 /*
331 ** Local Variables: --
332 ** mode: c++ --
333 ** c-file-style: "gnu" --
334 ** tab-width: 2 --
335 ** End: --
336 */
std::string label
Definition: gnuplot_drawer.h:73
int color
Definition: gnuplot_drawer.h:76
bool show_envelope
Definition: gnuplot_drawer.h:120
std::vector< dd_entry > dd_col_type
Collection of display data handle.
Definition: gnuplot_drawer.h:111
void set_output(const std::string &output_)
std::string filename
Definition: gnuplot_drawer.h:74
void reset()
bool active
Definition: gnuplot_drawer.h:118
static const std::string & force_hide_envelope_property_name()
dd_entry()
The geometry ID mapping.
Definition: mapping.h:43
static const std::string & force_hide_children_property_name()
const std::string & get_mode() const
Return the display mode.
static const std::string & view_key()
static const std::string & view_2d_xy()
const placement & get_placement() const
void draw_physical_from_gid(const model_factory &mf_, const geom_id &gid_, const mapping &mapping_, int max_display_level_)
Draw a physical volume given its GID its the world reference frame.
static const std::string & force_show_children_property_name()
Storage entry for embedded display data.
Definition: gnuplot_drawer.h:85
void draw_model(const model_factory &mf_, const std::string &model_name_, const placement &p_, int max_display_level_)
Draw a geometry model in its own reference frame.
bool is_initialized() const
Check intialization flag.
void set_display_data(const display_data &)
void set_terminal(const std::string &terminal_="", const std::string &terminal_options_="")
Set Gnuplot terminal and options.
void set_rendering_options_current(uint32_t flags_)
Set shape rendering options.
int daughter_level
Definition: gnuplot_drawer.h:122
int draw(const manager &mgr_, const std::string &what_="", int max_display_level_=0)
Main display method.
void reset_cstreams()
Reset colored streams.
static const std::string & mode_solid()
double min
Definition: gnuplot_drawer.h:294
bool show_daughters
Definition: gnuplot_drawer.h:121
Predicate that tests the address of a display data.
Definition: gnuplot_drawer.h:101
static const std::string & view_2d_yz()
A logical geometry volume (ala GDML)
Definition: logical_volume.h:40
bool use_title() const
Check 'title' flag.
virtual ~gnuplot_drawer()
Destructor.
static const std::string & default_view()
int set_output_medium(const std::string &file_="", const std::string &terminal_="", const std::string &terminal_options_="")
static const std::string & force_show_property_name()
void set_placement(const placement &)
void reset_rendering_options_current()
Reset shape rendering options.
bool is_solid() const
Check 'solid display' flag.
bool is_drawing_display_data() const
Return the flag to draw embedded display data.
static const std::string & force_show_envelope_property_name()
char axis
Definition: gnuplot_drawer.h:293
static bool check_view(const std::string &view_label_)
void _draw_display_data(const model_factory &mf_, const placement &p_)
void reset_rendering_options_depth()
Reset shape rendering options depth.
static const std::string & view_3d()
An Gnuplot driver object responsible of the display of a virtual geometry.
Definition: gnuplot_drawer.h:42
static const std::string & view_3d_free_scale()
void set_mode(const std::string &mode_)
Set the display mode.
void print(std::ostream &out_) const
std::ostringstream * oss
Definition: gnuplot_drawer.h:75
double max
Definition: gnuplot_drawer.h:295
void set_labels(bool labels_)
Set the 'labels' flag.
bool is_view_3d() const
Check '3D display' flag.
void draw_logical(const logical_volume &log_, const placement &p_, int max_display_level_, const std::string &title_, bool drawing_display_data_=false)
Draw a logical volume in its own reference frame.
void set_drawing_display_data(bool)
Set the flag to draw embedded display data.
static const std::string & world_name_key()
Definition: gnuplot_drawer.h:291
static void wait_for_key()
Wait for key stroke in interactive Gnuplot session.
Colored stream handle.
Definition: gnuplot_drawer.h:71
static const std::string & mode_wired()
bool show_volume
Definition: gnuplot_drawer.h:119
void set_using_title(bool)
Set the 'title' flag.
std::map< std::string, cstream > cstreams_col_type
Dictionary of colored stream handle.
Definition: gnuplot_drawer.h:82
static const std::string & view_2d_xz()
static const int DISPLAY_LEVEL_NO_LIMIT
Definition: gnuplot_drawer.h:46
Geometry manager for virtual geometry modelling. Main geometry manager for the modelisation of variou...
Definition: manager.h:70
void set_view(const std::string &view_)
Set the display view.
The placement for a geometry volume with its translation and rotation with respect to some mother ref...
Definition: placement.h:34
The factory of geometry models.
Definition: model_factory.h:40
Visibility rules for 3D volume rendering.
Definition: gnuplot_drawer.h:114
void reset_display_data()
Remove all display data formerly added to the scene.
Definition: geom_id.h:41
datatools::properties & grab_properties()
Return a mutable reference to the embedded auxiliary properties.
static int display_level_no_limit()
const std::string & get_view() const
Return the display view.
bool is_wired() const
Check 'wired display' flag.
bool is_valid() const
void print(std::ostream &out_) const
Basic print.
bool is_view_2d() const
Check '2D display' flag.
bool operator()(const dd_entry &dde_) const
gnuplot_drawer()
Default constructor.
void add_display_data(const display_data &dd_)
Add a display data object in the scene to be drawn.
const display_data & get_display_data() const
static const std::string & default_mode()
const datatools::properties & get_properties() const
Return a non mutable reference to the embedded auxiliary properties.
std::ostringstream & _get_stream(const std::string &section_)
void set_rendering_options_depth(int32_t depth_)
Set shape rendering options depth.
std::string color
Definition: gnuplot_drawer.h:123
bool use_labels() const
Check 'labels' flag.
void reset_terminal()
Reset Gnuplot terminal and options.
Definition: display_data.h:41
Top-level namespace of the Bayeux/geomtools module library.
Definition: electromagnetic_field_manager.h:39
A dictionary of arbitrary properties.
Definition: properties.h:125