简介:勾画的数据通常带有多个标签(多个组织),以vtkImageData存储,用 vtkDiscreteMarchingCubes 可以将其转化为网格数据vtkPolyData。下图为转化的效果。
详见代码,内有注释
vtkImageData* pMaskData = m_pMaskImage->GetSrcMaskData(mLabel);
double origin[3];
pMaskData->GetOrigin(origin);
pMaskData->SetOrigin(yunCommon::m_ImagePosition);
// 提取表面
vtkNew<vtkDiscreteMarchingCubes> discrete;
discrete->SetInputData(pMaskData);
// 1:表示只有一个轮廓
// mLabel 表示pMaskData 中标签的值,最好是整数
discrete->GenerateValues(1, mLabel, mLabel);
discrete->Update();
// 平滑处理
vtkNew<vtkWindowedSincPolyDataFilter> smoother;
smoother->SetInputConnection(discrete->GetOutputPort());
smoother->SetNumberOfIterations(smoothingIterations); // 迭代次数
smoother->BoundarySmoothingOff();
smoother->FeatureEdgeSmoothingOff();
smoother->SetFeatureAngle(featureAngle);
smoother->SetPassBand(passBand); // 值越小越光滑
smoother->NonManifoldSmoothingOn();
smoother->NormalizeCoordinatesOn();
smoother->Update();