src/shape/geometric_shapes.cpp
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 
40 
41 namespace hpp {
42 namespace fcl {
43 
44 void ConvexBase::initialize(bool own_storage, Vec3f* points_,
45  unsigned int num_points_) {
46  points = points_;
47  num_points = num_points_;
48  own_storage_ = own_storage;
49  computeCenter();
50 }
51 
52 void ConvexBase::set(bool own_storage_, Vec3f* points_,
53  unsigned int num_points_) {
54  if (own_storage_ && points) delete[] points;
55  initialize(own_storage_, points_, num_points_);
56 }
57 
59  : ShapeBase(other),
60  num_points(other.num_points),
61  center(other.center),
62  own_storage_(other.own_storage_) {
63  if (neighbors) delete[] neighbors;
64  if (nneighbors_) delete[] nneighbors_;
65  if (own_storage_) {
66  if (own_storage_ && points) delete[] points;
67 
68  points = new Vec3f[num_points];
69  std::copy(other.points, other.points + num_points, points);
70  } else
71  points = other.points;
72 
74  std::copy(other.neighbors, other.neighbors + num_points, neighbors);
75 
76  std::size_t c_nneighbors = 0;
77  for (std::size_t i = 0; i < num_points; ++i)
78  c_nneighbors += neighbors[i].count();
79  nneighbors_ = new unsigned int[c_nneighbors];
80  std::copy(other.nneighbors_, other.nneighbors_ + c_nneighbors, nneighbors_);
81 
82  ShapeBase::operator=(*this);
83 }
84 
86  if (neighbors) delete[] neighbors;
87  if (nneighbors_) delete[] nneighbors_;
88  if (own_storage_ && points) delete[] points;
89 }
90 
92  center.setZero();
93  for (std::size_t i = 0; i < num_points; ++i)
94  center += points[i]; // TODO(jcarpent): vectorization
95  center /= num_points;
96 }
97 
99  FCL_REAL l = n.norm();
100  if (l > 0) {
101  FCL_REAL inv_l = 1.0 / l;
102  n *= inv_l;
103  d *= inv_l;
104  } else {
105  n << 1, 0, 0;
106  d = 0;
107  }
108 }
109 
111  FCL_REAL l = n.norm();
112  if (l > 0) {
113  FCL_REAL inv_l = 1.0 / l;
114  n *= inv_l;
115  d *= inv_l;
116  } else {
117  n << 1, 0, 0;
118  d = 0;
119  }
120 }
121 
123  computeBV<AABB>(*this, Transform3f(), aabb_local);
125  aabb_radius = (aabb_local.min_ - aabb_center).norm();
126 }
127 
129  computeBV<AABB>(*this, Transform3f(), aabb_local);
132 }
133 
135  computeBV<AABB>(*this, Transform3f(), aabb_local);
137  aabb_radius = (aabb_local.min_ - aabb_center).norm();
138 }
139 
141  computeBV<AABB>(*this, Transform3f(), aabb_local);
143  aabb_radius = (aabb_local.min_ - aabb_center).norm();
144 }
145 
147  computeBV<AABB>(*this, Transform3f(), aabb_local);
149  aabb_radius = (aabb_local.min_ - aabb_center).norm();
150 }
151 
153  computeBV<AABB>(*this, Transform3f(), aabb_local);
155  aabb_radius = (aabb_local.min_ - aabb_center).norm();
156 }
157 
159  computeBV<AABB>(*this, Transform3f(), aabb_local);
161  aabb_radius = (aabb_local.min_ - aabb_center).norm();
162 }
163 
165  computeBV<AABB>(*this, Transform3f(), aabb_local);
167  aabb_radius = (aabb_local.min_ - aabb_center).norm();
168 }
169 
171  computeBV<AABB>(*this, Transform3f(), aabb_local);
173  aabb_radius = (aabb_local.min_ - aabb_center).norm();
174 }
175 
177  computeBV<AABB>(*this, Transform3f(), aabb_local);
179  aabb_radius = (aabb_local.min_ - aabb_center).norm();
180 }
181 
182 } // namespace fcl
183 
184 } // namespace hpp
hpp::fcl::ConvexBase::computeLocalAABB
void computeLocalAABB()
Compute AABB.
Definition: src/shape/geometric_shapes.cpp:158
hpp::fcl::Vec3f
Eigen::Matrix< FCL_REAL, 3, 1 > Vec3f
Definition: data_types.h:66
hpp::fcl::ConvexBase::neighbors
Neighbors * neighbors
Definition: shape/geometric_shapes.h:655
hpp::fcl::ConvexBase::points
Vec3f * points
An array of the points of the polygon.
Definition: shape/geometric_shapes.h:623
hpp::fcl::Cylinder::computeLocalAABB
void computeLocalAABB()
Compute AABB.
Definition: src/shape/geometric_shapes.cpp:152
hpp::fcl::ConvexBase::ConvexBase
ConvexBase()
Construct an uninitialized convex object Initialization is done with ConvexBase::initialize.
Definition: shape/geometric_shapes.h:664
hpp::fcl::ConvexBase::num_points
unsigned int num_points
Definition: shape/geometric_shapes.h:624
hpp::fcl::AABB::min_
Vec3f min_
The min point in the AABB.
Definition: BV/AABB.h:57
hpp::fcl::ConvexBase::own_storage_
bool own_storage_
Definition: shape/geometric_shapes.h:693
hpp::fcl::ConvexBase::nneighbors_
unsigned int * nneighbors_
Definition: shape/geometric_shapes.h:691
hpp::fcl::Plane::unitNormalTest
void unitNormalTest()
Turn non-unit normal into unit.
Definition: src/shape/geometric_shapes.cpp:110
hpp::fcl::CollisionGeometry::aabb_local
AABB aabb_local
AABB in local coordinate, used for tight AABB when only translation transform.
Definition: collision_object.h:159
geometric_shapes_utility.h
hpp::fcl::Halfspace::unitNormalTest
void unitNormalTest()
Turn non-unit normal into unit.
Definition: src/shape/geometric_shapes.cpp:98
hpp::fcl::ShapeBase::operator=
ShapeBase & operator=(const ShapeBase &other)=default
hpp::fcl::FCL_REAL
double FCL_REAL
Definition: data_types.h:65
hpp::fcl::Sphere::radius
FCL_REAL radius
Radius of the sphere.
Definition: shape/geometric_shapes.h:206
hpp::fcl::TriangleP::computeLocalAABB
void computeLocalAABB()
virtual function of compute AABB in local coordinate
Definition: src/shape/geometric_shapes.cpp:176
hpp::fcl::ConvexBase::~ConvexBase
virtual ~ConvexBase()
Definition: src/shape/geometric_shapes.cpp:85
hpp::fcl::Cone::computeLocalAABB
void computeLocalAABB()
Compute AABB.
Definition: src/shape/geometric_shapes.cpp:146
hpp::fcl::ConvexBase::computeCenter
void computeCenter()
Definition: src/shape/geometric_shapes.cpp:91
hpp::fcl::Plane::computeLocalAABB
void computeLocalAABB()
Compute AABB.
Definition: src/shape/geometric_shapes.cpp:170
hpp::fcl::Box::computeLocalAABB
void computeLocalAABB()
Compute AABB.
Definition: src/shape/geometric_shapes.cpp:122
hpp::fcl::Ellipsoid::computeLocalAABB
void computeLocalAABB()
Compute AABB.
Definition: src/shape/geometric_shapes.cpp:134
hpp
Main namespace.
Definition: broadphase_bruteforce.h:44
hpp::fcl::ConvexBase::set
void set(bool ownStorage, Vec3f *points_, unsigned int num_points_)
Set the points of the convex shape.
Definition: src/shape/geometric_shapes.cpp:52
hpp::fcl::Halfspace::computeLocalAABB
void computeLocalAABB()
Compute AABB.
Definition: src/shape/geometric_shapes.cpp:164
hpp::fcl::Plane::d
FCL_REAL d
Plane offset.
Definition: shape/geometric_shapes.h:851
hpp::fcl::Transform3f
Simple transform class used locally by InterpMotion.
Definition: transform.h:54
hpp::fcl::ConvexBase
Base for convex polytope.
Definition: shape/geometric_shapes.h:581
hpp::fcl::ConvexBase::center
Vec3f center
center of the convex polytope, this is used for collision: center is guaranteed in the internal of th...
Definition: shape/geometric_shapes.h:659
hpp::fcl::ConvexBase::initialize
void initialize(bool ownStorage, Vec3f *points_, unsigned int num_points_)
Initialize the points of the convex shape This also initializes the ConvexBase::center.
Definition: src/shape/geometric_shapes.cpp:44
geometric_shapes.h
hpp::fcl::Plane::n
Vec3f n
Plane normal.
Definition: shape/geometric_shapes.h:848
hpp::fcl::ShapeBase
Base class for all basic geometric shapes.
Definition: shape/geometric_shapes.h:51
hpp::fcl::CollisionGeometry::aabb_radius
FCL_REAL aabb_radius
AABB radius.
Definition: collision_object.h:155
hpp::fcl::Capsule::computeLocalAABB
void computeLocalAABB()
Compute AABB.
Definition: src/shape/geometric_shapes.cpp:140
hpp::fcl::Sphere::computeLocalAABB
void computeLocalAABB()
Compute AABB.
Definition: src/shape/geometric_shapes.cpp:128
hpp::fcl::Halfspace::d
FCL_REAL d
Plane offset.
Definition: shape/geometric_shapes.h:790
hpp::fcl::ConvexBase::Neighbors
Definition: shape/geometric_shapes.h:626
hpp::fcl::Halfspace::n
Vec3f n
Plane normal.
Definition: shape/geometric_shapes.h:787
hpp::fcl::AABB::center
Vec3f center() const
Center of the AABB.
Definition: BV/AABB.h:157
hpp::fcl::CollisionGeometry::aabb_center
Vec3f aabb_center
AABB center in local coordinate.
Definition: collision_object.h:152


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