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> 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>&); //!< forms polygons from lines
00058   
00059   //! Edge/Vertex Access Functions
00060   //@{
00061   const LineData& end1Ln() const { return edges.front(); } //!< returns first edge of this polygon
00062   const LineData& end2Ln() const { return edges.back(); } //!< returns last edge of this polygon
00063   const EndPoint& end1Pt() const { return edges.front().end1Pt(); } //!< returns end1Pt of end1Ln
00064   const EndPoint& end2Pt() const { return edges.back().end2Pt(); } //!< returns end2Pt of end2Ln
00065   const std::vector<Point>& getVertices() const { return vertices; } //!< returns all vertices of this polygon
00066   const std::vector<LineData>& getEdges() const { return edges; } //!< returns all edges of this polygon
00067   std::vector<LineData>& getEdgesRW() { return edges; } //!< returns address of edge vector for modification
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 ; //<! returns if this polygon is closed
00079   
00080   //! Convex hull using Graham's scan.
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(); //!< called everytime polygon is changed. updates vertices by finding intersections of adjascent edges
00099   static bool isFirstLineLonger(const LineData& ln1,const LineData& ln2);
00100 
00101 public:   
00102   //{@! functions virtual in BaseData
00103   virtual Point getCentroid() const;
00104   virtual bool isMatchFor(const ShapeRoot& other) const;
00105   virtual bool equivalentVertices(const PolygonData& other) const; //!< Return true if polys have the same vertices but possibly in a rotated order due to rebuilding
00106   virtual bool isAdmissible() const;
00107   virtual bool updateParams(const ShapeRoot& other, bool forceUpdate=false); //!< updates existing edges, but does not importing new edges
00108   virtual int getConfidence() const; //!< returns minimum confidence of all edges
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 } // namespace
00124 
00125 #endif

DualCoding 5.1CVS
Generated Mon May 9 04:56:27 2016 by Doxygen 1.6.3