Warning, /include/Geant4/tools/sg/gstos_add is written in an unsupported language. File is not indexed.
0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003
0004 #ifndef tools_sg_gstos_add
0005 #define tools_sg_gstos_add
0006
0007 #include "../vmanip"
0008 #include "../vdata"
0009 #include "../glprims"
0010 #include "../lina/mat4f"
0011
0012 namespace tools {
0013 namespace sg {
0014
0015 class gstos_add {
0016 public:
0017 gstos_add(){}
0018 virtual ~gstos_add(){}
0019 public:
0020 gstos_add(const gstos_add&) {}
0021 gstos_add& operator=(const gstos_add&){return *this;}
0022 public:
0023 void clear() {m_xyzs.clear();m_nms.clear();}
0024
0025 void add_points(size_t a_floatn,const float* a_xyzs) {
0026 append(m_xyzs,a_floatn,a_xyzs);
0027 }
0028 void add_lines(size_t a_floatn,const float* a_xyzs) {
0029 append(m_xyzs,a_floatn,a_xyzs);
0030 }
0031 void add_line_strip(size_t a_floatn,const float* a_xyzs) {
0032 size_t num = a_floatn/3;
0033 if(num<2) return;
0034 size_t nxyzs = (num-1)*2*3;
0035 size_t offset = m_xyzs.size();
0036 m_xyzs.resize(offset+nxyzs);
0037 float* pxyzs = vec_data<float>(m_xyzs)+offset;
0038 gl::line_strip_to_lines(num,a_xyzs,pxyzs);
0039 }
0040 void add_line_loop(size_t a_floatn,const float* a_xyzs) {
0041 size_t num = a_floatn/3;
0042 if(num<2) return;
0043 size_t nxyzs = num*2*3;
0044 size_t offset = m_xyzs.size();
0045 m_xyzs.resize(offset+nxyzs);
0046 float* pxyzs = vec_data<float>(m_xyzs)+offset;
0047 gl::line_loop_to_lines(num,a_xyzs,pxyzs);
0048 }
0049 void add_triangles_normal(size_t a_floatn,const float* a_xyzs,const float* a_nms) {
0050 append(m_xyzs,a_floatn,a_xyzs);
0051 append(m_nms,a_floatn,a_nms);
0052 }
0053 void add_triangle_strip_normal(size_t a_floatn,const float* a_xyzs,const float* a_nms) {
0054 size_t num = a_floatn/3;
0055 if(num<3) return;
0056 size_t nxyzs = (num-2)*3*3;
0057 size_t offset = m_xyzs.size();
0058 m_xyzs.resize(offset+nxyzs);
0059 float* pxyzs = vec_data<float>(m_xyzs)+offset;
0060 offset = m_nms.size();
0061 m_nms.resize(offset+nxyzs);
0062 float* pnms = vec_data<float>(m_nms)+offset;
0063 gl::triangle_strip_to_triangles_nms(num,a_xyzs,a_nms,pxyzs,pnms);
0064 }
0065 void add_triangle_fan_normal(size_t a_floatn,const float* a_xyzs,const float* a_nms) {
0066 size_t num = a_floatn/3;
0067 if(num<3) return;
0068 size_t nxyzs = (num-2)*3*3;
0069 size_t offset = m_xyzs.size();
0070 m_xyzs.resize(offset+nxyzs);
0071 float* pxyzs = vec_data<float>(m_xyzs)+offset;
0072 offset = m_nms.size();
0073 m_nms.resize(offset+nxyzs);
0074 float* pnms = vec_data<float>(m_nms)+offset;
0075 gl::triangle_fan_to_triangles_nms(num,a_xyzs,a_nms,pxyzs,pnms);
0076 }
0077
0078 void add_triangle_strip_as_triangles(size_t a_floatn,const float* a_xyzs,const float* a_nms) { //used in sg::sphere, icosahedron_sphere.
0079 add_triangle_strip_normal(a_floatn,a_xyzs,a_nms);
0080 }
0081 /*
0082 /////////////////////////////////////////////////////////
0083 /// for sg::markers and gstos : /////////////////////////
0084 /////////////////////////////////////////////////////////
0085 void add_lines(const std::vector<float>& a_xyzs) {
0086 append(m_xyzs,a_xyzs.size(),vec_data(a_xyzs));
0087 }
0088 void add_triangles_normal(const std::vector<float>& a_xyzs,const std::vector<float>& a_nms) { //for sg::markers.
0089 if(a_xyzs.size()!=a_nms.size()) return;
0090 append(m_xyzs,a_xyzs.size(),vec_data(a_xyzs));
0091 append(m_nms,a_nms.size(),vec_data(a_nms));
0092 }
0093 bool project_point(const mat4f& a_model_matrix,const mat4f& a_projection_matrix,
0094 float& a_x,float& a_y,float& a_z,float& a_w) {
0095 a_w = 1;
0096 a_model_matrix.mul_4f(a_x,a_y,a_z,a_w);
0097 a_projection_matrix.mul_4f(a_x,a_y,a_z,a_w);
0098 if(a_w==0.0F) return false;
0099 a_x /= a_w;
0100 a_y /= a_w;
0101 a_z /= a_w;
0102 return true;
0103 }
0104 /////////////////////////////////////////////////////////
0105 /////////////////////////////////////////////////////////
0106 /////////////////////////////////////////////////////////
0107 */
0108 public:
0109 std::vector<float> m_xyzs;
0110 std::vector<float> m_nms;
0111
0112 size_t m_gsto_points_sz;
0113 size_t m_gsto_lines_sz;
0114 size_t m_gsto_tris_sz;
0115 size_t m_gsto_nms_sz;
0116 };
0117
0118 }}
0119
0120 #endif