BVH_model.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2011-2014, Willow Garage, Inc.
5  * Copyright (c) 2014-2015, Open Source Robotics Foundation
6  * Copyright (c) 2020, INRIA
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Open Source Robotics Foundation nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  */
36 
39 #include "coal/BV/BV_node.h"
40 #include "coal/BVH/BVH_model.h"
41 
42 #include "coal/BV/BV.h"
43 #include "coal/shape/convex.h"
44 
47 
48 #include <iostream>
49 #include <string.h>
50 
51 namespace coal {
52 
54  : num_tris(0),
55  num_vertices(0),
56  build_state(BVH_BUILD_STATE_EMPTY),
57  num_tris_allocated(0),
58  num_vertices_allocated(0),
59  num_vertex_updated(0) {}
60 
62  : CollisionGeometry(other),
63  num_tris(other.num_tris),
64  num_vertices(other.num_vertices),
65  build_state(other.build_state),
66  num_tris_allocated(other.num_tris),
67  num_vertices_allocated(other.num_vertices) {
68  if (other.vertices.get() && other.vertices->size() > 0) {
69  vertices.reset(new std::vector<Vec3s>(*(other.vertices)));
70  } else
71  vertices.reset();
72 
73  if (other.tri_indices.get() && other.tri_indices->size() > 0) {
74  tri_indices.reset(new std::vector<Triangle>(*(other.tri_indices)));
75  } else
76  tri_indices.reset();
77 
78  if (other.prev_vertices.get() && other.prev_vertices->size() > 0) {
79  prev_vertices.reset(new std::vector<Vec3s>(*(other.prev_vertices)));
80  } else
81  prev_vertices.reset();
82 }
83 
84 bool BVHModelBase::isEqual(const CollisionGeometry& _other) const {
85  const BVHModelBase* other_ptr = dynamic_cast<const BVHModelBase*>(&_other);
86  if (other_ptr == nullptr) return false;
87  const BVHModelBase& other = *other_ptr;
88 
89  bool result =
90  num_tris == other.num_tris && num_vertices == other.num_vertices;
91 
92  if (!result) return false;
93 
94  if ((!(tri_indices.get()) && other.tri_indices.get()) ||
95  (tri_indices.get() && !(other.tri_indices.get())))
96  return false;
97  if (tri_indices.get() && other.tri_indices.get()) {
98  const std::vector<Triangle>& tri_indices_ = *(tri_indices);
99  const std::vector<Triangle>& other_tri_indices_ = *(other.tri_indices);
100  for (size_t k = 0; k < static_cast<size_t>(num_tris); ++k)
101  if (tri_indices_[k] != other_tri_indices_[k]) return false;
102  }
103 
104  if ((!(vertices.get()) && other.vertices.get()) ||
105  (vertices.get() && !(other.vertices.get())))
106  return false;
107  if (vertices.get() && other.vertices.get()) {
108  const std::vector<Vec3s>& vertices_ = *(vertices);
109  const std::vector<Vec3s>& other_vertices_ = *(other.vertices);
110  for (size_t k = 0; k < static_cast<size_t>(num_vertices); ++k)
111  if (vertices_[k] != other_vertices_[k]) return false;
112  }
113 
114  if ((!(prev_vertices.get()) && other.prev_vertices.get()) ||
115  (prev_vertices.get() && !(other.prev_vertices.get())))
116  return false;
117  if (prev_vertices.get() && other.prev_vertices.get()) {
118  const std::vector<Vec3s>& prev_vertices_ = *(prev_vertices);
119  const std::vector<Vec3s>& other_prev_vertices_ = *(other.prev_vertices);
120  for (size_t k = 0; k < static_cast<size_t>(num_vertices); ++k) {
121  if (prev_vertices_[k] != other_prev_vertices_[k]) return false;
122  }
123  }
124 
125  return true;
126 }
127 
129  if (!(vertices.get())) {
130  std::cerr << "BVH Error in `buildConvexRepresentation`! The BVHModel has "
131  "no vertices."
132  << std::endl;
133  return;
134  }
135  if (!(tri_indices.get())) {
136  std::cerr << "BVH Error in `buildConvexRepresentation`! The BVHModel has "
137  "no triangles."
138  << std::endl;
139  return;
140  }
141 
142  if (!convex) {
143  std::shared_ptr<std::vector<Vec3s>> points = vertices;
144  std::shared_ptr<std::vector<Triangle>> polygons = tri_indices;
145  if (!share_memory) {
146  points.reset(new std::vector<Vec3s>(*(vertices)));
147  polygons.reset(new std::vector<Triangle>(*(tri_indices)));
148  }
149  convex.reset(
150  new Convex<Triangle>(points, num_vertices, polygons, num_tris));
151  }
152 }
153 
154 bool BVHModelBase::buildConvexHull(bool keepTriangle,
155  const char* qhullCommand) {
156  convex.reset(ConvexBase::convexHull(vertices, num_vertices, keepTriangle,
157  qhullCommand));
158  return num_vertices == convex->num_points;
159 }
160 
161 template <typename BV>
163  : BVHModelBase(other),
164  bv_splitter(other.bv_splitter),
165  bv_fitter(other.bv_fitter) {
166  if (other.primitive_indices.get()) {
167  primitive_indices.reset(
168  new std::vector<unsigned int>(*(other.primitive_indices)));
169  } else
170  primitive_indices.reset();
171 
173  if (other.bvs.get()) {
174  bvs.reset(new bv_node_vector_t(*(other.bvs)));
175  } else
176  bvs.reset();
177 }
178 
179 int BVHModelBase::beginModel(unsigned int num_tris_,
180  unsigned int num_vertices_) {
182  vertices.reset();
183  tri_indices.reset();
184  tri_indices.reset();
185  prev_vertices.reset();
186 
188  deleteBVs();
189  }
190 
191  if (num_tris_ <= 0) num_tris_ = 8;
192  if (num_vertices_ <= 0) num_vertices_ = 8;
193 
194  num_vertices_allocated = num_vertices_;
195  num_tris_allocated = num_tris_;
196 
197  if (num_tris_allocated > 0) {
198  tri_indices.reset(new std::vector<Triangle>(num_tris_allocated));
199  if (!(tri_indices.get())) {
200  std::cerr << "BVH Error! Out of memory for tri_indices array on "
201  "BeginModel() call!"
202  << std::endl;
204  }
205  } else
206  tri_indices.reset();
207 
208  if (num_vertices_allocated > 0) {
209  vertices.reset(new std::vector<Vec3s>(num_vertices_allocated));
210  if (!(vertices.get())) {
211  std::cerr
212  << "BVH Error! Out of memory for vertices array on BeginModel() call!"
213  << std::endl;
215  }
216  } else {
217  vertices.reset();
218  prev_vertices.reset();
219  };
220 
222  std::cerr
223  << "BVH Warning! Calling beginModel() on a BVHModel that is not empty. "
224  "This model was cleared and previous triangles/vertices were lost."
225  << std::endl;
228  }
229 
231 
232  return BVH_OK;
233 }
234 
237  std::cerr << "BVH Warning! Call addVertex() in a wrong order. addVertex() "
238  "was ignored. Must do a beginModel() to clear the model for "
239  "addition of new vertices."
240  << std::endl;
242  }
243 
245  std::shared_ptr<std::vector<Vec3s>> temp(
246  new std::vector<Vec3s>(num_vertices_allocated * 2));
247  if (!(temp.get())) {
248  std::cerr
249  << "BVH Error! Out of memory for vertices array on addVertex() call!"
250  << std::endl;
252  }
253 
254  for (size_t i = 0; i < num_vertices; ++i) {
255  (*temp)[i] = (*vertices)[i];
256  }
257  vertices = temp;
259  }
260 
261  (*vertices)[num_vertices] = p;
262  num_vertices += 1;
263 
264  return BVH_OK;
265 }
266 
267 int BVHModelBase::addTriangles(const Matrixx3i& triangles) {
269  std::cerr << "BVH Warning! Call addSubModel() in a wrong order. "
270  "addSubModel() was ignored. Must do a beginModel() to clear "
271  "the model for addition of new vertices."
272  << std::endl;
274  }
275 
276  const unsigned int num_tris_to_add = (unsigned int)triangles.rows();
277 
278  if (num_tris + num_tris_to_add > num_tris_allocated) {
279  std::shared_ptr<std::vector<Triangle>> temp(
280  new std::vector<Triangle>(num_tris_allocated * 2 + num_tris_to_add));
281  if (!(temp.get())) {
282  std::cerr << "BVH Error! Out of memory for tri_indices array on "
283  "addSubModel() call!"
284  << std::endl;
286  }
287 
288  for (size_t i = 0; i < num_tris; ++i) {
289  (*temp)[i] = (*tri_indices)[i];
290  }
291  tri_indices = temp;
292  num_tris_allocated = num_tris_allocated * 2 + num_tris_to_add;
293  }
294 
295  std::vector<Triangle>& tri_indices_ = *tri_indices;
296  for (Eigen::DenseIndex i = 0; i < triangles.rows(); ++i) {
297  const Matrixx3i::ConstRowXpr triangle = triangles.row(i);
298  tri_indices_[num_tris++].set(
299  static_cast<Triangle::index_type>(triangle[0]),
300  static_cast<Triangle::index_type>(triangle[1]),
301  static_cast<Triangle::index_type>(triangle[2]));
302  }
303 
304  return BVH_OK;
305 }
306 
309  std::cerr << "BVH Warning! Call addVertex() in a wrong order. "
310  "addVertices() was ignored. Must do a beginModel() to clear "
311  "the model for addition of new vertices."
312  << std::endl;
314  }
315 
316  if (num_vertices + points.rows() > num_vertices_allocated) {
317  num_vertices_allocated = num_vertices + (unsigned int)points.rows();
318  std::shared_ptr<std::vector<Vec3s>> temp(
319  new std::vector<Vec3s>(num_vertices_allocated));
320  if (!(temp.get())) {
321  std::cerr
322  << "BVH Error! Out of memory for vertices array on addVertex() call!"
323  << std::endl;
325  }
326 
327  for (size_t i = 0; i < num_vertices; ++i) {
328  (*temp)[i] = (*vertices)[i];
329  }
330  vertices = temp;
331  }
332 
333  std::vector<Vec3s>& vertices_ = *vertices;
334  for (Eigen::DenseIndex id = 0; id < points.rows(); ++id)
335  vertices_[num_vertices++] = points.row(id).transpose();
336 
337  return BVH_OK;
338 }
339 
340 int BVHModelBase::addTriangle(const Vec3s& p1, const Vec3s& p2,
341  const Vec3s& p3) {
343  std::cerr << "BVH Warning! Call addTriangle() in a wrong order. "
344  "addTriangle() was ignored. Must do a beginModel() to clear "
345  "the model for addition of new triangles."
346  << std::endl;
348  }
349 
351  std::shared_ptr<std::vector<Vec3s>> temp(
352  new std::vector<Vec3s>(num_vertices_allocated * 2 + 2));
353  if (!(temp.get())) {
354  std::cerr << "BVH Error! Out of memory for vertices array on "
355  "addTriangle() call!"
356  << std::endl;
358  }
359 
360  for (size_t i = 0; i < num_vertices; ++i) {
361  (*temp)[i] = (*vertices)[i];
362  }
363  vertices = temp;
365  }
366 
367  const unsigned int offset = num_vertices;
368 
369  (*vertices)[num_vertices] = p1;
370  num_vertices++;
371  (*vertices)[num_vertices] = p2;
372  num_vertices++;
373  (*vertices)[num_vertices] = p3;
374  num_vertices++;
375 
376  if (num_tris >= num_tris_allocated) {
377  std::shared_ptr<std::vector<Triangle>> temp(
378  new std::vector<Triangle>(num_tris_allocated * 2));
379  if (!(temp.get())) {
380  std::cerr << "BVH Error! Out of memory for tri_indices array on "
381  "addTriangle() call!"
382  << std::endl;
384  }
385 
386  for (size_t i = 0; i < num_tris; ++i) {
387  (*temp)[i] = (*tri_indices)[i];
388  }
389  tri_indices = temp;
390  num_tris_allocated *= 2;
391  }
392 
393  (*tri_indices)[num_tris].set((Triangle::index_type)offset,
394  (Triangle::index_type)(offset + 1),
395  (Triangle::index_type)(offset + 2));
396  num_tris++;
397 
398  return BVH_OK;
399 }
400 
401 int BVHModelBase::addSubModel(const std::vector<Vec3s>& ps) {
403  std::cerr << "BVH Warning! Calling addSubModel() in a wrong order. "
404  "addSubModel() was ignored. Must do a beginModel() to clear "
405  "the model for addition of new vertices."
406  << std::endl;
408  }
409 
410  const unsigned int num_vertices_to_add = (unsigned int)ps.size();
411 
412  if (num_vertices + num_vertices_to_add - 1 >= num_vertices_allocated) {
413  std::shared_ptr<std::vector<Vec3s>> temp(new std::vector<Vec3s>(
414  num_vertices_allocated * 2 + num_vertices_to_add - 1));
415  if (!(temp.get())) {
416  std::cerr << "BVH Error! Out of memory for vertices array on "
417  "addSubModel() call!"
418  << std::endl;
420  }
421 
422  for (size_t i = 0; i < num_vertices; ++i) {
423  (*temp)[i] = (*vertices)[i];
424  }
425  vertices = temp;
427  num_vertices_allocated * 2 + num_vertices_to_add - 1;
428  }
429 
430  std::vector<Vec3s>& vertices_ = *vertices;
431  for (size_t i = 0; i < (size_t)num_vertices_to_add; ++i) {
432  vertices_[num_vertices] = ps[i];
433  num_vertices++;
434  }
435 
436  return BVH_OK;
437 }
438 
439 int BVHModelBase::addSubModel(const std::vector<Vec3s>& ps,
440  const std::vector<Triangle>& ts) {
442  std::cerr << "BVH Warning! Calling addSubModel() in a wrong order. "
443  "addSubModel() was ignored. Must do a beginModel() to clear "
444  "the model for addition of new vertices."
445  << std::endl;
447  }
448 
449  const unsigned int num_vertices_to_add = (unsigned int)ps.size();
450 
451  if (num_vertices + num_vertices_to_add - 1 >= num_vertices_allocated) {
452  std::shared_ptr<std::vector<Vec3s>> temp(new std::vector<Vec3s>(
453  num_vertices_allocated * 2 + num_vertices_to_add - 1));
454  if (!(temp.get())) {
455  std::cerr << "BVH Error! Out of memory for vertices array on "
456  "addSubModel() call!"
457  << std::endl;
459  }
460 
461  for (size_t i = 0; i < num_vertices; ++i) {
462  (*temp)[i] = (*vertices)[i];
463  }
464  vertices = temp;
466  num_vertices_allocated * 2 + num_vertices_to_add - 1;
467  }
468 
469  const unsigned int offset = num_vertices;
470 
471  std::vector<Vec3s>& vertices_ = *vertices;
472  for (size_t i = 0; i < (size_t)num_vertices_to_add; ++i) {
473  vertices_[num_vertices] = ps[i];
474  num_vertices++;
475  }
476 
477  const unsigned int num_tris_to_add = (unsigned int)ts.size();
478 
479  if (num_tris + num_tris_to_add - 1 >= num_tris_allocated) {
480  std::shared_ptr<std::vector<Triangle>> temp(new std::vector<Triangle>(
481  num_tris_allocated * 2 + num_tris_to_add - 1));
482  if (!(temp.get())) {
483  std::cerr << "BVH Error! Out of memory for tri_indices array on "
484  "addSubModel() call!"
485  << std::endl;
487  }
488 
489  for (size_t i = 0; i < num_tris; ++i) {
490  (*temp)[i] = (*tri_indices)[i];
491  }
492  tri_indices = temp;
493  num_tris_allocated = num_tris_allocated * 2 + num_tris_to_add - 1;
494  }
495 
496  std::vector<Triangle>& tri_indices_ = *tri_indices;
497  for (size_t i = 0; i < (size_t)num_tris_to_add; ++i) {
498  const Triangle& t = ts[i];
499  tri_indices_[num_tris].set(t[0] + (size_t)offset, t[1] + (size_t)offset,
500  t[2] + (size_t)offset);
501  num_tris++;
502  }
503 
504  return BVH_OK;
505 }
506 
509  std::cerr << "BVH Warning! Call endModel() in wrong order. endModel() was "
510  "ignored."
511  << std::endl;
513  }
514 
515  if (num_tris == 0 && num_vertices == 0) {
516  std::cerr << "BVH Error! endModel() called on model with no triangles and "
517  "vertices."
518  << std::endl;
520  }
521 
523  if (num_tris > 0) {
524  std::shared_ptr<std::vector<Triangle>> new_tris(
525  new std::vector<Triangle>(num_tris));
526  if (!(new_tris.get())) {
527  std::cerr << "BVH Error! Out of memory for tri_indices array in "
528  "endModel() call!"
529  << std::endl;
531  }
532 
533  for (size_t i = 0; i < num_tris; ++i) {
534  (*new_tris)[i] = (*tri_indices)[i];
535  }
536  tri_indices = new_tris;
538  } else {
539  tri_indices.reset();
541  }
542  }
543 
545  if (num_vertices > 0) {
546  std::shared_ptr<std::vector<Vec3s>> new_vertices(
547  new std::vector<Vec3s>(num_vertices));
548  if (!(new_vertices.get())) {
549  std::cerr
550  << "BVH Error! Out of memory for vertices array in endModel() call!"
551  << std::endl;
553  }
554 
555  for (size_t i = 0; i < num_vertices; ++i) {
556  (*new_vertices)[i] = (*vertices)[i];
557  }
558  vertices = new_vertices;
560  } else {
561  vertices.reset();
563  }
564  }
565 
566  // construct BVH tree
568 
569  buildTree();
570 
571  // finish constructing
573 
574  return BVH_OK;
575 }
576 
579  std::cerr << "BVH Error! Call beginReplaceModel() on a BVHModel that has "
580  "no previous frame."
581  << std::endl;
583  }
584 
585  if (prev_vertices.get()) prev_vertices.reset();
586 
587  num_vertex_updated = 0;
588 
590 
591  return BVH_OK;
592 }
593 
596  std::cerr << "BVH Warning! Call replaceVertex() in a wrong order. "
597  "replaceVertex() was ignored. Must do a beginReplaceModel() "
598  "for initialization."
599  << std::endl;
601  }
602 
603  (*vertices)[num_vertex_updated] = p;
605 
606  return BVH_OK;
607 }
608 
610  const Vec3s& p3) {
612  std::cerr << "BVH Warning! Call replaceTriangle() in a wrong order. "
613  "replaceTriangle() was ignored. Must do a beginReplaceModel() "
614  "for initialization."
615  << std::endl;
617  }
618 
619  (*vertices)[num_vertex_updated] = p1;
621  (*vertices)[num_vertex_updated] = p2;
623  (*vertices)[num_vertex_updated] = p3;
625  return BVH_OK;
626 }
627 
628 int BVHModelBase::replaceSubModel(const std::vector<Vec3s>& ps) {
630  std::cerr << "BVH Warning! Call replaceSubModel() in a wrong order. "
631  "replaceSubModel() was ignored. Must do a beginReplaceModel() "
632  "for initialization."
633  << std::endl;
635  }
636 
637  std::vector<Vec3s>& vertices_ = *vertices;
638  for (unsigned int i = 0; i < ps.size(); ++i) {
639  vertices_[num_vertex_updated] = ps[i];
641  }
642  return BVH_OK;
643 }
644 
645 int BVHModelBase::endReplaceModel(bool refit, bool bottomup) {
647  std::cerr << "BVH Warning! Call endReplaceModel() in a wrong order. "
648  "endReplaceModel() was ignored. "
649  << std::endl;
651  }
652 
654  std::cerr << "BVH Error! The replaced model should have the same number of "
655  "vertices as the old model."
656  << std::endl;
657  return BVH_ERR_INCORRECT_DATA;
658  }
659 
660  if (refit) // refit, do not change BVH structure
661  {
662  refitTree(bottomup);
663  } else // reconstruct bvh tree based on current frame data
664  {
665  buildTree();
666  }
667 
669 
670  return BVH_OK;
671 }
672 
676  std::cerr << "BVH Error! Call beginUpdatemodel() on a BVHModel that has no "
677  "previous frame."
678  << std::endl;
680  }
681 
682  if (prev_vertices.get()) {
683  std::shared_ptr<std::vector<Vec3s>> temp = prev_vertices;
685  vertices = temp;
686  } else {
688  vertices.reset(new std::vector<Vec3s>(num_vertices));
689  }
690 
691  num_vertex_updated = 0;
692 
694 
695  return BVH_OK;
696 }
697 
700  std::cerr
701  << "BVH Warning! Call updateVertex() in a wrong order. updateVertex() "
702  "was ignored. Must do a beginUpdateModel() for initialization."
703  << std::endl;
705  }
706 
707  (*vertices)[num_vertex_updated] = p;
709 
710  return BVH_OK;
711 }
712 
714  const Vec3s& p3) {
716  std::cerr << "BVH Warning! Call updateTriangle() in a wrong order. "
717  "updateTriangle() was ignored. Must do a beginUpdateModel() "
718  "for initialization."
719  << std::endl;
721  }
722 
723  (*vertices)[num_vertex_updated] = p1;
725  (*vertices)[num_vertex_updated] = p2;
727  (*vertices)[num_vertex_updated] = p3;
729  return BVH_OK;
730 }
731 
732 int BVHModelBase::updateSubModel(const std::vector<Vec3s>& ps) {
734  std::cerr << "BVH Warning! Call updateSubModel() in a wrong order. "
735  "updateSubModel() was ignored. Must do a beginUpdateModel() "
736  "for initialization."
737  << std::endl;
739  }
740 
741  std::vector<Vec3s>& vertices_ = *vertices;
742  for (unsigned int i = 0; i < ps.size(); ++i) {
743  vertices_[num_vertex_updated] = ps[i];
745  }
746  return BVH_OK;
747 }
748 
749 int BVHModelBase::endUpdateModel(bool refit, bool bottomup) {
751  std::cerr << "BVH Warning! Call endUpdateModel() in a wrong order. "
752  "endUpdateModel() was ignored. "
753  << std::endl;
755  }
756 
758  std::cerr << "BVH Error! The updated model should have the same number of "
759  "vertices as the old model."
760  << std::endl;
761  return BVH_ERR_INCORRECT_DATA;
762  }
763 
764  if (refit) // refit, do not change BVH structure
765  {
766  refitTree(bottomup);
767  } else // reconstruct bvh tree based on current frame data
768  {
769  buildTree();
770 
771  // then refit
772 
773  refitTree(bottomup);
774  }
775 
777 
778  return BVH_OK;
779 }
780 
782  AABB aabb_;
783  const std::vector<Vec3s>& vertices_ = *vertices;
784  for (unsigned int i = 0; i < num_vertices; ++i) {
785  aabb_ += vertices_[i];
786  }
787 
788  aabb_center = aabb_.center();
789 
790  aabb_radius = 0;
791  for (unsigned int i = 0; i < num_vertices; ++i) {
792  CoalScalar r = (aabb_center - vertices_[i]).squaredNorm();
793  if (r > aabb_radius) aabb_radius = r;
794  }
795 
796  aabb_radius = sqrt(aabb_radius);
797 
798  aabb_local = aabb_;
799 }
800 
802 template <typename BV>
804  : BVHModelBase(),
805  bv_splitter(new BVSplitter<BV>(SPLIT_METHOD_MEAN)),
806  bv_fitter(new BVFitter<BV>()),
807  num_bvs_allocated(0),
808  num_bvs(0) {}
809 
810 template <typename BV>
812  bvs.reset();
813  primitive_indices.reset();
814  num_bvs_allocated = num_bvs = 0;
815 }
816 
817 template <typename BV>
819  // construct BVH tree
820  unsigned int num_bvs_to_be_allocated = 0;
821  if (num_tris == 0)
822  num_bvs_to_be_allocated = 2 * num_vertices - 1;
823  else
824  num_bvs_to_be_allocated = 2 * num_tris - 1;
825 
826  bvs.reset(new bv_node_vector_t(num_bvs_to_be_allocated));
827  primitive_indices.reset(
828  new std::vector<unsigned int>(num_bvs_to_be_allocated));
829  if (!(bvs.get()) || !(primitive_indices.get())) {
830  std::cerr << "BVH Error! Out of memory for BV array in endModel()!"
831  << std::endl;
832  return false;
833  }
834  num_bvs_allocated = num_bvs_to_be_allocated;
835  num_bvs = 0;
836  return true;
837 }
838 
839 template <typename BV>
840 int BVHModel<BV>::memUsage(const bool msg) const {
841  unsigned int mem_bv_list = (unsigned int)sizeof(BV) * num_bvs;
842  unsigned int mem_tri_list = (unsigned int)sizeof(Triangle) * num_tris;
843  unsigned int mem_vertex_list = (unsigned int)sizeof(Vec3s) * num_vertices;
844 
845  unsigned int total_mem = mem_bv_list + mem_tri_list + mem_vertex_list +
846  (unsigned int)sizeof(BVHModel<BV>);
847  if (msg) {
848  std::cerr << "Total for model " << total_mem << " bytes." << std::endl;
849  std::cerr << "BVs: " << num_bvs << " allocated." << std::endl;
850  std::cerr << "Tris: " << num_tris << " allocated." << std::endl;
851  std::cerr << "Vertices: " << num_vertices << " allocated." << std::endl;
852  }
853 
854  return static_cast<int>(total_mem);
855 }
856 
857 template <typename BV>
859  // set BVFitter
860  Vec3s* vertices_ = vertices.get() ? vertices->data() : NULL;
861  Triangle* tri_indices_ = tri_indices.get() ? tri_indices->data() : NULL;
862  bv_fitter->set(vertices_, tri_indices_, getModelType());
863  // set SplitRule
864  bv_splitter->set(vertices_, tri_indices_, getModelType());
865 
866  num_bvs = 1;
867 
868  unsigned int num_primitives = 0;
869  switch (getModelType()) {
870  case BVH_MODEL_TRIANGLES:
871  num_primitives = (unsigned int)num_tris;
872  break;
874  num_primitives = (unsigned int)num_vertices;
875  break;
876  default:
877  std::cerr << "BVH Error: Model type not supported!" << std::endl;
879  }
880 
881  std::vector<unsigned int>& primitive_indices_ = *primitive_indices;
882  for (unsigned int i = 0; i < num_primitives; ++i) primitive_indices_[i] = i;
883  recursiveBuildTree(0, 0, num_primitives);
884 
885  bv_fitter->clear();
886  bv_splitter->clear();
887 
888  return BVH_OK;
889 }
890 
891 template <typename BV>
892 int BVHModel<BV>::recursiveBuildTree(int bv_id, unsigned int first_primitive,
893  unsigned int num_primitives) {
894  BVHModelType type = getModelType();
895  BVNode<BV>* bvnode = bvs->data() + bv_id;
896  unsigned int* cur_primitive_indices =
897  primitive_indices->data() + first_primitive;
898 
899  // constructing BV
900  BV bv = bv_fitter->fit(cur_primitive_indices, num_primitives);
901  bv_splitter->computeRule(bv, cur_primitive_indices, num_primitives);
902 
903  bvnode->bv = bv;
904  bvnode->first_primitive = first_primitive;
905  bvnode->num_primitives = num_primitives;
906 
907  if (num_primitives == 1) {
908  bvnode->first_child = -((int)(*cur_primitive_indices) + 1);
909  } else {
910  bvnode->first_child = (int)num_bvs;
911  num_bvs += 2;
912 
913  unsigned int c1 = 0;
914  const std::vector<Vec3s>& vertices_ = *vertices;
915  const std::vector<Triangle>& tri_indices_ = *tri_indices;
916  for (unsigned int i = 0; i < num_primitives; ++i) {
917  Vec3s p;
918  if (type == BVH_MODEL_POINTCLOUD)
919  p = vertices_[cur_primitive_indices[i]];
920  else if (type == BVH_MODEL_TRIANGLES) {
921  const Triangle& t = tri_indices_[cur_primitive_indices[i]];
922  const Vec3s& p1 = vertices_[t[0]];
923  const Vec3s& p2 = vertices_[t[1]];
924  const Vec3s& p3 = vertices_[t[2]];
925 
926  p = (p1 + p2 + p3) / 3.;
927  } else {
928  std::cerr << "BVH Error: Model type not supported!" << std::endl;
930  }
931 
932  // loop invariant: up to (but not including) index c1 in group 1,
933  // then up to (but not including) index i in group 2
934  //
935  // [1] [1] [1] [1] [2] [2] [2] [x] [x] ... [x]
936  // c1 i
937  //
938  if (bv_splitter->apply(p)) // in the right side
939  {
940  // do nothing
941  } else {
942  unsigned int temp = cur_primitive_indices[i];
943  cur_primitive_indices[i] = cur_primitive_indices[c1];
944  cur_primitive_indices[c1] = temp;
945  c1++;
946  }
947  }
948 
949  if ((c1 == 0) || (c1 == num_primitives)) c1 = num_primitives / 2;
950 
951  const unsigned int num_first_half = c1;
952 
953  recursiveBuildTree(bvnode->leftChild(), first_primitive, num_first_half);
954  recursiveBuildTree(bvnode->rightChild(), first_primitive + num_first_half,
955  num_primitives - num_first_half);
956  }
957 
958  return BVH_OK;
959 }
960 
961 template <typename BV>
962 int BVHModel<BV>::refitTree(bool bottomup) {
963  if (bottomup)
964  return refitTree_bottomup();
965  else
966  return refitTree_topdown();
967 }
968 
969 template <typename BV>
971  // TODO the recomputation of the BV is done manually, without using
972  // bv_fitter. The manual BV recomputation seems bugged. Using bv_fitter
973  // seems to correct the bug.
974  // bv_fitter->set(vertices, tri_indices, getModelType());
975 
976  int res = recursiveRefitTree_bottomup(0);
977 
978  // bv_fitter->clear();
979  return res;
980 }
981 
982 template <typename BV>
984  BVNode<BV>* bvnode = bvs->data() + bv_id;
985  if (bvnode->isLeaf()) {
986  BVHModelType type = getModelType();
987  int primitive_id = -(bvnode->first_child + 1);
988  if (type == BVH_MODEL_POINTCLOUD) {
989  BV bv;
990 
991  if (prev_vertices.get()) {
992  Vec3s v[2];
993  v[0] = (*prev_vertices)[static_cast<size_t>(primitive_id)];
994  v[1] = (*vertices)[static_cast<size_t>(primitive_id)];
995  fit(v, 2, bv);
996  } else
997  fit(vertices->data() + primitive_id, 1, bv);
998 
999  bvnode->bv = bv;
1000  } else if (type == BVH_MODEL_TRIANGLES) {
1001  BV bv;
1002  const Triangle& triangle =
1003  (*tri_indices)[static_cast<size_t>(primitive_id)];
1004 
1005  if (prev_vertices.get()) {
1006  Vec3s v[6];
1007  for (Triangle::index_type i = 0; i < 3; ++i) {
1008  v[i] = (*prev_vertices)[triangle[i]];
1009  v[i + 3] = (*vertices)[triangle[i]];
1010  }
1011 
1012  fit(v, 6, bv);
1013  } else {
1014  // TODO use bv_fitter to build BV. See comment in refitTree_bottomup
1015  // unsigned int* cur_primitive_indices = primitive_indices +
1016  // bvnode->first_primitive; bv = bv_fitter->fit(cur_primitive_indices,
1017  // bvnode->num_primitives);
1018  Vec3s v[3];
1019  for (int i = 0; i < 3; ++i) {
1020  v[i] = (*vertices)[triangle[(Triangle::index_type)i]];
1021  }
1022 
1023  fit(v, 3, bv);
1024  }
1025 
1026  bvnode->bv = bv;
1027  } else {
1028  std::cerr << "BVH Error: Model type not supported!" << std::endl;
1030  }
1031  } else {
1032  recursiveRefitTree_bottomup(bvnode->leftChild());
1033  recursiveRefitTree_bottomup(bvnode->rightChild());
1034  bvnode->bv = (*bvs)[static_cast<size_t>(bvnode->leftChild())].bv +
1035  (*bvs)[static_cast<size_t>(bvnode->rightChild())].bv;
1036  // TODO use bv_fitter to build BV. See comment in refitTree_bottomup
1037  // unsigned int* cur_primitive_indices = primitive_indices +
1038  // bvnode->first_primitive; bvnode->bv =
1039  // bv_fitter->fit(cur_primitive_indices, bvnode->num_primitives);
1040  }
1041 
1042  return BVH_OK;
1043 }
1044 
1045 template <typename BV>
1047  Vec3s* vertices_ = vertices.get() ? vertices->data() : NULL;
1048  Vec3s* prev_vertices_ = prev_vertices.get() ? prev_vertices->data() : NULL;
1049  Triangle* tri_indices_ = tri_indices.get() ? tri_indices->data() : NULL;
1050  bv_fitter->set(vertices_, prev_vertices_, tri_indices_, getModelType());
1051  BVNode<BV>* bvs_ = bvs->data();
1052  unsigned int* primitive_indices_ = primitive_indices->data();
1053  for (unsigned int i = 0; i < num_bvs; ++i) {
1054  BV bv = bv_fitter->fit(primitive_indices_ + bvs_[i].first_primitive,
1055  bvs_[i].num_primitives);
1056  bvs_[i].bv = bv;
1057  }
1058 
1059  bv_fitter->clear();
1060 
1061  return BVH_OK;
1062 }
1063 
1064 template <>
1066  const Vec3s& parent_c) {
1067  bv_node_vector_t& bvs_ = *bvs;
1068  OBB& obb = bvs_[static_cast<size_t>(bv_id)].bv;
1069  if (!bvs_[static_cast<size_t>(bv_id)].isLeaf()) {
1070  makeParentRelativeRecurse(bvs_[static_cast<size_t>(bv_id)].first_child,
1071  obb.axes, obb.To);
1072 
1073  makeParentRelativeRecurse(bvs_[static_cast<size_t>(bv_id)].first_child + 1,
1074  obb.axes, obb.To);
1075  }
1076 
1077  // make self parent relative
1078  // obb.axes = parent_axes.transpose() * obb.axes;
1079  obb.axes.applyOnTheLeft(parent_axes.transpose());
1080 
1081  Vec3s t(obb.To - parent_c);
1082  obb.To.noalias() = parent_axes.transpose() * t;
1083 }
1084 
1085 template <>
1087  const Vec3s& parent_c) {
1088  bv_node_vector_t& bvs_ = *bvs;
1089  RSS& rss = bvs_[static_cast<size_t>(bv_id)].bv;
1090  if (!bvs_[static_cast<size_t>(bv_id)].isLeaf()) {
1091  makeParentRelativeRecurse(bvs_[static_cast<size_t>(bv_id)].first_child,
1092  rss.axes, rss.Tr);
1093 
1094  makeParentRelativeRecurse(bvs_[static_cast<size_t>(bv_id)].first_child + 1,
1095  rss.axes, rss.Tr);
1096  }
1097 
1098  // make self parent relative
1099  // rss.axes = parent_axes.transpose() * rss.axes;
1100  rss.axes.applyOnTheLeft(parent_axes.transpose());
1101 
1102  Vec3s t(rss.Tr - parent_c);
1103  rss.Tr.noalias() = parent_axes.transpose() * t;
1104 }
1105 
1106 template <>
1108  Matrix3s& parent_axes,
1109  const Vec3s& parent_c) {
1110  bv_node_vector_t& bvs_ = *bvs;
1111  OBB& obb = bvs_[static_cast<size_t>(bv_id)].bv.obb;
1112  RSS& rss = bvs_[static_cast<size_t>(bv_id)].bv.rss;
1113  if (!bvs_[static_cast<size_t>(bv_id)].isLeaf()) {
1114  makeParentRelativeRecurse(bvs_[static_cast<size_t>(bv_id)].first_child,
1115  obb.axes, obb.To);
1116 
1117  makeParentRelativeRecurse(bvs_[static_cast<size_t>(bv_id)].first_child + 1,
1118  obb.axes, obb.To);
1119  }
1120 
1121  // make self parent relative
1122  rss.axes.noalias() = parent_axes.transpose() * obb.axes;
1123  obb.axes = rss.axes;
1124 
1125  Vec3s t(obb.To - parent_c);
1126  obb.To.noalias() = parent_axes.transpose() * t;
1127  rss.Tr = obb.To;
1128 }
1129 
1130 template <>
1132  return BV_AABB;
1133 }
1134 
1135 template <>
1137  return BV_OBB;
1138 }
1139 
1140 template <>
1142  return BV_RSS;
1143 }
1144 
1145 template <>
1147  return BV_kIOS;
1148 }
1149 
1150 template <>
1152  return BV_OBBRSS;
1153 }
1154 
1155 template <>
1156 NODE_TYPE BVHModel<KDOP<16>>::getNodeType() const {
1157  return BV_KDOP16;
1158 }
1159 
1160 template <>
1161 NODE_TYPE BVHModel<KDOP<18>>::getNodeType() const {
1162  return BV_KDOP18;
1163 }
1164 
1165 template <>
1166 NODE_TYPE BVHModel<KDOP<24>>::getNodeType() const {
1167  return BV_KDOP24;
1168 }
1169 
1170 template class BVHModel<KDOP<16>>;
1171 template class BVHModel<KDOP<18>>;
1172 template class BVHModel<KDOP<24>>;
1173 template class BVHModel<OBB>;
1174 template class BVHModel<AABB>;
1175 template class BVHModel<RSS>;
1176 template class BVHModel<kIOS>;
1177 template class BVHModel<OBBRSS>;
1178 
1179 } // namespace coal
coal::BVHModelBase::replaceVertex
int replaceVertex(const Vec3s &p)
Replace one point in the old BVH model.
Definition: BVH_model.cpp:594
coal::BVH_BUILD_STATE_REPLACE_BEGUN
@ BVH_BUILD_STATE_REPLACE_BEGUN
Definition: coal/BVH/BVH_internal.h:58
coal::BVHModelBase::beginModel
int beginModel(unsigned int num_tris=0, unsigned int num_vertices=0)
Begin a new BVH model.
Definition: BVH_model.cpp:179
coal::BVHModelBase::replaceSubModel
int replaceSubModel(const std::vector< Vec3s > &ps)
Replace a set of points in the old BVH model.
Definition: BVH_model.cpp:628
coal::BVHModel::num_bvs_allocated
unsigned int num_bvs_allocated
Definition: coal/BVH/BVH_model.h:379
coal::BV_AABB
@ BV_AABB
Definition: coal/collision_object.h:66
coal::BVHModelBase::num_vertex_updated
unsigned int num_vertex_updated
Definition: coal/BVH/BVH_model.h:303
coal::BVHModelBase::replaceTriangle
int replaceTriangle(const Vec3s &p1, const Vec3s &p2, const Vec3s &p3)
Replace one triangle in the old BVH model.
Definition: BVH_model.cpp:609
coal::BVHModel::makeParentRelativeRecurse
void makeParentRelativeRecurse(int bv_id, Matrix3s &parent_axes, const Vec3s &parent_c)
Definition: coal/BVH/BVH_model.h:412
coal::Vec3s
Eigen::Matrix< CoalScalar, 3, 1 > Vec3s
Definition: coal/data_types.h:77
doxygen_xml_parser.type
type
Definition: doxygen_xml_parser.py:885
coal::BVHModelBase::buildConvexRepresentation
void buildConvexRepresentation(bool share_memory)
Build this Convex<Triangle> representation of this model. The result is stored in attribute convex.
Definition: BVH_model.cpp:128
coal::BVHModelType
BVHModelType
BVH model type.
Definition: coal/BVH/BVH_internal.h:79
coal::BV_KDOP24
@ BV_KDOP24
Definition: coal/collision_object.h:73
coal::BVHModelBase::vertices
std::shared_ptr< std::vector< Vec3s > > vertices
Geometry point data.
Definition: coal/BVH/BVH_model.h:68
coal::BVHModelBase::endModel
int endModel()
End BVH model construction, will build the bounding volume hierarchy.
Definition: BVH_model.cpp:507
coal::BVHModel::memUsage
int memUsage(const bool msg) const
Check the number of memory used.
Definition: BVH_model.cpp:840
BV_fitter.h
coal::BV_kIOS
@ BV_kIOS
Definition: coal/collision_object.h:69
coal::Triangle::set
void set(index_type p1, index_type p2, index_type p3)
Set the vertex indices of the triangle.
Definition: coal/data_types.h:123
coal::BVHModel::refitTree_bottomup
int refitTree_bottomup()
Refit the bounding volume hierarchy in a bottom-up way (fast but less compact)
Definition: BVH_model.cpp:970
coal::BV_OBBRSS
@ BV_OBBRSS
Definition: coal/collision_object.h:70
obb
Definition: obb.py:1
coal::BVHModelBase
A base class describing the bounding hierarchy of a mesh model or a point cloud model (which is viewe...
Definition: coal/BVH/BVH_model.h:65
coal::BVHModel::num_bvs
unsigned int num_bvs
Number of BV nodes in bounding volume hierarchy.
Definition: coal/BVH/BVH_model.h:386
coal::BVHModel::refitTree
int refitTree(bool bottomup)
Refit the bounding volume hierarchy.
Definition: BVH_model.cpp:962
coal::NODE_TYPE
NODE_TYPE
traversal node type: bounding volume (AABB, OBB, RSS, kIOS, OBBRSS, KDOP16, KDOP18,...
Definition: coal/collision_object.h:64
coal::BVHModelBase::allocateBVs
virtual bool allocateBVs()=0
coal::BV_RSS
@ BV_RSS
Definition: coal/collision_object.h:68
coal::BVHModelBase::endReplaceModel
int endReplaceModel(bool refit=true, bool bottomup=true)
End BVH model replacement, will also refit or rebuild the bounding volume hierarchy.
Definition: BVH_model.cpp:645
coal::BVHModelBase::num_vertices_allocated
unsigned int num_vertices_allocated
Definition: coal/BVH/BVH_model.h:302
coal
Main namespace.
Definition: coal/broadphase/broadphase_bruteforce.h:44
coal::BVHModel::buildTree
int buildTree()
Build the bounding volume hierarchy.
Definition: BVH_model.cpp:858
coal::Triangle::index_type
std::size_t index_type
Definition: coal/data_types.h:113
octree.r
r
Definition: octree.py:9
coal::fit
void fit(Vec3s *ps, unsigned int n, BV &bv)
Compute a bounding volume that fits a set of n points.
Definition: coal/internal/BV_fitter.h:51
coal::BVHModelBase::beginUpdateModel
int beginUpdateModel()
Replace the geometry information of current frame (i.e. should have the same mesh topology with the p...
Definition: BVH_model.cpp:673
coal::BVHModelBase::num_tris_allocated
unsigned int num_tris_allocated
Definition: coal/BVH/BVH_model.h:301
coal::BVNodeBase::num_primitives
unsigned int num_primitives
The number of primitives belonging to the current node.
Definition: coal/BV/BV_node.h:64
coal::BV_KDOP18
@ BV_KDOP18
Definition: coal/collision_object.h:72
coal::BVHModelBase::addVertices
int addVertices(const MatrixX3s &points)
Add points in the new BVH model.
Definition: BVH_model.cpp:307
coal::BVNodeBase::rightChild
int rightChild() const
Return the index of the second child. The index is referred to the bounding volume array (i....
Definition: coal/BV/BV_node.h:99
coal::BVNodeBase::first_child
int first_child
An index for first child node or primitive If the value is positive, it is the index of the first chi...
Definition: coal/BV/BV_node.h:56
coal::BVSplitter
A class describing the split rule that splits each BV node.
Definition: coal/BVH/BVH_model.h:61
BV.h
coal::BVHModelBase::addSubModel
int addSubModel(const std::vector< Vec3s > &ps, const std::vector< Triangle > &ts)
Add a set of triangles in the new BVH model.
Definition: BVH_model.cpp:439
coal::BVHModelBase::updateSubModel
int updateSubModel(const std::vector< Vec3s > &ps)
Update a set of points in the old BVH model.
Definition: BVH_model.cpp:732
coal::CollisionGeometry
The geometry for the object for collision or distance computation.
Definition: coal/collision_object.h:94
coal::BVHModelBase::updateTriangle
int updateTriangle(const Vec3s &p1, const Vec3s &p2, const Vec3s &p3)
Update one triangle in the old BVH model.
Definition: BVH_model.cpp:713
coal::BVH_BUILD_STATE_PROCESSED
@ BVH_BUILD_STATE_PROCESSED
Definition: coal/BVH/BVH_internal.h:53
coal::AABB
A class describing the AABB collision structure, which is a box in 3D space determined by two diagona...
Definition: coal/BV/AABB.h:55
convex.h
coal::SPLIT_METHOD_MEAN
@ SPLIT_METHOD_MEAN
Definition: coal/internal/BV_splitter.h:51
coal::BVNode::bv
BV bv
bounding volume storing the geometry
Definition: coal/BV/BV_node.h:110
coal::BVH_BUILD_STATE_UPDATE_BEGUN
@ BVH_BUILD_STATE_UPDATE_BEGUN
after tree has been build, ready for cd use
Definition: coal/BVH/BVH_internal.h:54
res
res
coal::BVH_MODEL_POINTCLOUD
@ BVH_MODEL_POINTCLOUD
triangle model
Definition: coal/BVH/BVH_internal.h:82
coal::BVHModel::recursiveRefitTree_bottomup
int recursiveRefitTree_bottomup(int bv_id)
Recursive kernel for bottomup refitting.
Definition: BVH_model.cpp:983
coal::BVHModelBase::addTriangle
int addTriangle(const Vec3s &p1, const Vec3s &p2, const Vec3s &p3)
Add one triangle in the new BVH model.
Definition: BVH_model.cpp:340
coal::BVH_MODEL_TRIANGLES
@ BVH_MODEL_TRIANGLES
unknown model type
Definition: coal/BVH/BVH_internal.h:81
coal::BVHModel::deleteBVs
void deleteBVs()
Definition: BVH_model.cpp:811
BVH_model.h
coal::BVH_ERR_BUILD_EMPTY_MODEL
@ BVH_ERR_BUILD_EMPTY_MODEL
BVH construction does not follow correct sequence.
Definition: coal/BVH/BVH_internal.h:69
coal::BVH_ERR_INCORRECT_DATA
@ BVH_ERR_INCORRECT_DATA
BVH model update failed.
Definition: coal/BVH/BVH_internal.h:74
coal::BVH_BUILD_STATE_EMPTY
@ BVH_BUILD_STATE_EMPTY
Definition: coal/BVH/BVH_internal.h:50
coal::BVHModel::BVHModel
BVHModel()
Default constructor to build an empty BVH.
Definition: BVH_model.cpp:803
coal::BVHModel::recursiveBuildTree
int recursiveBuildTree(int bv_id, unsigned int first_primitive, unsigned int num_primitives)
Recursive kernel for hierarchy construction.
Definition: BVH_model.cpp:892
coal::CollisionGeometry::aabb_local
AABB aabb_local
AABB in local coordinate, used for tight AABB when only translation transform.
Definition: coal/collision_object.h:158
coal::ConvexBase::convexHull
static ConvexBase * convexHull(std::shared_ptr< std::vector< Vec3s >> &points, unsigned int num_points, bool keepTriangles, const char *qhullCommand=NULL)
Build a convex hull based on Qhull library and store the vertices and optionally the triangles.
Definition: src/shape/convex.cpp:44
coal::BVHModelBase::convex
shared_ptr< ConvexBase > convex
Convex<Triangle> representation of this object.
Definition: coal/BVH/BVH_model.h:86
coal::BVH_BUILD_STATE_UPDATED
@ BVH_BUILD_STATE_UPDATED
Definition: coal/BVH/BVH_internal.h:56
coal::BVHModelBase::updateVertex
int updateVertex(const Vec3s &p)
Update one point in the old BVH model.
Definition: BVH_model.cpp:698
coal::BVH_ERR_UNSUPPORTED_FUNCTION
@ BVH_ERR_UNSUPPORTED_FUNCTION
BVH geometry in previous frame is not prepared.
Definition: coal/BVH/BVH_internal.h:72
coal::BVHModelBase::addVertex
int addVertex(const Vec3s &p)
Add one point in the new BVH model.
Definition: BVH_model.cpp:235
coal::CollisionGeometry::aabb_radius
CoalScalar aabb_radius
AABB radius.
Definition: coal/collision_object.h:154
coal::Convex
Convex polytope.
Definition: coal/serialization/collision_object.h:51
coal::BVHModel::primitive_indices
std::shared_ptr< std::vector< unsigned int > > primitive_indices
Definition: coal/BVH/BVH_model.h:380
coal::BVH_OK
@ BVH_OK
Definition: coal/BVH/BVH_internal.h:64
coal::BVHModelBase::isEqual
virtual bool isEqual(const CollisionGeometry &other) const
for ccd vertex update
Definition: BVH_model.cpp:84
coal::BVNodeBase::first_primitive
unsigned int first_primitive
The start id the primitive belonging to the current node. The index is referred to the primitive_indi...
Definition: coal/BV/BV_node.h:61
coal::BVHModelBase::beginReplaceModel
int beginReplaceModel()
Replace the geometry information of current frame (i.e. should have the same mesh topology with the p...
Definition: BVH_model.cpp:577
coal::BVHModelBase::computeLocalAABB
void computeLocalAABB()
Compute the AABB for the BVH, used for broad-phase collision.
Definition: BVH_model.cpp:781
coal::MatrixX3s
Eigen::Matrix< CoalScalar, Eigen::Dynamic, 3, Eigen::RowMajor > MatrixX3s
Definition: coal/data_types.h:82
coal::BVHModelBase::build_state
BVHBuildState build_state
The state of BVH building process.
Definition: coal/BVH/BVH_model.h:83
BV_splitter.h
coal::BVHModel::bvs
std::shared_ptr< bv_node_vector_t > bvs
Bounding volume hierarchy.
Definition: coal/BVH/BVH_model.h:383
coal::AABB::center
Vec3s center() const
Center of the AABB.
Definition: coal/BV/AABB.h:164
octree.p1
tuple p1
Definition: octree.py:54
coal::BVNode
A class describing a bounding volume node. It includes the tree structure providing in BVNodeBase and...
Definition: coal/BV/BV_node.h:106
coal::BVHModel::getNodeType
NODE_TYPE getNodeType() const
Get the BV type: default is unknown.
Definition: coal/BVH/BVH_model.h:361
coal::BVH_ERR_BUILD_EMPTY_PREVIOUS_FRAME
@ BVH_ERR_BUILD_EMPTY_PREVIOUS_FRAME
BVH geometry is not prepared.
Definition: coal/BVH/BVH_internal.h:70
coal::BVHModelBase::buildConvexHull
bool buildConvexHull(bool keepTriangle, const char *qhullCommand=NULL)
Build a convex hull and store it in attribute convex.
Definition: BVH_model.cpp:154
coal::BVHModelBase::addTriangles
int addTriangles(const Matrixx3i &triangles)
Add triangles in the new BVH model.
Definition: BVH_model.cpp:267
coal::BVHModel::allocateBVs
bool allocateBVs()
Definition: BVH_model.cpp:818
coal::BVHModelBase::tri_indices
std::shared_ptr< std::vector< Triangle > > tri_indices
Geometry triangle index data, will be NULL for point clouds.
Definition: coal/BVH/BVH_model.h:71
coal::RSS::axes
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Matrix3s axes
Orientation of RSS. axis[i] is the ith column of the orientation matrix for the RSS; it is also the i...
Definition: coal/BV/RSS.h:61
coal::BVHModel
A class describing the bounding hierarchy of a mesh model or a point cloud model (which is viewed as ...
Definition: coal/BVH/BVH_model.h:314
coal::BVHModelBase::endUpdateModel
int endUpdateModel(bool refit=true, bool bottomup=true)
End BVH model update, will also refit or rebuild the bounding volume hierarchy.
Definition: BVH_model.cpp:749
coal::Matrix3s
Eigen::Matrix< CoalScalar, 3, 3 > Matrix3s
Definition: coal/data_types.h:81
coal::BVHModel::refitTree_topdown
int refitTree_topdown()
Refit the bounding volume hierarchy in a top-down way (slow but more compact)
Definition: BVH_model.cpp:1046
coal::BVHModelBase::buildTree
virtual int buildTree()=0
Build the bounding volume hierarchy.
ts
ts
coal::BVFitter
The class for the default algorithm fitting a bounding volume to a set of points.
Definition: coal/BVH/BVH_model.h:59
coal::BVNodeBase::isLeaf
bool isLeaf() const
Whether current node is a leaf node (i.e. contains a primitive index.
Definition: coal/BV/BV_node.h:87
coal::BVHModelBase::num_vertices
unsigned int num_vertices
Number of points.
Definition: coal/BVH/BVH_model.h:80
coal::RSS::Tr
Vec3s Tr
Origin of the rectangle in RSS.
Definition: coal/BV/RSS.h:64
coal::BVHModelBase::deleteBVs
virtual void deleteBVs()=0
coal::BVHModelBase::refitTree
virtual int refitTree(bool bottomup)=0
Refit the bounding volume hierarchy.
coal::OBB
Oriented bounding box class.
Definition: include/coal/BV/OBB.h:51
coal::BVHModelBase::BVHModelBase
BVHModelBase()
Constructing an empty BVH.
Definition: BVH_model.cpp:53
coal::BVH_ERR_BUILD_OUT_OF_SEQUENCE
@ BVH_ERR_BUILD_OUT_OF_SEQUENCE
Cannot allocate memory for vertices and triangles.
Definition: coal/BVH/BVH_internal.h:67
coal::BV_OBB
@ BV_OBB
Definition: coal/collision_object.h:67
coal::CollisionGeometry::aabb_center
Vec3s aabb_center
AABB center in local coordinate.
Definition: coal/collision_object.h:151
coal::Triangle
Triangle with 3 indices for points.
Definition: coal/data_types.h:111
coal::BVH_ERR_MODEL_OUT_OF_MEMORY
@ BVH_ERR_MODEL_OUT_OF_MEMORY
BVH is valid.
Definition: coal/BVH/BVH_internal.h:65
t
dictionary t
coal::RSS
A class for rectangle sphere-swept bounding volume.
Definition: coal/BV/RSS.h:53
coal::BVHModelBase::num_tris
unsigned int num_tris
Number of triangles.
Definition: coal/BVH/BVH_model.h:77
coal::CoalScalar
double CoalScalar
Definition: coal/data_types.h:76
coal::BVHModelBase::prev_vertices
std::shared_ptr< std::vector< Vec3s > > prev_vertices
Geometry point data in previous frame.
Definition: coal/BVH/BVH_model.h:74
coal::BVNodeBase::leftChild
int leftChild() const
Return the index of the first child. The index is referred to the bounding volume array (i....
Definition: coal/BV/BV_node.h:95
coal::Matrixx3i
Eigen::Matrix< Eigen::DenseIndex, Eigen::Dynamic, 3, Eigen::RowMajor > Matrixx3i
Definition: coal/data_types.h:85
obb.v
list v
Definition: obb.py:48
coal::BV_KDOP16
@ BV_KDOP16
Definition: coal/collision_object.h:71
coal::BVH_BUILD_STATE_BEGUN
@ BVH_BUILD_STATE_BEGUN
empty state, immediately after constructor
Definition: coal/BVH/BVH_internal.h:51
coal::BVHModel::bv_node_vector_t
std::vector< BVNode< BV >, Eigen::aligned_allocator< BVNode< BV > >> bv_node_vector_t
Definition: coal/BVH/BVH_model.h:319
BV_node.h


hpp-fcl
Author(s):
autogenerated on Sat Nov 23 2024 03:44:57