#include "itkImageRegionIterator.h"
#include "itkImageRegionIteratorWithIndex.h"
#include "itkNumericTraits.h"
+#if ITK_VERSION_MAJOR <= 4
#include "itkSimpleFastMutexLock.h"
+#else
+#include <mutex>
+#endif
namespace clitk
{
//Some other typedefs
typedef double CoordRepType;
typedef itk::Image<double, ImageDimension> WeightsImageType;
+#if ITK_VERSION_MAJOR <= 4
typedef itk::Image<itk::SimpleFastMutexLock, ImageDimension> MutexImageType;
+#endif
/** Point type */
typedef itk::Point<CoordRepType,itkGetStaticConstMacro(ImageDimension)> PointType;
//Typedefs
typedef typename OutputImageType::PixelType OutputPixelType;
typedef itk::Image<double, ImageDimension > WeightsImageType;
- typedef itk::Image<itk::SimpleFastMutexLock, ImageDimension > MutexImageType;
+#if ITK_VERSION_MAJOR <= 4
+ typedef itk::Image<itk::SimpleFastMutexLock, ImageDimension> MutexImageType;
+#endif
//===================================================================================
//Set methods
void SetWeights(const typename WeightsImageType::Pointer input) {
m_DeformationField=input;
this->Modified();
}
+#if ITK_VERSION_MAJOR <= 4
void SetMutexImage(const typename MutexImageType::Pointer input) {
m_MutexImage=input;
this->Modified();
m_ThreadSafe=true;
}
+#else
+ void SetMutexImage() {
+ this->Modified();
+ m_ThreadSafe=true;
+ }
+#endif
//Get methods
typename WeightsImageType::Pointer GetWeights() {
//member data
typename itk::Image< double, ImageDimension>::Pointer m_Weights;
typename DeformationFieldType::Pointer m_DeformationField;
+#if ITK_VERSION_MAJOR <= 4
typename MutexImageType::Pointer m_MutexImage;
+#else
+ std::mutex m_Mutex;
+#endif
bool m_ThreadSafe;
};
} else {
//Entering critilal section: shared memory
+#if ITK_VERSION_MAJOR <= 4
m_MutexImage->GetPixel(neighIndex).Lock();
+#else
+ m_Mutex.lock();
+#endif
//Set the pixel and weight at neighIndex
outputPtr->SetPixel(neighIndex, outputPtr->GetPixel(neighIndex) + overlap * static_cast<OutputPixelType>(inputIt.Get()));
m_Weights->SetPixel(neighIndex, m_Weights->GetPixel(neighIndex) + overlap);
//Unlock
+#if ITK_VERSION_MAJOR <= 4
m_MutexImage->GetPixel(neighIndex).Unlock();
+#else
+ m_Mutex.unlock();
+#endif
}
//Add to total overlap
//Threadsafe?
if(m_ThreadSafe) {
//Allocate the mutex image
+#if ITK_VERSION_MAJOR <= 4
typename MutexImageType::Pointer mutex=ForwardWarpImageFilter::MutexImageType::New();
mutex->SetRegions(region);
mutex->Allocate();
mutex->SetSpacing(inputPtr->GetSpacing());
helper1->SetMutexImage(mutex);
+#else
+ helper1->SetMutexImage();
+#endif
if (m_Verbose) std::cout <<"Forwarp warping using a thread-safe algorithm" <<std::endl;
} else if(m_Verbose)std::cout <<"Forwarp warping using a thread-unsafe algorithm" <<std::endl;
//Some other typedefs
typedef double CoordRepType;
typedef itk::Image<double, ImageDimension> WeightsImageType;
+#if ITK_VERSION_MAJOR <= 4
typedef itk::Image<itk::SimpleFastMutexLock, ImageDimension> MutexImageType;
+#endif
/** Point type */
typedef itk::Point<CoordRepType,itkGetStaticConstMacro(ImageDimension)> PointType;
//Typedefs
typedef typename OutputImageType::PixelType PixelType;
typedef itk::Image<double, ImageDimension > WeightsImageType;
- typedef itk::Image<itk::SimpleFastMutexLock, ImageDimension > MutexImageType;
+#if ITK_VERSION_MAJOR <= 4
+ typedef itk::Image<itk::SimpleFastMutexLock, ImageDimension> MutexImageType;
+#endif
//===================================================================================
//Set methods
m_Weights = input;
this->Modified();
}
+#if ITK_VERSION_MAJOR <= 4
void SetMutexImage(const typename MutexImageType::Pointer input) {
m_MutexImage=input;
this->Modified();
m_ThreadSafe=true;
}
+#else
+ void SetMutexImage() {
+ this->Modified();
+ m_ThreadSafe=true;
+ }
+#endif
//Get methods
typename WeightsImageType::Pointer GetWeights() {
//member data
typename WeightsImageType::Pointer m_Weights;
+#if ITK_VERSION_MAJOR <= 4
typename MutexImageType::Pointer m_MutexImage;
+#else
+ std::mutex m_Mutex;
+#endif
bool m_ThreadSafe;
};
else {
//Entering critilal section: shared memory
+#if ITK_VERSION_MAJOR <= 4
m_MutexImage->GetPixel(neighIndex).Lock();
+#else
+ m_Mutex.lock();
+#endif
//Set the pixel and weight at neighIndex
outputPtr->SetPixel(neighIndex, outputPtr->GetPixel(neighIndex) - (displacement*overlap));
m_Weights->SetPixel(neighIndex, m_Weights->GetPixel(neighIndex) + overlap);
//Unlock
+#if ITK_VERSION_MAJOR <= 4
m_MutexImage->GetPixel(neighIndex).Unlock();
+#else
+ m_Mutex.unlock();
+#endif
}
//Add to total overlap
//Threadsafe?
if(m_ThreadSafe) {
//Allocate the mutex image
+#if ITK_VERSION_MAJOR <= 4
typename MutexImageType::Pointer mutex=InvertVFFilter::MutexImageType::New();
mutex->SetRegions(region);
mutex->Allocate();
mutex->SetSpacing(inputPtr->GetSpacing());
helper1->SetMutexImage(mutex);
+#else
+ helper1->SetMutexImage();
+#endif
if (m_Verbose) std::cout <<"Inverting using a thread-safe algorithm" <<std::endl;
} else if(m_Verbose)std::cout <<"Inverting using a thread-unsafe algorithm" <<std::endl;
#include "itkImageRegionIterator.h"
#include "itkImageRegionIteratorWithIndex.h"
#include "itkNumericTraits.h"
+#if ITK_VERSION_MAJOR <= 4
#include "itkSimpleFastMutexLock.h"
+#else
+#include <mutex>
+#endif
#include "itkImageMaskSpatialObject.h"
namespace clitk