contrib/gel/vsol/vsol_curve_2d.h
Go to the documentation of this file.
00001 #ifndef vsol_curve_2d_h_
00002 #define vsol_curve_2d_h_
00003 //*****************************************************************************
00004 //:
00005 // \file
00006 // \brief Abstract curve in a 2D space
00007 //
00008 // \author
00009 //  François BERTEL
00010 //
00011 // \verbatim
00012 //  Modifications
00013 //   2000/06/17 Peter Vanroose  Implemented all operator==()s and type info
00014 //   2000/04/27 François BERTEL Creation
00015 //   2002/04/22 Amir Tamrakar   Added POLYLINE type
00016 //   2004/09/10 Peter Vanroose  Inlined all 1-line methods in class decl
00017 //   2004/09/23 MingChing Chang fix name of cast_to functions and added endpoints_equal
00018 // \endverbatim
00019 //*****************************************************************************
00020 
00021 //*****************************************************************************
00022 // External declarations for values
00023 //*****************************************************************************
00024 #include <vsol/vsol_spatial_object_2d.h>
00025 #include <vsol/vsol_point_2d_sptr.h>
00026 class vdgl_digital_curve;
00027 class vsol_line_2d;
00028 class vsol_conic_2d;
00029 class vsol_polyline_2d;
00030 class vsol_digital_curve_2d;
00031 class dbsol_circ_arc_2d;
00032 
00033 class vsol_curve_2d : public vsol_spatial_object_2d
00034 {
00035  protected:
00036   enum vsol_curve_2d_type
00037   { CURVE_NO_TYPE=0,
00038     LINE,
00039     CIRCULAR_ARC,
00040     CONIC,
00041     POLYLINE,
00042     DIGITAL_CURVE,
00043     NUM_CURVE_TYPES
00044   };
00045  private: // has been superseded by is_a()
00046   //: return the curve type
00047   virtual vsol_curve_2d_type curve_type()const{return vsol_curve_2d::CURVE_NO_TYPE;}
00048 
00049   //***************************************************************************
00050   // Initialization
00051   //***************************************************************************
00052  public:
00053   //---------------------------------------------------------------------------
00054   //: Destructor
00055   //---------------------------------------------------------------------------
00056   virtual ~vsol_curve_2d() {}
00057 
00058   //***************************************************************************
00059   // Access
00060   //***************************************************************************
00061 
00062   //---------------------------------------------------------------------------
00063   //: return the spatial type
00064   //---------------------------------------------------------------------------
00065   vsol_spatial_object_2d_type spatial_type()const{return vsol_spatial_object_2d::CURVE;}
00066 
00067  public:
00068   //---------------------------------------------------------------------------
00069   //: Return the first point of `this'; pure virtual function
00070   //---------------------------------------------------------------------------
00071   virtual vsol_point_2d_sptr p0() const=0;
00072 
00073   //---------------------------------------------------------------------------
00074   //: Return the last point of `this'; pure virtual function
00075   //---------------------------------------------------------------------------
00076   virtual vsol_point_2d_sptr p1() const=0;
00077 
00078   //***************************************************************************
00079   // Replaces dynamic_cast<T>
00080   //***************************************************************************
00081 
00082   //---------------------------------------------------------------------------
00083   //: Return `this' if `this' is a curve, 0 otherwise
00084   //---------------------------------------------------------------------------
00085   virtual vsol_curve_2d *cast_to_curve() {return this;}
00086   virtual const vsol_curve_2d *cast_to_curve() const {return this;}
00087 
00088   //---------------------------------------------------------------------------
00089   //: Return `this' if `this' is a line, 0 otherwise
00090   //---------------------------------------------------------------------------
00091   virtual vsol_line_2d const*cast_to_line()const{return 0;}
00092   virtual vsol_line_2d *cast_to_line() {return 0;}
00093 
00094   //---------------------------------------------------------------------------
00095   //: Return `this' if `this' is a conic, 0 otherwise
00096   //---------------------------------------------------------------------------
00097   virtual dbsol_circ_arc_2d const*cast_to_circ_arc()const{return 0;}
00098   virtual dbsol_circ_arc_2d *cast_to_circ_arc() {return 0;}
00099 
00100 
00101   //---------------------------------------------------------------------------
00102   //: Return `this' if `this' is a conic, 0 otherwise
00103   //---------------------------------------------------------------------------
00104   virtual vsol_conic_2d const*cast_to_conic()const{return 0;}
00105   virtual vsol_conic_2d *cast_to_conic() {return 0;}
00106 
00107   //---------------------------------------------------------------------------
00108   //: Return `this' if `this' is a polyline, 0 otherwise
00109   //---------------------------------------------------------------------------
00110   virtual vsol_polyline_2d const*cast_to_polyline()const{return 0;}
00111   virtual vsol_polyline_2d *cast_to_polyline() {return 0;}
00112 
00113   //---------------------------------------------------------------------------
00114   //: Return `this' if `this' is a digital_curve_2d, 0 otherwise
00115   //---------------------------------------------------------------------------
00116   virtual vsol_digital_curve_2d const*cast_to_digital_curve()const{return 0;}
00117   virtual vsol_digital_curve_2d *cast_to_digital_curve() {return 0;}
00118 
00119   //---------------------------------------------------------------------------
00120   //: Return `this' if `this' is a vdgl_digital_curve, 0 otherwise
00121   //---------------------------------------------------------------------------
00122   virtual vdgl_digital_curve const*cast_to_vdgl_digital_curve()const{return 0;}
00123   virtual vdgl_digital_curve *cast_to_vdgl_digital_curve() {return 0;}
00124 
00125   //***************************************************************************
00126   // Status report
00127   //***************************************************************************
00128 
00129   //---------------------------------------------------------------------------
00130   //: Return the length of `this'
00131   //---------------------------------------------------------------------------
00132   virtual double length() const=0;
00133 
00134   //***************************************************************************
00135   // Status setting
00136   //***************************************************************************
00137 
00138   //---------------------------------------------------------------------------
00139   //: Set the first point of the curve
00140   //---------------------------------------------------------------------------
00141   virtual void set_p0(const vsol_point_2d_sptr &new_p0)=0;
00142 
00143   //---------------------------------------------------------------------------
00144   //: Set the last point of the curve
00145   //---------------------------------------------------------------------------
00146   virtual void set_p1(const vsol_point_2d_sptr &new_p1)=0;
00147 
00148  protected:
00149   //: Helper function to determine if curve endpoints are equal (in any order).
00150   // Useful for curve equality tests.
00151   bool endpoints_equal(const vsol_curve_2d &other) const;
00152 };
00153 
00154 #endif // vsol_curve_2d_h_