[vtkusers] SetInputData() vs SetInputConnection()

Maarten Beek beekmaarten at yahoo.com
Mon Apr 28 11:53:30 EDT 2014


Hi all,

I bumped into something I don't really understand:


void MyClass::activate()
{
    vtkSmartPointer<vtkTIFFReader> reader = vtkSmartPointer<vtkTIFFReader>::New();
    <...>
    reader->Update();

    m_Processor->SetInputData(reader->GetOutput());
}

void MyClass::deactivate()
{
    if( 0 != m_Processor )
    {
        m_Processor->RemoveAllInputs();
        m_Processor->Delete();
        m_Processor = 0;

    }
}

In the deactivate() function I do need the RemoveAllInputs() call to avoid a 50MB memory leak (100 slice 512x512 tiff). I don't need RemoveAllInputs() when I use SetInputConnection(reader->GetOutputPort()) in the activate() function.

Why is the difference between SetInputData() and SetInputConnection() with regards to memory management?

m_Processor is derived from vtkImageAlgorithm and has an internal pipeline inside the RequestData(), processing the image data with vtkImageConvolve, vtkImageSobel2D, vtkImageThreshold and a few more.

int ProcessorClass::RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector* outputVector)
{
    vtkInformation* outInfo = outputVector->GetInformationObject(0);
    vtkImageData* output = vtkImageData::SafeDownCast(outInfo->Get(vtkdataObject::DATA_OBJECT()));

    if( this->GetMTime() > this->BuildTime )
    {
        this->buildPipeline();
    }

    if( 0 != this->GetNumberOfInputConnections(0) )
    {
        this->MergeFilter->Update();
        output->ShallowCopy(this->MergeFilter->GetOutput());
    }

    return 1;
}



Maarten
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140428/645641cf/attachment.html>


More information about the vtkusers mailing list