[Insight-users] Register and Delete

Miller, James V (Research) millerjv at crd.ge.com
Fri, 16 Apr 2004 09:44:29 -0400


The problem is that the scope of the itkExporter is limited to the 
viewImage function.  Once you leave this function, the exporter destroys
itself.  You should hold onto a smart pointer to the exporter for the 
duration the image is to be displayed.

One option is to have an ivar in you SegmentationBase class that is the 
smartpointer to the itkExporter.  Another option is to pass in the exporter
to use in the viewImage routine.  A third option is to pass back the
exporter as the return type of the viewImage routine and cache it in the
method/class that calls viewImage.

Jim


-----Original Message-----
From: Toon Huysmans [mailto:denhuys at hotmail.com]
Sent: Friday, April 16, 2004 5:45 AM
To: insight-users at itk.org
Subject: [Insight-users] Register and Delete


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();
}
_______________________________________________
Insight-users mailing list
Insight-users at itk.org
http://www.itk.org/mailman/listinfo/insight-users