GCC Code Coverage Report


Directory: ./
File: include/hpp/core/path-vector.hh
Date: 2024-08-10 11:29:48
Exec Total Coverage
Lines: 16 42 38.1%
Branches: 5 38 13.2%

Line Branch Exec Source
1 //
2 // Copyright (c) 2014 CNRS
3 // Authors: Florent Lamiraux
4 //
5
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
10 // 1. Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 //
13 // 2. Redistributions in binary form must reproduce the above copyright
14 // notice, this list of conditions and the following disclaimer in the
15 // documentation and/or other materials provided with the distribution.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
28 // DAMAGE.
29
30 #ifndef HPP_CORE_PATH_VECTOR_HH
31 #define HPP_CORE_PATH_VECTOR_HH
32
33 #include <hpp/core/fwd.hh>
34 #include <hpp/core/path.hh>
35 #include <hpp/pinocchio/device.hh>
36
37 namespace hpp {
38 namespace core {
39 /// \addtogroup path
40 /// \{
41
42 /// Concatenation of several paths
43 class HPP_CORE_DLLAPI PathVector : public Path {
44 public:
45 typedef Path parent_t;
46 /// \name Construction, destruction, copy
47 /// \{
48
49 /// Create instance and return shared pointer
50 208 static PathVectorPtr_t create(size_type outputSize,
51 size_type outputDerivativeSize) {
52
1/2
✓ Branch 2 taken 208 times.
✗ Branch 3 not taken.
208 PathVector* ptr = new PathVector(outputSize, outputDerivativeSize);
53 208 PathVectorPtr_t shPtr(ptr);
54
1/2
✓ Branch 2 taken 208 times.
✗ Branch 3 not taken.
208 ptr->init(shPtr);
55 208 return shPtr;
56 }
57
58 /// Create instance and return shared pointer
59 static PathVectorPtr_t create(size_type outputSize,
60 size_type outputDerivativeSize,
61 const ConstraintSetPtr_t& constraint) {
62 PathVector* ptr =
63 new PathVector(outputSize, outputDerivativeSize, constraint);
64 PathVectorPtr_t shPtr(ptr);
65 ptr->init(shPtr);
66 return shPtr;
67 }
68
69 /// Create instance and return shared pointer
70 static PathVectorPtr_t createCopy(const PathVectorPtr_t& original) {
71 PathVector* ptr = new PathVector(*original);
72 PathVectorPtr_t shPtr(ptr);
73 ptr->init(shPtr);
74 return shPtr;
75 }
76
77 /// Create instance and return shared pointer
78 static PathVectorPtr_t createCopy(const PathVectorPtr_t& original,
79 const ConstraintSetPtr_t& constraints) {
80 PathVector* ptr = new PathVector(*original, constraints);
81 PathVectorPtr_t shPtr(ptr);
82 ptr->init(shPtr);
83 return shPtr;
84 }
85
86 /// Return a shared pointer to a copy of this
87 virtual PathPtr_t copy() const { return createCopy(weak_.lock()); }
88
89 /// Return a shared pointer to a copy of this with constraints
90 /// \param constraints constraints to apply to the copy
91 /// \pre *this should not have constraints.
92 virtual PathPtr_t copy(const ConstraintSetPtr_t& constraints) const {
93 return createCopy(weak_.lock(), constraints);
94 }
95
96 /// Destructor
97 780 virtual ~PathVector() {}
98 /// \}
99
100 /// Get the number of sub paths
101 926627 std::size_t numberPaths() const { return paths_.size(); }
102
103 /// Get a path in the vector
104 ///
105 /// \param rank rank of the path in the vector. Should be between 0 and
106 /// numberPaths ().
107 /// \return shared pointer to a copy of the path at requested rank with
108 /// constraints applicable to the PathVector.
109 PathPtr_t pathAtRank(std::size_t rank) const;
110
111 /// Get rank of direct path in vector at param
112 ///
113 /// \param param parameter in interval of definition,
114 /// \retval localParam parameter on sub-path
115 /// \return rank of direct path in vector
116 std::size_t rankAtParam(const value_type& param,
117 value_type& localParam) const;
118
119 /// Append a path at the end of the vector
120 void appendPath(const PathPtr_t& path);
121
122 /// Concatenate two vectors of path
123 /// \param path path to append at the end of this one
124 ///
125 /// Each element of path is appended to this one.
126 void concatenate(const PathVectorPtr_t& path);
127
128 /// Get the initial configuration
129 28 virtual Configuration_t initial() const { return paths_.front()->initial(); }
130
131 /// Get the final configuration
132 30 virtual Configuration_t end() const { return paths_.back()->end(); }
133
134 /// Return the a path vector representing the same path but ensuring
135 /// that there is no PathVector in the PathVector.
136 void flatten(PathVectorPtr_t flattenedPath) const;
137
138 /// Reversion of a path
139 virtual PathPtr_t reverse() const;
140
141 protected:
142 /// Print path in a stream
143 virtual std::ostream& print(std::ostream& os) const;
144 /// Constructor
145 208 PathVector(std::size_t outputSize, std::size_t outputDerivativeSize)
146 : parent_t(std::make_pair(0, 0), outputSize, outputDerivativeSize),
147
2/4
✓ Branch 1 taken 208 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 208 times.
✗ Branch 6 not taken.
208 paths_() {}
148 /// Constructor
149 PathVector(std::size_t outputSize, std::size_t outputDerivativeSize,
150 const ConstraintSetPtr_t& constraint)
151 : parent_t(std::make_pair(0, 0), outputSize, outputDerivativeSize,
152 constraint),
153 paths_() {}
154 /// Copy constructor
155 PathVector(const PathVector& path) : parent_t(path), paths_() {
156 assert(timeRange() == path.timeRange());
157 for (Paths_t::const_iterator it = path.paths_.begin();
158 it != path.paths_.end(); it++) {
159 paths_.push_back((*it)->copy());
160 }
161 }
162
163 /// Copy constructor with constraints
164 PathVector(const PathVector& path, const ConstraintSetPtr_t& constraints)
165 : parent_t(path, constraints), paths_() {
166 assert(timeRange() == path.timeRange());
167 for (Paths_t::const_iterator it = path.paths_.begin();
168 it != path.paths_.end(); it++) {
169 paths_.push_back((*it)->copy());
170 }
171 }
172
173 208 void init(PathVectorPtr_t self) {
174
1/2
✓ Branch 2 taken 208 times.
✗ Branch 3 not taken.
208 parent_t::init(self);
175 208 weak_ = self;
176 208 }
177 virtual bool impl_compute(ConfigurationOut_t result, value_type t) const;
178 /// Virtual implementation of derivative
179 virtual void impl_derivative(vectorOut_t result, const value_type& t,
180 size_type order) const;
181 /// Extraction of a sub-path
182 /// \param subInterval interval of definition of the extract path
183 virtual PathPtr_t impl_extract(const interval_t& subInterval) const;
184
185 /// Virtual implementation of velocity bound
186 virtual void impl_velocityBound(vectorOut_t bound, const value_type& param0,
187 const value_type& param1) const;
188
189 private:
190 Paths_t paths_;
191 PathVectorWkPtr_t weak_;
192
193 protected:
194 PathVector() {}
195
196 private:
197 HPP_SERIALIZABLE();
198 }; // class PathVector
199 /// \}
200 } // namespace core
201 } // namespace hpp
202
203 18 BOOST_CLASS_EXPORT_KEY(hpp::core::PathVector)
204
205 #endif // HPP_CORE_PATH_VECTOR_HH
206