contrib/gel/vsol/vsol_polygon_3d.h

Go to the documentation of this file.
00001 // This is gel/vsol/vsol_polygon_3d.h
00002 #ifndef vsol_polygon_3d_h_
00003 #define vsol_polygon_3d_h_
00004 //*****************************************************************************
00005 //:
00006 // \file
00007 // \brief Polygon in 3D space
00008 //
00009 // The vertices are to be defined in counterclockwise order.
00010 //
00011 // \author François BERTEL
00012 // \date   2000/05/09
00013 //
00014 // \verbatim
00015 //  Modifications
00016 //   2000/05/09 François BERTEL Creation
00017 //   2000/06/17 Peter Vanroose  Implemented all operator==()s and type info
00018 //   2001/07/03 Peter Vanroose  Replaced vnl_double_3 by vgl_vector_3d
00019 //   2001/07/03 Peter Vanroose  Corrected the implementation of is_convex()
00020 //   2004/05/14 Peter Vanroose  Added describe()
00021 //   2004/09/06 Peter Vanroose  Added Binary I/O
00022 // \endverbatim
00023 //*****************************************************************************
00024 
00025 #include <vsol/vsol_region_3d.h>
00026 #include <vsol/vsol_point_3d_sptr.h>
00027 #include <vcl_vector.h>
00028 #include <vcl_iosfwd.h>
00029 #include <vsl/vsl_binary_io.h>
00030 #include <vgl/vgl_fwd.h> // vgl_vector_3d
00031 #include <vgl/vgl_homg_plane_3d.h>
00032 class vsol_triangle_3d;
00033 class vsol_rectangle_3d;
00034 
00035 class vsol_polygon_3d : public vsol_region_3d
00036 {
00037  protected:
00038   //***************************************************************************
00039   // Data members
00040   //***************************************************************************
00041 
00042   //---------------------------------------------------------------------------
00043   //: List of vertices
00044   //---------------------------------------------------------------------------
00045   vcl_vector<vsol_point_3d_sptr> *storage_;
00046 
00047   //***************************************************************************
00048   // Initialization
00049   //***************************************************************************
00050 
00051  public:
00052   //---------------------------------------------------------------------------
00053   //: Constructor from a vcl_vector (not a geometric vector but a list of points)
00054   //  REQUIRE: new_vertices.size()>=3 and valid_vertices(new_vertices)
00055   //---------------------------------------------------------------------------
00056   explicit vsol_polygon_3d(vcl_vector<vsol_point_3d_sptr> const& new_vertices);
00057 
00058   //---------------------------------------------------------------------------
00059   //: Copy constructor
00060   //---------------------------------------------------------------------------
00061   vsol_polygon_3d(vsol_polygon_3d const& other);
00062 
00063   //---------------------------------------------------------------------------
00064   //: Destructor
00065   //---------------------------------------------------------------------------
00066   virtual ~vsol_polygon_3d();
00067 
00068   //---------------------------------------------------------------------------
00069   //: Clone `this': creation of a new object and initialization
00070   //  See Prototype pattern
00071   //---------------------------------------------------------------------------
00072   virtual vsol_spatial_object_3d* clone(void) const;
00073 
00074   //---------------------------------------------------------------------------
00075   //: Safe down-casting methods
00076   //---------------------------------------------------------------------------
00077   virtual vsol_polygon_3d *cast_to_polygon(void) {return this;}
00078   virtual vsol_polygon_3d const* cast_to_polygon(void) const {return this;}
00079 
00080   virtual vsol_triangle_3d* cast_to_triangle(void) {return 0;}
00081   virtual const vsol_triangle_3d* cast_to_triangle(void) const {return 0;}
00082 
00083   virtual vsol_rectangle_3d* cast_to_rectangle(void) {return 0;}
00084   virtual const vsol_rectangle_3d* cast_to_rectangle(void) const {return 0;}
00085 
00086   //***************************************************************************
00087   // Access
00088   //***************************************************************************
00089 
00090   //---------------------------------------------------------------------------
00091   //: Return vertex `i'
00092   //  REQUIRE: valid_index(i)
00093   //---------------------------------------------------------------------------
00094   vsol_point_3d_sptr vertex(const int i) const;
00095 
00096   //***************************************************************************
00097   // Comparison
00098   //***************************************************************************
00099 
00100   //---------------------------------------------------------------------------
00101   //: Has `this' the same points than `other' in the same order ?
00102   //---------------------------------------------------------------------------
00103   virtual bool operator==(vsol_polygon_3d const& other) const;
00104   virtual bool operator==(vsol_spatial_object_3d const& obj) const; // virtual of vsol_spatial_object_3d
00105 
00106   //---------------------------------------------------------------------------
00107   //: Has `this' not the same points than `other' in the same order ?
00108   //---------------------------------------------------------------------------
00109   inline bool operator!=(vsol_polygon_3d const& o)const{return !operator==(o);}
00110 
00111   //***************************************************************************
00112   // Status report
00113   //***************************************************************************
00114 
00115   //---------------------------------------------------------------------------
00116   //: Return the region type of a polygon.  Its spatial type is a REGION
00117   //---------------------------------------------------------------------------
00118   vsol_region_3d_type region_type(void) const { return vsol_region_3d::POLYGON; }
00119 
00120   //---------------------------------------------------------------------------
00121   //: Compute the bounding box of `this'
00122   //---------------------------------------------------------------------------
00123   virtual void compute_bounding_box(void) const;
00124 
00125   //---------------------------------------------------------------------------
00126   //: Return the number of vertices
00127   //---------------------------------------------------------------------------
00128   unsigned int size(void) const { return storage_->size(); }
00129 
00130   //---------------------------------------------------------------------------
00131   //: Return the area of `this'
00132   //---------------------------------------------------------------------------
00133   virtual double area(void) const; // virtual of vsol_region_3d
00134 
00135   //---------------------------------------------------------------------------
00136   //: Return the plane where 'this' polygon resides 
00137   //---------------------------------------------------------------------------
00138   vgl_homg_plane_3d<double> plane(void) const { return plane_; } 
00139 
00140   //---------------------------------------------------------------------------
00141   //: Is `this' convex ?
00142   //---------------------------------------------------------------------------
00143   virtual bool is_convex(void) const;
00144 
00145   //---------------------------------------------------------------------------
00146   //: Is `i' a valid index for the list of vertices ?
00147   //---------------------------------------------------------------------------
00148   bool valid_index(unsigned int i) const { return i<storage_->size(); }
00149 
00150   //---------------------------------------------------------------------------
00151   //: Are `new_vertices' valid vertices to build a polygon of the current type?
00152   //  That is: are all vertices in the same plane ?
00153   //---------------------------------------------------------------------------
00154   virtual bool valid_vertices(const vcl_vector<vsol_point_3d_sptr> new_vertices) const;
00155 
00156   //***************************************************************************
00157   // Basic operations
00158   //***************************************************************************
00159 
00160   //---------------------------------------------------------------------------
00161   //: Is `p' in `this' ?
00162   //---------------------------------------------------------------------------
00163   virtual bool in(vsol_point_3d_sptr const& p) const;
00164 
00165   //---------------------------------------------------------------------------
00166   //: Return the unit normal vector at point `p'. Have to be deleted manually
00167   //  REQUIRE: in(p)
00168   //---------------------------------------------------------------------------
00169   virtual vgl_vector_3d<double> normal_at_point(vsol_point_3d_sptr const& p) const;
00170 
00171   //---------------------------------------------------------------------------
00172   //: Return the normal vector
00173   //---------------------------------------------------------------------------
00174   vgl_vector_3d<double> normal() const;
00175   
00176   // ==== Binary IO methods ======
00177 
00178   //: Binary save self to stream.
00179   void b_write(vsl_b_ostream &os) const;
00180 
00181   //: Binary load self from stream.
00182   void b_read(vsl_b_istream &is);
00183 
00184   //: Return IO version number;
00185   short version() const;
00186 
00187   //: Print an ascii summary to the stream
00188   void print_summary(vcl_ostream &os) const;
00189 
00190   //: Return a platform independent string identifying the class
00191   virtual vcl_string is_a() const { return vcl_string("vsol_polygon_3d"); }
00192 
00193   //: Return true if the argument matches the string identifying the class or any parent class
00194   virtual bool is_class(vcl_string const& cls) const
00195   { return cls==is_a() || vsol_region_3d::is_class(cls); }
00196 
00197   //---------------------------------------------------------------------------
00198   //: output description to stream
00199   //---------------------------------------------------------------------------
00200   void describe(vcl_ostream &strm, int blanking=0) const;
00201 
00202  protected:
00203   //---------------------------------------------------------------------------
00204   //: Default constructor. Do nothing. Just to enable inheritance.  Protected.
00205   //---------------------------------------------------------------------------
00206   vsol_polygon_3d();
00207   vgl_homg_plane_3d<double> plane_;
00208 };
00209 
00210 //: Binary save vsol_polygon_3d* to stream.
00211 void vsl_b_write(vsl_b_ostream &os, const vsol_polygon_3d* p);
00212 
00213 //: Binary load vsol_polygon_3d* from stream.
00214 void vsl_b_read(vsl_b_istream &is, vsol_polygon_3d* &p);
00215 
00216 #endif // vsol_polygon_3d_h_

Generated on Thu Nov 20 05:15:13 2008 for contrib/gel/vsol by  doxygen 1.5.1