g4tools  5.4.0
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
tools::sg::vertices Class Reference
Inheritance diagram for tools::sg::vertices:
Inheritance graph
[legend]
Collaboration diagram for tools::sg::vertices:
Collaboration graph
[legend]

Public Member Functions

virtual const desc_fieldsnode_desc_fields () const
 
virtual void render (render_action &a_action)
 
virtual void pick (pick_action &a_action)
 
virtual void bbox (bbox_action &a_action)
 
virtual void is_visible (visible_action &a_action)
 
 vertices ()
 
virtual ~vertices ()
 
 vertices (const vertices &a_from)
 
verticesoperator= (const vertices &a_from)
 
template<class VEC >
void add (const VEC &a_v)
 
void add (float a_x, float a_y, float a_z)
 
void add_allocated (size_t &a_pos, float a_x, float a_y, float a_z)
 
bool add (const std::vector< float > &a_v)
 
size_t number () const
 
void clear ()
 
bool add_dashed_line (float a_bx, float a_by, float a_bz, float a_ex, float a_ey, float a_ez, unsigned int a_num_dash)
 
bool center ()
 
- Public Member Functions inherited from tools::sg::node
virtual void * cast (const std::string &a_class) const
 
virtual const std::string & s_cls () const =0
 
virtual nodecopy () const =0
 
virtual unsigned int cls_version () const
 
virtual void search (search_action &a_action)
 
virtual void get_matrix (get_matrix_action &a_action)
 
virtual bool write (write_action &a_action)
 
virtual void event (event_action &)
 
virtual bool read (read_action &a_action)
 
virtual void protocol_one_fields (std::vector< field * > &a_fields) const
 
virtual bool draw_in_frame_buffer () const
 
virtual bool touched ()
 
virtual void reset_touched ()
 
 node ()
 
virtual ~node ()
 
void touch ()
 
fieldfield_from_desc (const field_desc &a_desc) const
 
void dump_field_descs (std::ostream &a_out) const
 
fieldfind_field_by_name (const std::string &a_name) const
 
- Public Member Functions inherited from tools::sg::gstos
size_t num_gstos () const
 

Public Attributes

sf< gl::mode_tmode
 
mf< float > xyzs
 

Protected Member Functions

virtual unsigned int create_gsto (std::ostream &, sg::render_manager &a_mgr)
 
bool _is_visible (const matrix_action &a_action)
 
- Protected Member Functions inherited from tools::sg::node
 node (const node &)
 
nodeoperator= (const node &)
 
void add_field (field *a_field)
 
bool write_fields (write_action &a_action)
 
bool read_fields (read_action &a_action)
 
field_desc::offset_t field_offset (const field *a_field) const
 
fieldfind_field (const field_desc &a_rdesc) const
 
void check_fields (std::ostream &a_out) const
 
- Protected Member Functions inherited from tools::sg::gstos
 gstos ()
 
virtual ~gstos ()
 
 gstos (const gstos &)
 
gstosoperator= (const gstos &a_from)
 
unsigned int get_tex_id (std::ostream &a_out, render_manager &a_mgr, const img_byte &a_img, bool a_NEAREST)
 
unsigned int get_gsto_id (std::ostream &a_out, render_manager &a_mgr)
 
void clean_gstos ()
 
void clean_gstos (render_manager *a_mgr)
 
unsigned int _find (render_manager *a_mgr)
 

Additional Inherited Members

- Protected Attributes inherited from tools::sg::gstos
std::vector< std::pair< unsigned int, render_manager * > > m_gstos
 

Detailed Description

Definition at line 22 of file vertices.

Constructor & Destructor Documentation

◆ vertices() [1/2]

tools::sg::vertices::vertices ( )
inline

Definition at line 119 of file vertices.

120  :parent()
121  ,mode(gl::line_strip()){
122 #ifdef TOOLS_MEM
123  mem::increment(s_class().c_str());
124 #endif
125  add_fields();
126  }

◆ ~vertices()

virtual tools::sg::vertices::~vertices ( )
inlinevirtual

Definition at line 127 of file vertices.

127  {
128 #ifdef TOOLS_MEM
129  mem::decrement(s_class().c_str());
130 #endif
131  }

◆ vertices() [2/2]

tools::sg::vertices::vertices ( const vertices a_from)
inline

Definition at line 133 of file vertices.

134  :parent(a_from)
135  ,parent_gstos(a_from)
136  ,mode(a_from.mode)
137  ,xyzs(a_from.xyzs)
138  {
139 #ifdef TOOLS_MEM
140  mem::increment(s_class().c_str());
141 #endif
142  add_fields();
143  }

Member Function Documentation

◆ _is_visible()

bool tools::sg::vertices::_is_visible ( const matrix_action a_action)
inlineprotected

Definition at line 240 of file vertices.

240  {
241  if(xyzs.empty()) return false;
242  const state& _state = a_action.state();
243  pick_action action(a_action.out(),_state.m_ww,_state.m_wh,0,float(_state.m_ww),0,float(_state.m_wh));
244  action.set_win_size(_state.m_ww,_state.m_wh);
245  action.set_area(0,float(_state.m_ww),0,float(_state.m_wh));
246  action.set_stop_at_first(true);
247  action.matrix_action::operator=(a_action); //IMPORTANT.
248  int old_cur = action.cur(); //not 0.
249  action.add__primitive(*this,mode.value(),xyzs.values(),true);
250  if(action.cur()!=old_cur) return false;
251  if(!action.node()) return false;
252  return true;
253  }

◆ add() [1/3]

bool tools::sg::vertices::add ( const std::vector< float > &  a_v)
inline

Definition at line 172 of file vertices.

172  {
173  std::vector<float>::size_type _number = a_v.size()/3;
174  if(3*_number!=a_v.size()) return false;
175  std::vector<float>::const_iterator it;
176  for(it=a_v.begin();it!=a_v.end();it+=3) {
177  xyzs.add(*(it+0));
178  xyzs.add(*(it+1));
179  xyzs.add(*(it+2));
180  }
181  return true;
182  }

◆ add() [2/3]

template<class VEC >
void tools::sg::vertices::add ( const VEC &  a_v)
inline

Definition at line 155 of file vertices.

155  {
156  xyzs.add(a_v.x());
157  xyzs.add(a_v.y());
158  xyzs.add(a_v.z());
159  }

◆ add() [3/3]

void tools::sg::vertices::add ( float  a_x,
float  a_y,
float  a_z 
)
inline

Definition at line 160 of file vertices.

160  {
161  xyzs.add(a_x);
162  xyzs.add(a_y);
163  xyzs.add(a_z);
164  }

◆ add_allocated()

void tools::sg::vertices::add_allocated ( size_t &  a_pos,
float  a_x,
float  a_y,
float  a_z 
)
inline

Definition at line 165 of file vertices.

165  {
166  std::vector<float>& v = xyzs.values();
167  v[a_pos] = a_x;a_pos++;
168  v[a_pos] = a_y;a_pos++;
169  v[a_pos] = a_z;a_pos++;
170  xyzs.touch();
171  }

◆ add_dashed_line()

bool tools::sg::vertices::add_dashed_line ( float  a_bx,
float  a_by,
float  a_bz,
float  a_ex,
float  a_ey,
float  a_ez,
unsigned int  a_num_dash 
)
inline

Definition at line 187 of file vertices.

189  {
190  //optimized version.
191  if(!a_num_dash) return false;
192  // there is a dash at beg and end of line.
193 
194  float fac = 1.0f/float(2*a_num_dash-1);
195  float sx = (a_ex-a_bx)*fac;
196  float sy = (a_ey-a_by)*fac;
197  float sz = (a_ez-a_bz)*fac;
198 
199  float two_sx = sx*2.0f;
200  float two_sy = sy*2.0f;
201  float two_sz = sz*2.0f;
202 
203  float px = a_bx;
204  float py = a_by;
205  float pz = a_bz;
206 
207  for(unsigned int idash=0;idash<a_num_dash;idash++) {
208  add(px,py,pz);
209  add(px+sx,py+sy,pz+sz);
210  px += two_sx;
211  py += two_sy;
212  pz += two_sz;
213  }
214  return true;
215  }

◆ bbox()

virtual void tools::sg::vertices::bbox ( bbox_action a_action)
inlinevirtual

Reimplemented from tools::sg::node.

Definition at line 109 of file vertices.

109  {
110  if(touched()) {clean_gstos();reset_touched();}
111  a_action.add_points(xyzs.values());
112  }

◆ center()

bool tools::sg::vertices::center ( )
inline

Definition at line 216 of file vertices.

216  {
217  std::vector<float>& v = xyzs.values();
218  std::vector<float>::size_type _number = v.size()/3;
219  if(!_number) return true;
220  if(3*_number!=v.size()) return false;
221  float x_mean = 0;
222  float y_mean = 0;
223  float z_mean = 0;
224  {for(std::vector<float>::const_iterator it=v.begin();it!=v.end();it+=3) {
225  x_mean += *(it+0);
226  y_mean += *(it+1);
227  z_mean += *(it+2);
228  }}
229  x_mean /= float(_number);
230  y_mean /= float(_number);
231  z_mean /= float(_number);
232  {for(std::vector<float>::iterator it=v.begin();it!=v.end();it+=3) {
233  *(it+0) -= x_mean;
234  *(it+1) -= y_mean;
235  *(it+2) -= z_mean;
236  }}
237  return true;
238  }

◆ clear()

void tools::sg::vertices::clear ( )
inline

Definition at line 185 of file vertices.

185 {xyzs.clear();}

◆ create_gsto()

virtual unsigned int tools::sg::vertices::create_gsto ( std::ostream &  ,
sg::render_manager a_mgr 
)
inlineprotectedvirtual

Reimplemented from tools::sg::gstos.

Reimplemented in tools::sg::atb_vertices.

Definition at line 43 of file vertices.

43  {
44  //unsigned int npt = xyzs.values().size()/3;
45  //::printf("debug : vertices : %lu : create_gsto : %u\n",this,npt);
46  return a_mgr.create_gsto_from_data(xyzs.values());
47  }

◆ is_visible()

virtual void tools::sg::vertices::is_visible ( visible_action a_action)
inlinevirtual

Reimplemented from tools::sg::node.

Definition at line 113 of file vertices.

113  {
114  if(touched()) {clean_gstos();reset_touched();}
115  if(_is_visible(a_action)) a_action.increment();
116  }

◆ node_desc_fields()

virtual const desc_fields& tools::sg::vertices::node_desc_fields ( ) const
inlinevirtual

Reimplemented from tools::sg::node.

Reimplemented in tools::sg::atb_vertices.

Definition at line 29 of file vertices.

29  {
31  static const desc_fields s_v(parent::node_desc_fields(),2, //WARNING : take care of count.
34  );
35  return s_v;
36  }

◆ number()

size_t tools::sg::vertices::number ( ) const
inline

Definition at line 184 of file vertices.

184 {return xyzs.size()/3;}

◆ operator=()

vertices& tools::sg::vertices::operator= ( const vertices a_from)
inline

Definition at line 144 of file vertices.

144  {
145  parent::operator=(a_from);
146  parent_gstos::operator=(a_from);
147 
148  mode = a_from.mode;
149  xyzs = a_from.xyzs;
150 
151  return *this;
152  }

◆ pick()

virtual void tools::sg::vertices::pick ( pick_action a_action)
inlinevirtual

Reimplemented from tools::sg::node.

Definition at line 104 of file vertices.

104  {
105  if(touched()) {clean_gstos();reset_touched();}
106  a_action.add__primitive(*this,mode.value(),xyzs.values(),true);
107  }

◆ render()

virtual void tools::sg::vertices::render ( render_action a_action)
inlinevirtual

_id

Reimplemented from tools::sg::node.

Reimplemented in tools::sg::atb_vertices.

Definition at line 50 of file vertices.

50  {
51  if(touched()) {clean_gstos();reset_touched();}
52  if(xyzs.empty()) return;
53 
54  const state& state = a_action.state();
55 
56  if(state.m_use_gsto) {
57  unsigned int _id = get_gsto_id(a_action.out(),a_action.render_manager());
58  if(_id) {
59 #ifdef __APPLE__
60  bool restore_blend = check_set_blend(a_action);
61 #endif
62  a_action.begin_gsto(_id);
63  size_t npt = xyzs.values().size()/3;
64  bufpos pos = 0;
65  if(gl::is_line(mode.value())) {
66  //Same logic as Inventor SoLightModel.model = BASE_COLOR.
67  a_action.set_lighting(false);
68  a_action.draw_gsto_v(mode.value(),npt,pos);
69  a_action.set_lighting(state.m_GL_LIGHTING);
70  } else {
71  a_action.draw_gsto_v(mode.value(),npt,pos);
72  }
73  a_action.end_gsto();
74 #ifdef __APPLE__
75  if(restore_blend) a_action.set_blend(true);
76 #endif
77  return;
78  } else {
79  // use immediate rendering.
80  }
81 
82  } else {
83  clean_gstos(&a_action.render_manager());
84  }
85 
86 #ifdef __APPLE__
87  bool restore_blend = check_set_blend(a_action);
88 #endif
89 
90  // immediate rendering :
91  if(gl::is_line(mode.value())) {
92  //Same logic as Inventor SoLightModel.model = BASE_COLOR.
93  a_action.set_lighting(false);
94  a_action.draw_vertex_array(mode.value(),xyzs.values());
95  a_action.set_lighting(state.m_GL_LIGHTING);
96  } else {
97  a_action.draw_vertex_array(mode.value(),xyzs.values());
98  }
99 
100 #ifdef __APPLE__
101  if(restore_blend) a_action.set_blend(true);
102 #endif
103  }

Member Data Documentation

◆ mode

sf<gl::mode_t> tools::sg::vertices::mode

Definition at line 26 of file vertices.

◆ xyzs

mf<float> tools::sg::vertices::xyzs

Definition at line 27 of file vertices.


The documentation for this class was generated from the following file:
tools::sg::field::touch
void touch()
Definition: field:59
tools::sg::bmf::empty
bool empty() const
Definition: bmf:70
tools::gl::is_line
bool is_line(mode_t a_mode)
Definition: glprims:31
tools::sg::vertices::mode
sf< gl::mode_t > mode
Definition: vertices:26
tools::sg::bmf::add
void add(const T &a_value)
Definition: bmf:73
tools::sg::gstos::clean_gstos
void clean_gstos()
Definition: gstos:89
tools::gl::line_strip
mode_t line_strip()
Definition: glprims:19
tools::sg::gstos::operator=
gstos & operator=(const gstos &a_from)
Definition: gstos:22
tools::sg::bmf::values
const std::vector< T > & values() const
Definition: bmf:71
tools::sg::vertices::_is_visible
bool _is_visible(const matrix_action &a_action)
Definition: vertices:240
tools::sg::gstos::get_gsto_id
unsigned int get_gsto_id(std::ostream &a_out, render_manager &a_mgr)
Definition: gstos:60
tools::sg::bmf::clear
void clear()
Definition: bmf:108
TOOLS_FIELD_DESC_NODE_CLASS
#define TOOLS_FIELD_DESC_NODE_CLASS(a__class)
Definition: field:68
tools::sg::vertices::xyzs
mf< float > xyzs
Definition: vertices:27
tools::sg::bsf::value
T & value()
Definition: bsf:98
tools::sg::bufpos
size_t bufpos
Definition: render_action:22
tools::sg::bmf::size
size_t size() const
Definition: bmf:69
tools::sg::node::touched
virtual bool touched()
Definition: node:96
tools::sg::vertices::add
void add(const VEC &a_v)
Definition: vertices:155
TOOLS_ARG_FIELD_DESC
#define TOOLS_ARG_FIELD_DESC(a__field)
Definition: field:71
tools::sg::node::reset_touched
virtual void reset_touched()
Definition: node:102
tools::sg::vertices
Definition: vertices:22