shape_doc 0.1
|
00001 /***************************************************************************** 00002 * M a t h e m a g i x 00003 ***************************************************************************** 00004 * 2011-04-26 00005 * Bernard Mourrain 00006 ***************************************************************************** 00007 * Copyright (C) 2011 INRIA Sophia-Antipolis 00008 ***************************************************************************** 00009 * Comments : 00010 ****************************************************************************/ 00011 # ifndef shape_mesher3d_hpp 00012 # define shape_mesher3d_hpp 00013 00014 # include <shape/subdivision.hpp> 00015 # include <shape/tpl3d.hpp> 00016 00017 # define TMPL template<class C,class V, class Shape, class Cell> 00018 # define TMPL1 template<class V> 00019 # define Viewer viewer<W> 00020 # define SELF mesher3d<C,V,Shape,Cell> 00021 //==================================================================== 00022 namespace mmx { 00023 namespace shape { 00024 //==================================================================== 00025 struct mesher3d_def {}; 00026 00027 template<> struct use<mesher3d_def, default_env> 00028 { 00029 template<class Topo, class Cell> static 00030 void polygonise(Topo* t, Cell* c) { 00031 c->polygonise(t); 00032 } 00033 }; 00034 //-------------------------------------------------------------------- 00035 00036 template<class C,class V=default_env, class Shape=typename SHAPE_OF(V), class Cell=cell3d<C,V> > 00037 struct mesher3d : public PROCESS_OF(V) 00038 { 00039 typedef subdivision<C,V,Shape,Cell> Subdivisor; 00040 00041 typedef Cell Input; 00042 typedef tpl3d<C,V> Output; 00043 typedef typename Output::Point Point; 00044 typedef typename Output::Edge Edge; 00045 typedef typename Output::Face Face; 00046 typedef typename Cell::BoundingBox BoundingBox; 00047 00048 mesher3d(double e1= 0.1, double e2=0.01); 00049 ~mesher3d(void) ; 00050 00051 void set_input (Cell* cl) { m_input= cl; } 00052 void set_input (Shape* s, const BoundingBox& bx); 00053 00054 void set_smoothness(double e) { m_smooth = e; } 00055 void set_precision (double e) { m_prec = e; } 00056 00057 double get_smoothness(void) { return m_smooth; } 00058 double get_precision (void) { return m_prec; } 00059 00060 00061 Input* input (void) { return m_input; } 00062 Output* output (void) { return m_output; } 00063 00064 void run(void); 00065 void clear(void); 00066 00067 private: 00068 double m_smooth ; 00069 double m_prec ; 00070 00071 Cell* m_input; 00072 Output* m_output; 00073 00074 }; 00075 //-------------------------------------------------------------------- 00076 TMPL SELF::mesher3d(double e1, double e2): m_smooth(e1), m_prec(e2) 00077 { 00078 m_output = new Output; 00079 } 00080 00081 TMPL SELF::~mesher3d(void) { 00082 delete m_output; 00083 } 00084 //-------------------------------------------------------------------- 00085 TMPL void SELF::set_input(Shape* s, const BoundingBox& bx) 00086 { 00087 this->set_input(cell3d_factory<C,V>::instance()->create(s,bx)); 00088 } 00089 //-------------------------------------------------------------------- 00090 TMPL void SELF::run(void) { 00091 00092 Subdivisor* sbd = new Subdivisor(m_smooth,m_prec); 00093 sbd->set_input(this->input()); 00094 sbd->run(); 00095 00096 std::cout<< "leaves = "<< sbd->output()->m_leaves.size()<<"\n"; 00097 00098 foreach(Cell * cl, sbd->output()->m_leaves) { 00099 use<mesher3d_def,V>::polygonise(this->output(), cl); 00100 // marching_cube::polygonise(*this->output(), *cl); 00101 //foreach(Point* p, cl->m_points) this->output()->insert(p); 00102 } 00103 } 00104 00105 //-------------------------------------------------------------------- 00106 TMPL void SELF::clear(void) { 00107 this->output()->clear(); 00108 } 00109 //==================================================================== 00110 } ; // namespace shape 00111 } ; // namespace mmx 00112 //==================================================================== 00113 # undef TMPL 00114 # undef TMPL1 00115 # undef Shape 00116 # undef Viewer 00117 # undef Graphic 00118 # undef SELF 00119 # endif