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 
47 namespace hpp {
48 namespace fcl {
49 
51 template <typename BV>
52 void 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 
59 template <>
60 void fit<OBB>(Vec3f* ps, unsigned int n, OBB& bv);
61 
62 template <>
63 void fit<RSS>(Vec3f* ps, unsigned int n, RSS& bv);
64 
65 template <>
66 void fit<kIOS>(Vec3f* ps, unsigned int n, kIOS& bv);
67 
68 template <>
69 void fit<OBBRSS>(Vec3f* ps, unsigned int n, OBBRSS& bv);
70 
71 template <>
72 void fit<AABB>(Vec3f* ps, unsigned int n, AABB& bv);
73 
76 template <typename BV>
77 class HPP_FCL_DLLAPI BVFitterTpl {
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;
110  }
111 
112  protected:
117 };
118 
121 template <typename BV>
122 class HPP_FCL_DLLAPI BVFitter : public BVFitterTpl<BV> {
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 
170 template <>
171 class HPP_FCL_DLLAPI BVFitter<OBB> : public BVFitterTpl<OBB> {
172  public:
176  OBB fit(unsigned int* primitive_indices, unsigned int num_primitives);
177 };
178 
180 template <>
181 class HPP_FCL_DLLAPI BVFitter<RSS> : public BVFitterTpl<RSS> {
182  public:
186  RSS fit(unsigned int* primitive_indices, unsigned int num_primitives);
187 };
188 
190 template <>
191 class HPP_FCL_DLLAPI BVFitter<kIOS> : public BVFitterTpl<kIOS> {
192  public:
196  kIOS fit(unsigned int* primitive_indices, unsigned int num_primitives);
197 };
198 
200 template <>
201 class HPP_FCL_DLLAPI BVFitter<OBBRSS> : public BVFitterTpl<OBBRSS> {
202  public:
206  OBBRSS fit(unsigned int* primitive_indices, unsigned int num_primitives);
207 };
208 
210 template <>
211 class HPP_FCL_DLLAPI BVFitter<AABB> : public BVFitterTpl<AABB> {
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
BVH_internal.h
hpp::fcl::Vec3f
Eigen::Matrix< FCL_REAL, 3, 1 > Vec3f
Definition: data_types.h:66
doxygen_xml_parser.type
type
Definition: doxygen_xml_parser.py:882
hpp::fcl::BVFitterTpl::vertices
Vec3f * vertices
Definition: BV_fitter.h:113
hpp::fcl::BVFitterTpl
The class for the default algorithm fitting a bounding volume to a set of points.
Definition: BV_fitter.h:77
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:92
hpp::fcl::BVFitterTpl::clear
void clear()
Clear the geometry primitive data.
Definition: BV_fitter.h:105
hpp::fcl::kIOS
A class describing the kIOS collision structure, which is a set of spheres.
Definition: kIOS.h:53
hpp::fcl::BVH_MODEL_UNKNOWN
@ BVH_MODEL_UNKNOWN
Definition: BVH_internal.h:81
hpp::fcl::fit
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
hpp::fcl::fit< OBBRSS >
void fit< OBBRSS >(Vec3f *ps, unsigned int n, OBBRSS &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:83
hpp::fcl::BVH_MODEL_TRIANGLES
@ BVH_MODEL_TRIANGLES
unknown model type
Definition: BVH_internal.h:82
hpp::fcl::fit< OBB >
void fit< OBB >(Vec3f *ps, unsigned int n, OBB &bv)
hpp::fcl::BVHModelType
BVHModelType
BVH model type.
Definition: BVH_internal.h:80
hpp
Main namespace.
Definition: broadphase_bruteforce.h:44
hpp::fcl::OBB
Oriented bounding box class.
Definition: include/hpp/fcl/BV/OBB.h:52
t
tuple t
hpp::fcl::BVFitterTpl::tri_indices
Triangle * tri_indices
Definition: BV_fitter.h:115
hpp::fcl::AABB
A class describing the AABB collision structure, which is a box in 3D space determined by two diagona...
Definition: BV/AABB.h:54
hpp::fcl::BVFitter::Base
BVFitterTpl< BV > Base
Definition: BV_fitter.h:123
hpp::fcl::BVFitter
The class for the default algorithm fitting a bounding volume to a set of points.
Definition: BVH/BVH_model.h:57
hpp::fcl::BVFitter::fit
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
hpp::fcl::RSS
A class for rectangle sphere-swept bounding volume.
Definition: BV/RSS.h:53
hpp::fcl::fit< kIOS >
void fit< kIOS >(Vec3f *ps, unsigned int n, kIOS &bv)
OBBRSS.h
AABB.h
hpp::fcl::fit< AABB >
void fit< AABB >(Vec3f *ps, unsigned int n, AABB &bv)
hpp::fcl::Triangle
Triangle with 3 indices for points.
Definition: data_types.h:96
hpp::fcl::OBBRSS
Class merging the OBB and RSS, can handle collision and distance simultaneously.
Definition: BV/OBBRSS.h:54
hpp::fcl::BVH_MODEL_POINTCLOUD
@ BVH_MODEL_POINTCLOUD
triangle model
Definition: BVH_internal.h:83
hpp::fcl::BVFitterTpl::prev_vertices
Vec3f * prev_vertices
Definition: BV_fitter.h:114
kIOS.h
hpp::fcl::fit< RSS >
void fit< RSS >(Vec3f *ps, unsigned int n, RSS &bv)
hpp::fcl::BVFitterTpl::type
BVHModelType type
Definition: BV_fitter.h:116
hpp::fcl::BVFitterTpl::~BVFitterTpl
virtual ~BVFitterTpl()
default deconstructor
Definition: BV_fitter.h:80


hpp-fcl
Author(s):
autogenerated on Fri Aug 2 2024 02:45:13