Skip to content

Commit 275a545

Browse files
committed
ENH: use vnl_matrix over nested array allocation
The single allocation should provide coherent memory allocation add improve efficiency with coherent memory access. Using the vnl_matrix over a raw arrays enable the class to automatically free the memory and follows resource acquisition is initialization (RAII) best practices.
1 parent 0d94ab5 commit 275a545

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

include/itkRunLengthTextureFeaturesImageFilter.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,10 @@ class ITK_TEMPLATE_EXPORT RunLengthTextureFeaturesImageFilter:public ImageToImag
233233

234234
void NormalizeOffsetDirection(OffsetType &offset);
235235
bool IsInsideNeighborhood(const OffsetType &iteratedOffset);
236-
void IncreaseHistogram(unsigned int **hist, unsigned int &totalNumberOfRuns,
236+
void IncreaseHistogram(vnl_matrix<unsigned int> &hist, unsigned int &totalNumberOfRuns,
237237
const PixelType &currentInNeighborhoodPixelIntensity,
238238
const OffsetType &offset, const unsigned int &pixelDistance);
239-
void ComputeFeatures( unsigned int **hist, const unsigned int &totalNumberOfRuns,
239+
void ComputeFeatures( vnl_matrix<unsigned int> &hist, const unsigned int &totalNumberOfRuns,
240240
typename TOutputImage::PixelType &outputPixel);
241241
virtual void PrintSelf( std::ostream & os, Indent indent ) const ITK_OVERRIDE;
242242

include/itkRunLengthTextureFeaturesImageFilter.hxx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,9 @@ RunLengthTextureFeaturesImageFilter<TInputImage, TOutputImage>
181181
// Declaration of the variables useful to iterate over the all the offsets
182182
OffsetType offset;
183183
unsigned int totalNumberOfRuns;
184-
unsigned int **histogram = new unsigned int*[m_NumberOfBinsPerAxis];
185-
for(unsigned int axis = 0; axis < m_NumberOfBinsPerAxis; ++axis)
186-
{
187-
histogram[axis] = new unsigned int[m_NumberOfBinsPerAxis];
188-
}
184+
185+
vnl_matrix<unsigned int> histogram(m_NumberOfBinsPerAxis, m_NumberOfBinsPerAxis);
186+
189187

190188
// Declaration of the variables useful to iterate over the all neighborhood region
191189
PixelType currentInNeighborhoodPixelIntensity;
@@ -295,11 +293,6 @@ RunLengthTextureFeaturesImageFilter<TInputImage, TOutputImage>
295293
}
296294
}
297295

298-
for(unsigned int axis = 0; axis < m_NumberOfBinsPerAxis; ++axis)
299-
{
300-
delete[] histogram[axis];
301-
}
302-
delete[] histogram;
303296
}
304297

305298
template<typename TInputImage, typename TOutputImage>
@@ -365,7 +358,7 @@ RunLengthTextureFeaturesImageFilter<TInputImage, TOutputImage>
365358
template<typename TInputImage, typename TOutputImage>
366359
void
367360
RunLengthTextureFeaturesImageFilter<TInputImage, TOutputImage>
368-
::IncreaseHistogram(unsigned int **histogram, unsigned int &totalNumberOfRuns,
361+
::IncreaseHistogram(vnl_matrix<unsigned int> &histogram, unsigned int &totalNumberOfRuns,
369362
const PixelType &currentInNeighborhoodPixelIntensity,
370363
const OffsetType &offset, const unsigned int &pixelDistance)
371364
{
@@ -387,7 +380,7 @@ RunLengthTextureFeaturesImageFilter<TInputImage, TOutputImage>
387380
template<typename TInputImage, typename TOutputImage>
388381
void
389382
RunLengthTextureFeaturesImageFilter<TInputImage, TOutputImage>
390-
::ComputeFeatures( unsigned int **histogram,const unsigned int &totalNumberOfRuns,
383+
::ComputeFeatures( vnl_matrix<unsigned int> &histogram, const unsigned int &totalNumberOfRuns,
391384
typename TOutputImage::PixelType &outputPixel)
392385
{
393386
OutputRealType shortRunEmphasis = NumericTraits<OutputRealType>::ZeroValue();

0 commit comments

Comments
 (0)