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 
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 //vertices unique
00026 //num vertices >= 1
00027 //for wall bounds, vertices are in clockwise order
00028 //order of vertices isn't ambiguous
00029 //average of vertices is the centroid
00030 
00031 class PolygonData : public BaseData {
00032 protected:
00033   std::vector<LineData> edges; // edges which consist this polygon
00034 private:
00035   std::vector<Point> vertices; // cache of vertices
00036 
00037 public:
00038   static ShapeType_t getStaticType() { return polygonDataType; }
00039 
00040   DATASTUFF_H(PolygonData);
00041   friend class Shape<PolygonData>;
00042 
00043   //! Constructors
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); //!< extracts then-edges lines
00053   //! forms polygons from lines and existing polygons
00054   //! existing polygons may be updated or deleted for which case they are added to deleted vector
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>&); //!< 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   
00070   BoundingBox getBoundingBox() const;
00071 
00072   std::vector<ShapeRoot> updateState();
00073 
00074   bool isClosed() const ; //<! returns if this polygon is closed
00075   
00076   //! Convex hull using Graham's scan.
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(); //!< called everytime polygon is changed. updates vertices by finding intersections of adjascent edges
00095   static bool isFirstLineLonger(const Shape<LineData>& ln1,const Shape<LineData>& ln2);
00096 
00097 public:   
00098   //{@! functions virtual in BaseData
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); //!< updates existing edges, but does not importing new edges
00103   virtual int getConfidence() const; //!< returns minimum confidence of all edges
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 } // namespace
00118 
00119 #endif

DualCoding 4.0
Generated Thu Nov 22 00:52:36 2007 by Doxygen 1.5.4