在医学影像中,由于CT、MRI等成像设备的数据均以断层影像的形式输出,对其进行轮廓提取和三维重建就成为一个常见的需求。
将一组相互平行的轮廓线,以三角面片连接,形成放样曲面,即为surface from contours问题。这一问题的经典解决方法可参见论文Piecewise-Linear Interpolation between Polygonal Slices(简单贪心)
及approximating complex surfaces by triangulation of contour lines
(动态规划)。
在VTK库中,类vtkVoxelContoursToSurfaceFilter提供了一个基于网格体元的实现。
create surface from contours
vtkVoxelContoursToSurfaceFilter is a filter that takes contours and produces surfaces. There are some restrictions for the contours:
The contours are input as vtkPolyData, with the contours being polys in the vtkPolyData.
The contours lie on XY planes - each contour has a constant Z
The contours are ordered in the polys of the vtkPolyData such that all contours on the first (lowest) XY plane are first, then continuing in order of increasing Z value.
The X, Y and Z coordinates are all integer values.
The desired sampling of the contour data is 1x1x1 - Aspect can be used to control the aspect ratio in the output polygonal dataset.
This filter takes the contours and produces a structured points dataset of signed floating point number indicating distance from a contour. A contouring filter is then applied to generate 3D surfaces from a stack of 2D contour distance slices. This is done in a streaming fashion so as not to use to much memory.
以下为代码注释
// 曲面提取主函数
// Append data sets into single unstructured grid
int vtkVoxelContoursToSurfaceFilter::RequestData(
vtkInformation *vtkNotUsed(request),
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
// get the info objects
vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
vtkInformation *outInfo = outputVector->GetInformationObject(0);
// get the input and output
vtkPolyData *input = vtkPolyData::SafeDownCast(
inInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkPolyData *output = vtkPolyData::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkCellArray *inputPolys = input->GetPolys();
int gridSize[3];
double gridOrigin[3];