contrib/gel/vsol/vsol_point_2d.h
Go to the documentation of this file.
00001 // This is gel/vsol/vsol_point_2d.h
00002 #ifndef vsol_point_2d_h_
00003 #define vsol_point_2d_h_
00004 //*****************************************************************************
00005 //:
00006 // \file
00007 // \brief Point in 2D space
00008 //
00009 // \author François BERTEL
00010 // \date   2000-04-14
00011 //
00012 // \verbatim
00013 //  Modifications
00014 //   2000-04-14 François BERTEL Creation
00015 //   2000-05-12 François BERTEL Replacement of vnl_vector_fixed<double,2> by vnl_double_2
00016 //   2000-06-17 Peter Vanroose  Implemented all operator==()s and type info
00017 //   2000-09-18 Peter Tu        using vgl_point_2d instead of vnl_vector
00018 //   2001-06-30 Peter Vanroose  Added constructor from vgl_point_2d
00019 //   2001-07-03 Peter Vanroose  Replaced vnl_double_2 by vgl_vector_2d
00020 //   2001-07-03 Peter Vanroose  Replaced new/delete by vgl_point_2d as member
00021 //   2004-04-06 Joseph Mundy    Added Binary I/O
00022 //   2004-05-14 Peter Vanroose  Added describe()
00023 // \endverbatim
00024 //*****************************************************************************
00025 
00026 class vsol_point_2d;
00027 
00028 //*****************************************************************************
00029 // External declarations for values
00030 //*****************************************************************************
00031 #include <vsl/vsl_binary_io.h>
00032 #include <vsol/vsol_point_2d_sptr.h>
00033 #include <vsol/vsol_spatial_object_2d.h>
00034 #include <vgl/vgl_vector_2d.h>
00035 #include <vgl/vgl_point_2d.h>
00036 #include <vcl_iostream.h>
00037 
00038 class vsol_point_2d : public vsol_spatial_object_2d
00039 {
00040   //***************************************************************************
00041   // Data members
00042   //***************************************************************************
00043 
00044   //---------------------------------------------------------------------------
00045   //: Coordinates of the point
00046   //---------------------------------------------------------------------------
00047   vgl_point_2d<double> p_;
00048 
00049  public:
00050   //***************************************************************************
00051   // Initialization
00052   //***************************************************************************
00053 
00054    //---------------------------------------------------------------------------
00055   //: Default Constructor
00056   //---------------------------------------------------------------------------
00057   inline vsol_point_2d() : p_(0.0,0.0) {}
00058 
00059   //---------------------------------------------------------------------------
00060   //: Constructor from vgl_point_2d (automatic cast)
00061   //---------------------------------------------------------------------------
00062   inline vsol_point_2d(vgl_point_2d<double> const& p) : p_(p) {}
00063 
00064   //---------------------------------------------------------------------------
00065   //: Constructor from cartesian coordinates `x' and `y'
00066   //---------------------------------------------------------------------------
00067   inline vsol_point_2d(double x, double y) : p_(x,y) {}
00068 
00069   //---------------------------------------------------------------------------
00070   //: Copy constructor
00071   //---------------------------------------------------------------------------
00072   inline vsol_point_2d(vsol_point_2d const& pt) : vsol_spatial_object_2d(pt), p_(pt.x(),pt.y()) {}
00073 
00074   //---------------------------------------------------------------------------
00075   //: Destructor
00076   //---------------------------------------------------------------------------
00077   virtual ~vsol_point_2d();
00078 
00079   //---------------------------------------------------------------------------
00080   //: Clone `this': creation of a new object and initialization
00081   //  See Prototype pattern
00082   //---------------------------------------------------------------------------
00083   virtual vsol_spatial_object_2d* clone(void) const;
00084 
00085   //---------------------------------------------------------------------------
00086   //: Safe casting
00087   //---------------------------------------------------------------------------
00088 
00089   virtual vsol_point_2d* cast_to_point(void) { return this;}
00090   virtual vsol_point_2d const* cast_to_point(void) const { return this;}
00091 
00092   //***************************************************************************
00093   // Access
00094   //***************************************************************************
00095 
00096   //---------------------------------------------------------------------------
00097   //: Return the abscissa
00098   //---------------------------------------------------------------------------
00099   inline double x(void) const { return p_.x(); }
00100 
00101   //---------------------------------------------------------------------------
00102   //: Return the ordinate
00103   //---------------------------------------------------------------------------
00104   inline double y(void) const { return p_.y(); }
00105 
00106   //***************************************************************************
00107   // Comparison
00108   //***************************************************************************
00109 
00110   //---------------------------------------------------------------------------
00111   //: Has `this' the same coordinates than `other' ?
00112   //---------------------------------------------------------------------------
00113   virtual bool operator==(vsol_point_2d const& other) const;
00114   virtual bool operator==(vsol_spatial_object_2d const& obj) const; // virtual of vsol_spatial_object_2d
00115 
00116   //---------------------------------------------------------------------------
00117   //: Has `this' not the same coordinates than `other' ?
00118   //---------------------------------------------------------------------------
00119   inline bool operator!=(vsol_point_2d const& o) const {return !operator==(o);}
00120 
00121   //***************************************************************************
00122   // Status report
00123   //***************************************************************************
00124 
00125   //---------------------------------------------------------------------------
00126   //: Return the real type of a point. It is a POINT
00127   //---------------------------------------------------------------------------
00128   vsol_spatial_object_2d_type spatial_type(void) const;
00129 
00130   //---------------------------------------------------------------------------
00131   //: Compute the bounding box of `this'
00132   //---------------------------------------------------------------------------
00133   virtual void compute_bounding_box(void) const;
00134 
00135   //***************************************************************************
00136   // Status setting
00137   //***************************************************************************
00138 
00139   //---------------------------------------------------------------------------
00140   //: Set the abscissa
00141   //---------------------------------------------------------------------------
00142   virtual void set_x(const double new_x);
00143 
00144   //---------------------------------------------------------------------------
00145   //: Set the ordinate
00146   //---------------------------------------------------------------------------
00147   virtual void set_y(const double new_y);
00148 
00149   //***************************************************************************
00150   // Basic operations
00151   //***************************************************************************
00152 
00153   //---------------------------------------------------------------------------
00154   //: return the point
00155   //---------------------------------------------------------------------------
00156   vgl_point_2d<double> get_p () const { return p_; }
00157 
00158   //---------------------------------------------------------------------------
00159   //: Return the distance (N2) between `this' and `other'
00160   //---------------------------------------------------------------------------
00161   virtual double distance(vsol_point_2d const& other) const;
00162   virtual double distance(vsol_point_2d_sptr other) const;
00163 
00164   //---------------------------------------------------------------------------
00165   //: Return the middle point between `this' and `other'
00166   //---------------------------------------------------------------------------
00167   virtual vsol_point_2d_sptr middle(vsol_point_2d const& other) const;
00168 
00169   //---------------------------------------------------------------------------
00170   //: Add `v' to `this'
00171   //---------------------------------------------------------------------------
00172   virtual void add_vector(vgl_vector_2d<double> const&v);
00173 
00174   //---------------------------------------------------------------------------
00175   //: Add `v' and `this'
00176   //---------------------------------------------------------------------------
00177   virtual vsol_point_2d_sptr plus_vector(vgl_vector_2d<double> const&v) const;
00178 
00179   //---------------------------------------------------------------------------
00180   //: Return the vector `this',`other'.
00181   //---------------------------------------------------------------------------
00182   virtual vgl_vector_2d<double> to_vector(vsol_point_2d const& other) const;
00183 
00184   // ==== Binary IO methods ======
00185 
00186   //: Binary save self to stream.
00187   void b_write(vsl_b_ostream &os) const;
00188 
00189   //: Binary load self from stream.
00190   void b_read(vsl_b_istream &is);
00191 
00192   //: Return IO version number;
00193   short version() const;
00194 
00195   //: Print an ascii summary to the stream
00196   void print_summary(vcl_ostream &os) const;
00197 
00198   //: Return a platform independent string identifying the class
00199   virtual vcl_string is_a() const { return vcl_string("vsol_point_2d"); }
00200 
00201   //: Return true if the argument matches the string identifying the class or any parent class
00202   virtual bool is_class(const vcl_string& cls) const { return cls==is_a(); }
00203 
00204   //---------------------------------------------------------------------------
00205   //: output description to stream
00206   //---------------------------------------------------------------------------
00207   inline void describe(vcl_ostream &strm, int blanking=0) const
00208   {
00209     if (blanking < 0) blanking = 0; while (blanking--) strm << ' ';
00210     strm << '(' << x() << ' ' << y() << ')' << vcl_endl;
00211   }
00212 };
00213 
00214 //: Binary save vsol_point_2d* to stream.
00215 void vsl_b_write(vsl_b_ostream &os, vsol_point_2d const* p);
00216 
00217 //: Binary load vsol_point_2d* from stream.
00218 void vsl_b_read(vsl_b_istream &is, vsol_point_2d* &p);
00219 
00220 #endif // vsol_point_2d_h_