AMCAX Kernel
Geometry kernel for CAD/CAE/CAM
九韶内核 1.0.0.0
载入中...
搜索中...
未找到
网格处理

增量式重网格化

AMCAX::Meshing::Remeshing::TriMesh_IncrementalRemeshing 实现对输入网格进行各向同性重网格化。当输入三维网格的点和面以及参数 Params 时,便会输出 incremental remesh(尽可能生成正三角形)后的点和面。

Params 中可以设置的参数 :

  • Max_error:与原网格的最大误差,用于计算自适应长度,参数越大,自适应长度会越长,默认值 0.0005
  • targetEdgeLength:目标边长与原网格所有边的平均长度的比值,默认值 0.5。长度范围是 [0.3*targetEdgeLength*meanLength,3*targetEdgeLength*meanLength]
  • isAdaptive:是否自适应,true 自适应,false 不自适应,默认值 false
  • featurePreserved:是否保持特征,true 保持,false 不保持,默认值 false
  • tolAngle:判断特征的角度阈值,弧度制,默认值 0.7854
  • iterNum:迭代次数,默认值 5,一般迭代 10 次足够

Incremental remesh主要步骤:

  1. 输入网格的点和面,可以根据实际情况自行读入某种格式 (obj/stl) 的文件
  2. 设置参数
  3. 初始化 reference mesh 和 variable mesh 的点和面
  4. 执行 remesh
  5. 输出为需要的文件格式 (obj/stl)
std::string inputfilename = "./data/32770_sf.obj";
io_options.vertex_has_point = true;
reader.read(inputfilename, io_options);
AMCAX::Meshing::Mesh::TriSoupTraits_Coord::Points input_points = std::move(reader.m_points);
AMCAX::Meshing::Mesh::TriSoupTraits_Coord::Triangles input_triangles = std::move(reader.m_triangles);
AMCAX::Meshing::Mesh::TriSoupTraits_Coord::Points output_points = input_points;
AMCAX::Meshing::Mesh::TriSoupTraits_Coord::Triangles output_triangles = input_triangles;
params.featurePreserved = true;
params.isAdaptive = true;
params.iterNum = 10;
params.Max_error = 0.0002;
params.targetEdgeLength = 0.2;
params.tolAngle = 60. / 180. * M_PI;
remesher.setReferenceMesh(input_points, input_triangles);
remesher.setVariableMesh(output_points, output_triangles);
remesher.remesh(params);
std::string outputfilename =
"incrementalRemeshing" + std::to_string(params.iterNum) + ".obj";
writer.m_points = std::move(output_points);
writer.m_triangles = std::move(output_triangles);
writer.write(outputfilename, io_options, 15);
Options about pre-described properties in mesh IO.
定义 IOOptions.hpp:19
Read triangle soup from an OBJ file.
定义 OBJReader.hpp:38
Points m_points
point position
定义 OBJReader.hpp:125
Triangles m_triangles
triangle faces
定义 OBJReader.hpp:130
AMCAXMeshing_API bool read(const std::string &filename, IOOptions &opt)
Read triangle soup from the file. results will be stored in member variables of reader,...
Write triangle soup to an OBJ file.
定义 OBJWriter.hpp:38
Triangles m_triangles
triangle faces
定义 OBJWriter.hpp:131
AMCAXMeshing_API bool write(const std::string &filename, IOOptions &opt, std::streamsize precision)
Write triangle soup to file with given options and precison.
Points m_points
point position
定义 OBJWriter.hpp:126
定义 TriMesh_IncrementalRemeshing.hpp:24
AMCAXMeshing_API void setReferenceMesh(const iPoints &points, const iTriangles &triangles)
add a triangle mesh (triangle soup) as one input.
AMCAXMeshing_API void setVariableMesh(iPoints &points, iTriangles &triangles)
Set the triangle mesh (triangle soup) as output destination.
AMCAXMeshing_API void remesh(Params params)
Adaptive/Isotropic remeshing controled by the control parameters
the parameters that control the remeshing
定义 TriMesh_IncrementalRemeshing.hpp:40
bool featurePreserved
Whether keep the feature or not, not yet implemented
定义 TriMesh_IncrementalRemeshing.hpp:57
double tolAngle
Dihedral angle greater than tolAngle (in radians) will be recognized as a feature edge,...
定义 TriMesh_IncrementalRemeshing.hpp:62
size_t iterNum
The iterations number
定义 TriMesh_IncrementalRemeshing.hpp:66
bool isAdaptive
If true, adaptive remeshing; else, isotropic remeshing
定义 TriMesh_IncrementalRemeshing.hpp:53
double targetEdgeLength
Target edge length expressed as a percentage of the mean length of all edges
定义 TriMesh_IncrementalRemeshing.hpp:49

网格切割与网格参数化

AMCAX::Meshing::TriMeshCut::GreedyCut< Traits >::cut 实现对封闭的曲面网格进行切割,使其与圆盘拓扑同胚,并尽可能的降低参数化扭曲,为参数化算法提供支持。需要注意的是网格切割算法具有随机性,因此每一次切割并不一致。
以下分别为切割后的网格(图中绿色线条为网格边界):

将切割网格作为参数化算法的输入,便得到参数化网格(参数化网格是一个平面的,不会自相交):

对 3D 曲面网格进行参数化,得到低扭曲、低自相交的平面参数化网格,为纹理贴图等应用提供支持。需要注意的是输入网格需要保证有切割的边界,并且无非流行结构(网格必须是 2 维流形网格),另外 stl 文件会在一定的误差范围内对点进行合并,所以需要在调用算法前对输入网格进行确认。

io_options.vertex_has_point = true;
std::string in_filename = "./data/cow.obj";
std::string out_cut_filename = "bunny_cut.obj";
std::string out_para_filename = "bunny_parameterization.obj";
// Read the object file
obj_reader.read(in_filename, io_options);
AMCAX::Meshing::Mesh::TriSoupTraits_Coord::Points i_points = std::move(obj_reader.m_points);
AMCAX::Meshing::Mesh::TriSoupTraits_Coord::Triangles i_triangles = std::move(obj_reader.m_triangles);
// Perform mesh cut
i_points, i_triangles, true);
AMCAX::Meshing::Mesh::TriSoupTraits_Coord::Points cut_points;
AMCAX::Meshing::Mesh::TriSoupTraits_Coord::Triangles cut_triangles;
mesh_cut.cut(cut_points, cut_triangles);
// Write the cut mesh to a new file
obj_writer.m_points = cut_points;
obj_writer.m_triangles = cut_triangles;
obj_writer.write(out_cut_filename, io_options, 10);
obj_writer.clear();
AMCAX::Meshing::Mesh::TriSoupTraits_Coord::Points para_points;
// Perform bijective parameterization on the cut mesh
cut_points, cut_triangles, para_points,true);
para.parameterization();
// Write the parameterized cut mesh to a new file
obj_writer.m_points = std::move(para_points);
obj_writer.m_triangles = std::move(cut_triangles);
obj_writer.write(out_para_filename, io_options, 10);
AMCAXMeshing_API void clear()
Clear data stored in writer
定义 MeshParameterization.hpp:23