[ITK-users] [ITK] Proper chaining of filters
Matt McCormick
matt.mccormick at kitware.com
Thu Oct 2 10:16:08 EDT 2014
Hi Joël,
Calling
temp->SetInput(dilate->GetOutput());
Connects the DataObject generated by dilate to the temp filter. temp
does not increment dilate's reference count, and it would be difficult
to do since the SetInput input is the DataObject, not the
ProcessObject.
As a consequence, at least one SmartPointer needs to be kept in scope
as with your second example.
HTH,
Matt
On Thu, Oct 2, 2014 at 5:33 AM, Joël Schaerer <joel.schaerer at laposte.net> wrote:
> Hi all,
>
> I've noticed a couple times that when building a pipeline with ITK, you need
> to keep a reference to all filters before the pipeline is updated. This
> seems a little counter-intuitive to me, so I would like to better understand
> the issue and see if there is a way around it.
>
> As an example, the following code doesn't work:
>
> DilateType::Pointer dilate = DilateType::New();
> dilate->SetInput(thresh->GetOutput());
> dilate->SetKernel(kernel);
>
> dilate_filters.push_back(dilate);
> for (int i=0; i<14; ++i) {
> DilateType::Pointer temp = DilateType::New();
> temp->SetInput(dilate->GetOutput());
> temp->SetKernel(kernel);
> dilate = temp;
> }
> dilate->Update();
>
> Regions don't get propagated properly and I get the following exception when
> writing the output:
>
> C++ exception with description
> "/home/joel/workspace/ITK/Modules/IO/ImageBase/include/itkImageFileWriter.hxx:290:
> itk::ERROR: ImageFileWriter(0x3130460): Largest possible region does not
> fully contain requested paste IO regionPaste IO region: ImageIORegion
> (0x7fff9bb72cc0)
> Dimension: 3
> Index: 0 0 0
> Size: 0 0 0
> Largest possible region: ImageRegion (0x7fff9bb72bc0)
> Dimension: 3
> Index: [0, 0, 0]
> Size: [0, 0, 0]
> " thrown in the test body.
>
> My guess is that the filters get destroyed before they get a chance to be
> executed. If I explicitely keep references to each filter, it works:
>
> DilateType::Pointer dilate = DilateType::New();
> dilate->SetInput(thresh->GetOutput());
> dilate->SetKernel(kernel);
> // We need to keep a reference to each filter in the pipeline before it is
> updated
> std::vector<DilateType::Pointer> dilate_filters;
> dilate_filters.push_back(dilate);
> for (int i=0; i<14; ++i) {
> DilateType::Pointer temp = DilateType::New();
> temp->SetInput(dilate_filters.back()->GetOutput());
> temp->SetKernel(kernel);
> dilate = temp;
> dilate_filters.push_back(temp);
> }
> dilate_filters.back()->Update();
>
> My question is, why doesn't a filter keep a reference to the previous filter
> in the pipeline? Is there a way around this?
>
> Thanks!
>
> Joël
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/insight-users
> _______________________________________________
> Community mailing list
> Community at itk.org
> http://public.kitware.com/mailman/listinfo/community
More information about the Insight-users
mailing list