contrib/gel/vsol/vsol_digital_curve_2d.h

Go to the documentation of this file.
00001 // This is gel/vsol/vsol_digital_curve_2d.h
00002 #ifndef vsol_digital_curve_2d_h_
00003 #define vsol_digital_curve_2d_h_
00004 //*****************************************************************************
00005 //:
00006 // \file
00007 // \brief Digital curve in 2D with interpolation
00008 //
00009 // This class inherits from vsol_curve_2d.
00010 //
00011 // \author Matt Leotta
00012 // \date   2004/07/13
00013 //
00014 // \verbatim
00015 //  Modifications
00016 // \endverbatim
00017 //*****************************************************************************
00018 
00019 #include <vgl/vgl_fwd.h>
00020 #include <vsl/vsl_binary_io.h>
00021 #include <vsol/vsol_curve_2d.h>
00022 #include <vsol/vsol_point_2d_sptr.h>
00023 #include <vsol/vsol_digital_curve_2d_sptr.h>
00024 #include <vcl_vector.h>
00025 
00026 //: Digital curve class, part of the vsol_curve_2d hierarchy
00027 // This class is more basic and "pure" than the vdgl counterpart.
00028 // The curve is made up of vsol point and has no addition data members
00029 
00030 class vsol_digital_curve_2d : public vsol_curve_2d
00031 {
00032  protected:
00033   //***************************************************************************
00034   // Data members
00035   //***************************************************************************
00036 
00037   //---------------------------------------------------------------------------
00038   // Description: List of vsol_point_2d
00039   //---------------------------------------------------------------------------
00040   vcl_vector<vsol_point_2d_sptr> samples_;
00041 
00042  public:
00043 
00044   //***************************************************************************
00045   // Initialization
00046   //***************************************************************************
00047 
00048   //---------------------------------------------------------------------------
00049   //: Default Constructor
00050   //---------------------------------------------------------------------------
00051   vsol_digital_curve_2d();
00052 
00053   //---------------------------------------------------------------------------
00054   //: Constructor from a vcl_vector of points
00055   //---------------------------------------------------------------------------
00056   vsol_digital_curve_2d(const vcl_vector<vsol_point_2d_sptr> &samples);
00057 
00058   //---------------------------------------------------------------------------
00059   //: Copy constructor
00060   //---------------------------------------------------------------------------
00061   vsol_digital_curve_2d(const vsol_digital_curve_2d &other);
00062 
00063   //---------------------------------------------------------------------------
00064   //: Destructor
00065   //---------------------------------------------------------------------------
00066   virtual ~vsol_digital_curve_2d();
00067 
00068   //---------------------------------------------------------------------------
00069   //: Clone `this': creation of a new object and initialization
00070   // See Prototype pattern
00071   //---------------------------------------------------------------------------
00072   virtual vsol_spatial_object_2d* clone() const;
00073 
00074   //***************************************************************************
00075   // Access
00076   //***************************************************************************
00077 
00078   //---------------------------------------------------------------------------
00079   //: Return the first point of `this'
00080   //---------------------------------------------------------------------------
00081   virtual vsol_point_2d_sptr p0() const; // pure virtual of vsol_curve_2d
00082 
00083   //---------------------------------------------------------------------------
00084   //: Return the last point of `this'
00085   //---------------------------------------------------------------------------
00086   virtual vsol_point_2d_sptr p1() const; // pure virtual of vsol_curve_2d
00087 
00088   //---------------------------------------------------------------------------
00089   //: Return point `i'
00090   //  REQUIRE: valid_index(i)
00091   //---------------------------------------------------------------------------
00092   vsol_point_2d_sptr point(const int i) const;
00093 
00094   //---------------------------------------------------------------------------
00095   //: Interpolate a point on the curve given a floating point index
00096   //  Linear interpolation is used for now
00097   //  \note index is NOT arc length.  For example, if size()==10
00098   //        then interp(5.5) is interpolated half way between points
00099   //        at indices 5 and 6.  In general this is not at 5.5 units along
00100   //        the curve or even at 55% through the curve.
00101   //---------------------------------------------------------------------------
00102   vgl_point_2d<double> interp(double index) const;
00103 
00104   //***************************************************************************
00105   // Comparison
00106   //***************************************************************************
00107 
00108   //---------------------------------------------------------------------------
00109   //: Has `this' the same points than `other' in the same order ?
00110   //---------------------------------------------------------------------------
00111   virtual bool operator==(const vsol_digital_curve_2d &other) const;
00112   virtual bool operator==(const vsol_spatial_object_2d& obj) const; // virtual of vsol_spatial_object_2d
00113 
00114   //---------------------------------------------------------------------------
00115   //: Has `this' the same points than `other' in the same order ?
00116   //---------------------------------------------------------------------------
00117   inline bool operator!=(const vsol_digital_curve_2d &o) const {return !operator==(o);}
00118 
00119 
00120   //***************************************************************************
00121   // Status setting
00122   //***************************************************************************
00123 
00124   //---------------------------------------------------------------------------
00125   //: Set the first point of the curve
00126   //  REQUIRE: in(new_p0)
00127   //---------------------------------------------------------------------------
00128   virtual void set_p0(const vsol_point_2d_sptr &new_p0);
00129 
00130   //---------------------------------------------------------------------------
00131   //: Set the last point of the curve
00132   //  REQUIRE: in(new_p1)
00133   //---------------------------------------------------------------------------
00134   virtual void set_p1(const vsol_point_2d_sptr &new_p1);
00135 
00136   //---------------------------------------------------------------------------
00137   //: Add another point to the curve
00138   //---------------------------------------------------------------------------
00139   void add_vertex(const vsol_point_2d_sptr &new_p);
00140 
00141   //***************************************************************************
00142   // Status report
00143   //***************************************************************************
00144 
00145   //---------------------------------------------------------------------------
00146   //: Return `this' if `this' is an digital_curve, 0 otherwise
00147   //---------------------------------------------------------------------------
00148   virtual vsol_digital_curve_2d const*cast_to_digital_curve()const{return this;}
00149   virtual vsol_digital_curve_2d *cast_to_digital_curve() {return this;}
00150 
00151  private: // has been superceeded by is_a()
00152   //: Return the curve type
00153   virtual vsol_curve_2d_type curve_type() const { return vsol_curve_2d::DIGITAL_CURVE; }
00154 
00155  public:
00156   //---------------------------------------------------------------------------
00157   //: Return the length of `this'
00158   //---------------------------------------------------------------------------
00159   virtual double length() const; // pure virtual of vsol_curve_2d
00160 
00161   //---------------------------------------------------------------------------
00162   //: Compute the bounding box of `this'
00163   //---------------------------------------------------------------------------
00164   virtual void compute_bounding_box() const;
00165 
00166   //---------------------------------------------------------------------------
00167   //: Return the number of vertices
00168   //---------------------------------------------------------------------------
00169   unsigned int size() const { return samples_.size(); }
00170 
00171   //---------------------------------------------------------------------------
00172   //: Is `i' a valid index for the list of vertices ?
00173   //---------------------------------------------------------------------------
00174   bool valid_index(unsigned int i) const { return i<samples_.size(); }
00175 
00176   //***************************************************************************
00177   // Basic operations
00178   //***************************************************************************
00179 
00180   //---------------------------------------------------------------------------
00181   //: output description to stream
00182   //---------------------------------------------------------------------------
00183   void describe(vcl_ostream &strm, int blanking=0) const;
00184 
00185   // ==== Binary IO methods ======
00186 
00187   //: Binary save self to stream.
00188   void b_write(vsl_b_ostream &os) const;
00189 
00190   //: Binary load self from stream.
00191   void b_read(vsl_b_istream &is);
00192 
00193   //: Return IO version number;
00194   short version() const;
00195 
00196   //: Print an ascii summary to the stream
00197   void print_summary(vcl_ostream &os) const;
00198 
00199   //: Return a platform independent string identifying the class
00200   virtual vcl_string is_a() const { return vcl_string("vsol_digital_curve_2d"); }
00201 
00202   //: Return true if the argument matches the string identifying the class or any parent class
00203   virtual bool is_class(vcl_string const& cls) const { return cls==is_a(); }
00204 };
00205 
00206 //: Binary save vsol_digital_curve_2d* to stream.
00207 void vsl_b_write(vsl_b_ostream &os, const vsol_digital_curve_2d* p);
00208 
00209 //: Binary load vsol_digital_curve_2d* from stream.
00210 void vsl_b_read(vsl_b_istream &is, vsol_digital_curve_2d* &p);
00211 
00212 //: Return the floating point index of the point on the curve nearest to \p point
00213 double closest_index(const vgl_point_2d<double>& point,
00214                      const vsol_digital_curve_2d_sptr& curve);
00215 
00216 //: Split the input curve into two pieces at the floating point index
00217 bool split(const vsol_digital_curve_2d_sptr& input,
00218            double index,
00219            vsol_digital_curve_2d_sptr& output1,
00220            vsol_digital_curve_2d_sptr& output2);
00221 
00222 #endif // vsol_digital_curve_2d_h_

Generated on Tue Oct 7 05:14:50 2008 for contrib/gel/vsol by  doxygen 1.5.1