Skip to content

Commit

Permalink
Replace vector with array in axes_on_write
Browse files Browse the repository at this point in the history
Since we know the size of the mask needs to be 3 for NiFTI, array makes more sense.
  • Loading branch information
daljit46 committed Jan 9, 2024
1 parent b28af8f commit 1561297
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion core/file/json_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* For more details, see http://www.mrtrix.org/.
*/

#include <array>
#include <fstream>
#include <sstream>

Expand Down Expand Up @@ -254,7 +255,7 @@ void write(const Header &header, nlohmann::json &json, const std::string &image_
}

std::vector<size_t> order;
std::vector<bool> flip;
std::array<bool, 3> flip;
File::NIfTI::axes_on_write(header, order, flip);
if (order[0] == 0 && order[1] == 1 && order[2] == 2 && !flip[0] && !flip[1] && !flip[2]) {
INFO(
Expand Down
4 changes: 2 additions & 2 deletions core/file/nifti_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,15 +544,15 @@ template <class NiftiHeader> void store(NiftiHeader &NH, const Header &H, const
}
}

void axes_on_write(const Header &H, std::vector<size_t> &order, std::vector<bool> &flip) {
void axes_on_write(const Header &H, std::vector<size_t> &order, std::array<bool, 3> &flip) {
Stride::List strides = Stride::get(H);
strides.resize(3);
order = Stride::order(strides);
flip = {strides[order[0]] < 0, strides[order[1]] < 0, strides[order[2]] < 0};
}

transform_type adjust_transform(const Header &H, std::vector<size_t> &axes) {
std::vector<bool> flip;
std::array<bool, 3> flip;
axes_on_write(H, axes, flip);

if (axes[0] == 0 && axes[1] == 1 && axes[2] == 2 && !flip[0] && !flip[1] && !flip[2])
Expand Down
3 changes: 2 additions & 1 deletion core/file/nifti_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#ifndef __file_nifti_utils_h__
#define __file_nifti_utils_h__

#include <array>
// nifti1_io.h and nifti2_io.h headers must be included after dirent.h (transitively included by header.h)
// otherwise we run into definitions conflict on Linux
// clang-format off
Expand All @@ -35,7 +36,7 @@ namespace File {
namespace NIfTI {
extern bool right_left_warning_issued;

void axes_on_write(const Header &H, std::vector<size_t> &order, std::vector<bool> &flip);
void axes_on_write(const Header &H, std::vector<size_t> &order, std::array<bool, 3> &flip);
transform_type adjust_transform(const Header &H, std::vector<size_t> &order);

bool check(int VERSION, Header &H, const size_t num_axes, const std::vector<std::string> &suffixes);
Expand Down
3 changes: 2 additions & 1 deletion core/phase_encoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define __phaseencoding_h__

#include <Eigen/Dense>
#include <array>

#include "app.h"
#include "axes.h"
Expand Down Expand Up @@ -192,7 +193,7 @@ Eigen::MatrixXd transform_for_image_load(const MatrixType &pe_scheme, const Head
template <class MatrixType, class HeaderType>
Eigen::MatrixXd transform_for_nifti_write(const MatrixType &pe_scheme, const HeaderType &H) {
std::vector<size_t> order;
std::vector<bool> flip;
std::array<bool, 3> flip;
File::NIfTI::axes_on_write(H, order, flip);
if (order[0] == 0 && order[1] == 1 && order[2] == 2 && !flip[0] && !flip[1] && !flip[2]) {
INFO("No transformation of phase encoding data required for export to file");
Expand Down

0 comments on commit 1561297

Please sign in to comment.