Skip to content

Commit

Permalink
Issue #92: fix affine initialisation in f3d. matrix went out of scope…
Browse files Browse the repository at this point in the history
… during refactoring.
  • Loading branch information
mmodat committed Jul 7, 2023
1 parent a349585 commit 5b7d8fe
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion niftyreg_build_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
266
267
30 changes: 15 additions & 15 deletions reg-apps/reg_aladin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ int main(int argc, char **argv) {
int rigidFlag = 1;
int blockStepSize = 1;
int blockPercentage = 50;
float inlierLts = 50.0f;
int inlierLts = 50;
int alignCentre = 1;
int alignCentreOfMass = 0;
int interpolation = 1;
Expand Down Expand Up @@ -255,16 +255,16 @@ int main(int argc, char **argv) {
alignCentre = 0;
alignCentreOfMass = 2;
} else if (strcmp(argv[i], "-%v") == 0 || strcmp(argv[i], "-pv") == 0 || strcmp(argv[i], "--pv") == 0) {
float value = atof(argv[++i]);
if (value < 0.f || value>100.f) {
reg_print_msg_error("The variance argument is expected to be between 0 and 100");
int value = atoi(argv[++i]);
if (value < 1 || value>100) {
reg_print_msg_error("The variance argument is expected to be an integer between 1 and 100");
return EXIT_FAILURE;
}
blockPercentage = value;
} else if (strcmp(argv[i], "-%i") == 0 || strcmp(argv[i], "-pi") == 0 || strcmp(argv[i], "--pi") == 0) {
float value = atof(argv[++i]);
if (value < 0.f || value>100.f) {
reg_print_msg_error("The inlier argument is expected to be between 0 and 100");
int value = atoi(argv[++i]);
if (value < 1 || value>100) {
reg_print_msg_error("The inlier argument is expected to be an integer between 1 and 100");
return EXIT_FAILURE;
}
inlierLts = value;
Expand All @@ -273,17 +273,17 @@ int main(int argc, char **argv) {
} else if (strcmp(argv[i], "-interp") == 0 || strcmp(argv[i], "--interp") == 0) {
interpolation = atoi(argv[++i]);
} else if (strcmp(argv[i], "-refLowThr") == 0 || strcmp(argv[i], "--refLowThr") == 0) {
referenceLowerThr = atof(argv[++i]);
referenceLowerThr = std::stof(argv[++i]);
} else if (strcmp(argv[i], "-refUpThr") == 0 || strcmp(argv[i], "--refUpThr") == 0) {
referenceUpperThr = atof(argv[++i]);
referenceUpperThr = std::stof(argv[++i]);
} else if (strcmp(argv[i], "-floLowThr") == 0 || strcmp(argv[i], "--floLowThr") == 0) {
floatingLowerThr = atof(argv[++i]);
floatingLowerThr = std::stof(argv[++i]);
} else if (strcmp(argv[i], "-floUpThr") == 0 || strcmp(argv[i], "--floUpThr") == 0) {
floatingUpperThr = atof(argv[++i]);
floatingUpperThr = std::stof(argv[++i]);
}

else if (strcmp(argv[i], "-pad") == 0 || strcmp(argv[i], "--pad") == 0) {
paddingValue = atof(argv[++i]);
paddingValue = std::stof(argv[++i]);
} else if (strcmp(argv[i], "-iso") == 0 || strcmp(argv[i], "--iso") == 0) {
iso = true;
} else if (strcmp(argv[i], "-voff") == 0 || strcmp(argv[i], "--voff") == 0) {
Expand Down Expand Up @@ -495,9 +495,9 @@ int main(int argc, char **argv) {
#endif
time_t end;
time(&end);
int minutes = (int)floorf((end - start) / 60.0f);
int seconds = (int)(end - start - 60 * minutes);
sprintf(text, "Registration performed in %i min %i sec", minutes, seconds);
float minutes = floorf((end - start) / 60.0f);
float seconds = (end - start - 60 * minutes);
sprintf(text, "Registration performed in %i min %i sec", (int)minutes, (int)seconds);
reg_print_info((argv[0]), text);
reg_print_info((argv[0]), "Have a good day !");
#ifdef NDEBUG
Expand Down
6 changes: 4 additions & 2 deletions reg-apps/reg_f3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ int main(int argc, char **argv) {
int refBinNumber = 0;
int floBinNumber = 0;

// mat44 to store the affine matrix if needed
mat44 affineMatrix;

/* read the input parameter */
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "-ref") == 0 || strcmp(argv[i], "-target") == 0 ||
Expand All @@ -341,7 +344,6 @@ int main(int argc, char **argv) {
return EXIT_FAILURE;
}
// Read the affine matrix
mat44 affineMatrix;
reg_tool_ReadAffineFile(&affineMatrix, affineTransformationName);
// Send the transformation to the registration object
reg->SetAffineTransformation(&affineMatrix);
Expand Down Expand Up @@ -748,7 +750,7 @@ int main(int argc, char **argv) {
time_t end;
time(&end);
int minutes = (int)floorf((end - start) / 60.0f);
int seconds = (int)(end - start - 60 * minutes);
int seconds = ((int)(end - start) - 60 * minutes);
text = stringFormat("Registration performed in %i min %i sec", minutes, seconds);
reg_print_info((argv[0]), text.c_str());
reg_print_info((argv[0]), "Have a good day !");
Expand Down
4 changes: 2 additions & 2 deletions reg-lib/cpu/_reg_optimiser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void reg_optimiser<T>::Initialise(size_t nvox,
this->maxIterationNumber = maxIt;
this->currentIterationNumber = startIt;
this->currentDof = cppData;
if (this->bestDof) free(this->bestDof);
if (this->bestDof != nullptr) free(this->bestDof);
this->bestDof = (T*)malloc(this->dofNumber * sizeof(T));
memcpy(this->bestDof, this->currentDof, this->dofNumber * sizeof(T));
if (gradData)
Expand All @@ -80,7 +80,7 @@ void reg_optimiser<T>::Initialise(size_t nvox,
if (cppDataBw) {
this->currentDofBw = cppDataBw;
this->isBackwards = true;
if (this->bestDofBw) free(this->bestDofBw);
if (this->bestDofBw != nullptr) free(this->bestDofBw);
this->bestDofBw = (T*)malloc(this->dofNumberBw * sizeof(T));
memcpy(this->bestDofBw, this->currentDofBw, this->dofNumberBw * sizeof(T));
}
Expand Down

0 comments on commit 5b7d8fe

Please sign in to comment.