shape_doc 0.1
|
00001 /***************************************************************************** 00002 * M a t h e m a g i x 00003 ***************************************************************************** 00004 * AlgebraicCurve 00005 * 2008-03-28 00006 * Julien Wintz 00007 ***************************************************************************** 00008 * Copyright (C) 2006 INRIA Sophia-Antipolis 00009 ***************************************************************************** 00010 * Comments : 00011 ****************************************************************************/ 00012 # ifndef algebraic_curve_hpp 00013 # define algebraic_curve_hpp 00014 00015 00016 # include <shape/curve.hpp> 00017 # include <shape/bounding_box.hpp> 00018 # include <shape/algebraic_set.hpp> 00019 00020 # define TMPL template<class C, class V> 00021 # define TMPL1 template<class V> 00022 # define SELF algebraic_curve<C,V> 00023 # define Viewer viewer<axel,V> 00024 //==================================================================== 00025 namespace mmx { 00026 namespace shape { 00027 00028 // TMPL struct algebraic_curve; 00029 00030 // struct algebraic_curve_def {}; 00031 00032 // TMPL1 struct use<algebraic_curve_def,V> 00033 // :public use<algebraic_set_def,V> 00034 // { 00035 // typedef curve<V> Curve; 00036 // typedef algebraic_curve<typename use<scalar_def,V>::Scalar,V> AlgebraicCurve; 00037 // }; 00038 //-------------------------------------------------------------------- 00039 00040 template<class C, class V=default_env> 00041 class algebraic_curve 00042 :public curve<REF_OF(V)> 00043 ,public algebraic_set<C,REF_OF(V)> 00044 { 00045 public: 00046 00047 typedef REF_OF(V) Ref; 00048 typedef typename algebraic_set<C,Ref>::Polynomial Polynomial; 00049 typedef curve<Ref> Curve; 00050 00051 algebraic_curve(void): Curve() {}; 00052 algebraic_curve(char* s) ; 00053 algebraic_curve(const char* s1, const char* s2); 00054 algebraic_curve(const Polynomial& eq) ; 00055 algebraic_curve(const Polynomial& eq1, const Polynomial& eq2); 00056 00057 ~algebraic_curve(void) {}; 00058 00059 }; 00060 00061 TMPL 00062 SELF::algebraic_curve(char * s): Curve() 00063 { 00064 typedef typename use<numeric_def,V>::Rational Coefficients; 00065 polynomial<Coefficients, with<Sparse,DegRevLex> >t(s, variables("x y")); 00066 Polynomial e; let::assign(e,t); 00067 this->insert(e); 00068 } 00069 00070 TMPL 00071 SELF::algebraic_curve(const char * s1, const char* s2) : Curve() 00072 { 00073 variables var("x y z"); 00074 //polynomial<double,with<Sparse,DegRevLex> > t1(s1, var); 00075 //Polynomial e1; let::assign(e1,t1); 00076 Polynomial e1(s1,var); 00077 this->insert(e1); 00078 00079 //polynomial<double,with<Sparse,DegRevLex> > t2(s2, var); 00080 //Polynomial e2; let::assign(e2,t2); 00081 Polynomial e2(s2,var); 00082 this->insert(e2); 00083 } 00084 00085 TMPL 00086 SELF::algebraic_curve(const Polynomial& s) : Curve() 00087 { 00088 this->insert(s); 00089 } 00090 00091 TMPL 00092 SELF::algebraic_curve(const Polynomial& p1, const Polynomial& p2) : Curve() 00093 { 00094 this->insert(p1); 00095 this->insert(p2); 00096 } 00097 00098 //-------------------------------------------------------------------- 00099 TMPL struct viewer; 00100 TMPL Viewer& 00101 operator<<(Viewer& os, const SELF& c) { 00102 typedef SELF AlgebraicCurve; 00103 typedef typename AlgebraicCurve::Polynomial Polynomial; 00104 os<<"<curve type=\"implicit\" color=\""<<(int)(255*os.color.r)<<" "<<(int)(255*os.color.g)<<" "<<(int)(255*os.color.b)<<"\">\n"; 00105 os<<" <domain>" 00106 <<os(0,0)<<" "<<os(0,1)<<" " 00107 <<os(1,0)<<" "<<os(1,1)<<" " 00108 <<os(2,0)<<" "<<os(2,1) 00109 <<"</domain>\n"; 00110 for(unsigned i=0; i<c.equations().size();i++) 00111 { 00112 typename use<numeric_def,V>::Integer m=1; 00113 Polynomial p=c.equation(i); 00114 for(typename Polynomial::const_iterator it=p.begin();it!=p.end();it++){ 00115 m = lcm(denominator(it->coeff()), m); 00116 } 00117 p*=(typename Polynomial::Scalar)m; 00118 os<<(char*)" <polynomial>"; 00119 print(os,p,variables("x y z")); 00120 os<<(char*)"</polynomial>\n"; 00121 } 00122 os<<"</curve>\n"; 00123 return os; 00124 } 00125 00126 00127 //==================================================================== 00128 } ; // namespace shape 00129 //==================================================================== 00130 00131 template<class OSTREAM, class C, class V> 00132 OSTREAM& operator<<(OSTREAM& os, const shape::SELF& cv) { 00133 os<<"AlgebraicCurve("; 00134 for(int i=0; i<cv.nbequation();i++){ 00135 if(i>0) os<<","; 00136 print(os,cv.equation(i),variables("x y z")); 00137 } 00138 os<<")"; 00139 return os; 00140 } 00141 00142 //==================================================================== 00143 } ; // namespace mmx 00144 //==================================================================== 00145 # undef TMPL 00146 # undef TMPL1 00147 # undef SELF 00148 # undef Viewer 00149 # endif // shape_algebraic_curve_hpp