00001
00002 #ifndef _BASEDATA_H_
00003 #define _BASEDATA_H_
00004
00005 #include <vector>
00006 #include <iostream>
00007 #include <string>
00008 #include "Wireless/Socket.h"
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;
00060 int refcount;
00061 bool viewable;
00062 rgb color_rgb;
00063
00064 int confidence;
00065 bool mobile;
00066
00067 Sketch<bool>* rendering_sketch;
00068
00069 public:
00070
00071 BaseData(ShapeSpace& _space, ShapeType_t typeval, int _parentId=0);
00072
00073
00074 BaseData(const BaseData& otherData);
00075
00076
00077
00078
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
00116
00117 virtual int getConfidence() const { return confidence; }
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
00128
00129
00130 virtual ShapeType_t getType() const=0;
00131 const char* getTypeName() const;
00132
00133
00134 bool isType(ShapeType_t this_type) const;
00135
00136
00137 bool isSameTypeAs(const ShapeRoot& other) const;
00138
00139
00140
00141
00142
00143
00144 rgb getColor() const { return color_rgb; }
00145
00146
00147
00148 void setColor(std::string const &color_name);
00149 void setColor(rgb new_color);
00150
00151
00152
00153 bool isSameColorAs(const ShapeRoot& other) const;
00154
00155
00156
00157
00158 virtual bool isMatchFor(const ShapeRoot& other) const = 0;
00159
00160
00161
00162
00163
00164 virtual bool isAdmissible() const { return true; }
00165
00166
00167 virtual bool updateParams(const ShapeRoot& other, bool forceUpdate=false) = 0;
00168
00169
00170 virtual bool isInside(const Point&) const { return false; }
00171
00172 virtual unsigned short getDimension() const = 0;
00173
00174
00175
00176 bool isMobile() const;
00177 void setMobile(bool mobility);
00178
00179
00180 void deleteRendering();
00181
00182
00183 virtual Point getCentroid() const=0;
00184
00185 virtual Shape<PointData> getCentroidPtShape() const;
00186
00187
00188 virtual void printParams() const=0;
00189
00190
00191 virtual void applyTransform(const NEWMAT::Matrix& Tmat)=0;
00192
00193
00194 virtual void projectToGround(const NEWMAT::Matrix& camToBase,
00195 const NEWMAT::ColumnVector& groundplane)=0;
00196
00197
00198
00199
00200
00201
00202
00203
00204 Sketch<bool>& getRendering();
00205
00206
00207 virtual Sketch<bool>* render() const=0;
00208
00209
00210
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 }
00224
00225 #endif