D:\install\CGAL-5.3\examples\Linear_cell_complex\linear_cell_complex_3_with_colored_vertices.cpp

    image.png
    image.png
    image.png
    image.png

    1. #include <CGAL/Linear_cell_complex_for_combinatorial_map.h>
    2. #include <iostream>
    3. #include <algorithm>
    4. #ifdef _DEBUG
    5. #include <CGAL/draw_linear_cell_complex.h>
    6. #endif // _DEBUG
    7. struct Average_functor
    8. {
    9. template<class CellAttribute>
    10. void operator()(CellAttribute& ca1, CellAttribute& ca2)
    11. {
    12. ca1.info() = (ca1.info() + ca2.info()) / 2;
    13. }
    14. };
    15. struct Myitem
    16. {
    17. template<class Refs>
    18. struct Dart_wrapper
    19. {
    20. typedef CGAL::Cell_attribute_with_point< Refs, int, CGAL::Tag_true,
    21. Average_functor >
    22. Vertex_attribute;
    23. typedef std::tuple<Vertex_attribute> Attributes;
    24. };
    25. };
    26. typedef CGAL::Linear_cell_complex_traits
    27. <3, CGAL::Exact_predicates_inexact_constructions_kernel> Traits;
    28. typedef CGAL::Linear_cell_complex_for_combinatorial_map<3, 3, Traits, Myitem> LCC_3;
    29. typedef LCC_3::Dart_handle Dart_handle;
    30. typedef LCC_3::Point Point;
    31. typedef LCC_3::FT FT;
    32. //创建正方体
    33. //长方体中心点:basepoint
    34. //lg:长方体长度的一半
    35. Dart_handle make_iso_cuboid(LCC_3& lcc, const Point& basepoint, FT lg)
    36. {
    37. return lcc.make_hexahedron(basepoint,
    38. Traits::Construct_translated_point()
    39. (basepoint, Traits::Vector(lg, 0, 0)),
    40. Traits::Construct_translated_point()
    41. (basepoint, Traits::Vector(lg, lg, 0)),
    42. Traits::Construct_translated_point()
    43. (basepoint, Traits::Vector(0, lg, 0)),
    44. Traits::Construct_translated_point()
    45. (basepoint, Traits::Vector(0, lg, lg)),
    46. Traits::Construct_translated_point()
    47. (basepoint, Traits::Vector(0, 0, lg)),
    48. Traits::Construct_translated_point()
    49. (basepoint, Traits::Vector(lg, 0, lg)),
    50. Traits::Construct_translated_point()
    51. (basepoint, Traits::Vector(lg, lg, lg)));
    52. }
    53. int main()
    54. {
    55. LCC_3 lcc;
    56. std::cout << "==========创建两个正方体==========" << std::endl;
    57. // Create two iso_cuboids.
    58. Dart_handle d1 = make_iso_cuboid(lcc, Point(-2, 0, 0), 1);
    59. Dart_handle d2 = make_iso_cuboid(lcc, Point(0, 0, 0), 1);
    60. #ifdef _DEBUG
    61. //绘制
    62. CGAL::draw(lcc);
    63. #endif // _DEBUG
    64. std::cout << "==========为两个正方体设置颜色==========" << std::endl;
    65. //设置第一个正方体所有顶点颜色为1
    66. // Set the "color" of all vertices of the first cube to 1.
    67. for (LCC_3::One_dart_per_incident_cell_range<0, 3>::iterator
    68. it = lcc.one_dart_per_incident_cell<0, 3>(d1).begin(),
    69. itend = lcc.one_dart_per_incident_cell<0, 3>(d1).end(); it != itend; ++it)
    70. {
    71. lcc.info<0>(it) = 1;
    72. }
    73. //设置第二个正方体所有顶点颜色为2
    74. // Set the "color" of all vertices of the second cube to 19.
    75. for (LCC_3::One_dart_per_incident_cell_range<0, 3>::iterator it =
    76. lcc.one_dart_per_incident_cell<0, 3>(d2).begin(),
    77. itend = lcc.one_dart_per_incident_cell<0, 3>(d2).end(); it != itend; ++it)
    78. {
    79. lcc.info<0>(it) = 19;
    80. }
    81. #ifdef _DEBUG
    82. //绘制
    83. CGAL::draw(lcc);
    84. #endif // _DEBUG
    85. std::cout << "==========缝合==========" << std::endl;
    86. // 3-Sew the two cubes along one facet.
    87. lcc.sew<3>(lcc.beta(d1, 1, 1, 2), lcc.beta(d2, 2));
    88. #ifdef _DEBUG
    89. //绘制
    90. CGAL::draw(lcc);
    91. #endif // _DEBUG
    92. std::cout << "==========对两个Cube的公共面做Barycentric三角剖分==========" << std::endl;
    93. //对两个Cube的公共面做Barycentric三角剖分
    94. // Barycentric triangulation of the facet between the two cubes.
    95. Dart_handle d3 = lcc.insert_barycenter_in_cell<2>(lcc.beta(d2, 2));
    96. //设置新顶点的颜色为5。
    97. // Set the color of the new vertex to 5.
    98. lcc.info<0>(d3) = 5;
    99. // Display all the vertices of the map.
    100. for (LCC_3::Vertex_attribute_range::iterator
    101. it = lcc.vertex_attributes().begin(),
    102. itend = lcc.vertex_attributes().end();
    103. it != itend; ++it)
    104. {
    105. std::cout << "point: " << lcc.point_of_vertex_attribute(it) << ", " << "color: "
    106. << lcc.info_of_attribute<0>(it) << std::endl;
    107. }
    108. #ifdef _DEBUG
    109. //绘制
    110. CGAL::draw(lcc);
    111. #endif // _DEBUG
    112. return EXIT_SUCCESS;
    113. }