37 #ifndef VIGRA_GRAPH_MAPS
38 #define VIGRA_GRAPH_MAPS
41 #include "multi_array.hxx"
42 #include "graph_generalization.hxx"
50 template<
class T,
class KEY,
class REF,
class CREF>
51 class DenseReferenceMap
52 :
public MultiArray<1,T>
57 typedef REF Reference;
58 typedef CREF ConstReference;
61 typedef Value value_type;
62 typedef Reference reference;
63 typedef ConstReference const_reference;
64 typedef boost::read_write_property_map_tag category;
72 DenseReferenceMap(
const size_t maxKey)
75 DenseReferenceMap(
const size_t maxKey,ConstReference value)
82 ConstReference operator[](
const KEY & key)
const{
86 Reference operator[](
const KEY & key){
91 return this->shape(0);
94 void assign(
const size_t maxKey){
95 this->
reshape(Shape1Type(maxKey+1));
104 template<
class GRAPH,
class ITEM,
class T,
class REF,
class CREF>
105 class DenseGraphItemReferenceMap
106 :
public DenseReferenceMap<T,ITEM,REF,CREF>
110 typedef DenseReferenceMap<T,ITEM,REF,CREF> DenseReferenceMapType;
111 typedef GraphItemHelper<Graph,ITEM> ItemHelper;
112 typedef typename ItemHelper::ItemIt ItemIt;
115 DenseGraphItemReferenceMap()
116 : DenseReferenceMapType(){
119 DenseGraphItemReferenceMap(
const Graph & g)
120 : DenseReferenceMapType(ItemHelper::itemNum(g)==0 ? 0: ItemHelper::maxItemId(g) ){
123 DenseGraphItemReferenceMap(
const Graph & g,
typename DenseReferenceMapType::ConstReference value)
124 : DenseReferenceMapType(ItemHelper::itemNum(g)==0 ? 0: ItemHelper::maxItemId(g)){
127 void assign(
const Graph & g){
128 DenseReferenceMapType::assign(ItemHelper::itemNum(g)==0 ? 0: ItemHelper::maxItemId(g));
133 template<
class GRAPH,
class T,
class REF= T & ,
class CREF = const T & >
134 class DenseNodeReferenceMap
135 :
public DenseGraphItemReferenceMap<GRAPH,typename GRAPH::Node,T,REF,CREF>
137 typedef typename GRAPH::Node Node;
138 typedef DenseGraphItemReferenceMap<GRAPH,Node,T,REF,CREF> DenseGraphItemReferenceMapType;
140 DenseNodeReferenceMap()
141 : DenseGraphItemReferenceMapType(){
143 DenseNodeReferenceMap(
const GRAPH & g)
144 : DenseGraphItemReferenceMapType(g){
146 DenseNodeReferenceMap(
const GRAPH & g,
typename DenseGraphItemReferenceMapType::ConstReference value)
147 : DenseGraphItemReferenceMapType(g,value){
152 template<
class GRAPH,
class T,
class REF= T & ,
class CREF = const T & >
153 class DenseEdgeReferenceMap
154 :
public DenseGraphItemReferenceMap<GRAPH,typename GRAPH::Edge,T,REF,CREF>
156 typedef typename GRAPH::Edge Edge;
157 typedef DenseGraphItemReferenceMap<GRAPH,Edge,T,REF,CREF> DenseGraphItemReferenceMapType;
159 DenseEdgeReferenceMap()
160 : DenseGraphItemReferenceMapType(){
162 DenseEdgeReferenceMap(
const GRAPH & g)
163 : DenseGraphItemReferenceMapType(g){
165 DenseEdgeReferenceMap(
const GRAPH & g,
typename DenseGraphItemReferenceMapType::ConstReference value)
166 : DenseGraphItemReferenceMapType(g,value){
171 template<
class GRAPH,
class T,
class REF= T & ,
class CREF = const T & >
172 class DenseArcReferenceMap
173 :
public DenseGraphItemReferenceMap<GRAPH,typename GRAPH::Arc,T,REF,CREF>
175 typedef typename GRAPH::Arc Arc;
176 typedef DenseGraphItemReferenceMap<GRAPH,Arc,T,REF,CREF> DenseGraphItemReferenceMapType;
178 DenseArcReferenceMap()
179 : DenseGraphItemReferenceMapType(){
181 DenseArcReferenceMap(
const GRAPH & g)
182 : DenseGraphItemReferenceMapType(g){
184 DenseArcReferenceMap(
const GRAPH & g,
typename DenseGraphItemReferenceMapType::ConstReference value)
185 : DenseGraphItemReferenceMapType(g,value){
195 template<
class G,
class NODE_MAP,
class FUNCTOR,
class RESULT>
196 class OnTheFlyEdgeMap{
200 typedef typename Graph::Node Node;
201 typedef NODE_MAP NodeMap;
202 typedef typename Graph::Edge Key;
203 typedef RESULT Value;
204 typedef RESULT ConstReference;
206 typedef Key key_type;
207 typedef Value value_type;
208 typedef ConstReference const_reference;
210 typedef boost::readable_property_map_tag category;
212 OnTheFlyEdgeMap(
const Graph & graph,
const NodeMap & nodeMap,FUNCTOR & f)
218 ConstReference operator[](
const Key & key){
219 const Node u(graph_.u(key));
220 const Node v(graph_.v(key));
221 return f_(nodeMap_[u],nodeMap_[v]);
224 ConstReference operator[](
const Key & key)
const{
225 const Node u(graph_.u(key));
226 const Node v(graph_.v(key));
227 return f_(nodeMap_[u],nodeMap_[v]);
231 const Graph & graph_;
232 const NodeMap & nodeMap_;
237 template<
class G,
class EDGE_MAP_A,
class EDGE_MAP_B,
class FUNCTOR,
class RESULT>
238 class BinaryOpEdgeMap{
241 typedef typename Graph::Edge Key;
242 typedef RESULT Value;
243 typedef RESULT ConstReference;
245 typedef Key key_type;
246 typedef Value value_type;
247 typedef ConstReference const_reference;
249 typedef boost::readable_property_map_tag category;
251 BinaryOpEdgeMap(
const Graph & graph,
const EDGE_MAP_A & edgeMapA,
const EDGE_MAP_B & edgeMapB,FUNCTOR & f)
257 ConstReference operator[](
const Key & key){
258 return f_(edgeMapA_[key],edgeMapB_[key]);
260 ConstReference operator[](
const Key & key)
const{
261 return f_(edgeMapA_[key],edgeMapB_[key]);
265 const Graph & graph_;
266 const EDGE_MAP_A & edgeMapA_;
267 const EDGE_MAP_B & edgeMapB_;
276 #endif // VIGRA_GRAPH_MAPS