hpp-fcl  1.4.4
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;
113  }
114 
115 protected:
116 
121 };
122 
124 template<typename BV>
125 class BVFitter : public BVFitterTpl<BV>
126 {
127 public:
130  BV fit(unsigned int* primitive_indices, int num_primitives)
131  {
132  BV bv;
133 
134  if(type == BVH_MODEL_TRIANGLES)
135  {
136  for(int i = 0; i < num_primitives; ++i)
137  {
138  Triangle t = tri_indices[primitive_indices[i]];
139  bv += vertices[t[0]];
140  bv += vertices[t[1]];
141  bv += vertices[t[2]];
142 
143  if(prev_vertices)
144  {
145  bv += prev_vertices[t[0]];
146  bv += prev_vertices[t[1]];
147  bv += prev_vertices[t[2]];
148  }
149  }
150  }
151  else if(type == BVH_MODEL_POINTCLOUD)
152  {
153  for(int i = 0; i < num_primitives; ++i)
154  {
155  bv += vertices[primitive_indices[i]];
156 
157  if(prev_vertices)
158  {
159  bv += prev_vertices[primitive_indices[i]];
160  }
161  }
162  }
163 
164  return bv;
165  }
166 
167 protected:
171  using BVFitterTpl<BV>::type;
172 };
173 
175 template<>
176 class BVFitter<OBB> : public BVFitterTpl<OBB>
177 {
178 public:
181  OBB fit(unsigned int* primitive_indices, int num_primitives);
182 };
183 
185 template<>
186 class BVFitter<RSS> : public BVFitterTpl<RSS>
187 {
188 public:
191  RSS fit(unsigned int* primitive_indices, int num_primitives);
192 };
193 
195 template<>
196 class BVFitter<kIOS> : public BVFitterTpl<kIOS>
197 {
198 public:
201  kIOS fit(unsigned int* primitive_indices, int num_primitives);
202 };
203 
205 template<>
206 class BVFitter<OBBRSS> : public BVFitterTpl<OBBRSS>
207 {
208 public:
211  OBBRSS fit(unsigned int* primitive_indices, int num_primitives);
212 };
213 
215 template<>
216 class BVFitter<AABB> : public BVFitterTpl<AABB>
217 {
218 public:
221  AABB fit(unsigned int* primitive_indices, int num_primitives);
222 };
223 
224 }
225 
226 } // namespace hpp
227 
228 #endif
Vec3f * vertices
Definition: BV_fitter.h:117
void fit< RSS >(Vec3f *ps, int n, RSS &bv)
A class for rectangle sphere-swept bounding volume.
Definition: RSS.h:55
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
Oriented bounding box class.
Definition: OBB.h:54
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
Class merging the OBB and RSS, can handle collision and distance simultaneously.
Definition: OBBRSS.h:56
void fit< OBBRSS >(Vec3f *ps, int n, OBBRSS &bv)
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:77
virtual BV fit(unsigned int *primitive_indices, int num_primitives)=0
Compute the fitting BV.
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:73
triangle model
Definition: BVH_internal.h:81
BVHModelType type
Definition: BV_fitter.h:120
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:130