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/core/distance.hh> |
30 |
|
|
#include <hpp/core/edge.hh> |
31 |
|
|
#include <hpp/manipulation/graph/state.hh> |
32 |
|
|
#include <hpp/manipulation/graph/statistics.hh> |
33 |
|
|
#include <hpp/manipulation/leaf-connected-comp.hh> |
34 |
|
|
#include <hpp/manipulation/roadmap-node.hh> |
35 |
|
|
#include <hpp/manipulation/roadmap.hh> |
36 |
|
|
#include <hpp/util/pointer.hh> |
37 |
|
|
|
38 |
|
|
namespace hpp { |
39 |
|
|
namespace manipulation { |
40 |
|
✗ |
Roadmap::Roadmap(const core::DistancePtr_t& distance, |
41 |
|
✗ |
const core::DevicePtr_t& robot) |
42 |
|
✗ |
: core::Roadmap(distance, robot), weak_() {} |
43 |
|
|
|
44 |
|
✗ |
RoadmapPtr_t Roadmap::create(const core::DistancePtr_t& distance, |
45 |
|
|
const core::DevicePtr_t& robot) { |
46 |
|
✗ |
Roadmap* ptr = new Roadmap(distance, robot); |
47 |
|
✗ |
RoadmapPtr_t shPtr(ptr); |
48 |
|
✗ |
ptr->init(shPtr); |
49 |
|
✗ |
return shPtr; |
50 |
|
|
} |
51 |
|
|
|
52 |
|
✗ |
void Roadmap::clear() { |
53 |
|
✗ |
Parent::clear(); |
54 |
|
✗ |
Histograms_t::const_iterator it; |
55 |
|
✗ |
for (it = histograms_.begin(); it != histograms_.end(); ++it) (*it)->clear(); |
56 |
|
✗ |
if (graph_) { |
57 |
|
✗ |
const Histograms_t& hs = graph_->histograms(); |
58 |
|
✗ |
for (it = hs.begin(); it != hs.end(); ++it) (*it)->clear(); |
59 |
|
|
} |
60 |
|
✗ |
leafCCs_.clear(); |
61 |
|
|
} |
62 |
|
|
|
63 |
|
✗ |
void Roadmap::push_node(const core::NodePtr_t& n) { |
64 |
|
✗ |
Parent::push_node(n); |
65 |
|
✗ |
const RoadmapNodePtr_t& node = static_cast<RoadmapNodePtr_t>(n); |
66 |
|
✗ |
statInsert(node); |
67 |
|
✗ |
leafCCs_.insert(node->leafConnectedComponent()); |
68 |
|
|
} |
69 |
|
|
|
70 |
|
✗ |
void Roadmap::statInsert(const RoadmapNodePtr_t& n) { |
71 |
|
✗ |
Histograms_t::const_iterator it; |
72 |
|
✗ |
for (it = histograms_.begin(); it != histograms_.end(); ++it) (*it)->add(n); |
73 |
|
✗ |
if (graph_) { |
74 |
|
✗ |
const Histograms_t& hs = graph_->histograms(); |
75 |
|
✗ |
for (it = hs.begin(); it != hs.end(); ++it) (*it)->add(n); |
76 |
|
|
} |
77 |
|
|
} |
78 |
|
|
|
79 |
|
✗ |
void Roadmap::insertHistogram(const graph::HistogramPtr_t hist) { |
80 |
|
✗ |
histograms_.push_back(hist); |
81 |
|
✗ |
core::Nodes_t::const_iterator _node; |
82 |
|
✗ |
for (_node = nodes().begin(); _node != nodes().end(); ++_node) |
83 |
|
✗ |
hist->add(static_cast<RoadmapNodePtr_t>(*_node)); |
84 |
|
|
} |
85 |
|
|
|
86 |
|
✗ |
void Roadmap::constraintGraph(const graph::GraphPtr_t& graph) { |
87 |
|
✗ |
graph_ = graph; |
88 |
|
|
// FIXME Add the current nodes() to the graph->histograms() |
89 |
|
|
// The main issue is that new histograms may be added to |
90 |
|
|
// graph->histograms() and this class will not know it. |
91 |
|
|
} |
92 |
|
|
|
93 |
|
✗ |
RoadmapNodePtr_t Roadmap::nearestNodeInState( |
94 |
|
|
ConfigurationIn_t configuration, |
95 |
|
|
const ConnectedComponentPtr_t& connectedComponent, |
96 |
|
|
const graph::StatePtr_t& state, value_type& minDistance) const { |
97 |
|
✗ |
core::NodePtr_t result = NULL; |
98 |
|
✗ |
minDistance = std::numeric_limits<value_type>::infinity(); |
99 |
|
|
const RoadmapNodes_t& roadmapNodes = |
100 |
|
✗ |
connectedComponent->getRoadmapNodes(state); |
101 |
|
|
// std::cout << "State: " << state->name () << std::endl; |
102 |
|
|
// std::cout << "roadmapNodes.size () = " << roadmapNodes.size () |
103 |
|
|
// << std::endl; |
104 |
|
✗ |
for (RoadmapNodes_t::const_iterator itNode = roadmapNodes.begin(); |
105 |
|
✗ |
itNode != roadmapNodes.end(); ++itNode) { |
106 |
|
✗ |
value_type d = (*distance())((*itNode)->configuration(), configuration); |
107 |
|
✗ |
if (d < minDistance) { |
108 |
|
✗ |
minDistance = d; |
109 |
|
✗ |
result = *itNode; |
110 |
|
|
} |
111 |
|
|
} |
112 |
|
✗ |
return static_cast<RoadmapNode*>(result); |
113 |
|
|
} |
114 |
|
|
|
115 |
|
✗ |
core::NodePtr_t Roadmap::createNode(ConfigurationIn_t q) const { |
116 |
|
|
// call RoadmapNode constructor with new manipulation connected component |
117 |
|
✗ |
RoadmapNodePtr_t node = new RoadmapNode(q, ConnectedComponent::create(weak_)); |
118 |
|
✗ |
LeafConnectedCompPtr_t sc = WeighedLeafConnectedComp::create(weak_.lock()); |
119 |
|
✗ |
node->leafConnectedComponent(sc); |
120 |
|
✗ |
sc->setFirstNode(node); |
121 |
|
✗ |
return node; |
122 |
|
|
} |
123 |
|
|
|
124 |
|
✗ |
graph::StatePtr_t Roadmap::getState(RoadmapNodePtr_t node) { |
125 |
|
✗ |
return graph_->getState(node); |
126 |
|
|
} |
127 |
|
|
|
128 |
|
✗ |
void Roadmap::connect(const LeafConnectedCompPtr_t& cc1, |
129 |
|
|
const LeafConnectedCompPtr_t& cc2) { |
130 |
|
✗ |
if (cc1->canReach(cc2)) return; |
131 |
|
✗ |
LeafConnectedComp::LeafConnectedComps_t cc2Tocc1; |
132 |
|
✗ |
if (cc2->canReach(cc1, cc2Tocc1)) { |
133 |
|
✗ |
merge(cc1, cc2Tocc1); |
134 |
|
|
} else { |
135 |
|
✗ |
cc1->to_.insert(cc2.get()); |
136 |
|
✗ |
cc2->from_.insert(cc1.get()); |
137 |
|
|
} |
138 |
|
|
} |
139 |
|
|
|
140 |
|
✗ |
void Roadmap::merge(const LeafConnectedCompPtr_t& cc1, |
141 |
|
|
LeafConnectedComp::LeafConnectedComps_t& ccs) { |
142 |
|
✗ |
for (LeafConnectedComp::LeafConnectedComps_t::iterator itcc = ccs.begin(); |
143 |
|
✗ |
itcc != ccs.end(); ++itcc) { |
144 |
|
✗ |
if (*itcc != cc1.get()) { |
145 |
|
✗ |
cc1->merge((*itcc)->self()); |
146 |
|
|
#ifndef NDEBUG |
147 |
|
|
std::size_t nb = |
148 |
|
|
#endif |
149 |
|
✗ |
leafCCs_.erase((*itcc)->self()); |
150 |
|
✗ |
assert(nb == 1); |
151 |
|
|
} |
152 |
|
|
} |
153 |
|
|
} |
154 |
|
|
|
155 |
|
✗ |
void Roadmap::impl_addEdge(const core::EdgePtr_t& edge) { |
156 |
|
✗ |
Parent::impl_addEdge(edge); |
157 |
|
✗ |
const RoadmapNodePtr_t& f = static_cast<RoadmapNodePtr_t>(edge->from()); |
158 |
|
✗ |
const RoadmapNodePtr_t& t = static_cast<RoadmapNodePtr_t>(edge->to()); |
159 |
|
✗ |
if (f->graphState() == t->graphState()) { |
160 |
|
✗ |
LeafConnectedCompPtr_t cc1(f->leafConnectedComponent()); |
161 |
|
✗ |
LeafConnectedCompPtr_t cc2(t->leafConnectedComponent()); |
162 |
|
|
|
163 |
|
✗ |
connect(cc1, cc2); |
164 |
|
|
} |
165 |
|
|
} |
166 |
|
|
} // namespace manipulation |
167 |
|
|
} // namespace hpp |
168 |
|
|
|