计算 volume of 3D .vtk points (triangle mesh, closed polydata)

问题描述:有一个.vtk点集,带triangle mesh,这些点构成一个闭合的三维物体表面。想计算这些点围成的这个closed object的内部体积。

解决思路:vtkMassProperties就像这里vtkMassProperties的提示: Currently only triangles are processed. Use vtkTriangleFilter to convert any strips or polygons to triangles. 也就是说,目前该类只能用于triangle mesh connectivity closed surface.


代码,polyDataVolume.cpp文件:

#include <vtkPolyDataReader.h>
#include "vtkPolyData.h"
#include "vtkSmartPointer.h"
#include <vtkMassProperties.h>


int main( int argc, char* argv[] ){

    // read in the .vtk file
    vtkSmartPointer<vtkPolyDataReader> reader = vtkSmartPointer<vtkPolyDataReader>::New();
    reader->SetFileName(argv[1]);
    reader->Update();

    vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
    polyData = reader->GetOutput();

    // evaluate the volume
    vtkMassProperties *mass = vtkMassProperties::New();

    mass->SetInput(polyData);

    cout << "---- the volume of this vtk polydata is: " << mass->GetVolume() << endl;

    return 0;
}

CMakeLists.txt文件:

cmake_minimum_required(VERSION 2.8)
 
PROJECT(polyDataVolume)
 
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
 
add_executable(polyDataVolume MACOSX_BUNDLE polyDataVolume)
 
if(VTK_LIBRARIES)
  target_link_libraries(polyDataVolume ${VTK_LIBRARIES})
else()
  target_link_libraries(polyDataVolume vtkHybrid vtkWidgets)
endif()

编译:

ccmake ../

make


运行:

./polyDataVolume ../test.vtk


运行结果:

---- the volume of this vtk polydatais: 0.00339752


这个小实验的代码已打包,可点这里下载。


参考:

http://www.vtk.org/pipermail/vtkusers/2013-June/080004.html

http://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/EmbedPointsIntoVolume

http://markmail.org/message/6u6psqha5ckz2ec3

http://www.paraview.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataToImageData

http://permalink.gmane.org/gmane.comp.lib.vtk.user/67470

http://public.kitware.com/pipermail/vtkusers/2011-January/065437.html

http://vtk.1045678.n5.nabble.com/Polydata-volume-calculation-problem-td3347493.html

http://public.kitware.com/pipermail/vtkusers/2014-July/084469.html

http://www.paraview.org/Wiki/VTK/Examples/Cxx/Modelling/Delaunay3D

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值