37#ifndef HPP_FCL_SHAPE_CONVEX_HXX
38#define HPP_FCL_SHAPE_CONVEX_HXX
46template <
typename PolygonT>
48 unsigned int num_points_, PolygonT* polygons_,
49 unsigned int num_polygons_)
50 :
ConvexBase(), polygons(polygons_), num_polygons(num_polygons_) {
55template <
typename PolygonT>
58 polygons(other.polygons),
59 num_polygons(other.num_polygons) {
66template <
typename PolygonT>
68 if (own_storage_)
delete[] polygons;
71template <
typename PolygonT>
73 unsigned int num_points_, PolygonT* polygons_,
74 unsigned int num_polygons_) {
75 if (own_storage_)
delete[] polygons;
78 num_polygons = num_polygons_;
84template <
typename PolygonT>
87 std::copy(points, points + num_points, cloned_points);
89 PolygonT* cloned_polygons =
new PolygonT[num_polygons];
90 std::copy(polygons, polygons + num_polygons, cloned_polygons);
92 Convex* copy_ptr =
new Convex(
true, cloned_points, num_points,
93 cloned_polygons, num_polygons);
95 copy_ptr->ShapeBase::operator=(*this);
99template <
typename PolygonT>
101 typedef typename PolygonT::size_type size_type;
102 typedef typename PolygonT::index_type index_type;
107 C_canonical << 1 / 60.0, 1 / 120.0, 1 / 120.0, 1 / 120.0, 1 / 60.0, 1 / 120.0,
108 1 / 120.0, 1 / 120.0, 1 / 60.0;
110 for (
unsigned int i = 0; i < num_polygons; ++i) {
111 const PolygonT& polygon = polygons[i];
114 Vec3f plane_center(0, 0, 0);
115 for (size_type j = 0; j < polygon.size(); ++j)
116 plane_center += points[polygon[(index_type)j]];
117 plane_center /= polygon.size();
121 const Vec3f& v3 = plane_center;
122 for (size_type j = 0; j < polygon.size(); ++j) {
123 index_type e_first = polygon[
static_cast<index_type
>(j)];
124 index_type e_second =
125 polygon[
static_cast<index_type
>((j + 1) % polygon.size())];
126 const Vec3f& v1 = points[e_first];
127 const Vec3f& v2 = points[e_second];
129 A << v1.transpose(), v2.transpose(),
131 C += A.transpose() * C_canonical * A * (v1.cross(v2)).dot(v3);
135 return C.trace() * Matrix3f::Identity() - C;
138template <
typename PolygonT>
140 typedef typename PolygonT::size_type size_type;
141 typedef typename PolygonT::index_type index_type;
145 for (
unsigned int i = 0; i < num_polygons; ++i) {
146 const PolygonT& polygon = polygons[i];
148 Vec3f plane_center(0, 0, 0);
149 for (size_type j = 0; j < polygon.size(); ++j)
150 plane_center += points[polygon[(index_type)j]];
151 plane_center /= polygon.size();
155 const Vec3f& v3 = plane_center;
156 for (size_type j = 0; j < polygon.size(); ++j) {
157 index_type e_first = polygon[
static_cast<index_type
>(j)];
158 index_type e_second =
159 polygon[
static_cast<index_type
>((j + 1) % polygon.size())];
160 const Vec3f& v1 = points[e_first];
161 const Vec3f& v2 = points[e_second];
162 FCL_REAL d_six_vol = (v1.cross(v2)).dot(v3);
164 com += (points[e_first] + points[e_second] + plane_center) * d_six_vol;
168 return com / (vol * 4);
171template <
typename PolygonT>
173 typedef typename PolygonT::size_type size_type;
174 typedef typename PolygonT::index_type index_type;
177 for (
unsigned int i = 0; i < num_polygons; ++i) {
178 const PolygonT& polygon = polygons[i];
181 Vec3f plane_center(0, 0, 0);
182 for (size_type j = 0; j < polygon.size(); ++j)
183 plane_center += points[polygon[(index_type)j]];
184 plane_center /= polygon.size();
188 const Vec3f& v3 = plane_center;
189 for (size_type j = 0; j < polygon.size(); ++j) {
190 index_type e_first = polygon[
static_cast<index_type
>(j)];
191 index_type e_second =
192 polygon[
static_cast<index_type
>((j + 1) % polygon.size())];
193 const Vec3f& v1 = points[e_first];
194 const Vec3f& v2 = points[e_second];
195 FCL_REAL d_six_vol = (v1.cross(v2)).dot(v3);
203template <
typename PolygonT>
205 if (neighbors)
delete[] neighbors;
208 typedef typename PolygonT::size_type size_type;
209 typedef typename PolygonT::index_type index_type;
210 std::vector<std::set<index_type> > nneighbors(num_points);
211 unsigned int c_nneighbors = 0;
213 for (
unsigned int l = 0; l < num_polygons; ++l) {
214 const PolygonT& polygon = polygons[l];
215 const size_type n = polygon.size();
217 for (size_type j = 0; j < polygon.size(); ++j) {
218 size_type i = (j == 0) ? n - 1 : j - 1;
219 size_type k = (j == n - 1) ? 0 : j + 1;
220 index_type pi = polygon[(index_type)i], pj = polygon[(index_type)j],
221 pk = polygon[(index_type)k];
223 if (nneighbors[pj].count(pi) == 0) {
225 nneighbors[pj].insert(pi);
227 if (nneighbors[pj].count(pk) == 0) {
229 nneighbors[pj].insert(pk);
234 if (nneighbors_)
delete[] nneighbors_;
235 nneighbors_ =
new unsigned int[c_nneighbors];
237 unsigned int* p_nneighbors = nneighbors_;
238 for (
unsigned int i = 0; i < num_points; ++i) {
240 if (nneighbors[i].size() >= (std::numeric_limits<unsigned char>::max)())
242 n.
count_ = (
unsigned char)nneighbors[i].size();
245 std::copy(nneighbors[i].begin(), nneighbors[i].end(), p_nneighbors);
247 assert(p_nneighbors == nneighbors_ + c_nneighbors);
Base for convex polytope.
Definition: geometric_shapes.h:581
Convex polytope.
Definition: convex.h:50
virtual Convex< PolygonT > * clone() const
 
Definition: convex.hxx:85
void set(bool ownStorage, Vec3f *points, unsigned int num_points, PolygonT *polygons, unsigned int num_polygons)
Set the current Convex from a list of points and polygons.
Definition: convex.hxx:72
Convex()
Construct an uninitialized convex object.
Definition: convex.h:53
~Convex()
Definition: convex.hxx:67
unsigned int num_polygons
Definition: convex.h:77
Vec3f computeCOM() const
compute center of mass
Definition: convex.hxx:139
PolygonT * polygons
An array of PolygonT object. PolygonT should contains a list of vertices for each polygon,...
Definition: convex.h:76
FCL_REAL computeVolume() const
compute the volume
Definition: convex.hxx:172
void fillNeighbors()
Definition: convex.hxx:204
Matrix3f computeMomentofInertia() const
based on http://number-none.com/blow/inertia/bb_inertia.doc
Definition: convex.hxx:100
#define HPP_FCL_THROW_PRETTY(message, exception)
Definition: fwd.hh:57
void initialize(bool ownStorage, Vec3f *points_, unsigned int num_points_)
Initialize the points of the convex shape This also initializes the ConvexBase::center.
bool own_storage_
Definition: geometric_shapes.h:693
unsigned int * n_
Definition: geometric_shapes.h:628
void set(bool ownStorage, Vec3f *points_, unsigned int num_points_)
Set the points of the convex shape.
unsigned char count_
Definition: geometric_shapes.h:627
Eigen::Matrix< FCL_REAL, 3, 3 > Matrix3f
Definition: data_types.h:68
Eigen::Matrix< FCL_REAL, 3, 1 > Vec3f
Definition: data_types.h:66
double FCL_REAL
Definition: data_types.h:65
Main namespace.
Definition: broadphase_bruteforce.h:44
Definition: geometric_shapes.h:626