[vtkusers] Pixel buffer to vtkContourFilter

Vincent Honnet vhonnet at freenet.de
Mon Feb 14 10:06:06 EST 2005


Hello,

I'm trying to give to vtk a 3D pixelbuffer in order to extract some 
isosurface. But it crashes at the execution. Could you help me ?
Thanks a lot in advance for your help.

Vincent.

Here is the source code:


    vtkImageImport *import = vtkImageImport::New();
    int width = GetOriginalSlicesWidth();
    int height =GetOriginalSlicesHeight();
    float *imagePositionPatient = GetImagePositionPatient(0);
    import -> SetDataOrigin(imagePositionPatient[0], 
imagePositionPatient[1], imagePositionPatient[2]);
    import -> SetDataSpacing (GetSlicesXPixelspacing(), 
GetSlicesYPixelspacing(), GetSliceThickness());
    import -> SetNumberOfScalarComponents(GetNumberOfOriginalSlices());
    import -> SetDataExtent(0,width, 0,height, 0, 
GetNumberOfOriginalSlices() );
    import -> SetWholeExtent(0,width, 0,height, 0, 
GetNumberOfOriginalSlices() );
    switch(GetSlicesDepth())
    {
        case 8:
        {
            if(GetPixelRepresentation() == 0) 
import->SetDataScalarType(VTK_UNSIGNED_CHAR);
            else import->SetDataScalarType(VTK_CHAR);
            break;
        }
        case 16:
        {
            if (GetPixelRepresentation() == 0) 
import->SetDataScalarType(VTK_UNSIGNED_SHORT);
            else import->SetDataScalarType(VTK_SHORT);
            break;
        }
        default:
        {
            std::cout << "Only 8 and 16 bits can be extracted, sorry !";
            return;
        }
    }

    //here I convert my buffers in one buffer for vtk
.....
    //
    import->SetImportVoidPointer(vtkPointer);

    import->Update();
    vtkContourFilter *extractor = vtkContourFilter::New();
    extractor->SetInput( import->GetOutput());
    extractor->SetValue(0, extractValue);

    vtkPolyDataNormals *normals = vtkPolyDataNormals::New();
    normals->SetInput(extractor->GetOutput());
    normals->SetFeatureAngle(60.0);

    vtkStripper *stripper = vtkStripper::New();
    stripper->SetInput(normals->GetOutput());
    stripper->Update();

    vtkPolyData *stripsPolyData = stripper->GetOutput();
    vtkCellArray *     stripsCellArray = stripsPolyData->GetStrips();




More information about the vtkusers mailing list