00001
00002 #ifndef _POLYGONDATA_H_
00003 #define _POLYGONDATA_H_
00004
00005 #include <vector>
00006 #include <iostream>
00007 #include <string>
00008
00009 #include "BaseData.h"
00010 #include "LineData.h"
00011 #include "Shared/Measures.h"
00012
00013 namespace DualCoding {
00014
00015 class EndPoint;
00016 class NEWMAT::ColumnVector;
00017 class NEWMAT::Matrix;
00018 class ShapeRoot;
00019 class ShapeSpace;
00020 template<> class Shape<LineData>;
00021
00022 #define POLYGON_DATA_MOBILE false
00023 #define THRESH_DIST_VERTEX 50
00024
00025
00026
00027
00028
00029
00030
00031 class PolygonData : public BaseData {
00032 protected:
00033 std::vector<LineData> edges;
00034 private:
00035 std::vector<Point> vertices;
00036
00037 public:
00038 static ShapeType_t getStaticType() { return polygonDataType; }
00039
00040 DATASTUFF_H(PolygonData);
00041 friend class Shape<PolygonData>;
00042
00043
00044 PolygonData(const LineData&);
00045 PolygonData(ShapeSpace& space, const std::vector<Point>& pts, bool closed,
00046 bool end1Valid=true, bool end2Valid=true);
00047 PolygonData(const std::vector<LineData>& lns)
00048 : BaseData(lns.front()), edges(lns), vertices() { updateVertices(); }
00049 PolygonData(const PolygonData& other)
00050 : BaseData(other), edges(other.edges), vertices(other.vertices) {}
00051
00052 static std::vector<Shape<LineData> > extractPolygonEdges(Sketch<bool> const& sketch, Sketch<bool> const& occluder);
00053
00054
00055 static std::vector<ShapeRoot> formPolygons(const std::vector<LineData>&,
00056 std::vector<Shape<PolygonData> >& existing, std::vector<ShapeRoot>& deleted);
00057 static std::vector<ShapeRoot> formPolygons(const std::vector<LineData>&);
00058
00059
00060
00061 const LineData& end1Ln() const { return edges.front(); }
00062 const LineData& end2Ln() const { return edges.back(); }
00063 const EndPoint& end1Pt() const { return edges.front().end1Pt(); }
00064 const EndPoint& end2Pt() const { return edges.back().end2Pt(); }
00065 const std::vector<Point>& getVertices() const { return vertices; }
00066 const std::vector<LineData>& getEdges() const { return edges; }
00067 std::vector<LineData>& getEdgesRW() { return edges; }
00068
00069
00070 BoundingBox getBoundingBox() const;
00071
00072 std::vector<ShapeRoot> updateState();
00073
00074 bool isClosed() const ;
00075
00076
00077 static Shape<PolygonData> convexHull(const Sketch<bool> &sketch);
00078
00079 PolygonData& operator=(const PolygonData& other) {
00080 if (&other == this)
00081 return *this;
00082 BaseData::operator=(other);
00083 edges = other.edges;
00084 vertices = other.vertices;
00085 return *this;
00086 }
00087
00088 private:
00089 bool tryClosePolygon();
00090 bool tryImportNewEndline(const LineData& line, bool useEnd1Pt=true, bool useEnd2Pt=true);
00091 bool tryUpdateEdge(const ShapeRoot&);
00092 bool isMatchForEdge(const LineData& other) const;
00093 bool formsNewEndline(const LineData& ln, bool useEnd1Pt=true, bool useEnd2Pt=true) const;
00094 void updateVertices();
00095 static bool isFirstLineLonger(const Shape<LineData>& ln1,const Shape<LineData>& ln2);
00096
00097 public:
00098
00099 virtual Point getCentroid() const;
00100 virtual bool isMatchFor(const ShapeRoot& other) const;
00101 virtual bool isAdmissible() const;
00102 virtual bool updateParams(const ShapeRoot& other, bool forceUpdate=false);
00103 virtual int getConfidence() const;
00104 virtual bool isInside(const Point& pt) const;
00105 virtual void printParams() const;
00106 virtual void applyTransform(const NEWMAT::Matrix& Tmat, const ReferenceFrameType_t newref=unspecified);
00107 virtual void projectToGround(const NEWMAT::Matrix& camToBase,
00108 const NEWMAT::ColumnVector& groundplane);
00109 virtual void setColor(const rgb &new_color);
00110 virtual void setColor(const unsigned int color_index);
00111 virtual void setColor(const std::string &color_name);
00112 virtual Sketch<bool>* render() const;
00113 virtual unsigned short getDimension() const { return 2; }
00114
00115 };
00116
00117 }
00118
00119 #endif