ITK学习笔记:1.Data presentation-1.3Mesh网格(五):简化网格的创建

Mesh类是非常通用和灵活的。

可以通过itk::AutomaticTopologyMeshSource类,根据我们所添加的单元自动生成一个显性复合体。

  • 它包括了所有的边界信息,因此产生的网格可以很容易地遍历。
  • 它合并了所有共享的边、顶点和面,因此几何特征不会重复出现。

本文展示如何使用AutomaticTopologyMeshSource实例化表示K-Complex的网格。我们将首先从上文中生成相同的四面体,之后我们将添加一个空心的四面体来说明网格源的一些额外特性。

首先包含需要的头文件:

#include "itkMesh.h" 
#include "itkVertexCell.h" 
#include "itkLineCell.h" 
#include "itkTriangleCell.h" 
#include "itkTetrahedronCell.h" 
#include "itkAutomaticTopologyMeshSource.h"

然后定义必要的类型,并实例化网格源。
网格中的每个单元格都有一个标识符,其类型由网格特征决定。

typedef float PixelType; 
typedef itk::Mesh< PixelType, 3 > MeshType;
typedef MeshType::PointType PointType; 
typedef MeshType::CellType CellType;

//AutomaticTopologyMeshSource要求所有顶点和单元格的标识符类型为unsig long。
//但是,如果创建了一个新的mesh traits类来使用字符串标记作为标识符,那么得到的mesh将itk::AutomaticTopologyMeshSource不兼容。
typedef itk::AutomaticTopologyMeshSource< MeshType > MeshSourceType;

//两种新类型是IdentifierType和IdentifierArrayType。
typedef MeshSourceType::IdentifierType IdentifierType;
//IdentifierArrayType只是一个IdentifierType对象的itk::Array。 
typedef MeshSourceType::IdentifierArrayType IdentifierArrayType;

MeshSourceType::Pointer meshSource;
meshSource = MeshSourceType::New();

现在我们来生成这个四面体。
下面一行代码生成所有顶点、边和面以及四面体实体,并将它们与连接信息一起添加到网格中:

meshSource->AddTetrahedron( 
 meshSource->AddPoint( -1, -1, -1 ), 
 meshSource->AddPoint( 1, 1, -1 ),
 meshSource->AddPoint( 1, -1, 1 ), 
 meshSource->AddPoint( -1, 1, 1 )
  );

也可以像下面一样,先加点,再加面

PointType p; 
IdentifierArrayType idArray( 4 );
p[ 0 ] = -2; p[ 1 ] = -2; p[ 2 ] = -2;
idArray[ 0 ] = meshSource->AddPoint( p );
p[ 0 ] = 2; p[ 1 ] = 2; p[ 2 ] = -2;
idArray[ 1 ] = meshSource->AddPoint( p );
p[ 0 ] = 2; p[ 1 ] = -2; p[ 2 ] = 2; 
idArray[ 2 ] = meshSource->AddPoint( p );
p[ 0 ] = -2; p[ 1 ] = 2; p[ 2 ] = 2; 
idArray[ 3 ] = meshSource->AddPoint( p );

现在我们添加单元格。这一次我们将创建一个四面体的边界,因此我们必须分别添加每个面:

meshSource->AddTriangle( idArray[0], idArray[1], idArray[2] ); 
meshSource->AddTriangle( idArray[1], idArray[2], idArray[3] ); 
meshSource->AddTriangle( idArray[2], idArray[3], idArray[0] ); 
meshSource->AddTriangle( idArray[3], idArray[0], idArray[1] );

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值