BVH_model.cpp 31.2 KB
Newer Older
sachinc's avatar
sachinc committed
1
2
3
/*
 * Software License Agreement (BSD License)
 *
4
5
 *  Copyright (c) 2011-2014, Willow Garage, Inc.
 *  Copyright (c) 2014-2015, Open Source Robotics Foundation
6
 *  Copyright (c) 2020, INRIA
sachinc's avatar
sachinc committed
7
8
9
10
11
12
13
14
15
16
17
18
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above
 *     copyright notice, this list of conditions and the following
 *     disclaimer in the documentation and/or other materials provided
 *     with the distribution.
19
 *   * Neither the name of Open Source Robotics Foundation nor the names of its
sachinc's avatar
sachinc committed
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 */

/** \author Jia Pan */

39
#include <hpp/fcl/BVH/BVH_model.h>
40

sachinc's avatar
sachinc committed
41
42
43
#include <iostream>
#include <string.h>

44
45
46
#include <hpp/fcl/BV/BV.h>
#include <hpp/fcl/shape/convex.h>

Lucile Remigy's avatar
Lucile Remigy committed
47
#include <hpp/fcl/internal/BV_splitter.h>
48
#include <hpp/fcl/internal/BV_fitter.h>
49

50
51
namespace hpp
{
sachinc's avatar
sachinc committed
52
53
54
namespace fcl
{

55
56
57
58
59
60
61
62
63
64
65
66
67
BVHModelBase::BVHModelBase()
  : vertices(NULL)
  , tri_indices(NULL)
  , prev_vertices(NULL)
  , num_tris(0)
  , num_vertices(0)
  , build_state(BVH_BUILD_STATE_EMPTY)
  , num_tris_allocated(0)
  , num_vertices_allocated(0)
  , num_vertex_updated(0)
{
}

68
69
70
71
72
73
74
BVHModelBase::BVHModelBase(const BVHModelBase& other) :
  CollisionGeometry(other),
  num_tris(other.num_tris),
  num_vertices(other.num_vertices),
  build_state(other.build_state),
  num_tris_allocated(other.num_tris),
  num_vertices_allocated(other.num_vertices)
sachinc's avatar
sachinc committed
75
76
77
78
{
  if(other.vertices)
  {
    vertices = new Vec3f[num_vertices];
Justin Carpentier's avatar
Justin Carpentier committed
79
    memcpy(vertices, other.vertices, sizeof(Vec3f) * (size_t)num_vertices);
sachinc's avatar
sachinc committed
80
81
82
83
84
85
86
  }
  else
    vertices = NULL;

  if(other.tri_indices)
  {
    tri_indices = new Triangle[num_tris];
Justin Carpentier's avatar
Justin Carpentier committed
87
    memcpy(tri_indices, other.tri_indices, sizeof(Triangle) * (size_t)num_tris);
sachinc's avatar
sachinc committed
88
89
90
91
92
93
94
  }
  else
    tri_indices = NULL;

  if(other.prev_vertices)
  {
    prev_vertices = new Vec3f[num_vertices];
Justin Carpentier's avatar
Justin Carpentier committed
95
    memcpy(prev_vertices, other.prev_vertices, sizeof(Vec3f) * (size_t)num_vertices);
sachinc's avatar
sachinc committed
96
97
98
  }
  else
    prev_vertices = NULL;
99
100
}

101
102
103
104
105
106
107
108
109
bool BVHModelBase::operator==(const BVHModelBase & other) const
{
  bool result =
     CollisionGeometry::operator==(static_cast<const CollisionGeometry &>(other))
  && num_tris == other.num_tris
  && num_vertices == other.num_vertices;
  
  if(!result) return false;
  
110
  for(size_t k = 0; k < static_cast<size_t>(num_tris); ++k)
111
112
113
    if(tri_indices[k] != other.tri_indices[k])
      return false;
  
114
  for(size_t k = 0; k < static_cast<size_t>(num_vertices); ++k)
115
116
117
118
119
    if(vertices[k] != other.vertices[k])
      return false;
  
  if(prev_vertices != NULL && other.prev_vertices != NULL)
  {
120
    for(size_t k = 0; k < static_cast<size_t>(num_vertices); ++k)
121
122
123
124
125
126
127
128
129
    {
      if(prev_vertices[k] != other.prev_vertices[k])
        return false;
    }
  }
      
  return true;
}

130
131
132
void BVHModelBase::buildConvexRepresentation(bool share_memory)
{
  if (!convex) {
133
134
135
136
    Vec3f* points = vertices;
    Triangle* polygons = tri_indices;
    if (!share_memory) {
      points = new Vec3f[num_vertices];
Justin Carpentier's avatar
Justin Carpentier committed
137
      memcpy(points, vertices, sizeof(Vec3f) * (size_t)num_vertices);
138
139

      polygons = new Triangle[num_tris];
Justin Carpentier's avatar
Justin Carpentier committed
140
      memcpy(polygons, tri_indices, sizeof(Triangle) * (size_t)num_tris);
141
    }
142
    convex.reset(new Convex<Triangle>(!share_memory, points, num_vertices, polygons, num_tris));
143
144
  }
}
sachinc's avatar
sachinc committed
145

146
147
148
149
150
151
152
153
bool BVHModelBase::buildConvexHull(bool keepTriangle, const char* qhullCommand)
{
  convex.reset(
      ConvexBase::convexHull(vertices, num_vertices, keepTriangle, qhullCommand)
      );
  return num_vertices == convex->num_points;
}

154
155
156
157
158
template<typename BV>
BVHModel<BV>::BVHModel(const BVHModel<BV>& other) : BVHModelBase(other),
                                                    bv_splitter(other.bv_splitter),
                                                    bv_fitter(other.bv_fitter)
{
sachinc's avatar
sachinc committed
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
  if(other.primitive_indices)
  {
    int num_primitives = 0;
    switch(other.getModelType())
    {
      case BVH_MODEL_TRIANGLES:
        num_primitives = num_tris;
        break;
      case BVH_MODEL_POINTCLOUD:
        num_primitives = num_vertices;
        break;
      default:
        ;
    }

    primitive_indices = new unsigned int[num_primitives];
Justin Carpentier's avatar
Justin Carpentier committed
175
    memcpy(primitive_indices, other.primitive_indices, sizeof(unsigned int) * (size_t)num_primitives);
sachinc's avatar
sachinc committed
176
177
178
179
180
181
182
183
  }
  else
    primitive_indices = NULL;

  num_bvs = num_bvs_allocated = other.num_bvs;
  if(other.bvs)
  {
    bvs = new BVNode<BV>[num_bvs];
Justin Carpentier's avatar
Justin Carpentier committed
184
    memcpy(bvs, other.bvs, sizeof(BVNode<BV>) * (size_t)num_bvs);
sachinc's avatar
sachinc committed
185
186
187
188
189
190
  }
  else
    bvs = NULL;
}


191
int BVHModelBase::beginModel(int num_tris_, int num_vertices_)
sachinc's avatar
sachinc committed
192
193
194
195
196
197
198
{
  if(build_state != BVH_BUILD_STATE_EMPTY)
  {
    delete [] vertices; vertices = NULL;
    delete [] tri_indices; tri_indices = NULL;
    delete [] prev_vertices; prev_vertices = NULL;

199
200
    num_vertices_allocated = num_vertices = num_tris_allocated = num_tris = 0;
    deleteBVs();
sachinc's avatar
sachinc committed
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
  }

  if(num_tris_ <= 0) num_tris_ = 8;
  if(num_vertices_ <= 0) num_vertices_ = 8;

  num_vertices_allocated = num_vertices_;
  num_tris_allocated = num_tris_;

  tri_indices = new Triangle[num_tris_allocated];

  if(!tri_indices)
  {
    std::cerr << "BVH Error! Out of memory for tri_indices array on BeginModel() call!" << std::endl;
    return BVH_ERR_MODEL_OUT_OF_MEMORY;
  }
Justin Carpentier's avatar
Justin Carpentier committed
216
217
  
  vertices = new Vec3f[num_vertices_allocated];
sachinc's avatar
sachinc committed
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
  if(!vertices)
  {
    std::cerr << "BVH Error! Out of memory for vertices array on BeginModel() call!" << std::endl;
    return BVH_ERR_MODEL_OUT_OF_MEMORY;
  }

  if(build_state != BVH_BUILD_STATE_EMPTY)
  {
    std::cerr << "BVH Warning! Call beginModel() on a BVHModel that is not empty. This model was cleared and previous triangles/vertices were lost." << std::endl;
    build_state = BVH_BUILD_STATE_EMPTY;
    return BVH_ERR_BUILD_OUT_OF_SEQUENCE;
  }

  build_state = BVH_BUILD_STATE_BEGUN;

  return BVH_OK;
}

236
int BVHModelBase::addVertex(const Vec3f& p)
sachinc's avatar
sachinc committed
237
{
238
  if(build_state != BVH_BUILD_STATE_BEGUN)
sachinc's avatar
sachinc committed
239
240
241
242
243
244
245
246
247
248
249
250
251
252
  {
    std::cerr << "BVH Warning! Call addVertex() in a wrong order. addVertex() was ignored. Must do a beginModel() to clear the model for addition of new vertices." << std::endl;
    return BVH_ERR_BUILD_OUT_OF_SEQUENCE;
  }

  if(num_vertices >= num_vertices_allocated)
  {
    Vec3f* temp = new Vec3f[num_vertices_allocated * 2];
    if(!temp)
    {
      std::cerr << "BVH Error! Out of memory for vertices array on addVertex() call!" << std::endl;
      return BVH_ERR_MODEL_OUT_OF_MEMORY;
    }

Justin Carpentier's avatar
Justin Carpentier committed
253
    memcpy(temp, vertices, sizeof(Vec3f) * (size_t)num_vertices);
sachinc's avatar
sachinc committed
254
255
256
257
258
259
260
261
262
263
264
    delete [] vertices;
    vertices = temp;
    num_vertices_allocated *= 2;
  }

  vertices[num_vertices] = p;
  num_vertices += 1;

  return BVH_OK;
}

265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
int BVHModelBase::addTriangles(const Matrixx3i & triangles)
{
  if(build_state == BVH_BUILD_STATE_PROCESSED)
  {
    std::cerr << "BVH Warning! Call addSubModel() in a wrong order. addSubModel() was ignored. Must do a beginModel() to clear the model for addition of new vertices." << std::endl;
    return BVH_ERR_BUILD_OUT_OF_SEQUENCE;
  }
  
  const int num_tris_to_add = (int)triangles.rows();

  if(num_tris + num_tris_to_add > num_tris_allocated)
  {
    Triangle* temp = new Triangle[num_tris_allocated * 2 + num_tris_to_add];
    if(!temp)
    {
      std::cerr << "BVH Error! Out of memory for tri_indices array on addSubModel() call!" << std::endl;
      return BVH_ERR_MODEL_OUT_OF_MEMORY;
    }

    memcpy(temp, tri_indices, sizeof(Triangle) * (size_t)num_tris);
    delete [] tri_indices;
    tri_indices = temp;
    num_tris_allocated = num_tris_allocated * 2 + num_tris_to_add;
  }

  for(Eigen::DenseIndex i = 0; i < triangles.rows(); ++i)
  {
    const Matrixx3i::ConstRowXpr triangle = triangles.row(i);
    tri_indices[num_tris++].set(triangle[0], triangle[1], triangle[2]);
  }

  return BVH_OK;
}

Justin Carpentier's avatar
Justin Carpentier committed
299
int BVHModelBase::addVertices(const Matrixx3f & points)
300
301
302
303
304
305
306
307
308
{
  if(build_state != BVH_BUILD_STATE_BEGUN)
  {
    std::cerr << "BVH Warning! Call addVertex() in a wrong order. addVertices() was ignored. Must do a beginModel() to clear the model for addition of new vertices." << std::endl;
    return BVH_ERR_BUILD_OUT_OF_SEQUENCE;
  }

  if(num_vertices + points.rows() > num_vertices_allocated)
  {
309
    num_vertices_allocated = num_vertices + (int)points.rows();
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
    Vec3f * temp = new Vec3f[num_vertices_allocated];
    if(!temp)
    {
      std::cerr << "BVH Error! Out of memory for vertices array on addVertex() call!" << std::endl;
      return BVH_ERR_MODEL_OUT_OF_MEMORY;
    }

    memcpy(temp, vertices, sizeof(Vec3f) * (size_t)num_vertices);
    delete [] vertices;
    vertices = temp;
  }

  for(Eigen::DenseIndex id = 0; id < points.rows(); ++id)
    vertices[num_vertices++] = points.row(id).transpose();

  return BVH_OK;
}

328
int BVHModelBase::addTriangle(const Vec3f& p1, const Vec3f& p2, const Vec3f& p3)
sachinc's avatar
sachinc committed
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
{
  if(build_state == BVH_BUILD_STATE_PROCESSED)
  {
    std::cerr << "BVH Warning! Call addTriangle() in a wrong order. addTriangle() was ignored. Must do a beginModel() to clear the model for addition of new triangles." << std::endl;
    return BVH_ERR_BUILD_OUT_OF_SEQUENCE;
  }

  if(num_vertices + 2 >= num_vertices_allocated)
  {
    Vec3f* temp = new Vec3f[num_vertices_allocated * 2 + 2];
    if(!temp)
    {
      std::cerr << "BVH Error! Out of memory for vertices array on addTriangle() call!" << std::endl;
      return BVH_ERR_MODEL_OUT_OF_MEMORY;
    }

Justin Carpentier's avatar
Justin Carpentier committed
345
    memcpy(temp, vertices, sizeof(Vec3f) * (size_t)num_vertices);
sachinc's avatar
sachinc committed
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
    delete [] vertices;
    vertices = temp;
    num_vertices_allocated = num_vertices_allocated * 2 + 2;
  }

  int offset = num_vertices;

  vertices[num_vertices] = p1;
  num_vertices++;
  vertices[num_vertices] = p2;
  num_vertices++;
  vertices[num_vertices] = p3;
  num_vertices++;

  if(num_tris >= num_tris_allocated)
  {
    Triangle* temp = new Triangle[num_tris_allocated * 2];
    if(!temp)
    {
      std::cerr << "BVH Error! Out of memory for tri_indices array on addTriangle() call!" << std::endl;
      return BVH_ERR_MODEL_OUT_OF_MEMORY;
    }

Justin Carpentier's avatar
Justin Carpentier committed
369
    memcpy(temp, tri_indices, sizeof(Triangle) * (size_t)num_tris);
sachinc's avatar
sachinc committed
370
371
372
373
374
    delete [] tri_indices;
    tri_indices = temp;
    num_tris_allocated *= 2;
  }

Justin Carpentier's avatar
Justin Carpentier committed
375
376
377
  tri_indices[num_tris].set((Triangle::index_type)offset,
                            (Triangle::index_type)(offset + 1),
                            (Triangle::index_type)(offset + 2));
378
  num_tris++;
sachinc's avatar
sachinc committed
379
380
381
382

  return BVH_OK;
}

383
int BVHModelBase::addSubModel(const std::vector<Vec3f>& ps)
sachinc's avatar
sachinc committed
384
385
386
387
388
389
390
{
  if(build_state == BVH_BUILD_STATE_PROCESSED)
  {
    std::cerr << "BVH Warning! Call addSubModel() in a wrong order. addSubModel() was ignored. Must do a beginModel() to clear the model for addition of new vertices." << std::endl;
    return BVH_ERR_BUILD_OUT_OF_SEQUENCE;
  }

391
  int num_vertices_to_add = (int)ps.size();
sachinc's avatar
sachinc committed
392
393
394
395
396
397
398
399
400
401

  if(num_vertices + num_vertices_to_add - 1 >= num_vertices_allocated)
  {
    Vec3f* temp = new Vec3f[num_vertices_allocated * 2 + num_vertices_to_add - 1];
    if(!temp)
    {
      std::cerr << "BVH Error! Out of memory for vertices array on addSubModel() call!" << std::endl;
      return BVH_ERR_MODEL_OUT_OF_MEMORY;
    }

Justin Carpentier's avatar
Justin Carpentier committed
402
    memcpy(temp, vertices, sizeof(Vec3f) * (size_t)num_vertices);
sachinc's avatar
sachinc committed
403
404
405
406
407
    delete [] vertices;
    vertices = temp;
    num_vertices_allocated = num_vertices_allocated * 2 + num_vertices_to_add - 1;
  }

Justin Carpentier's avatar
Justin Carpentier committed
408
  for(size_t i = 0; i < (size_t)num_vertices_to_add; ++i)
sachinc's avatar
sachinc committed
409
410
411
412
413
414
415
416
  {
    vertices[num_vertices] = ps[i];
    num_vertices++;
  }

  return BVH_OK;
}

417
int BVHModelBase::addSubModel(const std::vector<Vec3f>& ps, const std::vector<Triangle>& ts)
sachinc's avatar
sachinc committed
418
419
420
421
422
423
424
{
  if(build_state == BVH_BUILD_STATE_PROCESSED)
  {
    std::cerr << "BVH Warning! Call addSubModel() in a wrong order. addSubModel() was ignored. Must do a beginModel() to clear the model for addition of new vertices." << std::endl;
    return BVH_ERR_BUILD_OUT_OF_SEQUENCE;
  }

425
  int num_vertices_to_add = (int)ps.size();
sachinc's avatar
sachinc committed
426
427
428
429
430
431
432
433
434
435

  if(num_vertices + num_vertices_to_add - 1 >= num_vertices_allocated)
  {
    Vec3f* temp = new Vec3f[num_vertices_allocated * 2 + num_vertices_to_add - 1];
    if(!temp)
    {
      std::cerr << "BVH Error! Out of memory for vertices array on addSubModel() call!" << std::endl;
      return BVH_ERR_MODEL_OUT_OF_MEMORY;
    }

Justin Carpentier's avatar
Justin Carpentier committed
436
    memcpy(temp, vertices, sizeof(Vec3f) * (size_t)num_vertices);
sachinc's avatar
sachinc committed
437
438
439
440
441
442
443
    delete [] vertices;
    vertices = temp;
    num_vertices_allocated = num_vertices_allocated * 2 + num_vertices_to_add - 1;
  }

  int offset = num_vertices;

Justin Carpentier's avatar
Justin Carpentier committed
444
  for(size_t i = 0; i < (size_t)num_vertices_to_add; ++i)
sachinc's avatar
sachinc committed
445
446
447
448
449
450
  {
    vertices[num_vertices] = ps[i];
    num_vertices++;
  }


451
  int num_tris_to_add = (int)ts.size();
sachinc's avatar
sachinc committed
452
453
454
455
456
457
458
459
460
461

  if(num_tris + num_tris_to_add - 1 >= num_tris_allocated)
  {
    Triangle* temp = new Triangle[num_tris_allocated * 2 + num_tris_to_add - 1];
    if(!temp)
    {
      std::cerr << "BVH Error! Out of memory for tri_indices array on addSubModel() call!" << std::endl;
      return BVH_ERR_MODEL_OUT_OF_MEMORY;
    }

Justin Carpentier's avatar
Justin Carpentier committed
462
    memcpy(temp, tri_indices, sizeof(Triangle) * (size_t)num_tris);
sachinc's avatar
sachinc committed
463
464
465
466
467
    delete [] tri_indices;
    tri_indices = temp;
    num_tris_allocated = num_tris_allocated * 2 + num_tris_to_add - 1;
  }

Justin Carpentier's avatar
Justin Carpentier committed
468
  for(size_t i = 0; i < (size_t)num_tris_to_add; ++i)
sachinc's avatar
sachinc committed
469
470
  {
    const Triangle& t = ts[i];
Justin Carpentier's avatar
Justin Carpentier committed
471
472
473
    tri_indices[num_tris].set(t[0] + (size_t)offset,
                              t[1] + (size_t)offset,
                              t[2] + (size_t)offset);
sachinc's avatar
sachinc committed
474
475
476
477
478
479
    num_tris++;
  }

  return BVH_OK;
}

480
int BVHModelBase::endModel()
sachinc's avatar
sachinc committed
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
{
  if(build_state != BVH_BUILD_STATE_BEGUN)
  {
    std::cerr << "BVH Warning! Call endModel() in wrong order. endModel() was ignored." << std::endl;
    return BVH_ERR_BUILD_OUT_OF_SEQUENCE;
  }

  if(num_tris == 0 && num_vertices == 0)
  {
    std::cerr << "BVH Error! endModel() called on model with no triangles and vertices." << std::endl;
    return BVH_ERR_BUILD_EMPTY_MODEL;
  }

  if(num_tris_allocated > num_tris)
  {
496
    if(num_tris > 0)
sachinc's avatar
sachinc committed
497
    {
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
      Triangle* new_tris = new Triangle[num_tris];
      if(!new_tris)
      {
        std::cerr << "BVH Error! Out of memory for tri_indices array in endModel() call!" << std::endl;
        return BVH_ERR_MODEL_OUT_OF_MEMORY;
      }
      memcpy(new_tris, tri_indices, sizeof(Triangle) * (size_t)num_tris);
      delete [] tri_indices;
      tri_indices = new_tris;
      num_tris_allocated = num_tris;
    }
    else
    {
      delete [] tri_indices;
      tri_indices = NULL;
      num_tris = num_tris_allocated = 0;
sachinc's avatar
sachinc committed
514
515
516
517
518
519
520
521
522
523
524
    }
  }

  if(num_vertices_allocated > num_vertices)
  {
    Vec3f* new_vertices = new Vec3f[num_vertices];
    if(!new_vertices)
    {
      std::cerr << "BVH Error! Out of memory for vertices array in endModel() call!" << std::endl;
      return BVH_ERR_MODEL_OUT_OF_MEMORY;
    }
Justin Carpentier's avatar
Justin Carpentier committed
525
    memcpy(new_vertices, vertices, sizeof(Vec3f) * (size_t)num_vertices);
sachinc's avatar
sachinc committed
526
527
528
529
530
531
    delete [] vertices;
    vertices = new_vertices;
    num_vertices_allocated = num_vertices;
  }

  // construct BVH tree
532
  if (!allocateBVs ())
sachinc's avatar
sachinc committed
533
534
535
536
537
538
539
540
541
542
543
544
    return BVH_ERR_MODEL_OUT_OF_MEMORY;

  buildTree();

  // finish constructing
  build_state = BVH_BUILD_STATE_PROCESSED;

  return BVH_OK;
}



545
int BVHModelBase::beginReplaceModel()
sachinc's avatar
sachinc committed
546
547
548
549
550
551
552
{
  if(build_state != BVH_BUILD_STATE_PROCESSED)
  {
    std::cerr << "BVH Error! Call beginReplaceModel() on a BVHModel that has no previous frame." << std::endl;
    return BVH_ERR_BUILD_EMPTY_PREVIOUS_FRAME;
  }

553
554
  if(prev_vertices) delete [] prev_vertices;
  prev_vertices = NULL;
sachinc's avatar
sachinc committed
555
556
557
558
559
560
561
562

  num_vertex_updated = 0;

  build_state = BVH_BUILD_STATE_REPLACE_BEGUN;

  return BVH_OK;
}

563
int BVHModelBase::replaceVertex(const Vec3f& p)
sachinc's avatar
sachinc committed
564
565
566
567
568
569
570
571
572
573
574
575
576
{
  if(build_state != BVH_BUILD_STATE_REPLACE_BEGUN)
  {
    std::cerr << "BVH Warning! Call replaceVertex() in a wrong order. replaceVertex() was ignored. Must do a beginReplaceModel() for initialization." << std::endl;
    return BVH_ERR_BUILD_OUT_OF_SEQUENCE;
  }

  vertices[num_vertex_updated] = p;
  num_vertex_updated++;

  return BVH_OK;
}

577
int BVHModelBase::replaceTriangle(const Vec3f& p1, const Vec3f& p2, const Vec3f& p3)
sachinc's avatar
sachinc committed
578
579
580
581
582
583
584
585
586
587
588
589
590
{
  if(build_state != BVH_BUILD_STATE_REPLACE_BEGUN)
  {
    std::cerr << "BVH Warning! Call replaceTriangle() in a wrong order. replaceTriangle() was ignored. Must do a beginReplaceModel() for initialization." << std::endl;
    return BVH_ERR_BUILD_OUT_OF_SEQUENCE;
  }

  vertices[num_vertex_updated] = p1; num_vertex_updated++;
  vertices[num_vertex_updated] = p2; num_vertex_updated++;
  vertices[num_vertex_updated] = p3; num_vertex_updated++;
  return BVH_OK;
}

591
int BVHModelBase::replaceSubModel(const std::vector<Vec3f>& ps)
sachinc's avatar
sachinc committed
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
{
  if(build_state != BVH_BUILD_STATE_REPLACE_BEGUN)
  {
    std::cerr << "BVH Warning! Call replaceSubModel() in a wrong order. replaceSubModel() was ignored. Must do a beginReplaceModel() for initialization." << std::endl;
    return BVH_ERR_BUILD_OUT_OF_SEQUENCE;
  }

  for(unsigned int i = 0; i < ps.size(); ++i)
  {
    vertices[num_vertex_updated] = ps[i];
    num_vertex_updated++;
  }
  return BVH_OK;
}

607
int BVHModelBase::endReplaceModel(bool refit, bool bottomup)
sachinc's avatar
sachinc committed
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
{
  if(build_state != BVH_BUILD_STATE_REPLACE_BEGUN)
  {
    std::cerr << "BVH Warning! Call endReplaceModel() in a wrong order. endReplaceModel() was ignored. " << std::endl;
    return BVH_ERR_BUILD_OUT_OF_SEQUENCE;
  }

  if(num_vertex_updated != num_vertices)
  {
    std::cerr << "BVH Error! The replaced model should have the same number of vertices as the old model." << std::endl;
    return BVH_ERR_INCORRECT_DATA;
  }

  if(refit)  // refit, do not change BVH structure
  {
    refitTree(bottomup);
  }
  else // reconstruct bvh tree based on current frame data
  {
    buildTree();
  }

  build_state = BVH_BUILD_STATE_PROCESSED;

  return BVH_OK;
}





639
int BVHModelBase::beginUpdateModel()
sachinc's avatar
sachinc committed
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
{
  if(build_state != BVH_BUILD_STATE_PROCESSED && build_state != BVH_BUILD_STATE_UPDATED)
  {
    std::cerr << "BVH Error! Call beginUpdatemodel() on a BVHModel that has no previous frame." << std::endl;
    return BVH_ERR_BUILD_EMPTY_PREVIOUS_FRAME;
  }

  if(prev_vertices)
  {
    Vec3f* temp = prev_vertices;
    prev_vertices = vertices;
    vertices = temp;
  }
  else
  {
    prev_vertices = vertices;
    vertices = new Vec3f[num_vertices];
  }

  num_vertex_updated = 0;

  build_state = BVH_BUILD_STATE_UPDATE_BEGUN;

  return BVH_OK;
}

666
int BVHModelBase::updateVertex(const Vec3f& p)
sachinc's avatar
sachinc committed
667
668
669
670
671
672
673
674
675
676
677
678
679
{
  if(build_state != BVH_BUILD_STATE_UPDATE_BEGUN)
  {
    std::cerr << "BVH Warning! Call updateVertex() in a wrong order. updateVertex() was ignored. Must do a beginUpdateModel() for initialization." << std::endl;
    return BVH_ERR_BUILD_OUT_OF_SEQUENCE;
  }

  vertices[num_vertex_updated] = p;
  num_vertex_updated++;

  return BVH_OK;
}

680
int BVHModelBase::updateTriangle(const Vec3f& p1, const Vec3f& p2, const Vec3f& p3)
sachinc's avatar
sachinc committed
681
682
683
684
685
686
687
688
689
690
691
692
693
{
  if(build_state != BVH_BUILD_STATE_UPDATE_BEGUN)
  {
    std::cerr << "BVH Warning! Call updateTriangle() in a wrong order. updateTriangle() was ignored. Must do a beginUpdateModel() for initialization." << std::endl;
    return BVH_ERR_BUILD_OUT_OF_SEQUENCE;
  }

  vertices[num_vertex_updated] = p1; num_vertex_updated++;
  vertices[num_vertex_updated] = p2; num_vertex_updated++;
  vertices[num_vertex_updated] = p3; num_vertex_updated++;
  return BVH_OK;
}

694
int BVHModelBase::updateSubModel(const std::vector<Vec3f>& ps)
sachinc's avatar
sachinc committed
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
{
  if(build_state != BVH_BUILD_STATE_UPDATE_BEGUN)
  {
    std::cerr << "BVH Warning! Call updateSubModel() in a wrong order. updateSubModel() was ignored. Must do a beginUpdateModel() for initialization." << std::endl;
    return BVH_ERR_BUILD_OUT_OF_SEQUENCE;
  }

  for(unsigned int i = 0; i < ps.size(); ++i)
  {
    vertices[num_vertex_updated] = ps[i];
    num_vertex_updated++;
  }
  return BVH_OK;
}

710
int BVHModelBase::endUpdateModel(bool refit, bool bottomup)
sachinc's avatar
sachinc committed
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
{
  if(build_state != BVH_BUILD_STATE_UPDATE_BEGUN)
  {
    std::cerr << "BVH Warning! Call endUpdateModel() in a wrong order. endUpdateModel() was ignored. " << std::endl;
    return BVH_ERR_BUILD_OUT_OF_SEQUENCE;
  }

  if(num_vertex_updated != num_vertices)
  {
    std::cerr << "BVH Error! The updated model should have the same number of vertices as the old model." << std::endl;
    return BVH_ERR_INCORRECT_DATA;
  }

  if(refit)  // refit, do not change BVH structure
  {
    refitTree(bottomup);
  }
  else // reconstruct bvh tree based on current frame data
  {
    buildTree();

    // then refit

    refitTree(bottomup);
  }


  build_state = BVH_BUILD_STATE_UPDATED;

  return BVH_OK;
}



745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
void BVHModelBase::computeLocalAABB()
{
  AABB aabb_;
  for(int i = 0; i < num_vertices; ++i)
  {
    aabb_ += vertices[i];
  }

  aabb_center = aabb_.center();

  aabb_radius = 0;
  for(int i = 0; i < num_vertices; ++i)
  {
    FCL_REAL r = (aabb_center - vertices[i]).squaredNorm();
    if(r > aabb_radius) aabb_radius = r;
  }

  aabb_radius = sqrt(aabb_radius);

  aabb_local = aabb_;
}

767
768
769
770
771
772
773
774
775
776
777
778
779
780

  /// @brief Constructing an empty BVH
template<typename BV>
BVHModel<BV>::BVHModel() :
  BVHModelBase (),
  bv_splitter(new BVSplitter<BV>(SPLIT_METHOD_MEAN)),
  bv_fitter(new BVFitter<BV>()),
  num_bvs_allocated(0),
  primitive_indices(NULL),
  bvs(NULL),
  num_bvs(0)
{
}

781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
template<typename BV>
void BVHModel<BV>::deleteBVs()
{
  delete [] bvs; bvs = NULL;
  delete [] primitive_indices; primitive_indices = NULL;
  num_bvs_allocated = num_bvs = 0;
}

template<typename BV>
bool BVHModel<BV>::allocateBVs()
{
  // construct BVH tree
  int num_bvs_to_be_allocated = 0;
  if(num_tris == 0)
    num_bvs_to_be_allocated = 2 * num_vertices - 1;
  else
    num_bvs_to_be_allocated = 2 * num_tris - 1;


  bvs = new BVNode<BV> [num_bvs_to_be_allocated];
  primitive_indices = new unsigned int [num_bvs_to_be_allocated];
  if(!bvs || !primitive_indices)
  {
    std::cerr << "BVH Error! Out of memory for BV array in endModel()!" << std::endl;
    return false;
  }
  num_bvs_allocated = num_bvs_to_be_allocated;
  num_bvs = 0;
  return true;
}
sachinc's avatar
sachinc committed
811
812

template<typename BV>
813
int BVHModel<BV>::memUsage(const bool msg) const
sachinc's avatar
sachinc committed
814
{
815
816
817
  int mem_bv_list = (int)sizeof(BV) * num_bvs;
  int mem_tri_list = (int)sizeof(Triangle) * num_tris;
  int mem_vertex_list = (int)sizeof(Vec3f) * num_vertices;
sachinc's avatar
sachinc committed
818

819
820
  int total_mem = mem_bv_list + mem_tri_list + mem_vertex_list +
    (int)sizeof(BVHModel<BV>);
sachinc's avatar
sachinc committed
821
822
823
824
825
826
827
828
  if(msg)
  {
    std::cerr << "Total for model " << total_mem << " bytes." << std::endl;
    std::cerr << "BVs: " << num_bvs << " allocated." << std::endl;
    std::cerr << "Tris: " << num_tris << " allocated." << std::endl;
    std::cerr << "Vertices: " << num_vertices << " allocated." << std::endl;
  }

829
  return total_mem;
sachinc's avatar
sachinc committed
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
}

template<typename BV>
int BVHModel<BV>::buildTree()
{
  // set BVFitter
  bv_fitter->set(vertices, tri_indices, getModelType());
  // set SplitRule
  bv_splitter->set(vertices, tri_indices, getModelType());

  num_bvs = 1;

  int num_primitives = 0;
  switch(getModelType())
  {
    case BVH_MODEL_TRIANGLES:
      num_primitives = num_tris;
      break;
    case BVH_MODEL_POINTCLOUD:
      num_primitives = num_vertices;
      break;
    default:
      std::cerr << "BVH Error: Model type not supported!" << std::endl;
      return BVH_ERR_UNSUPPORTED_FUNCTION;
  }

Justin Carpentier's avatar
Justin Carpentier committed
856
  for(unsigned int i = 0; i < (unsigned int)num_primitives; ++i)
sachinc's avatar
sachinc committed
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
    primitive_indices[i] = i;
  recursiveBuildTree(0, 0, num_primitives);

  bv_fitter->clear();
  bv_splitter->clear();

  return BVH_OK;
}

template<typename BV>
int BVHModel<BV>::recursiveBuildTree(int bv_id, int first_primitive, int num_primitives)
{
  BVHModelType type = getModelType();
  BVNode<BV>* bvnode = bvs + bv_id;
  unsigned int* cur_primitive_indices = primitive_indices + first_primitive;

  // constructing BV
  BV bv = bv_fitter->fit(cur_primitive_indices, num_primitives);
  bv_splitter->computeRule(bv, cur_primitive_indices, num_primitives);

  bvnode->bv = bv;
  bvnode->first_primitive = first_primitive;
  bvnode->num_primitives = num_primitives;

  if(num_primitives == 1)
  {
Justin Carpentier's avatar
Justin Carpentier committed
883
    bvnode->first_child = -((int)(*cur_primitive_indices) + 1);
sachinc's avatar
sachinc committed
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
  }
  else
  {
    bvnode->first_child = num_bvs;
    num_bvs += 2;

    int c1 = 0;
    for(int i = 0; i < num_primitives; ++i)
    {
      Vec3f p;
      if(type == BVH_MODEL_POINTCLOUD) p = vertices[cur_primitive_indices[i]];
      else if(type == BVH_MODEL_TRIANGLES)
      {
        const Triangle& t = tri_indices[cur_primitive_indices[i]];
        const Vec3f& p1 = vertices[t[0]];
        const Vec3f& p2 = vertices[t[1]];
        const Vec3f& p3 = vertices[t[2]];
901
902

        p = (p1 + p2 + p3) / 3.;
sachinc's avatar
sachinc committed
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
      }
      else
      {
        std::cerr << "BVH Error: Model type not supported!" << std::endl;
        return BVH_ERR_UNSUPPORTED_FUNCTION;
      }


      // loop invariant: up to (but not including) index c1 in group 1,
      // then up to (but not including) index i in group 2
      //
      //  [1] [1] [1] [1] [2] [2] [2] [x] [x] ... [x]
      //                   c1          i
      //
      if(bv_splitter->apply(p)) // in the right side
      {
        // do nothing
      }
      else
      {
        unsigned int temp = cur_primitive_indices[i];
        cur_primitive_indices[i] = cur_primitive_indices[c1];
        cur_primitive_indices[c1] = temp;
        c1++;
      }
    }


    if((c1 == 0) || (c1 == num_primitives)) c1 = num_primitives / 2;

    int num_first_half = c1;

    recursiveBuildTree(bvnode->leftChild(), first_primitive, num_first_half);
    recursiveBuildTree(bvnode->rightChild(), first_primitive + num_first_half, num_primitives - num_first_half);
  }

  return BVH_OK;
}

template<typename BV>
int BVHModel<BV>::refitTree(bool bottomup)
{
  if(bottomup)
    return refitTree_bottomup();
  else
    return refitTree_topdown();
}

template<typename BV>
int BVHModel<BV>::refitTree_bottomup()
{
954
955
956
957
958
  // TODO the recomputation of the BV is done manually, without using
  // bv_fitter. The manual BV recomputation seems bugged. Using bv_fitter
  // seems to correct the bug.
  //bv_fitter->set(vertices, tri_indices, getModelType());

sachinc's avatar
sachinc committed
959
960
  int res = recursiveRefitTree_bottomup(0);

961
  //bv_fitter->clear();
sachinc's avatar
sachinc committed
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
  return res;
}


template<typename BV>
int BVHModel<BV>::recursiveRefitTree_bottomup(int bv_id)
{
  BVNode<BV>* bvnode = bvs + bv_id;
  if(bvnode->isLeaf())
  {
    BVHModelType type = getModelType();
    int primitive_id = -(bvnode->first_child + 1);
    if(type == BVH_MODEL_POINTCLOUD)
    {
      BV bv;

      if(prev_vertices)
      {
        Vec3f v[2];
        v[0] = prev_vertices[primitive_id];
        v[1] = vertices[primitive_id];
        fit(v, 2, bv);
      }
      else
        fit(vertices + primitive_id, 1, bv);

      bvnode->bv = bv;
    }
    else if(type == BVH_MODEL_TRIANGLES)
    {
      BV bv;
      const Triangle& triangle = tri_indices[primitive_id];

      if(prev_vertices)
      {
        Vec3f v[6];
        for(int i = 0; i < 3; ++i)
        {
          v[i] = prev_vertices[triangle[i]];
          v[i + 3] = vertices[triangle[i]];
        }

        fit(v, 6, bv);
      }
      else
      {
1008
1009
1010
        //TODO use bv_fitter to build BV. See comment in refitTree_bottomup
        //unsigned int* cur_primitive_indices = primitive_indices + bvnode->first_primitive;
        //bv = bv_fitter->fit(cur_primitive_indices, bvnode->num_primitives);
sachinc's avatar
sachinc committed
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
        Vec3f v[3];
        for(int i = 0; i < 3; ++i)
        {
          v[i] = vertices[triangle[i]];
        }

        fit(v, 3, bv);
      }

      bvnode->bv = bv;
    }
    else
    {
      std::cerr << "BVH Error: Model type not supported!" << std::endl;
      return BVH_ERR_UNSUPPORTED_FUNCTION;
    }
  }
  else
  {
    recursiveRefitTree_bottomup(bvnode->leftChild());
    recursiveRefitTree_bottomup(bvnode->rightChild());
    bvnode->bv = bvs[bvnode->leftChild()].bv + bvs[bvnode->rightChild()].bv;
1033
1034
1035
    //TODO use bv_fitter to build BV. See comment in refitTree_bottomup
    //unsigned int* cur_primitive_indices = primitive_indices + bvnode->first_primitive;
    //bvnode->bv = bv_fitter->fit(cur_primitive_indices, bvnode->num_primitives);
sachinc's avatar
sachinc committed
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
  }

  return BVH_OK;
}

template<typename BV>
int BVHModel<BV>::refitTree_topdown()
{
  bv_fitter->set(vertices, prev_vertices, tri_indices, getModelType());
  for(int i = 0; i < num_bvs; ++i)
  {
    BV bv = bv_fitter->fit(primitive_indices + bvs[i].first_primitive, bvs[i].num_primitives);
    bvs[i].bv = bv;
  }

  bv_fitter->clear();

  return BVH_OK;
}

jpan's avatar
jpan committed
1056
1057

template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
1058
void BVHModel<OBB>::makeParentRelativeRecurse(int bv_id, Matrix3f& parent_axes, const Vec3f& parent_c)
jpan's avatar
jpan committed
1059
1060
1061
1062
{
  OBB& obb = bvs[bv_id].bv;
  if(!bvs[bv_id].isLeaf())
  {
Joseph Mirabel's avatar
Joseph Mirabel committed
1063
    makeParentRelativeRecurse(bvs[bv_id].first_child, obb.axes, obb.To);
jpan's avatar
jpan committed
1064

Joseph Mirabel's avatar
Joseph Mirabel committed
1065
    makeParentRelativeRecurse(bvs[bv_id].first_child + 1, obb.axes, obb.To);
jpan's avatar
jpan committed
1066
1067
1068
  }

  // make self parent relative
Joseph Mirabel's avatar
Joseph Mirabel committed
1069
1070
  // obb.axes = parent_axes.transpose() * obb.axes;
  obb.axes.applyOnTheLeft(parent_axes.transpose());
jpan's avatar
jpan committed
1071

Joseph Mirabel's avatar
Joseph Mirabel committed
1072
1073
  Vec3f t (obb.To - parent_c);
  obb.To.noalias() = parent_axes.transpose() * t;
jpan's avatar
jpan committed
1074
1075
1076
}

template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
1077
void BVHModel<RSS>::makeParentRelativeRecurse(int bv_id, Matrix3f& parent_axes, const Vec3f& parent_c)
jpan's avatar
jpan committed
1078
1079
1080
1081
{
  RSS& rss = bvs[bv_id].bv;
  if(!bvs[bv_id].isLeaf())
  {
Joseph Mirabel's avatar
Joseph Mirabel committed
1082
    makeParentRelativeRecurse(bvs[bv_id].first_child, rss.axes, rss.Tr);
jpan's avatar
jpan committed
1083

Joseph Mirabel's avatar
Joseph Mirabel committed
1084
    makeParentRelativeRecurse(bvs[bv_id].first_child + 1, rss.axes, rss.Tr);
jpan's avatar
jpan committed
1085
1086
1087
  }

  // make self parent relative
Joseph Mirabel's avatar
Joseph Mirabel committed
1088
1089
  // rss.axes = parent_axes.transpose() * rss.axes;
  rss.axes.applyOnTheLeft(parent_axes.transpose());
jpan's avatar
jpan committed
1090

Joseph Mirabel's avatar
Joseph Mirabel committed
1091
1092
  Vec3f t (rss.Tr - parent_c);
  rss.Tr.noalias() = parent_axes.transpose() * t;
jpan's avatar
jpan committed
1093
1094
1095
}

template<>
Joseph Mirabel's avatar
Joseph Mirabel committed
1096
void BVHModel<OBBRSS>::makeParentRelativeRecurse(int bv_id, Matrix3f& parent_axes, const Vec3f& parent_c)
jpan's avatar
jpan committed
1097
1098
1099
1100
1101
{
  OBB& obb = bvs[bv_id].bv.obb;
  RSS& rss = bvs[bv_id].bv.rss;
  if(!bvs[bv_id].isLeaf())
  {
Joseph Mirabel's avatar
Joseph Mirabel committed
1102
    makeParentRelativeRecurse(bvs[bv_id].first_child, obb.axes, obb.To);
jpan's avatar
jpan committed
1103

Joseph Mirabel's avatar
Joseph Mirabel committed
1104
    makeParentRelativeRecurse(bvs[bv_id].first_child + 1, obb.axes, obb.To);
jpan's avatar
jpan committed
1105
1106
1107
  }

  // make self parent relative
Joseph Mirabel's avatar
Joseph Mirabel committed
1108
  rss.axes.noalias() = parent_axes.transpose() * obb.axes;
1109
  obb.axes = rss.axes;
jpan's avatar
jpan committed
1110

Joseph Mirabel's avatar
Joseph Mirabel committed
1111
  Vec3f t (obb.To - parent_c);
1112
1113
  obb.To.noalias() = parent_axes.transpose() * t;
  rss.Tr = obb.To;
jpan's avatar
jpan committed
1114
1115
1116
1117
}



sachinc's avatar
sachinc committed
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
template<>
NODE_TYPE BVHModel<AABB>::getNodeType() const
{
  return BV_AABB;
}

template<>
NODE_TYPE BVHModel<OBB>::getNodeType() const
{
  return BV_OBB;
}

template<>
NODE_TYPE BVHModel<RSS>::getNodeType() const
{
  return BV_RSS;
}

1136
1137
1138
template<>
NODE_TYPE BVHModel<kIOS>::getNodeType() const
{
1139
  return BV_kIOS;
1140
1141
}

jpan's avatar
   
jpan committed
1142
1143
1144
1145
1146
1147
template<>
NODE_TYPE BVHModel<OBBRSS>::getNodeType() const
{
  return BV_OBBRSS;
}

sachinc's avatar
sachinc committed
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
template<>
NODE_TYPE BVHModel<KDOP<16> >::getNodeType() const
{
  return BV_KDOP16;
}

template<>
NODE_TYPE BVHModel<KDOP<18> >::getNodeType() const
{
  return BV_KDOP18;
}

template<>
NODE_TYPE BVHModel<KDOP<24> >::getNodeType() const
{
  return BV_KDOP24;
}

template class BVHModel<KDOP<16> >;
template class BVHModel<KDOP<18> >;
template class BVHModel<KDOP<24> >;
template class BVHModel<OBB>;
template class BVHModel<AABB>;
template class BVHModel<RSS>;
1172
template class BVHModel<kIOS>;
jpan's avatar
   
jpan committed
1173
template class BVHModel<OBBRSS>;
1174
1175

} // namespace fcl
1176
1177

} // namespace hpp