Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

Region.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_Region_h
00003 #define INCLUDED_Region_h
00004 
00005 #include <list>
00006 
00007 #include "Shared/Measures.h"
00008 
00009 #include "Point.h"
00010 #include "LineData.h"
00011 #include "SketchIndices.h"
00012 #include "Sketch.h"
00013 
00014 namespace DualCoding {
00015 
00016 class SketchSpace;
00017 
00018 #define MAX_MOMENT 5
00019 
00020 class Region : public SketchIndices {
00021 public:
00022   Region(const SketchSpace& _space); //!< initializes all properties to be NOTCOMPUTED
00023   ~Region() {};
00024   
00025   //! Returns a list of the different Regions in labels, sorted by area
00026   //@param labels Each different region in labels should have a different number assigned to it
00027   //@param area_thresh Minimum allowed area of a region
00028   static std::list<Region> extractRegions(const Sketch<uint>& labels, uint area_thresh = 10);
00029 
00030   //! Return a single region from a Sketch<bool>
00031   static Region extractRegion(const Sketch<bool>& sketch);
00032   
00033   //! Render a region as a Sketch<bool>
00034   Sketch<bool> getRendering() const { return SketchIndices::getRendering(const_cast<SketchSpace&>(space)); }
00035 
00036   //! Compares areas of two Regions; really only used to sort Regions
00037   //! assumes area already calculated
00038   //! Notes that it actually returns greater-than instead of less-than, so
00039   //! that lists are sorted with biggest areas first
00040   bool operator< (const Region& other) const;
00041   
00042 
00043   //! sets all properties to be NOTCOMPUTED
00044   //! called after making changes (either addition/deletion) to table
00045   void recomputeProperties();
00046 
00047   int findTopBound();
00048   int findBotBound();
00049   int findLeftBound();
00050   int findRightBound();
00051 
00052   Point findTopBoundPoint();
00053   Point findBotBoundPoint();
00054   Point findLeftBoundPoint();
00055   Point findRightBoundPoint();
00056   bool isContained(const Point&, const uint max_dist=0);
00057 
00058   Point mostDistantPtFrom(const LineData&);
00059   
00060   //! Calculates the two-dimensional Cartesian moment Mpq 
00061   float findMoment(size_t p, size_t q);
00062   float findCentralMoment(size_t p, size_t q);
00063   //! Finds the area-normalized central moment
00064   float findNormCentralMoment(size_t p, size_t q);
00065   
00066   int findArea();
00067   Point findCentroid(); //!< returns coords of center of mass
00068   
00069   //! Returns the angle of the orientation of the principal axis in radians
00070   AngPi findPrincipalAxisOrientation();
00071   
00072   //! Returns the length of the semi-major (x) axis of the image ellipse
00073   float findSemiMajorAxisLength();
00074   
00075   //! Returns the length of the semi-minor (y) axis of the image ellipse
00076   float findSemiMinorAxisLength();
00077   
00078   float findRadius() { return findSemiMajorAxisLength(); } //FIX THIS
00079 
00080 private:
00081   const SketchSpace& space;
00082   
00083   int topBound;
00084   int botBound;
00085   int leftBound;
00086   int rightBound;
00087   
00088   float moments[MAX_MOMENT+1][MAX_MOMENT+1];
00089   float cmoments[MAX_MOMENT+1][MAX_MOMENT+1];
00090   
00091   int area;
00092   
00093   int findXcoordFor(const coordinate_t y_coord);
00094   int findYcoordFor(const coordinate_t x_coord);
00095   
00096 public:
00097   const SketchSpace& getSpace() const { return space; };
00098   Region& operator=(const Region &other);
00099 };
00100 
00101 } // namespace
00102 
00103 #endif

DualCoding 5.1CVS
Generated Mon May 9 04:56:27 2016 by Doxygen 1.6.3