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 "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
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
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;
00063 int refcount;
00064 bool viewable;
00065 rgb color_rgb;
00066
00067 int confidence;
00068 bool mobile;
00069
00070 Sketch<bool>* rendering_sketch;
00071
00072 public:
00073
00074 BaseData(ShapeSpace& _space, ShapeType_t typeval, int _parentId=0);
00075
00076
00077 BaseData(const BaseData& otherData);
00078
00079
00080
00081
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
00119
00120 virtual int getConfidence() const { return confidence; }
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
00131
00132
00133 virtual ShapeType_t getType() const=0;
00134 const char* getTypeName() const;
00135
00136
00137 bool isType(ShapeType_t this_type) const;
00138
00139
00140 bool isSameTypeAs(const ShapeRoot& other) const;
00141
00142
00143
00144
00145
00146
00147 rgb getColor() const { return color_rgb; }
00148
00149
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
00157 bool isSameColorAs(const ShapeRoot& other) const;
00158
00159
00160
00161
00162 virtual bool isMatchFor(const ShapeRoot& other) const = 0;
00163
00164
00165
00166
00167
00168 virtual bool isAdmissible() const { return true; }
00169
00170
00171 virtual bool updateParams(const ShapeRoot& other, bool forceUpdate=false) = 0;
00172
00173
00174 virtual bool isInside(const Point&) const { return false; }
00175
00176 virtual unsigned short getDimension() const = 0;
00177
00178
00179
00180 bool getMobile() const;
00181 void setMobile(bool mobility);
00182
00183
00184 void deleteRendering();
00185
00186
00187 virtual Point getCentroid() const=0;
00188
00189 virtual Shape<PointData> getCentroidPtShape() const;
00190
00191
00192 virtual void printParams() const=0;
00193
00194
00195 virtual void applyTransform(const NEWMAT::Matrix& Tmat, const ReferenceFrameType_t newref=unspecified)=0;
00196
00197
00198 virtual void projectToGround(const NEWMAT::Matrix& camToBase,
00199 const NEWMAT::ColumnVector& groundplane)=0;
00200
00201
00202
00203
00204
00205
00206
00207
00208 Sketch<bool>& getRendering();
00209
00210 private:
00211
00212 virtual Sketch<bool>* render() const=0;
00213
00214
00215 public:
00216
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 }
00230
00231 #endif