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);
131  aabb_radius = radius;
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
Simple transform class used locally by InterpMotion.
Definition: transform.h:54
void set(bool ownStorage, Vec3f *points_, unsigned int num_points_)
Set the points of the convex shape.
void computeLocalAABB()
virtual function of compute AABB in local coordinate
Vec3f min_
The min point in the AABB.
Definition: BV/AABB.h:57
Vec3f center() const
Center of the AABB.
Definition: BV/AABB.h:157
Main namespace.
void computeLocalAABB()
Compute AABB.
ConvexBase()
Construct an uninitialized convex object Initialization is done with ConvexBase::initialize.
Base class for all basic geometric shapes.
void computeLocalAABB()
Compute AABB.
AABB aabb_local
AABB in local coordinate, used for tight AABB when only translation transform.
void computeLocalAABB()
Compute AABB.
double FCL_REAL
Definition: data_types.h:65
FCL_REAL aabb_radius
AABB radius.
void initialize(bool ownStorage, Vec3f *points_, unsigned int num_points_)
Initialize the points of the convex shape This also initializes the ConvexBase::center.
void computeLocalAABB()
Compute AABB.
void computeLocalAABB()
Compute AABB.
Base for convex polytope.
void computeLocalAABB()
Compute AABB.
Vec3f aabb_center
AABB center in local coordinate.
void unitNormalTest()
Turn non-unit normal into unit.
ShapeBase & operator=(const ShapeBase &other)=default
void computeLocalAABB()
Compute AABB.
void unitNormalTest()
Turn non-unit normal into unit.
Eigen::Matrix< FCL_REAL, 3, 1 > Vec3f
Definition: data_types.h:66
void computeLocalAABB()
Compute AABB.
void computeLocalAABB()
Compute AABB.
Vec3f center
center of the convex polytope, this is used for collision: center is guaranteed in the internal of th...
Vec3f * points
An array of the points of the polygon.


hpp-fcl
Author(s):
autogenerated on Fri Jun 2 2023 02:39:01