contrib/gel/vsol/vsol_line_3d.h
Go to the documentation of this file.
00001 // This is gel/vsol/vsol_line_3d.h
00002 #ifndef vsol_line_3d_h_
00003 #define vsol_line_3d_h_
00004 //*****************************************************************************
00005 //:
00006 // \file
00007 // \brief Straight line segment in a 3D space.
00008 //
00009 // The direction gives the orientation and the length of the segment
00010 //
00011 // \author François BERTEL
00012 // \date   2000-05-03
00013 //
00014 // \verbatim
00015 //  Modifications
00016 //   2000-05-03 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 //   2004-05-14 Peter Vanroose  Added describe()
00020 //   2004-09-06 Peter Vanroose  Added Binary I/O
00021 // \endverbatim
00022 //*****************************************************************************
00023 
00024 #include <vsol/vsol_curve_3d.h>
00025 #include <vsol/vsol_point_3d_sptr.h>
00026 #include <vsl/vsl_binary_io.h>
00027 #include <vgl/vgl_fwd.h> // vgl_vector_3d, vgl_homg_line_3d_2_points
00028 #include <vcl_iosfwd.h>
00029 
00030 class vsol_line_3d : public vsol_curve_3d
00031 {
00032   //***************************************************************************
00033   // Data members
00034   //***************************************************************************
00035 
00036   //---------------------------------------------------------------------------
00037   //: First point of the straight line segment
00038   //---------------------------------------------------------------------------
00039   vsol_point_3d_sptr p0_;
00040 
00041   //---------------------------------------------------------------------------
00042   //: Last point of the straight line segment
00043   //---------------------------------------------------------------------------
00044   vsol_point_3d_sptr p1_;
00045 
00046  public:
00047   //***************************************************************************
00048   // Initialization
00049   //***************************************************************************
00050 
00051   //---------------------------------------------------------------------------
00052   //: Constructor from the direction and the middle point
00053   //---------------------------------------------------------------------------
00054   vsol_line_3d(vgl_vector_3d<double> const& new_direction,
00055                vsol_point_3d_sptr const& new_middle);
00056 
00057   //---------------------------------------------------------------------------
00058   //: Constructor from the first and the last point of the straight line
00059   //---------------------------------------------------------------------------
00060   vsol_line_3d(vsol_point_3d_sptr const& new_p0,
00061                vsol_point_3d_sptr const& new_p1)
00062     : p0_(new_p0), p1_(new_p1) {}
00063 
00064   //---------------------------------------------------------------------------
00065   //: Copy constructor
00066   //  no duplication of the points
00067   //---------------------------------------------------------------------------
00068   vsol_line_3d(vsol_line_3d const& other)
00069   : vsol_curve_3d(other), p0_(other.p0_), p1_(other.p1_) {}
00070 
00071   //---------------------------------------------------------------------------
00072   //: Destructor
00073   //---------------------------------------------------------------------------
00074   virtual ~vsol_line_3d() {}
00075 
00076   //---------------------------------------------------------------------------
00077   //: Return `this' if `this' is a line_3d, 0 otherwise
00078   //---------------------------------------------------------------------------
00079   virtual vsol_line_3d const*cast_to_line()const{return this;}
00080   virtual vsol_line_3d *cast_to_line() {return this;}
00081 
00082  private: // has been superseded by is_a()
00083   //: Return the curve type
00084   virtual vsol_curve_3d_type curve_type() const { return vsol_curve_3d::LINE; }
00085 
00086  public:
00087   //---------------------------------------------------------------------------
00088   //: Clone `this': creation of a new object and initialization
00089   //  See Prototype pattern
00090   //---------------------------------------------------------------------------
00091   virtual vsol_spatial_object_3d* clone() const;
00092 
00093   //***************************************************************************
00094   // Access
00095   //***************************************************************************
00096 
00097   //---------------------------------------------------------------------------
00098   //: Middle point of the straight line segment
00099   //---------------------------------------------------------------------------
00100   vsol_point_3d_sptr middle() const;
00101 
00102   //---------------------------------------------------------------------------
00103   //: direction of the straight line segment.
00104   //---------------------------------------------------------------------------
00105   vgl_vector_3d<double> direction() const;
00106 
00107   //---------------------------------------------------------------------------
00108   //: First point of the straight line segment; pure virtual of vsol_curve_3d
00109   //---------------------------------------------------------------------------
00110   virtual vsol_point_3d_sptr p0() const { return p0_; }
00111 
00112   //---------------------------------------------------------------------------
00113   //: Last point of the straight line segment; pure virtual of vsol_curve_3d
00114   //---------------------------------------------------------------------------
00115   virtual vsol_point_3d_sptr p1() const { return p1_; }
00116 
00117   //***************************************************************************
00118   // Comparison
00119   //***************************************************************************
00120 
00121   //---------------------------------------------------------------------------
00122   //: Has `this' the same points than `other' ?
00123   //---------------------------------------------------------------------------
00124   virtual bool operator==(vsol_line_3d const& other) const;
00125   virtual bool operator==(vsol_spatial_object_3d const& obj) const; // virtual of vsol_spatial_object_3d
00126 
00127   //---------------------------------------------------------------------------
00128   //: Has `this' not the same points than `other' ?
00129   //---------------------------------------------------------------------------
00130   inline bool operator!=(vsol_line_3d const& o) const {return !operator==(o);}
00131 
00132   //***************************************************************************
00133   // Status report
00134   //***************************************************************************
00135 
00136   //---------------------------------------------------------------------------
00137   //: Compute the bounding box of `this'
00138   //---------------------------------------------------------------------------
00139   virtual void compute_bounding_box() const;
00140 
00141   //---------------------------------------------------------------------------
00142   //: Return the length of `this'
00143   //---------------------------------------------------------------------------
00144   virtual double length() const;
00145 
00146   //***************************************************************************
00147   // Status setting
00148   //***************************************************************************
00149 
00150   //---------------------------------------------------------------------------
00151   //: Set the first point of the straight line segment
00152   //---------------------------------------------------------------------------
00153   virtual void set_p0(vsol_point_3d_sptr const& new_p0);
00154 
00155   //---------------------------------------------------------------------------
00156   //: Set the last point of the straight line segment
00157   //---------------------------------------------------------------------------
00158   virtual void set_p1(vsol_point_3d_sptr const& new_p1);
00159 
00160   //---------------------------------------------------------------------------
00161   //: Set the length of `this'. Doesn't change middle point and orientation.
00162   //  If p0 and p1 are equal then the direction is set to (1,0,0)
00163   //  REQUIRE: new_length>=0
00164   //---------------------------------------------------------------------------
00165   void set_length(const double new_length);
00166 
00167   //***************************************************************************
00168   // Basic operations
00169   //***************************************************************************
00170 
00171   //---------------------------------------------------------------------------
00172   //: Is `p' in `this' ?
00173   //---------------------------------------------------------------------------
00174   virtual bool in(vsol_point_3d_sptr const& p) const;
00175 
00176   //---------------------------------------------------------------------------
00177   //: Return the tangent to `this' at `p'. Has to be deleted manually
00178   //  REQUIRE: in(p)
00179   //---------------------------------------------------------------------------
00180   virtual vgl_homg_line_3d_2_points<double>* tangent_at_point(vsol_point_3d_sptr const& p) const;
00181 
00182   // ==== Binary IO methods ======
00183 
00184   //: Binary save self to stream.
00185   void b_write(vsl_b_ostream &os) const;
00186 
00187   //: Binary load self from stream.
00188   void b_read(vsl_b_istream &is);
00189 
00190   //: Return IO version number;
00191   short version() const;
00192 
00193   //: Print an ascii summary to the stream
00194   void print_summary(vcl_ostream &os) const;
00195 
00196   //: Return a platform independent string identifying the class
00197   virtual vcl_string is_a() const { return vcl_string("vsol_line_3d"); }
00198 
00199   //: Return true if the argument matches the string identifying the class or any parent class
00200   virtual bool is_class(vcl_string const& cls) const { return cls==is_a(); }
00201 
00202   //---------------------------------------------------------------------------
00203   //: output description to stream
00204   //---------------------------------------------------------------------------
00205   void describe(vcl_ostream &strm, int blanking=0) const;
00206 };
00207 
00208 //: Binary save vsol_line_3d* to stream.
00209 void vsl_b_write(vsl_b_ostream &os, const vsol_line_3d* p);
00210 
00211 //: Binary load vsol_line_3d* from stream.
00212 void vsl_b_read(vsl_b_istream &is, vsol_line_3d* &p);
00213 
00214 #endif // vsol_line_3d_h_