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   void setSpace(ShapeSpace* _space) { space = _space; }
00071   
00072   ReferenceFrameType_t getRefFrameType() const;
00073 
00074   int getId() const { return id; }
00075   int getParentId() const { return parentId; }
00076   void setParentId(int _pid) { parentId = _pid; }
00077 
00078   bool isViewable() const { return viewable; }
00079   void setViewable(bool _viewable) { viewable = _viewable; }
00080 
00081   int getViewableId() const {
00082     if ( viewable )
00083       return id;
00084     else
00085       return parentId;
00086   }
00087   
00088   void inheritFrom(const BaseData &parent);
00089   void inheritFrom(const ShapeRoot &parent);
00090   void inheritFrom(const SketchDataRoot &parent);
00091 
00092   int getLastMatchId() const { return lastMatchId; }
00093   void setLastMatchId(int _lmid) { lastMatchId = _lmid; }
00094 
00095   const std::string& getName() const { return name; }
00096   void setName(const std::string& _name) { name = _name; }
00097   
00098   void V(std::string const &_name="");
00099   void N(std::string const &_name="");
00100   
00101   virtual void importAdjust() {} //!< Adjust shape components after the shape has been imported (e.g., used by polygons)
00102 
00103   virtual BoundingBox2D getBoundingBox() const { return BoundingBox2D(); }
00104 
00105   //! Confidence.
00106   //@{
00107   virtual int getConfidence() const { return confidence; } //!< returns confidence of Data. Reimpletemnted in PolygonData
00108 
00109   void increaseConfidence(int n=1, int maxConfidence=-1);
00110   void increaseConfidence(const BaseData& other, int maxConfidence=-1);
00111   void increaseConfidence(const ShapeRoot& other, int maxConfidence=-1);
00112 
00113   void decreaseConfidence();
00114 
00115   void setConfidence(const BaseData& other) { confidence = other.getConfidence(); }
00116   //@}
00117   
00118   //! Type.
00119   //@{
00120   //! Get the shape type.
00121   virtual ShapeType_t getType() const=0;
00122   const char* getTypeName() const;
00123   
00124   //! Test the shape type.
00125   bool isType(ShapeType_t this_type) const;
00126   
00127   //! Test if shape types are the same.
00128   bool isSameTypeAs(const ShapeRoot& other) const;
00129   //@}
00130   
00131   
00132   //! Color.
00133   //@{
00134   //! Get the color.
00135   rgb getColor() const { return color_rgb; }
00136   
00137   //! Set shape and rendering sketch color.
00138   //@{
00139   void setColor(const std::string &color_name);
00140   void setColor(const rgb &new_color);
00141   void setColor(const unsigned int color_index);
00142   //@}
00143 
00144   //! Test if shape colors are the same.
00145   bool isSameColorAs(const ShapeRoot& other) const;
00146   
00147   //@}
00148   
00149   //! Shapes match if their coordinates agree.  DOES NOT Assume type and color already checked.
00150   virtual bool isMatchFor(const ShapeRoot& other) const = 0;
00151 
00152   //! Combine two shapes by taking weighted average depending on confidence level.
00153   //  virtual void mergeWith(const ShapeRoot& other) = 0;
00154 
00155   //! Shapes are admissible to the local map if they're large enough not to be noise.
00156   virtual bool isAdmissible() const { return true; }
00157 
00158   //! Update shape parameters after matching to another shape.
00159   virtual bool updateParams(const ShapeRoot& other, bool forceUpdate=false) = 0;
00160 
00161   //! returns if a point is inside the shape or not. Reimplemented by EllipseData, SphereData, PolygonData
00162   virtual bool isInside(const Point&) const { return false; }
00163 
00164   virtual unsigned short getDimension() const = 0;
00165 
00166   //! Mobility
00167   //@{
00168   bool getMobile() const;
00169   void setMobile(bool mobility);
00170   //@}
00171 
00172   virtual bool localizeByCamera() const {return false;}
00173   
00174   bool isObstacle() const { return obstacle; }
00175   void setObstacle(bool _obstacle=true) { obstacle = _obstacle; }
00176   
00177   bool isLandmark() const { return landmark; }
00178   void setLandmark(bool _landmark=true) { landmark = _landmark; }
00179   
00180   void deleteRendering();
00181 
00182   //! return the centroid of the shape in point format
00183   virtual Point getCentroid() const=0;
00184 
00185   virtual Shape<PointData> getCentroidPtShape() const;
00186   
00187   //! Set the position of a shape
00188   virtual void setPosition(const Point &pt);
00189 
00190   //! Prints information about this shape.
00191   virtual void printParams() const=0;
00192   
00193   //! Apply a transformation matrix to the shape.
00194   virtual void applyTransform(const fmat::Transform& Tmat, const ReferenceFrameType_t newref=unspecified)=0;
00195   
00196   //! Project to ground plane using given matrix
00197   virtual void projectToGround(const fmat::Transform& camToBase,
00198              const PlaneEquation& groundplane)=0;
00199     
00200   //! Update properties of the shape derived from endpoints or other basic parameters.
00201   //  virtual void update_derived_properties() {}
00202   
00203   //! Rendering.
00204   //@{
00205   //! Returns a pointer to the rendering associated with the ShapeRoot object.
00206   //! If no such rendering exists, it is created.
00207   Sketch<bool>& getRendering();
00208   
00209 private:
00210   //! Render into a sketch space.
00211   virtual Sketch<bool>* render() const=0;
00212   
00213   //@}
00214 
00215 public:
00216   //! Assignment 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 5.1CVS
Generated Mon May 9 04:56:25 2016 by Doxygen 1.6.3