Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

BlobData.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef _BLOBDATA_H_
00003 #define _BLOBDATA_H_
00004 
00005 #include <vector>
00006 #include <set>
00007 #include <map>
00008 #include <iostream>
00009 #include <string>
00010 
00011 #include "Shared/newmat/newmat.h"
00012 #include "Vision/cmv_types.h"
00013 
00014 #include "BaseData.h"      // superclass
00015 #include "Point.h"         // Point data member
00016 #include "SketchTypes.h"   // uchar
00017 #include "ShapeTypes.h"    // blobDataType
00018 #include "ShapeFuns.h"
00019 
00020 namespace DualCoding {
00021 
00022 class ShapeRoot;
00023 template<typename T> class Sketch;
00024 
00025 //! Blob shapes, described by bounding boxes and an optional list of runs.
00026 
00027 class BlobData : public BaseData {
00028  public:
00029 
00030   //! Assumed orientation of the blob in 3D space.
00031   enum BlobOrientation_t {
00032     groundplane,  //!< 2D shape lying flat on the ground
00033     pillar,       //!< 3D shape standing on the ground
00034     poster        //!< 3D shape hanging vertically in space
00035   };
00036 
00037   struct run {
00038   public:
00039     unsigned short int x, y, width;
00040     run() : x(0), y(0), width(0) {}
00041     run(unsigned short int _x, unsigned short int _y, unsigned short int _width) :
00042       x(_x), y(_y), width(_width) {}
00043   };
00044 
00045   // Data members
00046   BlobOrientation_t orientation; //!< Orientation of the blob
00047   coordinate_t assumedHeight; //!< Assumed height above ground of blob centroid (for poster) or top (for pillar)
00048   //! Bounding quadrilateral: may not be square when projected to ground space.
00049   Point topLeft, topRight, bottomLeft, bottomRight;
00050   float area; //!< Area of the blob; may not be integer when projected to ground space
00051   const std::vector<run> runvec; //!< Runs (for rendering in camera space)
00052 
00053  public:
00054   //! Constructor
00055   BlobData(ShapeSpace& _space,
00056      const Point &_topLeft, const Point &_topRight,
00057      const Point &_bottomLeft, const Point &_bottomRight,
00058      const float _area=0,
00059      const std::vector<run> &_runvec=std::vector<run>(), 
00060      const BlobOrientation_t _orientation=groundplane,
00061      const coordinate_t assumedHeight=0,
00062      const rgb rgbvalue=rgb());
00063 
00064   static ShapeType_t getStaticType() { return blobDataType; }
00065 
00066   DATASTUFF_H(BlobData);
00067 
00068   friend class Shape<BlobData>;
00069 
00070   //! return the centroid of the shape in point format
00071   virtual Point getCentroid() const;
00072   
00073   //! Area of the blob
00074   float getArea() { return area; }
00075 
00076   //! Print information about this shape.
00077   virtual void printParams() const;
00078 
00079   //! Transformations. (Virtual in BaseData.)
00080   virtual void applyTransform(const NEWMAT::Matrix& Tmat, const ReferenceFrameType_t newref=unspecified);
00081   
00082   //! Project to ground
00083   //  virtual void projectToGround(int xres, int yres, const NEWMAT::ColumnVector& groundplane);
00084   virtual void projectToGround(const NEWMAT::Matrix& camToBase,
00085              const NEWMAT::ColumnVector& groundplane);
00086 
00087   //! Update derived properties
00088   virtual void update_derived_properties();
00089 
00090   //! Match blobs based on their parameters.  (Virtual in BaseData.)
00091   virtual bool isMatchFor(const ShapeRoot& other) const;
00092 
00093   virtual bool updateParams(const ShapeRoot& other, bool forceUpdate=false);
00094 
00095   virtual unsigned short getDimension() const { return (orientation==groundplane) ? 2 : 3; }
00096 
00097 
00098   //! Import blobs from Sketch<bool> as a vector of Shape<BlobData>
00099   static std::vector<Shape<BlobData> > 
00100   extractBlobs(const Sketch<bool> &sketch,
00101          int minarea=25,
00102          BlobOrientation_t orient=BlobData::groundplane, 
00103          coordinate_t height=0,
00104          int maxblobs=50); 
00105 
00106   //! Import blobs of all colors from Sketch<uchar> as a vector of Shape<BlobData>
00107   static std::vector<Shape<BlobData> >
00108   extractBlobs(const Sketch<uchar> &sketch,
00109          int minarea=25,
00110          BlobOrientation_t orient=BlobData::groundplane,
00111          const coordinate_t height=0,
00112          int maxblobs=50);
00113 
00114   //! Import blobs of specified colors from Sketch<uchar> as a vector of Shape<BlobData>
00115   static std::vector<Shape<BlobData> >
00116   extractBlobs(const Sketch<uchar> &sketch, 
00117          const std::set<color_index>& colors,
00118          const std::map<color_index,int>& minareas,
00119          const std::map<color_index,BlobOrientation_t>& orients,
00120          const std::map<color_index,coordinate_t>& heights,
00121          int maxblobs);
00122 
00123   //! Utility function for making a new blob instance from CMVision's region data structures
00124   static BlobData* new_blob(ShapeSpace& space,
00125      const CMVision::region &reg, 
00126      const CMVision::run<CMVision::uchar> *rle_buff,
00127      const BlobOrientation_t orient,
00128      const coordinate_t height,
00129      const rgb rgbvalue);
00130 
00131   //!@name Corner extraction for rectangular blobs
00132   //@{
00133   std::vector<Point> findCorners(unsigned int nExpected, std::vector<Point>& candidates, float &bestValue);
00134   std::vector<Point> findCornersDerivative();
00135   std::vector<Point> findCornersDiagonal();
00136   std::vector<Point> findCornersShapeFit(unsigned int ncorners, std::vector<Point>& candidates, float &bestValue);
00137   //@}
00138 
00139  // comparison predicates
00140 
00141   class AreaLessThan : public BinaryShapePred<BlobData> {
00142   public:
00143     bool operator() (const Shape<BlobData> &b1, const Shape<BlobData> &b2) const;
00144   };
00145 
00146 private:
00147   //! Render into a sketch space and return reference. (Private.)
00148   virtual Sketch<bool>* render() const;
00149 
00150   BlobData& operator=(const BlobData&); //!< don't call
00151 
00152 };
00153 
00154 } // namespace
00155 
00156 #endif // BLOBDATA_H_

DualCoding 4.0
Generated Thu Nov 22 00:52:36 2007 by Doxygen 1.5.4