shape_doc 0.1
|
00001 /***************************************************************************** 00002 * M a t h e m a g i x 00003 ***************************************************************************** 00004 * ParametricCurve 00005 * 2008-03-28 00006 * Julien Wintz 00007 ***************************************************************************** 00008 * Copyright (C) 2006 INRIA Sophia-Antipolis 00009 ***************************************************************************** 00010 * Comments : 00011 ****************************************************************************/ 00012 00013 # ifndef PARAMETRICCURVE_H 00014 # define PARAMETRICCURVE_H 00015 00016 # include <realroot/Seq.hpp> 00017 # include <shape/vertex.hpp> 00018 # include <shape/edge.hpp> 00019 # include <shape/curve.hpp> 00020 # include <shape/curve_pl.hpp> 00021 00022 # undef SELF 00023 # define TMPL template<class C, class V> 00024 # define SELF parametric_curve<C,V> 00025 # define REF REF_OF(V) 00026 # define PLCurve curve_pl<C,REF> 00027 //==================================================================== 00028 namespace mmx { 00029 namespace shape { 00030 00031 // TMPL struct parametric_curve; 00032 00033 // TMPL struct with_parametric_curve { 00034 // typedef parametric_curve<K> ParametricCurve; 00035 // }; 00036 00037 // TMPL struct parametric_curve_def 00038 // :public curve_def<K> 00039 // ,public with_point<K> 00040 // ,public with_point_set<K> 00041 // ,public with_parametric_curve<K> {}; 00042 00043 TMPL 00044 class parametric_curve : public curve<V> { 00045 public: 00046 typedef C Scalar; 00047 typedef point<C,REF> Point; 00048 typedef curve<REF> Curve; 00049 typedef bounding_box<C,REF> BoundingBox; 00050 typedef typename point_set<C,REF>::PointIterator PointIterator; 00051 00052 parametric_curve(void) {} ; 00053 parametric_curve(const BoundingBox box) : Curve(box) {} 00054 virtual ~parametric_curve(void){} ; 00055 00056 virtual double tmin(void) const = 0 ; 00057 virtual double tmax(void) const = 0 ; 00058 virtual void set_range(double tmin, double tmax) = 0; 00059 00060 virtual Point* eval (const double& t) const = 0 ; 00061 virtual Point* operator() (double t) const { return this->eval(t); } 00062 00063 virtual void eval (Point&, Scalar) const = 0 ; 00064 virtual void sample (PointIterator, int) const; 00065 virtual void sample (Point*, const Scalar*, int) const; 00066 00067 virtual void subdivide(SELF*& a, SELF*& b, double t ) const = 0; 00068 00069 virtual Seq<Point *> critical_points(void) = 0 ; 00070 virtual Seq<Point *> extremal_points(void) = 0 ; 00071 virtual Seq<Point *> singular_points(void) = 0 ; 00072 00073 } ; 00074 00075 TMPL void 00076 SELF::sample(PointIterator p, int n) const { 00077 assert(n>1); 00078 Scalar h=(this->tmax() - this->tmin())/(n-1), t=tmin(); 00079 for (int i=0; i<n; i++, p++) { 00080 this->eval(*p, t); // SEGFAULT ? 00081 t+=h; 00082 } 00083 } 00084 00085 TMPL void 00086 SELF::sample(Point* res, const Scalar* t, int n) const { 00087 for ( Point * o = res; o != res + n; o++, t++ ) 00088 this->eval(*o,*t); 00089 } 00090 00091 00092 TMPL PLCurve* 00093 mesh(SELF* pc ) { 00094 typedef typename PLCurve::Edge Edge; 00095 int n = 500; 00096 PLCurve* res = new PLCurve;//n,n-1,0,0,false); 00097 pc->sample(res->begin(), n); 00098 for ( int i = 0; i < n-1; i ++ ) { 00099 res->push_edge(new Edge(&res->vertex(i),&res->vertex(i+1))); 00100 } 00101 return res; 00102 } 00103 00104 } // namespace shape 00105 } // namespace mmx 00106 # undef TMPL 00107 # undef TMPL_DEF 00108 # undef REF 00109 # undef PLCurve 00110 # undef SELF 00111 # endif // PARAMETRICCURVE_H