00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 # ifndef shape_mesher2d_dual_hpp
00012 # define shape_mesher2d_dual_hpp
00013
00014 # include <shape/subdivision.hpp>
00015 # include <shape/cell2d.hpp>
00016 # include <shape/tpl3d.hpp>
00017 # include <shape/dualize2d.hpp>
00018 # include <shape/polygonizer2d.hpp>
00019
00020 # undef Cell
00021 # define TMPL template<class Cell, class V>
00022 # define TMPL1 template<class V>
00023 # define Viewer viewer<W>
00024 # define SELF mesher2d_dual<Cell,V>
00025
00026 namespace mmx { namespace shape {
00027
00028 struct mesher2d_dual_def {};
00029
00030 template<> struct use<mesher2d_dual_def, default_env>
00031 {
00032 template<class Topo, class Cell> static
00033 void polygonise(Topo* t, Cell* c) { c->polygonise(t); }
00034 };
00035
00036
00037 template<class Cell, class V=default_env >
00038 struct mesher2d_dual : public PROCESS_OF(V)
00039 {
00040
00041 typedef double C;
00042 typedef Cell Shape;
00043 typedef subdivision<C,V,Cell> Subdivisor;
00044 typedef Cell Input;
00045 typedef mesh3d<C,V> Output;
00046 typedef typename Output::Point Point;
00047 typedef typename Output::Edge Edge;
00048 typedef typename Output::Face Face;
00049 typedef typename Cell::BoundingBox BoundingBox;
00050
00051 mesher2d_dual(double e1= 0.1, double e2=0.01);
00052 ~mesher2d_dual(void) ;
00053
00054 void set_input (Cell* cl) { m_input= cl; }
00055
00056 void set_smoothness(double e) { m_smooth = e; }
00057 void set_precision (double e) { m_prec = e; }
00058
00059 double get_smoothness(void) const { return m_smooth; }
00060 double get_precision (void) const { return m_prec; }
00061
00062 Input* input (void) { return m_input; }
00063 Output* output (void) { return m_output; }
00064
00065 void run(void);
00066 void clear(void);
00067
00068 private:
00069 double m_smooth ;
00070 double m_prec ;
00071
00072 Cell* m_input;
00073 Output* m_output;
00074
00075 };
00076
00077 TMPL SELF::mesher2d_dual(double e1, double e2): m_smooth(e1), m_prec(e2)
00078 {
00079 m_output = new Output;
00080 }
00081
00082 TMPL SELF::~mesher2d_dual(void) {
00083 delete m_output;
00084 }
00085
00086 TMPL void SELF::run(void) {
00087
00088 Subdivisor* sbd = new Subdivisor(m_smooth,m_prec);
00089 sbd->set_input(this->input());
00090 sbd->run();
00091
00092 typedef dualize<C,default_2d,Cell> Dualize;
00093 Dualize* dl = new Dualize(sbd->get_output());
00094 dl->run();
00095
00096 std::cout<< "\nCells = "<< sbd->get_output()->m_leaves.size()<<"\n";
00097 std::cout<< "Cells = "<< dl->get_output()->m_vertices.size()<<"\n";
00098 std::cout<< "Dual edges = "<< dl->get_output()->m_edges.size()/2<<"\n";
00099 std::cout<< "Dual faces = "<< dl->get_output()->m_faces.size()/4<<"\n";
00100
00101 typedef polygonizer<C,default_2d,typename Dualize::Output> Polygonizer;
00102 Polygonizer* plg = new Polygonizer(dl->get_output(), m_output);
00103 plg->run();
00104
00105 }
00106
00107
00108 TMPL void SELF::clear(void) {
00109 this->get_output()->clear();
00110 }
00111
00112 } ;
00113 } ;
00114
00115 # undef TMPL
00116 # undef TMPL1
00117 # undef Shape
00118 # undef Viewer
00119 # undef Graphic
00120 # undef SELF
00121 # endif