shape_doc 0.1
/Users/mourrain/Devel/mmx/shape/glue/glue_implicit_curve.hpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 * MODULE     : implicit_curve_glue.hpp
00003 * DESCRIPTION: Glue for implicit curve
00004 * COPYRIGHT  : (C) 2007 Bernard Mourrain
00005 *******************************************************************************
00006 * This software falls under the GNU general public license and comes WITHOUT
00007 * ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
00008 * If you don't have this file, write to the Free Software Foundation, Inc.,
00009 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00010 ******************************************************************************/
00011 #ifndef __MMX_SHAPE_IMPLICIT_CURVE_GLUE_HPP
00012 #define __MMX_SHAPE_IMPLICIT_CURVE_GLUE_HPP
00013 #include <basix/glue.hpp>
00014 #include <basix/tuple.hpp>
00015 #include <realroot/ring_sparse_glue.hpp>
00016 #include <glue_axel_viewer.hpp>
00017 #include <shape/BoundingBox.hpp>
00018 #include <shape/AlgebraicCurve.hpp>
00019 
00020 
00021 namespace mmx {
00022 
00023 #define CURVE shape::ImplicitCurve
00024 #define BOX   shape::BoundingBox
00025 #define Polynomial polynom< ring<mmx::rational,Sparse<DegReveLex> > >
00026 
00027   namespace shape {
00028     inline bool operator ==(const CURVE& v1, const CURVE& v2) {return true;}
00029     inline bool operator !=(const CURVE& v1, const CURVE& v2) {return !(v1==v2);}
00030     inline bool  eq(const CURVE& v1, const CURVE& v2) {return v1==v2;}
00031     inline bool neq(const CURVE& v1, const CURVE& v2) {return v1!=v2;}
00032     
00033     inline unsigned hash (const CURVE& v) 
00034     {
00035       register unsigned i, h= 214365, n=1;
00036       for (i=0; i<n; i++) h= (h<<1) ^ (h<<5) ^ (h>>27) ;//^ hash(v[i]);
00037       return h;
00038     }
00039     inline unsigned soft_hash (const CURVE& m) {return hash(m);}
00040 
00041     syntactic flatten (const CURVE& s) 
00042     {
00043       using namespace shape;
00044       
00045       syntactic res = "ImplicitCurve";
00046       
00047       vector<syntactic> box;
00048       box<<mmx::flatten(s.boundingBox()->xmin());
00049       box<<mmx::flatten(s.boundingBox()->xmax());
00050       box<<mmx::flatten(s.boundingBox()->ymin());
00051       box<<mmx::flatten(s.boundingBox()->ymax());
00052       
00053       return apply(res, mmx::flatten(s.equation()), mmx::flatten(box));
00054       
00055     }
00056   }
00057   
00058   CURVE implicit_curve_string (const string& eq)
00059   {
00060     return CURVE (as_charp(eq));
00061   }
00062 
00063   CURVE implicit_curve_string (const string& eq, const BOX& bx)
00064   {
00065     BOX* b = new BOX(bx);
00066     return CURVE(as_charp(eq), b);
00067   }
00068 
00069   CURVE implicit_curve(const Polynomial& eq, const BOX& bx)
00070   {
00071     BOX* b = new BOX(bx);
00072     return CURVE(eq, b);
00073   }
00074   
00075 
00076   axel::ostream& operator<<(axel::ostream& os, const CURVE& c)
00077   {
00078     os<<"<curve type=\"implicit\">\n";
00079     os<<"  <domain>"
00080       <<c.boundingBox()->xmin()<<" "<<c.boundingBox()->xmax()<<" "
00081       <<c.boundingBox()->ymin()<<" "<<c.boundingBox()->ymax()
00082       <<"</domain>\n";
00083     os<<"  <polynomial>";
00084     MPOLDST::print(os,c.equation(),Variables("x y"));
00085     os<<"</polynomial>\n";
00086     os<<"</curve>\n";
00087   return os;
00088   }
00089 
00090 
00091 #undef BOX
00092 #undef CURVE
00093 #undef Polynomial
00094 //====================================================================
00095 } // namespace mmx
00096 #endif // __MMX_IMPLICIT_CURVE_GLUE_HPP