Directory: | ./ |
---|---|
File: | src/graph/graph-component.cc |
Date: | 2025-03-07 11:10:46 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 26 | 46 | 56.5% |
Branches: | 9 | 26 | 34.6% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // Copyright (c) 2014, LAAS-CNRS | ||
2 | // Authors: Joseph Mirabel (joseph.mirabel@laas.fr) | ||
3 | // | ||
4 | |||
5 | // Redistribution and use in source and binary forms, with or without | ||
6 | // modification, are permitted provided that the following conditions are | ||
7 | // met: | ||
8 | // | ||
9 | // 1. Redistributions of source code must retain the above copyright | ||
10 | // notice, this list of conditions and the following disclaimer. | ||
11 | // | ||
12 | // 2. Redistributions in binary form must reproduce the above copyright | ||
13 | // notice, this list of conditions and the following disclaimer in the | ||
14 | // documentation and/or other materials provided with the distribution. | ||
15 | // | ||
16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
20 | // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | ||
27 | // DAMAGE. | ||
28 | |||
29 | #include "hpp/manipulation/graph/graph-component.hh" | ||
30 | |||
31 | #include <hpp/constraints/differentiable-function.hh> | ||
32 | #include <hpp/constraints/implicit.hh> | ||
33 | #include <hpp/core/config-projector.hh> | ||
34 | #include <hpp/core/constraint-set.hh> | ||
35 | |||
36 | #include "hpp/manipulation/graph/graph.hh" | ||
37 | |||
38 | namespace hpp { | ||
39 | namespace manipulation { | ||
40 | namespace graph { | ||
41 | typedef constraints::Implicit Implicit; | ||
42 | 20 | const std::string& GraphComponent::name() const { return name_; } | |
43 | |||
44 | ✗ | std::ostream& GraphComponent::print(std::ostream& os) const { | |
45 | ✗ | os << id() << " : " << name(); | |
46 | ✗ | return os; | |
47 | } | ||
48 | |||
49 | ✗ | std::ostream& GraphComponent::dotPrint(std::ostream& os, | |
50 | dot::DrawingAttributes) const { | ||
51 | ✗ | os << id(); | |
52 | ✗ | return os; | |
53 | } | ||
54 | |||
55 | 1 | void GraphComponent::addNumericalConstraint(const ImplicitPtr_t& nm) { | |
56 | 1 | invalidate(); | |
57 | 1 | numericalConstraints_.push_back(nm); | |
58 | 1 | } | |
59 | |||
60 | ✗ | void GraphComponent::addNumericalCost(const ImplicitPtr_t& cost) { | |
61 | ✗ | invalidate(); | |
62 | ✗ | numericalCosts_.push_back(cost); | |
63 | } | ||
64 | |||
65 | ✗ | void GraphComponent::resetNumericalConstraints() { | |
66 | ✗ | invalidate(); | |
67 | ✗ | numericalConstraints_.clear(); | |
68 | ✗ | numericalCosts_.clear(); | |
69 | } | ||
70 | |||
71 | 8 | bool GraphComponent::insertNumericalConstraints( | |
72 | ConfigProjectorPtr_t& proj) const { | ||
73 |
1/4✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 8 times.
|
8 | for (const auto& nc : numericalConstraints_) proj->add(nc); |
74 |
1/4✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 8 times.
|
8 | for (const auto& nc : numericalCosts_) proj->add(nc, 1); |
75 | 8 | return !numericalConstraints_.empty(); | |
76 | } | ||
77 | |||
78 | 96 | const NumericalConstraints_t& GraphComponent::numericalConstraints() const { | |
79 | 96 | return numericalConstraints_; | |
80 | } | ||
81 | |||
82 | 96 | const NumericalConstraints_t& GraphComponent::numericalCosts() const { | |
83 | 96 | return numericalCosts_; | |
84 | } | ||
85 | |||
86 | 16 | GraphPtr_t GraphComponent::parentGraph() const { return graph_.lock(); } | |
87 | |||
88 | 14 | void GraphComponent::parentGraph(const GraphWkPtr_t& parent) { | |
89 | 14 | graph_ = parent; | |
90 | 14 | GraphPtr_t g = graph_.lock(); | |
91 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
|
14 | assert(g); |
92 |
1/2✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
|
14 | id_ = g->components().size(); |
93 |
2/4✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 14 times.
✗ Branch 6 not taken.
|
14 | g->components().push_back(wkPtr_); |
94 | 14 | } | |
95 | |||
96 | 14 | void GraphComponent::init(const GraphComponentWkPtr_t& weak) { wkPtr_ = weak; } | |
97 | |||
98 | 5 | void GraphComponent::throwIfNotInitialized() const { | |
99 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | if (!isInit_) { |
100 |
1/2✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 | throw std::logic_error("The graph should have been initialized first."); |
101 | } | ||
102 | 1 | } | |
103 | |||
104 | ✗ | std::ostream& operator<<( | |
105 | std::ostream& os, | ||
106 | const hpp::manipulation::graph::GraphComponent& graphComp) { | ||
107 | ✗ | return graphComp.print(os); | |
108 | } | ||
109 | |||
110 | ✗ | void GraphComponent::populateTooltip(dot::Tooltip& tp) const { | |
111 | ✗ | for (NumericalConstraints_t::const_iterator it = | |
112 | ✗ | numericalConstraints_.begin(); | |
113 | ✗ | it != numericalConstraints_.end(); ++it) { | |
114 | ✗ | tp.addLine("- " + (*it)->function().name()); | |
115 | } | ||
116 | } | ||
117 | } // namespace graph | ||
118 | } // namespace manipulation | ||
119 | } // namespace hpp | ||
120 |