1. //自定义Point
    2. #include <CGAL/Linear_cell_complex_for_combinatorial_map.h>
    3. #include <iostream>
    4. #include <algorithm>
    5. template<typename K>
    6. struct mypoint : public K::Point_3
    7. {
    8. typedef typename K::Point_3 Base;
    9. mypoint() : mtype('a')
    10. {}
    11. mypoint(const Base& apoint) : Base(apoint),
    12. mtype('b')
    13. {}
    14. mypoint(const mypoint& apoint) : Base(apoint),
    15. mtype('c')
    16. {}
    17. mypoint(typename K::FT a, typename K::FT b, typename K::FT c) : Base(a,b,c),
    18. mtype('d')
    19. {}
    20. char type() const
    21. { return mtype; }
    22. private:
    23. char mtype;
    24. };
    25. template<typename K>
    26. struct mytraits: public CGAL::Linear_cell_complex_traits<3, K>
    27. {
    28. typedef mypoint<K> Point;
    29. };
    30. typedef mytraits<CGAL::Exact_predicates_inexact_constructions_kernel> Traits;
    31. typedef CGAL::Linear_cell_complex_for_combinatorial_map<3,3, Traits> LCC_3;
    32. typedef LCC_3::Dart_handle Dart_handle;
    33. typedef LCC_3::Point Point;
    34. typedef LCC_3::FT FT;
    35. //创建正方体
    36. Dart_handle make_iso_cuboid(LCC_3& lcc, const Point& basepoint, FT lg)
    37. {
    38. return lcc.make_hexahedron(basepoint,
    39. Traits::Construct_translated_point()
    40. (basepoint,Traits::Vector(lg,0,0)),
    41. Traits::Construct_translated_point()
    42. (basepoint,Traits::Vector(lg,lg,0)),
    43. Traits::Construct_translated_point()
    44. (basepoint,Traits::Vector(0,lg,0)),
    45. Traits::Construct_translated_point()
    46. (basepoint,Traits::Vector(0,lg,lg)),
    47. Traits::Construct_translated_point()
    48. (basepoint,Traits::Vector(0,0,lg)),
    49. Traits::Construct_translated_point()
    50. (basepoint,Traits::Vector(lg,0,lg)),
    51. Traits::Construct_translated_point()
    52. (basepoint,Traits::Vector(lg,lg,lg)));
    53. }
    54. int main()
    55. {
    56. LCC_3 lcc;
    57. //创建两个正方体
    58. // Create two iso_cuboids.
    59. Dart_handle d1 = make_iso_cuboid(lcc, Point(-2, 0, 0), 1);
    60. Dart_handle d2 = make_iso_cuboid(lcc, Point(0, 0, 0), 1);
    61. //缝合两个正方体
    62. // 3-Sew the two cubes along one facet.
    63. lcc.sew<3>(lcc.beta(d1, 1, 1, 2), lcc.beta(d2, 2));
    64. //将两个Cube相邻面做Barycentric三角剖分
    65. // Barycentric triangulation of the facet between the two cubes.
    66. lcc.insert_barycenter_in_cell<2>(lcc.beta(d2, 2));
    67. // Display all the vertices of the map.
    68. for (LCC_3::Vertex_attribute_range::iterator
    69. it=lcc.vertex_attributes().begin(),
    70. itend=lcc.vertex_attributes().end();
    71. it!=itend; ++it)
    72. {
    73. std::cout<<"point: "<<lcc.point_of_vertex_attribute(it)
    74. <<", "<<"type: "<<lcc.point_of_vertex_attribute(it).type()
    75. <<std::endl;
    76. }
    77. return EXIT_SUCCESS;
    78. }