Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 2 // See the file tools.license for terms. 3 3 4 #ifndef tools_sg_gstos_add 4 #ifndef tools_sg_gstos_add 5 #define tools_sg_gstos_add 5 #define tools_sg_gstos_add 6 6 7 #include "../vmanip" 7 #include "../vmanip" 8 #include "../vdata" 8 #include "../vdata" 9 #include "../glprims" 9 #include "../glprims" 10 #include "../lina/mat4f" 10 #include "../lina/mat4f" 11 11 12 namespace tools { 12 namespace tools { 13 namespace sg { 13 namespace sg { 14 14 15 class gstos_add { 15 class gstos_add { 16 public: 16 public: 17 gstos_add(){} 17 gstos_add(){} 18 virtual ~gstos_add(){} 18 virtual ~gstos_add(){} 19 public: 19 public: 20 gstos_add(const gstos_add&) {} 20 gstos_add(const gstos_add&) {} 21 gstos_add& operator=(const gstos_add&){retur 21 gstos_add& operator=(const gstos_add&){return *this;} 22 public: 22 public: 23 void clear() {m_xyzs.clear();m_nms.clear();} 23 void clear() {m_xyzs.clear();m_nms.clear();} 24 24 25 void add_points(size_t a_floatn,const float* 25 void add_points(size_t a_floatn,const float* a_xyzs) { 26 append(m_xyzs,a_floatn,a_xyzs); 26 append(m_xyzs,a_floatn,a_xyzs); 27 } 27 } 28 void add_lines(size_t a_floatn,const float* 28 void add_lines(size_t a_floatn,const float* a_xyzs) { 29 append(m_xyzs,a_floatn,a_xyzs); 29 append(m_xyzs,a_floatn,a_xyzs); 30 } 30 } 31 void add_line_strip(size_t a_floatn,const fl 31 void add_line_strip(size_t a_floatn,const float* a_xyzs) { 32 size_t num = a_floatn/3; 32 size_t num = a_floatn/3; 33 if(num<2) return; 33 if(num<2) return; 34 size_t nxyzs = (num-1)*2*3; 34 size_t nxyzs = (num-1)*2*3; 35 size_t offset = m_xyzs.size(); 35 size_t offset = m_xyzs.size(); 36 m_xyzs.resize(offset+nxyzs); 36 m_xyzs.resize(offset+nxyzs); 37 float* pxyzs = vec_data<float>(m_xyzs)+off 37 float* pxyzs = vec_data<float>(m_xyzs)+offset; 38 gl::line_strip_to_lines(num,a_xyzs,pxyzs); 38 gl::line_strip_to_lines(num,a_xyzs,pxyzs); 39 } 39 } 40 void add_line_loop(size_t a_floatn,const flo 40 void add_line_loop(size_t a_floatn,const float* a_xyzs) { 41 size_t num = a_floatn/3; 41 size_t num = a_floatn/3; 42 if(num<2) return; 42 if(num<2) return; 43 size_t nxyzs = num*2*3; 43 size_t nxyzs = num*2*3; 44 size_t offset = m_xyzs.size(); 44 size_t offset = m_xyzs.size(); 45 m_xyzs.resize(offset+nxyzs); 45 m_xyzs.resize(offset+nxyzs); 46 float* pxyzs = vec_data<float>(m_xyzs)+off 46 float* pxyzs = vec_data<float>(m_xyzs)+offset; 47 gl::line_loop_to_lines(num,a_xyzs,pxyzs); 47 gl::line_loop_to_lines(num,a_xyzs,pxyzs); 48 } 48 } 49 void add_triangles_normal(size_t a_floatn,co 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); 50 append(m_xyzs,a_floatn,a_xyzs); 51 append(m_nms,a_floatn,a_nms); 51 append(m_nms,a_floatn,a_nms); 52 } 52 } 53 void add_triangle_strip_normal(size_t a_floa 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; 54 size_t num = a_floatn/3; 55 if(num<3) return; 55 if(num<3) return; 56 size_t nxyzs = (num-2)*3*3; 56 size_t nxyzs = (num-2)*3*3; 57 size_t offset = m_xyzs.size(); 57 size_t offset = m_xyzs.size(); 58 m_xyzs.resize(offset+nxyzs); 58 m_xyzs.resize(offset+nxyzs); 59 float* pxyzs = vec_data<float>(m_xyzs)+off 59 float* pxyzs = vec_data<float>(m_xyzs)+offset; 60 offset = m_nms.size(); 60 offset = m_nms.size(); 61 m_nms.resize(offset+nxyzs); 61 m_nms.resize(offset+nxyzs); 62 float* pnms = vec_data<float>(m_nms)+offse 62 float* pnms = vec_data<float>(m_nms)+offset; 63 gl::triangle_strip_to_triangles_nms(num,a_ 63 gl::triangle_strip_to_triangles_nms(num,a_xyzs,a_nms,pxyzs,pnms); 64 } 64 } 65 void add_triangle_fan_normal(size_t a_floatn 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; 66 size_t num = a_floatn/3; 67 if(num<3) return; 67 if(num<3) return; 68 size_t nxyzs = (num-2)*3*3; 68 size_t nxyzs = (num-2)*3*3; 69 size_t offset = m_xyzs.size(); 69 size_t offset = m_xyzs.size(); 70 m_xyzs.resize(offset+nxyzs); 70 m_xyzs.resize(offset+nxyzs); 71 float* pxyzs = vec_data<float>(m_xyzs)+off 71 float* pxyzs = vec_data<float>(m_xyzs)+offset; 72 offset = m_nms.size(); 72 offset = m_nms.size(); 73 m_nms.resize(offset+nxyzs); 73 m_nms.resize(offset+nxyzs); 74 float* pnms = vec_data<float>(m_nms)+offse 74 float* pnms = vec_data<float>(m_nms)+offset; 75 gl::triangle_fan_to_triangles_nms(num,a_xy 75 gl::triangle_fan_to_triangles_nms(num,a_xyzs,a_nms,pxyzs,pnms); 76 } 76 } 77 77 78 void add_triangle_strip_as_triangles(size_t 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, 79 add_triangle_strip_normal(a_floatn,a_xyzs,a_nms); 80 } 80 } 81 /* 81 /* 82 //////////////////////////////////////////// 82 ///////////////////////////////////////////////////////// 83 /// for sg::markers and gstos : //////////// 83 /// for sg::markers and gstos : ///////////////////////// 84 //////////////////////////////////////////// 84 ///////////////////////////////////////////////////////// 85 void add_lines(const std::vector<float>& a_x 85 void add_lines(const std::vector<float>& a_xyzs) { 86 append(m_xyzs,a_xyzs.size(),vec_data(a_xyz 86 append(m_xyzs,a_xyzs.size(),vec_data(a_xyzs)); 87 } 87 } 88 void add_triangles_normal(const std::vector< 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; 89 if(a_xyzs.size()!=a_nms.size()) return; 90 append(m_xyzs,a_xyzs.size(),vec_data(a_xyz 90 append(m_xyzs,a_xyzs.size(),vec_data(a_xyzs)); 91 append(m_nms,a_nms.size(),vec_data(a_nms)) 91 append(m_nms,a_nms.size(),vec_data(a_nms)); 92 } 92 } 93 bool project_point(const mat4f& a_model_matr 93 bool project_point(const mat4f& a_model_matrix,const mat4f& a_projection_matrix, 94 float& a_x,float& a_y,flo 94 float& a_x,float& a_y,float& a_z,float& a_w) { 95 a_w = 1; 95 a_w = 1; 96 a_model_matrix.mul_4f(a_x,a_y,a_z,a_w); 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 97 a_projection_matrix.mul_4f(a_x,a_y,a_z,a_w); 98 if(a_w==0.0F) return false; 98 if(a_w==0.0F) return false; 99 a_x /= a_w; 99 a_x /= a_w; 100 a_y /= a_w; 100 a_y /= a_w; 101 a_z /= a_w; 101 a_z /= a_w; 102 return true; 102 return true; 103 } 103 } 104 //////////////////////////////////////////// 104 ///////////////////////////////////////////////////////// 105 //////////////////////////////////////////// 105 ///////////////////////////////////////////////////////// 106 //////////////////////////////////////////// 106 ///////////////////////////////////////////////////////// 107 */ 107 */ 108 public: 108 public: 109 std::vector<float> m_xyzs; 109 std::vector<float> m_xyzs; 110 std::vector<float> m_nms; 110 std::vector<float> m_nms; 111 111 112 size_t m_gsto_points_sz; 112 size_t m_gsto_points_sz; 113 size_t m_gsto_lines_sz; 113 size_t m_gsto_lines_sz; 114 size_t m_gsto_tris_sz; 114 size_t m_gsto_tris_sz; 115 size_t m_gsto_nms_sz; 115 size_t m_gsto_nms_sz; 116 }; 116 }; 117 117 118 }} 118 }} 119 119 120 #endif 120 #endif