Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

BaseData.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef _BASEDATA_H_
00003 #define _BASEDATA_H_
00004 
00005 #include <vector>
00006 #include <iostream>
00007 #include <string>
00008 #include "Wireless/Socket.h" // needed for sout
00009 
00010 #include "Macrodefs.h"
00011 #include "Shared/Measures.h"
00012 #include "Point.h"
00013 #include "Shared/newmat/newmat.h"
00014 #include "Motion/Kinematics.h"
00015 #include "ShapeTypes.h"
00016 #include "Vision/colors.h"
00017 
00018 namespace DualCoding {
00019 
00020 class Point;
00021 class PointData;
00022 class SketchSpace;
00023 template<typename T> class Sketch;
00024 class ShapeRoot;
00025 class ShapeSpace;
00026 class SketchDataRoot;
00027 template<typename T> class Shape;
00028 
00029 //! Bounding box of a shape; used for coordinate calculations
00030 class BoundingBox {
00031 public:
00032   coordinate_t xmin, ymin, xmax, ymax;
00033 
00034   BoundingBox(coordinate_t _xmin, coordinate_t _ymin, coordinate_t _xmax, coordinate_t _ymax) :
00035    xmin(_xmin), ymin(_ymin), xmax(_xmax), ymax(_ymax) {}
00036 
00037   BoundingBox() : xmin(0), ymin(0), xmax(0), ymax(0) {}
00038 
00039   BoundingBox(const Point &p) :
00040     xmin(p.coordX()), ymin(p.coordY()), xmax(p.coordX()), ymax(p.coordY()) {}
00041 
00042   BoundingBox(const BoundingBox &b1, const BoundingBox &b2);
00043 
00044   BoundingBox(const std::vector<ShapeRoot> &vec);
00045 
00046 };
00047 
00048 std::ostream& operator<< (std::ostream& out, const BoundingBox &b);
00049 
00050 //! Base class that all shape data classes inherit from, e.g., @a LineData, @a BlobData, etc.
00051 class BaseData {
00052 public:
00053   friend class ShapeRoot;
00054   friend class ShapeSpace;
00055   
00056 protected:
00057   ShapeSpace *space;
00058   std::string name;
00059   ShapeType_t type; 
00060   int id;
00061   int parentId;
00062   int lastMatchId;      //!< Id of the shape in the preceding space that gave rise to or was matched to this one.
00063   int refcount;
00064   bool viewable;
00065   rgb color_rgb;
00066   
00067   int confidence;       //!< Confidence that this shape exists and isn't noise.
00068   bool mobile;    //!< True if this shape can move in the world
00069   
00070   Sketch<bool>* rendering_sketch;
00071 
00072 public:
00073   //! Constructor
00074   BaseData(ShapeSpace& _space, ShapeType_t typeval, int _parentId=0);
00075 
00076   //! Copy constructor
00077   BaseData(const BaseData& otherData);
00078   
00079   // BaseData(ShapeType_t typeval, int _parentID=0);
00080 
00081   //! Destructor.
00082   virtual ~BaseData(void);
00083 
00084   virtual BaseData* clone(void) const = 0;
00085   
00086   ShapeSpace& getSpace() const { return *space; }
00087   ReferenceFrameType_t getRefFrameType() const;
00088 
00089   int getId() const { return id; }
00090   int getParentId() const { return parentId; }
00091   void setParentId(int _pid) { parentId = _pid; }
00092 
00093   bool isViewable() const { return viewable; }
00094   void setViewable(bool _viewable) { viewable = _viewable; }
00095 
00096   int getViewableId() const {
00097     if ( viewable )
00098       return id;
00099     else
00100       return parentId;
00101   }
00102   
00103   void inheritFrom(const BaseData &parent);
00104   void inheritFrom(const ShapeRoot &parent);
00105   void inheritFrom(const SketchDataRoot &parent);
00106 
00107   int getLastMatchId() const { return lastMatchId; }
00108   void setLastMatchId(int _lmid) { lastMatchId = _lmid; }
00109 
00110   const std::string& getName() const { return name; }
00111   void setName(const std::string& _name) { name = _name; }
00112   
00113   void V(std::string const &_name="");
00114   void N(std::string const &_name="");
00115   
00116   virtual BoundingBox getBoundingBox() const { return BoundingBox(); }
00117 
00118   //! Confidence.
00119   //@{
00120   virtual int getConfidence() const { return confidence; } //!< returns confidence of Data. Reimpletemnted in PolygonData
00121 
00122   void increaseConfidence(int n=1, int maxConfidence=-1);
00123   void increaseConfidence(const BaseData& other, int maxConfidence=-1);
00124   void increaseConfidence(const ShapeRoot& other, int maxConfidence=-1);
00125 
00126   void decreaseConfidence() { confidence--; }
00127   void setConfidence(const BaseData& other) { confidence = other.getConfidence(); }
00128   //@}
00129   
00130   //! Type.
00131   //@{
00132   //! Get the shape type.
00133   virtual ShapeType_t getType() const=0;
00134   const char* getTypeName() const;
00135   
00136   //! Test the shape type.
00137   bool isType(ShapeType_t this_type) const;
00138   
00139   //! Test if shape types are the same.
00140   bool isSameTypeAs(const ShapeRoot& other) const;
00141   //@}
00142   
00143   
00144   //! Color.
00145   //@{
00146   //! Get the color.
00147   rgb getColor() const { return color_rgb; }
00148   
00149   //! Set shape and rendering sketch color.
00150   //@{
00151   void setColor(const std::string &color_name);
00152   void setColor(const rgb &new_color);
00153   void setColor(const unsigned int color_index);
00154   //@}
00155 
00156   //! Test if shape colors are the same.
00157   bool isSameColorAs(const ShapeRoot& other) const;
00158   
00159   //@}
00160   
00161   //! Shapes match if their coordinates agree.  DOES NOT Assume type and color already checked.
00162   virtual bool isMatchFor(const ShapeRoot& other) const = 0;
00163 
00164   //! Combine two shapes by taking weighted average depending on confidence level.
00165   //  virtual void mergeWith(const ShapeRoot& other) = 0;
00166 
00167   //! Shapes are admissible to the local map if they're large enough not to be noise.
00168   virtual bool isAdmissible() const { return true; }
00169 
00170   //! Update shape parameters after matching to another shape.
00171   virtual bool updateParams(const ShapeRoot& other, bool forceUpdate=false) = 0;
00172 
00173   //! returns if a point is inside the shape or not. Reimplemented by EllipseData, SphereData, PolygonData
00174   virtual bool isInside(const Point&) const { return false; }
00175 
00176   virtual unsigned short getDimension() const = 0;
00177 
00178   //! Mobility
00179   //@{
00180   bool getMobile() const;
00181   void setMobile(bool mobility);
00182   //@}
00183   
00184   void deleteRendering();
00185 
00186   //! return the centroid of the shape in point format
00187   virtual Point getCentroid() const=0;
00188 
00189   virtual Shape<PointData> getCentroidPtShape() const;
00190   
00191   //! Prints information about this shape.
00192   virtual void printParams() const=0;
00193   
00194   //! Apply a transformation matrix to the shape.
00195   virtual void applyTransform(const NEWMAT::Matrix& Tmat, const ReferenceFrameType_t newref=unspecified)=0;
00196   
00197   //! Project to ground plane using given matrix
00198   virtual void projectToGround(const NEWMAT::Matrix& camToBase,
00199              const NEWMAT::ColumnVector& groundplane)=0;
00200   
00201   //! Update properties of the shape derived from endpoints or other basic parameters.
00202   //  virtual void update_derived_properties() {}
00203   
00204   //! Rendering.
00205   //@{
00206   //! Returns a pointer to the rendering associated with the ShapeRoot object.
00207   //! If no such rendering exists, it is created.
00208   Sketch<bool>& getRendering();
00209   
00210 private:
00211   //! Render into a sketch space.
00212   virtual Sketch<bool>* render() const=0;
00213   //@}
00214 
00215 public:
00216   //! Copy operator. Assumes "&other =? this" check is done by the sub class calling this operator
00217   BaseData& operator=(const BaseData& other); 
00218 };
00219 
00220 #define DATASTUFF_H(T) \
00221   virtual ShapeType_t getType() const { return getStaticType(); } \
00222   virtual BaseData* clone() const; \
00223   Shape<T> copy() const;
00224 
00225 #define DATASTUFF_CC(T) \
00226   BaseData* T::clone() const { return new T(*this); } \
00227   Shape<T> T::copy() const { return Shape<T>((T*)clone()); }
00228 
00229 } // namespace
00230 
00231 #endif

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