文件:linear_cell_complex_3_operations.cpp

    事先创建的三个六面体
    image.png image.png
    缝合结果
    image.pngimage.png
    插入的结果
    image.pngimage.png

    完整代码

    1. #include <CGAL/Linear_cell_complex_for_combinatorial_map.h>
    2. #include <CGAL/Linear_cell_complex_for_generalized_map.h>
    3. #include <vector>
    4. #ifdef _DEBUG
    5. #include <CGAL/draw_linear_cell_complex.h>
    6. #endif // _DEBUG
    7. typedef CGAL::Linear_cell_complex_for_combinatorial_map<3> LCC_3_cmap;
    8. typedef CGAL::Linear_cell_complex_for_generalized_map<3> LCC_3_gmap;
    9. template<typename LCC,
    10. typename Map = typename LCC::Combinatorial_data_structure>
    11. struct Alpha1
    12. {
    13. static typename LCC::Dart_handle run(LCC&, typename LCC::Dart_handle dh)
    14. {
    15. return dh;
    16. }
    17. };
    18. template<typename LCC>
    19. struct Alpha1<LCC, CGAL::Generalized_map_tag>
    20. {
    21. static typename LCC::Dart_handle run(LCC& lcc, typename LCC::Dart_handle dh)
    22. {
    23. return lcc.template alpha<1>(dh);
    24. }
    25. };
    26. template<typename LCC>
    27. void run_test()
    28. {
    29. typedef typename LCC::Point Point;
    30. typedef typename LCC::Dart_handle Dart_handle;
    31. LCC lcc;
    32. //创建三个六面体
    33. Dart_handle dh1 = lcc.
    34. make_hexahedron(Point(0, 0, 0), Point(1, 0, 0),
    35. Point(1, 2, 0), Point(0, 2, 0),
    36. Point(0, 3, 4), Point(0, 0, 4),
    37. Point(6, 0, 4), Point(6, 3, 4));
    38. Dart_handle dh2 = lcc.
    39. make_hexahedron(Point(0, -5, 0), Point(2, -5, 0),
    40. Point(2, -2, 0), Point(0, -2, 0),
    41. Point(1, -1, 5), Point(1, -2, 5),
    42. Point(5, -2, 5), Point(5, -2, 5));
    43. Dart_handle dh3 = lcc.
    44. make_hexahedron(Point(1, 0, 5), Point(0, 0, 6),
    45. Point(0, 2, 5), Point(1, 2, 6),
    46. Point(1, 3, 8), Point(0, 0, 8),
    47. Point(5, 0, 9), Point(7, 3, 9));
    48. #ifdef _DEBUG
    49. CGAL::draw(lcc);
    50. #endif // _DEBUG
    51. //缝合
    52. lcc.template sew<3>(dh1, lcc.other_orientation
    53. (lcc.template opposite<2>
    54. (lcc.next(lcc.next(lcc.template opposite<2>(dh2))))));
    55. lcc.template sew<3>(lcc.template opposite<2>(lcc.next(dh1)),
    56. lcc.other_orientation(lcc.template opposite<2>(lcc.previous(dh3))));
    57. #ifdef _DEBUG
    58. CGAL::draw(lcc);
    59. #endif // _DEBUG
    60. lcc.insert_cell_1_in_cell_2(lcc.next(dh1),
    61. Alpha1<LCC>::run(lcc, lcc.previous(dh1)));
    62. dh2 = lcc.template opposite<2>(lcc.next(lcc.next
    63. (lcc.template opposite<2>(dh1))));
    64. lcc.insert_cell_1_in_cell_2(dh2, Alpha1<LCC>::run
    65. (lcc, lcc.next(lcc.next(dh2))));
    66. std::vector<Dart_handle> path;
    67. path.push_back(lcc.next(dh1));
    68. path.push_back(lcc.next(lcc.template opposite<2>(lcc.previous(dh1))));
    69. path.push_back(lcc.previous(dh2));
    70. path.push_back(lcc.next(lcc.template opposite<2>(dh2)));
    71. lcc.insert_cell_2_in_cell_3(path.begin(), path.end());
    72. lcc.display_characteristics(std::cout) << ", valid="
    73. << lcc.is_valid() << std::endl;
    74. #ifdef _DEBUG
    75. CGAL::draw(lcc);
    76. #endif // _DEBUG
    77. }
    78. int main()
    79. {
    80. //组合地图
    81. run_test<LCC_3_cmap>();
    82. //广义地图
    83. //run_test<LCC_3_gmap>();
    84. return EXIT_SUCCESS;
    85. }