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_dualize3d_hpp 00012 # define shape_dualize3d_hpp 00013 00014 # include <shape/list.hpp> 00015 # include <shape/kdtree_cell.hpp> 00016 # include <shape/dualize.hpp> 00017 # define TMPL template<class C,class V,class Cell> 00018 # define TMPL1 template<class V> 00019 # define SELF dualize<C,V,Cell> 00020 //==================================================================== 00021 namespace mmx { namespace shape { 00022 //==================================================================== 00023 00024 00025 00026 template<class C> 00027 struct use<dualize_def,C,default_env> { 00028 00029 template<class Cell> 00030 struct graph { 00031 00032 typedef node<Cell*> Node; 00033 00034 public: 00035 Seq<Cell*> m_edges; 00036 Seq<Cell*> m_faces; 00037 Seq<Cell*> m_cells; 00038 }; 00039 00040 template <class Tree, class Node> 00041 static void insert_vertex(Tree* t, Node* n){ 00042 // t->output()->m_vertices<<n->get_cell(); 00043 } 00044 00045 template <class Tree, class Node> 00046 static void insert_edge(Tree* t, Node* n1, Node* n2){ 00047 t->get_output()->m_edges<<n1->get_cell()<<n2->get_cell(); 00048 } 00049 00050 template <class Tree, class Node> 00051 static void insert_face(Tree* t, Node* n1, Node* n2, Node* n3, Node* n4){ 00052 t->get_output()->m_faces<<n1->get_cell()<<n2->get_cell()<<n3->get_cell()<<n4->get_cell(); 00053 } 00054 00055 00056 template <class Tree, class Node> 00057 static void insert_cell(Tree* t, 00058 Node* n1, Node* n2, Node* n3, Node* n4, 00059 Node* n5, Node* n6, Node* n7, Node* n8) { 00060 t->get_output()->m_cells<<n1->get_cell()<<n2->get_cell()<<n3->get_cell()<<n4->get_cell() 00061 <<n5->get_cell()<<n6->get_cell()<<n7->get_cell()<<n8->get_cell(); 00062 } 00063 00064 template <class Tree, class Node> 00065 static void dual_edge(Tree* t, Node* n1, Node* n2) { 00066 t->get_dual_edge(n1, n2); 00067 } 00068 00069 template <class Tree, class Node> 00070 static void dual_face(Tree* t, Node* n1, Node* n2, Node* n3, Node* n4) { 00071 if (is_adjacent(n1,n4) && is_adjacent(n2,n3)) 00072 t->get_dual_face(n1, n2, n3, n4); 00073 } 00074 00075 template <class Tree, class Node> 00076 static void dual_cell(Tree* t, 00077 Node* n1, Node* n2, Node* n3, Node* n4, 00078 Node* n5, Node* n6, Node* n7, Node* n8) { 00079 t->get_dual_cell(n1, n2, n3, n4, n5, n6, n7, n8); 00080 } 00081 }; 00082 00083 00084 //template<class C,class V=default_env, class Cell=cell<C,V> > 00085 //struct dualize: public PROCESS_OF(V) 00086 //{ 00087 00088 // typedef node<Cell*> Node; 00089 // typedef kdtree_cell<Cell> Input; 00090 // typedef graph_dual<Cell> Output; 00091 00092 // dualize(void); 00093 // ~dualize(void) ; 00094 00095 // void input (Input* i) { m_input = i; } 00096 // Input* input (void) { return m_input; } 00097 // Output* output (void) { return m_output; } 00098 00099 // void update(); 00100 00101 // void get_dual_vertex(Node*); 00102 // void get_dual_edge (Node*, Node*); 00103 // void get_dual_face (Node*, Node*, Node*, Node*); 00104 // void get_dual_cell (Node*, Node*, Node*, Node*, Node*, Node*, Node*, Node*); 00105 00106 // void clear(void); 00107 00108 //private: 00109 // Input* m_input; 00110 // Output* m_output; 00111 //}; 00113 //TMPL SELF::dualize() { 00114 // m_output = new Output; 00115 //} 00117 //TMPL SELF::~dualize(void) { 00118 // delete m_output; 00119 //} 00121 //TMPL void SELF::get_dual_vertex(Node* n) { 00122 // if(!n->get_cell()->is_active()) return; 00123 // if(!n->is_leaf()) { 00124 // this->get_dual_vertex(n->left()); 00125 // this->get_dual_vertex(n->right()); 00126 // this->get_dual_edge(n->left(),n->right()); 00127 // } 00128 // return; 00129 //} 00130 00132 //TMPL void SELF::get_dual_edge(Node* n1, Node* n2) { 00133 00134 // // if(!is_adjacent(n1,n2)) return; 00135 00136 // if(!n1->get_cell()->is_active()) return; 00137 // if(!n2->get_cell()->is_active()) return; 00138 00139 // if(!n1->is_leaf()) { 00140 // //if (is_adjacent(n1->left(),n2)) 00141 // get_dual_edge(n1->left(), n2); 00142 // //if (is_adjacent(n1->right(),n2)) 00143 // get_dual_edge(n1->right(), n2); 00144 // //if (is_adjacent(n1->left(),n2) && is_adjacent(n1->right(),n2)) 00145 // get_dual_face(n1->right(), n1->left(), n2, n2); 00146 // return; 00147 // } 00148 00149 // if(!n2->is_leaf()){ 00150 // //if (is_adjacent(n1,n2->left())) 00151 // get_dual_edge(n1,n2->left()); 00152 // //if (is_adjacent(n1,n2->right())) 00153 // get_dual_edge(n1,n2->right()); 00154 // //if (is_adjacent(n1,n2->left()) && is_adjacent(n1,n2->right())) 00155 // get_dual_face(n1, n1, n2->left(), n2->right()); 00156 // return; 00157 // } 00158 00159 // this->output()->m_edges<<n1->get_cell()<<n2->get_cell(); 00160 // return; 00161 //} 00162 00164 //TMPL void SELF::get_dual_face(Node* n1, Node* n2, Node* n3, Node* n4) { 00165 // if(!n1->get_cell()->is_active()) return; 00166 // if(!n2->get_cell()->is_active()) return; 00167 // if(!n3->get_cell()->is_active()) return; 00168 // if(!n4->get_cell()->is_active()) return; 00169 00170 // //std::cout<<"\nFace "; 00171 // // if(is_adjacent(n1,n2) && 00172 // // is_adjacent(n2,n3) && 00173 // // is_adjacent(n3,n4) && 00174 // // is_adjacent(n4,n1)) std::cout << " OK"; 00175 00176 // if(!is_adjacent(n1,n2) || 00177 // !is_adjacent(n2,n3) || 00178 // !is_adjacent(n3,n4) || 00179 // !is_adjacent(n4,n1) ) return; 00180 00181 00182 // if(!n1->is_leaf()) { 00183 // if (is_adjacent(n1->left(),n2) && is_adjacent(n1->left(),n4)) 00184 // get_dual_face(n1->left(),n2,n3,n4); 00185 // if (is_adjacent(n1->right(),n2) && is_adjacent(n1->right(),n4)) 00186 // get_dual_face(n1->right(),n2,n3,n4); 00187 00188 // if (is_adjacent(n1->left() ,n2) && is_adjacent(n1->left() ,n4) && 00189 // is_adjacent(n1->right(),n2) && is_adjacent(n1->right(),n4) ) 00190 // get_dual_cell(n1->left(), n2,n3,n4, n1->right(),n2,n3,n4); 00191 // return; 00192 // } 00193 00194 // if(!n2->is_leaf()) { 00195 // if (is_adjacent(n1,n2->left()) && is_adjacent(n2->left(),n3)) 00196 // get_dual_face(n1,n2->left(), n3,n4); 00197 // if (is_adjacent(n1,n2->right()) && is_adjacent(n2->right(),n3)) 00198 // get_dual_face(n1,n2->right(),n3,n4); 00199 00200 // if (is_adjacent(n1,n2->left() ) && is_adjacent(n2->left() ,n3) && 00201 // is_adjacent(n1,n2->right()) && is_adjacent(n2->right(),n3) ) 00202 // get_dual_cell(n1,n2->left(), n3,n4, n1,n2->right(),n3,n4); 00203 // return; 00204 // } 00205 00206 // if(!n3->is_leaf()) { 00207 // if (is_adjacent(n2,n3->left()) && is_adjacent(n3->left(),n4)) 00208 // get_dual_face(n1,n2,n3->left(), n4); 00209 // if (is_adjacent(n2,n3->right()) && is_adjacent(n3->right(),n4)) 00210 // get_dual_face(n1,n2,n3->right(),n4); 00211 00212 // if (is_adjacent(n2,n3->left() ) && is_adjacent(n3->left() ,n4) && 00213 // is_adjacent(n2,n3->right()) && is_adjacent(n3->right(),n4) ) 00214 // get_dual_cell(n1,n2,n3->left(),n4, n1,n2,n3->right(),n4); 00215 // return; 00216 // } 00217 00218 // if(!n4->is_leaf()) { 00219 // if (is_adjacent(n3,n4->left()) && is_adjacent(n4->left(),n1)) 00220 // get_dual_face(n1,n2,n3,n4->left()); 00221 // if (is_adjacent(n3,n4->right()) && is_adjacent(n4->right(),n1)) 00222 // get_dual_face(n1,n2,n3,n4->right()); 00223 00224 // if (is_adjacent(n3,n4->left() ) && is_adjacent(n4->left() ,n1) && 00225 // is_adjacent(n3,n4->right()) && is_adjacent(n4->right(),n1) ) 00226 // get_dual_cell(n1,n2,n3, n4->left(), n1,n2,n3, n4->right()); 00227 // return; 00228 // } 00229 00230 // this->output()->m_faces<<n1->get_cell()<<n2->get_cell()<<n3->get_cell()<<n4->get_cell(); 00231 // return; 00232 //} 00234 //TMPL void SELF::get_dual_cell(Node* n1, Node* n2, Node* n3, Node* n4, 00235 // Node* n5, Node* n6, Node* n7, Node* n8) { 00236 00237 // if(!n1->get_cell()->is_active() && 00238 // !n2->get_cell()->is_active() && 00239 // !n3->get_cell()->is_active() && 00240 // !n4->get_cell()->is_active() && 00241 // !n5->get_cell()->is_active() && 00242 // !n6->get_cell()->is_active() && 00243 // !n7->get_cell()->is_active() && 00244 // !n8->get_cell()->is_active()) return; 00245 00246 // // std::cout<<"\nCell "; 00247 // // if(!is_adjacent(n1,n2) || 00248 // // !is_adjacent(n2,n3) || 00249 // // !is_adjacent(n3,n4) || 00250 // // !is_adjacent(n4,n1) || 00251 // // !is_adjacent(n1,n5) || 00252 // // !is_adjacent(n2,n6) || 00253 // // !is_adjacent(n3,n7) || 00254 // // !is_adjacent(n4,n8) 00255 // // ) return; 00256 // // else 00257 // // std::cout<<" OK "; 00258 00259 // if(!n1->is_leaf()) { 00260 // if (is_adjacent(n1->left(),n2) && is_adjacent(n1->left(),n4) && is_adjacent(n1->left(),n5)) 00261 // get_dual_cell(n1->left(), n2,n3,n4,n5,n6,n7,n8); 00262 // if (is_adjacent(n1->right(),n2) && is_adjacent(n1->right(),n4) && is_adjacent(n1->right(),n5)) 00263 // get_dual_cell(n1->right(),n2,n3,n4,n5,n6,n7,n8); 00264 // return; 00265 // } 00266 00267 // if(!n2->is_leaf()) { 00268 // if (is_adjacent(n1,n2->left()) && is_adjacent(n2->left(),n3) && is_adjacent(n2->left(),n6)) 00269 // get_dual_cell(n1,n2->left(), n3,n4,n5,n6,n7,n8); 00270 // if (is_adjacent(n1,n2->right()) && is_adjacent(n2->right(),n3) && is_adjacent(n2->right(),n6)) 00271 // get_dual_cell(n1,n2->right(),n3,n4,n5,n6,n7,n8); 00272 // return; 00273 // } 00274 00275 // if(!n3->is_leaf()) { 00276 // if (is_adjacent(n2,n3->left()) && is_adjacent(n3->left(),n4) && is_adjacent(n3->left(),n7)) 00277 // get_dual_cell(n1,n2,n3->left(), n4,n5,n6,n7,n8); 00278 // if (is_adjacent(n2,n3->right()) && is_adjacent(n3->right(),n4) && is_adjacent(n3->right(),n7)) 00279 // get_dual_cell(n1,n2,n3->right(),n4,n5,n6,n7,n8); 00280 // return; 00281 // } 00282 00283 // if(!n4->is_leaf()) { 00284 // if (is_adjacent(n3,n4->left()) && is_adjacent(n4->left(),n1) && is_adjacent(n4->left(),n8)) 00285 // get_dual_cell(n1,n2,n3,n4->left(), n5,n6,n7,n8); 00286 // if (is_adjacent(n3,n4->right()) && is_adjacent(n4->right(),n1) && is_adjacent(n4->right(),n8)) 00287 // get_dual_cell(n1,n2,n3,n4->right(),n5,n6,n7,n8); 00288 // return; 00289 // } 00290 00291 00292 // if(!n8->is_leaf()) { 00293 // if (is_adjacent(n4,n8->left()) && is_adjacent(n7,n8->left()) && is_adjacent(n8->left(),n5)) 00294 // get_dual_cell(n1,n2,n3,n4,n5,n6,n7,n8->left() ); 00295 // if (is_adjacent(n4,n8->right()) && is_adjacent(n7,n8->right()) && is_adjacent(n8->right(),n5)) 00296 // get_dual_cell(n1,n2,n3,n4,n5,n6,n7,n8->right()); 00297 // return; 00298 // } 00299 00300 // if(!n7->is_leaf()) { 00301 // if (is_adjacent(n3,n7->left()) && is_adjacent(n6,n7->left()) && is_adjacent(n7->left(),n8)) 00302 // get_dual_cell(n1,n2,n3,n4,n5,n6,n7->left(), n8); 00303 // if (is_adjacent(n3,n7->right()) && is_adjacent(n6,n7->right()) && is_adjacent(n7->right(),n8)) 00304 // get_dual_cell(n1,n2,n3,n4,n5,n6,n7->right(),n8); 00305 // return; 00306 // } 00307 00308 // if(!n6->is_leaf()) { 00309 // if (is_adjacent(n2,n6->left()) && is_adjacent(n5,n6->left()) && is_adjacent(n6->left(),n7)) 00310 // get_dual_cell(n1,n2,n3,n4,n5,n6->left(), n7,n8); 00311 // if (is_adjacent(n2,n6->right()) && is_adjacent(n5,n6->right()) && is_adjacent(n6->right(),n7)) 00312 // get_dual_cell(n1,n2,n3,n4,n5,n6->right(),n7,n8); 00313 // return; 00314 // } 00315 00316 // if(!n5->is_leaf()) { 00317 // if (is_adjacent(n1,n5->left()) && is_adjacent(n5->left(),n6) && is_adjacent(n8,n5->left())) 00318 // get_dual_cell(n1,n2,n3,n4,n5->left(), n6,n7,n8); 00319 // if (is_adjacent(n1,n5->right()) && is_adjacent(n5->right(),n6) && is_adjacent(n8,n5->right())) 00320 // get_dual_cell(n1,n2,n3,n4,n5->right(),n6,n7,n8); 00321 // return; 00322 // } 00323 00324 // this->output()->m_cells<<n1->get_cell()<<n2->get_cell()<<n3->get_cell()<<n4->get_cell() 00325 // <<n5->get_cell()<<n6->get_cell()<<n7->get_cell()<<n8->get_cell(); 00326 //} 00328 //TMPL void SELF::update() { 00329 // this->get_dual_vertex(m_input->root()); 00330 //} 00332 //TMPL void SELF::clear(void) { 00333 00334 //} 00335 00336 //==================================================================== 00337 } ; // namespace shape 00338 } ; // namespace mmx 00339 //==================================================================== 00340 # undef TMPL 00341 # undef TMPL1 00342 # undef SELF 00343 # endif