Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

PolygonData.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef _POLYGONDATA_H_
00003 #define _POLYGONDATA_H_
00004 
00005 #include <vector>
00006 #include <iostream>
00007 #include <string>
00008 
00009 #include "BaseData.h"    // superclass
00010 #include "LineData.h"    // LineData data member
00011 #include "Shared/Measures.h"    // coordinate_t; AngPi data member
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 //vertices unique
00025 //num vertices >= 1
00026 //for wall bounds, vertices are in clockwise order
00027 //order of vertices isn't ambiguous
00028 //average of vertices is the centroid
00029 
00030 class PolygonData : public BaseData {
00031 protected:
00032   std::vector<LineData> edges; // edges that make up this polygon
00033 private:
00034   std::vector<Point> vertices; // cache of vertices
00035 
00036 public:
00037   static ShapeType_t getStaticType() { return polygonDataType; }
00038 
00039   DATASTUFF_H(PolygonData);
00040   friend class Shape<PolygonData>;
00041 
00042   //! Constructors
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); //!< extracts then-edges lines
00052   //! forms polygons from lines and existing polygons
00053   //! existing polygons may be updated or deleted for which case they are added to deleted vector
00054   static std::vector<ShapeRoot> formPolygons(const std::vector<LineData>&, 
00055           std::vector<Shape<PolygonData> >& existing, std::vector<ShapeRoot>& deleted); 
00056   static std::vector<ShapeRoot> formPolygons(const std::vector<LineData>&); //!< forms polygons from lines
00057   
00058   //! Edge/Vertex Access Functions
00059   //@{
00060   const LineData& end1Ln() const { return edges.front(); } //!< returns first edge of this polygon
00061   const LineData& end2Ln() const { return edges.back(); } //!< returns last edge of this polygon
00062   const EndPoint& end1Pt() const { return edges.front().end1Pt(); } //!< returns end1Pt of end1Ln
00063   const EndPoint& end2Pt() const { return edges.back().end2Pt(); } //!< returns end2Pt of end2Ln
00064   const std::vector<Point>& getVertices() const { return vertices; } //!< returns all vertices of this polygon
00065   const std::vector<LineData>& getEdges() const { return edges; } //!< returns all edges of this polygon
00066   std::vector<LineData>& getEdgesRW() { return edges; } //!< returns address of edge vector for modification
00067 
00068   void setVertices(std::vector<Point> &vs, bool closed, bool end1Valid=true, bool end2Valid=true);
00069   //@}
00070   
00071   BoundingBox2D getBoundingBox() const;
00072 
00073   std::vector<ShapeRoot> updateState();
00074 
00075   bool isClosed() const ; //<! returns if this polygon is closed
00076   
00077   //! Convex hull using Graham's scan.
00078   static Shape<PolygonData> convexHull(const Sketch<bool> &sketch);
00079 
00080   PolygonData& operator=(const PolygonData& other) {
00081     if (&other == this)
00082       return *this;
00083     BaseData::operator=(other);
00084     edges = other.edges;
00085     vertices = other.vertices;
00086     return *this;
00087   }
00088 
00089 private:
00090   bool tryClosePolygon();
00091   bool tryImportNewEndline(const LineData& line, bool useEnd1Pt=true, bool useEnd2Pt=true);
00092   bool tryUpdateEdge(const ShapeRoot&);
00093   bool isMatchForEdge(const LineData& other) const;
00094   bool formsNewEndline(const LineData& ln, bool useEnd1Pt=true, bool useEnd2Pt=true) const;
00095   void updateVertices(); //!< called everytime polygon is changed. updates vertices by finding intersections of adjascent edges
00096   static bool isFirstLineLonger(const LineData& ln1,const LineData& ln2);
00097 
00098 public:   
00099   //{@! functions virtual in BaseData
00100   virtual Point getCentroid() const;
00101   virtual bool isMatchFor(const ShapeRoot& other) const;
00102   virtual bool isAdmissible() const;
00103   virtual bool updateParams(const ShapeRoot& other, bool forceUpdate=false); //!< updates existing edges, but does not importing new edges
00104   virtual int getConfidence() const; //!< returns minimum confidence of all edges
00105   virtual bool isInside(const Point& pt) const;
00106   virtual bool intersectsLine(const LineData& line);
00107   virtual void printParams() const;
00108   virtual void applyTransform(const fmat::Transform& Tmat, const ReferenceFrameType_t newref=unspecified);
00109   virtual void projectToGround(const fmat::Transform& camToBase,
00110              const PlaneEquation& groundplane);
00111   virtual void setColor(const rgb &new_color);
00112   virtual void setColor(const unsigned int color_index);
00113   virtual void setColor(const std::string &color_name);
00114   virtual Sketch<bool>* render() const;
00115   virtual unsigned short getDimension() const { return 2; }
00116   //}
00117 };
00118 
00119 } // namespace
00120 
00121 #endif

DualCoding 5.1CVS
Generated Sat May 4 06:29:28 2013 by Doxygen 1.6.3