这个示例与《示例:基于广义地图的线性单元复合体》的相同

    1. #include <CGAL/Linear_cell_complex_for_combinatorial_map.h>
    2. #include <iostream>
    3. #include <algorithm>
    4. typedef CGAL::Linear_cell_complex_for_combinatorial_map<3> LCC_3;
    5. typedef LCC_3::Dart_handle Dart_handle;
    6. typedef LCC_3::Point Point;
    7. //一个仿函数,用于遍历一个体元的所有顶点
    8. // Functor used to display all the vertices of a given volume.
    9. template<class LCC>
    10. struct Display_vol_vertices : public CGAL::cpp98::unary_function<LCC, void>
    11. {
    12. Display_vol_vertices(const LCC& alcc) :
    13. lcc(alcc),
    14. nb_volume(0)
    15. {}
    16. void operator() (typename LCC::Dart& d)
    17. {
    18. std::cout << "Volume " << ++nb_volume << " : ";
    19. for (typename LCC::template One_dart_per_incident_cell_range<0, 3>::
    20. const_iterator it = lcc.template one_dart_per_incident_cell<0, 3>
    21. (lcc.dart_handle(d)).begin(),
    22. itend = lcc.template one_dart_per_incident_cell<0, 3>
    23. (lcc.dart_handle(d)).end();
    24. it != itend; ++it)
    25. {
    26. std::cout << lcc.point(it) << "; ";
    27. }
    28. std::cout << std::endl;
    29. }
    30. private:
    31. const LCC& lcc; //线性单元复合体(体模型)
    32. unsigned int nb_volume; //该体元对应的索引(第nb_volume+1个体元)
    33. };
    34. int main()
    35. {
    36. LCC_3 lcc;
    37. // Create two tetrahedra.
    38. Dart_handle d1 = lcc.make_tetrahedron(Point(-1, 0, 0), Point(0, 2, 0),
    39. Point(1, 0, 0), Point(1, 1, 2));
    40. Dart_handle d2 = lcc.make_tetrahedron(Point(0, 2, -1),
    41. Point(-1, 0, -1),
    42. Point(1, 0, -1),
    43. Point(1, 1, -3));
    44. // Display all the vertices of the lcc by iterating on the
    45. // Vertex_attribute container.
    46. CGAL::IO::set_ascii_mode(std::cout);
    47. std::cout << "Vertices: ";
    48. for (LCC_3::Vertex_attribute_const_range::iterator
    49. v = lcc.vertex_attributes().begin(),
    50. vend = lcc.vertex_attributes().end();
    51. v != vend; ++v)
    52. std::cout << lcc.point_of_vertex_attribute(v) << "; ";
    53. std::cout << std::endl;
    54. // Display the vertices of each volume by iterating on darts.
    55. std::for_each(lcc.one_dart_per_cell<3>().begin(),
    56. lcc.one_dart_per_cell<3>().end(),
    57. Display_vol_vertices<LCC_3>(lcc));
    58. // 3-Sew the 2 tetrahedra along one facet
    59. lcc.sew<3>(d1, d2);
    60. // Display the vertices of each volume by iterating on darts.
    61. std::for_each(lcc.one_dart_per_cell<3>().begin(),
    62. lcc.one_dart_per_cell<3>().end(),
    63. Display_vol_vertices<LCC_3>(lcc));
    64. // Translate the second tetrahedra by a given vector
    65. LCC_3::Vector v(3, 1, 1);
    66. for (LCC_3::One_dart_per_incident_cell_range<0, 3>::iterator
    67. it = lcc.one_dart_per_incident_cell<0, 3>(d2).begin(),
    68. itend = lcc.one_dart_per_incident_cell<0, 3>(d2).end();
    69. it != itend; ++it)
    70. {
    71. lcc.point(it) = LCC_3::Traits::Construct_translated_point_3()
    72. (lcc.point(it), v);
    73. }
    74. // Display the vertices of each volume by iterating on darts.
    75. std::for_each(lcc.one_dart_per_cell<3>().begin(),
    76. lcc.one_dart_per_cell<3>().end(),
    77. Display_vol_vertices<LCC_3>(lcc));
    78. // We display the lcc characteristics.
    79. std::cout << "LCC characteristics: ";
    80. lcc.display_characteristics(std::cout) << ", valid=" << lcc.is_valid()
    81. << std::endl;
    82. return EXIT_SUCCESS;
    83. }