1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
//***************************************************************************
//* Copyright (c) 2015 Saint Petersburg State University
//* Copyright (c) 2011-2014 Saint Petersburg Academic University
//* All Rights Reserved
//* See file LICENSE for details.
//***************************************************************************
#pragma once
#include <unordered_map>
//#include "utils.hpp"
#include "visualization/graph_labeler.hpp"
#include "utils/stl_utils.hpp"
#include "assembly_graph/core/action_handlers.hpp"
using namespace omnigraph;
namespace omnigraph {
template<class Graph>
class GraphElementFinder : public GraphActionHandler<Graph> {
private:
typedef typename Graph::VertexId VertexId;
typedef typename Graph::EdgeId EdgeId;
unordered_map<size_t, VertexId> id2vertex_;
unordered_map<size_t, EdgeId> id2edge_;
public:
GraphElementFinder(const Graph &graph) : GraphActionHandler<Graph>(graph, "Graph element finder") {
}
virtual ~GraphElementFinder() {
}
virtual void HandleAdd(EdgeId e) {
#pragma omp critical
{
id2edge_[e.int_id()] = e;
}
}
virtual void HandleAdd(VertexId v) {
#pragma omp critical
{
id2vertex_[v.int_id()] = v;
}
}
virtual void HandleDelete(EdgeId e) {
id2edge_[e.int_id()] = e;
}
virtual void HandleDelete(VertexId v) {
id2vertex_[v.int_id()] = v;
}
VertexId ReturnVertexId(size_t id) const {
auto it = id2vertex_.find(id);
if(it == id2vertex_.end())
return VertexId();
else
return it->second;
}
EdgeId ReturnEdgeId(size_t id) const {
auto it = id2edge_.find(id);
if(it == id2edge_.end())
return EdgeId();
else
return it->second;
}
void Init() {
for(auto it = this->g().begin(); it != this->g().end(); ++it) {
HandleAdd(*it);
for(auto eit = this->g().OutgoingEdges(*it).begin(); eit != this->g().OutgoingEdges(*it).end(); ++eit) {
HandleAdd(*eit);
}
}
}
};
}
|