hpp-fcl  1.7.5
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 
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>
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 
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<>
178 {
179 public:
182  OBB fit(unsigned int* primitive_indices, int num_primitives);
183 };
184 
186 template<>
188 {
189 public:
192  RSS fit(unsigned int* primitive_indices, int num_primitives);
193 };
194 
196 template<>
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<>
218 {
219 public:
222  AABB fit(unsigned int* primitive_indices, int num_primitives);
223 };
224 
225 }
226 
227 } // namespace hpp
228 
229 #endif
Vec3f * vertices
Definition: BV_fitter.h:117
void fit< RSS >(Vec3f *ps, int n, RSS &bv)
void fit< AABB >(Vec3f *ps, int n, AABB &bv)
Main namespace.
Definition: AABB.h:43
void fit< OBB >(Vec3f *ps, int n, OBB &bv)
Definition: BVH_internal.h:79
Triangle * tri_indices
Definition: BV_fitter.h:119
The class for the default algorithm fitting a bounding volume to a set of points. ...
Definition: BV_fitter.h:79
void clear()
Clear the geometry primitive data.
Definition: BV_fitter.h:107
A class describing the kIOS collision structure, which is a set of spheres.
Definition: kIOS.h:55
virtual ~BVFitterTpl()
default deconstructor
Definition: BV_fitter.h:83
unknown model type
Definition: BVH_internal.h:80
void fit(Vec3f *ps, int n, BV &bv)
Compute a bounding volume that fits a set of n points.
Definition: BV_fitter.h:54
void fit< OBBRSS >(Vec3f *ps, int n, OBBRSS &bv)
A class for rectangle sphere-swept bounding volume.
Definition: RSS.h:55
BVHModelType
BVH model type.
Definition: BVH_internal.h:77
A class describing the AABB collision structure, which is a box in 3D space determined by two diagona...
Definition: AABB.h:55
void fit< kIOS >(Vec3f *ps, int n, kIOS &bv)
Triangle with 3 indices for points.
Definition: data_types.h:74
Vec3f * prev_vertices
Definition: BV_fitter.h:118
The class for the default algorithm fitting a bounding volume to a set of points. ...
Definition: BVH_model.h:58
Eigen::Matrix< FCL_REAL, 3, 1 > Vec3f
Definition: data_types.h:67
triangle model
Definition: BVH_internal.h:81
Class merging the OBB and RSS, can handle collision and distance simultaneously.
Definition: OBBRSS.h:56
BVHModelType type
Definition: BV_fitter.h:120
#define HPP_FCL_DLLAPI
Definition: config.hh:64
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
Oriented bounding box class.
Definition: OBB.h:54