| Directory: | ./ |
|---|---|
| File: | include/hpp/core/subchain-path.hh |
| Date: | 2025-03-10 11:18:21 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 22 | 60 | 36.7% |
| Branches: | 12 | 68 | 17.6% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2016 CNRS | ||
| 3 | // Authors: Joseph Mirabel | ||
| 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_DOF_EXTRACTED_PATH_HH | ||
| 31 | #define HPP_CORE_DOF_EXTRACTED_PATH_HH | ||
| 32 | |||
| 33 | #include <hpp/constraints/matrix-view.hh> | ||
| 34 | #include <hpp/core/path.hh> | ||
| 35 | |||
| 36 | namespace hpp { | ||
| 37 | namespace core { | ||
| 38 | /// \addtogroup path | ||
| 39 | /// \{ | ||
| 40 | |||
| 41 | /// Result of the selection of some configuration parameter of an original path | ||
| 42 | /// \note Decorator design pattern | ||
| 43 | /// \todo the configuration parameter cannot be rearranged. | ||
| 44 | class SubchainPath : public Path { | ||
| 45 | public: | ||
| 46 | typedef Path parent_t; | ||
| 47 | |||
| 48 | 4 | virtual ~SubchainPath() {} | |
| 49 | |||
| 50 | /// Return a shared pointer to a copy of this | ||
| 51 | ✗ | virtual PathPtr_t copy() const { return createCopy(weak_.lock()); } | |
| 52 | |||
| 53 | /// Return a shared pointer to a copy of this and set constraints | ||
| 54 | /// | ||
| 55 | /// \param constraints constraints to apply to the copy | ||
| 56 | /// \pre *this should not have constraints. | ||
| 57 | ✗ | virtual PathPtr_t copy(const ConstraintSetPtr_t& constraints) const { | |
| 58 | ✗ | return createCopy(weak_.lock(), constraints); | |
| 59 | } | ||
| 60 | |||
| 61 | /// \copydoc SubchainPath::SubchainPath | ||
| 62 | 1 | static SubchainPathPtr_t create(const PathPtr_t& original, | |
| 63 | const segments_t& confIntervals, | ||
| 64 | const segments_t& velIntervals) { | ||
| 65 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | SubchainPath* ptr = new SubchainPath(original, confIntervals, velIntervals); |
| 66 | 1 | SubchainPathPtr_t shPtr(ptr); | |
| 67 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | ptr->init(shPtr); |
| 68 | 1 | return shPtr; | |
| 69 | } | ||
| 70 | |||
| 71 | ✗ | static SubchainPathPtr_t createCopy(const SubchainPathPtr_t& path) { | |
| 72 | ✗ | SubchainPath* ptr = new SubchainPath(*path); | |
| 73 | ✗ | SubchainPathPtr_t shPtr(ptr); | |
| 74 | ✗ | ptr->init(shPtr); | |
| 75 | ✗ | return shPtr; | |
| 76 | } | ||
| 77 | |||
| 78 | ✗ | static SubchainPathPtr_t createCopy(const SubchainPathPtr_t& path, | |
| 79 | const ConstraintSetPtr_t& constraints) { | ||
| 80 | ✗ | SubchainPath* ptr = new SubchainPath(*path, constraints); | |
| 81 | ✗ | SubchainPathPtr_t shPtr(ptr); | |
| 82 | ✗ | ptr->init(shPtr); | |
| 83 | ✗ | return shPtr; | |
| 84 | } | ||
| 85 | |||
| 86 | 3 | virtual bool impl_compute(ConfigurationOut_t result, value_type param) const { | |
| 87 |
1/2✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
|
3 | bool success = original_->eval(q_, param); |
| 88 |
3/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
|
3 | if (success) dofExtract(q_, result); |
| 89 | 3 | return success; | |
| 90 | } | ||
| 91 | |||
| 92 | /// Get the initial configuration | ||
| 93 | ✗ | inline Configuration_t initial() const { | |
| 94 | ✗ | Configuration_t q(outputSize()); | |
| 95 | ✗ | dofExtract(original_->initial(), q); | |
| 96 | ✗ | return q; | |
| 97 | } | ||
| 98 | |||
| 99 | /// Get the final configuration | ||
| 100 | ✗ | inline Configuration_t end() const { | |
| 101 | ✗ | Configuration_t q(outputSize()); | |
| 102 | ✗ | dofExtract(original_->end(), q); | |
| 103 | ✗ | return q; | |
| 104 | } | ||
| 105 | |||
| 106 | 3 | void dofExtract(ConfigurationIn_t qin, ConfigurationOut_t qout) const { | |
| 107 |
1/2✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | qout = configView_.rview(qin); |
| 108 | 3 | } | |
| 109 | |||
| 110 | protected: | ||
| 111 | /// Print path in a stream | ||
| 112 | ✗ | virtual std::ostream& print(std::ostream& os) const { | |
| 113 | ✗ | os << "Dof Extracted Path:" << std::endl; | |
| 114 | ✗ | os << "intervals: " << configView_ << std::endl; | |
| 115 | ✗ | os << "original path:" << std::endl; | |
| 116 | ✗ | os << *original_ << std::endl; | |
| 117 | ✗ | return os; | |
| 118 | } | ||
| 119 | |||
| 120 | /// Constructor | ||
| 121 | /// | ||
| 122 | /// \param original Path to extract, | ||
| 123 | /// \param confIntervals of the configuration parameters to be extracted | ||
| 124 | /// \param velIntervals of the configuration parameters to be extracted | ||
| 125 | 1 | SubchainPath(const PathPtr_t& original, const segments_t& confIntervals, | |
| 126 | const segments_t& velIntervals) | ||
| 127 | 1 | : Path(original->timeRange(), Eigen::BlockIndex::cardinal(confIntervals), | |
| 128 | Eigen::BlockIndex::cardinal(velIntervals)), | ||
| 129 | 1 | original_(original), | |
| 130 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | configView_(confIntervals), |
| 131 |
3/6✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 12 taken 1 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 1 times.
✗ Branch 16 not taken.
|
2 | q_(Configuration_t::Zero(original->outputSize())) {} |
| 132 | |||
| 133 | ✗ | SubchainPath(const SubchainPath& path) | |
| 134 | ✗ | : Path(path), | |
| 135 | ✗ | original_(path.original_), | |
| 136 | ✗ | configView_(path.configView_), | |
| 137 | ✗ | q_(path.q_), | |
| 138 | ✗ | weak_() {} | |
| 139 | |||
| 140 | ✗ | SubchainPath(const SubchainPath& path, const ConstraintSetPtr_t& constraints) | |
| 141 | ✗ | : Path(path, constraints), | |
| 142 | ✗ | original_(path.original_), | |
| 143 | ✗ | configView_(path.configView_), | |
| 144 | ✗ | weak_() {} | |
| 145 | |||
| 146 | 1 | void init(SubchainPathPtr_t self) { | |
| 147 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | parent_t::init(self); |
| 148 | 1 | weak_ = self; | |
| 149 | 1 | } | |
| 150 | |||
| 151 | private: | ||
| 152 | PathPtr_t original_; | ||
| 153 | Eigen::RowBlockIndices configView_, velView_; | ||
| 154 | mutable Configuration_t q_; | ||
| 155 | SubchainPathWkPtr_t weak_; | ||
| 156 | }; // SubchainPath | ||
| 157 | /// \} | ||
| 158 | } // namespace core | ||
| 159 | } // namespace hpp | ||
| 160 | #endif // HPP_CORE_DOF_EXTRACTED_PATH_HH | ||
| 161 |