GCC Code Coverage Report


Directory: ./
File: include/hpp/affordance/operations.hh
Date: 2025-03-07 12:08:39
Exec Total Coverage
Lines: 13 14 92.9%
Branches: 2 4 50.0%

Line Branch Exec Source
1 //
2 // Copyright (c) 2016 CNRS
3 // Authors: Anna Seppala
4 //
5 // This file is part of hpp-affordance
6 // hpp-affordance is free software: you can redistribute it
7 // and/or modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation, either version
9 // 3 of the License, or (at your option) any later version.
10 //
11 // hpp-affordance is distributed in the hope that it will be
12 // useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Lesser Public License for more details. You should have
15 // received a copy of the GNU Lesser General Public License along with
16 // hpp-affordance If not, see
17 // <http://www.gnu.org/licenses/>.
18
19 #ifndef HPP_AFFORDANCE_OPERATIONS_HH
20 #define HPP_AFFORDANCE_OPERATIONS_HH
21
22 #include <coal/data_types.h>
23
24 namespace hpp {
25 namespace affordance {
26 /// \addtogroup affordance
27 /// \{
28
29 /// Base class for the data needed to determine affordances of different
30 /// types. For each affordance type, a child class inheriting OperationBase
31 /// will have to be created.
32 class OperationBase {
33 public:
34 /// If an OperationBase object is created without parameters, an
35 /// affordance type called "noAffordance" is created as default,
36 /// with certain default values for its member variables. This
37 /// constructor should not be used..!
38 OperationBase()
39 : zWorld_(0, 0, 1),
40 margin_(0.3),
41 neighbouringTriangleMargin_(0.3),
42 minArea_(0.05),
43 affordance_("noAffordance") {}
44 /// Constructor that allows for user-defined parameters. Default values are
45 /// given for parameters that are not defined by the user. \param margin
46 /// Margin needed for the evaluation of the requirement function \param
47 /// nbTriMargin Margin between two triangles tested for a single
48 /// affordance surface. If the angle between two triangles is greater
49 /// than the provided margin, the triangles cannot be part of the same
50 /// affordance surface.
51 /// \param minArea Minimum area needed for the formation of an affordance
52 /// object \param affordanceName The name of the affordance type
53 10 explicit OperationBase(const double margin = 0.3,
54 const double nbTriMargin = 0.3,
55 const double minArea = 0.05,
56 const char* affordanceName = "noAffordance")
57 : zWorld_(0, 0, 1),
58 10 margin_(margin),
59 10 neighbouringTriangleMargin_(nbTriMargin),
60 10 minArea_(minArea),
61
1/2
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
10 affordance_(affordanceName) {}
62 /// Fully virtual function that will determine whether or not a given
63 /// triangle normal fullfils the requirement of a child class. If yes,
64 /// the tested triangle forms part of a potential affordance.
65 /// \param normal Normal vector of the tested triangle.
66 virtual bool requirement(const coal::Vec3f& normal) = 0;
67 /// The orientation of the world z axis. Needed to find potential affordance
68 /// objects.
69 const coal::Vec3f zWorld_;
70 /// The error margin within which the requirement function must be fullfilled.
71 const double margin_;
72 /// The margin for the deviation of the normal of neighbouring triangles.
73 /// Used to determine affordance objects comprising more than one triangle.
74 const double neighbouringTriangleMargin_;
75 /// The minimum area required for an affordance object. The total area may
76 /// comprise multiple triangles.
77 const double minArea_;
78 /// Name of the affordance type for which te requirement exists.
79 const char* affordance_;
80 }; // class OperationBase
81 /// Class that contains the information needed to create affordance
82 /// objects of type Support. Inherits the OperationBase class.
83 class SupportOperation : public OperationBase {
84 public:
85 /// Constructor that takes in user-defined parameters
86 /// \param margin Margin needed for the evaluation of the requirement function
87 /// \param nbTriMargin Margin between two triangles tested for a single
88 /// affordance surface. If the angle between two triangles is greater
89 /// than the provided margin, the triangles cannot be part of the same
90 /// affordance surface.
91 /// \param minArea Minimum area needed for the formation of an affordance
92 /// object \param affordanceName The name of the affordance type
93 5 explicit SupportOperation(const double margin = 0.3,
94 const double nbTriMargin = 0.3,
95 const double minArea = 0.05,
96 const char* affordanceName = "Support")
97 5 : OperationBase(margin, nbTriMargin, minArea, affordanceName) {}
98 /// The implementation of the requirement function for Support affordances
99 /// overrides the virtual function in class OperationBase.
100 /// \param nromal Normal vector of the tested triangle.
101 51 bool requirement(const coal::Vec3f& normal) {
102
1/2
✓ Branch 2 taken 51 times.
✗ Branch 3 not taken.
51 return ((zWorld_ - normal).squaredNorm() < margin_);
103 }
104 }; // class SupportOperation
105 /// Class that contains the information needed to create affordance
106 /// objects of type Lean. Inherits the OperationBase class.
107 class LeanOperation : public OperationBase {
108 public:
109 /// Constructor that takes in user-defined parameters
110 /// \param margin Margin needed for the evaluation of the requirement function
111 /// \param nbTriMargin Margin between two triangles tested for a single
112 /// affordance surface. If the angle between two triangles is greater
113 /// than the provided margin, the triangles cannot be part of the same
114 /// affordance surface.
115 /// \param minArea Minimum area needed for the formation of an affordance
116 /// object \param affordanceName The name of the affordance type
117 5 explicit LeanOperation(const double margin = 0.3,
118 const double nbTriMargin = 0.3,
119 const double minArea = 0.05,
120 const char* affordanceName = "Lean")
121 5 : OperationBase(margin, nbTriMargin, minArea, affordanceName) {}
122 /// The implementation of the requirement function for Lean affordances
123 /// overrides the virtual function in class OperationBase.
124 /// \param nromal Normal vector of the tested triangle.
125 37 bool requirement(const coal::Vec3f& normal) {
126 37 return (fabs(normal.dot(zWorld_)) < margin_);
127 }
128 }; // class LeanOperation
129
130 /// Class that contains the information needed to create affordance
131 /// objects of type Lean. Inherits the OperationBase class.
132 class Support45Operation : public OperationBase {
133 public:
134 /// Constructor that takes in user-defined parameters
135 /// \param margin Margin needed for the evaluation of the requirement function
136 /// \param nbTriMargin Margin between two triangles tested for a single
137 /// affordance surface. If the angle between two triangles is greater
138 /// than the provided margin, the triangles cannot be part of the same
139 /// affordance surface.
140 /// \param minArea Minimum area needed for the formation of an affordance
141 /// object \param affordanceName The name of the affordance type
142 explicit Support45Operation(const double margin = 0.3,
143 const double nbTriMargin = 0.3,
144 const double minArea = 0.05,
145 const char* affordanceName = "Support45")
146 : OperationBase(margin, 0.05, minArea, affordanceName),
147 axis45_(coal::Vec3f(1. / sqrt(2.), 0, 1. / sqrt(2.))) {}
148
149 private:
150 const coal::Vec3f axis45_;
151
152 /// The implementation of the requirement function for Support45 affordances
153 /// overrides the virtual function in class OperationBase.
154 /// Test if the normal in oriented with 45° up +- margin
155 /// \param nromal Normal vector of the tested triangle.
156 bool requirement(const coal::Vec3f& normal) {
157 coal::Vec3f projectedNormal(0, 0, normal[2]); // project normal in x,z plan
158 projectedNormal[0] = sqrt(normal[0] * normal[0] + normal[1] * normal[1]);
159 return ((axis45_ - projectedNormal).squaredNorm() < margin_);
160 }
161 }; // class LeanOperation
162
163 /// \}
164 } // namespace affordance
165 } // namespace hpp
166
167 #endif // HPP_AFFORDANCE_OPERATIONS_HH
168