GCC Code Coverage Report


Directory: ./
File: src/connected-component.cc
Date: 2025-03-07 11:10:46
Exec Total Coverage
Lines: 0 45 0.0%
Branches: 0 54 0.0%

Line Branch Exec Source
1 //
2 // Copyright (c) 2015 CNRS
3 // Authors: Anna Seppala (seppala@laas.fr)
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/manipulation/connected-component.hh>
31
32 #include "hpp/manipulation/roadmap-node.hh"
33 #include "hpp/manipulation/roadmap.hh"
34
35 namespace hpp {
36 namespace manipulation {
37 RoadmapNodes_t ConnectedComponent::empty_ = RoadmapNodes_t();
38
39 bool ConnectedComponent::check() const {
40 std::set<core::NodePtr_t> s1;
41 for (core::NodeVector_t::const_iterator it = nodes().begin();
42 it != nodes().end(); ++it) {
43 s1.insert(*it);
44 }
45 std::set<core::NodePtr_t> s2;
46 for (GraphStates_t::const_iterator it = graphStateMap_.begin();
47 it != graphStateMap_.end(); ++it) {
48 for (RoadmapNodes_t::const_iterator itNodes = it->second.begin();
49 itNodes != it->second.end(); ++itNodes) {
50 s2.insert(*itNodes);
51 }
52 }
53 if (s1.size() == 0) return false;
54 if (s1 == s2) return true;
55 return false;
56 }
57
58 ConnectedComponentPtr_t ConnectedComponent::create(
59 const RoadmapWkPtr_t& roadmap) {
60 ConnectedComponent* ptr = new ConnectedComponent();
61 ConnectedComponentPtr_t shPtr(ptr);
62 // calls init function in core::ConnectedComponent that saves
63 // shPtr into the class variable weak_ (weak pointer). Reimplement?
64 ptr->init(shPtr);
65 shPtr->roadmap_ = roadmap.lock();
66 return shPtr;
67 }
68
69 void ConnectedComponent::merge(const core::ConnectedComponentPtr_t& otherCC) {
70 core::ConnectedComponent::merge(otherCC);
71 const ConnectedComponentPtr_t other =
72 static_pointer_cast<ConnectedComponent>(otherCC);
73 /// take all graph states in other->graphStateMap_ and put them in
74 /// this->graphStateMap_ if they already exist in this->graphStateMap_, append
75 /// roadmap nodes from other graph state to graph state in this.
76 for (GraphStates_t::iterator otherIt = other->graphStateMap_.begin();
77 otherIt != other->graphStateMap_.end(); otherIt++) {
78 // find other graph state in this-graphStateMap_ -> merge their roadmap
79 // nodes
80 GraphStates_t::iterator mapIt = this->graphStateMap_.find(otherIt->first);
81 if (mapIt != this->graphStateMap_.end()) {
82 mapIt->second.insert(mapIt->second.end(), otherIt->second.begin(),
83 otherIt->second.end());
84 } else {
85 this->graphStateMap_.insert(*otherIt);
86 }
87 }
88 other->graphStateMap_.clear();
89 assert(check());
90 }
91
92 void ConnectedComponent::addNode(const core::NodePtr_t& node) {
93 core::ConnectedComponent::addNode(node);
94 // Find right graph state in map and add roadmap node to corresponding vector
95 const RoadmapNodePtr_t& n = static_cast<RoadmapNodePtr_t>(node);
96 RoadmapPtr_t roadmap = roadmap_.lock();
97 if (!roadmap)
98 throw std::logic_error(
99 "The roadmap of this ConnectedComponent as been deleted.");
100 graphStateMap_[roadmap->getState(n)].push_back(n);
101 assert(check());
102 }
103
104 const RoadmapNodes_t& ConnectedComponent::getRoadmapNodes(
105 const graph::StatePtr_t graphState) const {
106 GraphStates_t::const_iterator mapIt = graphStateMap_.find(graphState);
107 if (mapIt != graphStateMap_.end()) return mapIt->second;
108 return empty_;
109 }
110
111 } // namespace manipulation
112 } // namespace hpp
113