Skip to content
Draft
15 changes: 9 additions & 6 deletions cpp/cmd/5ttedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,26 +192,29 @@ bool Modifier::operator()(const Iterator &pos) {
for (auto i = Loop(3)(v_out); i; ++i)
sum_result += v_out.value();
if (MR::abs(sum_result - 1.0) > 1e-5) {
std::cerr << "[" << str(pos.index(0)) << "," << str(pos.index(1)) << "," << str(pos.index(2)) << "]\n";
std::cerr << "[" << fmt::format("{}", pos.index(0)) << "," << fmt::format("{}", pos.index(1)) << ","
<< fmt::format("{}", pos.index(2)) << "]\n";
std::cerr << "Input image values: ";
for (auto i = Loop(3)(v_in); i; ++i)
std::cerr << str(v_in.value()) << " ";
std::cerr << fmt::format("{}", v_in.value()) << " ";
std::cerr << "\n";
std::cerr << "User modification values: ";
for (size_t tissue = 0; tissue != 5; ++tissue) {
if (buffers[tissue].valid()) {
std::cerr << str<float>(buffers[tissue].value()) << " ";
std::cerr << fmt::format("{}", static_cast<float>(buffers[tissue].value())) << " ";
} else {
std::cerr << "<> ";
}
}
std::cerr << "\n";
std::cerr << "Output image values: ";
for (auto i = Loop(3)(v_out); i; ++i)
std::cerr << str(v_out.value()) << " ";
std::cerr << fmt::format("{}", v_out.value()) << " ";
std::cerr << "\n";
std::cerr << "sum_user=" << str<float>(sum_user) << "; sum_unmodified=" << str<float>(sum_unmodified)
<< "; multiplier=" << str<float>(multiplier) << "\n";
std::cerr << fmt::format("sum_user={}; sum_unmodified={}; multiplier={}\n",
static_cast<float>(sum_user),
static_cast<float>(sum_unmodified),
static_cast<float>(multiplier));
}
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/cmd/amp2response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ void run() {

KeyValues keyvals;
if (shells) {
std::string line = str(static_cast<size_t>(std::round((*shells)[0].get_mean())));
std::string line = fmt::format("{}", static_cast<size_t>(std::round((*shells)[0].get_mean())));
for (size_t i = 1; i != (*shells).count(); ++i)
line += fmt::format(",{}", static_cast<size_t>(std::round((*shells)[i].get_mean())));
keyvals["Shells"] = line;
Expand Down
14 changes: 7 additions & 7 deletions cpp/cmd/fixelcfestats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,11 @@ void run() {
}

Header output_header(dynamic_cast<SubjectFixelImport *>(importer[0].get())->header());
output_header.keyval()["cfe_dh"] = str(cfe_dh);
output_header.keyval()["cfe_e"] = str(cfe_e);
output_header.keyval()["cfe_h"] = str(cfe_h);
output_header.keyval()["cfe_c"] = str(cfe_c);
output_header.keyval()["cfe_legacy"] = str(cfe_legacy);
output_header.keyval()["cfe_dh"] = fmt::format("{}", cfe_dh);
output_header.keyval()["cfe_e"] = fmt::format("{}", cfe_e);
output_header.keyval()["cfe_h"] = fmt::format("{}", cfe_h);
output_header.keyval()["cfe_c"] = fmt::format("{}", cfe_c);
output_header.keyval()["cfe_legacy"] = fmt::format("{}", cfe_legacy);

measurements_matrix_type data(importer.size(), num_fixels);
{
Expand Down Expand Up @@ -468,14 +468,14 @@ void run() {
matrix_type empirical_cfe_statistic;
if (do_nonstationarity_adjustment) {
Stats::PermTest::precompute_empirical_stat(glm_test, cfe_integrator, empirical_skew, empirical_cfe_statistic);
output_header.keyval()["nonstationarity_adjustment"] = str(true);
output_header.keyval()["nonstationarity_adjustment"] = fmt::format("{}", true);
for (Math::Stats::index_type i = 0; i != num_hypotheses; ++i)
write_fixel_output(output_fixel_directory / fmt::format("cfe_empirical{}.mif", postfix(i)),
empirical_cfe_statistic.col(i),
mask_processing_image,
output_header);
} else {
output_header.keyval()["nonstationarity_adjustment"] = str(false);
output_header.keyval()["nonstationarity_adjustment"] = fmt::format("{}", false);
}

// Precompute default statistic and CFE statistic
Expand Down
2 changes: 1 addition & 1 deletion cpp/cmd/fixelcrop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void run() {
total_nfixels--;
}

out_index_header.keyval()[Fixel::n_fixels_key] = str(total_nfixels);
out_index_header.keyval()[Fixel::n_fixels_key] = fmt::format("{}", total_nfixels);
auto out_index_image =
Image<index_type>::create(out_fixel_directory / in_index_header.path().filename(), out_index_header);

Expand Down
2 changes: 1 addition & 1 deletion cpp/cmd/fixeltransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void run() {
// Ready to construct output images
Header output_index_header(warp_header);
output_index_header.size(3) = 2;
output_index_header.keyval()[Fixel::n_fixels_key] = str(nfixels_out);
output_index_header.keyval()[Fixel::n_fixels_key] = fmt::format("{}", nfixels_out);
Image<index_type> output_index_image = //
Image<index_type>::create(output_dir / "index.mif", //
output_index_header); //
Expand Down
2 changes: 1 addition & 1 deletion cpp/cmd/fod2fixel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void Segmented_FOD_receiver::commit() {
std::unique_ptr<DataImage> skew_image;

auto index_header(H);
index_header.keyval()[Fixel::n_fixels_key] = str(fixel_count);
index_header.keyval()[Fixel::n_fixels_key] = fmt::format("{}", fixel_count);
index_header.ndim() = 4;
index_header.size(3) = 2;
index_header.datatype() = DataType::from<index_type>();
Expand Down
2 changes: 1 addition & 1 deletion cpp/cmd/label2colour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void run() {
colour[1] = dist(rng);
colour[2] = dist(rng);
} while (colour.sum() < 100);
lut.insert(std::make_pair(i, LUT_node(str(i), colour)));
lut.insert(std::make_pair(i, LUT_node(fmt::format("{}", i), colour)));
}
}

Expand Down
4 changes: 2 additions & 2 deletions cpp/cmd/label2mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void run() {
if (!missing_nodes.empty()) {
WARN("The following labels are absent from the parcellation image "
"and so will have an empty mesh in the output file: " +
join(missing_nodes, ", "));
fmt::format("{}", fmt::join(missing_nodes, ", ")));
}

{
Expand All @@ -120,7 +120,7 @@ void run() {
};

auto worker = [&](const size_t &in) {
meshes[in].set_name(str(in));
meshes[in].set_name(fmt::format("{}", in));
std::vector<int> from, dimensions;
for (size_t axis = 0; axis != 3; ++axis) {
from.push_back(lower_corners[in][axis]);
Expand Down
2 changes: 1 addition & 1 deletion cpp/cmd/labelvalidate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void run() {
for (size_t i = 0; i < std::min(ngaps, max_listed); ++i) {
if (i > 0U)
missing_str += ", ";
missing_str += str(result.missing_indices[i]);
missing_str += fmt::format("{}", result.missing_indices[i]);
}
if (ngaps > max_listed)
missing_str += fmt::format(", ... (and {} more)", ngaps - max_listed);
Expand Down
2 changes: 1 addition & 1 deletion cpp/cmd/mraverageheader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void usage() {
" (see Description)."
" Valid options are: {};"
" default = {}",
join(avgspace_voxspacing_choices, ","),
fmt::join(avgspace_voxspacing_choices, ","),
SPACING_DEFAULT_STRING))
+ Argument("type").type_choice(avgspace_voxspacing_choices)
+ Option ("fill", "set the intensity in the first volume of the average space to 1")
Expand Down
2 changes: 1 addition & 1 deletion cpp/cmd/mrcalc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ std::string operation_string(const StackEntry &entry) {
replace(s, n, operation_string(entry.evaluator->operands[n]));
return s;
} else
return str(entry.value);
return fmt::format("{}", entry.value);
}

template <class Operation> class UnaryEvaluator : public Evaluator {
Expand Down
12 changes: 6 additions & 6 deletions cpp/cmd/mrclusterstats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,14 @@ void run() {
Header output_header(mask_header);
output_header.datatype() = DataType::Float32;
// output_header.keyval()["num permutations"] = str(num_perms);
output_header.keyval()["26 connectivity"] = str(do_26_connectivity);
output_header.keyval()["nonstationary adjustment"] = str(do_nonstationarity_adjustment);
output_header.keyval()["26 connectivity"] = fmt::format("{}", do_26_connectivity);
output_header.keyval()["nonstationary adjustment"] = fmt::format("{}", do_nonstationarity_adjustment);
if (use_tfce) {
output_header.keyval()["tfce_dh"] = str(tfce_dh);
output_header.keyval()["tfce_e"] = str(tfce_E);
output_header.keyval()["tfce_h"] = str(tfce_H);
output_header.keyval()["tfce_dh"] = fmt::format("{}", tfce_dh);
output_header.keyval()["tfce_e"] = fmt::format("{}", tfce_E);
output_header.keyval()["tfce_h"] = fmt::format("{}", tfce_H);
} else {
output_header.keyval()["threshold"] = str(cluster_forming_threshold);
output_header.keyval()["threshold"] = fmt::format("{}", cluster_forming_threshold);
}

const std::filesystem::path output_dir = argument[3];
Expand Down
2 changes: 1 addition & 1 deletion cpp/cmd/mrcolour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void usage() {

ARGUMENTS
+ Argument ("input", "the input image").type_image_in()
+ Argument ("map", fmt::format("the colourmap to apply; choices are: {}", join(colourmap_choices, ","))).type_choice (colourmap_choices)
+ Argument ("map", fmt::format("the colourmap to apply; choices are: {}", fmt::join(colourmap_choices, ","))).type_choice (colourmap_choices)
+ Argument ("output", "the output image").type_image_out();

OPTIONS
Expand Down
8 changes: 4 additions & 4 deletions cpp/cmd/mrconvert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ void run() {
opt = get_options("copy_properties");
if (!opt.empty()) {
header_out.keyval().clear();
if (str(opt[0][0]) != "NULL") {
if (std::string(opt[0][0]) != "NULL") {
try {
const Header source = Header::open(opt[0][0]);
header_out.keyval() = source.keyval();
Expand All @@ -426,7 +426,7 @@ void run() {

opt = get_options("clear_property");
for (size_t n = 0; n < opt.size(); ++n) {
if (str(opt[n][0]) == "command_history")
if (std::string(opt[n][0]) == "command_history")
add_to_command_history = false;
auto entry = header_out.keyval().find(opt[n][0]);
if (entry == header_out.keyval().end()) {
Expand All @@ -440,14 +440,14 @@ void run() {

opt = get_options("set_property");
for (size_t n = 0; n < opt.size(); ++n) {
if (str(opt[n][0]) == "command_history")
if (std::string(opt[n][0]) == "command_history")
add_to_command_history = false;
header_out.keyval()[std::string(opt[n][0])] = std::string(opt[n][1]);
}

opt = get_options("append_property");
for (size_t n = 0; n < opt.size(); ++n) {
if (str(opt[n][0]) == "command_history")
if (std::string(opt[n][0]) == "command_history")
add_to_command_history = false;
add_line(header_out.keyval()[std::string(opt[n][0])], std::string(opt[n][1]));
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/cmd/mrgrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ void run() {
const size_t axis = opt[i][0];
if (axis >= input_header.ndim())
throw Exception("-axis {} larger than image dimensions ({})", axis, input_header.ndim());
std::string spec = str(opt[i][1]);
std::string spec = std::string(opt[i][1]);
std::string::size_type start = 0, end;
end = spec.find_first_of(":", start);
if (end == std::string::npos) { // spec = delta_lower,delta_upper
Expand Down
4 changes: 2 additions & 2 deletions cpp/cmd/mrhistmatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ void match_linear(Image<float> &input,
Header H(input);
H.datatype() = DataType::Float32;
H.datatype().set_byte_order_native();
H.keyval()["mrhistmatch_scale"] = str<float>(parameters[0]);
H.keyval()["mrhistmatch_scale"] = fmt::format("{}", static_cast<float>(parameters[0]));
if (estimate_intercept) {
CONSOLE("Estimated linear transform is: {}x + {}", parameters[0], parameters[1]);
H.keyval()["mrhistmatch_offset"] = str<float>(parameters[1]);
H.keyval()["mrhistmatch_offset"] = fmt::format("{}", static_cast<float>(parameters[1]));
auto output = Image<float>::create(output_path, H);
for (auto l = Loop("Writing output image data", input)(input, output); l; ++l) {
if (std::isfinite(static_cast<float>(input.value()))) {
Expand Down
8 changes: 4 additions & 4 deletions cpp/cmd/mrinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void print_dimensions(const Header &header) {
for (size_t i = 0; i < header.ndim(); ++i) {
if (i)
buffer += " ";
buffer += str(header.size(i));
buffer += fmt::format("{}", header.size(i));
}
std::cout << buffer << "\n";
}
Expand All @@ -181,7 +181,7 @@ void print_spacing(const Header &header) {
for (size_t i = 0; i < header.ndim(); ++i) {
if (i)
buffer += " ";
buffer += str(header.spacing(i));
buffer += fmt::format("{}", header.spacing(i));
}
std::cout << buffer << "\n";
}
Expand All @@ -193,7 +193,7 @@ void print_strides(const Header &header) {
for (size_t i = 0; i < header.ndim(); ++i) {
if (i)
buffer += " ";
buffer += strides[i] == 0 ? "?" : str(strides[i]);
buffer += strides[i] == 0 ? "?" : fmt::format("{}", strides[i]);
}
std::cout << buffer << "\n";
}
Expand All @@ -215,7 +215,7 @@ void print_shells(const Eigen::MatrixXd &grad,
}
if (shell_indices) {
for (size_t i = 0; i < dwshells.count(); i++)
std::cout << join(dwshells[i].get_volumes(), ",") + " ";
std::cout << fmt::format("{}", fmt::join(dwshells[i].get_volumes(), ",")) + " ";
std::cout << "\n";
}
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/cmd/mrmetric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,9 @@ void run() {

if (normalisation)
sos.array() /= static_cast<value_type>(n_voxels);
std::cout << str(sos.transpose());
std::cout << fmt::format("{}", sos.transpose());

if (!get_options("overlap").empty())
std::cout << " " << str(n_voxels);
std::cout << " " << fmt::format("{}", n_voxels);
std::cout << std::endl;
}
40 changes: 23 additions & 17 deletions cpp/cmd/mrstats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ void usage() {
using value_type = Stats::value_type;
using complex_type = Stats::complex_type;

class Volume_loop {
template <typename T> class Volume_loop {
public:
Volume_loop(Image<complex_type> &in) : image(in), is_4D(in.ndim() == 4), status(true) {
Volume_loop(Image<T> &in) : image(in), is_4D(in.ndim() == 4), status(true) {
if (is_4D)
image.index(3) = 0;
}
Expand All @@ -76,12 +76,12 @@ class Volume_loop {
}

private:
Image<complex_type> &image;
Image<T> &image;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member 'image' of type 'Image &' is a reference [cppcoreguidelines-avoid-const-or-ref-data-members]

  Image<T> &image;
            ^

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member 'image' of type 'Image<complex> &' is a reference [cppcoreguidelines-avoid-const-or-ref-data-members]

  Image<T> &image;
            ^

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member 'image' of type 'Image &' is a reference [cppcoreguidelines-avoid-const-or-ref-data-members]

  Image<T> &image;
            ^

const bool is_4D;
bool status;
};

void run_volume(Stats::Stats &stats, Image<complex_type> &data, Image<bool> &mask) {
template <typename T> void run_volume(Stats::Stats<T> &stats, Image<T> &data, Image<bool> &mask) {
if (mask.valid()) {
for (auto l = Loop(0, 3)(data, mask); l; ++l) {
if (mask.value())
Expand All @@ -93,12 +93,8 @@ void run_volume(Stats::Stats &stats, Image<complex_type> &data, Image<bool> &mas
}
}

void run() {
auto header = Header::open(argument[0]);
if (header.ndim() > 4)
throw Exception("mrstats is not designed to handle images greater than 4D");
const bool is_complex = header.datatype().is_complex();
auto data = header.get_image<complex_type>();
template <typename T> void run_impl(Header &header) {
auto data = header.get_image<T>();
const bool ignorezero = !get_options("ignorezero").empty();

auto opt = get_options("mask");
Expand All @@ -114,18 +110,28 @@ void run() {
fields.push_back(opt[n][0]);

if (App::log_level && fields.empty())
Stats::print_header(is_complex);
Stats::print_header<T>();

if (get_options("allvolumes").empty()) {
for (auto i = Volume_loop(data); i; ++i) {
Stats::Stats stats(is_complex, ignorezero);
run_volume(stats, data, mask);
for (auto i = Volume_loop<T>(data); i; ++i) {
Stats::Stats<T> stats(ignorezero);
run_volume<T>(stats, data, mask);
stats.print(data, fields);
}
} else {
Stats::Stats stats(is_complex, ignorezero);
for (auto i = Volume_loop(data); i; ++i)
run_volume(stats, data, mask);
Stats::Stats<T> stats(ignorezero);
for (auto i = Volume_loop<T>(data); i; ++i)
run_volume<T>(stats, data, mask);
stats.print(data, fields);
}
}

void run() {
auto header = Header::open(argument[0]);
if (header.ndim() > 4)
throw Exception("mrstats is not designed to handle images greater than 4D");
if (header.datatype().is_complex())
run_impl<complex_type>(header);
else
run_impl<value_type>(header);
}
4 changes: 2 additions & 2 deletions cpp/cmd/mtnormalise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,9 @@ void write_output(const std::filesystem::path &original,
auto in = ImageType::open(original);
Header header(in);
header.datatype() = DataType::Float32;
header.keyval()["lognorm_scale"] = str(lognorm_scale);
header.keyval()["lognorm_scale"] = fmt::format("{}", lognorm_scale);
if (output_balanced)
header.keyval()["lognorm_balance"] = str(balance_factor);
header.keyval()["lognorm_balance"] = fmt::format("{}", balance_factor);
else
balance_factor = 1.0;
auto out = ImageType::create(corrected, header);
Expand Down
2 changes: 1 addition & 1 deletion cpp/cmd/peaks2fixel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void run() {
index_header.datatype() = DataType::UInt32;
index_header.datatype().set_byte_order_native();
index_header.size(3) = 2;
index_header.keyval()[Fixel::n_fixels_key] = str(nfixels);
index_header.keyval()[Fixel::n_fixels_key] = fmt::format("{}", nfixels);
auto index_image = Image<uint32_t>::create(index_path, index_header);

Header directions_header = Fixel::directions_header_from_index(index_header);
Expand Down
Loading
Loading