AMCAX Kernel
Geometry kernel for CAD/CAE/CAM
九韶内核 1.0.0.0
载入中...
搜索中...
未找到
多边形网格细分建模

基本体构建

基本体包括平面矩形、立方体、圆柱体、圆锥体、圆台、球体、环面等。

MeshMakeRectangle(平面矩形)

AMCAX::SubD::MeshMakeRectangle mkRect(frame, 3, 3, 3, 3);
AMCAX::SubD::PolyMesh* mesh1 = mkRect.BuildMesh();
多边形网格接口中用于创建矩形的类
定义 MeshMakeRectangle.hpp:15
多边形网格结构的类。 当前版本未导出底层的接口功能
定义 PolyMesh.hpp:23
FrameT< double, 3 > Frame3
三维标架
定义 FrameT.hpp:885

MeshMakeCube(立方体)

AMCAX::SubD::MeshMakeCube makeCube(frame, 10, 10, 10, 10, 10, 10);
AMCAX::SubD::PolyMesh* mesh2 = makeCube.BuildMesh();
多边形网格接口中用于创建立方体的类
定义 MeshMakeCube.hpp:15

MeshMakeCylinder(圆柱体)

AMCAX::SubD::MeshMakeCylinder makeCylinder(frame, 2.0, 5.0);
AMCAX::SubD::PolyMesh* mesh3 = makeCylinder.BuildMesh();
多边形网格接口中用于创建圆柱体的类
定义 MeshMakeCylinder.hpp:15

MeshMakeCone(圆锥体)

AMCAX::SubD::MeshMakeCone meshmakeCone1(1., 1.);
AMCAX::SubD::PolyMesh* mesh4 = meshmakeCone1.BuildMesh();
多边形网格接口中用于创建圆锥体的类
定义 MeshMakeCone.hpp:15

MeshMakeCone(圆台)

AMCAX::SubD::MeshMakeCone meshmakeCone2(frame, 2., 1., 2.);
AMCAX::SubD::PolyMesh* mesh5 = meshmakeCone2.BuildMesh();

MeshMakeSphere(球体)

double r = 2.1;
AMCAX::SubD::PolyMesh* mesh6 = sphere.BuildMesh();
多边形网格接口中用于创建球体的类
定义 MeshMakeSphere.hpp:15

MeshMakeTorus(环面)

AMCAX::SubD::MeshMakeTorus maketorus(2.0, 0.5, 8, 4);
AMCAX::SubD::PolyMesh* mesh7 = maketorus.BuildMesh();
多边形网格接口中用于创建圆环体的类
定义 MeshMakeTorus.hpp:15

基本编辑功能

基本编辑功能包括遍历、添加面、细化、删除、分离、缝合等。

遍历

AMCAX::SubD::MeshTool 类提供遍历功能,具体如下:
AMCAX::SubD::MeshTool::EdgeVertexIndexs 用于获取 PolyMesh 中某条边顶点的索引;
AMCAX::SubD::MeshTool::FaceVertexIndexs 用于获取 PolyMesh 中某个面所有顶点的索引;
AMCAX::SubD::MeshTool::FaceEdgeIndexs 用于获取 PolyMesh 中某个面所有边的索引;
AMCAX::SubD::MeshTool::EdgeFaceIndexs 用于获取 PolyMesh 中与输入边相邻的面的索引;
AMCAX::SubD::MeshTool::VertEdgeIndexs 用于获取 PolyMesh 中与输入顶点相邻的边的索引;
AMCAX::SubD::MeshTool::VertFaceIndexs 用于获取 PolyMesh 中与输入顶点相邻的面的索引;
AMCAX::SubD::MeshTool::FaceAdjacentFaces 用于获取 PolyMesh 中与输入面相邻的面的索引。

获取 PolyMesh 中某条边的顶点的索引

AMCAX::SubD::MeshMakeCube makeCube(frame, 10, 10, 10, 10, 10, 10);
AMCAX::SubD::PolyMesh* mesh = makeCube.BuildMesh();
int edge = 0;
int vfirst, vlast;
//Get the vertices of the edge
AMCAX::SubD::MeshTool::EdgeVertexIndexs(mesh, edge, vfirst, vlast);
//Get the position of the vertex
static AMCAX_API const Point3 & Position(PolyMesh *mesh, int vert)
获取多边形网格中某一顶点的位置
static AMCAX_API void EdgeVertexIndexs(PolyMesh *mesh, int edge, int &vfirst, int &vlast)
获取多边形网格中某条边的顶点
PointT< double, 3 > Point3
三维点
定义 PointT.hpp:459

用于获取 PolyMesh 中某个面的所有顶点的索引

AMCAX::SubD::MeshMakeCube makeCube(frame, 10, 10, 10, 10, 10, 10);
AMCAX::SubD::PolyMesh* mesh = makeCube.BuildMesh();
int face = 0;
//Get the indices of vertices in face
std::vector< int > index = AMCAX::SubD::MeshTool::FaceVertexIndexs(mesh, face);
//Get the position of the vertex
static AMCAX_API std::vector< int > FaceVertexIndexs(PolyMesh *mesh, int face)
获取多边形网格中某一面上的顶点

获取 PolyMesh 中某个面的所有边的索引

AMCAX::SubD::MeshMakeCube makeCube(frame, 10, 10, 10, 10, 10, 10);
AMCAX::SubD::PolyMesh* mesh = makeCube.BuildMesh();
int face = 0;
//Get the edges of the face
std::vector< int > index_e = AMCAX::SubD::MeshTool::FaceEdgeIndexs(mesh, face);
static AMCAX_API std::vector< int > FaceEdgeIndexs(PolyMesh *mesh, int face)
获取多边形网格中某一面上的边

获取 PolyMesh 中与输入边相邻的面的索引

AMCAX::SubD::MeshMakeCube makeCube(frame, 10, 10, 10, 10, 10, 10);
AMCAX::SubD::PolyMesh* mesh = makeCube.BuildMesh();
int edge = 0;
//Get the faces adjacent to the input edge
std::vector< int > index_f = AMCAX::SubD::MeshTool::EdgeFaceIndexs(mesh, edge);
static AMCAX_API std::vector< int > EdgeFaceIndexs(PolyMesh *mesh, int edge)
获取多边形网格中与某一边相邻接的面

获取 PolyMesh 中与输入顶点相邻的边的索引

AMCAX::SubD::MeshMakeCube makeCube(frame, 10, 10, 10, 10, 10, 10);
AMCAX::SubD::PolyMesh* mesh = makeCube.BuildMesh();
int vertex = 0;
//Get the edges adjacent to the input vertex
std::vector< int > index_e1 = AMCAX::SubD::MeshTool::VertEdgeIndexs(mesh, vertex);
static AMCAX_API std::vector< int > VertEdgeIndexs(PolyMesh *mesh, int vert)
获取多边形网格中与某一顶点相邻接的边

获取 PolyMesh 中与输入顶点相邻的面的索引

AMCAX::SubD::MeshMakeCube makeCube(frame, 10, 10, 10, 10, 10, 10);
AMCAX::SubD::PolyMesh* mesh = makeCube.BuildMesh();
int vertex = 0;
//Get the faces adjacent to the input vertex
std::vector< int > index_f1 = AMCAX::SubD::MeshTool::VertFaceIndexs(mesh, vertex);
static AMCAX_API std::vector< int > VertFaceIndexs(PolyMesh *mesh, int vert)
获取多边形网格中与某一顶点相邻接的面

获取 PolyMesh 中与输入面相邻的面的索引

AMCAX::SubD::MeshMakeCube makeCube(frame, 10, 10, 10, 10, 10, 10);
AMCAX::SubD::PolyMesh* mesh = makeCube.BuildMesh();
int face = 0;
//Get the faces adjacent to the input face
std::vector< int > index_f2 = AMCAX::SubD::MeshTool::FaceAdjacentFaces(mesh, face);
static AMCAX_API std::vector< int > FaceAdjacentFaces(PolyMesh *mesh, int face)
获取多边形网格中与某一面相邻接的面

添加面

AMCAX::SubD::MeshInsertFace 类提供添加功能。具体如下:
AMCAX::SubD::MeshInsertFace::AddSingleFace 用于为 PolyMesh 添加由点构建的单个面;
AMCAX::SubD::MeshInsertFace::EmbedSingleFace 用于添加由某些 PolyMesh 顶点构建出的单个面;
AMCAX::SubD::MeshInsertFace::AddFaceByEdge 用于添加一个由两条边构成的单个面。

为 PolyMesh 添加由点构建出的单个面

AMCAX::SubD::MeshMakeCube makeCube(frame, 10, 10, 10, 10, 10, 10);
AMCAX::SubD::PolyMesh* mesh = makeCube.BuildMesh();
//Define point
AMCAX::Point3 p1(10., 2., 1.);
AMCAX::Point3 p2(12., 5., 3.);
AMCAX::Point3 p3(15., 7., 6.);
std::vector< AMCAX::Point3 > p = { p1,p2,p3 };
// Add a single face constructed from points to PolyMesh
static AMCAX_API MPolyFace * AddSingleFace(PolyMesh *mesh, const std::vector< Point3 > &points)
向多边形网格中添加由点集构造的单个面

为 PolyMesh 添加由某些 PolyMesh 顶点构建出的单个面

该顶点必须是边界顶点,边界顶点即这个顶点周围具有边界边(该边所属的面少于2个)或者没有边。

AMCAX::SubD::MeshMakeRectangle mkRect(frame, 15, 15, 1, 1);
AMCAX::SubD::PolyMesh* mesh3 = mkRect.BuildMesh();
//Add a single face constructed from some PolyMesh vert
std::vector< int > vlist{ 0,1,2 };
static AMCAX_API MPolyFace * EmbedSingleFace(PolyMesh *mesh, const std::vector< int > &vlist)
向多边形网格中添加由若干多边形网格顶点构造的单个面

为 PolyMesh 添加由两条边构建出的单个面

这两条边必须为边界边。

AMCAX::SubD::MeshMakeRectangle mkRect(frame, 15, 15, 1, 1);
AMCAX::SubD::PolyMesh* mesh3 = mkRect.BuildMesh();
int face = 0;
std::vector< int > index_e = AMCAX::SubD::MeshTool::FaceEdgeIndexs(mesh3, face);
//Add a single face constructed from two edges
AMCAX::SubD::MeshInsertFace::AddFaceByEdge(mesh3, index_e[1], index_e[2]);
static AMCAX_API MPolyFace * AddFaceByEdge(PolyMesh *mesh, int edge1, int edge2)
向多边形网格中添加由两条边构造的单个面

细化

AMCAX::SubD::MeshSplit 类提供细化功能。
建设中。

删除

AMCAX::SubD::MeshReduce 类提供删除功能。其中 AMCAX::SubD::MeshReduce::DeleteFaces 用于删除 PolyMesh 中的面(可以自由删除任意数目的面并留下洞。); AMCAX::SubD::MeshReduce::DeleteIsolatedVertices 用于删除 PolyMesh 中所有的孤立顶点。

删除面

AMCAX::SubD::MeshMakeCube makeCube(frame, 10, 10, 10, 10, 10, 10);
AMCAX::SubD::PolyMesh* mesh = makeCube.BuildMesh();
std::vector<int> face_id = { 1,3, 4 };
//Delete given faces
static AMCAX_API void DeleteFaces(PolyMesh *mesh, const std::vector< int > &flist)
删除多边形网格中的指定面

分离与缝合

AMCAX::SubD::MeshSeparate 类提供分离功能, AMCAX::SubD::MeshWeld 类提供缝合功能。

AMCAX::SubD::MeshMakeCube makeCube(frame, 10, 10, 10, 10, 10, 10);
AMCAX::SubD::PolyMesh* mesh = makeCube.BuildMesh();
std::vector< int >edge = { 1,2,3 };
//Separate
std::cout << r << std::endl;
//Weld
static AMCAX_API bool SeparateEdges(PolyMesh *mesh, const std::vector< int > &edges)
分离指定边使其相互独立,分离后的边将保持空间重叠直至被移动
static AMCAX_API void MeshWeldEdges(PolyMesh *mesh, const std::vector< int > &elist, double tolerance=0.01)
在多边形网格中查找输入边中在容差范围内的边,并将它们合并为内部边

拓扑建模功能

拓扑建模功能包括变换、拉伸、加厚、补洞等。

变换

AMCAX::SubD::MeshTransform 类提供变换功能。变换包括:
AMCAX::SubD::MeshTransform::TransformMeshEdges 对 PolyMesh 中的边列表应用变换;
AMCAX::SubD::MeshTransform::TransformMeshFaces 对 PolyMesh 中的面列表应用变换;
AMCAX::SubD::MeshTransform::TransformMeshVertices 对 PolyMesh 中的点列表应用变换。

对 PolyMesh 中的边列表应用变换

AMCAX::SubD::MeshMakeCube makeCube(frame, 10, 10, 10, 10, 10, 10);
AMCAX::SubD::PolyMesh* mesh = makeCube.BuildMesh();
//Set the transformation as the translation
double h = 2.;
AMCAX::Vector3 vh(frame.Direction().Coord() * h);
trsfMove.SetTranslation(vh);
trsfF.SetTransformation(trsfMove);
//Applying transformations to the edge list
std::vector< int > index_e = { 0,1,2 };
trsfF.TransformMeshEdges(mesh, index_e);
constexpr const CoordType & Coord() const noexcept
获取方向的内在坐标
定义 DirectionT.hpp:213
constexpr const DirectionT< Scalar, DIM > & Direction() const noexcept
获取三维主方向(z 方向)
定义 FrameT.hpp:441
对多边形网格进行变换的类
定义 MeshTransform.hpp:15
AMCAX_API void TransformMeshEdges(PolyMesh *mesh, const std::vector< int > &elist)
对多边形网格中指定的边列表应用变换
AMCAX_API void SetTransformation(const Transformation3 &t)
设置要应用的变换
constexpr void SetTranslation(const VectorT< OtherScalar, DIM > &vec) noexcept
设置变换为平移
定义 TransformationT.hpp:311
TransformationT< double, 3 > Transformation3
三维变换
定义 TransformationT.hpp:1102
VectorT< double, 3 > Vector3
三维向量
定义 VectorT.hpp:707

对 PolyMesh 中的面列表应用变换

AMCAX::SubD::MeshMakeCube makeCube(frame, 10, 10, 10, 10, 10, 10);
AMCAX::SubD::PolyMesh* mesh = makeCube.BuildMesh();
//Set the transformation as the translation
double h = 2.;
AMCAX::Vector3 vh(frame.Direction().Coord() * h);
trsfMove.SetTranslation(vh);
trsfF.SetTransformation(trsfMove);
//Applying transformations to the face list
std::vector< int > index_f = { 50,70,90,100 };
trsfF.TransformMeshFaces(mesh, index_f);
AMCAX_API void TransformMeshFaces(PolyMesh *mesh, const std::vector< int > &flist)
对多边形网格中指定的面列表应用变换

对 PolyMesh 中的顶点列表应用变换

AMCAX::SubD::MeshMakeCube makeCube(frame, 10, 10, 10, 10, 10, 10);
AMCAX::SubD::PolyMesh* mesh = makeCube.BuildMesh();
//Set the transformation as the translation
double h = 2.;
AMCAX::Vector3 vh(frame.Direction().Coord() * h);
trsfMove.SetTranslation(vh);
trsfF.SetTransformation(trsfMove);
//Applying transformations to the vertex list
std::vector< int > index_v = { 5,7,9,11 };
trsfF.TransformMeshVertices(mesh, index_v);
AMCAX_API void TransformMeshVertices(PolyMesh *mesh, const std::vector< int > &vlist)
对多边形网格中指定的顶点列表应用变换

拉伸

AMCAX::SubD::MeshExtrude 类提供拉伸功能。其中 AMCAX::SubD::MeshExtrude::ExtrudeEdge 用于拉伸边, AMCAX::SubD::MeshExtrude::ExtrudeFace 用于拉伸面。
建设中。

加厚

AMCAX::SubD::MeshOffset 类提供加厚功能。

double h = 2;
AMCAX::SubD::MeshMakeRectangle mkRect(frame, 3, 3, 3, 3);
AMCAX::SubD::PolyMesh* mesh = mkRect.BuildMesh();
//Thicken a mesh
static AMCAX_API bool ThickenMesh(PolyMesh *mesh, double dist, bool isConnect=true)
加厚多边形网格以生成拟合壳体或为多边形网格赋予厚度

补洞

AMCAX::SubD::MeshFillHole 类提供补洞功能。其中 AMCAX::SubD::MeshFillHole::FillAllHole 可补 PolyMesh 中所有的洞; AMCAX::SubD::MeshFillHole::FillSingleHole 可补 PolyMesh 中的某一个洞(输入边的id为洞任意一条边的id)。

补 PolyMesh 中的某一个洞

AMCAX::SubD::MeshMakeCube makeCube(frame, 10, 10, 10, 10, 10, 10);
AMCAX::SubD::PolyMesh* mesh = makeCube.BuildMesh();
//Delete given faces
std::vector<int> face_id = { 1,3, 4 };
//Get the edges of the face
int face = 0;
std::vector< int > index_e = AMCAX::SubD::MeshTool::FaceEdgeIndexs(mesh, face);
//Fill a hole with input edge
bool r = AMCAX::SubD::MeshFillHole::FillSingleHole(mesh, index_e[1]);
std::cout << r << std::endl;
static AMCAX_API bool FillSingleHole(PolyMesh *mesh, int edge)
使用单个多边形面填充输入边所在的孔

补 PolyMesh 中所有的洞

AMCAX::SubD::MeshMakeCube makeCube(frame, 10, 10, 10, 10, 10, 10);
AMCAX::SubD::PolyMesh* mesh = makeCube.BuildMesh();
//Delete given faces
std::vector<int> face_id = { 1,3, 4 };
//Fill all holes in PolyMesh
std::cout << r2 << std::endl;
static AMCAX_API bool FillAllHole(PolyMesh *mesh)
使用单个多边形面填充多边形网格中的所有孔

网格细分

网格细分包括两种:Catmull-Clark 细分和 Loop 细分,其中 Catmull-Clark 细分支持任意网格,Loop 细分仅支持三角形网格(可以通过三角化 AMCAX::SubD::MeshTool::MeshTriangles 得到全三角形网格)。

Catmull-Clark 细分

double r = 1;
double h = 1;
AMCAX::SubD::MeshMakeCone meshmakeCone(r, h);
AMCAX::SubD::PolyMesh* mesh = meshmakeCone.BuildMesh();
//Do Catmull-Clark Subdivision for input mesh
static AMCAX_API void CatmullClark(PolyMesh *mesh, size_t subTime)
对输入的多边形网格执行 Catmull-Clark 细分

另外为提升细分效率,内核还提供 AMCAX::SubD::MeshSubdivideRenderCC(针对全四边形的网格)。其结果和Catmull-Clark 细分结果相同,顶点数目相同,但顺序不同,因此不能进行比较。另外可以通过一次细分 AMCAX::MeshSubdivideHE::CatmullClark(mesh, 1) 得到全四边形网格。

double r = 1;
double h = 1;
AMCAX::SubD::MeshMakeCone meshmakeCone(r, h);
AMCAX::SubD::PolyMesh* mesh = meshmakeCone.BuildMesh();
//Do Catmull-Clark subdivision for input mesh
bool r1 = subdivide.DoCatmullClark(mesh, 1);
std::cout << r1 << std::endl;
多边形网格接口中用于对四边形网格执行 Catmull-Clark 细分的类
定义 MeshSubdivideRender.hpp:15
AMCAX_API bool DoCatmullClark(PolyMesh *mesh, size_t subtime)
对四边形网格执行 Catmull-Clark 细分

Loop 细分

double r = 1;
double h = 1;
AMCAX::SubD::MeshMakeCone meshmakeCone3(r, h);
AMCAX::SubD::PolyMesh* mesh3 = meshmakeCone3.BuildMesh();
//Make a mesh to triangular mesh
// Do Loop subdivision for input mesh
static AMCAX_API void Loop(PolyMesh *mesh, size_t subTime)
对输入的三角网格执行 Loop 细分,仅适用于三角网格
static AMCAX_API void MeshTriangles(PolyMesh *mesh)
将多边形网格转化为三角网格

另外为提升细分效率,内核还提供 AMCAX::SubD::MeshSubdivideRenderLoop(针对全三角形网格)。其结果和 Loop 细分结果相同,顶点数目相同,但顺序不同,因此不能进行比较。

OBJ/OFF文件导入和导出

导入

//OBJ
std::string fileNameOBJ5 = "MeshSubdivideRenderLoop.obj";
AMCAX::SubD::PolyMeshIO::LoadMesh(fileNameOBJ5, mesh4);
static AMCAX_API bool LoadMesh(const std::string &filename, PolyMesh *&mesh)
加载文件中的多边形网格

导出

//OBJ
std::string fileNameOBJ = "sampleResult.obj";
//OFF
std::string fileNameOFF = "sampleResult.off";
static AMCAX_API bool WriteMesh(const std::string &filename, PolyMesh *mesh)
将多边形网格写入文件