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