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

DualCoding 3.0beta
Generated Wed Oct 4 00:01:53 2006 by Doxygen 1.4.7