hpp-fcl 2.4.1
HPP 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 HPP_FCL_BV_FITTER_H
39#define HPP_FCL_BV_FITTER_H
40
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
47namespace hpp {
48namespace fcl {
49
51template <typename BV>
52void fit(Vec3f* ps, unsigned int n, BV& bv) {
53 for (unsigned int i = 0; i < n; ++i) // TODO(jcarpent): vectorize
54 {
55 bv += ps[i];
56 }
57}
58
59template <>
60void fit<OBB>(Vec3f* ps, unsigned int n, OBB& bv);
61
62template <>
63void fit<RSS>(Vec3f* ps, unsigned int n, RSS& bv);
64
65template <>
66void fit<kIOS>(Vec3f* ps, unsigned int n, kIOS& bv);
67
68template <>
69void fit<OBBRSS>(Vec3f* ps, unsigned int n, OBBRSS& bv);
70
71template <>
72void fit<AABB>(Vec3f* ps, unsigned int n, AABB& bv);
73
76template <typename BV>
78 public:
80 virtual ~BVFitterTpl() {}
81
83 void set(Vec3f* vertices_, Triangle* tri_indices_, BVHModelType type_) {
84 vertices = vertices_;
85 prev_vertices = NULL;
86 tri_indices = tri_indices_;
87 type = type_;
88 }
89
92 void set(Vec3f* vertices_, Vec3f* prev_vertices_, Triangle* tri_indices_,
93 BVHModelType type_) {
94 vertices = vertices_;
95 prev_vertices = prev_vertices_;
96 tri_indices = tri_indices_;
97 type = type_;
98 }
99
101 virtual BV fit(unsigned int* primitive_indices,
102 unsigned int num_primitives) = 0;
103
105 void clear() {
106 vertices = NULL;
107 prev_vertices = NULL;
108 tri_indices = NULL;
109 type = BVH_MODEL_UNKNOWN;
110 }
111
112 protected:
117};
118
121template <typename BV>
123 typedef BVFitterTpl<BV> Base;
124
125 public:
129 BV fit(unsigned int* primitive_indices, unsigned int num_primitives) {
130 BV bv;
131
132 if (type == BVH_MODEL_TRIANGLES)
133 {
134 for (unsigned int i = 0; i < num_primitives; ++i) {
135 Triangle t = tri_indices[primitive_indices[i]];
136 bv += vertices[t[0]];
137 bv += vertices[t[1]];
138 bv += vertices[t[2]];
139
140 if (prev_vertices)
141 {
142 bv += prev_vertices[t[0]];
143 bv += prev_vertices[t[1]];
144 bv += prev_vertices[t[2]];
145 }
146 }
147 } else if (type == BVH_MODEL_POINTCLOUD)
148 {
149 for (unsigned int i = 0; i < num_primitives; ++i) {
150 bv += vertices[primitive_indices[i]];
151
152 if (prev_vertices)
153 {
154 bv += prev_vertices[primitive_indices[i]];
155 }
156 }
157 }
158
159 return bv;
160 }
161
162 protected:
163 using Base::prev_vertices;
164 using Base::tri_indices;
165 using Base::type;
166 using Base::vertices;
167};
168
170template <>
172 public:
176 OBB fit(unsigned int* primitive_indices, unsigned int num_primitives);
177};
178
180template <>
182 public:
186 RSS fit(unsigned int* primitive_indices, unsigned int num_primitives);
187};
188
190template <>
192 public:
196 kIOS fit(unsigned int* primitive_indices, unsigned int num_primitives);
197};
198
200template <>
201class HPP_FCL_DLLAPI BVFitter<OBBRSS> : public BVFitterTpl<OBBRSS> {
202 public:
206 OBBRSS fit(unsigned int* primitive_indices, unsigned int num_primitives);
207};
208
210template <>
212 public:
216 AABB fit(unsigned int* primitive_indices, unsigned int num_primitives);
217};
218
219} // namespace fcl
220
221} // namespace hpp
222
223#endif
A class describing the AABB collision structure, which is a box in 3D space determined by two diagona...
Definition: AABB.h:54
The class for the default algorithm fitting a bounding volume to a set of points.
Definition: BV_fitter.h:77
BVHModelType type
Definition: BV_fitter.h:116
Vec3f * vertices
Definition: BV_fitter.h:113
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:92
void clear()
Clear the geometry primitive data.
Definition: BV_fitter.h:105
Triangle * tri_indices
Definition: BV_fitter.h:115
Vec3f * prev_vertices
Definition: BV_fitter.h:114
void set(Vec3f *vertices_, Triangle *tri_indices_, BVHModelType type_)
Prepare the geometry primitive data for fitting.
Definition: BV_fitter.h:83
virtual BV fit(unsigned int *primitive_indices, unsigned int num_primitives)=0
Compute the fitting BV.
virtual ~BVFitterTpl()
default deconstructor
Definition: BV_fitter.h:80
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:122
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:129
Triangle with 3 indices for points.
Definition: data_types.h:96
A class describing the kIOS collision structure, which is a set of spheres.
Definition: kIOS.h:53
#define HPP_FCL_DLLAPI
Definition: config.hh:88
void fit< RSS >(Vec3f *ps, unsigned int n, RSS &bv)
Eigen::Matrix< FCL_REAL, 3, 1 > Vec3f
Definition: data_types.h:66
BVHModelType
BVH model type.
Definition: BVH_internal.h:80
@ BVH_MODEL_POINTCLOUD
triangle model
Definition: BVH_internal.h:83
@ BVH_MODEL_UNKNOWN
Definition: BVH_internal.h:81
@ BVH_MODEL_TRIANGLES
unknown model type
Definition: BVH_internal.h:82
void fit(Vec3f *ps, unsigned int n, BV &bv)
Compute a bounding volume that fits a set of n points.
Definition: BV_fitter.h:52
void fit< AABB >(Vec3f *ps, unsigned int n, AABB &bv)
void fit< OBB >(Vec3f *ps, unsigned int n, OBB &bv)
void fit< OBBRSS >(Vec3f *ps, unsigned int n, OBBRSS &bv)
void fit< kIOS >(Vec3f *ps, unsigned int n, kIOS &bv)
Main namespace.
Definition: broadphase_bruteforce.h:44
Class merging the OBB and RSS, can handle collision and distance simultaneously.
Definition: OBBRSS.h:54
Oriented bounding box class.
Definition: OBB.h:52
A class for rectangle sphere-swept bounding volume.
Definition: RSS.h:53