Skip to content

Commit

Permalink
Use ConvKernelType instead of NREG_CONV_KERNEL_TYPE
Browse files Browse the repository at this point in the history
  • Loading branch information
onurulgen committed Oct 10, 2023
1 parent 9f24fa1 commit 9b32632
Show file tree
Hide file tree
Showing 24 changed files with 96 additions and 101 deletions.
2 changes: 1 addition & 1 deletion niftyreg_build_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
337
338
2 changes: 1 addition & 1 deletion reg-apps/reg_f3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ int main(int argc, char **argv) {
}
}
if (useMeanLNCC)
reg->SetLNCCKernelType(2);
reg->SetLNCCKernelType(ConvKernelType::Gaussian);

NR_DEBUG("*******************************************");
NR_DEBUG("*******************************************");
Expand Down
18 changes: 9 additions & 9 deletions reg-apps/reg_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,24 +520,24 @@ int main(int argc, char **argv)
bool boolX[3]= {1,0,0};
for(int i=0; i<smoothImg->nt*smoothImg->nu; ++i) kernelSize[i]=param->smoothValueX;
if(flag->smoothMeanFlag)
reg_tools_kernelConvolution(smoothImg,kernelSize,MEAN_KERNEL,nullptr,timePoint,boolX);
reg_tools_kernelConvolution(smoothImg,kernelSize,ConvKernelType::Mean,nullptr,timePoint,boolX);
else if(flag->smoothSplineFlag)
reg_tools_kernelConvolution(smoothImg,kernelSize,CUBIC_SPLINE_KERNEL,nullptr,timePoint,boolX);
else reg_tools_kernelConvolution(smoothImg,kernelSize,GAUSSIAN_KERNEL,nullptr,timePoint,boolX);
reg_tools_kernelConvolution(smoothImg,kernelSize,ConvKernelType::Cubic,nullptr,timePoint,boolX);
else reg_tools_kernelConvolution(smoothImg,kernelSize,ConvKernelType::Gaussian,nullptr,timePoint,boolX);
bool boolY[3]= {0,1,0};
for(int i=0; i<smoothImg->nt*smoothImg->nu; ++i) kernelSize[i]=param->smoothValueY;
if(flag->smoothMeanFlag)
reg_tools_kernelConvolution(smoothImg,kernelSize,MEAN_KERNEL,nullptr,timePoint,boolY);
reg_tools_kernelConvolution(smoothImg,kernelSize,ConvKernelType::Mean,nullptr,timePoint,boolY);
else if(flag->smoothSplineFlag)
reg_tools_kernelConvolution(smoothImg,kernelSize,CUBIC_SPLINE_KERNEL,nullptr,timePoint,boolY);
else reg_tools_kernelConvolution(smoothImg,kernelSize,GAUSSIAN_KERNEL,nullptr,timePoint,boolY);
reg_tools_kernelConvolution(smoothImg,kernelSize,ConvKernelType::Cubic,nullptr,timePoint,boolY);
else reg_tools_kernelConvolution(smoothImg,kernelSize,ConvKernelType::Gaussian,nullptr,timePoint,boolY);
bool boolZ[3]= {0,0,1};
for(int i=0; i<smoothImg->nt*smoothImg->nu; ++i) kernelSize[i]=param->smoothValueZ;
if(flag->smoothMeanFlag)
reg_tools_kernelConvolution(smoothImg,kernelSize,MEAN_KERNEL,nullptr,timePoint,boolZ);
reg_tools_kernelConvolution(smoothImg,kernelSize,ConvKernelType::Mean,nullptr,timePoint,boolZ);
else if(flag->smoothSplineFlag)
reg_tools_kernelConvolution(smoothImg,kernelSize,CUBIC_SPLINE_KERNEL,nullptr,timePoint,boolZ);
else reg_tools_kernelConvolution(smoothImg,kernelSize,GAUSSIAN_KERNEL,nullptr,timePoint,boolZ);
reg_tools_kernelConvolution(smoothImg,kernelSize,ConvKernelType::Cubic,nullptr,timePoint,boolZ);
else reg_tools_kernelConvolution(smoothImg,kernelSize,ConvKernelType::Gaussian,nullptr,timePoint,boolZ);
delete []kernelSize;
delete []timePoint;
if(flag->outputImageFlag)
Expand Down
4 changes: 2 additions & 2 deletions reg-lib/Compute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ void Compute::NormaliseGradient(double maxGradLength, bool optimiseX, bool optim
void Compute::SmoothGradient(float sigma) {
if (sigma != 0) {
sigma = fabs(sigma);
reg_tools_kernelConvolution(dynamic_cast<F3dContent&>(con).GetTransformationGradient(), &sigma, GAUSSIAN_KERNEL);
reg_tools_kernelConvolution(dynamic_cast<F3dContent&>(con).GetTransformationGradient(), &sigma, ConvKernelType::Gaussian);
}
}
/* *************************************************************** */
Expand Down Expand Up @@ -231,7 +231,7 @@ void Compute::GetDefFieldFromVelocityGrid(const bool updateStepNumber) {
/* *************************************************************** */
void Compute::ConvolveImage(nifti_image *image) {
const nifti_image *controlPointGrid = dynamic_cast<F3dContent&>(con).F3dContent::GetControlPointGrid();
constexpr int kernelType = CUBIC_SPLINE_KERNEL;
constexpr ConvKernelType kernelType = ConvKernelType::Cubic;
float currentNodeSpacing[3];
currentNodeSpacing[0] = currentNodeSpacing[1] = currentNodeSpacing[2] = controlPointGrid->dx;
bool activeAxis[3] = { 1, 0, 0 };
Expand Down
4 changes: 2 additions & 2 deletions reg-lib/ConvolutionKernel.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "Kernel.h"
#include "RNifti.h"
#include "_reg_tools.h"

class ConvolutionKernel: public Kernel {
public:
Expand All @@ -10,5 +10,5 @@ class ConvolutionKernel: public Kernel {
}
ConvolutionKernel() : Kernel() {}
virtual ~ConvolutionKernel() {}
virtual void Calculate(nifti_image *image, float *sigma, int kernelType, int *mask = nullptr, bool *timePoints = nullptr, bool *axis = nullptr) = 0;
virtual void Calculate(nifti_image *image, float *sigma, ConvKernelType kernelType, int *mask = nullptr, bool *timePoints = nullptr, bool *axis = nullptr) = 0;
};
4 changes: 2 additions & 2 deletions reg-lib/_reg_aladin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void reg_aladin<T>::InitialiseRegistration() {
for (int i = 1; i < this->referencePyramid[l]->nt; ++i)
active[i] = false;
sigma[0] = this->referenceSigma;
convolutionKernel->castTo<ConvolutionKernel>()->Calculate(this->referencePyramid[l], sigma.get(), 0, nullptr, active.get());
convolutionKernel->castTo<ConvolutionKernel>()->Calculate(this->referencePyramid[l], sigma.get(), ConvKernelType::Mean, nullptr, active.get());
}
if (this->floatingSigma != 0) {
// Only the first image is smoothed
Expand All @@ -184,7 +184,7 @@ void reg_aladin<T>::InitialiseRegistration() {
for (int i = 1; i < this->floatingPyramid[l]->nt; ++i)
active[i] = false;
sigma[0] = this->floatingSigma;
convolutionKernel->castTo<ConvolutionKernel>()->Calculate(this->floatingPyramid[l], sigma.get(), 0, nullptr, active.get());
convolutionKernel->castTo<ConvolutionKernel>()->Calculate(this->floatingPyramid[l], sigma.get(), ConvKernelType::Mean, nullptr, active.get());
}
}

Expand Down
6 changes: 3 additions & 3 deletions reg-lib/_reg_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ void reg_base<T>::Initialise() {
for (int i = 1; i < referencePyramid[l]->nt; ++i)
active[i] = false;
sigma[0] = referenceSmoothingSigma;
reg_tools_kernelConvolution(referencePyramid[l], sigma.get(), GAUSSIAN_KERNEL, nullptr, active.get());
reg_tools_kernelConvolution(referencePyramid[l], sigma.get(), ConvKernelType::Gaussian, nullptr, active.get());
}
if (floatingSmoothingSigma != 0) {
// Only the first image is smoothed
Expand All @@ -444,7 +444,7 @@ void reg_base<T>::Initialise() {
for (int i = 1; i < floatingPyramid[l]->nt; ++i)
active[i] = false;
sigma[0] = floatingSmoothingSigma;
reg_tools_kernelConvolution(floatingPyramid[l], sigma.get(), GAUSSIAN_KERNEL, nullptr, active.get());
reg_tools_kernelConvolution(floatingPyramid[l], sigma.get(), ConvKernelType::Gaussian, nullptr, active.get());
}
}

Expand Down Expand Up @@ -623,7 +623,7 @@ void reg_base<T>::UseLNCC(int timepoint, float stddev) {
}
/* *************************************************************** */
template<class T>
void reg_base<T>::SetLNCCKernelType(int type) {
void reg_base<T>::SetLNCCKernelType(ConvKernelType type) {
if (!measure_lncc)
NR_FATAL_ERROR("The LNCC object has to be created first");
measure_lncc->SetKernelType(type);
Expand Down
2 changes: 1 addition & 1 deletion reg-lib/_reg_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class reg_base: public InterfaceOptimiser {
virtual void UseKLDivergence(int);
virtual void UseDTI(bool*);
virtual void UseLNCC(int, float);
virtual void SetLNCCKernelType(int type);
virtual void SetLNCCKernelType(ConvKernelType type);
virtual void SetLocalWeightSim(NiftiImage);

virtual void SetNMIWeight(int, double);
Expand Down
2 changes: 1 addition & 1 deletion reg-lib/cl/ClConvolutionKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "_reg_tools.h"

/* *************************************************************** */
void ClConvolutionKernel::Calculate(nifti_image *image, float *sigma, int kernelType, int *mask, bool *timePoints, bool *axis) {
void ClConvolutionKernel::Calculate(nifti_image *image, float *sigma, ConvKernelType kernelType, int *mask, bool *timePoints, bool *axis) {
reg_tools_kernelConvolution(image, sigma, kernelType, mask, timePoints, axis);
}
/* *************************************************************** */
2 changes: 1 addition & 1 deletion reg-lib/cl/ClConvolutionKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ class ClConvolutionKernel: public ConvolutionKernel {
public:
ClConvolutionKernel() : ConvolutionKernel() {}
~ClConvolutionKernel() {}
void Calculate(nifti_image *image, float *sigma, int kernelType, int *mask = nullptr, bool *timePoints = nullptr, bool *axis = nullptr);
void Calculate(nifti_image *image, float *sigma, ConvKernelType kernelType, int *mask = nullptr, bool *timePoints = nullptr, bool *axis = nullptr);
};
2 changes: 1 addition & 1 deletion reg-lib/cpu/CpuConvolutionKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "_reg_globalTrans.h"

/* *************************************************************** */
void CpuConvolutionKernel::Calculate(nifti_image *image, float *sigma, int kernelType, int *mask, bool *timePoints, bool *axis) {
void CpuConvolutionKernel::Calculate(nifti_image *image, float *sigma, ConvKernelType kernelType, int *mask, bool *timePoints, bool *axis) {
reg_tools_kernelConvolution(image, sigma, kernelType, mask, timePoints, axis);
}
/* *************************************************************** */
2 changes: 1 addition & 1 deletion reg-lib/cpu/CpuConvolutionKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
class CpuConvolutionKernel: public ConvolutionKernel {
public:
CpuConvolutionKernel() : ConvolutionKernel() {}
void Calculate(nifti_image *image, float *sigma, int kernelType, int *mask = nullptr, bool *timePoints = nullptr, bool *axis = nullptr);
void Calculate(nifti_image *image, float *sigma, ConvKernelType kernelType, int *mask = nullptr, bool *timePoints = nullptr, bool *axis = nullptr);
};
26 changes: 13 additions & 13 deletions reg-lib/cpu/_reg_lncc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ reg_lncc::reg_lncc(): reg_measure() {
this->backwardMask = nullptr;

// Gaussian kernel is used by default
this->kernelType = GAUSSIAN_KERNEL;
this->kernelType = ConvKernelType::Gaussian;

for (int i = 0; i < 255; ++i)
kernelStandardDeviation[i] = -5.f;
Expand Down Expand Up @@ -201,8 +201,8 @@ void UpdateLocalStatImages(const nifti_image *refImage,
const int *refMask,
int *combinedMask,
const float *kernelStandardDeviation,
const int& kernelType,
const int& currentTimepoint) {
const ConvKernelType kernelType,
const int currentTimepoint) {
// Generate the combined mask to ignore all NaN values
#ifdef _WIN32
long voxel;
Expand Down Expand Up @@ -258,8 +258,8 @@ double reg_getLnccValue(const nifti_image *referenceImage,
const int *combinedMask,
const float *kernelStandardDeviation,
nifti_image *correlationImage,
const int& kernelType,
const int& currentTimepoint) {
const ConvKernelType kernelType,
const int currentTimepoint) {
#ifdef _WIN32
long voxel;
const long voxelNumber = (long)NiftiImage::calcVoxelNumber(referenceImage, 3);
Expand Down Expand Up @@ -318,8 +318,8 @@ double GetSimilarityMeasureValue(const nifti_image *referenceImage,
int *forwardMask,
const float *kernelStandardDeviation,
nifti_image *correlationImage,
const int& kernelType,
const int& referenceTimePoint,
const ConvKernelType kernelType,
const int referenceTimePoint,
const double *timePointWeight) {
double lncc = 0;
for (int currentTimepoint = 0; currentTimepoint < referenceTimePoint; ++currentTimepoint) {
Expand Down Expand Up @@ -401,9 +401,9 @@ void reg_getVoxelBasedLnccGradient(const nifti_image *referenceImage,
nifti_image *correlationImage,
const nifti_image *warpedGradient,
nifti_image *measureGradient,
const int& kernelType,
const int& currentTimepoint,
const double& timepointWeight) {
const ConvKernelType kernelType,
const int currentTimepoint,
const double timepointWeight) {
#ifdef _WIN32
long voxel;
long voxelNumber = (long)NiftiImage::calcVoxelNumber(referenceImage, 3);
Expand Down Expand Up @@ -529,9 +529,9 @@ void GetVoxelBasedSimilarityMeasureGradient(const nifti_image *referenceImage,
nifti_image *correlationImage,
const nifti_image *warpedGradient,
nifti_image *measureGradient,
const int& kernelType,
const int& currentTimepoint,
const double& timepointWeight) {
const ConvKernelType kernelType,
const int currentTimepoint,
const double timepointWeight) {
std::visit([&](auto&& refImgDataType) {
using RefImgDataType = std::decay_t<decltype(refImgDataType)>;
// Compute the mean and variance of the reference and warped floating
Expand Down
4 changes: 2 additions & 2 deletions reg-lib/cpu/_reg_lncc.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class reg_lncc: public reg_measure {
this->kernelStandardDeviation[t] = stddev;
}
/// @brief Set the kernel type
virtual void SetKernelType(int t) {
virtual void SetKernelType(ConvKernelType t) {
this->kernelType = t;
}

Expand All @@ -67,6 +67,6 @@ class reg_lncc: public reg_measure {
nifti_image *warpedSdevImageBw;
int *backwardMask;

int kernelType;
ConvKernelType kernelType;
};
/* *************************************************************** */
4 changes: 2 additions & 2 deletions reg-lib/cpu/_reg_mind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void GetMindImageDescriptorCore(const nifti_image *inputImage,
ShiftImage<DataType>(currentInputImage, shiftedImage, mask, rSamplingX[i], rSamplingY[i], rSamplingZ[i]);
reg_tools_subtractImageFromImage(currentInputImage, shiftedImage, diffImage);
reg_tools_multiplyImageToImage(diffImage, diffImage, diffImage);
reg_tools_kernelConvolution(diffImage, &sigma, GAUSSIAN_KERNEL, mask);
reg_tools_kernelConvolution(diffImage, &sigma, ConvKernelType::Gaussian, mask);
reg_tools_addImageToImage(meanImage, diffImage, meanImage);
// Store the current descriptor
const size_t index = i * diffImage->nvox;
Expand Down Expand Up @@ -217,7 +217,7 @@ void GetMindSscImageDescriptorCore(const nifti_image *inputImage,
ShiftImage<DataType>(currentInputImage, shiftedImage, mask, rSamplingX[i], rSamplingY[i], rSamplingZ[i]);
reg_tools_subtractImageFromImage(currentInputImage, shiftedImage, diffImage);
reg_tools_multiplyImageToImage(diffImage, diffImage, diffImage);
reg_tools_kernelConvolution(diffImage, &sigma, GAUSSIAN_KERNEL, mask);
reg_tools_kernelConvolution(diffImage, &sigma, ConvKernelType::Gaussian, mask);

for (int j = 0; j < 2; j++) {
ShiftImage<DataType>(diffImage, diffImageShifted, maskDiffImage, tx[compteurId], ty[compteurId], tz[compteurId]);
Expand Down
Loading

0 comments on commit 9b32632

Please sign in to comment.