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_graph::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)
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_graph::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_;
238 template<
class G,
class RESULT>
243 typedef typename Graph::Node Key;
244 typedef RESULT Value;
245 typedef RESULT ConstReference;
247 typedef Key key_type;
248 typedef Value value_type;
249 typedef ConstReference const_reference;
250 typedef boost_graph::readable_property_map_tag category;
255 value_type operator[](
const Key &)
const
263 template<
class T_OUT>
266 T_OUT operator()(
const T & a,
const T & b)
const{
267 return static_cast<T_OUT
>(a+b)/static_cast<T_OUT>(2.0);
279 template<
class G,
class NODE_MAP,
class FUNCTOR,
class RESULT>
280 class OnTheFlyEdgeMap2{
284 typedef typename Graph::Node Node;
285 typedef NODE_MAP NodeMap;
286 typedef typename Graph::Edge Key;
287 typedef RESULT Value;
288 typedef RESULT ConstReference;
290 typedef Key key_type;
291 typedef Value value_type;
292 typedef ConstReference const_reference;
294 typedef boost_graph::readable_property_map_tag category;
296 OnTheFlyEdgeMap2(
const Graph & graph,
const NodeMap & nodeMap,FUNCTOR f)
302 ConstReference operator[](
const Key & key){
303 const Node u(graph_.u(key));
304 const Node v(graph_.v(key));
305 return f_(nodeMap_[u],nodeMap_[v]);
308 ConstReference operator[](
const Key & key)
const{
309 const Node u(graph_.u(key));
310 const Node v(graph_.v(key));
311 return f_(nodeMap_[u],nodeMap_[v]);
315 const Graph & graph_;
316 const NodeMap nodeMap_;
322 template<
class G,
class EDGE_MAP_A,
class EDGE_MAP_B,
class FUNCTOR,
class RESULT>
323 class BinaryOpEdgeMap{
326 typedef typename Graph::Edge Key;
327 typedef RESULT Value;
328 typedef RESULT ConstReference;
330 typedef Key key_type;
331 typedef Value value_type;
332 typedef ConstReference const_reference;
334 typedef boost_graph::readable_property_map_tag category;
336 BinaryOpEdgeMap(
const Graph & graph,
const EDGE_MAP_A & edgeMapA,
const EDGE_MAP_B & edgeMapB,FUNCTOR & f)
342 ConstReference operator[](
const Key & key){
343 return f_(edgeMapA_[key],edgeMapB_[key]);
345 ConstReference operator[](
const Key & key)
const{
346 return f_(edgeMapA_[key],edgeMapB_[key]);
350 const Graph & graph_;
351 const EDGE_MAP_A & edgeMapA_;
352 const EDGE_MAP_B & edgeMapB_;
359 template<
class T,
class GRAPH,
class KEY>
362 typedef MultiArrayView<1, T> View;
368 ArrayMap(
const GRAPH & graph)
373 ArrayMap(
const GRAPH & graph,
const View & view)
378 void setArray(
const MultiArrayView<1, T> & view){
382 Reference operator[](
const Key & key){
383 return view_(graph_.id(key));
386 ConstReference operator[](
const Key & key)
const{
387 return view_(graph_.id(key));
389 const GRAPH & graph_;
390 MultiArrayView<1, T> view_;
399 #endif // VIGRA_GRAPH_MAPS
const value_type & const_reference
Definition: multi_array.hxx:727
MultiArray()
Definition: multi_array.hxx:2588
void reshape(const difference_type &shape)
Definition: multi_array.hxx:2861
reference operator()(difference_type_1 x)
Definition: multi_array.hxx:1121
view_type::difference_type difference_type
Definition: multi_array.hxx:2522
value_type & reference
Definition: multi_array.hxx:723
T value_type
Definition: multi_array.hxx:719