《itk实用demo》-Image 转化 vtkPolydata

版权声明:本文为博主原创文章,转载请注明出处,谢谢 https://blog.csdn.net/rabbitbride/article/details/82422863

Image 转化 vtkPolydata

void ImageToPolyData(ImageType::Pointer sliceimage)
{
    typedef itk::ImageToVTKImageFilter<ImageType> itkVtkConverter;
    itkVtkConverter::Pointer conv=itkVtkConverter::New();
    conv->SetInput(sliceimage);
    conv->Update();

    vtkImageData *pData=conv->GetOutput();

    vtkPoints*points=vtkPoints::New();
    vtkCellArray* vertices =vtkCellArray::New();

    int*dims=pData->GetDimensions();

    double tmp[3];
    int id=0;

    double *spacing=orginalImage->GetSpacing();
    double *origin=orginalImage->GetOrigin();
    for(int i=0; i<dims[0]; i++)
    {
        for(int j=0; j<dims[1]; j++)
        {
            int tmp_point[3];
            tmp_point[0]=i;
            tmp_point[1]=j;
            tmp_point[2]=0;

            short* gray_value = static_cast<short*>(pData->GetScalarPointer(tmp_point));
            if (*gray_value!=0)
            {
                double wordp[3];
                tmp_point[2]=sliceIndex;
                for(int k=0;k<3;k++)
                {
                    wordp[k]=tmp_point[k]*(spacing[k])+origin[k];
                }
                vtkIdType pid[1];

                pid[0] = points->InsertNextPoint(wordp[0],wordp[1],wordp[2]+0.0001);
                vertices->InsertNextCell(1,pid);

            }
        }
    }

    //// Convert the image to a polydata
    //vtkImageDataGeometryFilter* imageDataGeometryFilter = vtkImageDataGeometryFilter::New();
    //imageDataGeometryFilter->SetInput(conv->GetOutput());
    //imageDataGeometryFilter->Update();

    this->CLine->SetPoints(points);
    this->CLine->SetVerts(vertices);
    this->CLine->Update();

    vertices->Delete();
    points->Delete();
}

猜你喜欢

转载自blog.csdn.net/rabbitbride/article/details/82422863