1 #ifndef CLEARANCE_MAP_H_
2 #define CLEARANCE_MAP_H_
5 #include <unordered_map>
14 #include <containers/sequential/graph/directed_preds_graph.h>
43 template<
class MPTraits>
52 typedef stapl::sequential::directed_preds_graph<
53 stapl::MULTIEDGES, Point3d, vector<Point3d>>
GraphType;
54 typedef GraphType::vertex_descriptor
VD;
55 typedef GraphType::edge_descriptor
ED;
94 void ComputeMinClearance(
const ED& _ed);
99 double GetClearanceInfo(
const Point3d& _p);
112 struct EdgeDescriptorComp{
119 bool operator()(
const ED& _a,
const ED& _b)
const{
120 if(_a.source() > _b.source())
return true;
121 else if(_a.source() == _b.source()){
122 if(_a.target() > _b.target()){
130 map<ED, double, EdgeDescriptorComp> m_clearanceMap;
140 template<
class MPTraits>
145 for(
auto eit = m_skeleton->GetGraph().edges_begin();
146 eit != m_skeleton->GetGraph().edges_end(); eit++){
147 ComputeMinClearance(eit->descriptor());
151 template<
class MPTraits>
156 adj_edge_iterator eit;
157 m_skeleton->GetGraph().find_edge(_ed, vit, eit);
159 const vector<Point3d>& vp = eit->property();
162 double min = numeric_limits<double>::max();
163 for(
const auto &n : vp){
164 double c = GetClearanceInfo(n);
168 if(m_clearanceMap.find(_ed) == m_clearanceMap.end()){
169 m_clearanceMap.insert(make_pair(_ed, min));
175 template<
class MPTraits>
180 auto graph = m_skeleton->GetGraph();
182 for(
auto mit = m_clearanceMap.begin();
183 mit != m_clearanceMap.end(); ++mit){
185 m_clearanceMap[mit->first] = numeric_limits<double>::infinity();
186 graph.delete_edge(mit->first);
189 m_skeleton->SetGraph(graph);
196 template<
class MPTraits>
197 map<typename ClearanceMap<MPTraits>::ED,
double>&
200 for(
auto mit = m_clearanceMap.begin();
201 mit != m_clearanceMap.end(); ++mit){
203 m_clearanceMap[mit->first] = numeric_limits<double>::infinity();
206 return m_clearanceMap;
209 template<
class MPTraits>
214 auto vc = this->GetValidityChecker(
"pqp_solid");
215 auto pointRobot = this->GetMPProblem()->GetRobot(
"point");
217 CfgType cfg(_p, pointRobot);
221 vc->IsValid(cfg, cdInfo,
"Obtain clearance map");
234 template<
class MPTraits>
239 auto graph = m_skeleton->GetGraph();
242 for(
auto vit = graph.begin(); vit != graph.end(); ++vit) {
244 if(vit->predecessors().size() == 1 && vit->size() == 1) {
246 auto pred = graph.find_vertex(vit->predecessors()[0]);
248 vector<Vector3d> inPath;
249 vector<Vector3d> outPath;
250 for(
auto eit : *pred) {
251 if(eit.target() == vit->descriptor()){
252 in = eit.descriptor();
253 inPath = eit.property();
256 out = (*vit->begin()).descriptor();
257 outPath = (*vit->begin()).property();
260 vector<Vector3d> mergedPath;
261 for(
size_t i = 0; i < inPath.size(); i++){
262 mergedPath.push_back(inPath[i]);
264 for(
size_t i = 1; i < outPath.size(); i++){
265 mergedPath.push_back(outPath[i]);
267 ED neweid = graph.add_edge(in.source(), out.target(), mergedPath);
270 graph.delete_edge(in);
271 graph.delete_edge(out);
272 cout <<
"deleted 2-node ID: " << vit->descriptor() << endl;
273 graph.delete_vertex(vit->descriptor());
279 m_skeleton->SetGraph(graph);
Definition: ClearanceMap.h:44
GraphType::vertex_descriptor VD
Definition: ClearanceMap.h:54
GraphType::adj_edge_iterator adj_edge_iterator
Definition: ClearanceMap.h:57
GraphType::vertex_iterator vertex_iterator
Definition: ClearanceMap.h:56
WorkspaceSkeleton * GetAnnotatedSkeleton(FilterFunction &&_f)
Definition: ClearanceMap.h:178
void Construct(WorkspaceSkeleton *_s)
Definition: ClearanceMap.h:143
function< bool(double)> FilterFunction
Definition: ClearanceMap.h:61
GraphType::edge_descriptor ED
Definition: ClearanceMap.h:55
stapl::sequential::directed_preds_graph< stapl::MULTIEDGES, Point3d, vector< Point3d > > GraphType
Graph type is a directed multiedge graph of points and paths.
Definition: ClearanceMap.h:53
map< ED, double > & GetAnnotatedClearanceMap(FilterFunction &&_f)
Definition: ClearanceMap.h:199
map< ED, double > & GetClearanceMap()
Get the clerance map.
Definition: ClearanceMap.h:84
MPTraits::CfgType CfgType
Definition: ClearanceMap.h:59
Definition: MPBaseObject.h:46
Geometric skeleton of the workspace.
Definition: WorkspaceSkeleton.h:22
bool m_retAllInfo
Consider all collisions or only the first?
Definition: CDInfo.h:173
double m_minDist
Distance between Robot and closest obstacle.
Definition: CDInfo.h:176
void ResetVars(const bool _retAllInfo=false)
Definition: CDInfo.cpp:162
Filtration function.
Definition: ClearanceMap.h:27
Filtration(double _a)
Set the minimum clearance to the given clearance value.
Definition: ClearanceMap.h:29
double m_min
Minimum clearance.
Definition: ClearanceMap.h:28
bool operator()(double _i)
Definition: ClearanceMap.h:34
C CfgType
Definition: ParallelCfgTraits.h:145