Skip to content

Commit

Permalink
Refactorisations
Browse files Browse the repository at this point in the history
  • Loading branch information
onurulgen committed Nov 16, 2023
1 parent 86db434 commit 5577571
Show file tree
Hide file tree
Showing 43 changed files with 160 additions and 154 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
*.app

# IDE
.devcontainer
.idea
.vscode
.vs
Expand Down
2 changes: 1 addition & 1 deletion niftyreg_build_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
363
364
2 changes: 1 addition & 1 deletion reg-io/RNifti/NiftiImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -2021,7 +2021,7 @@ class NiftiImage
* @param dimCount Number of dimensions to consider
* @return The number of voxels in the image
*/
static size_t calcVoxelNumber(const nifti_image *image, const int& dimCount) {
static size_t calcVoxelNumber(const nifti_image *image, const int dimCount) {
if (image == nullptr)
return 0;
size_t voxelNumber = 1;
Expand Down
2 changes: 1 addition & 1 deletion reg-lib/AladinContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ class AladinContent: public Content {
protected:
#endif
// Functions for testing
virtual void SetCaptureRange(const int& captureRangeIn) { blockMatchingParams->voxelCaptureRange = captureRangeIn; }
virtual void SetCaptureRange(const int captureRangeIn) { blockMatchingParams->voxelCaptureRange = captureRangeIn; }
virtual void SetBlockMatchingParams(_reg_blockMatchingParam *bmp) { blockMatchingParams = bmp; }
};
2 changes: 1 addition & 1 deletion reg-lib/ContentCreatorFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ enum class ContentType { Base, Aladin, Def, F3d, F3d2 };

class ContentCreatorFactory {
public:
virtual ContentCreator* Produce(const ContentType& conType) {
virtual ContentCreator* Produce(const ContentType conType) {
switch (conType) {
case ContentType::Base:
return new ContentCreator();
Expand Down
2 changes: 1 addition & 1 deletion reg-lib/Measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "_reg_mind.h"

/* *************************************************************** */
reg_measure* Measure::Create(const MeasureType& measureType) {
reg_measure* Measure::Create(const MeasureType measureType) {
switch (measureType) {
case MeasureType::Nmi:
return new reg_nmi();
Expand Down
2 changes: 1 addition & 1 deletion reg-lib/Measure.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ enum class MeasureType { Nmi, Ssd, Dti, Lncc, Kld, Mind, MindSsc };

class Measure {
public:
virtual reg_measure* Create(const MeasureType& measureType);
virtual reg_measure* Create(const MeasureType measureType);
virtual void Initialise(reg_measure& measure, DefContent& con, DefContent *conBw = nullptr);
};
4 changes: 2 additions & 2 deletions reg-lib/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#endif

/* *************************************************************** */
Platform::Platform(const PlatformType& platformTypeIn) {
Platform::Platform(const PlatformType platformTypeIn) {
platformType = platformTypeIn;
if (platformType == PlatformType::Cpu) {
platformName = "CPU";
Expand Down Expand Up @@ -102,7 +102,7 @@ Compute* Platform::CreateCompute(Content& con) const {
return computeFactory->Produce(con);
}
/* *************************************************************** */
ContentCreator* Platform::CreateContentCreator(const ContentType& conType) const {
ContentCreator* Platform::CreateContentCreator(const ContentType conType) const {
return contentCreatorFactory->Produce(conType);
}
/* *************************************************************** */
Expand Down
4 changes: 2 additions & 2 deletions reg-lib/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ constexpr PlatformType PlatformTypes[] = {

class Platform {
public:
Platform(const PlatformType& platformTypeIn);
Platform(const PlatformType platformTypeIn);
~Platform();

std::string GetName() const;
Expand All @@ -29,7 +29,7 @@ class Platform {
void SetGpuIdx(unsigned gpuIdxIn);

Compute* CreateCompute(Content& con) const;
ContentCreator* CreateContentCreator(const ContentType& conType = ContentType::Base) const;
ContentCreator* CreateContentCreator(const ContentType conType = ContentType::Base) const;
Kernel* CreateKernel(const std::string& name, Content *con) const;
Measure* CreateMeasure() const;
template<typename Type>
Expand Down
2 changes: 1 addition & 1 deletion reg-lib/_reg_aladin.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class reg_aladin {
}
NiftiImage GetFinalWarpedImage();

void SetPlatformType(const PlatformType& platformTypeIn) {
void SetPlatformType(const PlatformType platformTypeIn) {
this->platformType = platformTypeIn;
}
void SetGpuIdx(unsigned gpuIdxIn) {
Expand Down
4 changes: 2 additions & 2 deletions reg-lib/_reg_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ class reg_base: public InterfaceOptimiser {
virtual bool GetSymmetricStatus() { return false; }

// Platform
virtual void SetPlatformType(const PlatformType& platformType) {
virtual void SetPlatformType(const PlatformType platformType) {
platform.reset(new Platform(platformType));
measure.reset(platform->CreateMeasure());
}
virtual void SetGpuIdx(const unsigned& gpuIdx) { platform->SetGpuIdx(gpuIdx); }
virtual void SetGpuIdx(const unsigned gpuIdx) { platform->SetGpuIdx(gpuIdx); }

// Optimisation-related functions
virtual void SetMaximalIterationNumber(unsigned);
Expand Down
2 changes: 1 addition & 1 deletion reg-lib/cl/ClContentCreatorFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class ClContentCreatorFactory: public ContentCreatorFactory {
public:
virtual ContentCreator* Produce(const ContentType& conType) override {
virtual ContentCreator* Produce(const ContentType conType) override {
switch (conType) {
case ContentType::Aladin:
return new ClAladinContentCreator();
Expand Down
4 changes: 2 additions & 2 deletions reg-lib/cpu/_reg_globalTrans.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct _reg_sorted_point3D
warped[2] = r[2];
}

bool operator <(const _reg_sorted_point3D &sp) const
bool operator <(const _reg_sorted_point3D& sp) const
{
return (sp.distance < distance);
}
Expand All @@ -61,7 +61,7 @@ struct _reg_sorted_point2D
warped[0] = r[0];
warped[1] = r[1];
}
bool operator <(const _reg_sorted_point2D &sp) const
bool operator <(const _reg_sorted_point2D& sp) const
{
return (sp.distance < distance);
}
Expand Down
6 changes: 3 additions & 3 deletions reg-lib/cpu/_reg_kld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,21 +232,21 @@ void reg_getKLDivergenceVoxelBasedGradient(const nifti_image *referenceImage,
tempValue *= jacPtr[voxel];

// Ensure that gradient of the warpedImage image along x-axis is not NaN
const double& tempGradX = currentGradPtrX[voxel];
const double tempGradX = currentGradPtrX[voxel];
if (tempGradX == tempGradX)
// Update the gradient along the x-axis
measureGradPtrX[voxel] -= static_cast<DataType>(tempValue * tempGradX);

// Ensure that gradient of the warpedImage image along y-axis is not NaN
const double& tempGradY = currentGradPtrY[voxel];
const double tempGradY = currentGradPtrY[voxel];
if (tempGradY == tempGradY)
// Update the gradient along the y-axis
measureGradPtrY[voxel] -= static_cast<DataType>(tempValue * tempGradY);

// Check if the current images are 3D
if (referenceImage->nz > 1) {
// Ensure that gradient of the warpedImage image along z-axis is not NaN
const double& tempGradZ = currentGradPtrZ[voxel];
const double tempGradZ = currentGradPtrZ[voxel];
if (tempGradZ == tempGradZ)
// Update the gradient along the z-axis
measureGradPtrZ[voxel] -= static_cast<DataType>(tempValue * tempGradZ);
Expand Down
10 changes: 5 additions & 5 deletions reg-lib/cpu/_reg_lncc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,10 @@ void reg_getVoxelBasedLnccGradient(const nifti_image *referenceImage,
for (voxel = 0; voxel < voxelNumber; ++voxel) {
// Check if the current voxel belongs to the mask
if (combinedMask[voxel] > -1) {
const double& refMeanValue = meanImgPtr[voxel];
const double& warMeanValue = warMeanPtr[voxel];
const double& refSdevValue = sdevImgPtr[voxel];
const double& warSdevValue = warSdevPtr[voxel];
const double refMeanValue = meanImgPtr[voxel];
const double warMeanValue = warMeanPtr[voxel];
const double refSdevValue = sdevImgPtr[voxel];
const double warSdevValue = warSdevPtr[voxel];
const double correlaValue = correlationPtr[voxel] - (refMeanValue * warMeanValue);
double temp1 = 1.0 / (refSdevValue * warSdevValue);
double temp2 = correlaValue / (refSdevValue * warSdevValue * warSdevValue * warSdevValue);
Expand Down Expand Up @@ -511,7 +511,7 @@ void reg_getVoxelBasedLnccGradient(const nifti_image *referenceImage,
shared(voxelNumber, measureGradPtrX)
#endif
for (voxel = 0; voxel < voxelNumber; ++voxel) {
const DataType& val = measureGradPtrX[voxel];
const DataType val = measureGradPtrX[voxel];
if (val != val || isinf(val))
measureGradPtrX[voxel] = 0;
}
Expand Down
10 changes: 5 additions & 5 deletions reg-lib/cpu/_reg_localTrans_regul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1152,8 +1152,8 @@ void reg_spline_approxLinearEnergyGradient2D(const nifti_image *splineControlPoi
for (int b = -1; b < 2; b++) {
for (int a = -1; a < 2; a++) {
const int index = (y + b) * splineControlPoint->nx + x + a;
const DataType& splineCoeffX = splinePtrX[index];
const DataType& splineCoeffY = splinePtrY[index];
const DataType splineCoeffX = splinePtrX[index];
const DataType splineCoeffY = splinePtrY[index];

matrix.m[0][0] += static_cast<float>(basisX[i] * splineCoeffX);
matrix.m[1][0] += static_cast<float>(basisY[i] * splineCoeffX);
Expand Down Expand Up @@ -1221,9 +1221,9 @@ void reg_spline_approxLinearEnergyGradient3D(const nifti_image *splineControlPoi
for (int b = -1; b < 2; b++) {
for (int a = -1; a < 2; a++) {
const int index = ((z + c) * splineControlPoint->ny + y + b) * splineControlPoint->nx + x + a;
const DataType& splineCoeffX = splinePtrX[index];
const DataType& splineCoeffY = splinePtrY[index];
const DataType& splineCoeffZ = splinePtrZ[index];
const DataType splineCoeffX = splinePtrX[index];
const DataType splineCoeffY = splinePtrY[index];
const DataType splineCoeffZ = splinePtrZ[index];

matrix.m[0][0] += static_cast<float>(basisX[i] * splineCoeffX);
matrix.m[1][0] += static_cast<float>(basisY[i] * splineCoeffX);
Expand Down
26 changes: 13 additions & 13 deletions reg-lib/cpu/_reg_mind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ template <class DataType>
void ShiftImage(const nifti_image *inputImage,
nifti_image *shiftedImage,
const int *mask,
const int& tx,
const int& ty,
const int& tz) {
const int tx,
const int ty,
const int tz) {
const DataType* inputData = static_cast<DataType*>(inputImage->data);
DataType* shiftImageData = static_cast<DataType*>(shiftedImage->data);
#ifdef _OPENMP
Expand Down Expand Up @@ -57,8 +57,8 @@ template <class DataType>
void GetMindImageDescriptorCore(const nifti_image *inputImage,
nifti_image *mindImage,
const int *mask,
const int& descriptorOffset,
const int& currentTimePoint) {
const int descriptorOffset,
const int currentTimePoint) {
#ifdef WIN32
long voxelIndex;
const long voxelNumber = (long)NiftiImage::calcVoxelNumber(inputImage, 3);
Expand Down Expand Up @@ -131,7 +131,7 @@ void GetMindImageDescriptorCore(const nifti_image *inputImage,

mindIndex = voxelIndex;
for (int t = 0; t < samplingNbr; t++) {
const DataType& descValue = mindImgDataPtr[mindIndex];
const DataType descValue = mindImgDataPtr[mindIndex];
mindImgDataPtr[mindIndex] = descValue / maxDesc;
mindIndex += voxelNumber;
}
Expand All @@ -147,8 +147,8 @@ void GetMindImageDescriptorCore(const nifti_image *inputImage,
void GetMindImageDescriptor(const nifti_image *inputImage,
nifti_image *mindImage,
const int *mask,
const int& descriptorOffset,
const int& currentTimePoint) {
const int descriptorOffset,
const int currentTimePoint) {
if (inputImage->datatype != mindImage->datatype)
NR_FATAL_ERROR("The input image and the MIND image must have the same datatype");
std::visit([&](auto&& imgType) {
Expand All @@ -162,8 +162,8 @@ template <class DataType>
void GetMindSscImageDescriptorCore(const nifti_image *inputImage,
nifti_image *mindSscImage,
const int *mask,
const int& descriptorOffset,
const int& currentTimePoint) {
const int descriptorOffset,
const int currentTimePoint) {
#ifdef WIN32
long voxelIndex;
const long voxelNumber = (long)NiftiImage::calcVoxelNumber(inputImage, 3);
Expand Down Expand Up @@ -253,7 +253,7 @@ void GetMindSscImageDescriptorCore(const nifti_image *inputImage,

mindIndex = voxelIndex;
for (int t = 0; t < lengthDescriptor; t++) {
const DataType& descValue = mindSscImgDataPtr[mindIndex];
const DataType descValue = mindSscImgDataPtr[mindIndex];
mindSscImgDataPtr[mindIndex] = descValue / maxDesc;
mindIndex += voxelNumber;
}
Expand All @@ -271,8 +271,8 @@ void GetMindSscImageDescriptorCore(const nifti_image *inputImage,
void GetMindSscImageDescriptor(const nifti_image *inputImage,
nifti_image *mindSscImage,
const int *mask,
const int& descriptorOffset,
const int& currentTimePoint) {
const int descriptorOffset,
const int currentTimePoint) {
if (inputImage->datatype != mindSscImage->datatype)
NR_FATAL_ERROR("The input image and the MINDSSC image must have the same datatype!");
std::visit([&](auto&& imgType) {
Expand Down
8 changes: 4 additions & 4 deletions reg-lib/cpu/_reg_mind.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ class reg_mindssc: public reg_mind {
void GetMindImageDescriptor(const nifti_image *inputImage,
nifti_image *mindImage,
const int *mask,
const int& descriptorOffset,
const int& currentTimePoint);
const int descriptorOffset,
const int currentTimePoint);
/* *************************************************************** */
void GetMindSscImageDescriptor(const nifti_image *inputImage,
nifti_image *mindSscImage,
const int *mask,
const int& descriptorOffset,
const int& currentTimePoint);
const int descriptorOffset,
const int currentTimePoint);
/* *************************************************************** */
Loading

0 comments on commit 5577571

Please sign in to comment.