GCC Code Coverage Report


Directory: ./
File: src/body.cc
Date: 2025-05-04 12:09:19
Exec Total Coverage
Lines: 19 68 27.9%
Branches: 12 114 10.5%

Line Branch Exec Source
1 //
2 // Copyright (c) 2016 CNRS
3 // Author: NMansard
4 //
5 //
6
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are
9 // met:
10 //
11 // 1. Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 //
14 // 2. Redistributions in binary form must reproduce the above copyright
15 // notice, this list of conditions and the following disclaimer in the
16 // documentation and/or other materials provided with the distribution.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
29 // DAMAGE.
30
31 #include <boost/foreach.hpp>
32 #include <hpp/pinocchio/body.hh>
33 #include <hpp/pinocchio/collision-object.hh>
34 #include <hpp/pinocchio/device.hh>
35 #include <hpp/pinocchio/joint-collection.hh>
36 #include <hpp/pinocchio/joint.hh>
37 #include <pinocchio/multibody/geometry.hpp>
38 #include <pinocchio/multibody/model.hpp>
39 #include <pinocchio/spatial/fcl-pinocchio-conversions.hpp>
40
41 namespace hpp {
42 namespace pinocchio {
43
44 81 Body::Body(DeviceWkPtr_t device, JointIndex joint)
45 81 : devicePtr(device), jointIndex(joint), frameIndexSet(false) {
46
1/2
✓ Branch 1 taken 81 times.
✗ Branch 2 not taken.
81 selfAssert();
47 81 }
48
49 162 void Body::selfAssert() const {
50 162 DevicePtr_t device = devicePtr.lock();
51
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 162 times.
162 assert(device);
52
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 162 times.
162 assert(device->modelPtr());
53
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 162 times.
162 assert(device->model().joints.size() > std::size_t(jointIndex));
54
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 162 times.
162 if (frameIndexSet)
55 ✗ assert(device->model().frames.size() > std::size_t(frameIndex));
56 162 }
57
58 81 const Model& Body::model() const { return devicePtr.lock()->model(); }
59 ✗ Model& Body::model() { return devicePtr.lock()->model(); }
60 ✗ ::pinocchio::Frame& Body::frame() {
61 ✗ searchFrameIndex();
62 ✗ return model().frames[frameIndex];
63 }
64 ✗ const ::pinocchio::Frame& Body::frame() const {
65 ✗ searchFrameIndex();
66 ✗ return model().frames[frameIndex];
67 }
68
69 ✗ void Body::searchFrameIndex() const {
70 ✗ if (frameIndexSet) return;
71 ✗ frameIndex = 0;
72 ✗ BOOST_FOREACH (const ::pinocchio::Frame& frame, model().frames) {
73 ✗ if ((::pinocchio::BODY == frame.type) && (frame.parent == jointIndex))
74 ✗ break;
75 ✗ frameIndex++;
76 }
77 // If index not find, then it is set to size() -> normal behavior
78 ✗ frameIndexSet = true;
79 }
80
81 ✗ const std::string& Body::name() const {
82 ✗ selfAssert();
83 ✗ return frame().name;
84 }
85
86 ✗ JointPtr_t Body::joint() const {
87 ✗ selfAssert();
88 ✗ return Joint::create(devicePtr, jointIndex);
89 }
90
91 ✗ const vector3_t& Body::localCenterOfMass() const {
92 ✗ selfAssert();
93 ✗ return model().inertias[jointIndex].lever();
94 }
95 ✗ matrix3_t Body::inertiaMatrix() const {
96 ✗ selfAssert();
97 ✗ return model().inertias[jointIndex].inertia();
98 }
99 ✗ value_type Body::mass() const {
100 ✗ selfAssert();
101 ✗ return model().inertias[jointIndex].mass();
102 }
103
104 ✗ size_type Body::nbInnerObjects() const {
105 ✗ selfAssert();
106 ✗ DevicePtr_t device = devicePtr.lock();
107 ✗ return (size_type)device->geomData().innerObjects[jointIndex].size();
108 }
109
110 ✗ CollisionObjectPtr_t Body::innerObjectAt(const size_type& i) const {
111 ✗ selfAssert();
112 ✗ assert(0 <= i && i < nbInnerObjects());
113 ✗ DevicePtr_t device = devicePtr.lock();
114 return CollisionObjectPtr_t(new CollisionObject(
115 ✗ device, device->geomData().innerObjects[jointIndex][(std::size_t)i]));
116 }
117
118 81 value_type Body::radius() const {
119
1/2
✓ Branch 1 taken 81 times.
✗ Branch 2 not taken.
81 selfAssert();
120 81 DevicePtr_t device = devicePtr.lock();
121
2/4
✓ Branch 2 taken 81 times.
✗ Branch 3 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 81 times.
81 assert(device->geomDataPtr());
122
3/6
✓ Branch 2 taken 81 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 81 times.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 81 times.
81 assert(std::size_t(device->geomData().radius.size()) ==
123 model().joints.size());
124
1/2
✓ Branch 2 taken 81 times.
✗ Branch 3 not taken.
162 return device->geomData().radius[jointIndex];
125 81 }
126
127 ✗ size_type Body::nbOuterObjects() const {
128 ✗ selfAssert();
129 ✗ DevicePtr_t device = devicePtr.lock();
130 ✗ return (size_type)device->geomData().outerObjects[jointIndex].size();
131 }
132
133 ✗ CollisionObjectPtr_t Body::outerObjectAt(const size_type& i) const {
134 ✗ selfAssert();
135 ✗ assert(0 <= i && i < nbOuterObjects());
136 ✗ DevicePtr_t device = devicePtr.lock();
137 return CollisionObjectPtr_t(new CollisionObject(
138 ✗ device, device->geomData().outerObjects[jointIndex][(std::size_t)i]));
139 }
140 } // namespace pinocchio
141 } // namespace hpp
142