g4tools  5.4.0
gstos_add
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_gstos_add
5 #define tools_sg_gstos_add
6 
7 #include "../vmanip"
8 #include "../vdata"
9 #include "../glprims"
10 #include "../lina/mat4f"
11 
12 namespace tools {
13 namespace sg {
14 
15 class gstos_add {
16 public:
18  virtual ~gstos_add(){}
19 public:
20  gstos_add(const gstos_add&) {}
21  gstos_add& operator=(const gstos_add&){return *this;}
22 public:
23  void clear() {m_xyzs.clear();m_nms.clear();}
24 
25  void add_points(size_t a_floatn,const float* a_xyzs) {
26  append(m_xyzs,a_floatn,a_xyzs);
27  }
28  void add_lines(size_t a_floatn,const float* a_xyzs) {
29  append(m_xyzs,a_floatn,a_xyzs);
30  }
31  void add_line_strip(size_t a_floatn,const float* a_xyzs) {
32  size_t num = a_floatn/3;
33  if(num<2) return;
34  size_t nxyzs = (num-1)*2*3;
35  size_t offset = m_xyzs.size();
36  m_xyzs.resize(offset+nxyzs);
37  float* pxyzs = vec_data<float>(m_xyzs)+offset;
38  gl::line_strip_to_lines(num,a_xyzs,pxyzs);
39  }
40  void add_line_loop(size_t a_floatn,const float* a_xyzs) {
41  size_t num = a_floatn/3;
42  if(num<2) return;
43  size_t nxyzs = num*2*3;
44  size_t offset = m_xyzs.size();
45  m_xyzs.resize(offset+nxyzs);
46  float* pxyzs = vec_data<float>(m_xyzs)+offset;
47  gl::line_loop_to_lines(num,a_xyzs,pxyzs);
48  }
49  void add_triangles_normal(size_t a_floatn,const float* a_xyzs,const float* a_nms) {
50  append(m_xyzs,a_floatn,a_xyzs);
51  append(m_nms,a_floatn,a_nms);
52  }
53  void add_triangle_strip_normal(size_t a_floatn,const float* a_xyzs,const float* a_nms) {
54  size_t num = a_floatn/3;
55  if(num<3) return;
56  size_t nxyzs = (num-2)*3*3;
57  size_t offset = m_xyzs.size();
58  m_xyzs.resize(offset+nxyzs);
59  float* pxyzs = vec_data<float>(m_xyzs)+offset;
60  offset = m_nms.size();
61  m_nms.resize(offset+nxyzs);
62  float* pnms = vec_data<float>(m_nms)+offset;
63  gl::triangle_strip_to_triangles_nms(num,a_xyzs,a_nms,pxyzs,pnms);
64  }
65  void add_triangle_fan_normal(size_t a_floatn,const float* a_xyzs,const float* a_nms) {
66  size_t num = a_floatn/3;
67  if(num<3) return;
68  size_t nxyzs = (num-2)*3*3;
69  size_t offset = m_xyzs.size();
70  m_xyzs.resize(offset+nxyzs);
71  float* pxyzs = vec_data<float>(m_xyzs)+offset;
72  offset = m_nms.size();
73  m_nms.resize(offset+nxyzs);
74  float* pnms = vec_data<float>(m_nms)+offset;
75  gl::triangle_fan_to_triangles_nms(num,a_xyzs,a_nms,pxyzs,pnms);
76  }
77 
78  void add_triangle_strip_as_triangles(size_t a_floatn,const float* a_xyzs,const float* a_nms) { //used in sg::sphere, icosahedron_sphere.
79  add_triangle_strip_normal(a_floatn,a_xyzs,a_nms);
80  }
81 /*
85  void add_lines(const std::vector<float>& a_xyzs) {
86  append(m_xyzs,a_xyzs.size(),vec_data(a_xyzs));
87  }
88  void add_triangles_normal(const std::vector<float>& a_xyzs,const std::vector<float>& a_nms) { //for sg::markers.
89  if(a_xyzs.size()!=a_nms.size()) return;
90  append(m_xyzs,a_xyzs.size(),vec_data(a_xyzs));
91  append(m_nms,a_nms.size(),vec_data(a_nms));
92  }
93  bool project_point(const mat4f& a_model_matrix,const mat4f& a_projection_matrix,
94  float& a_x,float& a_y,float& a_z,float& a_w) {
95  a_w = 1;
96  a_model_matrix.mul_4f(a_x,a_y,a_z,a_w);
97  a_projection_matrix.mul_4f(a_x,a_y,a_z,a_w);
98  if(a_w==0.0F) return false;
99  a_x /= a_w;
100  a_y /= a_w;
101  a_z /= a_w;
102  return true;
103  }
107 */
108 public:
109  std::vector<float> m_xyzs;
110  std::vector<float> m_nms;
111 
116 };
117 
118 }}
119 
120 #endif
tools::gl::triangle_strip_to_triangles_nms
void triangle_strip_to_triangles_nms(size_t a_npt, const float *a_xyzs, const float *a_nms, float *&a_pxyzs, float *&a_pnms)
Definition: glprims:307
tools::gl::triangle_fan_to_triangles_nms
void triangle_fan_to_triangles_nms(size_t a_npt, const float *a_xyzs, const float *a_nms, float *&a_pxyzs, float *&a_pnms)
Definition: glprims:302
tools::sg::gstos_add::add_triangle_fan_normal
void add_triangle_fan_normal(size_t a_floatn, const float *a_xyzs, const float *a_nms)
Definition: gstos_add:65
tools::sg::gstos_add::gstos_add
gstos_add(const gstos_add &)
Definition: gstos_add:20
tools::gl::line_strip_to_lines
void line_strip_to_lines(size_t a_npt, const float *a_xyzs, float *&a_pxyzs)
Definition: glprims:425
tools::sg::gstos_add::m_gsto_nms_sz
size_t m_gsto_nms_sz
Definition: gstos_add:115
tools::sg::gstos_add::m_xyzs
std::vector< float > m_xyzs
Definition: gstos_add:109
tools::sg::gstos_add::gstos_add
gstos_add()
Definition: gstos_add:17
tools::sg::gstos_add::m_gsto_points_sz
size_t m_gsto_points_sz
Definition: gstos_add:112
tools::append
void append(std::vector< T > &a_vec, const std::vector< T > &a_from)
Definition: vmanip:66
tools::sg::gstos_add::m_gsto_tris_sz
size_t m_gsto_tris_sz
Definition: gstos_add:114
tools::sg::gstos_add::~gstos_add
virtual ~gstos_add()
Definition: gstos_add:18
tools::sg::gstos_add::add_line_loop
void add_line_loop(size_t a_floatn, const float *a_xyzs)
Definition: gstos_add:40
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::sg::gstos_add
Definition: gstos_add:15
tools::gl::line_loop_to_lines
void line_loop_to_lines(size_t a_npt, const float *a_xyzs, float *&a_pxyzs)
Definition: glprims:455
tools::sg::gstos_add::add_points
void add_points(size_t a_floatn, const float *a_xyzs)
Definition: gstos_add:25
tools::sg::gstos_add::m_gsto_lines_sz
size_t m_gsto_lines_sz
Definition: gstos_add:113
tools::sg::gstos_add::add_lines
void add_lines(size_t a_floatn, const float *a_xyzs)
Definition: gstos_add:28
tools::sg::gstos_add::clear
void clear()
Definition: gstos_add:23
tools::sg::gstos_add::m_nms
std::vector< float > m_nms
Definition: gstos_add:110
tools::sg::gstos_add::add_triangle_strip_normal
void add_triangle_strip_normal(size_t a_floatn, const float *a_xyzs, const float *a_nms)
Definition: gstos_add:53
tools::sg::gstos_add::operator=
gstos_add & operator=(const gstos_add &)
Definition: gstos_add:21
tools::sg::gstos_add::add_line_strip
void add_line_strip(size_t a_floatn, const float *a_xyzs)
Definition: gstos_add:31
tools::sg::gstos_add::add_triangles_normal
void add_triangles_normal(size_t a_floatn, const float *a_xyzs, const float *a_nms)
Definition: gstos_add:49
tools::sg::gstos_add::add_triangle_strip_as_triangles
void add_triangle_strip_as_triangles(size_t a_floatn, const float *a_xyzs, const float *a_nms)
Definition: gstos_add:78