CGAL中combinational map 的遍历方法
1.遍历整个CM的函数
cm.number_of_attributes ()<i> const | Returns the number of i-attributes in cm. |
cm.darts <i>() | Returns a range of all the darts in cm. |
cm.attributes<i> () | Returns a range of all the i-attributes in cm. |
cm.one_dart_per_cell<i,j,dim=dimension> () | Returns a range of one dart of each i-cell in cm. Cells are considered in dim dimension. |
2.遍历和给定Dart_handle相关的cell
cm.darts_of_orbit <i>( Dart_handle dh) | Returns a range of all the darts of the orbit <Beta...>(dh) |
cm.darts_of_cell <i,dim=dimension>( Dart_handle dh) | Returns a range of all the darts of the i-cell containing dh. i-cells are considered in dim dimension. |
cm.one_dart_per_incident_cell<i,j,dim=dimensioin> ( Dart_handle dh) | Returns a range of one dart of each i-cell incident to the j-cell containing dh. |
遍历顺序(一个立方体,编号顺序和有限元中一样)
1 Assembly_su* assembly; 2 Dart_handle dh; 3 void print_lcc(){ 4 cout<<"summary : "<<endl; 5 assembly->display_characteristics(cout); 6 cout<<endl; 7 } 8 void setLabel2(){ 9 static int faceIndices[]={1,2,5,4,0,3}; 10 int n=0; 11 Assembly_su::One_dart_per_incident_cell_range<2,3> 12 dr=assembly->one_dart_per_incident_cell<2,3>(dh); 13 for(Assembly_su::One_dart_per_incident_cell_range<2,3>::iterator itr=dr.begin();itr!=dr.end();++itr){ 14 Dart_handle dh1=itr; 15 assembly->set_attribute<2>(dh1,assembly->create_attribute<2>()); 16 dh1->attribute<2>()->info().setLabel(faceIndices[n]); 17 n++; 18 } 19 } 20 void setLabel3(){ 21 int n=0; 22 Assembly_su::One_dart_per_incident_cell_range<3,3> 23 dr=assembly->one_dart_per_incident_cell<3,3>(dh); 24 for(Assembly_su::One_dart_per_incident_cell_range<3,3>::iterator itr=dr.begin();itr!=dr.end();++itr){ 25 Dart_handle dh1=itr; 26 assembly->set_attribute<3>(dh1,assembly->create_attribute<3>()); 27 dh1->attribute<3>()->info().setLabel(n); 28 n++; 29 } 30 } 31 void setLabel0(){ 32 Assembly_su::One_dart_per_incident_cell_range<0,3> 33 dr=assembly->one_dart_per_incident_cell<0,3>(dh); 34 for(Assembly_su::One_dart_per_incident_cell_range<0,3>::iterator itr=dr.begin();itr!=dr.end();++itr){ 35 Dart_handle dh1=itr; 36 int l=int(assembly->point(dh1).x()); 37 dh1->attribute<0>()->info().setLabel(l); 38 } 39 } 40 void setLabel(){ 41 setLabel0(); 42 setLabel2(); 43 setLabel3(); 44 } 45 int size_of_face(const Dart_handle& dh){ 46 Assembly_su::One_dart_per_incident_cell_range<0,2> dr_02=assembly->one_dart_per_incident_cell<0,2>(dh); 47 return dr_02.size(); 48 } 49 void print_node(const Dart_handle& dh){ 50 cout<<dh->attribute<0>()->info().label()<<"("; 51 cout<<dh->attribute<2>()->info().label()<<")"; 52 } 53 void print_face(const Dart_handle& dh){ 54 cout<<"nodes of face "; 55 cout<<dh->attribute<2>()->info().label()<<" : "; 56 Assembly_su::One_dart_per_incident_cell_range<0,2> dr=assembly->one_dart_per_incident_cell<0,2>(dh); 57 for(Assembly_su::One_dart_per_incident_cell_range<0,2>::iterator itr=dr.begin();itr!=dr.end();++itr){ 58 print_node(itr); 59 cout<<" "; 60 } 61 cout<<", size : "<<size_of_face(dh); 62 cout<<endl; 63 } 64 void test_one_dart_per_incident_cell(){ 65 cout<<"one_dart_per_incident_cell<0,3>(dh) : "<<endl; 66 Assembly_su::One_dart_per_incident_cell_range<0,3> dr=assembly->one_dart_per_incident_cell<0,3>(dh); 67 for(Assembly_su::One_dart_per_incident_cell_range<0,3>::iterator itr=dr.begin();itr!=dr.end();++itr){ 68 print_node(itr); 69 cout<<assembly->point(itr); 70 cout<<endl; 71 } 72 cout<<"one_dart_per_incident_cell<2,3>(dh) : "<<endl; 73 Assembly_su::One_dart_per_incident_cell_range<2,3> dr_23=assembly->one_dart_per_incident_cell<2,3>(dh); 74 for(Assembly_su::One_dart_per_incident_cell_range<2,3>::iterator itr=dr_23.begin();itr!=dr_23.end();++itr){ 75 print_face(itr); 76 } 77 cout<<"one_dart_per_incident_cell<0,2>(dh) : "<<endl; 78 Assembly_su::One_dart_per_incident_cell_range<0,2> dr_02=assembly->one_dart_per_incident_cell<0,2>(dh); 79 for(Assembly_su::One_dart_per_incident_cell_range<0,2>::iterator itr=dr_02.begin();itr!=dr_02.end();++itr){ 80 print_node(itr); 81 cout<<" "; 82 } 83 cout<<endl; 84 } 85 void test_darts_of_orbit(){ 86 cout<<"nodes of orbit 0 : "<<endl; 87 Assembly_su::Dart_of_orbit_range<0> do_0=assembly->darts_of_orbit<0>(dh); 88 for(Assembly_su::Dart_of_orbit_range<0>::iterator itr=do_0.begin();itr!=do_0.end();++itr){ 89 cout<<"\t"; 90 print_node(itr); 91 cout<<endl; 92 } 93 cout<<"nodes of orbit 1 : "<<endl; 94 Assembly_su::Dart_of_orbit_range<1> do_1=assembly->darts_of_orbit<1>(dh); 95 for(Assembly_su::Dart_of_orbit_range<1>::iterator itr=do_1.begin();itr!=do_1.end();++itr){ 96 cout<<"\t"; 97 print_node(itr); 98 cout<<endl; 99 } 100 cout<<"nodes of orbit 2 : "<<endl; 101 Assembly_su::Dart_of_orbit_range<2> do_2=assembly->darts_of_orbit<2>(dh); 102 for(Assembly_su::Dart_of_orbit_range<2>::iterator itr=do_2.begin();itr!=do_2.end();++itr){ 103 cout<<"\t"; 104 print_node(itr); 105 cout<<endl; 106 } 107 cout<<"nodes of orbit 3 : "<<endl; 108 Assembly_su::Dart_of_orbit_range<3> do_3=assembly->darts_of_orbit<3>(dh); 109 for(Assembly_su::Dart_of_orbit_range<3>::iterator itr=do_3.begin();itr!=do_3.end();++itr){ 110 cout<<"\t"; 111 print_node(itr); 112 cout<<endl; 113 } 114 } 115 void test_darts_of_cell(){ 116 cout<<"nodes of cell 0 : "<<endl; 117 Assembly_su::Dart_of_cell_range<0> do_0=assembly->darts_of_cell<0>(dh); 118 for(Assembly_su::Dart_of_cell_range<0>::iterator itr=do_0.begin();itr!=do_0.end();++itr){ 119 cout<<"\t"; 120 print_node(itr); 121 cout<<endl; 122 } 123 cout<<"nodes of cell 1 : "<<endl; 124 Assembly_su::Dart_of_cell_range<1> do_1=assembly->darts_of_cell<1>(dh); 125 for(Assembly_su::Dart_of_cell_range<1>::iterator itr=do_1.begin();itr!=do_1.end();++itr){ 126 cout<<"\t"; 127 print_node(itr); 128 cout<<endl; 129 } 130 cout<<"nodes of cell 2 : "<<endl; 131 Assembly_su::Dart_of_cell_range<2> do_2=assembly->darts_of_cell<2>(dh); 132 for(Assembly_su::Dart_of_cell_range<2>::iterator itr=do_2.begin();itr!=do_2.end();++itr){ 133 cout<<"\t"; 134 print_node(itr); 135 cout<<endl; 136 } 137 cout<<"nodes of cell 3 : "<<endl; 138 Assembly_su::Dart_of_cell_range<3> do_3=assembly->darts_of_cell<3>(dh); 139 for(Assembly_su::Dart_of_cell_range<3>::iterator itr=do_3.begin();itr!=do_3.end();++itr){ 140 cout<<"\t"; 141 print_node(itr); 142 cout<<endl; 143 } 144 } 145 int main(){ 146 system("echo %time%"); 147 assembly=new Assembly_su; 148 vector<Point> p(8); 149 for(int i=0;i<8;i++){ 150 p[i]=Point((double)i,0.,0.); 151 } 152 dh=assembly->make_hexahedron(p[0],p[3],p[2],p[1],p[5],p[4],p[7],p[6]); 153 setLabel(); 154 print_lcc(); 155 test_one_dart_per_incident_cell(); 156 test_darts_of_orbit(); 157 test_darts_of_cell(); 158 delete assembly; 159 system("echo %time%"); 160 return 0; 161 }
输出结果如下,括号中为面的编号:
16:16:10.42
summary :
#Darts=24, #0-cells=8, #1-cells=12, #2-cells=6, #3-cells=1, #ccs=1
one_dart_per_incident_cell<0,3>(dh) :
0(1)0 0 0
4(1)4 0 0
7(1)7 0 0
3(1)3 0 0
1(2)1 0 0
5(2)5 0 0
6(5)6 0 0
2(4)2 0 0
one_dart_per_incident_cell<2,3>(dh) :
nodes of face 1 : 0(1) 4(1) 7(1) 3(1) , size : 4
nodes of face 2 : 4(2) 0(2) 1(2) 5(2) , size : 4
nodes of face 5 : 7(5) 4(5) 5(5) 6(5) , size : 4
nodes of face 4 : 3(4) 7(4) 6(4) 2(4) , size : 4
nodes of face 0 : 0(0) 3(0) 2(0) 1(0) , size : 4
nodes of face 3 : 5(3) 1(3) 2(3) 6(3) , size : 4
one_dart_per_incident_cell<0,2>(dh) :
0(1) 4(1) 7(1) 3(1)
nodes of orbit 0 :
0(1)
3(1)
7(1)
4(1)
nodes of orbit 1 :
0(1)
4(1)
7(1)
3(1)
nodes of orbit 2 :
0(1)
4(2)
nodes of orbit 3 :
0(1)
nodes of cell 0 :
0(1)
0(0)
0(2)
nodes of cell 1 :
0(1)
4(2)
nodes of cell 2 :
0(1)
4(1)
7(1)
3(1)
nodes of cell 3 :
0(1)
4(1)
7(1)
3(1)
4(2)
0(2)
1(2)
5(2)
7(5)
4(5)
5(5)
6(5)
3(4)
7(4)
6(4)
2(4)
0(0)
3(0)
2(0)
1(0)
5(3)
1(3)
2(3)
6(3)
16:16:10.44