Skip to content

Commit

Permalink
Merge pull request #2672 from MRtrix3/tcksift2_saveweights_take2
Browse files Browse the repository at this point in the history
tcksift2: Fix check for allocation of memory for weights vector
  • Loading branch information
jdtournier authored Jul 4, 2023
2 parents 5a0f40c + 2ac2e7b commit 8a19272
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/dwi/tractography/SIFT2/tckfactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,19 +344,22 @@ namespace MR {
{
if (size_t(coefficients.size()) != contributions.size())
throw Exception ("Cannot output weighting factors if they have not first been estimated!");
decltype(coefficients) weights;
try {
decltype(coefficients) weights (coefficients.size());
for (SIFT::track_t i = 0; i != num_tracks(); ++i)
weights[i] = (coefficients[i] == min_coeff || !std::isfinite(coefficients[i])) ?
0.0 :
std::exp (coefficients[i]);
save_vector (weights, path);
weights.resize (coefficients.size());
} catch (...) {
WARN ("Unable to assign memory for output factor file: \"" + Path::basename(path) + "\" not created");
return;
}
for (SIFT::track_t i = 0; i != num_tracks(); ++i)
weights[i] = (coefficients[i] == min_coeff || !std::isfinite(coefficients[i])) ?
0.0 :
std::exp (coefficients[i]);
save_vector (weights, path);
}



void TckFactor::output_coefficients (const std::string& path) const
{
save_vector (coefficients, path);
Expand Down

0 comments on commit 8a19272

Please sign in to comment.