PlanarGC  1.0.2
 All Data Structures Functions Variables Enumerations Enumerator Friends Pages
Planar.h
1 /*****************************************************************************
2 * PlanarCut - software to compute MinCut / MaxFlow in a planar graph *
3 * Version 1.0 *
4 * *
5 * Copyright 2011 Eno Töppe <toeppe@in.tum.de> *
6 * Frank R. Schmidt <fschmidt@uwo.ca> *
7 ******************************************************************************
8 
9  If you use this software for research purposes, YOU MUST CITE the following
10  paper in any resulting publication:
11 
12  [1] Efficient Planar Graph Cuts with Applications in Computer Vision.
13  F. R. Schmidt, E. Töppe, D. Cremers,
14  IEEE CVPR, Miami, Florida, June 2009
15 
16 ******************************************************************************
17 
18  This software is released under the LGPL license. Details are explained
19  in the files 'COPYING' and 'COPYING.LESSER'.
20 
21 *****************************************************************************/
22 
23 #ifndef __PLANAR_H
24 #define __PLANAR_H
25 
26 #include "CutPlanarDefs.h"
27 
28 
29 class PlanarVertex; //forward declaration
30 class PlanarEdge; //forward declaration
31 class PlanarFace
37 {};
38 
39 class PlanarEdge
52 {
53  friend class PlanarVertex; //for efficiency vertex and edge are closely connected
54 
55  CapType cap; //forward edge capacity
56  CapType rcap; //backward edge capacity
57 
58  PlanarVertex *tail; //an edge points from the tail vertex
59  PlanarVertex *head; //to the head vertex.
60 
61  PlanarFace *tailDual; //the face left of the edge wrt. the pointing direction
62  PlanarFace *headDual; //the face right of the edge wrt. the pointing direction
63 
64  //these are for fast access to edge IDs
65  int tailEdgeID; //the ID of this edge with respect to the tail vertex
66  int headEdgeID; //the ID of this edge with respect to the head vertex
67 
68  uchar flags; //a maximum of 8 flags that can be used freely
69 
70 
71 public:
72 
76  PlanarEdge();
78  CapType getCapacity() { return cap; }
80  CapType getRevCapacity() { return rcap; }
81 
84  void setCapacity(CapType cap) { this->cap = cap; }
87  void setRevCapacity(CapType rcap) { this->rcap = rcap; }
88 
92  void setEdge(PlanarVertex *tail, PlanarVertex *head,
93  PlanarFace *tailDual, PlanarFace *headDual,
94  CapType cap=1.0, CapType rcap=0.0);
95 
97  void setFlags(uchar value) { flags = value; }
99  uchar getFlags() { return flags; }
100 
102  PlanarVertex *getHead() { return head; }
104  PlanarVertex *getTail() { return tail; }
106  PlanarFace *getHeadDual() { return headDual; }
108  PlanarFace *getTailDual() { return tailDual; }
109 
110 };
111 
128 {
129  friend class PlanarEdge; //for efficiency vertex and edge are closely connected
130 
131  int nEdges; //number of adjacent edges
132  PlanarEdge **edgesCCW; //ccw list of adjacent edges
133 
134  public:
136  PlanarVertex();
138  ~PlanarVertex();
139 
141  int getNumEdges() { return nEdges; };
154  PlanarEdge *getEdge(int id) { id=id%nEdges; return (id<0)?edgesCCW[id+nEdges]:edgesCCW[id]; };
159  inline void setEdgesCCW(PlanarEdge **ccw, int nEdges);
163  inline int getEdgeID(PlanarEdge *e);
164 };
165 
166 
167 /***************************************************
168  *** PlanarVertex INLINE ***************************
169  ***************************************************/
170 void PlanarVertex::setEdgesCCW(PlanarEdge **ccw, int nEdges) {
171 
172  if (nEdges != this->nEdges) {
173  if (this->nEdges)
174  delete [] edgesCCW;
175  if (nEdges)
176  edgesCCW = new PlanarEdge*[nEdges];
177  this->nEdges = nEdges;
178  }
179  for (int i=0; i<nEdges; i++) {
180  edgesCCW[i] = ccw[i];
181  if (edgesCCW[i]->getTail() == this)
182  edgesCCW[i]->tailEdgeID = i;
183  else if (edgesCCW[i]->getHead() == this)
184  edgesCCW[i]->headEdgeID = i;
185  }
186 
187 }
188 
189 
191  //for efficiency edge IDs are stored in the edges themselves
192  if (e->getTail() == this)
193  return e->tailEdgeID;
194  else if (e->getHead() == this)
195  return e->headEdgeID;
196  else
197  return -1;
198 }
199 
200 #endif
© 2009 - 2013 by Eno Töppe, Frank R. Schmidt
generated by Doxygen