00001 // This is gel/gst/gst_polygon_2d.h 00002 #ifndef gst_polygon_2d_h_ 00003 #define gst_polygon_2d_h_ 00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00005 #pragma interface 00006 #endif 00007 //: 00008 // \file 00009 // \author crossge@crd.ge.com 00010 00011 #include <vcl_iosfwd.h> 00012 #include <vcl_vector.h> 00013 #include <vbl/vbl_ref_count.h> 00014 #include "gst_edge_2d_sptr.h" 00015 00016 class gst_polygon_2d : public vbl_ref_count 00017 { 00018 public: 00019 00020 // constructors and destructors 00021 gst_polygon_2d() {} 00022 ~gst_polygon_2d() {} 00023 // copy constructor - compiler-provided one sets ref_count to nonzero which is wrong -PVr 00024 gst_polygon_2d(gst_polygon_2d const& p) : vbl_ref_count(), edges_(p.edges_) {} 00025 00026 // getters and setters 00027 unsigned int size() const { return edges_.size(); } 00028 gst_edge_2d_sptr operator[](unsigned int i) const { return i<size() ? edges_[i] : (gst_edge_2d_sptr)0; } 00029 void add(gst_edge_2d_sptr edge) { edges_.push_back(edge); } 00030 00031 //: check closure of edges 00032 // returns false if the edges are not closed or 00033 // if there is more than one possible cycle 00034 bool check_validity() const; 00035 00036 // useful computational accessors 00037 bool inside(const double x, const double y) const; 00038 bool inside(const gst_vertex_2d_sptr v) const; 00039 00040 double get_centroid_x() const; 00041 double get_centroid_y() const; 00042 00043 double area() const; 00044 00045 // output 00046 friend vcl_ostream &operator<<( vcl_ostream &os, gst_polygon_2d &p); 00047 00048 protected: 00049 //: unordered, but oriented, list of edges 00050 vcl_vector<gst_edge_2d_sptr> edges_; 00051 }; 00052 00053 vcl_ostream &operator<<( vcl_ostream &os, gst_polygon_2d &p); 00054 00055 #endif // gst_polygon_2d_h_