contrib/gel/vsol/vsol_line_2d.h

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

Generated on Tue Dec 2 05:14:57 2008 for contrib/gel/vsol by  doxygen 1.5.1