Direct Graphical Models  v.1.7.0
GraphPairwiseExt.h
1 // Extended (pairwise) Graph class interface;
2 // Written by Sergey Kosov in 2016 for Project X
3 #pragma once
4 
5 #include "GraphExt.h"
6 #include "GraphLayeredExt.h"
7 
8 namespace DirectGraphicalModels
9 {
10  class IGraphPairwise;
11 
12  // ================================ Extended Pairwise Graph Class ================================
20  {
21  public:
27  DllExport CGraphPairwiseExt(IGraphPairwise& graph, byte gType = GRAPH_EDGES_GRID)
28  : m_pGraphLayeredExt(std::make_unique<CGraphLayeredExt>(graph, 1, gType))
29  {}
30  DllExport virtual ~CGraphPairwiseExt(void) = default;
31 
32  // From CGraphExt
33  DllExport void buildGraph(Size graphSize) override
34  {
35  m_pGraphLayeredExt->buildGraph(graphSize);
36  }
37  DllExport void setGraph(const Mat& pots) override
38  {
39  m_pGraphLayeredExt->setGraph(pots, Mat());
40  }
46  DllExport void addDefaultEdgesModel(float val, float weight = 1.0f) override;
53  DllExport void addDefaultEdgesModel(const Mat& featureVectors, float val, float weight = 1.0f) override;
60  DllExport void addDefaultEdgesModel(const vec_mat_t& featureVectors, float val, float weight = 1.0f) override;
61  DllExport Size getSize() const override
62  {
63  return m_pGraphLayeredExt->getSize();
64  }
65 
75  DllExport void addFeatureVecs(CTrainEdge &edgeTrainer, const Mat &featureVectors, const Mat &gt)
76  {
77  m_pGraphLayeredExt->addFeatureVecs(edgeTrainer, featureVectors, gt);
78  }
88  DllExport void addFeatureVecs(CTrainEdge &edgeTrainer, const vec_mat_t &featureVectors, const Mat &gt)
89  {
90  m_pGraphLayeredExt->addFeatureVecs(edgeTrainer, featureVectors, gt);
91  }
102  DllExport void fillEdges(const CTrainEdge& edgeTrainer, const Mat& featureVectors, const vec_float_t& vParams, float weight = 1.0f)
103  {
104  m_pGraphLayeredExt->fillEdges(edgeTrainer, NULL, featureVectors, vParams, weight);
105  }
116  DllExport void fillEdges(const CTrainEdge& edgeTrainer, const vec_mat_t& featureVectors, const vec_float_t& vParams, float weight = 1.0f)
117  {
118  m_pGraphLayeredExt->fillEdges(edgeTrainer, NULL, featureVectors, vParams, weight);
119  }
128  DllExport void defineEdgeGroup(float A, float B, float C, byte group)
129  {
130  m_pGraphLayeredExt->defineEdgeGroup(A, B, C, group);
131  }
137  DllExport void setEdges(std::optional<byte> group, const Mat &pot)
138  {
139  m_pGraphLayeredExt->setEdges(group, pot);
140  }
145  DllExport byte getType(void) const
146  {
147  return m_pGraphLayeredExt->getType();
148  }
149 
150 
151  private:
152  std::unique_ptr<CGraphLayeredExt> m_pGraphLayeredExt;
153  };
154 }
CGraphPairwiseExt(IGraphPairwise &graph, byte gType=GRAPH_EDGES_GRID)
Constructor.
void addFeatureVecs(CTrainEdge &edgeTrainer, const vec_mat_t &featureVectors, const Mat &gt)
Adds a block of new feature vectors.
void fillEdges(const CTrainEdge &edgeTrainer, const Mat &featureVectors, const vec_float_t &vParams, float weight=1.0f)
Fills the graph edges with potentials.
Vertical and horizontal edges.
Extended Pairwise graph class for 2D image classifaction.
Base abstract class for edge potentials training.
Definition: TrainEdge.h:24
Size getSize() const override
Returns the size of the graph.
General graph extension abstract class for 2D image classifaction.
Definition: GraphExt.h:16
byte getType(void) const
Returns the type of the graph.
STL namespace.
Extended Pairwise Layered graph class.
void defineEdgeGroup(float A, float B, float C, byte group)
Assign the edges, which cross the given line to the grop group.
void addDefaultEdgesModel(float val, float weight=1.0f) override
Adds default data-independet edge model.
void setGraph(const Mat &pots) override
Fills an existing 2D graph with potentials or builds a new 2D graph of size corresponding to pots...
void addFeatureVecs(CTrainEdge &edgeTrainer, const Mat &featureVectors, const Mat &gt)
Adds a block of new feature vectors.
void buildGraph(Size graphSize) override
Builds a 2D graph of size corresponding to the image resolution.
Interface class for graphical models.
std::unique_ptr< CGraphLayeredExt > m_pGraphLayeredExt
void fillEdges(const CTrainEdge &edgeTrainer, const vec_mat_t &featureVectors, const vec_float_t &vParams, float weight=1.0f)
Fills the graph edges with potentials.
virtual ~CGraphPairwiseExt(void)=default
void setEdges(std::optional< byte > group, const Mat &pot)
Sets potential pot to all edges in the group group.