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_markers 4 #ifndef tools_sg_markers 5 #define tools_sg_markers 5 #define tools_sg_markers 6 6 7 #include "node" 7 #include "node" 8 8 9 #include "sf_enum" 9 #include "sf_enum" 10 #include "mf" 10 #include "mf" 11 #include "render_action" 11 #include "render_action" 12 #include "pick_action" 12 #include "pick_action" 13 #include "bbox_action" 13 #include "bbox_action" 14 #include "../mathf" 14 #include "../mathf" 15 #include "../lina/vec2f" 15 #include "../lina/vec2f" 16 #include "../lina/geom2" 16 #include "../lina/geom2" 17 17 18 namespace tools { 18 namespace tools { 19 namespace sg { 19 namespace sg { 20 20 21 class markers : public node { 21 class markers : public node { 22 TOOLS_NODE(markers,tools::sg::markers,node) 22 TOOLS_NODE(markers,tools::sg::markers,node) 23 public: 23 public: 24 sf_enum<marker_style> style; 24 sf_enum<marker_style> style; 25 mf<float> xyzs; //[x,y,z] 25 mf<float> xyzs; //[x,y,z] 26 sf<float> size; //horizontal size in pixels. 26 sf<float> size; //horizontal size in pixels. 27 public: 27 public: 28 virtual const desc_fields& node_desc_fields( 28 virtual const desc_fields& node_desc_fields() const { 29 TOOLS_FIELD_DESC_NODE_CLASS(tools::sg::mar 29 TOOLS_FIELD_DESC_NODE_CLASS(tools::sg::markers) 30 static const desc_fields s_v(parent::node_ 30 static const desc_fields s_v(parent::node_desc_fields(),3, //WARNING : take care of count. 31 TOOLS_ARG_FIELD_DESC(style), 31 TOOLS_ARG_FIELD_DESC(style), 32 TOOLS_ARG_FIELD_DESC(xyzs), 32 TOOLS_ARG_FIELD_DESC(xyzs), 33 TOOLS_ARG_FIELD_DESC(size) 33 TOOLS_ARG_FIELD_DESC(size) 34 ); 34 ); 35 return s_v; 35 return s_v; 36 } 36 } 37 private: 37 private: 38 void add_fields(){ 38 void add_fields(){ 39 add_field(&style); 39 add_field(&style); 40 add_field(&xyzs); 40 add_field(&xyzs); 41 add_field(&size); 41 add_field(&size); 42 } 42 } 43 public: 43 public: 44 virtual bool draw_in_frame_buffer() const {r 44 virtual bool draw_in_frame_buffer() const {return true;} 45 45 46 virtual void render(render_action& a_action) 46 virtual void render(render_action& a_action) { 47 size_t num = xyzs.size()/3; 47 size_t num = xyzs.size()/3; 48 if(!num) return; 48 if(!num) return; 49 49 50 //NOTE : gstos would not work because of p 50 //NOTE : gstos would not work because of project_point() that must be done at each render(). 51 51 52 const state& state = a_action.state(); 52 const state& state = a_action.state(); 53 53 54 const std::vector<float>& _xyzs = xyzs.val 54 const std::vector<float>& _xyzs = xyzs.values(); 55 55 56 std::vector<float> pts; 56 std::vector<float> pts; 57 57 58 float sx = size.value()/float(state.m_ww); 58 float sx = size.value()/float(state.m_ww); //in [-1,1] 59 float hsx = sx*0.5f; 59 float hsx = sx*0.5f; 60 60 61 float sy = size.value()/float(state.m_wh); 61 float sy = size.value()/float(state.m_wh); //in [-1,1] 62 float hsy = sy*0.5f; 62 float hsy = sy*0.5f; 63 63 64 float rad = hsx; 64 float rad = hsx; 65 float hsx2 = hsx*0.5f; 65 float hsx2 = hsx*0.5f; 66 float hsy2 = hsy*0.5f; 66 float hsy2 = hsy*0.5f; 67 67 68 float x,y,z,w; 68 float x,y,z,w; 69 69 70 bool filled = false; 70 bool filled = false; 71 if(style.value()==marker_circle_line) { 71 if(style.value()==marker_circle_line) { 72 unsigned int segs = 16; 72 unsigned int segs = 16; 73 float _cos[16];float _sin[16]; 73 float _cos[16];float _sin[16]; 74 float dtheta = ftwo_pi()/float(segs); 74 float dtheta = ftwo_pi()/float(segs); 75 float theta = dtheta; 75 float theta = dtheta; 76 {for(unsigned int i=0;i<segs;i++,theta+=d 76 {for(unsigned int i=0;i<segs;i++,theta+=dtheta) {_cos[i] = rad*fcos(theta);_sin[i] = rad*fsin(theta);}} 77 float xprev,yprev,xnext,ynext; 77 float xprev,yprev,xnext,ynext; 78 std::vector<float>::const_iterator it; 78 std::vector<float>::const_iterator it; 79 for(it=_xyzs.begin();it!=_xyzs.end();){ 79 for(it=_xyzs.begin();it!=_xyzs.end();){ 80 x = *it;it++; 80 x = *it;it++; 81 y = *it;it++; 81 y = *it;it++; 82 z = *it;it++; 82 z = *it;it++; 83 a_action.project_point(x,y,z,w); //in 83 a_action.project_point(x,y,z,w); //in [-1,1][-1,1] 84 xprev = x+rad; 84 xprev = x+rad; 85 yprev = y; 85 yprev = y; 86 for(unsigned int i=0;i<segs;i++) { 86 for(unsigned int i=0;i<segs;i++) { 87 xnext = x+_cos[i]; 87 xnext = x+_cos[i]; 88 ynext = y+_sin[i]; 88 ynext = y+_sin[i]; 89 _add(pts,xprev,yprev,z); 89 _add(pts,xprev,yprev,z); 90 _add(pts,xnext,ynext,z); 90 _add(pts,xnext,ynext,z); 91 xprev = xnext; 91 xprev = xnext; 92 yprev = ynext; 92 yprev = ynext; 93 } 93 } 94 } 94 } 95 95 96 } else if(style.value()==marker_circle_fil 96 } else if(style.value()==marker_circle_filled) { 97 //} else if((style.value()==marker_circle_fi 97 //} else if((style.value()==marker_circle_filled)||(style.value()==marker_dot)) { 98 filled = true; 98 filled = true; 99 unsigned int segs = 16; 99 unsigned int segs = 16; 100 float _cos[16];float _sin[16]; 100 float _cos[16];float _sin[16]; 101 float dtheta = ftwo_pi()/float(segs); 101 float dtheta = ftwo_pi()/float(segs); 102 float theta = dtheta; 102 float theta = dtheta; 103 {for(unsigned int i=0;i<segs;i++,theta+=d 103 {for(unsigned int i=0;i<segs;i++,theta+=dtheta) {_cos[i] = rad*fcos(theta);_sin[i] = rad*fsin(theta);}} 104 float xprev,yprev,xnext,ynext; 104 float xprev,yprev,xnext,ynext; 105 std::vector<float>::const_iterator it; 105 std::vector<float>::const_iterator it; 106 for(it=_xyzs.begin();it!=_xyzs.end();){ 106 for(it=_xyzs.begin();it!=_xyzs.end();){ 107 x = *it;it++; 107 x = *it;it++; 108 y = *it;it++; 108 y = *it;it++; 109 z = *it;it++; 109 z = *it;it++; 110 a_action.project_point(x,y,z,w); //in 110 a_action.project_point(x,y,z,w); //in [-1,1][-1,1] 111 xprev = x+rad; 111 xprev = x+rad; 112 yprev = y; 112 yprev = y; 113 for(unsigned int i=0;i<segs;i++) { 113 for(unsigned int i=0;i<segs;i++) { 114 xnext = x+_cos[i]; 114 xnext = x+_cos[i]; 115 ynext = y+_sin[i]; 115 ynext = y+_sin[i]; 116 _add(pts,x ,y ,z); 116 _add(pts,x ,y ,z); 117 _add(pts,xprev,yprev,z); 117 _add(pts,xprev,yprev,z); 118 _add(pts,xnext,ynext,z); 118 _add(pts,xnext,ynext,z); 119 xprev = xnext; 119 xprev = xnext; 120 yprev = ynext; 120 yprev = ynext; 121 } 121 } 122 } 122 } 123 123 124 } else if(style.value()==marker_square_lin 124 } else if(style.value()==marker_square_line) { 125 std::vector<float>::const_iterator it; 125 std::vector<float>::const_iterator it; 126 for(it=_xyzs.begin();it!=_xyzs.end();){ 126 for(it=_xyzs.begin();it!=_xyzs.end();){ 127 x = *it;it++; 127 x = *it;it++; 128 y = *it;it++; 128 y = *it;it++; 129 z = *it;it++; 129 z = *it;it++; 130 a_action.project_point(x,y,z,w); //in 130 a_action.project_point(x,y,z,w); //in [-1,1][-1,1] 131 _add(pts, x-hsx,y-hsy,z); 131 _add(pts, x-hsx,y-hsy,z); 132 _add(pts, x+hsx,y-hsy,z); 132 _add(pts, x+hsx,y-hsy,z); 133 133 134 _add(pts, x+hsx,y-hsy,z); 134 _add(pts, x+hsx,y-hsy,z); 135 _add(pts, x+hsx,y+hsy,z); 135 _add(pts, x+hsx,y+hsy,z); 136 136 137 _add(pts, x+hsx,y+hsy,z); 137 _add(pts, x+hsx,y+hsy,z); 138 _add(pts, x-hsx,y+hsy,z); 138 _add(pts, x-hsx,y+hsy,z); 139 139 140 _add(pts, x-hsx,y+hsy,z); 140 _add(pts, x-hsx,y+hsy,z); 141 _add(pts, x-hsx,y-hsy,z); 141 _add(pts, x-hsx,y-hsy,z); 142 } 142 } 143 //} else if(style.value()==marker_square_fil 143 //} else if(style.value()==marker_square_filled) { 144 } else if((style.value()==marker_square_fi 144 } else if((style.value()==marker_square_filled)||(style.value()==marker_dot)) { 145 filled = true; 145 filled = true; 146 std::vector<float>::const_iterator it; 146 std::vector<float>::const_iterator it; 147 for(it=_xyzs.begin();it!=_xyzs.end();){ 147 for(it=_xyzs.begin();it!=_xyzs.end();){ 148 x = *it;it++; 148 x = *it;it++; 149 y = *it;it++; 149 y = *it;it++; 150 z = *it;it++; 150 z = *it;it++; 151 a_action.project_point(x,y,z,w); //in 151 a_action.project_point(x,y,z,w); //in [-1,1][-1,1] 152 _add(pts, x-hsx,y-hsy,z); 152 _add(pts, x-hsx,y-hsy,z); 153 _add(pts, x+hsx,y-hsy,z); 153 _add(pts, x+hsx,y-hsy,z); 154 _add(pts, x+hsx,y+hsy,z); 154 _add(pts, x+hsx,y+hsy,z); 155 155 156 _add(pts, x-hsx,y-hsy,z); 156 _add(pts, x-hsx,y-hsy,z); 157 _add(pts, x+hsx,y+hsy,z); 157 _add(pts, x+hsx,y+hsy,z); 158 _add(pts, x-hsx,y+hsy,z); 158 _add(pts, x-hsx,y+hsy,z); 159 } 159 } 160 160 161 } else if(style.value()==marker_triangle_u 161 } else if(style.value()==marker_triangle_up_line) { 162 std::vector<float>::const_iterator it; 162 std::vector<float>::const_iterator it; 163 for(it=_xyzs.begin();it!=_xyzs.end();){ 163 for(it=_xyzs.begin();it!=_xyzs.end();){ 164 x = *it;it++; 164 x = *it;it++; 165 y = *it;it++; 165 y = *it;it++; 166 z = *it;it++; 166 z = *it;it++; 167 a_action.project_point(x,y,z,w); //in 167 a_action.project_point(x,y,z,w); //in [-1,1][-1,1] 168 _add(pts, x-hsx,y-hsy,z); 168 _add(pts, x-hsx,y-hsy,z); 169 _add(pts, x+hsx,y-hsy,z); 169 _add(pts, x+hsx,y-hsy,z); 170 170 171 _add(pts, x+hsx,y-hsy,z); 171 _add(pts, x+hsx,y-hsy,z); 172 _add(pts, x ,y+hsy,z); 172 _add(pts, x ,y+hsy,z); 173 173 174 _add(pts, x ,y+hsy,z); 174 _add(pts, x ,y+hsy,z); 175 _add(pts, x-hsx,y-hsy,z); 175 _add(pts, x-hsx,y-hsy,z); 176 } 176 } 177 } else if(style.value()==marker_triangle_u 177 } else if(style.value()==marker_triangle_up_filled) { 178 filled = true; 178 filled = true; 179 std::vector<float>::const_iterator it; 179 std::vector<float>::const_iterator it; 180 for(it=_xyzs.begin();it!=_xyzs.end();){ 180 for(it=_xyzs.begin();it!=_xyzs.end();){ 181 x = *it;it++; 181 x = *it;it++; 182 y = *it;it++; 182 y = *it;it++; 183 z = *it;it++; 183 z = *it;it++; 184 a_action.project_point(x,y,z,w); //in 184 a_action.project_point(x,y,z,w); //in [-1,1][-1,1] 185 _add(pts, x-hsx,y-hsy,z); 185 _add(pts, x-hsx,y-hsy,z); 186 _add(pts, x+hsx,y-hsy,z); 186 _add(pts, x+hsx,y-hsy,z); 187 _add(pts, x ,y+hsy,z); 187 _add(pts, x ,y+hsy,z); 188 } 188 } 189 189 190 } else if(style.value()==marker_triangle_d 190 } else if(style.value()==marker_triangle_down_line) { 191 std::vector<float>::const_iterator it; 191 std::vector<float>::const_iterator it; 192 for(it=_xyzs.begin();it!=_xyzs.end();){ 192 for(it=_xyzs.begin();it!=_xyzs.end();){ 193 x = *it;it++; 193 x = *it;it++; 194 y = *it;it++; 194 y = *it;it++; 195 z = *it;it++; 195 z = *it;it++; 196 a_action.project_point(x,y,z,w); //in 196 a_action.project_point(x,y,z,w); //in [-1,1][-1,1] 197 _add(pts, x-hsx,y+hsy,z); 197 _add(pts, x-hsx,y+hsy,z); 198 _add(pts, x ,y-hsy,z); 198 _add(pts, x ,y-hsy,z); 199 199 200 _add(pts, x ,y-hsy,z); 200 _add(pts, x ,y-hsy,z); 201 _add(pts, x+hsx,y+hsy,z); 201 _add(pts, x+hsx,y+hsy,z); 202 202 203 _add(pts, x+hsx,y+hsy,z); 203 _add(pts, x+hsx,y+hsy,z); 204 _add(pts, x-hsx,y+hsy,z); 204 _add(pts, x-hsx,y+hsy,z); 205 } 205 } 206 } else if(style.value()==marker_triangle_d 206 } else if(style.value()==marker_triangle_down_filled) { 207 filled = true; 207 filled = true; 208 std::vector<float>::const_iterator it; 208 std::vector<float>::const_iterator it; 209 for(it=_xyzs.begin();it!=_xyzs.end();){ 209 for(it=_xyzs.begin();it!=_xyzs.end();){ 210 x = *it;it++; 210 x = *it;it++; 211 y = *it;it++; 211 y = *it;it++; 212 z = *it;it++; 212 z = *it;it++; 213 a_action.project_point(x,y,z,w); //in 213 a_action.project_point(x,y,z,w); //in [-1,1][-1,1] 214 _add(pts, x-hsx,y+hsy,z); 214 _add(pts, x-hsx,y+hsy,z); 215 _add(pts, x ,y-hsy,z); 215 _add(pts, x ,y-hsy,z); 216 _add(pts, x+hsx,y+hsy,z); 216 _add(pts, x+hsx,y+hsy,z); 217 } 217 } 218 218 219 } else if(style.value()==marker_diamond_li 219 } else if(style.value()==marker_diamond_line) { 220 std::vector<float>::const_iterator it; 220 std::vector<float>::const_iterator it; 221 for(it=_xyzs.begin();it!=_xyzs.end();){ 221 for(it=_xyzs.begin();it!=_xyzs.end();){ 222 x = *it;it++; 222 x = *it;it++; 223 y = *it;it++; 223 y = *it;it++; 224 z = *it;it++; 224 z = *it;it++; 225 a_action.project_point(x,y,z,w); //in 225 a_action.project_point(x,y,z,w); //in [-1,1][-1,1] 226 _add(pts, x ,y-hsy,z); 226 _add(pts, x ,y-hsy,z); 227 _add(pts, x+hsx, y,z); 227 _add(pts, x+hsx, y,z); 228 228 229 _add(pts, x+hsx, y,z); 229 _add(pts, x+hsx, y,z); 230 _add(pts, x ,y+hsy,z); 230 _add(pts, x ,y+hsy,z); 231 231 232 _add(pts, x ,y+hsy,z); 232 _add(pts, x ,y+hsy,z); 233 _add(pts, x-hsx,y ,z); 233 _add(pts, x-hsx,y ,z); 234 234 235 _add(pts, x-hsx,y ,z); 235 _add(pts, x-hsx,y ,z); 236 _add(pts, x ,y-hsy,z); 236 _add(pts, x ,y-hsy,z); 237 } 237 } 238 } else if(style.value()==marker_diamond_fi 238 } else if(style.value()==marker_diamond_filled) { 239 filled = true; 239 filled = true; 240 std::vector<float>::const_iterator it; 240 std::vector<float>::const_iterator it; 241 for(it=_xyzs.begin();it!=_xyzs.end();){ 241 for(it=_xyzs.begin();it!=_xyzs.end();){ 242 x = *it;it++; 242 x = *it;it++; 243 y = *it;it++; 243 y = *it;it++; 244 z = *it;it++; 244 z = *it;it++; 245 a_action.project_point(x,y,z,w); //in 245 a_action.project_point(x,y,z,w); //in [-1,1][-1,1] 246 _add(pts, x ,y-hsy,z); 246 _add(pts, x ,y-hsy,z); 247 _add(pts, x+hsx, y,z); 247 _add(pts, x+hsx, y,z); 248 _add(pts, x ,y+hsy,z); 248 _add(pts, x ,y+hsy,z); 249 249 250 _add(pts, x ,y+hsy,z); 250 _add(pts, x ,y+hsy,z); 251 _add(pts, x-hsx,y ,z); 251 _add(pts, x-hsx,y ,z); 252 _add(pts, x ,y-hsy,z); 252 _add(pts, x ,y-hsy,z); 253 } 253 } 254 254 255 } else if(style.value()==marker_swiss_cros 255 } else if(style.value()==marker_swiss_cross_line) { 256 std::vector<float>::const_iterator it; 256 std::vector<float>::const_iterator it; 257 for(it=_xyzs.begin();it!=_xyzs.end();){ 257 for(it=_xyzs.begin();it!=_xyzs.end();){ 258 x = *it;it++; 258 x = *it;it++; 259 y = *it;it++; 259 y = *it;it++; 260 z = *it;it++; 260 z = *it;it++; 261 a_action.project_point(x,y,z,w); //in 261 a_action.project_point(x,y,z,w); //in [-1,1][-1,1] 262 _add(pts, x-hsx2,y-hsy,z); 262 _add(pts, x-hsx2,y-hsy,z); 263 _add(pts, x+hsx2,y-hsy,z); 263 _add(pts, x+hsx2,y-hsy,z); 264 264 265 _add(pts, x+hsx2,y-hsy ,z); 265 _add(pts, x+hsx2,y-hsy ,z); 266 _add(pts, x+hsx2,y-hsy2,z); 266 _add(pts, x+hsx2,y-hsy2,z); 267 267 268 _add(pts, x+hsx2,y-hsy2,z); 268 _add(pts, x+hsx2,y-hsy2,z); 269 _add(pts, x+hsx ,y-hsy2,z); 269 _add(pts, x+hsx ,y-hsy2,z); 270 270 271 _add(pts, x+hsx ,y-hsy2,z); 271 _add(pts, x+hsx ,y-hsy2,z); 272 _add(pts, x+hsx ,y+hsy2,z); 272 _add(pts, x+hsx ,y+hsy2,z); 273 273 274 _add(pts, x+hsx ,y+hsy2,z); 274 _add(pts, x+hsx ,y+hsy2,z); 275 _add(pts, x+hsx2,y+hsy2,z); 275 _add(pts, x+hsx2,y+hsy2,z); 276 276 277 _add(pts, x+hsx2,y+hsy2,z); 277 _add(pts, x+hsx2,y+hsy2,z); 278 _add(pts, x+hsx2,y+hsy ,z); 278 _add(pts, x+hsx2,y+hsy ,z); 279 279 280 _add(pts, x+hsx2,y+hsy ,z); 280 _add(pts, x+hsx2,y+hsy ,z); 281 _add(pts, x-hsx2,y+hsy ,z); 281 _add(pts, x-hsx2,y+hsy ,z); 282 282 283 _add(pts, x-hsx2,y+hsy ,z); 283 _add(pts, x-hsx2,y+hsy ,z); 284 _add(pts, x-hsx2,y+hsy2,z); 284 _add(pts, x-hsx2,y+hsy2,z); 285 285 286 _add(pts, x-hsx2,y+hsy2,z); 286 _add(pts, x-hsx2,y+hsy2,z); 287 _add(pts, x-hsx ,y+hsy2,z); 287 _add(pts, x-hsx ,y+hsy2,z); 288 288 289 _add(pts, x-hsx ,y+hsy2,z); 289 _add(pts, x-hsx ,y+hsy2,z); 290 _add(pts, x-hsx ,y-hsy2,z); 290 _add(pts, x-hsx ,y-hsy2,z); 291 291 292 _add(pts, x-hsx ,y-hsy2,z); 292 _add(pts, x-hsx ,y-hsy2,z); 293 _add(pts, x-hsx2,y-hsy2,z); 293 _add(pts, x-hsx2,y-hsy2,z); 294 294 295 _add(pts, x-hsx2,y-hsy2,z); 295 _add(pts, x-hsx2,y-hsy2,z); 296 _add(pts, x-hsx2,y-hsy, z); 296 _add(pts, x-hsx2,y-hsy, z); 297 } 297 } 298 } else if(style.value()==marker_swiss_cros 298 } else if(style.value()==marker_swiss_cross_filled) { 299 filled = true; 299 filled = true; 300 std::vector<float>::const_iterator it; 300 std::vector<float>::const_iterator it; 301 for(it=_xyzs.begin();it!=_xyzs.end();){ 301 for(it=_xyzs.begin();it!=_xyzs.end();){ 302 x = *it;it++; 302 x = *it;it++; 303 y = *it;it++; 303 y = *it;it++; 304 z = *it;it++; 304 z = *it;it++; 305 a_action.project_point(x,y,z,w); //in 305 a_action.project_point(x,y,z,w); //in [-1,1][-1,1] 306 _add(pts, x-hsx2,y-hsy,z); 306 _add(pts, x-hsx2,y-hsy,z); 307 _add(pts, x+hsx2,y-hsy,z); 307 _add(pts, x+hsx2,y-hsy,z); 308 _add(pts, x+hsx2,y+hsy,z); 308 _add(pts, x+hsx2,y+hsy,z); 309 309 310 _add(pts, x+hsx2,y+hsy,z); 310 _add(pts, x+hsx2,y+hsy,z); 311 _add(pts, x-hsx2,y+hsy,z); 311 _add(pts, x-hsx2,y+hsy,z); 312 _add(pts, x-hsx2,y-hsy,z); 312 _add(pts, x-hsx2,y-hsy,z); 313 313 314 _add(pts, x-hsx ,y-hsy2,z); 314 _add(pts, x-hsx ,y-hsy2,z); 315 _add(pts, x+hsx ,y-hsy2,z); 315 _add(pts, x+hsx ,y-hsy2,z); 316 _add(pts, x+hsx ,y+hsy2,z); 316 _add(pts, x+hsx ,y+hsy2,z); 317 317 318 _add(pts, x+hsx ,y+hsy2,z); 318 _add(pts, x+hsx ,y+hsy2,z); 319 _add(pts, x-hsx ,y+hsy2,z); 319 _add(pts, x-hsx ,y+hsy2,z); 320 _add(pts, x-hsx ,y-hsy2,z); 320 _add(pts, x-hsx ,y-hsy2,z); 321 } 321 } 322 322 323 } else if(style.value()==marker_david_star 323 } else if(style.value()==marker_david_star_line) { 324 std::vector<float>::const_iterator it; 324 std::vector<float>::const_iterator it; 325 for(it=_xyzs.begin();it!=_xyzs.end();){ 325 for(it=_xyzs.begin();it!=_xyzs.end();){ 326 x = *it;it++; 326 x = *it;it++; 327 y = *it;it++; 327 y = *it;it++; 328 z = *it;it++; 328 z = *it;it++; 329 a_action.project_point(x,y,z,w); //in 329 a_action.project_point(x,y,z,w); //in [-1,1][-1,1] 330 _add(pts, x-hsx,y-hsy2,z); 330 _add(pts, x-hsx,y-hsy2,z); 331 _add(pts, x+hsx,y-hsy2,z); 331 _add(pts, x+hsx,y-hsy2,z); 332 332 333 _add(pts, x+hsx,y-hsy2,z); 333 _add(pts, x+hsx,y-hsy2,z); 334 _add(pts, x ,y+hsy ,z); 334 _add(pts, x ,y+hsy ,z); 335 335 336 _add(pts, x ,y+hsy ,z); 336 _add(pts, x ,y+hsy ,z); 337 _add(pts, x-hsx,y-hsy2,z); 337 _add(pts, x-hsx,y-hsy2,z); 338 338 339 _add(pts, x+hsx,y+hsy2,z); 339 _add(pts, x+hsx,y+hsy2,z); 340 _add(pts, x-hsx,y+hsy2,z); 340 _add(pts, x-hsx,y+hsy2,z); 341 341 342 _add(pts, x-hsx,y+hsy2,z); 342 _add(pts, x-hsx,y+hsy2,z); 343 _add(pts, x ,y-hsy ,z); 343 _add(pts, x ,y-hsy ,z); 344 344 345 _add(pts, x ,y-hsy ,z); 345 _add(pts, x ,y-hsy ,z); 346 _add(pts, x+hsx,y+hsy2,z); 346 _add(pts, x+hsx,y+hsy2,z); 347 } 347 } 348 } else if(style.value()==marker_david_star 348 } else if(style.value()==marker_david_star_filled) { 349 filled = true; 349 filled = true; 350 std::vector<float>::const_iterator it; 350 std::vector<float>::const_iterator it; 351 for(it=_xyzs.begin();it!=_xyzs.end();){ 351 for(it=_xyzs.begin();it!=_xyzs.end();){ 352 x = *it;it++; 352 x = *it;it++; 353 y = *it;it++; 353 y = *it;it++; 354 z = *it;it++; 354 z = *it;it++; 355 a_action.project_point(x,y,z,w); //in 355 a_action.project_point(x,y,z,w); //in [-1,1][-1,1] 356 _add(pts, x-hsx,y-hsy2,z); 356 _add(pts, x-hsx,y-hsy2,z); 357 _add(pts, x+hsx,y-hsy2,z); 357 _add(pts, x+hsx,y-hsy2,z); 358 _add(pts, x ,y+hsy ,z); 358 _add(pts, x ,y+hsy ,z); 359 359 360 _add(pts, x+hsx,y+hsy2,z); 360 _add(pts, x+hsx,y+hsy2,z); 361 _add(pts, x-hsx,y+hsy2,z); 361 _add(pts, x-hsx,y+hsy2,z); 362 _add(pts, x ,y-hsy ,z); 362 _add(pts, x ,y-hsy ,z); 363 } 363 } 364 364 365 } else if(style.value()==marker_penta_star 365 } else if(style.value()==marker_penta_star_line) { 366 float _cos[5];float _sin[5]; 366 float _cos[5];float _sin[5]; 367 float dtheta = ftwo_pi()/5.0f; 367 float dtheta = ftwo_pi()/5.0f; 368 float theta = fhalf_pi(); 368 float theta = fhalf_pi(); 369 {for(unsigned int i=0;i<5;i++,theta+=dthe 369 {for(unsigned int i=0;i<5;i++,theta+=dtheta) {_cos[i] = rad*fcos(theta);_sin[i] = rad*fsin(theta);}} 370 std::vector<float>::const_iterator it; 370 std::vector<float>::const_iterator it; 371 for(it=_xyzs.begin();it!=_xyzs.end();){ 371 for(it=_xyzs.begin();it!=_xyzs.end();){ 372 x = *it;it++; 372 x = *it;it++; 373 y = *it;it++; 373 y = *it;it++; 374 z = *it;it++; 374 z = *it;it++; 375 a_action.project_point(x,y,z,w); //in 375 a_action.project_point(x,y,z,w); //in [-1,1][-1,1] 376 _add(pts, x+_cos[0],y+_sin[0] ,z); 376 _add(pts, x+_cos[0],y+_sin[0] ,z); 377 _add(pts, x+_cos[2],y+_sin[2] ,z); 377 _add(pts, x+_cos[2],y+_sin[2] ,z); 378 378 379 _add(pts, x+_cos[2],y+_sin[2] ,z); 379 _add(pts, x+_cos[2],y+_sin[2] ,z); 380 _add(pts, x+_cos[4],y+_sin[4] ,z); 380 _add(pts, x+_cos[4],y+_sin[4] ,z); 381 381 382 _add(pts, x+_cos[4],y+_sin[4] ,z); 382 _add(pts, x+_cos[4],y+_sin[4] ,z); 383 _add(pts, x+_cos[1],y+_sin[1] ,z); 383 _add(pts, x+_cos[1],y+_sin[1] ,z); 384 384 385 _add(pts, x+_cos[1],y+_sin[1] ,z); 385 _add(pts, x+_cos[1],y+_sin[1] ,z); 386 _add(pts, x+_cos[3],y+_sin[3] ,z); 386 _add(pts, x+_cos[3],y+_sin[3] ,z); 387 387 388 _add(pts, x+_cos[3],y+_sin[3] ,z); 388 _add(pts, x+_cos[3],y+_sin[3] ,z); 389 _add(pts, x+_cos[0],y+_sin[0] ,z); 389 _add(pts, x+_cos[0],y+_sin[0] ,z); 390 } 390 } 391 } else if(style.value()==marker_penta_star 391 } else if(style.value()==marker_penta_star_filled) { 392 filled = true; 392 filled = true; 393 float _cos[5];float _sin[5]; 393 float _cos[5];float _sin[5]; 394 float dtheta = ftwo_pi()/5.0f; 394 float dtheta = ftwo_pi()/5.0f; 395 float theta = fhalf_pi(); 395 float theta = fhalf_pi(); 396 {for(unsigned int i=0;i<5;i++,theta+=dthe 396 {for(unsigned int i=0;i<5;i++,theta+=dtheta) {_cos[i] = rad*fcos(theta);_sin[i] = rad*fsin(theta);}} 397 vec2f i3; 397 vec2f i3; 398 {vec2f p1(_cos[2],_sin[2]); 398 {vec2f p1(_cos[2],_sin[2]); 399 vec2f q1(_cos[4],_sin[4]); 399 vec2f q1(_cos[4],_sin[4]); 400 vec2f p2(_cos[3],_sin[3]); 400 vec2f p2(_cos[3],_sin[3]); 401 vec2f q2(_cos[0],_sin[0]); 401 vec2f q2(_cos[0],_sin[0]); 402 if(!intersect(p1,q1,p2,q2,i3)) {}} 402 if(!intersect(p1,q1,p2,q2,i3)) {}} 403 vec2f i4; 403 vec2f i4; 404 {vec2f p1(_cos[1],_sin[1]); 404 {vec2f p1(_cos[1],_sin[1]); 405 vec2f q1(_cos[4],_sin[4]); 405 vec2f q1(_cos[4],_sin[4]); 406 vec2f p2(_cos[3],_sin[3]); 406 vec2f p2(_cos[3],_sin[3]); 407 vec2f q2(_cos[0],_sin[0]); 407 vec2f q2(_cos[0],_sin[0]); 408 if(!intersect(p1,q1,p2,q2,i4)) {}} 408 if(!intersect(p1,q1,p2,q2,i4)) {}} 409 vec2f i0; 409 vec2f i0; 410 {vec2f p1(_cos[1],_sin[1]); 410 {vec2f p1(_cos[1],_sin[1]); 411 vec2f q1(_cos[4],_sin[4]); 411 vec2f q1(_cos[4],_sin[4]); 412 vec2f p2(_cos[0],_sin[0]); 412 vec2f p2(_cos[0],_sin[0]); 413 vec2f q2(_cos[2],_sin[2]); 413 vec2f q2(_cos[2],_sin[2]); 414 if(!intersect(p1,q1,p2,q2,i0)) {}} 414 if(!intersect(p1,q1,p2,q2,i0)) {}} 415 std::vector<float>::const_iterator it; 415 std::vector<float>::const_iterator it; 416 for(it=_xyzs.begin();it!=_xyzs.end();){ 416 for(it=_xyzs.begin();it!=_xyzs.end();){ 417 x = *it;it++; 417 x = *it;it++; 418 y = *it;it++; 418 y = *it;it++; 419 z = *it;it++; 419 z = *it;it++; 420 a_action.project_point(x,y,z,w); //in 420 a_action.project_point(x,y,z,w); //in [-1,1][-1,1] 421 _add(pts, x+_cos[0],y+_sin[0] ,z); 421 _add(pts, x+_cos[0],y+_sin[0] ,z); 422 _add(pts, x+_cos[2],y+_sin[2] ,z); 422 _add(pts, x+_cos[2],y+_sin[2] ,z); 423 _add(pts, x+ i3.x(),y+ i3.y() ,z); 423 _add(pts, x+ i3.x(),y+ i3.y() ,z); 424 424 425 _add(pts, x+_cos[1],y+_sin[1] ,z); 425 _add(pts, x+_cos[1],y+_sin[1] ,z); 426 _add(pts, x+_cos[3],y+_sin[3] ,z); 426 _add(pts, x+_cos[3],y+_sin[3] ,z); 427 _add(pts, x+ i4.x(),y+ i4.y() ,z); 427 _add(pts, x+ i4.x(),y+ i4.y() ,z); 428 428 429 _add(pts, x+ i0.x(),y+ i0.y() ,z); 429 _add(pts, x+ i0.x(),y+ i0.y() ,z); 430 _add(pts, x+_cos[2],y+_sin[2] ,z); 430 _add(pts, x+_cos[2],y+_sin[2] ,z); 431 _add(pts, x+_cos[4],y+_sin[4] ,z); 431 _add(pts, x+_cos[4],y+_sin[4] ,z); 432 } 432 } 433 433 434 } else if(style.value()==marker_plus) { 434 } else if(style.value()==marker_plus) { 435 std::vector<float>::const_iterator it; 435 std::vector<float>::const_iterator it; 436 for(it=_xyzs.begin();it!=_xyzs.end();){ 436 for(it=_xyzs.begin();it!=_xyzs.end();){ 437 x = *it;it++; 437 x = *it;it++; 438 y = *it;it++; 438 y = *it;it++; 439 z = *it;it++; 439 z = *it;it++; 440 a_action.project_point(x,y,z,w); //in 440 a_action.project_point(x,y,z,w); //in [-1,1][-1,1] 441 _add(pts, x-hsx,y,z); 441 _add(pts, x-hsx,y,z); 442 _add(pts, x+hsx,y,z); 442 _add(pts, x+hsx,y,z); 443 _add(pts, x ,y-hsy,z); 443 _add(pts, x ,y-hsy,z); 444 _add(pts, x ,y+hsy,z); 444 _add(pts, x ,y+hsy,z); 445 } 445 } 446 } else if(style.value()==marker_asterisk) 446 } else if(style.value()==marker_asterisk) { 447 std::vector<float>::const_iterator it; 447 std::vector<float>::const_iterator it; 448 for(it=_xyzs.begin();it!=_xyzs.end();){ 448 for(it=_xyzs.begin();it!=_xyzs.end();){ 449 x = *it;it++; 449 x = *it;it++; 450 y = *it;it++; 450 y = *it;it++; 451 z = *it;it++; 451 z = *it;it++; 452 a_action.project_point(x,y,z,w); //in 452 a_action.project_point(x,y,z,w); //in [-1,1][-1,1] 453 _add(pts, x ,y-hsy ,z); 453 _add(pts, x ,y-hsy ,z); 454 _add(pts, x ,y+hsy ,z); 454 _add(pts, x ,y+hsy ,z); 455 _add(pts, x-hsx,y-hsy2,z); 455 _add(pts, x-hsx,y-hsy2,z); 456 _add(pts, x+hsx,y+hsy2,z); 456 _add(pts, x+hsx,y+hsy2,z); 457 _add(pts, x-hsx,y+hsy2,z); 457 _add(pts, x-hsx,y+hsy2,z); 458 _add(pts, x+hsx,y-hsy2,z); 458 _add(pts, x+hsx,y-hsy2,z); 459 } 459 } 460 } else if(style.value()==marker_star) { 460 } else if(style.value()==marker_star) { 461 std::vector<float>::const_iterator it; 461 std::vector<float>::const_iterator it; 462 for(it=_xyzs.begin();it!=_xyzs.end();){ 462 for(it=_xyzs.begin();it!=_xyzs.end();){ 463 x = *it;it++; 463 x = *it;it++; 464 y = *it;it++; 464 y = *it;it++; 465 z = *it;it++; 465 z = *it;it++; 466 a_action.project_point(x,y,z,w); //in 466 a_action.project_point(x,y,z,w); //in [-1,1][-1,1] 467 _add(pts, x ,y-hsy ,z); 467 _add(pts, x ,y-hsy ,z); 468 _add(pts, x ,y+hsy ,z); 468 _add(pts, x ,y+hsy ,z); 469 _add(pts, x-hsx,y-hsy2,z); 469 _add(pts, x-hsx,y-hsy2,z); 470 _add(pts, x+hsx,y+hsy2,z); 470 _add(pts, x+hsx,y+hsy2,z); 471 _add(pts, x-hsx,y+hsy2,z); 471 _add(pts, x-hsx,y+hsy2,z); 472 _add(pts, x+hsx,y-hsy2,z); 472 _add(pts, x+hsx,y-hsy2,z); 473 _add(pts, x-hsx,y ,z); 473 _add(pts, x-hsx,y ,z); 474 _add(pts, x+hsx,y ,z); 474 _add(pts, x+hsx,y ,z); 475 } 475 } 476 } else if(style.value()==marker_minus) { 476 } else if(style.value()==marker_minus) { 477 std::vector<float>::const_iterator it; 477 std::vector<float>::const_iterator it; 478 for(it=_xyzs.begin();it!=_xyzs.end();){ 478 for(it=_xyzs.begin();it!=_xyzs.end();){ 479 x = *it;it++; 479 x = *it;it++; 480 y = *it;it++; 480 y = *it;it++; 481 z = *it;it++; 481 z = *it;it++; 482 a_action.project_point(x,y,z,w); //in 482 a_action.project_point(x,y,z,w); //in [-1,1][-1,1] 483 _add(pts, x-hsx,y,z); 483 _add(pts, x-hsx,y,z); 484 _add(pts, x+hsx,y,z); 484 _add(pts, x+hsx,y,z); 485 } 485 } 486 } else { //marker_cross. 486 } else { //marker_cross. 487 std::vector<float>::const_iterator it; 487 std::vector<float>::const_iterator it; 488 for(it=_xyzs.begin();it!=_xyzs.end();){ 488 for(it=_xyzs.begin();it!=_xyzs.end();){ 489 x = *it;it++; 489 x = *it;it++; 490 y = *it;it++; 490 y = *it;it++; 491 z = *it;it++; 491 z = *it;it++; 492 a_action.project_point(x,y,z,w); //in 492 a_action.project_point(x,y,z,w); //in [-1,1][-1,1] 493 _add(pts, x-hsx,y-hsy,z); 493 _add(pts, x-hsx,y-hsy,z); 494 _add(pts, x+hsx,y+hsy,z); 494 _add(pts, x+hsx,y+hsy,z); 495 _add(pts, x+hsx,y-hsy,z); 495 _add(pts, x+hsx,y-hsy,z); 496 _add(pts, x-hsx,y+hsy,z); 496 _add(pts, x-hsx,y+hsy,z); 497 } 497 } 498 } 498 } 499 499 500 a_action.load_matrices_to_identity(); 500 a_action.load_matrices_to_identity(); 501 501 502 //Same logic as Inventor SoLightModel.mode 502 //Same logic as Inventor SoLightModel.model = BASE_COLOR. 503 a_action.set_lighting(false); 503 a_action.set_lighting(false); 504 a_action.draw_vertex_array(filled?gl::tria 504 a_action.draw_vertex_array(filled?gl::triangles():gl::lines(),pts); 505 a_action.set_lighting(a_action.state().m_G 505 a_action.set_lighting(a_action.state().m_GL_LIGHTING); 506 a_action.load_matrices_from_state(); 506 a_action.load_matrices_from_state(); 507 } 507 } 508 508 509 virtual void pick(pick_action& a_action) { 509 virtual void pick(pick_action& a_action) { 510 size_t num = xyzs.size()/3; 510 size_t num = xyzs.size()/3; 511 if(!num) return; 511 if(!num) return; 512 512 513 state& state = a_action.state(); 513 state& state = a_action.state(); 514 514 515 const std::vector<float>& _xyzs = xyzs.val 515 const std::vector<float>& _xyzs = xyzs.values(); 516 516 517 std::vector<float> pts; 517 std::vector<float> pts; 518 518 519 float sx = size.value()/float(state.m_ww); 519 float sx = size.value()/float(state.m_ww); //in [-1,1] 520 float hsx = sx*0.5f; 520 float hsx = sx*0.5f; 521 521 522 float sy = size.value()/float(state.m_wh); 522 float sy = size.value()/float(state.m_wh); //in [-1,1] 523 float hsy = sy*0.5f; 523 float hsy = sy*0.5f; 524 524 525 float x,y,z,w; 525 float x,y,z,w; 526 526 527 std::vector<float>::const_iterator it; 527 std::vector<float>::const_iterator it; 528 for(it=_xyzs.begin();it!=_xyzs.end();){ 528 for(it=_xyzs.begin();it!=_xyzs.end();){ 529 x = *it;it++; 529 x = *it;it++; 530 y = *it;it++; 530 y = *it;it++; 531 z = *it;it++; 531 z = *it;it++; 532 532 533 a_action.project_point(x,y,z,w); //in [- 533 a_action.project_point(x,y,z,w); //in [-1,1][-1,1] 534 534 535 _add(pts, x-hsx,y-hsy,z); //in [-1,1][- 535 _add(pts, x-hsx,y-hsy,z); //in [-1,1][-1,1] 536 _add(pts, x+hsx,y+hsy,z); 536 _add(pts, x+hsx,y+hsy,z); 537 _add(pts, x+hsx,y-hsy,z); 537 _add(pts, x+hsx,y-hsy,z); 538 _add(pts, x-hsx,y+hsy,z); 538 _add(pts, x-hsx,y+hsy,z); 539 } 539 } 540 540 541 a_action.set_matrices_to_identity(); 541 a_action.set_matrices_to_identity(); 542 a_action.add__lines(*this,pts); 542 a_action.add__lines(*this,pts); 543 a_action.set_matrices_from_state(); 543 a_action.set_matrices_from_state(); 544 } 544 } 545 545 546 virtual void bbox(bbox_action& a_action) { 546 virtual void bbox(bbox_action& a_action) { 547 const std::vector<float>& _xyzs = xyzs.val 547 const std::vector<float>& _xyzs = xyzs.values(); 548 float x,y,z; 548 float x,y,z; 549 std::vector<float>::const_iterator it; 549 std::vector<float>::const_iterator it; 550 for(it=_xyzs.begin();it!=_xyzs.end();){ 550 for(it=_xyzs.begin();it!=_xyzs.end();){ 551 x = *it;it++; 551 x = *it;it++; 552 y = *it;it++; 552 y = *it;it++; 553 z = *it;it++; 553 z = *it;it++; 554 a_action.add_one_point(x,y,z); 554 a_action.add_one_point(x,y,z); 555 } 555 } 556 } 556 } 557 public: 557 public: 558 markers() 558 markers() 559 :parent() 559 :parent() 560 ,style(marker_cross) 560 ,style(marker_cross) 561 ,size(10) 561 ,size(10) 562 { 562 { 563 #ifdef TOOLS_MEM 563 #ifdef TOOLS_MEM 564 mem::increment(s_class().c_str()); 564 mem::increment(s_class().c_str()); 565 #endif 565 #endif 566 add_fields(); 566 add_fields(); 567 } 567 } 568 virtual ~markers(){ 568 virtual ~markers(){ 569 #ifdef TOOLS_MEM 569 #ifdef TOOLS_MEM 570 mem::decrement(s_class().c_str()); 570 mem::decrement(s_class().c_str()); 571 #endif 571 #endif 572 } 572 } 573 public: 573 public: 574 markers(const markers& a_from) 574 markers(const markers& a_from) 575 :parent(a_from) 575 :parent(a_from) 576 ,style(a_from.style) 576 ,style(a_from.style) 577 ,xyzs(a_from.xyzs) 577 ,xyzs(a_from.xyzs) 578 ,size(a_from.size) 578 ,size(a_from.size) 579 { 579 { 580 #ifdef TOOLS_MEM 580 #ifdef TOOLS_MEM 581 mem::increment(s_class().c_str()); 581 mem::increment(s_class().c_str()); 582 #endif 582 #endif 583 add_fields(); 583 add_fields(); 584 } 584 } 585 markers& operator=(const markers& a_from){ 585 markers& operator=(const markers& a_from){ 586 parent::operator=(a_from); 586 parent::operator=(a_from); 587 style = a_from.style; 587 style = a_from.style; 588 xyzs = a_from.xyzs; 588 xyzs = a_from.xyzs; 589 size = a_from.size; 589 size = a_from.size; 590 return *this; 590 return *this; 591 } 591 } 592 public: 592 public: 593 template <class VEC> 593 template <class VEC> 594 void add(const VEC& a_v) { 594 void add(const VEC& a_v) { 595 xyzs.add(a_v.x()); 595 xyzs.add(a_v.x()); 596 xyzs.add(a_v.y()); 596 xyzs.add(a_v.y()); 597 xyzs.add(a_v.z()); 597 xyzs.add(a_v.z()); 598 } 598 } 599 void add(float a_x,float a_y,float a_z) { 599 void add(float a_x,float a_y,float a_z) { 600 xyzs.add(a_x); 600 xyzs.add(a_x); 601 xyzs.add(a_y); 601 xyzs.add(a_y); 602 xyzs.add(a_z); 602 xyzs.add(a_z); 603 } 603 } 604 void add_allocated(size_t& a_pos,float a_x,f 604 void add_allocated(size_t& a_pos,float a_x,float a_y,float a_z) { 605 std::vector<float>& v = xyzs.values(); 605 std::vector<float>& v = xyzs.values(); 606 v[a_pos] = a_x;a_pos++; 606 v[a_pos] = a_x;a_pos++; 607 v[a_pos] = a_y;a_pos++; 607 v[a_pos] = a_y;a_pos++; 608 v[a_pos] = a_z;a_pos++; 608 v[a_pos] = a_z;a_pos++; 609 xyzs.touch(); 609 xyzs.touch(); 610 } 610 } 611 bool add(const std::vector<float>& a_v) { 611 bool add(const std::vector<float>& a_v) { 612 std::vector<float>::size_type _number = a_ 612 std::vector<float>::size_type _number = a_v.size()/3; 613 if(3*_number!=a_v.size()) return false; 613 if(3*_number!=a_v.size()) return false; 614 std::vector<float>::const_iterator it; 614 std::vector<float>::const_iterator it; 615 for(it=a_v.begin();it!=a_v.end();it+=3) { 615 for(it=a_v.begin();it!=a_v.end();it+=3) { 616 xyzs.add(*(it+0)); 616 xyzs.add(*(it+0)); 617 xyzs.add(*(it+1)); 617 xyzs.add(*(it+1)); 618 xyzs.add(*(it+2)); 618 xyzs.add(*(it+2)); 619 } 619 } 620 return true; 620 return true; 621 } 621 } 622 size_t number() const {return xyzs.size()/3; 622 size_t number() const {return xyzs.size()/3;} 623 void clear() {xyzs.clear();} 623 void clear() {xyzs.clear();} 624 protected: 624 protected: 625 void _add(std::vector<float>& a_v,float a_x, 625 void _add(std::vector<float>& a_v,float a_x,float a_y,float a_z) { 626 a_v.push_back(a_x); 626 a_v.push_back(a_x); 627 a_v.push_back(a_y); 627 a_v.push_back(a_y); 628 a_v.push_back(a_z); 628 a_v.push_back(a_z); 629 } 629 } 630 }; 630 }; 631 631 632 }} 632 }} 633 633 634 #endif 634 #endif