Directory: | ./ |
---|---|
File: | src/node.cc |
Date: | 2024-08-10 11:29:48 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 37 | 46 | 80.4% |
Branches: | 18 | 38 | 47.4% |
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 | #include <hpp/core/connected-component.hh> | ||
31 | #include <hpp/core/edge.hh> | ||
32 | #include <hpp/core/node.hh> | ||
33 | #include <hpp/pinocchio/configuration.hh> | ||
34 | #include <hpp/util/debug.hh> | ||
35 | #include <stdexcept> | ||
36 | |||
37 | namespace hpp { | ||
38 | namespace core { | ||
39 | |||
40 | using pinocchio::displayConfig; | ||
41 | |||
42 | 82 | Node::Node(ConfigurationIn_t configuration) | |
43 | 82 | : configuration_(configuration), | |
44 |
1/2✓ Branch 4 taken 82 times.
✗ Branch 5 not taken.
|
82 | connectedComponent_(ConnectedComponent::create()) {} |
45 | |||
46 | ✗ | Node::Node(ConfigurationIn_t configuration, | |
47 | ✗ | ConnectedComponentPtr_t connectedComponent) | |
48 | ✗ | : configuration_(configuration), connectedComponent_(connectedComponent) { | |
49 | ✗ | assert(connectedComponent_); | |
50 | } | ||
51 | |||
52 | 132 | void Node::addOutEdge(EdgePtr_t edge) { | |
53 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 132 times.
|
132 | assert(edge->from() == this); |
54 | // Check that same edge does not exist | ||
55 |
2/2✓ Branch 4 taken 79 times.
✓ Branch 5 taken 132 times.
|
211 | for (Edges_t::iterator it = outEdges_.begin(); it != outEdges_.end(); ++it) { |
56 |
1/2✗ Branch 3 not taken.
✓ Branch 4 taken 79 times.
|
79 | if ((*it)->to() == edge->to()) { |
57 | std::string msg( | ||
58 | ✗ | "Attempt to insert an edge between two nodes already connected"); | |
59 | hppDout(error, msg.c_str()); | ||
60 | hppDout(error, "from: " << configuration_.transpose()); | ||
61 | hppDout(error, " to: " << edge->to()->configuration().transpose()); | ||
62 | ✗ | throw std::runtime_error(msg.c_str()); | |
63 | } | ||
64 | } | ||
65 | 132 | outEdges_.push_back(edge); | |
66 | 132 | } | |
67 | |||
68 | 132 | void Node::addInEdge(EdgePtr_t edge) { | |
69 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 132 times.
|
132 | assert(edge->to() == this); |
70 | // Check that same edge does not exist | ||
71 |
2/2✓ Branch 4 taken 80 times.
✓ Branch 5 taken 132 times.
|
212 | for (Edges_t::iterator it = inEdges_.begin(); it != inEdges_.end(); ++it) { |
72 |
1/2✗ Branch 3 not taken.
✓ Branch 4 taken 80 times.
|
80 | if ((*it)->from() == edge->from()) { |
73 | std::string msg( | ||
74 | ✗ | "Attempt to insert an edge between two nodes already connected"); | |
75 | hppDout(error, msg.c_str()); | ||
76 | hppDout(error, "from: " << (edge->from()->configuration()).transpose()); | ||
77 | hppDout(error, " to: " << configuration_.transpose()); | ||
78 | ✗ | throw std::runtime_error(msg.c_str()); | |
79 | } | ||
80 | } | ||
81 | 132 | inEdges_.push_back(edge); | |
82 | 132 | } | |
83 | |||
84 | 88 | void Node::connectedComponent(const ConnectedComponentPtr_t& cc) { | |
85 | 88 | connectedComponent_ = cc; | |
86 | 88 | } | |
87 | |||
88 | 757 | ConnectedComponentPtr_t Node::connectedComponent() const { | |
89 | 757 | return connectedComponent_; | |
90 | } | ||
91 | |||
92 | 168 | const Edges_t& Node::outEdges() const { return outEdges_; } | |
93 | |||
94 | ✗ | const Edges_t& Node::inEdges() const { return inEdges_; } | |
95 | |||
96 | 132 | bool Node::isOutNeighbor(const NodePtr_t& n) const { | |
97 |
2/2✓ Branch 3 taken 79 times.
✓ Branch 4 taken 132 times.
|
211 | for (Edges_t::const_iterator it = outEdges_.begin(); it != outEdges_.end(); |
98 | 79 | ++it) | |
99 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 79 times.
|
79 | if ((*it)->to() == n) return true; |
100 | 132 | return false; | |
101 | } | ||
102 | |||
103 | 132 | bool Node::isInNeighbor(const NodePtr_t& n) const { | |
104 |
2/2✓ Branch 3 taken 80 times.
✓ Branch 4 taken 132 times.
|
212 | for (Edges_t::const_iterator it = inEdges_.begin(); it != inEdges_.end(); |
105 | 80 | ++it) | |
106 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 80 times.
|
80 | if ((*it)->from() == n) return true; |
107 | 132 | return false; | |
108 | } | ||
109 | |||
110 | 1359 | const Configuration_t& Node::configuration() const { return configuration_; } | |
111 | |||
112 | 24 | std::ostream& Node::print(std::ostream& os) const { | |
113 |
3/6✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 24 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 24 times.
✗ Branch 10 not taken.
|
24 | os << displayConfig(configuration()) << std::endl; |
114 | 24 | return os; | |
115 | } | ||
116 | 24 | std::ostream& operator<<(std::ostream& os, const Node& n) { | |
117 | 24 | return n.print(os); | |
118 | } | ||
119 | } // namespace core | ||
120 | } // namespace hpp | ||
121 |