From f6cd3c7a6fd8d9e3030bf71978d5415597fdacd3 Mon Sep 17 00:00:00 2001 From: Mathias Polfliet <> Date: Tue, 20 Mar 2018 16:01:59 +0100 Subject: [PATCH 1/4] ADD: Added the ReducedFullSampler for more efficient full sampling in groupwise registration. --- .../itkImageReducedFullSampler.h | 123 ++++++++++++++ .../itkImageReducedFullSampler.hxx | 150 ++++++++++++++++++ .../ImageSamplers/ReducedFull/CMakeLists.txt | 5 + .../ReducedFull/elxReducedFullSampler.cxx | 17 ++ .../ReducedFull/elxReducedFullSampler.h | 122 ++++++++++++++ .../ReducedFull/elxReducedFullSampler.hxx | 27 ++++ 6 files changed, 444 insertions(+) create mode 100644 Common/ImageSamplers/itkImageReducedFullSampler.h create mode 100644 Common/ImageSamplers/itkImageReducedFullSampler.hxx create mode 100644 Components/ImageSamplers/ReducedFull/CMakeLists.txt create mode 100644 Components/ImageSamplers/ReducedFull/elxReducedFullSampler.cxx create mode 100644 Components/ImageSamplers/ReducedFull/elxReducedFullSampler.h create mode 100644 Components/ImageSamplers/ReducedFull/elxReducedFullSampler.hxx diff --git a/Common/ImageSamplers/itkImageReducedFullSampler.h b/Common/ImageSamplers/itkImageReducedFullSampler.h new file mode 100644 index 000000000..d330f4bef --- /dev/null +++ b/Common/ImageSamplers/itkImageReducedFullSampler.h @@ -0,0 +1,123 @@ +/*========================================================================= + * + * Copyright UMC Utrecht and contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *=========================================================================*/ + +#ifndef __ImageReducedFullSampler_h +#define __ImageReducedFullSampler_h + +#include "itkImageSamplerBase.h" + +namespace itk +{ +/** \class ImageReducedFullSampler + * + * \brief Samples all voxels in the InputImageRegion for groupwise registration. + * + * This ImageSampler samples all voxels in the InputImageRegion. + * If a mask is given: only those voxels within the mask AND the + * InputImageRegion. + * + * \ingroup ImageSamplers + */ + +template< class TInputImage > +class ImageReducedFullSampler : + public ImageSamplerBase< TInputImage > +{ +public: + + /** Standard ITK-stuff. */ + typedef ImageReducedFullSampler Self; + typedef ImageSamplerBase< TInputImage > Superclass; + typedef SmartPointer< Self > Pointer; + typedef SmartPointer< const Self > ConstPointer; + + /** Method for creation through the object factory. */ + itkNewMacro( Self ); + + /** Run-time type information (and related methods). */ + itkTypeMacro( ImageReducedFullSampler, ImageSamplerBase ); + + /** Typedefs inherited from the superclass. */ + typedef typename Superclass::DataObjectPointer DataObjectPointer; + typedef typename Superclass::OutputVectorContainerType OutputVectorContainerType; + typedef typename Superclass::OutputVectorContainerPointer OutputVectorContainerPointer; + typedef typename Superclass::InputImageType InputImageType; + typedef typename Superclass::InputImagePointer InputImagePointer; + typedef typename Superclass::InputImageConstPointer InputImageConstPointer; + typedef typename Superclass::InputImageRegionType InputImageRegionType; + typedef typename Superclass::InputImagePixelType InputImagePixelType; + typedef typename Superclass::ImageSampleType ImageSampleType; + typedef typename Superclass::ImageSampleContainerType ImageSampleContainerType; + typedef typename Superclass::ImageSampleContainerPointer ImageSampleContainerPointer; + typedef typename Superclass::MaskType MaskType; + + /** The input image dimension. */ + itkStaticConstMacro( InputImageDimension, unsigned int, Superclass::InputImageDimension ); + + itkStaticConstMacro( ReducedInputImageDimension, unsigned int, Superclass::InputImageDimension - 1 ); + + /** Other typdefs. */ + typedef typename InputImageType::IndexType InputImageIndexType; + typedef typename InputImageType::SizeType InputImageSizeType; + typedef typename InputImageType::PointType InputImagePointType; + + /** Selecting new samples makes no sense if nothing changed. + * The same samples would be selected anyway. + */ + virtual bool SelectNewSamplesOnUpdate( void ) + { + return false; + } + + + /** Returns whether the sampler supports SelectNewSamplesOnUpdate(). */ + virtual bool SelectingNewSamplesOnUpdateSupported( void ) const + { + return false; + } + + +protected: + + /** The constructor. */ + ImageReducedFullSampler() {} + /** The destructor. */ + virtual ~ImageReducedFullSampler() {} + + /** PrintSelf. */ + void PrintSelf( std::ostream & os, Indent indent ) const; + + /** Function that does the work. */ + virtual void GenerateData( void ); + +private: + + /** The private constructor. */ + ImageReducedFullSampler( const Self & ); // purposely not implemented + /** The private copy constructor. */ + void operator=( const Self & ); // purposely not implemented + +}; + +} // end namespace itk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "itkImageReducedFullSampler.hxx" +#endif + +#endif // end #ifndef __ImageReducedFullSampler_h diff --git a/Common/ImageSamplers/itkImageReducedFullSampler.hxx b/Common/ImageSamplers/itkImageReducedFullSampler.hxx new file mode 100644 index 000000000..f2a02fc55 --- /dev/null +++ b/Common/ImageSamplers/itkImageReducedFullSampler.hxx @@ -0,0 +1,150 @@ +/*========================================================================= + * + * Copyright UMC Utrecht and contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *=========================================================================*/ + +#ifndef __ImageReducedFullSampler_txx +#define __ImageReducedFullSampler_txx + +#include "itkImageReducedFullSampler.h" + +#include "itkImageRegionConstIteratorWithIndex.h" + +namespace itk +{ + +/** + * ******************* GenerateData ******************* + */ + +template< class TInputImage > +void +ImageReducedFullSampler< TInputImage > +::GenerateData( void ) +{ + + /** Get handles to the input image, output sample container, and the mask. */ + InputImageConstPointer inputImage = this->GetInput(); + typename ImageSampleContainerType::Pointer sampleContainer = this->GetOutput(); + typename MaskType::ConstPointer mask = this->GetMask(); + + /** Clear the container. */ + sampleContainer->Initialize(); + + /** Set up a region iterator within the user specified image region. */ + typedef ImageRegionConstIteratorWithIndex< InputImageType > InputImageIterator; + InputImageIndexType index = this->GetCroppedInputImageRegion().GetIndex(); + index[ ReducedInputImageDimension ] = 0; + InputImageSizeType size = this->GetCroppedInputImageRegion().GetSize(); + size[ ReducedInputImageDimension ] = 1; + InputImageRegionType region; + region.SetIndex( index ); + region.SetSize( size ); + InputImageIterator iter( inputImage, region ); + + /** Fill the sample container. */ + if( mask.IsNull() ) + { + /** Try to reserve memory. If no mask is used this can raise std + * exceptions when the input image is large. + */ + try + { + sampleContainer->Reserve( region + .GetNumberOfPixels() ); + } + catch( std::exception & excp ) + { + std::string message = "std: "; + message += excp.what(); + message += "\nERROR: failed to allocate memory for the sample container."; + const char * message2 = message.c_str(); + itkExceptionMacro( << message2 ); + } + catch( ... ) + { + itkExceptionMacro( << "ERROR: failed to allocate memory for the sample container." ); + } + + /** Simply loop over the image and store all samples in the container. */ + ImageSampleType tempSample; + unsigned long ind = 0; + for( iter.GoToBegin(); !iter.IsAtEnd(); ++iter, ++ind ) + { + /** Get sampled index */ + InputImageIndexType index = iter.GetIndex(); + + /** Translate index to point */ + inputImage->TransformIndexToPhysicalPoint( index, + tempSample.m_ImageCoordinates ); + + /** Get sampled image value */ + tempSample.m_ImageValue = iter.Get(); + + /** Store in container */ + sampleContainer->SetElement( ind, tempSample ); + + } // end for + } // end if no mask + else + { + if( mask->GetSource() ) + { + mask->GetSource()->Update(); + } + + /** Loop over the image and check if the points falls within the mask. */ + ImageSampleType tempSample; + for( iter.GoToBegin(); !iter.IsAtEnd(); ++iter ) + { + /** Get sampled index. */ + InputImageIndexType index = iter.GetIndex(); + + /** Translate index to point. */ + inputImage->TransformIndexToPhysicalPoint( index, + tempSample.m_ImageCoordinates ); + + if( mask->IsInside( tempSample.m_ImageCoordinates ) ) + { + /** Get sampled image value. */ + tempSample.m_ImageValue = iter.Get(); + + /** Store in container. */ + sampleContainer->push_back( tempSample ); + + } // end if + } // end for + } // end else (if mask exists) + +} // end GenerateData() + + +/** + * ******************* PrintSelf ******************* + */ + +template< class TInputImage > +void +ImageReducedFullSampler< TInputImage > +::PrintSelf( std::ostream & os, Indent indent ) const +{ + Superclass::PrintSelf( os, indent ); +} // end PrintSelf() + + +} // end namespace itk + +#endif // end #ifndef __ReducedImageFullSampler_txx diff --git a/Components/ImageSamplers/ReducedFull/CMakeLists.txt b/Components/ImageSamplers/ReducedFull/CMakeLists.txt new file mode 100644 index 000000000..7b0d3857c --- /dev/null +++ b/Components/ImageSamplers/ReducedFull/CMakeLists.txt @@ -0,0 +1,5 @@ +ADD_ELXCOMPONENT( ReducedFullSampler + elxReducedFullSampler.h + elxReducedFullSampler.hxx + elxReducedFullSampler.cxx +) diff --git a/Components/ImageSamplers/ReducedFull/elxReducedFullSampler.cxx b/Components/ImageSamplers/ReducedFull/elxReducedFullSampler.cxx new file mode 100644 index 000000000..e42a89527 --- /dev/null +++ b/Components/ImageSamplers/ReducedFull/elxReducedFullSampler.cxx @@ -0,0 +1,17 @@ +/*====================================================================== + + This file is part of the elastix software. + + Copyright (c) University Medical Center Utrecht. All rights reserved. + See src/CopyrightElastix.txt or http://elastix.isi.uu.nl/legal.php for + details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +======================================================================*/ + +#include "elxReducedFullSampler.h" + +elxInstallMacro( ReducedFullSampler ); diff --git a/Components/ImageSamplers/ReducedFull/elxReducedFullSampler.h b/Components/ImageSamplers/ReducedFull/elxReducedFullSampler.h new file mode 100644 index 000000000..f805b01aa --- /dev/null +++ b/Components/ImageSamplers/ReducedFull/elxReducedFullSampler.h @@ -0,0 +1,122 @@ +/*====================================================================== + + This file is part of the elastix software. + + Copyright (c) University Medical Center Utrecht. All rights reserved. + See src/CopyrightElastix.txt or http://elastix.isi.uu.nl/legal.php for + details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +======================================================================*/ +#ifndef __elxReducedFullSampler_h +#define __elxReducedFullSampler_h + +#include "elxIncludes.h" // include first to avoid MSVS warning +#include "itkImageReducedFullSampler.h" + +namespace elastix +{ + +/** + * \class ReducedFullSampler + * \brief An interpolator based on the itk::ImageReducedFullSampler. + * + * This image sampler samples all voxels in + * the InputImageRegion for a groupwise registration + * + * This sampler does not react to the NewSamplesEveryIteration parameter. + * + * The parameters used in this class are: + * \parameter ImageSampler: Select this image sampler as follows:\n + * (ImageSampler "ReducedFull") + * + * \ingroup ImageSamplers + */ + +template< class TElastix > +class ReducedFullSampler : + public + itk::ImageReducedFullSampler< + typename elx::ImageSamplerBase< TElastix >::InputImageType >, + public + elx::ImageSamplerBase< TElastix > +{ +public: + + /** Standard ITK-stuff. */ + typedef ReducedFullSampler Self; + typedef itk::ImageReducedFullSampler< + typename elx::ImageSamplerBase< TElastix >::InputImageType > + Superclass1; + typedef elx::ImageSamplerBase< TElastix > Superclass2; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + /** Method for creation through the object factory. */ + itkNewMacro( Self ); + + /** Run-time type information (and related methods). */ + itkTypeMacro( ReducedFullSampler, itk::ImageFullSampler ); + + /** Name of this class. + * Use this name in the parameter file to select this specific interpolator. \n + * example: (ImageSampler "Full")\n + */ + elxClassNameMacro( "ReducedFull" ); + + /** Typedefs inherited from the superclass. */ + typedef typename Superclass1::DataObjectPointer DataObjectPointer; + typedef typename Superclass1::OutputVectorContainerType OutputVectorContainerType; + typedef typename Superclass1::OutputVectorContainerPointer OutputVectorContainerPointer; + typedef typename Superclass1::InputImageType InputImageType; + typedef typename Superclass1::InputImagePointer InputImagePointer; + typedef typename Superclass1::InputImageConstPointer InputImageConstPointer; + typedef typename Superclass1::InputImageRegionType InputImageRegionType; + typedef typename Superclass1::InputImagePixelType InputImagePixelType; + typedef typename Superclass1::ImageSampleType ImageSampleType; + typedef typename Superclass1::ImageSampleContainerType ImageSampleContainerType; + typedef typename Superclass1::MaskType MaskType; + typedef typename Superclass1::InputImageIndexType InputImageIndexType; + typedef typename Superclass1::InputImagePointType InputImagePointType; + + /** The input image dimension. */ + itkStaticConstMacro( InputImageDimension, unsigned int, Superclass1::InputImageDimension ); + + /** The input image dimension. */ + itkStaticConstMacro( ReducedInputImageDimension, unsigned int, Superclass1::InputImageDimension - 1 ); + + /** Typedefs inherited from Elastix. */ + typedef typename Superclass2::ElastixType ElastixType; + typedef typename Superclass2::ElastixPointer ElastixPointer; + typedef typename Superclass2::ConfigurationType ConfigurationType; + typedef typename Superclass2::ConfigurationPointer ConfigurationPointer; + typedef typename Superclass2::RegistrationType RegistrationType; + typedef typename Superclass2::RegistrationPointer RegistrationPointer; + typedef typename Superclass2::ITKBaseType ITKBaseType; + +protected: + + /** The constructor. */ + ReducedFullSampler() {} + /** The destructor. */ + virtual ~ReducedFullSampler() {} + +private: + + /** The private constructor. */ + ReducedFullSampler( const Self & ); // purposely not implemented + /** The private copy constructor. */ + void operator=( const Self & ); // purposely not implemented + +}; + +} // end namespace elastix + +#ifndef ITK_MANUAL_INSTANTIATION +#include "elxReducedFullSampler.hxx" +#endif + +#endif // end #ifndef __elxReducedFullSampler_h diff --git a/Components/ImageSamplers/ReducedFull/elxReducedFullSampler.hxx b/Components/ImageSamplers/ReducedFull/elxReducedFullSampler.hxx new file mode 100644 index 000000000..51a12613b --- /dev/null +++ b/Components/ImageSamplers/ReducedFull/elxReducedFullSampler.hxx @@ -0,0 +1,27 @@ +/*====================================================================== + + This file is part of the elastix software. + + Copyright (c) University Medical Center Utrecht. All rights reserved. + See src/CopyrightElastix.txt or http://elastix.isi.uu.nl/legal.php for + details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +======================================================================*/ + +#ifndef __elxReducedFullSampler_hxx +#define __elxReducedFullSampler_hxx + +#include "elxReducedFullSampler.h" + +namespace elastix +{ + +//nothing + +} // end namespace elastix + +#endif // end #ifndef __elxReducedFullSampler_hxx From fa53d0c7b437cca404fffec55ad77532a52b6707 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Fri, 1 Mar 2024 10:55:37 +0100 Subject: [PATCH 2/4] STYLE: Run clang-format on ReducedFullSampler This is necessary in order to make the CI at github.com/SuperElastix/elastix happy. --- .../itkImageReducedFullSampler.h | 44 ++++++------- .../itkImageReducedFullSampler.hxx | 61 +++++++++---------- .../ReducedFull/elxReducedFullSampler.cxx | 2 +- .../ReducedFull/elxReducedFullSampler.h | 44 ++++++------- .../ReducedFull/elxReducedFullSampler.hxx | 2 +- 5 files changed, 70 insertions(+), 83 deletions(-) diff --git a/Common/ImageSamplers/itkImageReducedFullSampler.h b/Common/ImageSamplers/itkImageReducedFullSampler.h index d330f4bef..f42e7ef53 100644 --- a/Common/ImageSamplers/itkImageReducedFullSampler.h +++ b/Common/ImageSamplers/itkImageReducedFullSampler.h @@ -34,23 +34,21 @@ namespace itk * \ingroup ImageSamplers */ -template< class TInputImage > -class ImageReducedFullSampler : - public ImageSamplerBase< TInputImage > +template +class ImageReducedFullSampler : public ImageSamplerBase { public: - /** Standard ITK-stuff. */ - typedef ImageReducedFullSampler Self; - typedef ImageSamplerBase< TInputImage > Superclass; - typedef SmartPointer< Self > Pointer; - typedef SmartPointer< const Self > ConstPointer; + typedef ImageReducedFullSampler Self; + typedef ImageSamplerBase Superclass; + typedef SmartPointer Pointer; + typedef SmartPointer ConstPointer; /** Method for creation through the object factory. */ - itkNewMacro( Self ); + itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro( ImageReducedFullSampler, ImageSamplerBase ); + itkTypeMacro(ImageReducedFullSampler, ImageSamplerBase); /** Typedefs inherited from the superclass. */ typedef typename Superclass::DataObjectPointer DataObjectPointer; @@ -67,9 +65,9 @@ class ImageReducedFullSampler : typedef typename Superclass::MaskType MaskType; /** The input image dimension. */ - itkStaticConstMacro( InputImageDimension, unsigned int, Superclass::InputImageDimension ); + itkStaticConstMacro(InputImageDimension, unsigned int, Superclass::InputImageDimension); - itkStaticConstMacro( ReducedInputImageDimension, unsigned int, Superclass::InputImageDimension - 1 ); + itkStaticConstMacro(ReducedInputImageDimension, unsigned int, Superclass::InputImageDimension - 1); /** Other typdefs. */ typedef typename InputImageType::IndexType InputImageIndexType; @@ -79,45 +77,47 @@ class ImageReducedFullSampler : /** Selecting new samples makes no sense if nothing changed. * The same samples would be selected anyway. */ - virtual bool SelectNewSamplesOnUpdate( void ) + virtual bool + SelectNewSamplesOnUpdate(void) { return false; } /** Returns whether the sampler supports SelectNewSamplesOnUpdate(). */ - virtual bool SelectingNewSamplesOnUpdateSupported( void ) const + virtual bool + SelectingNewSamplesOnUpdateSupported(void) const { return false; } protected: - /** The constructor. */ ImageReducedFullSampler() {} /** The destructor. */ virtual ~ImageReducedFullSampler() {} /** PrintSelf. */ - void PrintSelf( std::ostream & os, Indent indent ) const; + void + PrintSelf(std::ostream & os, Indent indent) const; /** Function that does the work. */ - virtual void GenerateData( void ); + virtual void + GenerateData(void); private: - /** The private constructor. */ - ImageReducedFullSampler( const Self & ); // purposely not implemented + ImageReducedFullSampler(const Self &); // purposely not implemented /** The private copy constructor. */ - void operator=( const Self & ); // purposely not implemented - + void + operator=(const Self &); // purposely not implemented }; } // end namespace itk #ifndef ITK_MANUAL_INSTANTIATION -#include "itkImageReducedFullSampler.hxx" +# include "itkImageReducedFullSampler.hxx" #endif #endif // end #ifndef __ImageReducedFullSampler_h diff --git a/Common/ImageSamplers/itkImageReducedFullSampler.hxx b/Common/ImageSamplers/itkImageReducedFullSampler.hxx index f2a02fc55..20073c422 100644 --- a/Common/ImageSamplers/itkImageReducedFullSampler.hxx +++ b/Common/ImageSamplers/itkImageReducedFullSampler.hxx @@ -30,100 +30,96 @@ namespace itk * ******************* GenerateData ******************* */ -template< class TInputImage > +template void -ImageReducedFullSampler< TInputImage > -::GenerateData( void ) +ImageReducedFullSampler::GenerateData(void) { /** Get handles to the input image, output sample container, and the mask. */ - InputImageConstPointer inputImage = this->GetInput(); + InputImageConstPointer inputImage = this->GetInput(); typename ImageSampleContainerType::Pointer sampleContainer = this->GetOutput(); - typename MaskType::ConstPointer mask = this->GetMask(); + typename MaskType::ConstPointer mask = this->GetMask(); /** Clear the container. */ sampleContainer->Initialize(); /** Set up a region iterator within the user specified image region. */ - typedef ImageRegionConstIteratorWithIndex< InputImageType > InputImageIterator; - InputImageIndexType index = this->GetCroppedInputImageRegion().GetIndex(); - index[ ReducedInputImageDimension ] = 0; + typedef ImageRegionConstIteratorWithIndex InputImageIterator; + InputImageIndexType index = this->GetCroppedInputImageRegion().GetIndex(); + index[ReducedInputImageDimension] = 0; InputImageSizeType size = this->GetCroppedInputImageRegion().GetSize(); - size[ ReducedInputImageDimension ] = 1; + size[ReducedInputImageDimension] = 1; InputImageRegionType region; - region.SetIndex( index ); - region.SetSize( size ); - InputImageIterator iter( inputImage, region ); + region.SetIndex(index); + region.SetSize(size); + InputImageIterator iter(inputImage, region); /** Fill the sample container. */ - if( mask.IsNull() ) + if (mask.IsNull()) { /** Try to reserve memory. If no mask is used this can raise std * exceptions when the input image is large. */ try { - sampleContainer->Reserve( region - .GetNumberOfPixels() ); + sampleContainer->Reserve(region.GetNumberOfPixels()); } - catch( std::exception & excp ) + catch (std::exception & excp) { std::string message = "std: "; message += excp.what(); message += "\nERROR: failed to allocate memory for the sample container."; const char * message2 = message.c_str(); - itkExceptionMacro( << message2 ); + itkExceptionMacro(<< message2); } - catch( ... ) + catch (...) { - itkExceptionMacro( << "ERROR: failed to allocate memory for the sample container." ); + itkExceptionMacro(<< "ERROR: failed to allocate memory for the sample container."); } /** Simply loop over the image and store all samples in the container. */ ImageSampleType tempSample; unsigned long ind = 0; - for( iter.GoToBegin(); !iter.IsAtEnd(); ++iter, ++ind ) + for (iter.GoToBegin(); !iter.IsAtEnd(); ++iter, ++ind) { /** Get sampled index */ InputImageIndexType index = iter.GetIndex(); /** Translate index to point */ - inputImage->TransformIndexToPhysicalPoint( index, - tempSample.m_ImageCoordinates ); + inputImage->TransformIndexToPhysicalPoint(index, tempSample.m_ImageCoordinates); /** Get sampled image value */ tempSample.m_ImageValue = iter.Get(); /** Store in container */ - sampleContainer->SetElement( ind, tempSample ); + sampleContainer->SetElement(ind, tempSample); } // end for } // end if no mask else { - if( mask->GetSource() ) + if (mask->GetSource()) { mask->GetSource()->Update(); } /** Loop over the image and check if the points falls within the mask. */ ImageSampleType tempSample; - for( iter.GoToBegin(); !iter.IsAtEnd(); ++iter ) + for (iter.GoToBegin(); !iter.IsAtEnd(); ++iter) { /** Get sampled index. */ InputImageIndexType index = iter.GetIndex(); /** Translate index to point. */ - inputImage->TransformIndexToPhysicalPoint( index, - tempSample.m_ImageCoordinates ); + inputImage->TransformIndexToPhysicalPoint(index, tempSample.m_ImageCoordinates); - if( mask->IsInside( tempSample.m_ImageCoordinates ) ) + if (mask->IsInside(tempSample.m_ImageCoordinates)) { /** Get sampled image value. */ tempSample.m_ImageValue = iter.Get(); /** Store in container. */ - sampleContainer->push_back( tempSample ); + sampleContainer->push_back(tempSample); } // end if } // end for @@ -136,12 +132,11 @@ ImageReducedFullSampler< TInputImage > * ******************* PrintSelf ******************* */ -template< class TInputImage > +template void -ImageReducedFullSampler< TInputImage > -::PrintSelf( std::ostream & os, Indent indent ) const +ImageReducedFullSampler::PrintSelf(std::ostream & os, Indent indent) const { - Superclass::PrintSelf( os, indent ); + Superclass::PrintSelf(os, indent); } // end PrintSelf() diff --git a/Components/ImageSamplers/ReducedFull/elxReducedFullSampler.cxx b/Components/ImageSamplers/ReducedFull/elxReducedFullSampler.cxx index e42a89527..78af02fc6 100644 --- a/Components/ImageSamplers/ReducedFull/elxReducedFullSampler.cxx +++ b/Components/ImageSamplers/ReducedFull/elxReducedFullSampler.cxx @@ -14,4 +14,4 @@ #include "elxReducedFullSampler.h" -elxInstallMacro( ReducedFullSampler ); +elxInstallMacro(ReducedFullSampler); diff --git a/Components/ImageSamplers/ReducedFull/elxReducedFullSampler.h b/Components/ImageSamplers/ReducedFull/elxReducedFullSampler.h index f805b01aa..a34856b9f 100644 --- a/Components/ImageSamplers/ReducedFull/elxReducedFullSampler.h +++ b/Components/ImageSamplers/ReducedFull/elxReducedFullSampler.h @@ -36,36 +36,30 @@ namespace elastix * \ingroup ImageSamplers */ -template< class TElastix > -class ReducedFullSampler : - public - itk::ImageReducedFullSampler< - typename elx::ImageSamplerBase< TElastix >::InputImageType >, - public - elx::ImageSamplerBase< TElastix > +template +class ReducedFullSampler + : public itk::ImageReducedFullSampler::InputImageType> + , public elx::ImageSamplerBase { public: - /** Standard ITK-stuff. */ - typedef ReducedFullSampler Self; - typedef itk::ImageReducedFullSampler< - typename elx::ImageSamplerBase< TElastix >::InputImageType > - Superclass1; - typedef elx::ImageSamplerBase< TElastix > Superclass2; - typedef itk::SmartPointer< Self > Pointer; - typedef itk::SmartPointer< const Self > ConstPointer; + typedef ReducedFullSampler Self; + typedef itk::ImageReducedFullSampler::InputImageType> Superclass1; + typedef elx::ImageSamplerBase Superclass2; + typedef itk::SmartPointer Pointer; + typedef itk::SmartPointer ConstPointer; /** Method for creation through the object factory. */ - itkNewMacro( Self ); + itkNewMacro(Self); /** Run-time type information (and related methods). */ - itkTypeMacro( ReducedFullSampler, itk::ImageFullSampler ); + itkTypeMacro(ReducedFullSampler, itk::ImageFullSampler); /** Name of this class. * Use this name in the parameter file to select this specific interpolator. \n * example: (ImageSampler "Full")\n */ - elxClassNameMacro( "ReducedFull" ); + elxClassNameMacro("ReducedFull"); /** Typedefs inherited from the superclass. */ typedef typename Superclass1::DataObjectPointer DataObjectPointer; @@ -83,10 +77,10 @@ class ReducedFullSampler : typedef typename Superclass1::InputImagePointType InputImagePointType; /** The input image dimension. */ - itkStaticConstMacro( InputImageDimension, unsigned int, Superclass1::InputImageDimension ); + itkStaticConstMacro(InputImageDimension, unsigned int, Superclass1::InputImageDimension); /** The input image dimension. */ - itkStaticConstMacro( ReducedInputImageDimension, unsigned int, Superclass1::InputImageDimension - 1 ); + itkStaticConstMacro(ReducedInputImageDimension, unsigned int, Superclass1::InputImageDimension - 1); /** Typedefs inherited from Elastix. */ typedef typename Superclass2::ElastixType ElastixType; @@ -98,25 +92,23 @@ class ReducedFullSampler : typedef typename Superclass2::ITKBaseType ITKBaseType; protected: - /** The constructor. */ ReducedFullSampler() {} /** The destructor. */ virtual ~ReducedFullSampler() {} private: - /** The private constructor. */ - ReducedFullSampler( const Self & ); // purposely not implemented + ReducedFullSampler(const Self &); // purposely not implemented /** The private copy constructor. */ - void operator=( const Self & ); // purposely not implemented - + void + operator=(const Self &); // purposely not implemented }; } // end namespace elastix #ifndef ITK_MANUAL_INSTANTIATION -#include "elxReducedFullSampler.hxx" +# include "elxReducedFullSampler.hxx" #endif #endif // end #ifndef __elxReducedFullSampler_h diff --git a/Components/ImageSamplers/ReducedFull/elxReducedFullSampler.hxx b/Components/ImageSamplers/ReducedFull/elxReducedFullSampler.hxx index 51a12613b..91f895489 100644 --- a/Components/ImageSamplers/ReducedFull/elxReducedFullSampler.hxx +++ b/Components/ImageSamplers/ReducedFull/elxReducedFullSampler.hxx @@ -20,7 +20,7 @@ namespace elastix { -//nothing +// nothing } // end namespace elastix From fcb73936375f917a4126b0db254583915d49930c Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Fri, 1 Mar 2024 11:06:04 +0100 Subject: [PATCH 3/4] COMP: Make ReducedFullSampler compilable on current git main revision This work was originally "based" on commit 2ec22d0faa5189f8c27ae489fb97a2ed0f626318 "VER: increased to 4.900 in preparation of release", 2018-03-19. The code is adjusted to make it compile on the latest revision of the main branch: - IsInside is replaced with IsInsideInWorldSpace - Obsolete typedefs inherited from Superclass2 were removed - An elxOverrideGetSelfMacro call is added --- Common/ImageSamplers/itkImageReducedFullSampler.hxx | 2 +- .../ReducedFull/elxReducedFullSampler.h | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Common/ImageSamplers/itkImageReducedFullSampler.hxx b/Common/ImageSamplers/itkImageReducedFullSampler.hxx index 20073c422..e0ab73132 100644 --- a/Common/ImageSamplers/itkImageReducedFullSampler.hxx +++ b/Common/ImageSamplers/itkImageReducedFullSampler.hxx @@ -113,7 +113,7 @@ ImageReducedFullSampler::GenerateData(void) /** Translate index to point. */ inputImage->TransformIndexToPhysicalPoint(index, tempSample.m_ImageCoordinates); - if (mask->IsInside(tempSample.m_ImageCoordinates)) + if (mask->IsInsideInWorldSpace(tempSample.m_ImageCoordinates)) { /** Get sampled image value. */ tempSample.m_ImageValue = iter.Get(); diff --git a/Components/ImageSamplers/ReducedFull/elxReducedFullSampler.h b/Components/ImageSamplers/ReducedFull/elxReducedFullSampler.h index a34856b9f..5a7ae4b0f 100644 --- a/Components/ImageSamplers/ReducedFull/elxReducedFullSampler.h +++ b/Components/ImageSamplers/ReducedFull/elxReducedFullSampler.h @@ -83,13 +83,9 @@ class ReducedFullSampler itkStaticConstMacro(ReducedInputImageDimension, unsigned int, Superclass1::InputImageDimension - 1); /** Typedefs inherited from Elastix. */ - typedef typename Superclass2::ElastixType ElastixType; - typedef typename Superclass2::ElastixPointer ElastixPointer; - typedef typename Superclass2::ConfigurationType ConfigurationType; - typedef typename Superclass2::ConfigurationPointer ConfigurationPointer; - typedef typename Superclass2::RegistrationType RegistrationType; - typedef typename Superclass2::RegistrationPointer RegistrationPointer; - typedef typename Superclass2::ITKBaseType ITKBaseType; + typedef typename Superclass2::ElastixType ElastixType; + typedef typename Superclass2::RegistrationType RegistrationType; + typedef typename Superclass2::ITKBaseType ITKBaseType; protected: /** The constructor. */ @@ -103,6 +99,8 @@ class ReducedFullSampler /** The private copy constructor. */ void operator=(const Self &); // purposely not implemented + + elxOverrideGetSelfMacro; }; } // end namespace elastix From dd9cfd42f6cf4f9a9011af263b690000c78c082c Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Fri, 1 Mar 2024 14:26:52 +0100 Subject: [PATCH 4/4] COMP: Fix -Winconsistent-missing-override warnings in ReducedFullSampler Fixed macos-12/clang warnings like: > warning: 'SelectNewSamplesOnUpdate' overrides a member function but is not marked 'override' [-Winconsistent-missing-override] From https://my.cdash.org/viewBuildError.php?type=1&buildid=2507427 --- .../ImageSamplers/itkImageReducedFullSampler.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Common/ImageSamplers/itkImageReducedFullSampler.h b/Common/ImageSamplers/itkImageReducedFullSampler.h index f42e7ef53..f532addab 100644 --- a/Common/ImageSamplers/itkImageReducedFullSampler.h +++ b/Common/ImageSamplers/itkImageReducedFullSampler.h @@ -77,16 +77,16 @@ class ImageReducedFullSampler : public ImageSamplerBase /** Selecting new samples makes no sense if nothing changed. * The same samples would be selected anyway. */ - virtual bool - SelectNewSamplesOnUpdate(void) + bool + SelectNewSamplesOnUpdate(void) override { return false; } /** Returns whether the sampler supports SelectNewSamplesOnUpdate(). */ - virtual bool - SelectingNewSamplesOnUpdateSupported(void) const + bool + SelectingNewSamplesOnUpdateSupported(void) const override { return false; } @@ -96,15 +96,15 @@ class ImageReducedFullSampler : public ImageSamplerBase /** The constructor. */ ImageReducedFullSampler() {} /** The destructor. */ - virtual ~ImageReducedFullSampler() {} + ~ImageReducedFullSampler() override {} /** PrintSelf. */ void - PrintSelf(std::ostream & os, Indent indent) const; + PrintSelf(std::ostream & os, Indent indent) const override; /** Function that does the work. */ - virtual void - GenerateData(void); + void + GenerateData(void) override; private: /** The private constructor. */