步骤一:创建两个四面体

步骤二:缝合这两个四面体
发现上面的两个四面体是相离的,我们可以使用方法进行缝合
步骤三:整体平移

完整代码
#include <CGAL/Linear_cell_complex_for_generalized_map.h>#include <iostream>#include <algorithm>#ifdef _DEBUG#include <CGAL/draw_linear_cell_complex.h>#endif // _DEBUGtypedef CGAL::Linear_cell_complex_for_generalized_map<3> LCC_3;typedef LCC_3::Dart_handle Dart_handle;typedef LCC_3::Point Point;typedef LCC_3::FT FT;//一个仿函数,用于遍历一个体元的所有顶点// Functor used to display all the vertices of a given volume.template<class LCC>struct Display_vol_vertices : public CGAL::cpp98::unary_function<LCC, void>{Display_vol_vertices(const LCC& alcc) :lcc(alcc),nb_volume(0){}void operator() (typename LCC::Dart& d){std::cout << "Volume " << ++nb_volume << " : ";for (typename LCC::template One_dart_per_incident_cell_range<0, 3>::const_iterator it = lcc.template one_dart_per_incident_cell<0, 3>(lcc.dart_handle(d)).begin(),itend = lcc.template one_dart_per_incident_cell<0, 3>(lcc.dart_handle(d)).end();it != itend; ++it){std::cout << lcc.point(it) << "; ";}std::cout << std::endl;}private:const LCC& lcc; //线性单元复合体(体模型)unsigned int nb_volume; //该体元对应的索引(第nb_volume+1个体元)};int main(){//创建一个线性单元复合体(即体模型)LCC_3 lcc;std::cout << "==========创建两个四面体==========" << std::endl;//创建两个四面体// Create two tetrahedra.Dart_handle d1 = lcc.make_tetrahedron(Point(-1, 0, 0), Point(0, 2, 0),Point(1, 0, 0), Point(1, 1, 2));Dart_handle d2 = lcc.make_tetrahedron(Point(0, 2, -1),Point(-1, 0, -1),Point(1, 0, -1),Point(1, 1, -3));//通过顶点属性容器上的迭代器,遍历线性单元复合体的所有顶点// Display all the vertices of the lcc by iterating on the// Vertex_attribute container.CGAL::IO::set_ascii_mode(std::cout);std::cout << "Vertices: ";for (LCC_3::Vertex_attribute_const_range::iteratorv = lcc.vertex_attributes().begin(),vend = lcc.vertex_attributes().end();v != vend; ++v)std::cout << lcc.point_of_vertex_attribute(v) << "; ";std::cout << std::endl;//通过darts上的迭代器,遍历体元的所有顶点// Display the vertices of each volume by iterating on darts.std::for_each(lcc.one_dart_per_cell<3>().begin(),lcc.one_dart_per_cell<3>().end(),Display_vol_vertices<LCC_3>(lcc));#ifdef _DEBUGCGAL::draw(lcc);#endif // _DEBUGstd::cout << "==========缝合两个四面体==========" << std::endl;//沿着一个面(两个四面体的公共面)缝合两个四面体// 3-Sew the 2 tetrahedra along one facetlcc.sew<3>(d1, d2);//通过darts上的迭代器,遍历体元的所有顶点// Display the vertices of each volume by iterating on darts.std::for_each(lcc.one_dart_per_cell<3>().begin(),lcc.one_dart_per_cell<3>().end(),Display_vol_vertices<LCC_3>(lcc));#ifdef _DEBUGCGAL::draw(lcc);#endif // _DEBUGstd::cout << "==========平移操作==========" << std::endl;//平移第二个四面体// Translate the second tetrahedra by a given vectorLCC_3::Vector v(3, 1, 1);for (LCC_3::One_dart_per_incident_cell_range<0, 3>::iteratorit = lcc.one_dart_per_incident_cell<0, 3>(d2).begin(),itend = lcc.one_dart_per_incident_cell<0, 3>(d2).end();it != itend; ++it){lcc.point(it) = LCC_3::Traits::Construct_translated_point_3()(lcc.point(it), v);}//通过darts上的迭代器,遍历体元的所有顶点// Display the vertices of each volume by iterating on darts.std::for_each(lcc.one_dart_per_cell<3>().begin(),lcc.one_dart_per_cell<3>().end(),Display_vol_vertices<LCC_3>(lcc));//检查线性单元复合体是否有效// We display the lcc characteristics.std::cout << "LCC characteristics: ";lcc.display_characteristics(std::cout) << ", valid=" << lcc.is_valid()<< std::endl;#ifdef _DEBUGCGAL::draw(lcc);#endif // _DEBUGreturn EXIT_SUCCESS;}
