Skip to content

Commit

Permalink
Fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
onurulgen committed Feb 20, 2024
1 parent 6cbbccd commit f5e227f
Show file tree
Hide file tree
Showing 63 changed files with 1,508 additions and 2,545 deletions.
2 changes: 1 addition & 1 deletion niftyreg_build_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
413
414
5 changes: 0 additions & 5 deletions reg-apps/reg_aladin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ void Usage(char *exec) {
NR_INFO("\t\t\t\tPlease run reg_gpuinfo first to get platform information and their corresponding ids");
}

// NR_INFO("\t-crv\t\t\tChoose custom capture range for the block matching alg");
#ifdef _OPENMP
int defaultOpenMPValue = omp_get_num_procs();
if (getenv("OMP_NUM_THREADS") != nullptr)
Expand Down Expand Up @@ -161,7 +160,6 @@ int main(int argc, char **argv) {

bool iso = false;
bool verbose = true;
int captureRangeVox = 3;
PlatformType platformType(PlatformType::Cpu);
unsigned gpuIdx = 999;

Expand Down Expand Up @@ -300,8 +298,6 @@ int main(int argc, char **argv) {
platformType = value;
} else if (strcmp(argv[i], "-gpuid") == 0 || strcmp(argv[i], "--gpuid") == 0) {
gpuIdx = unsigned(atoi(argv[++i]));
} else if (strcmp(argv[i], "-crv") == 0 || strcmp(argv[i], "--crv") == 0) {
captureRangeVox = atoi(argv[++i]);
} else if (strcmp(argv[i], "-omp") == 0 || strcmp(argv[i], "--omp") == 0) {
#ifdef _OPENMP
omp_set_num_threads(atoi(argv[++i]));
Expand Down Expand Up @@ -406,7 +402,6 @@ int main(int argc, char **argv) {
reg->SetBlockPercentage(blockPercentage);
reg->SetInlierLts(inlierLts);
reg->SetInterpolation(interpolation);
reg->SetCaptureRangeVox(captureRangeVox);
reg->SetPlatformType(platformType);
reg->SetGpuIdx(gpuIdx);

Expand Down
8 changes: 2 additions & 6 deletions reg-apps/reg_average.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ mat44 compute_average_matrices(size_t matrixNumber,
for(size_t m=0; m<matrixNumber; ++m)
reg_tool_ReadAffineFile(&matrices[m],inputAffName[m]);
// Matrix to store the final result is created
mat44 average_matrix;
mat44 average_matrix{};
// An array to store the weight given to each matrix is generated
float *matrixWeight = (float *)malloc(matrixNumber*sizeof(float));
int *matrixIndexSorted = (int *)malloc(matrixNumber*sizeof(int));
Expand All @@ -133,11 +133,7 @@ mat44 compute_average_matrices(size_t matrixNumber,
if(lts_inlier<1.f && lts_inlier>0)
iterationNumber=10;
for(size_t it=0; it<iterationNumber; ++it){
double tempValue[16]= {0,0,0,0,
0,0,0,0,
0,0,0,0,
0,0,0,0
};
double tempValue[16]{};
double weightSum=0;
// The (weighted) average matrix is computed
for(size_t m=0; m<matrixNumber; ++m)
Expand Down
2,504 changes: 1,158 additions & 1,346 deletions reg-apps/reg_transform.cpp

Large diffs are not rendered by default.

12 changes: 3 additions & 9 deletions reg-io/_reg_ReadWriteImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@
#include <filesystem>

/* *************************************************************** */
void reg_hack_filename(nifti_image *image, std::string filename) {
filename.append("\0");
// Free the char arrays if already allocated
void reg_hack_filename(nifti_image *image, const char *filename) {
if (image->fname) free(image->fname);
if (image->iname) free(image->iname);
// Allocate the char arrays
image->fname = (char *)malloc((filename.size() + 1) * sizeof(char));
image->iname = (char *)malloc((filename.size() + 1) * sizeof(char));
// Copy the new name in the char arrays
strcpy(image->fname, filename.c_str());
strcpy(image->iname, filename.c_str());
image->fname = strdup(filename);
image->iname = strdup(filename);
}
/* *************************************************************** */
int reg_io_checkFileFormat(const std::string& filename) {
Expand Down
2 changes: 1 addition & 1 deletion reg-io/niftilib/nifti1_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -6441,7 +6441,7 @@ char *nifti_image_to_ascii( const nifti_image *nim )
nbuf = (int)strlen(buf) ;
char *temp = (char *)realloc((void *)buf, nbuf+1); /* cut back to proper length */
if (temp)
buf = temp; // cppcheck-suppress memleak // false negative
buf = temp; // cppcheck-suppress memleak // false positive
else
Rc_fprintf_stderr("** NITA: failed to realloc %d bytes\n", nbuf+1);
return buf ;
Expand Down
2 changes: 0 additions & 2 deletions reg-lib/AffineDeformationFieldKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@ class AffineDeformationFieldKernel: public Kernel {
static std::string GetName() {
return "AffineDeformationFieldKernel";
}
AffineDeformationFieldKernel() : Kernel() {}
virtual ~AffineDeformationFieldKernel() {}
virtual void Calculate(bool compose = false) = 0;
};
3 changes: 3 additions & 0 deletions reg-lib/AladinContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

class AladinContent: public Content {
public:
AladinContent(const AladinContent&) = delete;
AladinContent(nifti_image *referenceIn,
nifti_image *floatingIn,
int *referenceMaskIn = nullptr,
Expand All @@ -21,6 +22,8 @@ class AladinContent: public Content {
int blockStepSize = 0);
virtual ~AladinContent();

AladinContent& operator=(const AladinContent&) = delete;

// Getters
virtual _reg_blockMatchingParam* GetBlockMatchingParams() { return blockMatchingParams; }

Expand Down
2 changes: 0 additions & 2 deletions reg-lib/BlockMatchingKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@ class BlockMatchingKernel: public Kernel {
static std::string GetName() {
return "BlockMatchingKernel";
}
BlockMatchingKernel() : Kernel() {}
virtual ~BlockMatchingKernel() {}
virtual void Calculate() = 0;
};
9 changes: 6 additions & 3 deletions reg-lib/ConvolutionKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ class ConvolutionKernel: public Kernel {
static std::string GetName() {
return "ConvolutionKernel";
}
ConvolutionKernel() : Kernel() {}
virtual ~ConvolutionKernel() {}
virtual void Calculate(nifti_image *image, float *sigma, ConvKernelType 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;
};
6 changes: 2 additions & 4 deletions reg-lib/Kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@

class Kernel {
public:
Kernel() {}
virtual ~Kernel() {}

std::string GetName() const;
Kernel() = default;
virtual ~Kernel() = default;

template <class T>
T* castTo() { return dynamic_cast<T*>(this); }
Expand Down
2 changes: 0 additions & 2 deletions reg-lib/LtsKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@ class LtsKernel: public Kernel {
static std::string GetName() {
return "LtsKernel";
}
LtsKernel() : Kernel() {}
virtual ~LtsKernel() {}
virtual void Calculate(bool affine) = 0;
};
9 changes: 0 additions & 9 deletions reg-lib/Optimiser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,6 @@ template class Optimiser<float>;
template class Optimiser<double>;
/* *************************************************************** */
template <class T>
ConjugateGradient<T>::ConjugateGradient(): Optimiser<T>::Optimiser() {
this->array1 = nullptr;
this->array1Bw = nullptr;
this->array2 = nullptr;
this->array2Bw = nullptr;
NR_FUNC_CALLED();
}
/* *************************************************************** */
template <class T>
ConjugateGradient<T>::~ConjugateGradient() {
if (this->array1) {
free(this->array1);
Expand Down
12 changes: 6 additions & 6 deletions reg-lib/Optimiser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,19 @@ class Optimiser {
template <class T>
class ConjugateGradient: public Optimiser<T> {
protected:
T *array1;
T *array1Bw;
T *array2;
T *array2Bw;
bool firstCall;
T *array1 = nullptr;
T *array1Bw = nullptr;
T *array2 = nullptr;
T *array2Bw = nullptr;
bool firstCall = true;

#ifdef NR_TESTING
public:
#endif
virtual void UpdateGradientValues() override;

public:
ConjugateGradient();
ConjugateGradient() { NR_FUNC_CALLED(); }
virtual ~ConjugateGradient();
virtual void Initialise(size_t nvox,
int ndim,
Expand Down
8 changes: 3 additions & 5 deletions reg-lib/Platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,9 @@ void Platform::SetGpuIdx(unsigned gpuIdxIn) {
clContext.SetClIdx(gpuIdxIn);
}

std::size_t paramValueSize;
clContext.CheckErrNum(clGetDeviceInfo(clContext.GetDeviceId(), CL_DEVICE_TYPE, 0, nullptr, &paramValueSize), "Failed to find OpenCL device info ");
cl_device_type *field = (cl_device_type *)alloca(sizeof(cl_device_type) * paramValueSize);
clContext.CheckErrNum(clGetDeviceInfo(clContext.GetDeviceId(), CL_DEVICE_TYPE, paramValueSize, field, nullptr), "Failed to find OpenCL device info ");
if (CL_DEVICE_TYPE_CPU == *field)
cl_device_type field;
clContext.CheckErrNum(clGetDeviceInfo(clContext.GetDeviceId(), CL_DEVICE_TYPE, sizeof(field), &field, nullptr), "Failed to find OpenCL device info");
if (CL_DEVICE_TYPE_CPU == field)
NR_FATAL_ERROR("The OpenCL kernels only support GPU devices for now");
}
#endif
Expand Down
4 changes: 4 additions & 0 deletions reg-lib/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ constexpr PlatformType PlatformTypes[] = {

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

Platform& operator=(const Platform&) = delete;

std::string GetName() const;
PlatformType GetPlatformType() const;
unsigned GetGpuIdx() const;
Expand Down
8 changes: 4 additions & 4 deletions reg-lib/_reg_aladin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ void reg_aladin<T>::InitialiseRegistration() {
referenceCentre[0] /= referenceCount;
referenceCentre[1] /= referenceCount;
referenceCentre[2] /= referenceCount;
float refCOM[3];
float refCOM[3]{};
if (this->inputReference->sform_code > 0)
reg_mat44_mul(&(this->inputReference->sto_xyz), referenceCentre, refCOM);
reg_mat44_mul(&this->inputReference->sto_xyz, referenceCentre, refCOM);

float floatingCentre[3] = { 0, 0, 0 };
float floatingCount = 0;
Expand All @@ -275,9 +275,9 @@ void reg_aladin<T>::InitialiseRegistration() {
floatingCentre[0] /= floatingCount;
floatingCentre[1] /= floatingCount;
floatingCentre[2] /= floatingCount;
float floCOM[3];
float floCOM[3]{};
if (this->inputFloating->sform_code > 0)
reg_mat44_mul(&(this->inputFloating->sto_xyz), floatingCentre, floCOM);
reg_mat44_mul(&this->inputFloating->sto_xyz, floatingCentre, floCOM);
reg_mat44_eye(this->affineTransformation.get());
this->affineTransformation->m[0][3] = floCOM[0] - refCOM[0];
this->affineTransformation->m[1][3] = floCOM[1] - refCOM[1];
Expand Down
4 changes: 0 additions & 4 deletions reg-lib/_reg_aladin.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class reg_aladin {

bool performRigid;
bool performAffine;
int captureRangeVox;

int blockPercentage;
int inlierLts;
Expand Down Expand Up @@ -242,9 +241,6 @@ class reg_aladin {
void SetInterpolationToCubic() {
this->SetInterpolation(3);
}
void SetCaptureRangeVox(int captureRangeIn) {
this->captureRangeVox = captureRangeIn;
}

virtual int Check();
virtual void Print();
Expand Down
4 changes: 2 additions & 2 deletions reg-lib/_reg_aladin_sym.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void reg_aladin_sym<T>::InitialiseRegistration() {
referenceCentre[0] /= referenceCount;
referenceCentre[1] /= referenceCount;
referenceCentre[2] /= referenceCount;
float refCOG[3];
float refCOG[3]{};
if (this->inputReference->sform_code > 0)
reg_mat44_mul(&(this->inputReference->sto_xyz), referenceCentre, refCOG);

Expand All @@ -104,7 +104,7 @@ void reg_aladin_sym<T>::InitialiseRegistration() {
floatingCentre[0] /= floatingCount;
floatingCentre[1] /= floatingCount;
floatingCentre[2] /= floatingCount;
float floCOG[3];
float floCOG[3]{};
if (this->inputFloating->sform_code > 0)
reg_mat44_mul(&(this->inputFloating->sto_xyz), floatingCentre, floCOG);
reg_mat44_eye(this->affineTransformation.get());
Expand Down
9 changes: 8 additions & 1 deletion reg-lib/_reg_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/* *************************************************************** */
template<class T>
reg_base<T>::reg_base(int refTimePoints, int floTimePoints) {
SetPlatformType(PlatformType::Cpu);
reg_base::SetPlatformType(PlatformType::Cpu);

maxIterationNumber = 150;
optimiseX = true;
Expand Down Expand Up @@ -59,6 +59,13 @@ reg_base<T>::reg_base(int refTimePoints, int floTimePoints) {
landmarkReference = nullptr;
landmarkFloating = nullptr;

bestWMeasure = 0;
currentWMeasure = 0;
currentWLand = 0;
bestWLand = 0;
funcProgressCallback = nullptr;
paramsProgressCallback = nullptr;

NR_FUNC_CALLED();
}
/* *************************************************************** */
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 @@ -105,7 +105,7 @@ class reg_base: public InterfaceOptimiser {

// For the NiftyReg plugin in NiftyView
void (*funcProgressCallback)(float pcntProgress, void *params);
void* paramsProgressCallback;
void *paramsProgressCallback;

virtual void WarpFloatingImage(int);
virtual double ComputeSimilarityMeasure();
Expand Down
6 changes: 6 additions & 0 deletions reg-lib/_reg_f3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ reg_f3d<T>::reg_f3d(int refTimePoints, int floTimePoints):
this->useConjGradient = true;
this->useApproxGradient = false;
gridRefinement = true;
currentWJac = 0;
currentWBE = 0;
currentWLE = 0;
bestWJac = 0;
bestWBE = 0;
bestWLE = 0;

NR_FUNC_CALLED();
}
Expand Down
13 changes: 3 additions & 10 deletions reg-lib/cl/ClAffineDeformationFieldKernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,9 @@ ClAffineDeformationFieldKernel::ClAffineDeformationFieldKernel(Content *conIn) :
/* *************************************************************** */
void ClAffineDeformationFieldKernel::Calculate(bool compose) {
//localWorkSize[0]*localWorkSize[1]*localWorkSize[2]... should be lower than the value specified by CL_DEVICE_MAX_WORK_GROUP_SIZE
cl_uint maxWG = 0;
cl_int errNum;
std::size_t paramValueSize;
errNum = clGetDeviceInfo(sContext->GetDeviceId(), CL_DEVICE_MAX_WORK_GROUP_SIZE, 0, nullptr, &paramValueSize);
sContext->CheckErrNum(errNum, "Failed to GetDeviceId() OpenCL device info ");
cl_uint * info = (cl_uint *)alloca(sizeof(cl_uint) * paramValueSize);
errNum = clGetDeviceInfo(sContext->GetDeviceId(), CL_DEVICE_MAX_WORK_GROUP_SIZE, paramValueSize, info, nullptr);
sContext->CheckErrNum(errNum, "Failed to GetDeviceId() OpenCL device info ");
maxWG = *info;
size_t maxWG = 0;
auto errNum = clGetDeviceInfo(sContext->GetDeviceId(), CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(maxWG), &maxWG, nullptr);
sContext->CheckErrNum(errNum, "Failed to GetDeviceId() OpenCL device info");

//8=default value
unsigned xThreads = 8;
Expand Down Expand Up @@ -126,7 +120,6 @@ void ClAffineDeformationFieldKernel::Calculate(bool compose) {

free(trans);
clReleaseMemObject(cltransMat);
return;
}
/* *************************************************************** */
ClAffineDeformationFieldKernel::~ClAffineDeformationFieldKernel() {
Expand Down
4 changes: 2 additions & 2 deletions reg-lib/cl/ClAffineDeformationFieldKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
class ClAffineDeformationFieldKernel: public AffineDeformationFieldKernel {
public:
ClAffineDeformationFieldKernel(Content *conIn);
~ClAffineDeformationFieldKernel();
void Calculate(bool compose = false);
virtual ~ClAffineDeformationFieldKernel();
virtual void Calculate(bool compose = false) override;

private:
mat44 *affineTransformation, *referenceMatrix;
Expand Down
Loading

0 comments on commit f5e227f

Please sign in to comment.