如何在VTK中抽取后获得固定数量的顶点

How to get a fixed number of vertices after decimation in VTK

我正在使用 VTK 进行 3D 网格处理。我有一个网格,我正在使用函数 vtkDecimatePro() 来完成缩减。函数本身接受一个TargetReduction,这与三角形数量(百分比)的减少有关。问题是我需要有固定数量的顶点,例如我希望我所有的网格都有 2000 个顶点。目前我正在一个名为 openflipper 的软件中执行此操作,该软件允许将抽取限制为固定数量的顶点。但是,在 VTK 中,我不确定如何完成此任务。

感谢任何建议。

无法设置所需的顶点数。它不是那样工作的。即使目标缩减也只是近似值,并且您不能保证得到 恰好 的顶点数。

您可以做的是非常简单地计算缩减系数并设置:

// desiredN is the desired number of vertices after reduction
double f = static_cast<double>(desiredN) / poly->GetNumberOfVertices(); 

//...
decimate->SetTargetReduction(1.0 - f);

// We want to preserve topology so that reduction factor applies to vertices 
// (otherwise it prescribes reduction in number of faces)
decimate->SetPreserveTopology(1);

HTH,

米罗