coal 3.0.1
Coal, The Collision Detection Library. Previously known as HPP-FCL, fork of FCL -- The Flexible Collision Library
Loading...
Searching...
No Matches
BV_fitter.h
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 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * * Neither the name of Open Source Robotics Foundation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
38#ifndef COAL_BV_FITTER_H
39#define COAL_BV_FITTER_H
40
42#include "coal/BV/kIOS.h"
43#include "coal/BV/OBBRSS.h"
44#include "coal/BV/AABB.h"
45#include <iostream>
46
47namespace coal {
48
50template <typename BV>
51void fit(Vec3s* ps, unsigned int n, BV& bv) {
52 for (unsigned int i = 0; i < n; ++i) // TODO(jcarpent): vectorize
53 {
54 bv += ps[i];
55 }
56}
57
58template <>
59void fit<OBB>(Vec3s* ps, unsigned int n, OBB& bv);
60
61template <>
62void fit<RSS>(Vec3s* ps, unsigned int n, RSS& bv);
63
64template <>
65void fit<kIOS>(Vec3s* ps, unsigned int n, kIOS& bv);
66
67template <>
68void fit<OBBRSS>(Vec3s* ps, unsigned int n, OBBRSS& bv);
69
70template <>
71void fit<AABB>(Vec3s* ps, unsigned int n, AABB& bv);
72
75template <typename BV>
77 public:
79 virtual ~BVFitterTpl() {}
80
82 void set(Vec3s* vertices_, Triangle32* tri_indices_, BVHModelType type_) {
83 vertices = vertices_;
84 prev_vertices = NULL;
85 tri_indices = tri_indices_;
86 type = type_;
87 }
88
91 void set(Vec3s* vertices_, Vec3s* prev_vertices_, Triangle32* tri_indices_,
92 BVHModelType type_) {
93 vertices = vertices_;
94 prev_vertices = prev_vertices_;
95 tri_indices = tri_indices_;
96 type = type_;
97 }
98
100 virtual BV fit(unsigned int* primitive_indices,
101 unsigned int num_primitives) = 0;
102
104 void clear() {
105 vertices = NULL;
106 prev_vertices = NULL;
107 tri_indices = NULL;
108 type = BVH_MODEL_UNKNOWN;
109 }
110
111 protected:
116};
117
120template <typename BV>
121class COAL_DLLAPI BVFitter : public BVFitterTpl<BV> {
122 typedef BVFitterTpl<BV> Base;
123
124 public:
128 BV fit(unsigned int* primitive_indices, unsigned int num_primitives) {
129 BV bv;
130
131 if (type == BVH_MODEL_TRIANGLES)
132 {
133 for (unsigned int i = 0; i < num_primitives; ++i) {
134 Triangle32 t = tri_indices[primitive_indices[i]];
135 bv += vertices[t[0]];
136 bv += vertices[t[1]];
137 bv += vertices[t[2]];
138
139 if (prev_vertices)
140 {
141 bv += prev_vertices[t[0]];
142 bv += prev_vertices[t[1]];
143 bv += prev_vertices[t[2]];
144 }
145 }
146 } else if (type == BVH_MODEL_POINTCLOUD)
147 {
148 for (unsigned int i = 0; i < num_primitives; ++i) {
149 bv += vertices[primitive_indices[i]];
150
151 if (prev_vertices)
152 {
153 bv += prev_vertices[primitive_indices[i]];
154 }
155 }
156 }
157
158 return bv;
159 }
160
161 protected:
162 using Base::prev_vertices;
163 using Base::tri_indices;
164 using Base::type;
165 using Base::vertices;
166};
167
169template <>
170class COAL_DLLAPI BVFitter<OBB> : public BVFitterTpl<OBB> {
171 public:
175 OBB fit(unsigned int* primitive_indices, unsigned int num_primitives);
176};
177
179template <>
180class COAL_DLLAPI BVFitter<RSS> : public BVFitterTpl<RSS> {
181 public:
185 RSS fit(unsigned int* primitive_indices, unsigned int num_primitives);
186};
187
189template <>
190class COAL_DLLAPI BVFitter<kIOS> : public BVFitterTpl<kIOS> {
191 public:
195 kIOS fit(unsigned int* primitive_indices, unsigned int num_primitives);
196};
197
199template <>
200class COAL_DLLAPI BVFitter<OBBRSS> : public BVFitterTpl<OBBRSS> {
201 public:
205 OBBRSS fit(unsigned int* primitive_indices, unsigned int num_primitives);
206};
207
209template <>
210class COAL_DLLAPI BVFitter<AABB> : public BVFitterTpl<AABB> {
211 public:
215 AABB fit(unsigned int* primitive_indices, unsigned int num_primitives);
216};
217
218} // namespace coal
219
220#endif
A class describing the AABB collision structure, which is a box in 3D space determined by two diagona...
Definition AABB.h:55
The class for the default algorithm fitting a bounding volume to a set of points.
Definition BV_fitter.h:76
void set(Vec3s *vertices_, Vec3s *prev_vertices_, Triangle32 *tri_indices_, BVHModelType type_)
Prepare the geometry primitive data for fitting, for deformable mesh.
Definition BV_fitter.h:91
BVHModelType type
Definition BV_fitter.h:115
Vec3s * prev_vertices
Definition BV_fitter.h:113
void clear()
Clear the geometry primitive data.
Definition BV_fitter.h:104
void set(Vec3s *vertices_, Triangle32 *tri_indices_, BVHModelType type_)
Prepare the geometry primitive data for fitting.
Definition BV_fitter.h:82
virtual BV fit(unsigned int *primitive_indices, unsigned int num_primitives)=0
Compute the fitting BV.
Triangle32 * tri_indices
Definition BV_fitter.h:114
Vec3s * vertices
Definition BV_fitter.h:112
virtual ~BVFitterTpl()
default deconstructor
Definition BV_fitter.h:79
AABB fit(unsigned int *primitive_indices, unsigned int num_primitives)
Compute a bounding volume that fits a set of primitives (points or triangles). The primitive data was...
OBBRSS fit(unsigned int *primitive_indices, unsigned int num_primitives)
Compute a bounding volume that fits a set of primitives (points or triangles). The primitive data was...
OBB fit(unsigned int *primitive_indices, unsigned int num_primitives)
Compute a bounding volume that fits a set of primitives (points or triangles). The primitive data was...
RSS fit(unsigned int *primitive_indices, unsigned int num_primitives)
Compute a bounding volume that fits a set of primitives (points or triangles). The primitive data was...
kIOS fit(unsigned int *primitive_indices, unsigned int num_primitives)
Compute a bounding volume that fits a set of primitives (points or triangles). The primitive data was...
The class for the default algorithm fitting a bounding volume to a set of points.
Definition BV_fitter.h:121
BV fit(unsigned int *primitive_indices, unsigned int num_primitives)
Compute a bounding volume that fits a set of primitives (points or triangles). The primitive data was...
Definition BV_fitter.h:128
Triangle with 3 indices for points.
Definition data_types.h:122
A class describing the kIOS collision structure, which is a set of spheres.
Definition kIOS.h:52
#define COAL_DLLAPI
Definition config.hh:88
Main namespace.
Definition broadphase_bruteforce.h:44
BVHModelType
BVH model type.
Definition BVH_internal.h:79
@ BVH_MODEL_POINTCLOUD
triangle model
Definition BVH_internal.h:82
@ BVH_MODEL_TRIANGLES
unknown model type
Definition BVH_internal.h:81
@ BVH_MODEL_UNKNOWN
Definition BVH_internal.h:80
void fit< OBB >(Vec3s *ps, unsigned int n, OBB &bv)
void fit< kIOS >(Vec3s *ps, unsigned int n, kIOS &bv)
void fit< RSS >(Vec3s *ps, unsigned int n, RSS &bv)
void fit(Vec3s *ps, unsigned int n, BV &bv)
Compute a bounding volume that fits a set of n points.
Definition BV_fitter.h:51
Eigen::Matrix< Scalar, 3, 1 > Vec3s
Definition data_types.h:70
void fit< AABB >(Vec3s *ps, unsigned int n, AABB &bv)
void fit< OBBRSS >(Vec3s *ps, unsigned int n, OBBRSS &bv)
Class merging the OBB and RSS, can handle collision and distance simultaneously.
Definition OBBRSS.h:53
Oriented bounding box class.
Definition OBB.h:51
A class for rectangle sphere-swept bounding volume.
Definition RSS.h:53