/** * @file Graph.h * @brief a simple graph interface for superregion growing * @author Björn Fröhlich * @date 08/19/2009 */ #ifndef GRAPHINCLUDE #define GRAPHINCLUDE #include "vislearning/cbaselib/Example.h" #include namespace OBJREC { class Node { protected: //! list of the neighbor nodes std::vector neighbors; //! is it a borderregion? bool atborder; //! number of the region for lookup in Examples int number; //! actual class label of the region int label; //! size of the region in pixel int size; //! used to compute the centroid of the region int amountx, amounty; //! saving the bounding box int minx, miny, maxx, maxy; //! probabilities for each class std::vector probs; public: /** * simple constructor */ Node(int n); /** * adds a neighbor to the current node * @param nb pointer to a neighbor */ void addNeighbor(Node *nb); /** * set atborder to true if the region is a border region * @param nblabel changed label of the neighbor */ void change(int nblabel); /** * returns the label of the node * @return */ int getLabel() const; /** * return size of region * @return */ int getSize() const; /** * set a new label * @param l */ void setLabel(int l); /** * returns true if region is a borderregion * @return */ bool isAtBorder(); /** * returns the neighbors of the node * @param nb */ void getNeighbors(std::vector &nb) const; /** * returns the number of the region for lookup in Examples * @return */ int getRegion() const; /** * returns the number of the region for lookup in Examples * @return */ int getNumber() const { return number; }; /** * increments the size of the actual region * @param s */ void incSize(int s = 1); /** * add the position of a pixel of the region * used to compute the centroid of the region * @param x * @param y */ void addPos(int x, int y); /** * returns the postion of the centroid of the region * @param x * @param y */ void getCentroid(int &x, int &y) const; /** * set probabilities for each class * @param _probs vector of probabilities */ void setProbs(std::vector _probs); /** * get the max of width and height * @return max of width and height of the region */ int getSpan() const; /** * return the bounding box * @param x0 * @param y0 * @param x1 * @param y1 */ void getRect(int &x0, int &y0, int &x1, int &y1); /** * save node information in filestream * @param fout outputfilestream */ int store(std::ofstream & fout); }; class RegionGraph { protected: //! the nodes of the graph std::vector nodes; public: /** * simple constructor */ RegionGraph() {}; ~RegionGraph(); void get(std::vector &n) const; /** * creates the graph out of a region matrix * @param mask region label for each pixel * @param rgcount number of different regions */ void computeGraph(const NICE::Matrix &mask, const int &rgcount); /** * creates the graph ot of a region matrix mask * @param regions * @param mask */ void computeGraph(const Examples ®ions, const NICE::Matrix &mask); /** * returns the number of nodes * @return number of nodes */ int size() const; /** * get pointer to the i-th node * @param i number of node * @return node */ Node* operator[](int i) const; void write(std::string file); }; } //namespace #endif