[ITK] [ITK-users] get outputs from a std::vector list of smart-pointers of image-filters
Grothausmann, Roman Dr.
grothausmann.roman at mh-hannover.de
Mon Sep 12 05:41:09 EDT 2016
On 09/09/16 16:21, Dženan Zukić wrote:
> Hi Roman,
>
> you should not save the pointer the SmartPointer encapsulates, but rather the
> SmartPointer itself. The saving line of code should not be
> savedPointers.push_back(caster.GetPointer());
> but rather
> savedPointers.push_back(caster);
> and later usage should not be
> smoother->SetInput(dynamic_cast<ISType*>(savedPointers[i].GetPointer())->GetOutput());
> but rather
> smoother->SetInput(savedPointers[i]->GetOutput());
Many thanks Dženan for Your reply. I tried as You suggested:
https://github.com/romangrothausmann/ITK-CLIs/commit/b00551faf951192f50e4090d683300524b4c95ba
but am getting:
resample.cxx:79:49: error: no matching function for call to
?itk::ProcessObject::GetOutput()?
smoother->SetInput(savedPointers[i]->GetOutput());
^
resample.cxx:79:49: note: candidates are:
In file included from resample.cxx:5:
/opt/itk-4.9.1/include/ITK-4.9/itkProcessObject.h:612:16: note: itk::DataObject*
itk::ProcessObject::GetOutput(const DataObjectIdentifierType&)
DataObject * GetOutput(const DataObjectIdentifierType & key);
^
I also tried:
std::vector<itk::ProcessObject> savedPointers;
std::vector<itk::ISType> savedPointers;
std::vector< itk::SmartPointer<itk::ProcessObject> > savedPointers;
but always got compile errors.
I am confused when to use the smart-pointer as is and when with .GetPointer().
According to
https://cmake.org/pipermail/insight-users/2007-May/022374.html
I also tried storing the output-pointers (without pipe-line disconnection) in a
separate list
https://github.com/romangrothausmann/ITK-CLIs/commit/d9b5c3f1a786b595255a9153da9ceafd88d2a189
which does not compile either:
resample.cxx:77:5: error: request for member ?GetPointer? in
?caster.itk::SmartPointer<TObjectType>::operator-><itk::CastImageFilter<itk::Image<float,
1u>, itk::Image<float, 1u> > >()->itk::CastImageFilter<itk::Image<float, 1u>,
itk::Image<float, 1u>
>::<anonymous>.itk::UnaryFunctorImageFilter<itk::Image<float, 1u>,
itk::Image<float, 1u>, itk::Functor::Cast<float, float>
>::<anonymous>.itk::InPlaceImageFilter<itk::Image<float, 1u>, itk::Image<float,
1u> >::<anonymous>.itk::ImageToImageFilter<itk::Image<float, 1u>,
itk::Image<float, 1u>
>::<anonymous>.itk::ImageSource<TOutputImage>::GetOutput<itk::Image<float, 1u>
>()?, which is of pointer type ?itk::ImageSource<itk::Image<float, 1u>
>::OutputImageType* {aka itk::Image<float, 1u>*}? (maybe you meant to use ?->? ?)
savedOutPointers.push_back(caster->GetOutput().GetPointer());
^
I'm wondering if construct as needed is not possible at all because I can't find
anything like that in the ITK-sources or examples. For the code snippets I can
find in the MLs it is not clear whether they got tested and were accepted by a
compiler.
Any further ideas?
Best
Roman
> On Fri, Sep 9, 2016 at 8:29 AM, Grothausmann, Roman Dr.
> <grothausmann.roman at mh-hannover.de <mailto:grothausmann.roman at mh-hannover.de>>
> wrote:
>
> On 22/07/16 14:49, Lowekamp, Bradley (NIH/NLM/LHC) [C] wrote:
>
> Hi,
>
> Who is holding the pointer to the newly created ImageFileReader outside of
> the loop? For that type of operation I’ll frequently just stash smart
> pointers into a std::vector or list.
>
>
> I tried to change the resample example
> (https://itk.org/Doxygen/html/Examples_2Filtering_2ResampleVolumesToBeIsotropic_8cxx-example.html
> <https://itk.org/Doxygen/html/Examples_2Filtering_2ResampleVolumesToBeIsotropic_8cxx-example.html>
> that uses itkRecursiveGaussianImageFilter for each dimension) such that it works
> for any dimensional image.
> Doing as Brad suggested and storing each smart-pointer of
> itkRecursiveGaussianImageFilter in a std::vector I get a program
> (https://github.com/romangrothausmann/ITK-CLIs/blob/0968dd25af2abc37ffb0c0503cc4c2972b3b2098/resample.cxx
> <https://github.com/romangrothausmann/ITK-CLIs/blob/0968dd25af2abc37ffb0c0503cc4c2972b3b2098/resample.cxx>)
> that compiles but segfaults when used. I guess the way I'm trying to
> dereference a pointer from the list is not correct
> (https://github.com/romangrothausmann/ITK-CLIs/commit/0968dd25af2abc37ffb0c0503cc4c2972b3b2098#diff-cb1b1c6837c6074372c220250cfdbb36R80
> <https://github.com/romangrothausmann/ITK-CLIs/commit/0968dd25af2abc37ffb0c0503cc4c2972b3b2098#diff-cb1b1c6837c6074372c220250cfdbb36R80>)
> but I could not find an example except the one referenced in the code line.
> So how to correctly dereference a pointer from the list of smart-pointers to
> get its output?
>
> Thank for any help or hints
> Roman
>
> On Jul 22, 2016, at 6:00 AM, Grothausmann, Roman Dr.
> <grothausmann.roman at mh-hannover.de
> <mailto:grothausmann.roman at mh-hannover.de>> wrote:
>
> Many thanks Brad for Your detailed reply. I understand now the problems
> concerning streaming TileImageFilter. However I still wonder why my
> non-streaming version also does not work any more after moving the
> creation
> of reader instances into the for-loop:
> https://github.com/romangrothausmann/ITK-CLIs/blob/ebfc0aea37d28cbbf2bb22c3f56be52453cebde9/tile.cxx#L46-L50
> <https://github.com/romangrothausmann/ITK-CLIs/blob/ebfc0aea37d28cbbf2bb22c3f56be52453cebde9/tile.cxx#L46-L50>
>
>
>
> Is this construct inappropriate for the TileImageFilter?
>
> Why does it work for:
> https://itk.org/Doxygen/html/SphinxExamples_2src_2Filtering_2ImageGrid_2AppendTwo3DVolumes_2Code_8cxx-example.html#_a2
> <https://itk.org/Doxygen/html/SphinxExamples_2src_2Filtering_2ImageGrid_2AppendTwo3DVolumes_2Code_8cxx-example.html#_a2>
>
>
>
> On 21/07/16 15:41, Lowekamp, Bradley (NIH/NLM/LHC) [C] wrote:
>
> Hello,
>
> The TileImageFilter does not fully stream [1]. The filter also
> has some
> odd behavior, and other older implementation details. If you are
> going to
> work on a streaming pipelines it is best practice to examine the
> filters
> to determine how the Requested regions behave.
>
> However, there is no reason that the TileImageFilter algorithm
> couldn’t
> support streaming. It is just a matter of code and a bunch of
> testing. A
> contribution for this issue would be welcomed! Also this filter
> is in
> need a refactoring and bring it up to several other best
> practices. There
> are several issue with the current implementation that would
> cause it not
> to work correctly with a streaming pipeline, and cause excessive
> execution.
>
> You can also use the PipelieMoniotorImageFilter to record and
> print the
> pipeline interaction during Update [2]. This information helps with
> debugging and diagnosing problems, but if the pipeline is
> mis-behaving (
> as the TileImageFilter may ), the information may not be correct.
>
> I have tried similar streaming with the JoinSeriesImageFilter.
> However I
> ran into many problems with having hundreds of ImageIO being
> utilized at
> the same time. There were problems with having too many files
> open at the
> same time along with ImageIO libraries that couldn’t handle single
> threaded access to multiple files.
>
> [1]
> https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Filtering/ImageGrid/include/itkTileImageFilter.hxx#L125-L136
> <https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Filtering/ImageGrid/include/itkTileImageFilter.hxx#L125-L136>
>
>
>
>
> [2] https://itk.org/Doxygen/html/classitk_1_1PipelineMonitorImageFilter.html
> <https://itk.org/Doxygen/html/classitk_1_1PipelineMonitorImageFilter.html>
>
>
> On Jul 21, 2016, at 6:41 AM, Grothausmann, Roman Dr.
> <grothausmann.roman at mh-hannover.de
> <mailto:grothausmann.roman at mh-hannover.de>> wrote:
>
> Dear mailing list members,
>
>
> Based on the examples for TileImageFilter I've created a
> working CLI
> to append an arbitrary number of inputs
> (https://github.com/romangrothausmann/ITK-CLIs/blob/4fdf5778022598dcf83fb38e6002df72bd67bef3/tile.cxx
> <https://github.com/romangrothausmann/ITK-CLIs/blob/4fdf5778022598dcf83fb38e6002df72bd67bef3/tile.cxx>).
>
>
>
>
> As there is an example that does not apply Update and DisconnectPipeline on
> the readers
> (https://itk.org/Doxygen/html/SphinxExamples_2src_2Filtering_2ImageGrid_2AppendTwo3DVolumes_2Code_8cxx-example.html#_a2
> <https://itk.org/Doxygen/html/SphinxExamples_2src_2Filtering_2ImageGrid_2AppendTwo3DVolumes_2Code_8cxx-example.html#_a2>)
>
>
> I changed my code such that a reader instance is created for
> each input
> in a for-loop:
> https://github.com/romangrothausmann/ITK-CLIs/commit/ebfc0aea37d28cbbf2bb22c3f56be52453cebde9
> <https://github.com/romangrothausmann/ITK-CLIs/commit/ebfc0aea37d28cbbf2bb22c3f56be52453cebde9>
>
>
>
>
>
> However, the update from the writer seems not to propagate to the readers
> whether streaming or not. Can the TileImageFilter not stream in such a case
> or are further modifications necessary?
>
>
> Thanks for any help or hints Roman
>
>
> On 18/08/14 17:01, Michka Popoff wrote:
>
> Hi
>
> Going the way described in the CreateVolume example is
> the way to
> go.
>
> Why did you uncomment the DisconnectPipeline() call and
> Update() call
> in the for loop ? They need to stay there, else you will
> always use
> the last image. That’s why you see the same image, the
> single update
> call will be triggered at the end of the script and read
> only one
> image.
>
> You don’t need to call tileFilter->Update(), you can
> remove this
> line. The writer->Update() will take care of the
> pipeline update. As
> a bonus, you may wrap your writer->Update() call, to
> fetch errors at
> the end of the pipeline:
>
> try { writer->Update(); } catch( itk::ExceptionObject &
> error ) {
> std::cerr << "Error: " << error << std::endl; return
> EXIT_FAILURE; }
>
> I made a little Python prototype, the syntax is a little bit
> different than in C++ but it gives you the main idea.
>
> Michka
>
>
> -- Dr. Roman Grothausmann
>
> Tomographie und Digitale Bildverarbeitung Tomography and
> Digital Image
> Analysis
>
> Institut für Funktionelle und Angewandte Anatomie, OE 4120
> Medizinische Hochschule Hannover Carl-Neuberg-Str. 1 D-30625
> Hannover
>
> Tel. +49 511 532-2900 <tel:%2B49%20511%20532-2900>
> _____________________________________ Powered by
> www.kitware.com <http://www.kitware.com>
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> <http://www.kitware.com/opensource/opensource.html>
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
> <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
> <http://www.itk.org/Wiki/ITK_FAQ>
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/insight-users
> <http://public.kitware.com/mailman/listinfo/insight-users>
> _______________________________________________ Community
> mailing list
> Community at itk.org <mailto:Community at itk.org>
> http://public.kitware.com/mailman/listinfo/community
> <http://public.kitware.com/mailman/listinfo/community>
>
>
>
> -- Dr. Roman Grothausmann
>
> Tomographie und Digitale Bildverarbeitung Tomography and Digital Image
> Analysis
>
> Institut für Funktionelle und Angewandte Anatomie, OE 4120 Medizinische
> Hochschule Hannover Carl-Neuberg-Str. 1 D-30625 Hannover
>
> Tel. +49 511 532-2900 <tel:%2B49%20511%20532-2900>
>
>
>
> --
> Dr. Roman Grothausmann
>
> Tomographie und Digitale Bildverarbeitung
> Tomography and Digital Image Analysis
>
> Institut für Funktionelle und Angewandte Anatomie, OE 4120
> Medizinische Hochschule Hannover
> Carl-Neuberg-Str. 1
> D-30625 Hannover
>
> Tel. +49 511 532-2900 <tel:%2B49%20511%20532-2900>
> _____________________________________
> Powered by www.kitware.com <http://www.kitware.com>
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> <http://www.kitware.com/opensource/opensource.html>
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.php
> <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 <http://www.itk.org/Wiki/ITK_FAQ>
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/insight-users
> <http://public.kitware.com/mailman/listinfo/insight-users>
>
>
--
Dr. Roman Grothausmann
Tomographie und Digitale Bildverarbeitung
Tomography and Digital Image Analysis
Institut für Funktionelle und Angewandte Anatomie, OE 4120
Medizinische Hochschule Hannover
Carl-Neuberg-Str. 1
D-30625 Hannover
Tel. +49 511 532-2900
_____________________________________
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
More information about the Community
mailing list