[Insight-users] Register and Delete

Toon Huysmans denhuys at hotmail.com
Fri, 16 Apr 2004 11:45:11 +0200


Hi,

    I want to do a very simple thing, visualize a itk image in a
vtkRenderer, and I did it!  But I had to add some extra Register()'s and
leave out some Delete()'s otherwise the application crashes when an update
is propagated from the renderer down to the Image.

    The attached method works but the use of register and delete is
inconsistent.
    So I was wondering if anyone could tell me how to correctly use
Register() and Delete() in the attached method.


Toon.

// view the image in the renderer
void    SegmentationBase::viewImage(ImageType::Pointer im, vtkRenderer *ren)
{
    // connect itk with vtk
    ImageExportType::Pointer itkExporter = ImageExportType::New();
    vtkImageImport* vtkImporter = vtkImageImport::New();

    //If I dont do this it will crash!
    itkExporter->Register();
    vtkImporter->Register(NULL);

    itkExporter->SetInput(image);
    itkExporter->Update();

    vtkImporter->SetDataScalarTypeToUnsignedChar();

    ConnectPipelines(itkExporter, vtkImporter);

    vtkImporter->Update();

    //Use three orthogonal ImagePlaneWidgets to view the Image
    vtkOrthogonalImagePlaneSet *planeSet =
vtkOrthogonalImagePlaneSet::New();
    planeSet->SetInput(vtkImporter->GetOutput());
    planeSet->On();
    planeSet->SetInteractor(ren->GetRenderWindow()->GetInteractor());

    //outline of the image
    vtkOutlineFilter *outline = vtkOutlineFilter::New();
    outline->SetInput((vtkImporter->GetOutput()));

    vtkPolyDataMapper *outlineMapper = vtkPolyDataMapper::New();
    outlineMapper->SetInput(outline->GetOutput());

    vtkActor *outlineActor = vtkActor::New();
    outlineActor->SetMapper(outlineMapper);

    ren->AddActor(outlineActor);

    outline->Delete();
    outlineMapper->Delete();
    outlineActor->Delete();

    // If I delete any of these it also crashes
    //itkExporter->Delete();
    //vtkImporter->Delete();
    //planeSet->Delete();
}