Skip to content

Commit

Permalink
ENH: Add sparse threader for ANTS CC metric
Browse files Browse the repository at this point in the history
Add support to use sparse sampling of a point set with ANTS
CC metric. The implementation of the dense metric is integrated
with this sparse metric, by overloading corresponding functions.

ENH: Remove files of the dense threader class of ANTS CC.

The implementation of both dense and sparse threaders for ANTS CC
metric are now integrated in one class template by specialing different
domain threader types. A helper class is added for overloading by
different threader partitioner type.

ENH: Add test for sparse threader in ANTS registration test

ENH: Add test for sparse threader in ANTS CC metric test

ENH: moved the InitializeScaning from metric class to threader

Since all computation are now in the threader, it makes sense
to move InitializaScanning and all related types to the threader
class. The ANTS CC metric class is more like a wrapper class
to encapsulate the threader class and store metric options.

STYLE: updated with detailed comments for function overloading

Function overloading is used here to intergrate sparse and dense
threaers under the same class.

STYLE: indentation etc.

COMP: add a missing header file

Change-Id: I9c2c01f813030d7db8be30ef221b8d3cb015b54d
  • Loading branch information
songgang committed Sep 14, 2012
1 parent dbd2a92 commit 651dcd0
Show file tree
Hide file tree
Showing 9 changed files with 1,259 additions and 958 deletions.
2 changes: 1 addition & 1 deletion Modules/Core/Common/include/itkDomainThreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace itk
*
* \tparam TDomainPartitioner A class that inherits from
* ThreadedDomainPartitioner.
* \tparam TAssociate The asssociated class that uses a derived version of
* \tparam TAssociate The associated class that uses a derived version of
* this class as a "threaded method". The associated class usually declares
* derived version of this class as nested classes so there is easy access to
* its protected and private members in ThreadedExecution.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
#define __itkANTSNeighborhoodCorrelationImageToImageMetricv4_h

#include "itkImageToImageMetricv4.h"
#include "itkConstNeighborhoodIterator.h"

#include "itkANTSNeighborhoodCorrelationImageToImageMetricv4DenseGetValueAndDerivativeThreader.h"
#include "itkANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader.h"

#include <deque>

Expand Down Expand Up @@ -177,59 +175,13 @@ class ITK_EXPORT ANTSNeighborhoodCorrelationImageToImageMetricv4 :
ANTSNeighborhoodCorrelationImageToImageMetricv4();
virtual ~ANTSNeighborhoodCorrelationImageToImageMetricv4();

// interested values here updated during scanning
typedef InternalComputationValueType QueueRealType;
typedef std::deque<QueueRealType> SumQueueType;
typedef ConstNeighborhoodIterator<VirtualImageType> ScanIteratorType;

// one ScanMemType for each thread
typedef struct ScanMemType {
// queues used in the scanning
// sum of the fixed value squared
SumQueueType QsumFixed2;
// sum of the moving value squared
SumQueueType QsumMoving2;
SumQueueType QsumFixed;
SumQueueType QsumMoving;
SumQueueType QsumFixedMoving;
SumQueueType Qcount;

QueueRealType fixedA;
QueueRealType movingA;
QueueRealType sFixedMoving;
QueueRealType sFixedFixed;
QueueRealType sMovingMoving;

FixedImageGradientType fixedImageGradient;
MovingImageGradientType movingImageGradient;

FixedImagePointType mappedFixedPoint;
MovingImagePointType mappedMovingPoint;
VirtualPointType virtualPoint;
} ScanMemType;

typedef struct ScanParametersType {
// const values during scanning
ImageRegionType scanRegion;
SizeValueType numberOfFillZero; // for each queue
SizeValueType windowLength; // number of voxels in the scanning window
IndexValueType scanRegionBeginIndexDim0;

typename FixedImageType::ConstPointer fixedImage;
typename MovingImageType::ConstPointer movingImage;
typename VirtualImageType::ConstPointer virtualImage;
RadiusType radius;

} ScanParametersType;

friend class ANTSNeighborhoodCorrelationImageToImageMetricv4DenseGetValueAndDerivativeThreader< Superclass, Self >;
typedef ANTSNeighborhoodCorrelationImageToImageMetricv4DenseGetValueAndDerivativeThreader< Superclass, Self >
friend class ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader< ThreadedImageRegionPartitioner< VirtualImageDimension >, Superclass, Self >;
typedef ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader< ThreadedImageRegionPartitioner< VirtualImageDimension >, Superclass, Self >
ANTSNeighborhoodCorrelationImageToImageMetricv4DenseGetValueAndDerivativeThreaderType;

/** Create an iterator over the virtual sub region */
void InitializeScanning(const ImageRegionType &scanRegion,
ScanIteratorType &scanIt, ScanMemType &scanMem,
ScanParametersType &scanParameters ) const;
friend class ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader< ThreadedIndexedContainerPartitioner, Superclass, Self >;
typedef ANTSNeighborhoodCorrelationImageToImageMetricv4GetValueAndDerivativeThreader< ThreadedIndexedContainerPartitioner, Superclass, Self >
ANTSNeighborhoodCorrelationImageToImageMetricv4SparseGetValueAndDerivativeThreaderType;

virtual void PrintSelf(std::ostream & os, Indent indent) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ ANTSNeighborhoodCorrelationImageToImageMetricv4<TFixedImage, TMovingImage,TVirtu
// We have our own GetValueAndDerivativeThreader's that we want
// ImageToImageMetricv4 to use.
this->m_DenseGetValueAndDerivativeThreader = ANTSNeighborhoodCorrelationImageToImageMetricv4DenseGetValueAndDerivativeThreaderType::New();
// not implemented
//this->m_SparseGetValueAndDerivativeThreader =
this->m_SparseGetValueAndDerivativeThreader = ANTSNeighborhoodCorrelationImageToImageMetricv4SparseGetValueAndDerivativeThreaderType::New();
}

template<class TFixedImage, class TMovingImage, class TVirtualImage>
Expand All @@ -49,51 +48,9 @@ void
ANTSNeighborhoodCorrelationImageToImageMetricv4<TFixedImage, TMovingImage, TVirtualImage>
::Initialize(void) throw ( itk::ExceptionObject )
{
if( this->GetUseFixedSampledPointSet() )
{
itkExceptionMacro("UseFixedSampledPointSet is set, but not supported in this metric.");
}
Superclass::Initialize();
}

template<class TFixedImage, class TMovingImage, class TVirtualImage>
void
ANTSNeighborhoodCorrelationImageToImageMetricv4<TFixedImage, TMovingImage, TVirtualImage>
::InitializeScanning( const ImageRegionType &scanRegion, ScanIteratorType &scanIt,
ScanMemType & scanMem, ScanParametersType &scanParameters ) const
{
scanParameters.scanRegion = scanRegion;
scanParameters.fixedImage = this->m_FixedImage;
scanParameters.movingImage = this->m_MovingImage;
scanParameters.virtualImage = this->GetVirtualImage();
scanParameters.radius = this->GetRadius();

OffsetValueType numberOfFillZero = this->GetVirtualRegion().GetIndex(0)
- (scanRegion.GetIndex(0) - scanParameters.radius[0]);

if (numberOfFillZero < NumericTraits<OffsetValueType>::ZeroValue())
{
numberOfFillZero = NumericTraits<OffsetValueType>::ZeroValue();
}

scanParameters.numberOfFillZero = numberOfFillZero;

scanIt = ScanIteratorType(scanParameters.radius, scanParameters.virtualImage, scanRegion);
scanParameters.windowLength = scanIt.Size();
scanParameters.scanRegionBeginIndexDim0 = scanIt.GetBeginIndex()[0];

scanMem.fixedA = NumericTraits< QueueRealType >::Zero;
scanMem.movingA = NumericTraits< QueueRealType >::Zero;
scanMem.sFixedMoving = NumericTraits< QueueRealType >::Zero;
scanMem.sFixedFixed = NumericTraits< QueueRealType >::Zero;
scanMem.sMovingMoving = NumericTraits< QueueRealType >::Zero;

scanMem.fixedImageGradient.Fill(0.0);
scanMem.movingImageGradient.Fill(0.0);
scanMem.mappedMovingPoint.Fill(0.0);
}


template<class TFixedImage, class TMovingImage, class TVirtualImage>
void
ANTSNeighborhoodCorrelationImageToImageMetricv4<TFixedImage, TMovingImage, TVirtualImage>
Expand Down

This file was deleted.

Loading

0 comments on commit 651dcd0

Please sign in to comment.