GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: src/shape/geometric_shapes.cpp Lines: 63 102 61.8 %
Date: 2024-02-09 12:57:42 Branches: 36 126 28.6 %

Line Branch Exec Source
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
36
/** \author Jia Pan */
37
38
#include <hpp/fcl/shape/geometric_shapes.h>
39
#include <hpp/fcl/shape/geometric_shapes_utility.h>
40
41
namespace hpp {
42
namespace fcl {
43
44
55672
void ConvexBase::initialize(bool own_storage, Vec3f* points_,
45
                            unsigned int num_points_) {
46
55672
  points = points_;
47
55672
  num_points = num_points_;
48
55672
  own_storage_ = own_storage;
49
55672
  computeCenter();
50
55672
}
51
52
55656
void ConvexBase::set(bool own_storage_, Vec3f* points_,
53
                     unsigned int num_points_) {
54

55656
  if (own_storage_ && points) delete[] points;
55
55656
  initialize(own_storage_, points_, num_points_);
56
55656
}
57
58
ConvexBase::ConvexBase(const ConvexBase& other)
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
73
  neighbors = new Neighbors[num_points];
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
85
111348
ConvexBase::~ConvexBase() {
86

111348
  if (neighbors) delete[] neighbors;
87

111348
  if (nneighbors_) delete[] nneighbors_;
88

111348
  if (own_storage_ && points) delete[] points;
89
}
90
91
55672
void ConvexBase::computeCenter() {
92
55672
  center.setZero();
93
501067
  for (std::size_t i = 0; i < num_points; ++i)
94
445395
    center += points[i];  // TODO(jcarpent): vectorization
95
55672
  center /= num_points;
96
55672
}
97
98
258
void Halfspace::unitNormalTest() {
99
258
  FCL_REAL l = n.norm();
100
258
  if (l > 0) {
101
256
    FCL_REAL inv_l = 1.0 / l;
102
256
    n *= inv_l;
103
256
    d *= inv_l;
104
  } else {
105

2
    n << 1, 0, 0;
106
2
    d = 0;
107
  }
108
258
}
109
110
250
void Plane::unitNormalTest() {
111
250
  FCL_REAL l = n.norm();
112
250
  if (l > 0) {
113
248
    FCL_REAL inv_l = 1.0 / l;
114
248
    n *= inv_l;
115
248
    d *= inv_l;
116
  } else {
117

2
    n << 1, 0, 0;
118
2
    d = 0;
119
  }
120
250
}
121
122
14111
void Box::computeLocalAABB() {
123
14111
  computeBV<AABB>(*this, Transform3f(), aabb_local);
124
14111
  aabb_center = aabb_local.center();
125
14111
  aabb_radius = (aabb_local.min_ - aabb_center).norm();
126
14111
}
127
128
16917
void Sphere::computeLocalAABB() {
129
16917
  computeBV<AABB>(*this, Transform3f(), aabb_local);
130
16917
  aabb_center = aabb_local.center();
131
16917
  aabb_radius = radius;
132
16917
}
133
134
void Ellipsoid::computeLocalAABB() {
135
  computeBV<AABB>(*this, Transform3f(), aabb_local);
136
  aabb_center = aabb_local.center();
137
  aabb_radius = (aabb_local.min_ - aabb_center).norm();
138
}
139
140
10010
void Capsule::computeLocalAABB() {
141
10010
  computeBV<AABB>(*this, Transform3f(), aabb_local);
142
10010
  aabb_center = aabb_local.center();
143
10010
  aabb_radius = (aabb_local.min_ - aabb_center).norm();
144
10010
}
145
146
void Cone::computeLocalAABB() {
147
  computeBV<AABB>(*this, Transform3f(), aabb_local);
148
  aabb_center = aabb_local.center();
149
  aabb_radius = (aabb_local.min_ - aabb_center).norm();
150
}
151
152
8912
void Cylinder::computeLocalAABB() {
153
8912
  computeBV<AABB>(*this, Transform3f(), aabb_local);
154
8912
  aabb_center = aabb_local.center();
155
8912
  aabb_radius = (aabb_local.min_ - aabb_center).norm();
156
8912
}
157
158
1
void ConvexBase::computeLocalAABB() {
159
1
  computeBV<AABB>(*this, Transform3f(), aabb_local);
160
1
  aabb_center = aabb_local.center();
161
1
  aabb_radius = (aabb_local.min_ - aabb_center).norm();
162
1
}
163
164
void Halfspace::computeLocalAABB() {
165
  computeBV<AABB>(*this, Transform3f(), aabb_local);
166
  aabb_center = aabb_local.center();
167
  aabb_radius = (aabb_local.min_ - aabb_center).norm();
168
}
169
170
void Plane::computeLocalAABB() {
171
  computeBV<AABB>(*this, Transform3f(), aabb_local);
172
  aabb_center = aabb_local.center();
173
  aabb_radius = (aabb_local.min_ - aabb_center).norm();
174
}
175
176
void TriangleP::computeLocalAABB() {
177
  computeBV<AABB>(*this, Transform3f(), aabb_local);
178
  aabb_center = aabb_local.center();
179
  aabb_radius = (aabb_local.min_ - aabb_center).norm();
180
}
181
182
}  // namespace fcl
183
184
}  // namespace hpp