特徴線のある表面メッシュからテトラメッシュ作成(CGALライブラリ)†
鋭い角にあるエッジなどの特徴線をもつ表面メッシュからテトラメッシュを作成します。ここで使用するCGALは、テトラメッシュ分割法としてデローニー分割法を使用しています。
入力となる表面メッシュは、血管を切断して作成しました。下絵の赤線のように、切断面と血管表面の交線が特徴線となっています。
テトラメッシュの生成は、計算幾何学ライブラリCGALの例題Meshing Domains with Sharp Featuresを修正して実施しました。出力ファイル形式はParaViewで可視化できるように、VTKライブラリの非構造メッシュ(Unstructured grid)形式(*.vtu)にしています。結果は以下の通り、切断線上にメッシュの節点が乗った、テトラメッシュが見事に作成されました。
ただし、特徴線を出すためには、関数
domain.detect_features();
を呼び出すだけでなく、関数Mesh_criteria criteriaで、edge_sizeを設定しないとうまくいかないので注意が必要です。
mesh_polyhedral_domain_with_features.cpp†
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Mesh_triangulation_3.h>
#include <CGAL/Mesh_complex_3_in_triangulation_3.h>
#include <CGAL/Mesh_criteria_3.h>
#include <CGAL/Polyhedral_mesh_domain_with_features_3.h>
#include <CGAL/make_mesh_3.h>
// IO
#include <CGAL/IO/Polyhedron_iostream.h>
#include <CGAL/IO/Complex_3_in_triangulation_3_to_vtk.h>
// VTK
#include <vtkSmartPointer.h>
#include <vtkUnstructuredGrid.h>
#include <vtkXMLUnstructuredGridWriter.h>
// STL
#include <string>
// Domain
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Polyhedral_mesh_domain_with_features_3<K> Mesh_domain;
// Triangulation
typedef CGAL::Mesh_triangulation_3<Mesh_domain>::type Tr;
typedef CGAL::Mesh_complex_3_in_triangulation_3<
Tr,Mesh_domain::Corner_index,Mesh_domain::Curve_segment_index> C3t3;
// Criteria
typedef CGAL::Mesh_criteria_3<Tr> Mesh_criteria;
// To avoid verbose function and named parameters call
using namespace CGAL::parameters;
int main()
{
// Create domain
Mesh_domain domain("data/mesh.off");
// Get sharp features
domain.detect_features();
// Mesh criteria
Mesh_criteria criteria(facet_angle=25, facet_size=0.3, edge_size=0.3, facet_distance=0.1,
cell_radius_edge_ratio=3);
// Mesh generation
C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria,
lloyd(time_limit=30),
no_exude(),
perturb(sliver_bound=10, time_limit=15));
// Set tetrahedron size (keep cell_radius_edge_ratio), ignore facets
Mesh_criteria new_criteria(cell_radius_edge_ratio=3, cell_size=0.4);
// Mesh refinement
CGAL::refine_mesh_3(c3t3, domain, new_criteria);
CGAL::perturb_mesh_3(c3t3, domain, time_limit=15);
// Output
//std::ofstream medit_file("out.mesh");
//c3t3.output_to_medit(medit_file);
vtkSmartPointer<vtkUnstructuredGrid> output =
vtkSmartPointer<vtkUnstructuredGrid>::New();
CGAL::output_c3t3_to_vtk_unstructured_grid(c3t3, output);
vtkSmartPointer<vtkXMLUnstructuredGridWriter> writer =
vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New();
writer->SetFileName("out.vtu");
writer->SetInputData(output);
writer->Update();
}
ダウンロードとビルド†
データファイルdata/mesh.off:
Last-modified: 2014-06-10 (火) 11:03:06

