Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 46 additions & 14 deletions examples/Core/itkVectorIterationBenchmark.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
#include <fstream>


namespace
{
template <typename T>
static constexpr bool isVariableLengthVector = std::is_same_v<T, itk::VariableLengthVector<typename T::ValueType>>;
}

// Helper function to initialize an image with random values
template <typename TImage>
typename TImage::Pointer
Expand Down Expand Up @@ -94,12 +100,24 @@ CopyScanlineIterator(const TInputImage * inputPtr, TOutputImage * outputPtr)
while (!inputIt.IsAtEndOfLine())
{
const InputPixelType & inputPixel = inputIt.Get();
OutputPixelType value(outputIt.Get());
for (unsigned int k = 0; k < componentsPerPixel; ++k)

if constexpr (isVariableLengthVector<OutputPixelType>)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐇

{
value[k] = static_cast<typename OutputPixelType::ValueType>(inputPixel[k]);
OutputPixelType value(outputIt.Get());
for (unsigned int k = 0; k < componentsPerPixel; ++k)
{
value[k] = static_cast<typename OutputPixelType::ValueType>(inputPixel[k]);
}
}
else
{
OutputPixelType value;
for (unsigned int k = 0; k < componentsPerPixel; ++k)
{
value[k] = static_cast<typename OutputPixelType::ValueType>(inputPixel[k]);
}
outputIt.Set(value);
Comment on lines +104 to +119
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the VariableLengthVector case just calls outputIt.Get(), whereas the regular Vector/FixedArray case just calls outputIt.Set(value), with this PR!

}
outputIt.Set(value);

++inputIt;
++outputIt;
Expand Down Expand Up @@ -133,12 +151,23 @@ CopyScanlineIteratorNumericTraits(const TInputImage * inputPtr, TOutputImage * o
{
const InputPixelType & inputPixel = inputIt.Get();

OutputPixelType value{ outputIt.Get() };
for (unsigned int k = 0; k < componentsPerPixel; ++k)
if constexpr (isVariableLengthVector<OutputPixelType>)
{
OutputPixelType value(outputIt.Get());
for (unsigned int k = 0; k < componentsPerPixel; ++k)
{
value[k] = static_cast<typename OutputPixelType::ValueType>(inputPixel[k]);
}
}
else
{
value[k] = static_cast<typename OutputPixelType::ValueType>(inputPixel[k]);
OutputPixelType value;
for (unsigned int k = 0; k < componentsPerPixel; ++k)
{
value[k] = static_cast<typename OutputPixelType::ValueType>(inputPixel[k]);
}
outputIt.Set(value);
}
outputIt.Set(value);

++inputIt;
++outputIt;
Expand Down Expand Up @@ -171,12 +200,13 @@ CopyImageRegionRange(const TInputImage * inputPtr, TOutputImage * outputPtr)
while (inputIt != inputEnd)
{
const InputPixelType & inputPixel = *inputIt;
OutputPixelType outputPixel{ *outputIt };
std::conditional_t<isVariableLengthVector<OutputPixelType>, OutputPixelType, OutputPixelType &> outputPixel{
*outputIt
};
for (unsigned int k = 0; k < componentsPerPixel; ++k)
{
outputPixel[k] = static_cast<typename OutputPixelType::ValueType>(inputPixel[k]);
}
*outputIt = outputPixel;

++inputIt;
++outputIt;
Expand Down Expand Up @@ -206,12 +236,13 @@ CopyImageRegionRangeNumericTraits(const TInputImage * inputPtr, TOutputImage * o
while (inputIt != inputEnd)
{
const InputPixelType & inputPixel = *inputIt;
OutputPixelType outputPixel{ *outputIt };
std::conditional_t<isVariableLengthVector<OutputPixelType>, OutputPixelType, OutputPixelType &> outputPixel{
*outputIt
};
for (unsigned int k = 0; k < componentsPerPixel; ++k)
{
outputPixel[k] = static_cast<typename OutputPixelType::ValueType>(inputPixel[k]);
}
*outputIt = outputPixel;
++inputIt;
++outputIt;
}
Expand All @@ -235,12 +266,13 @@ CopyImageRegionRangeNumericTraitsAsRange(const TInputImage * inputPtr, TOutputIm
const unsigned int componentsPerPixel = itk::NumericTraits<OutputPixelType>::GetLength(*outputIt);
for (const InputPixelType & inputPixel : itk::ImageRegionRange<const TInputImage>(*inputPtr, inputRegion))
{
OutputPixelType outputPixel{ *outputIt };
std::conditional_t<isVariableLengthVector<OutputPixelType>, OutputPixelType, OutputPixelType &> outputPixel{
*outputIt
};
for (unsigned int k = 0; k < componentsPerPixel; ++k)
{
outputPixel[k] = static_cast<typename OutputPixelType::ValueType>(inputPixel[k]);
}
*outputIt = outputPixel;
++outputIt;
}
}
Expand Down
Loading