hpp-fcl: include/hpp/fcl/internal/BV_fitter.h Source File

hpp-fcl 1.7.7 HPP fork of FCL -- The Flexible Collision Library

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 HPP_FCL_BV_FITTER_H
39 #define HPP_FCL_BV_FITTER_H
40
41 #include <hpp/fcl/BVH/BVH_internal.h>
42 #include <hpp/fcl/BV/kIOS.h>
43 #include <hpp/fcl/BV/OBBRSS.h>
44 #include <hpp/fcl/BV/AABB.h>
45 #include <iostream>
46
47 namespace hpp
48 {
49 namespace fcl
50 {
51
53 template<typename BV>
54 void fit(Vec3f* ps, int n, BV& bv)
55 {
56 for(int i = 0; i < n; ++i)
57 {
58 bv += ps[i];
59 }
60 }
61
62 template<>
63 void fit<OBB>(Vec3f* ps, int n, OBB& bv);
64
65 template<>
66 void fit<RSS>(Vec3f* ps, int n, RSS& bv);
67
68 template<>
69 void fit<kIOS>(Vec3f* ps, int n, kIOS& bv);
70
71 template<>
72 void fit<OBBRSS>(Vec3f* ps, int n, OBBRSS& bv);
73
74 template<>
75 void fit<AABB>(Vec3f* ps, int n, AABB& bv);
76
78 template<typename BV>
79 class HPP_FCL_DLLAPI BVFitterTpl
80 {
81 public:
83 virtual ~BVFitterTpl() {}
84
86 void set(Vec3f* vertices_, Triangle* tri_indices_, BVHModelType type_)
87 {
88 vertices = vertices_;
89 prev_vertices = NULL;
90 tri_indices = tri_indices_;
91 type = type_;
92 }
93
95 void set(Vec3f* vertices_, Vec3f* prev_vertices_, Triangle* tri_indices_, BVHModelType type_)
96 {
97 vertices = vertices_;
98 prev_vertices = prev_vertices_;
99 tri_indices = tri_indices_;
100 type = type_;
101 }
102
104 virtual BV fit(unsigned int* primitive_indices, int num_primitives) = 0;
105
107 void clear()
108 {
109 vertices = NULL;
110 prev_vertices = NULL;
111 tri_indices = NULL;
112 type = BVH_MODEL_UNKNOWN;
113 }
114
115 protected:
116
117 Vec3f* vertices;
118 Vec3f* prev_vertices;
119 Triangle* tri_indices;
120 BVHModelType type;
121 };
122
124 template<typename BV>
125 class HPP_FCL_DLLAPI BVFitter : public BVFitterTpl<BV>
126 {
127 typedef BVFitterTpl<BV> Base;
128 public:
131 BV fit(unsigned int* primitive_indices, int num_primitives)
132 {
133 BV bv;
134
135 if(type == BVH_MODEL_TRIANGLES)
136 {
137 for(int i = 0; i < num_primitives; ++i)
138 {
139 Triangle t = tri_indices[primitive_indices[i]];
140 bv += vertices[t[0]];
141 bv += vertices[t[1]];
142 bv += vertices[t[2]];
143
144 if(prev_vertices)
145 {
146 bv += prev_vertices[t[0]];
147 bv += prev_vertices[t[1]];
148 bv += prev_vertices[t[2]];
149 }
150 }
151 }
152 else if(type == BVH_MODEL_POINTCLOUD)
153 {
154 for(int i = 0; i < num_primitives; ++i)
155 {
156 bv += vertices[primitive_indices[i]];
157
158 if(prev_vertices)
159 {
160 bv += prev_vertices[primitive_indices[i]];
161 }
162 }
163 }
164
165 return bv;
166 }
167
168 protected:
169 using Base::vertices;
170 using Base::prev_vertices;
171 using Base::tri_indices;
172 using Base::type;
173 };
174
176 template<>
177 class HPP_FCL_DLLAPI BVFitter<OBB> : public BVFitterTpl<OBB>
178 {
179 public:
182 OBB fit(unsigned int* primitive_indices, int num_primitives);
183 };
184
186 template<>
187 class HPP_FCL_DLLAPI BVFitter<RSS> : public BVFitterTpl<RSS>
188 {
189 public:
192 RSS fit(unsigned int* primitive_indices, int num_primitives);
193 };
194
196 template<>
197 class HPP_FCL_DLLAPI BVFitter<kIOS> : public BVFitterTpl<kIOS>
198 {
199 public:
202 kIOS fit(unsigned int* primitive_indices, int num_primitives);
203 };
204
206 template<>
207 class HPP_FCL_DLLAPI BVFitter<OBBRSS> : public BVFitterTpl<OBBRSS>
208 {
209 public:
212 OBBRSS fit(unsigned int* primitive_indices, int num_primitives);
213 };
214
216 template<>
217 class HPP_FCL_DLLAPI BVFitter<AABB> : public BVFitterTpl<AABB>
218 {
219 public:
222 AABB fit(unsigned int* primitive_indices, int num_primitives);
223 };
224
225 }
226
227 } // namespace hpp
228
229 #endif
AABB.h
OBBRSS.h
BVH_internal.h
hpp::fcl::AABB
A class describing the AABB collision structure, which is a box in 3D space determined by two diagona...
Definition: AABB.h:56
hpp::fcl::BVFitter< AABB >::fit
AABB fit(unsigned int *primitive_indices, int num_primitives)
Compute a bounding volume that fits a set of primitives (points or triangles). The primitive data was...
hpp::fcl::BVFitter< OBB >::fit
OBB fit(unsigned int *primitive_indices, int num_primitives)
Compute a bounding volume that fits a set of primitives (points or triangles). The primitive data was...
hpp::fcl::BVFitter< OBBRSS >::fit
OBBRSS fit(unsigned int *primitive_indices, int num_primitives)
Compute a bounding volume that fits a set of primitives (points or triangles). The primitive data was...
hpp::fcl::BVFitter< RSS >::fit
RSS fit(unsigned int *primitive_indices, int num_primitives)
Compute a bounding volume that fits a set of primitives (points or triangles). The primitive data was...
hpp::fcl::BVFitter< kIOS >::fit
kIOS fit(unsigned int *primitive_indices, int num_primitives)
Compute a bounding volume that fits a set of primitives (points or triangles). The primitive data was...
hpp::fcl::BVFitter
The class for the default algorithm fitting a bounding volume to a set of points.
Definition: BV_fitter.h:126
hpp::fcl::BVFitter::fit
BV fit(unsigned int *primitive_indices, int num_primitives)
Compute a bounding volume that fits a set of primitives (points or triangles). The primitive data was...
Definition: BV_fitter.h:131
hpp::fcl::BVFitterTpl
The class for the default algorithm fitting a bounding volume to a set of points.
Definition: BV_fitter.h:80
hpp::fcl::BVFitterTpl::type
BVHModelType type
Definition: BV_fitter.h:120
hpp::fcl::BVFitterTpl::vertices
Vec3f * vertices
Definition: BV_fitter.h:117
hpp::fcl::BVFitterTpl::set
void set(Vec3f *vertices_, Vec3f *prev_vertices_, Triangle *tri_indices_, BVHModelType type_)
Prepare the geometry primitive data for fitting, for deformable mesh.
Definition: BV_fitter.h:95
hpp::fcl::BVFitterTpl::clear
void clear()
Clear the geometry primitive data.
Definition: BV_fitter.h:107
hpp::fcl::BVFitterTpl::tri_indices
Triangle * tri_indices
Definition: BV_fitter.h:119
hpp::fcl::BVFitterTpl::prev_vertices
Vec3f * prev_vertices
Definition: BV_fitter.h:118
hpp::fcl::BVFitterTpl::fit
virtual BV fit(unsigned int *primitive_indices, int num_primitives)=0
Compute the fitting BV.
hpp::fcl::BVFitterTpl::set
void set(Vec3f *vertices_, Triangle *tri_indices_, BVHModelType type_)
Prepare the geometry primitive data for fitting.
Definition: BV_fitter.h:86
hpp::fcl::BVFitterTpl::~BVFitterTpl
virtual ~BVFitterTpl()
default deconstructor
Definition: BV_fitter.h:83
hpp::fcl::Triangle
Triangle with 3 indices for points.
Definition: data_types.h:75
hpp::fcl::kIOS
A class describing the kIOS collision structure, which is a set of spheres.
Definition: kIOS.h:56
kIOS.h
hpp::fcl::fit< OBBRSS >
void fit< OBBRSS >(Vec3f *ps, int n, OBBRSS &bv)
hpp::fcl::fit< kIOS >
void fit< kIOS >(Vec3f *ps, int n, kIOS &bv)
hpp::fcl::Vec3f
Eigen::Matrix< FCL_REAL, 3, 1 > Vec3f
Definition: data_types.h:67
hpp::fcl::fit< OBB >
void fit< OBB >(Vec3f *ps, int n, OBB &bv)
hpp::fcl::fit
void fit(Vec3f *ps, int n, BV &bv)
Compute a bounding volume that fits a set of n points.
Definition: BV_fitter.h:54
hpp::fcl::BVHModelType
BVHModelType
BVH model type.
Definition: BVH_internal.h:78
hpp::fcl::BVH_MODEL_POINTCLOUD
@ BVH_MODEL_POINTCLOUD
triangle model
Definition: BVH_internal.h:81
hpp::fcl::BVH_MODEL_UNKNOWN
@ BVH_MODEL_UNKNOWN
Definition: BVH_internal.h:79
hpp::fcl::BVH_MODEL_TRIANGLES
@ BVH_MODEL_TRIANGLES
unknown model type
Definition: BVH_internal.h:80
hpp::fcl::fit< AABB >
void fit< AABB >(Vec3f *ps, int n, AABB &bv)
hpp::fcl::fit< RSS >
void fit< RSS >(Vec3f *ps, int n, RSS &bv)
hpp
Main namespace.
Definition: AABB.h:44
hpp::fcl::OBB
Oriented bounding box class.
Definition: OBB.h:55
hpp::fcl::OBBRSS
Class merging the OBB and RSS, can handle collision and distance simultaneously.
Definition: OBBRSS.h:57
hpp::fcl::RSS
A class for rectangle sphere-swept bounding volume.
Definition: RSS.h:56