PolygonData.h
Go to the documentation of this file.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 #include "Shared/fmatSpatial.h"
00013
00014 namespace DualCoding {
00015
00016 class EndPoint;
00017 class ShapeRoot;
00018 class ShapeSpace;
00019 template<> class Shape<LineData>;
00020
00021 #define POLYGON_DATA_MOBILE false
00022 #define THRESH_DIST_VERTEX 50
00023
00024
00025
00026
00027
00028
00029
00030 class PolygonData : public BaseData {
00031 protected:
00032 std::vector<LineData> edges;
00033 private:
00034 std::vector<Point> vertices;
00035
00036 public:
00037 static ShapeType_t getStaticType() { return polygonDataType; }
00038
00039 DATASTUFF_H(PolygonData);
00040 friend class Shape<PolygonData>;
00041
00042
00043 PolygonData(const LineData&);
00044 PolygonData(ShapeSpace& space, const std::vector<Point>& pts, bool closed,
00045 bool end1Valid=true, bool end2Valid=true);
00046 PolygonData(const std::vector<LineData>& lns)
00047 : BaseData(lns.front()), edges(lns), vertices() { updateVertices(); }
00048 PolygonData(const PolygonData& other)
00049 : BaseData(other), edges(other.edges), vertices(other.vertices) {}
00050
00051 static std::vector<Shape<LineData> > extractPolygonEdges(Sketch<bool> const& sketch, Sketch<bool> const& occluder);
00052
00053
00054 static std::vector<ShapeRoot> rebuildPolygons(const std::vector<LineData>&,
00055 std::vector<Shape<PolygonData> >& existing,
00056 std::vector<Shape<PolygonData> >& 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 void setVertices(std::vector<Point> &vs, bool closed, bool end1Valid=true, bool end2Valid=true);
00070
00071
00072 void importAdjust();
00073
00074 BoundingBox2D getBoundingBox() const;
00075
00076 std::vector<ShapeRoot> updateState();
00077
00078 bool isClosed() const ;
00079
00080
00081 static Shape<PolygonData> convexHull(const Sketch<bool> &sketch);
00082
00083 PolygonData& operator=(const PolygonData& other) {
00084 if (&other == this)
00085 return *this;
00086 BaseData::operator=(other);
00087 edges = other.edges;
00088 vertices = other.vertices;
00089 return *this;
00090 }
00091
00092 private:
00093 bool tryClosePolygon();
00094 bool tryImportNewEndline(const LineData& line, bool useEnd1Pt=true, bool useEnd2Pt=true);
00095 bool tryUpdateEdge(const LineData &line);
00096 bool isMatchForEdge(const LineData& other) const;
00097 bool formsNewEndline(const LineData& ln, bool useEnd1Pt=true, bool useEnd2Pt=true) const;
00098 void updateVertices();
00099 static bool isFirstLineLonger(const LineData& ln1,const LineData& ln2);
00100
00101 public:
00102
00103 virtual Point getCentroid() const;
00104 virtual bool isMatchFor(const ShapeRoot& other) const;
00105 virtual bool equivalentVertices(const PolygonData& other) const;
00106 virtual bool isAdmissible() const;
00107 virtual bool updateParams(const ShapeRoot& other, bool forceUpdate=false);
00108 virtual int getConfidence() const;
00109 virtual bool isInside(const Point& pt) const;
00110 virtual bool intersectsLine(const LineData& line);
00111 virtual void printParams() const;
00112 virtual void applyTransform(const fmat::Transform& Tmat, const ReferenceFrameType_t newref=unspecified);
00113 virtual void projectToGround(const fmat::Transform& camToBase,
00114 const PlaneEquation& groundplane);
00115 virtual void setColor(const rgb &new_color);
00116 virtual void setColor(const unsigned int color_index);
00117 virtual void setColor(const std::string &color_name);
00118 virtual Sketch<bool>* render() const;
00119 virtual unsigned short getDimension() const { return 2; }
00120
00121 };
00122
00123 }
00124
00125 #endif