00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 # ifndef shape_polygonizer2d_hpp
00012 # define shape_polygonizer2d_hpp
00013
00014 # include <shape/list.hpp>
00015 # include <shape/tpl3d.hpp>
00016 # include <shape/polygonizer.hpp>
00017 # include <shape/marching_cube.hpp>
00018
00019 # define TMPL template<class C, class Input, class Output>
00020 # define TMPL1 template<class V>
00021 # define SELF polygonizer<C,default_2d,Input,Output>
00022
00023 namespace mmx { namespace shape {
00024
00025
00026 template<class C, class Input, class Output >
00027 struct polygonizer<C,default_2d,Input,Output>: public PROCESS_OF(default_2d)
00028 {
00029
00030
00031
00032 typedef typename Output::Point Point;
00033 typedef typename Output::Edge Edge;
00034 typedef typename Output::Face Face;
00035
00036 polygonizer();
00037 polygonizer(Input* in);
00038 polygonizer(Input* in, Output* out);
00039 ~polygonizer(void) ;
00040
00041 void set_input (Input* i) { m_input = i; }
00042 Input* get_input (void) const { return m_input; }
00043
00044 void set_output (Output* o) { m_output = o; }
00045 Output* get_output (void) const { return m_output; }
00046
00047 void run();
00048 void clear(void);
00049
00050 private:
00051 Input* m_input;
00052 Output* m_output;
00053 };
00054
00055 TMPL SELF::polygonizer() {
00056 m_output = new Output;
00057 }
00058
00059 TMPL SELF::polygonizer(Input* in) {
00060 m_input = in;
00061 m_output = new Output;
00062 }
00063
00064 TMPL SELF::polygonizer(Input* in, Output* out) {
00065 m_input = in;
00066 m_output = out;
00067 }
00068
00069 TMPL SELF::~polygonizer(void) {
00070 delete m_output;
00071 }
00072
00073 TMPL void SELF::run() {
00074 typedef typename Input::value_type Cell;
00075
00076 unsigned n=0;
00077
00078 if(false) for(unsigned i=0; i< this->get_input()->m_vertices.size(); i++) {
00079 Cell* c=this->get_input()->m_vertices[i];
00080 if (c->m_center == NULL){
00081 if(false) {
00082 Point* p1 = new Point(c->xmin(),c->ymin(),0);
00083 m_output->insert_vertex(p1);p1->set_index(n);n++;
00084 Point* p2 = new Point(c->xmax(),c->ymin(),0);
00085 m_output->insert_vertex(p2);p2->set_index(n);n++;
00086 Point* p3 = new Point(c->xmax(),c->ymax(),0);
00087 m_output->insert_vertex(p3);p3->set_index(n);n++;
00088 Point* p4 = new Point(c->xmin(),c->ymax(),0);
00089 m_output->insert_vertex(p4);p4->set_index(n);n++;
00090 m_output->insert_edge(new Edge(p1,p2));
00091 m_output->insert_edge(new Edge(p2,p3));
00092 m_output->insert_edge(new Edge(p3,p4));
00093 m_output->insert_edge(new Edge(p4,p1));
00094 }
00095 c->m_center = new Point(c->center());
00096 m_output->insert_vertex(c->m_center);
00097 c->m_center->set_index(n); n++;
00098 }
00099 }
00100
00101 if(false) for(unsigned i=0; i< this->get_input()->m_edges.size(); i+=2) {
00102 if(!this->get_input()->m_edges[i]->m_center) {
00103 Cell* c=this->get_input()->m_vertices[i];
00104 c->m_center = new Point(c->center());
00105 m_output->insert_vertex(c->m_center);
00106 c->m_center->set_index(n); n++;
00107 }
00108 if(!this->get_input()->m_edges[i+1]->m_center) {
00109 Cell* c=this->get_input()->m_vertices[i];
00110 c->m_center = new Point(c->center());
00111 m_output->insert_vertex(c->m_center);
00112 c->m_center->set_index(n); n++;
00113 }
00114
00115 m_output->insert_edge(new Edge(this->get_input()->m_edges[i]->m_center,
00116 this->get_input()->m_edges[i+1]->m_center));
00117 }
00118
00119 Point points[8];
00120 C values[8];
00121
00122 Seq<Cell*> L = this->get_input()->m_faces;
00123
00124 for(unsigned i=0; i< L.size(); i+=4) {
00125
00126 for(unsigned j=0; j<4; j++) {
00127 points[j] = L[i+j]->center();
00128 values[j] = L[i+j]->center_value();
00129 }
00130
00131 marching_square::polygonize(*this->get_output(), points, values, (double)0);
00132
00133 if(false) {
00134 Point* p1 = new Point(this->get_input()->m_faces[i]->center());
00135 m_output->insert_vertex(p1);p1->set_index(n);n++;
00136 Point* p2 = new Point(this->get_input()->m_faces[i+1]->center());
00137 m_output->insert_vertex(p2);p2->set_index(n);n++;
00138 Point* p3 = new Point(this->get_input()->m_faces[i+2]->center());
00139 m_output->insert_vertex(p3);p3->set_index(n);n++;
00140 Point* p4 = new Point(this->get_input()->m_faces[i+3]->center());
00141 m_output->insert_vertex(p4);p4->set_index(n);n++;
00142 m_output->insert_edge(new Edge(p1,p2));
00143 m_output->insert_edge(new Edge(p2,p3));
00144 m_output->insert_edge(new Edge(p3,p4));
00145 m_output->insert_edge(new Edge(p4,p1));
00146 }
00147 }
00148
00149 }
00150
00151 TMPL void SELF::clear(void) {
00152 }
00153
00154
00155 } ;
00156 } ;
00157
00158 # undef TMPL
00159 # undef TMPL1
00160 # undef SELF
00161 # endif