minstcutibfs.hxx

Go to the documentation of this file.
00001 #pragma once
00002 #ifndef OPENGM_MINSTCUTIBFS_HXX
00003 #define OPENGM_MINSTCUTIBFS_HXX
00004 
00005 #include <queue> 
00006 #include <cassert>
00007 #include "../src/external/ibfs.src-patched/ibfs.h"
00008 //#include "MaxFlow-v3.01/graph.h"
00009 
00010 namespace opengm {
00011   namespace external {
00012 
00014     template<class NType, class VType>
00015     class MinSTCutIBFS{
00016     public:
00017       // Type-Definitions
00018       typedef NType node_type;
00019       typedef VType ValueType;
00020       typedef IBFSGraph<ValueType,ValueType,ValueType> graph_type;
00021       //typedef maxflowLib::Graph<ValueType,ValueType,ValueType> graph_type;
00022      
00023       // Methods
00024       MinSTCutIBFS();
00025       MinSTCutIBFS(size_t numberOfNodes, size_t numberOfEdges);
00026       void addEdge(node_type,node_type,ValueType);
00027       void calculateCut(std::vector<bool>&);
00028       
00029     private: 
00030       // Members
00031       graph_type* graph_;
00032       size_t      numberOfNodes_;
00033       size_t      numberOfEdges_;
00034       static const NType S = 0;
00035       static const NType T = 1;
00036     };
00037     
00038     //*********************
00039     //** Implementation  **
00040     //*********************
00041     
00042     template<class NType, class VType>
00043     MinSTCutIBFS<NType,VType>::MinSTCutIBFS() {
00044       numberOfNodes_ = 2;
00045       numberOfEdges_ = 0;
00046       graph_         = NULL;
00047     };
00048 
00049     template<class NType, class VType>
00050     MinSTCutIBFS<NType,VType>::MinSTCutIBFS(size_t numberOfNodes, size_t numberOfEdges) {
00051       numberOfNodes_ = numberOfNodes;
00052       numberOfEdges_ = numberOfEdges;
00053       graph_         = new graph_type(numberOfNodes_-2,numberOfEdges_);
00054       //for(size_t i=0; i<numberOfNodes_-2;++i)
00055       //  graph_->add_node(); 
00056     };
00057  
00058 
00059     template<class NType, class VType>
00060     void MinSTCutIBFS<NType,VType>::addEdge(node_type n1, node_type n2, ValueType cost) {
00061       assert(n1 < numberOfNodes_);
00062       assert(n2 < numberOfNodes_);
00063       assert(cost >= 0);
00064       if(n1==S) {
00065    graph_->add_tweights( n2-2,   /* capacities */  cost, 0);
00066       }else if(n2==T) {
00067    graph_->add_tweights( n1-2,   /* capacities */  0, cost);
00068       }else{
00069    graph_->add_edge( n1-2, n2-2,    /* capacities */  cost, 0 );
00070       }
00071     };
00072    
00073     template<class NType, class VType>
00074     void MinSTCutIBFS<NType,VType>::calculateCut(std::vector<bool>& segmentation) {  
00075       int flow = graph_->maxflow(); 
00076       segmentation.resize(numberOfNodes_);
00077       for(size_t i=2; i<numberOfNodes_; ++i) {
00078    if (graph_->what_segment(i-2) == graph_type::SOURCE)
00079      segmentation[i]=false;
00080    else
00081      segmentation[i]=true;
00082       }  
00083       return;
00084     };
00085 
00086   } //namespace external
00087 } // namespace opengm
00088 
00089 #endif // #ifndef OPENGM_MINSTCUTIBFS_HXX
00090 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Mon Jun 17 16:31:04 2013 for OpenGM by  doxygen 1.6.3