g4tools  5.4.0
line_set
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
2 // See the file tools.license for terms.
3 
4 #ifndef tools_sg_line_set
5 #define tools_sg_line_set
6 
7 #include "node"
8 
9 #include "mf"
10 #include "../stype"
11 #include "render_action"
12 #include "pick_action"
13 #include "bbox_action"
14 
15 namespace tools {
16 namespace sg {
17 
18 class line_set : public node {
20 public:
22 public:
23  virtual const desc_fields& node_desc_fields() const {
25  static const desc_fields s_v(parent::node_desc_fields(),1, //WARNING : take care of count.
27  );
28  return s_v;
29  }
30 private:
31  void add_fields(){
32  add_field(&lines);
33  }
34 public:
35  typedef std::vector<float> line_t;
36 
37  virtual void render(render_action& a_action) {
39  a_action.draw_vertex_array(gl::line_strip(),*it);
40  }
41  }
42 
43  virtual void pick(pick_action& a_action) {
44  if(a_action.stop_at_first()){
46  a_action.add_line_strip(*it);
47  if(a_action.done()) {
48  a_action.set_node(this);
49  return;
50  }
51  }
52  } else {
54  a_action.set_done(false);
55  a_action.zs().clear();
56  a_action.ws().clear();
57  a_action.add_line_strip(*it);
58  if(a_action.done()) {
59  a_action.add_pick(*this,a_action.zs(),a_action.ws(),a_action.state());
60  a_action.set_done(false);
61  }
62  }
63  }
64  }
65 
66  virtual void bbox(bbox_action& a_action) {
68  a_action.add_points(*it);
69  }
70  }
71 
72 public:
74  :parent()
75  ,lines()
76  {
77 #ifdef TOOLS_MEM
78  mem::increment(s_class().c_str());
79 #endif
80  add_fields();
81  }
82  virtual ~line_set(){
83 #ifdef TOOLS_MEM
84  mem::decrement(s_class().c_str());
85 #endif
86  }
87 public:
88  line_set(const line_set& a_from)
89  :parent(a_from)
90  ,lines(a_from.lines)
91  {
92 #ifdef TOOLS_MEM
93  mem::increment(s_class().c_str());
94 #endif
95  add_fields();
96  }
97  line_set& operator=(const line_set& a_from){
98  parent::operator=(a_from);
99  lines = a_from.lines;
100  return *this;
101  }
102 public:
103  bool add(const line_t& a_line) {
104  size_t npoint = a_line.size()/3;
105  if(npoint*3!=a_line.size()) return false;
106  lines.add(a_line);
107  return true;
108  }
109  void clear() {lines.clear();}
110 };
111 
112 }}
113 
114 #endif
tools::sg::pick_action::zs
const std::vector< float > & zs() const
Definition: pick_action:320
tools::sg::mf_std_vec< float >
node
tools::sg::render_action::draw_vertex_array
virtual void draw_vertex_array(gl::mode_t, size_t, const float *)=0
tools::sg::line_set::node_desc_fields
virtual const desc_fields & node_desc_fields() const
Definition: line_set:23
tools::sg::line_set::line_set
line_set()
Definition: line_set:73
tools::sg::line_set::render
virtual void render(render_action &a_action)
Definition: line_set:37
tools::sg::bmf::add
void add(const T &a_value)
Definition: bmf:73
pick_action
render_action
tools::sg::pick_action::set_node
void set_node(sg::node *a_node)
Definition: pick_action:257
tools::sg::node
Definition: node:28
tools::sg::bbox_action
Definition: bbox_action:15
TOOLS_NODE
#define TOOLS_NODE(a__class, a__sclass, a__parent)
Definition: node:324
mf
tools::sg::pick_action::add_pick
void add_pick(sg::node &a_node, const std::vector< float > &a_zs, const std::vector< float > &a_ws, const sg::state &a_state)
Definition: pick_action:265
tools::gl::line_strip
mode_t line_strip()
Definition: glprims:19
tools::sg::pick_action::stop_at_first
bool stop_at_first() const
Definition: pick_action:252
tools::sg::desc_fields
Definition: field_desc:148
tools::sg::pick_action::set_done
void set_done(bool a_value)
Definition: pick_action:254
tools::sg::bmf::values
const std::vector< T > & values() const
Definition: bmf:71
tools::sg::pick_action
Definition: pick_action:59
tools::sg::line_set::bbox
virtual void bbox(bbox_action &a_action)
Definition: line_set:66
tools::sg::line_set
Definition: line_set:18
tools::sg::line_set::operator=
line_set & operator=(const line_set &a_from)
Definition: line_set:97
tools::sg::primitive_visitor::add_points
bool add_points(size_t a_floatn, const float *a_xyzs, bool a_stop=false)
Definition: primitive_visitor:1405
tools::sg::render_action
Definition: render_action:24
tools::sg::line_set::line_set
line_set(const line_set &a_from)
Definition: line_set:88
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::sg::bmf::clear
void clear()
Definition: bmf:108
tools::sg::node::add_field
void add_field(field *a_field)
Definition: node:128
tools::sg::primitive_visitor::add_line_strip
bool add_line_strip(size_t a_floatn, const float *a_xyzs, bool a_stop=false)
Definition: primitive_visitor:787
tools::sg::line_set::add
bool add(const line_t &a_line)
Definition: line_set:103
tools::sg::line_set::pick
virtual void pick(pick_action &a_action)
Definition: line_set:43
tools::sg::pick_action::done
bool done() const
Definition: pick_action:255
TOOLS_FIELD_DESC_NODE_CLASS
#define TOOLS_FIELD_DESC_NODE_CLASS(a__class)
Definition: field:68
tools::sg::pick_action::ws
const std::vector< float > & ws() const
Definition: pick_action:323
tools::sg::line_set::clear
void clear()
Definition: line_set:109
tools_vforcit
#define tools_vforcit(a__T, a__v, a__it)
Definition: forit:7
tools::sg::states::state
const sg::state & state() const
Definition: states:76
tools::sg::line_set::line_t
std::vector< float > line_t
Definition: line_set:35
tools::sg::line_set::~line_set
virtual ~line_set()
Definition: line_set:82
tools::sg::line_set::lines
mf_std_vec< float > lines
Definition: line_set:21
TOOLS_ARG_FIELD_DESC
#define TOOLS_ARG_FIELD_DESC(a__field)
Definition: field:71
bbox_action