contrib/gel/vsol/vsol_digital_curve_3d.h
Go to the documentation of this file.
00001 // This is gel/vsol/vsol_digital_curve_3d.h
00002 #ifndef vsol_digital_curve_3d_h_
00003 #define vsol_digital_curve_3d_h_
00004 //:
00005 // \file
00006 // \brief Digital curve in 3D with interpolation
00007 // Identical in interface and implementation to vsol_digital_curve_2d
00008 //
00009 // \author Peter Vanroose
00010 // \date   24 September 2004
00011 
00012 #include <vgl/vgl_fwd.h>
00013 #include <vsl/vsl_binary_io.h>
00014 #include <vsol/vsol_curve_3d.h>
00015 #include <vsol/vsol_point_3d_sptr.h>
00016 #include <vsol/vsol_digital_curve_3d_sptr.h>
00017 #include <vcl_vector.h>
00018 #include <vcl_string.h>
00019 #include <vcl_iosfwd.h>
00020 
00021 //: Digital curve class, part of the vsol_curve_3d hierarchy
00022 // The curve is made up of vsol points and has no addition data members
00023 // \relatesalso vdgl_digital_curve
00024 
00025 class vsol_digital_curve_3d : public vsol_curve_3d
00026 {
00027  protected:
00028   //: List of points
00029   vcl_vector<vsol_point_3d_sptr> samples_;
00030 
00031  public:
00032   // Default Constructor
00033   vsol_digital_curve_3d() : vsol_curve_3d(), samples_() {}
00034 
00035   //: Constructor from a list of points
00036   vsol_digital_curve_3d(vcl_vector<vsol_point_3d_sptr> const& sample_points)
00037     : vsol_curve_3d(), samples_(sample_points) {}
00038 
00039   // Copy constructor
00040   vsol_digital_curve_3d(vsol_digital_curve_3d const& other);
00041 
00042   // Destructor
00043   virtual ~vsol_digital_curve_3d() {}
00044 
00045   //: Clone `this': creation of a new object and initialization
00046   // See Prototype pattern
00047   virtual vsol_spatial_object_3d* clone() const;
00048 
00049   //: Return the first point of `this'
00050   virtual vsol_point_3d_sptr p0() const; // pure virtual of vsol_curve_3d
00051 
00052   //: Return the last point of `this'
00053   virtual vsol_point_3d_sptr p1() const; // pure virtual of vsol_curve_3d
00054 
00055   //: Return point `i'
00056   //  REQUIRE: valid_index(i)
00057   vsol_point_3d_sptr point(unsigned int i) const;
00058 
00059   //: Linearly interpolate a point on the curve given a floating point index
00060   //  \note index is NOT arc length.  For example, if size()==10
00061   //        then interp(5.5) is interpolated half way between points
00062   //        at indices 5 and 6.  In general this is not at 5.5 units along
00063   //        the curve or even at 55% through the curve.
00064   //  \note interp(i) and point(i) will return the same point if i is integer.
00065   vgl_point_3d<double> interp(double index) const;
00066 
00067   //: Has `this' the same points than `other' in the same order ?
00068   virtual bool operator==(vsol_digital_curve_3d const&) const;
00069   virtual bool operator==(vsol_spatial_object_3d const&) const; // virtual of vsol_spatial_object_3d
00070 
00071   //: Has `this' the same points than `other' and in the same order ?
00072   inline bool operator!=(vsol_digital_curve_3d const& c) const {return !operator==(c);}
00073 
00074   //: Set the first point of the curve
00075   //  REQUIRE: in(new_p0)
00076   virtual void set_p0(vsol_point_3d_sptr const& new_p0);
00077 
00078   //: Set the last point of the curve
00079   //  REQUIRE: in(new_p1)
00080   virtual void set_p1(vsol_point_3d_sptr const& new_p1);
00081 
00082   //: Add another point to the curve
00083   void add_vertex(vsol_point_3d_sptr const& new_p);
00084 
00085   //: Return `this' if `this' is a digital_curve, 0 otherwise
00086   virtual vsol_digital_curve_3d const*cast_to_digital_curve()const{return this;}
00087   virtual vsol_digital_curve_3d *cast_to_digital_curve() {return this;}
00088 
00089  private: // has been superseded by is_a()
00090   //: Return the curve type
00091   virtual vsol_curve_3d_type curve_type() const { return vsol_curve_3d::DIGITAL_CURVE; }
00092 
00093  public:
00094   //: Return the length of `this'
00095   virtual double length() const; // pure virtual of vsol_curve_3d
00096 
00097   //: Compute the bounding box of `this'
00098   virtual void compute_bounding_box() const;
00099 
00100   //: Return the number of sample points of this digital curve
00101   unsigned int size() const { return samples_.size(); }
00102 
00103   //: Is `i' a valid index for the list of sample points ?
00104   //  This is the case if i is between 0 (inclusive) and size() (exclusive).
00105   bool valid_index(unsigned int i) const { return i<samples_.size(); }
00106 
00107   //: output description to stream
00108   void describe(vcl_ostream &strm, int blanking=0) const;
00109 
00110   // ==== Binary IO methods ======
00111 
00112   //: Binary save self to stream.
00113   void b_write(vsl_b_ostream &os) const;
00114 
00115   //: Binary load self from stream.
00116   void b_read(vsl_b_istream &is);
00117 
00118   //: Return IO version number;
00119   short version() const;
00120 
00121   //: Print an ascii summary to the stream
00122   void print_summary(vcl_ostream &os) const;
00123 
00124   //: Return a platform independent string identifying the class
00125   virtual vcl_string is_a() const { return vcl_string("vsol_digital_curve_3d"); }
00126 
00127   //: Return true if the argument matches the string identifying the class or any parent class
00128   virtual bool is_class(vcl_string const& cls) const { return cls==is_a(); }
00129 };
00130 
00131 //: Binary save vsol_digital_curve_3d* to stream.
00132 void vsl_b_write(vsl_b_ostream &os, vsol_digital_curve_3d const* p);
00133 
00134 //: Binary load vsol_digital_curve_3d* from stream.
00135 void vsl_b_read(vsl_b_istream &is, vsol_digital_curve_3d* &p);
00136 
00137 //: Return the floating point index of the point on the curve nearest to \p point
00138 double closest_index(vgl_point_3d<double> const& point,
00139                      vsol_digital_curve_3d_sptr const& curve);
00140 
00141 //: Split the input curve into two pieces at the floating point index
00142 bool split(vsol_digital_curve_3d_sptr const& input,
00143            double index,
00144            vsol_digital_curve_3d_sptr& output1,
00145            vsol_digital_curve_3d_sptr& output2);
00146 
00147 #endif // vsol_digital_curve_3d_h_