-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pull request 52 (ReducedFullSampler) updated #1064
Draft
N-Dekker
wants to merge
4
commits into
main
Choose a base branch
from
MathiasPolfliet/ReducedFullSampler
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f6cd3c7
ADD: Added the ReducedFullSampler for more efficient full sampling in…
fa53d0c
STYLE: Run clang-format on ReducedFullSampler
N-Dekker fcb7393
COMP: Make ReducedFullSampler compilable on current git main revision
N-Dekker dd9cfd4
COMP: Fix -Winconsistent-missing-override warnings in ReducedFullSampler
N-Dekker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
*/ | ||
bool | ||
SelectNewSamplesOnUpdate(void) override | ||
{ | ||
return false; | ||
} | ||
|
||
|
||
/** Returns whether the sampler supports SelectNewSamplesOnUpdate(). */ | ||
bool | ||
SelectingNewSamplesOnUpdateSupported(void) const override | ||
{ | ||
return false; | ||
} | ||
|
||
|
||
protected: | ||
/** The constructor. */ | ||
ImageReducedFullSampler() {} | ||
/** The destructor. */ | ||
~ImageReducedFullSampler() override {} | ||
|
||
/** PrintSelf. */ | ||
void | ||
PrintSelf(std::ostream & os, Indent indent) const override; | ||
|
||
/** Function that does the work. */ | ||
void | ||
GenerateData(void) override; | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/*========================================================================= | ||
* | ||
* 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->IsInsideInWorldSpace(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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ADD_ELXCOMPONENT( ReducedFullSampler | ||
elxReducedFullSampler.h | ||
elxReducedFullSampler.hxx | ||
elxReducedFullSampler.cxx | ||
) |
17 changes: 17 additions & 0 deletions
17
Components/ImageSamplers/ReducedFull/elxReducedFullSampler.cxx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears to be the essential part, compared to the "non-reduced" FullSampler. Looks like seven lines of code could be simplified to the following three:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MathiasPolfliet @mstaring @stefanklein Is it really necessary for the "reduced" sampler to do
index[ReducedInputImageDimension] = 0
? Or would it be sufficient to only adjust the size, and leave the index alone?I'm asking, because ITK allows specifying start index of the buffered region of an image to be non-zero. So an index value of zero may be outside the buffered region. Trying to retrieve samples outside the buffered region might cause crashes. So if it is sufficient for the "reduced" sampler to only adjust the size, I would prefer to leave the index alone.
Another option might be something like:
But I wonder if that's useful/necessary.