QuadricCollision.cpp
Go to the documentation of this file.
4 
5 static const double MAX_COLLISION_CHECK_DIST = 200; // mm
6 
7 namespace{
8 
9 double WF_edge_euclid_dist(WF_edge* eu, WF_edge* ev)
10 {
11  auto u = eu->CenterPos();
12  auto v = ev->CenterPos();
13 
14  double dx = u.x() - v.x();
15  double dy = u.y() - v.y();
16  double dz = u.z() - v.z();
17  return sqrt(dx*dx + dy*dy + dz*dz);
18 }
19 
20 } // anon util namespace
21 
23 {
24 }
25 
27 {
28  ptr_frame_ = ptr_frame;
29 
30  // this shouldn't be changed, current implementation is highly
31  // crafted for this specific division resolution
32  divide_ = 60;
33 
34  int halfM = ptr_frame->SizeOfEdgeList() / 2;
35  colli_map_.resize(halfM*halfM);
36 
37  for (int i = 0; i < halfM*halfM; i++)
38  {
39  colli_map_[i] = NULL;
40  }
41 }
42 
44 {
45  int Nc = colli_map_.size();
46  for (int i = 0; i < Nc; i++)
47  {
48  if (NULL != colli_map_[i])
49  {
50  delete colli_map_[i];
51  colli_map_[i] = NULL;
52  }
53  }
54 }
55 
56 void QuadricCollision::Init(std::vector<lld>& colli_map)
57 {
58  lld temp = 0;
59  colli_map.clear();
60  colli_map.reserve(3);
61  colli_map.push_back(temp);
62  colli_map.push_back(temp);
63  colli_map.push_back(temp);
64 
65  // initial domain pruning
66  for(int i = 0; i < divide_; i++)
67  {
68  lld mask = ((lld) 1 << i);
69 
70  for(int j = 0; j < 3; j++)
71  {
72  // i-th bit = 0 means it's feasible
73  double theta = 0.0;
74  if (i < 20)
75  {
76  theta = (j * 3 + 1) * 18.0 / 180.0 * F_PI;
77  }
78 
79  if (i > 19 && i < 40)
80  {
81  theta = (j * 3 + 2) * 18.0 / 180.0 * F_PI;
82  }
83 
84  if (i > 39)
85  {
86  theta = (j * 3 + 3)* 18.0 / 180.0 * F_PI;
87  }
88 
89 // if(theta > F_PI - extruder_.Angle())
90  if(theta > F_PI - 75.0 / 180.0 * F_PI)
91  {
92  colli_map[j] |= mask;
93  }
94  }
95  }
96 }
97 
98 bool QuadricCollision::DetectCollision(WF_edge *target_e, DualGraph *ptr_subgraph,
99  vector<lld> &result_map)
100 {
101  Init(result_map);
102  target_e_ = target_e;
103 
104  bool change_flag = false;
105 
106  /* collision with edge */
107  int Nd = ptr_subgraph->SizeOfVertList();
108  for (int i = 0; i < Nd; i++)
109  {
110  // prune target_e's domain with existing edges
111  WF_edge* e = ptr_frame_->GetEdge(ptr_subgraph->e_orig_id(i));
112 
113  if (ptr_subgraph->isExistingEdge(e) && e != target_e_ && e != target_e_->ppair_)
114  {
115  change_flag = DetectEdge(e, result_map);
116  }
117  }
118 
119  return change_flag;
120 }
121 
123  std::vector<lld> &result_map)
124 {
125  Init(result_map);
126  target_e_ = target_e;
127 
128  /* collision with edge */
129  return(DetectEdge(order_e, result_map));
130 }
131 
132 void QuadricCollision::DetectCollision(WF_edge *target_e, std::vector<WF_edge*> exist_edge,
133  std::vector<GeoV3>& output)
134 {
135  output.clear();
136 
137  double theta, phi;
138  target_e_ = target_e;
139 
140  //North Point
141  if(!DetectEdges(exist_edge, 0, 0))
142  {
143  output.push_back(Orientation(0, 0));
144  }
145 
146  for (int j = 0; j < 3; j++)
147  {
148  for (int i = 0; i < divide_; i++)
149  {
150  if (i < 20)
151  {
152  theta = (j * 3 + 1) * 18.0 / 180.0 * F_PI;
153  }
154 
155  if (i > 19 && i < 40)
156  {
157  theta = (j * 3 + 2) * 18.0 / 180.0 * F_PI;
158  }
159 
160  if (i > 39)
161  {
162  theta = (j * 3 + 3) * 18.0 / 180.0 * F_PI;
163  }
164 
165  // divide = 60, 180 degree / 20 = 9 degree resolution
166  phi = (i % 20) * 18.0 / 180.0 * F_PI;
167 
168  if(DetectEdges(exist_edge, theta, phi))
169  {
170  continue;
171  }
172 
173  output.push_back(Orientation(theta, phi));
174  }
175  }
176 
177  //South Point not consider
178  /*if (!DetectEdges(exist_edge_, 0, 0))
179  temp.push_back(Orientation(F_PI, 0));*/
180 }
181 
182 void QuadricCollision::ModifyAngle(std::vector<lld>& angle_state, const std::vector<lld>& colli_map)
183 {
184  for (int i = 0; i < 3; i++)
185  {
186  angle_state[i] |= colli_map[i];
187  }
188 }
189 
190 int QuadricCollision::ColFreeAngle(const std::vector<lld>& colli_map)
191 {
192  if (colli_map[0] == (lld) 0 && colli_map[1] == (lld) 0 && colli_map[2] == (lld) 0)
193  {
194  // all directions are feasible
195  return Divide();
196  }
197 
198  int sum_angle = 0;
199  for(int j = 0; j < 62; j++)
200  {
201  lld mask = ((lld) 1 << j);
202 
203  for(int i = 0; i < 3; i++)
204  {
205  if(i != 2 && j > 59)
206  {
207  // south and north point is only recorded on channel 2 - 60 and 61 level
208  continue;
209  }
210 
211  // j-th bit = 0 means it's feasible
212  if((colli_map[i] & mask) == 0)
213  {
214  sum_angle++;
215  }
216  }
217  }
218 
219  return sum_angle;
220 }
221 
222 std::vector<Eigen::Vector3d> QuadricCollision::ConvertCollisionMapToEigenDirections(const std::vector<lld>& colli_map)
223 {
224  std::vector<Eigen::Vector3d> feasible_eef_directions;
225 
226  for(int i = 0; i < divide_; i++)
227  {
228  lld mask = ((lld) 1 << i);
229 
230  for(int j = 0; j < 3; j++)
231  {
232  // i-th bit = 0 means it's feasible
233  if((colli_map[j] & mask) == 0)
234  {
235  double phi = (i % 20) * 18.0 / 180.0 * F_PI;
236 
237  double theta = 0.0;
238  if (i < 20)
239  {
240  theta = (j * 3 + 1) * 18.0 / 180.0 * F_PI;
241  }
242 
243  if (i > 19 && i < 40)
244  {
245  theta = (j * 3 + 2) * 18.0 / 180.0 * F_PI;
246  }
247 
248  if (i > 39)
249  {
250  theta = (j * 3 + 3)* 18.0 / 180.0 * F_PI;
251  }
252 
253  feasible_eef_directions.push_back(ConvertAngleToEigenDirection(theta, phi));
254  }
255  }
256  }
257 
258  //North Point
259  lld north_mask = ((lld)1 << 60);
260  if((colli_map[2] & north_mask) == 0)
261  {
262  feasible_eef_directions.push_back(ConvertAngleToEigenDirection(0, 0));
263  }
264 
265  //South Point
266  lld south_mask = ((lld)1 << 61);
267  if((colli_map[2] & south_mask) == 0)
268  {
269  feasible_eef_directions.push_back(ConvertAngleToEigenDirection(F_PI, 0));
270  }
271 
272  return feasible_eef_directions;
273 }
274 
275 std::vector<int> QuadricCollision::ConvertCollisionMapToIntMap(const std::vector<lld>& colli_map)
276 {
277  // in int map, 0 means exist collision, 1 means collision-free
278  std::vector<int> int_map(this->Divide(), 0);
279 
280  for(int j = 0; j < 3; j++)
281  {
282  for(int i = 0; i < divide_; i++)
283  {
284  lld mask = ((lld) 1 << i);
285 
286  // i-th bit = 0 means it's feasible
287  if((colli_map[j] & mask) == 0)
288  {
289  int_map[j * divide_ + i] = 1;
290  }
291  }
292  }
293 
294  //North Point
295  lld north_mask = ((lld)1 << 60);
296  if((colli_map[2] & north_mask) == 0)
297  {
298  int_map[3*divide_] = 1;
299  }
300 
301  //South Point
302  lld south_mask = ((lld)1 << 61);
303  if((colli_map[2] & south_mask) == 0)
304  {
305  int_map[3*divide_ + 1] = 1;
306  }
307 
308  return int_map;
309 }
310 
311 bool QuadricCollision::DetectEdge(WF_edge *order_e, std::vector<lld> &result_map)
312 {
313  if(WF_edge_euclid_dist(target_e_, order_e) > MAX_COLLISION_CHECK_DIST)
314  {
315  // if this existing edge is too far away from target_e_, we assume that
316  // there's no constraint arc between the target_e and order_e
317 
318  // return false if too far away
319  return false;
320  }
321 
322  int halfM = ptr_frame_->SizeOfEdgeList() / 2;
323  int mi = order_e->ID() / 2 * halfM + target_e_->ID() / 2;
324 
325  if (colli_map_[mi] == NULL)
326  {
327  colli_map_[mi] = new vector<lld>;
328  Init(*colli_map_[mi]);
329 
330  // https://en.wikipedia.org/wiki/Spherical_coordinate_system
331  // ISO naming convention (commonly used in physics)
332  // polar angle theta (rad)
333  double theta;
334 
335  // azimuthal angle (rad)
336  double phi;
337 
338  for (int j = 0; j < 3; j++)
339  {
340  for (int i = 0; i < divide_; i++)
341  {
342  if (i < 20)
343  {
344  theta = (j * 3 + 1) * 18.0 / 180.0 * F_PI;
345  }
346 
347  if (i > 19 && i < 40)
348  {
349  theta = (j * 3 + 2) * 18.0 / 180.0 * F_PI;
350  }
351 
352  if (i > 39)
353  {
354  theta = (j * 3 + 3)* 18.0 / 180.0 * F_PI;
355  }
356 
357  phi = (i % 20) * 18.0 / 180.0 * F_PI;
358 
359  // left shift 1 to i-th bit
360  lld mask = ((lld)1 << i);
361 
362  if(DetectBulk(order_e, theta, phi))
363  {
364  // make i-th bit to 1, means collision
365  (*colli_map_[mi])[j] |= mask;
366  }
367  }
368  }
369 
370  //North Point
371  lld mask = ((lld)1 << 60);
372  if (DetectBulk(order_e, 0, 0))
373  {
374  (*colli_map_[mi])[2] |= mask;
375  }
376 
377  //South Point
378  mask = ((lld)1 << 61);
379  if (DetectBulk(order_e, F_PI, 0))
380  {
381  (*colli_map_[mi])[2] |= mask;
382  }
383  }
384 
385  for (int i = 0; i < 3; i++)
386  {
387  result_map[i] |= (*colli_map_[mi])[i];
388  }
389 
390  return true;
391 }
392 
393 bool QuadricCollision::DetectEdges(std::vector<WF_edge*> exist_edge, double theta, double phi)
394 {
395 for (int i = 0; i < exist_edge.size(); i++)
396 {
397 if (DetectBulk(exist_edge[i], theta, phi))
398 {
399 return true;
400 }
401 }
402 
403 // no collision
404 return false;
405 }
406 
407 bool QuadricCollision::DetectBulk(WF_edge *order_e, double theta, double phi)
408 {
409  GeoV3 target_start = target_e_->pvert_->Position();
410  GeoV3 target_end = target_e_->ppair_->pvert_->Position();
411  GeoV3 order_start = order_e->pvert_->Position();
412  GeoV3 order_end = order_e->ppair_->pvert_->Position();
413  GeoV3 normal = Orientation(theta, phi);
414 
415  //0
416  if (Parallel(normal, target_start - target_end))
417  {
418  if (ParallelCase(target_start, target_end, order_start, order_end, normal))
419  {
420  return true;
421  }
422  return false;
423  }
424 
425  //1
426  if ((target_start - order_end).norm() < GEO_EPS)
427  {
428  if (SpecialCase(target_start,target_end,order_start,normal ))
429  {
430  return true;
431  }
432  return false;
433  }
434 
435  if ((target_start - order_start).norm() < GEO_EPS)
436  {
437  if (SpecialCase(target_start, target_end, order_end, normal))
438  {
439  return true;
440  }
441  return false;
442  }
443 
444  if ((target_end - order_end).norm() < GEO_EPS)
445  {
446  if (SpecialCase(target_end, target_start, order_start, normal))
447  {
448  return true;
449  }
450  return false;
451  }
452 
453  if ((target_end - order_start).norm() < GEO_EPS)
454  {
455  if (SpecialCase(target_end, target_start, order_end, normal))
456  {
457  return true;
458  }
459  return false;
460  }
461 
462  //2
463  if (Case(target_start, target_end, order_start, order_end, normal))
464  {
465  return true;
466  }
467 
468  return false;
469 }
470 
471 bool QuadricCollision::DetectAngle(GeoV3 connect, GeoV3 end, GeoV3 target_end, GeoV3 normal)
472 {
473  if (angle(normal, target_end - connect) < extruder_.Angle())
474  return true;
475  return false;
476 }
477 
478 bool QuadricCollision::Case(GeoV3 target_start, GeoV3 target_end,
479  GeoV3 order_start, GeoV3 order_end, GeoV3 normal)
480 {
481  //Cone
482  if (DetectCone(target_start, normal, order_start, order_end))
483  return true;
484 
485  if (DetectCone(target_end, normal, order_start, order_end))
486  return true;
487 
488  //Cylinder
489  if (DetectCylinder(target_start, normal, order_start, order_end))
490  return true;
491 
492  if (DetectCylinder(target_end, normal, order_start, order_end))
493  return true;
494 
495 #ifdef STRICT_COLLISION
496  //Top
497  if (DetectTopCylinder(target_start, normal, order_start, order_end))
498  return true;
499  if (DetectTopCylinder(target_end, normal, order_start, order_end))
500  return true;
501 #endif // STRICT_COLLISION
502 
503  //Face
504  GenerateVolume(target_start, target_end, order_start, order_end, normal);
505  for (int i = 0; i < bulk_.size(); i++)
506  {
507  if (DetectTriangle(bulk_[i], order_start, order_end))
508  return true;
509  }
510 
511  return false;
512 }
513 
514 bool QuadricCollision::SpecialCase(GeoV3 connect, GeoV3 target_s, GeoV3 order_s, GeoV3 normal)
515 {
516  if (angle(normal, order_s - connect) < extruder_.Angle())
517  {
518  return true;
519  }
520 
521  if (DetectCone(target_s, normal, connect, order_s))
522  return true;
523 
524  if (DetectCylinder(target_s, normal, connect, order_s))
525  return true;
526 
527 #ifdef STRICT_COLLISION
528  //Top
529  if (DetectTopCylinder(connect, normal, connect, order_s))
530  return true;
531  if (DetectTopCylinder(target_s, normal, connect, order_s))
532  return true;
533 #endif
534 
535  //Face
536  GenerateVolume(connect, target_s, order_s, normal);
537  for (int i = 0; i < bulk_.size(); i++)
538  {
539  if (DetectTriangle(bulk_[i], connect, order_s))
540  return true;
541  }
542 
543  return false;
544 }
545 
546 bool QuadricCollision::ParallelCase(GeoV3 target_start, GeoV3 target_end,
547  GeoV3 order_start, GeoV3 order_end, GeoV3 normal)
548 {
549 
550  //Exception situation
551  if ((target_start - order_end).norm() < GEO_EPS)
552  {
553  if (DetectAngle(target_start, target_end, order_start, normal))
554  {
555  return true;
556  }
557  }
558  if ((target_start - order_start).norm() < GEO_EPS)
559  {
560  if (DetectAngle(target_start, target_end, order_end, normal))
561  {
562 
563  return true;
564  }
565  }
566  if ((target_end - order_end).norm() < GEO_EPS)
567  {
568  if (DetectAngle(target_end, target_start, order_start, normal))
569  {
570 
571  return true;
572  }
573  }
574  if ((target_end - order_start).norm() < GEO_EPS)
575  {
576  if (DetectAngle(target_end, target_start, order_end, normal))
577  {
578 
579  return true;
580  }
581  }
582 
583  //Normal situation
584  //Cone
585  if (DetectCone(target_start, normal, order_start, order_end))
586  return true;
587 
588  if (DetectCone(target_end, normal, order_start, order_end))
589  return true;
590 
591  //Cylinder
592  if (DetectCylinder(target_start, normal, order_start, order_end))
593  return true;
594 
595  if (DetectCylinder(target_end, normal, order_start, order_end))
596  return true;
597 
598 #ifdef STRICT_COLLISION
599  //Top
600  if (DetectTopCylinder(target_start, normal, order_start, order_end))
601  return true;
602  if (DetectTopCylinder(target_end, normal, order_start, order_end))
603  return true;
604 
605 #endif
606 
607  return false;
608 }
609 
610 
611 bool QuadricCollision::DetectCone(GeoV3 start, GeoV3 normal, GeoV3 target_start, GeoV3 target_end)
612 {
613  gte::Cone3<float> start_cone;
614  start_cone.angle = extruder_.Angle();
615  start_cone.height = extruder_.Height();
616 
617  gte::Ray3<float> start_ray;
618 
619  std::array<float, 3>s;
620  s[0] = start.getX(); s[1] = start.getY(); s[2] = start.getZ();
621  start_ray.origin = s;
622  s[0] = normal.getX(); s[1] = normal.getY(); s[2] = normal.getZ();
623  start_ray.direction = s;
624  start_cone.ray = start_ray;
625  gte::Segment<3, float> segment;
626  segment = Seg(target_start, target_end);
628  auto result = intersection(segment, start_cone);
629 
630  return result.intersect;
631 }
632 
633 bool QuadricCollision::DetectCylinder(GeoV3 start, GeoV3 normal, GeoV3 target_start, GeoV3 target_end)
634 {
635  gte::Cylinder3<float> cylinder;
636  cylinder.axis;
637  gte::Line3<float> cylinder_line;
638 
639  std::array<float, 3>s;
640 
641  GeoV3 cylin_center;
642  cylin_center = start + normal * (extruder_.Height() + extruder_.CyclinderLenth()/2);
643 
644  s[0] = cylin_center.getX(); s[1] = cylin_center.getY(); s[2] = cylin_center.getZ();
645  cylinder_line.origin = s;
646  s[0] = normal.getX(); s[1] = normal.getY(); s[2] = normal.getZ();
647  cylinder_line.direction = s;
648 
649  cylinder.axis = cylinder_line;
650 
651  cylinder.height = extruder_.CyclinderLenth();
652  cylinder.radius = extruder_.Radii();
653 
654  gte::Segment<3, float> segment;
655  segment = Seg(target_start, target_end);
657  auto fiq_result = fiq(segment, cylinder);
658 
659  return fiq_result.intersect;
660 }
661 
662 bool QuadricCollision::DetectTriangle(Triangle triangle, GeoV3 target_start, GeoV3 target_end)
663 {
664  gte::Triangle<3, float> triangle_ = Tri(triangle.v0(), triangle.v1(), triangle.v2());
665 
667  gte::Segment<3, float> segment = Seg(target_start, target_end);
668 
669  auto fiq_result = fiq(segment, triangle_);
670  return fiq_result.intersect;
671 }
672 
673 bool QuadricCollision::DetectTopCylinder(GeoV3 start, GeoV3 normal, GeoV3 target_start, GeoV3 target_end)
674 {
675  gte::Cylinder3<float> cylinder;
676  cylinder.axis;
677  gte::Line3<float> cylinder_line;
678  std::array<float, 3>s;
679  GeoV3 cylin_center;
680  cylin_center = start + normal*extruder_.TopCenter();
681  s[0] = cylin_center.getX(); s[1] = cylin_center.getY(); s[2] = cylin_center.getZ();
682  cylinder_line.origin = s;
683  s[0] = normal.getX(); s[1] = normal.getY(); s[2] = normal.getZ();
684  cylinder_line.direction = s;
685  cylinder.axis = cylinder_line;
686 
687  cylinder.height = extruder_.ToolLenth();
688  cylinder.radius = extruder_.TopRadii();
689 
690 
691  gte::Segment<3, float> segment;
692  segment = Seg(target_start, target_end);
694  auto fiq_result = fiq(segment, cylinder);
695 
696  return fiq_result.intersect;
697 }
698 
700  GeoV3 target_start, GeoV3 target_end, GeoV3 normal)
701 {
702  //face: front (up, down) back(up,down)
703  GeoV3 t = end - start;
704  double edge_length = t.norm();
705  t.normalize();
706 
707  GeoV3 p = cross(t, normal);
708  p.normalize();
709 
710  GeoV3 start_cone_center = normal*extruder_.Height() + start;
711  GeoV3 end_cone_center = normal*extruder_.Height() + end;
712 
713  //face front
714  GeoV3 start_front_cone = start_cone_center + p*extruder_.Radii();
715  GeoV3 start_front_cylinder = start_front_cone + normal*extruder_.CyclinderLenth();
716  GeoV3 end_front_cone = end_cone_center + p*extruder_.Radii();
717  GeoV3 end_front_cylinder = end_front_cone + normal*extruder_.CyclinderLenth();
718 
719  //face back
720  GeoV3 start_back_cone = start_cone_center - p*extruder_.Radii();
721  GeoV3 start_back_cylinder = start_back_cone + normal*extruder_.CyclinderLenth();
722  GeoV3 end_back_cone = end_cone_center - p*extruder_.Radii();
723  GeoV3 end_back_cylinder = end_back_cone + normal*extruder_.CyclinderLenth();
724 
725  bulk_.clear();
726 
727 #ifdef STRICT_COLLISION
728  //Circle
729  GeoV3 q = cross(normal, p);
730  q.normalize();
731  vector<GeoV3> start_circle_point,end_circle_point;
732  for (int i = 0; i < 16; i++)
733  {
734  double part = 2 * F_PI / 16;
735  double theta = i*part;
736  start_circle_point.push_back(start_cone_center + p*cos(theta)*extruder_.Radii() + q*sin(theta)*extruder_.Radii());
737  end_circle_point.push_back(start_circle_point[i] + end - start);
738  }
739 
740  for (int i = 0; i < 15; i++)
741  {
742  bulk_.push_back(Triangle(start_circle_point[i], start_circle_point[i + 1], end_circle_point[i]));
743  bulk_.push_back(Triangle(end_circle_point[i], end_circle_point[i + 1], start_circle_point[i + 1]));
744  }
745  bulk_.push_back(Triangle(start_circle_point[15], start_circle_point[0], end_circle_point[15]));
746  bulk_.push_back(Triangle(end_circle_point[15], end_circle_point[0], start_circle_point[0]));
747 
748  for (int i = 0; i < 15; i++)
749  {
750  bulk_.push_back(Triangle(start_circle_point[i], start_circle_point[i + 1], end_circle_point[i]));
751  bulk_.push_back(Triangle(end_circle_point[i], end_circle_point[i + 1], start_circle_point[i + 1]));
752  }
753  bulk_.push_back(Triangle(start_circle_point[15], start_circle_point[0], end_circle_point[15]));
754  bulk_.push_back(Triangle(end_circle_point[15], end_circle_point[0], start_circle_point[0]));
755 
756  //Top face
757 
758  GeoV3 start_top_front_up = start + normal*(extruder_.TopLenth() / 2 + extruder_.TopCenter())+p*extruder_.TopRadii();
759  GeoV3 start_top_front_down = start + normal*( extruder_.TopCenter() -extruder_.TopLenth() / 2 )+ p*extruder_.TopRadii();
760 
761  GeoV3 start_top_back_up = start + normal*(extruder_.TopLenth() / 2 + extruder_.TopCenter()) - p*extruder_.TopRadii();
762  GeoV3 start_top_back_down = start + normal*(extruder_.TopCenter() - extruder_.TopLenth() / 2) - p*extruder_.TopRadii();
763 
764  GeoV3 end_top_front_up = end + normal*(extruder_.TopLenth() / 2 + extruder_.TopCenter()) + p*extruder_.TopRadii();
765  GeoV3 end_top_front_down = end + normal*(extruder_.TopCenter() - extruder_.TopLenth() / 2) + p*extruder_.TopRadii();
766 
767  GeoV3 end_top_back_up = end + normal*(extruder_.TopLenth() / 2 + extruder_.TopCenter()) - p*extruder_.TopRadii();
768  GeoV3 end_top_back_down = end + normal*(extruder_.TopCenter() - extruder_.TopLenth() / 2) - p*extruder_.TopRadii();
769 
770  bulk_.push_back(Triangle(start_top_front_up, start_top_front_down, end_top_front_down));
771  bulk_.push_back(Triangle(start_top_front_up, end_top_front_up, end_top_front_down));
772  bulk_.push_back(Triangle(start_top_back_up, start_top_back_down, end_top_back_down));
773  bulk_.push_back(Triangle(start_top_back_up, end_top_back_up, end_top_back_down));
774 #endif
775 
776  //front
777  bulk_.push_back(Triangle(start, end, start_front_cone));
778  bulk_.push_back(Triangle(end, end_front_cone, start_front_cone));
779  bulk_.push_back(Triangle(start_front_cone, end_front_cone, start_front_cylinder));
780  bulk_.push_back(Triangle(end_front_cone, end_front_cylinder, start_front_cylinder));
781 
782  //back
783  bulk_.push_back(Triangle(start, end_back_cone, end));
784  bulk_.push_back(Triangle(start, start_back_cone, end_back_cone));
785  bulk_.push_back(Triangle(start_back_cone, end_back_cylinder, end_back_cone));
786  bulk_.push_back(Triangle(start_back_cone, start_back_cylinder, end_back_cylinder));
787 }
788 
789 void QuadricCollision::GenerateVolume(GeoV3 connect, GeoV3 target_s, GeoV3 order_s, GeoV3 normal)
790 {
791  GeoV3 t = target_s - connect;
792  double edge_length = t.norm();
793  t.normalize();
794 
795  GeoV3 p = cross(t, normal);
796  p.normalize();
797 
798  double eps = 1;
799 
800  GeoV3 start_cone_center = normal*extruder_.Height() + connect;
801 
802  //face front
803  GeoV3 start_front_cone = start_cone_center + p*extruder_.Radii() + t*eps;
804  GeoV3 start_front_cylinder = start_front_cone + normal*extruder_.CyclinderLenth() + t*eps;
805 
806  //face back
807  GeoV3 start_back_cone = start_cone_center - p*extruder_.Radii() + t*eps;
808  GeoV3 start_back_cylinder = start_back_cone + normal*extruder_.CyclinderLenth() + t*eps;
809  GeoV3 start = connect + t*eps;
810 
811  //front
812  bulk_.clear();
813  bulk_.push_back(Triangle(start, start_back_cone, start_front_cone));
814  bulk_.push_back(Triangle(start_front_cylinder, start_back_cone, start_front_cone));
815  bulk_.push_back(Triangle(start_front_cylinder, start_back_cylinder, start_back_cone));
816 
817 #ifdef STRICT_COLLISION
818  //Circle
819  start = connect;
820  GeoV3 end = target_s;
821 
822  GeoV3 q = cross(normal, p);
823  q.normalize();
824  vector<GeoV3> start_circle_point, end_circle_point;
825  for (int i = 0; i < 16; i++)
826  {
827  double part = 2 * F_PI / 16;
828  double theta = i*part;
829  start_circle_point.push_back(start_cone_center + p*cos(theta)*extruder_.Radii() + q*sin(theta)*extruder_.Radii());
830  end_circle_point.push_back(start_circle_point[i] + end - start);
831  }
832 
833  for (int i = 0; i < 15; i++)
834  {
835  bulk_.push_back(Triangle(start_circle_point[i], start_circle_point[i + 1], end_circle_point[i]));
836  bulk_.push_back(Triangle(end_circle_point[i], end_circle_point[i + 1], start_circle_point[i + 1]));
837  }
838  bulk_.push_back(Triangle(start_circle_point[15], start_circle_point[0], end_circle_point[15]));
839  bulk_.push_back(Triangle(end_circle_point[15], end_circle_point[0], start_circle_point[0]));
840 
841  //Top face
842  GeoV3 start_top_front_up = start + normal*(extruder_.TopLenth() / 2 + extruder_.TopCenter()) + p*extruder_.TopRadii();
843  GeoV3 start_top_front_down = start + normal*(extruder_.TopCenter() - extruder_.TopLenth() / 2) + p*extruder_.TopRadii();
844 
845  GeoV3 start_top_back_up = start + normal*(extruder_.TopLenth() / 2 + extruder_.TopCenter()) - p*extruder_.TopRadii();
846  GeoV3 start_top_back_down = start + normal*(extruder_.TopCenter() - extruder_.TopLenth() / 2) - p*extruder_.TopRadii();
847 
848  GeoV3 end_top_front_up = end + normal*(extruder_.TopLenth() / 2 + extruder_.TopCenter()) + p*extruder_.TopRadii();
849  GeoV3 end_top_front_down = end + normal*(extruder_.TopCenter() - extruder_.TopLenth() / 2) + p*extruder_.TopRadii();
850 
851  GeoV3 end_top_back_up = end + normal*(extruder_.TopLenth() / 2 + extruder_.TopCenter()) - p*extruder_.TopRadii();
852  GeoV3 end_top_back_down = end + normal*(extruder_.TopCenter() - extruder_.TopLenth() / 2) - p*extruder_.TopRadii();
853 
854  bulk_.push_back(Triangle(start_top_front_up, start_top_front_down, end_top_front_down));
855  bulk_.push_back(Triangle(start_top_front_up, end_top_front_up, end_top_front_down));
856  bulk_.push_back(Triangle(start_top_back_up, start_top_back_down, end_top_back_down));
857  bulk_.push_back(Triangle(start_top_back_up, end_top_back_up, end_top_back_down));
858 #endif
859 }
860 
862 {
863  if (abs(angle(a, b)) < GEO_EPS || abs(angle(a, b) - F_PI) < GEO_EPS)
864  return true;
865  return false;
866 }
867 
869 {
870  gte::Segment<3, float> segment, segment_target;
871  segment = Seg(order_e->pvert_->Position(), order_e->ppair_->pvert_->Position());
872  segment_target = Seg(target_e_->pvert_->Position(), target_e_->ppair_->pvert_->Position());
874  auto dcpq_result = dcpq(segment, segment_target);
875  return dcpq_result.distance;
876 }
877 
879 {
880  gte::Segment<3, float> segment;
881  segment.p[0][0] = target_start.x();
882  segment.p[0][1] = target_start.y();
883  segment.p[0][2] = target_start.z();
884  segment.p[1][0] = target_end.x();
885  segment.p[1][1] = target_end.y();
886  segment.p[1][2] = target_end.z();
887  return segment;
888 }
889 
891 {
892  gte::Segment<3, float> segment;
893  segment.p[0][0] = target_start.getX();
894  segment.p[0][1] = target_start.getY();
895  segment.p[0][2] = target_start.getZ();
896  segment.p[1][0] = target_end.getX();
897  segment.p[1][1] = target_end.getY();
898  segment.p[1][2] = target_end.getZ();
899  return segment;
900 }
901 
903 {
904  gte::Triangle<3, float> triangle;
905  triangle.v[0][0] = a.getX();
906  triangle.v[0][1] = a.getY();
907  triangle.v[0][2] = a.getZ();
908  triangle.v[1][0] = b.getX();
909  triangle.v[1][1] = b.getY();
910  triangle.v[1][2] = b.getZ();
911  triangle.v[2][0] = c.getX();
912  triangle.v[2][1] = c.getY();
913  triangle.v[2][2] = c.getZ();
914  return triangle;
915 }
916 
917 
static const double MAX_COLLISION_CHECK_DIST
#define GEO_EPS
Definition: GCommon.h:62
bool Case(GeoV3 target_start, GeoV3 target_end, GeoV3 order_start, GeoV3 order_end, GeoV3 normal)
int ColFreeAngle(const std::vector< lld > &colli_map)
bool DetectBulk(WF_edge *order_e, double theta, double phi)
Vector< N, Real > direction
std::vector< int > ConvertCollisionMapToIntMap(const std::vector< lld > &colli_map)
bool DetectEdges(std::vector< WF_edge * > exist_edge, double theta, double phi)
bool SpecialCase(GeoV3 connect, GeoV3 target_s, GeoV3 order_s, GeoV3 normal)
void ModifyAngle(std::vector< lld > &angle_state, const std::vector< lld > &colli_map)
bool DetectAngle(GeoV3 connect, GeoV3 end, GeoV3 target_end, GeoV3 normal)
WireFrame * ptr_frame_
bool DetectEdge(WF_edge *order_e, vector< lld > &colli_map)
Eigen::Vector3d ConvertAngleToEigenDirection(double theta, double phi)
double getY()
Definition: Geometry.h:91
bool DetectTriangle(Triangle triangle, GeoV3 target_start, GeoV3 target_end)
TFSIMD_FORCE_INLINE Vector3 cross(const Vector3 &v) const
GLuint start
static double angle(Vector3d vec1, Vector3d vec2)
Definition: Geometry.h:158
WF_edge * GetEdge(int i)
Definition: WireFrame.h:238
std::array< Vector< N, Real >, 2 > p
GeoV3 Orientation(double theta, double phi)
reference x()
Definition: Vec.h:194
bool ParallelCase(GeoV3 target_start, GeoV3 target_end, GeoV3 order_start, GeoV3 order_end, GeoV3 normal)
bool DetectCylinder(GeoV3 start, GeoV3 normal, GeoV3 target_start, GeoV3 target_end)
point CenterPos() const
Definition: WireFrame.h:135
std::vector< Eigen::Vector3d > ConvertCollisionMapToEigenDirections(const std::vector< lld > &colli_map)
std::vector< Triangle > bulk_
GLint GLuint mask
Vector< N, Real > direction
point v1()
Definition: Polyface.h:74
GLboolean GLboolean GLboolean GLboolean a
Ray< N, Real > ray
int e_orig_id(int u)
Definition: DualGraph.h:152
int ID() const
Definition: WireFrame.h:123
const GLubyte * c
bool Parallel(GeoV3 a, GeoV3 b)
double Radii()
Definition: ExtruderCone.h:71
WF_edge * ppair_
Definition: WireFrame.h:166
bool DetectCollision(WF_edge *target_e, DualGraph *ptr_subgraph, std::vector< lld > &result_map)
gte::Segment< 3, float > Seg(point target_start, point target_end)
GLuint GLuint end
unsigned long long lld
bool DetectTopCylinder(GeoV3 start, GeoV3 normal, GeoV3 target_start, GeoV3 target_end)
#define F_PI
Definition: GCommon.h:54
reference y()
Definition: Vec.h:203
GLdouble GLdouble t
std::vector< std::vector< lld > * > colli_map_
GLboolean GLboolean GLboolean b
static trimesh::Vec< D, T > abs(const trimesh::Vec< D, T > &v)
Definition: Vec.h:1193
bool DetectCone(GeoV3 start, GeoV3 normal, GeoV3 target_start, GeoV3 target_end)
point v2()
Definition: Polyface.h:79
double getX()
Definition: Geometry.h:90
bool isExistingEdge(WF_edge *e)
Definition: DualGraph.h:165
const GLdouble * v
WF_vert * pvert_
Definition: WireFrame.h:164
double getZ()
Definition: Geometry.h:92
GLdouble s
gte::Triangle< 3, float > Tri(GeoV3 a, GeoV3 b, GeoV3 c)
double TopCenter()
Definition: ExtruderCone.h:78
double TopRadii()
Definition: ExtruderCone.h:80
int SizeOfVertList()
Definition: DualGraph.h:145
double TopLenth()
Definition: ExtruderCone.h:79
GLdouble GLdouble GLdouble GLdouble q
Vector< N, Real > origin
Vector< N, Real > origin
double ToolLenth()
Definition: ExtruderCone.h:70
void Init(vector< lld > &colli_map)
double Distance(WF_edge *order_e)
double Angle()
Definition: ExtruderCone.h:68
reference z()
Definition: Vec.h:212
point v0()
Definition: Polyface.h:69
void GenerateVolume(GeoV3 start, GeoV3 end, GeoV3 target_start, GeoV3 target_end, GeoV3 normal)
ExtruderCone extruder_
GLfloat GLfloat p
double Height()
Definition: ExtruderCone.h:67
std::array< Vector< N, Real >, 3 > v
GLuint64EXT * result
Line3< Real > axis
double CyclinderLenth()
Definition: ExtruderCone.h:72
int SizeOfEdgeList() const
Definition: WireFrame.h:228
point Position() const
Definition: WireFrame.h:78


choreo_task_sequence_planner
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:03:14