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

DualCoding 5.1CVS
Generated Sat May 4 06:29:25 2013 by Doxygen 1.6.3