Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cpp/cmd/mraverageheader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
*/

#include "algo/loop.h"
#include "app.h"
#include "command.h"
#include "debug.h"
#include "enum.h"
#include "image.h"
#include "interp/nearest.h"
#include "math/average_space.h"
Expand Down Expand Up @@ -62,9 +64,9 @@ void usage() {
"Method for determination of voxel spacings based on"
" the set of input images and the average header axes"
" (see Description)."
" Valid options are: " + join(avgspace_voxspacing_choices, ",") + ";"
" Valid options are: " + MR::Enum::join<avgspace_voxspacing_t>(",") + ";"
" default = " + SPACING_DEFAULT_STRING)
+ Argument("type").type_choice(avgspace_voxspacing_choices)
+ Argument("type").type_choice<avgspace_voxspacing_t>()
+ Option ("fill", "set the intensity in the first volume of the average space to 1")
+ DataType::options();

Expand All @@ -80,9 +82,7 @@ void run() {
const default_type p = get_option_value("padding", PADDING_DEFAULT);
auto padding = Eigen::Matrix<default_type, 4, 1>(p, p, p, 1.0);
INFO("padding in template voxels: " + str(padding.transpose().head<3>()));
auto opt = get_options("spacing");
const avgspace_voxspacing_t spacing =
opt.empty() ? SPACING_DEFAULT_VALUE : static_cast<avgspace_voxspacing_t>(static_cast<int>(opt[0][0]));
const avgspace_voxspacing_t spacing = get_option_choice<avgspace_voxspacing_t>("spacing", SPACING_DEFAULT_VALUE);
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: no header providing "MR::App::get_option_choice" is directly included [misc-include-cleaner]

  const avgspace_voxspacing_t spacing = get_option_choice<avgspace_voxspacing_t>("spacing", SPACING_DEFAULT_VALUE);
                                        ^

const bool fill = !get_options("fill").empty();

std::vector<Header> headers_in;
Expand Down
15 changes: 6 additions & 9 deletions cpp/cmd/mrcolour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "command.h"
#include "datatype.h"
#include "enum.h"
#include "header.h"
#include "image.h"
#include "mrtrix.h"
Expand All @@ -29,16 +30,9 @@
using namespace MR;
using namespace App;

std::vector<std::string> colourmap_choices;

// clang-format off
void usage() {

for (const auto& entry : ColourMap::maps) {
if (entry.name != "Complex")
colourmap_choices.push_back(lowercase(entry.name));
}

AUTHOR = "Robert E. Smith (robert.smith@florey.edu.au)";

SYNOPSIS = "Apply a colour map to an image";
Expand All @@ -60,7 +54,7 @@ void usage() {
ARGUMENTS
+ Argument ("input", "the input image").type_image_in()
+ Argument ("map", "the colourmap to apply;"
" choices are: " + join(colourmap_choices, ",")).type_choice (colourmap_choices)
" choices are: " + MR::Enum::join<ColourMap::Choice>(",")).type_choice<ColourMap::Choice>()
+ Argument ("output", "the output image").type_image_out();

OPTIONS
Expand All @@ -79,7 +73,10 @@ void usage() {

void run() {
Header H_in = Header::open(argument[0]);
const ColourMap::Entry colourmap = ColourMap::maps[argument[1]];
// Resolve the selected colour map by name rather than by integer index,
// so the ColourMap::Choice enumeration need not be kept in lock-step with the maps table.
const ColourMap::Entry colourmap =
ColourMap::maps[ColourMap::index(MR::Enum::name(MR::Enum::from_name<ColourMap::Choice>(argument[1])))];
Eigen::Vector3d fixed_colour(Eigen::Vector3d::Constant(NaN));
if (colourmap.is_colour) {
if (!(H_in.ndim() == 3 || (H_in.ndim() == 4 && H_in.size(3) == 1)))
Expand Down
10 changes: 5 additions & 5 deletions cpp/cmd/mrgrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "adapter/regrid.h"
#include "algo/copy.h"
#include "app.h"
#include "command.h"
#include "enum.h"
#include "filter/resize.h"
Expand Down Expand Up @@ -131,9 +132,9 @@ void usage() {
+ Argument ("factor").type_sequence_float()

+ Option ("interp", std::string("set the interpolation method to use when reslicing")
+ " (choices: " + join(MR::Interp::interp_choices, ", ") + ";"
" default: " + MR::Interp::interp_choices[static_cast<ssize_t>(default_interp)] + ").")
+ Argument ("method").type_choice (MR::Interp::interp_choices)
+ " (choices: " + MR::Enum::join<MR::Interp::interp_type>() + ";"
" default: " + MR::Enum::lowercase_name(default_interp) + ").")
+ Argument ("method").type_choice<MR::Interp::interp_type>()

+ Option ("oversample",
"set the amount of over-sampling (in the target space) to perform when regridding."
Expand Down Expand Up @@ -221,8 +222,7 @@ void run() {
regrid_filter.set_out_of_bounds_value(out_of_bounds_value);
size_t resize_option_count = 0;
size_t template_option_count = 0;
const MR::Interp::interp_type interp =
MR::Interp::interp_type(get_option_value("interp", static_cast<ssize_t>(default_interp)));
const MR::Interp::interp_type interp = get_option_choice<MR::Interp::interp_type>("interp", default_interp);
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: no header providing "MR::App::get_option_choice" is directly included [misc-include-cleaner]

    const MR::Interp::interp_type interp = get_option_choice<MR::Interp::interp_type>("interp", default_interp);
                                           ^


// over-sampling
std::vector<uint32_t> oversample = Adapter::AutoOverSample;
Expand Down
10 changes: 5 additions & 5 deletions cpp/cmd/mrmetric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "algo/loop.h"
#include "algo/threaded_loop.h"
#include "app.h"
#include "command.h"
#include "enum.h"
#include "image.h"
Expand Down Expand Up @@ -199,9 +200,9 @@ void usage() {
+ Argument ("iteration method").type_choice<space_t>()

+ Option ("interp", std::string("set the interpolation method to use when reslicing") +
" (choices: nearest, linear, cubic, sinc."
" Default: " + MR::Interp::interp_choices[static_cast<ssize_t>(default_interp)] + ").")
+ Argument ("method").type_choice(MR::Interp::interp_choices)
" (choices: " + MR::Enum::join<MR::Interp::interp_type>() + "."
" Default: " + MR::Enum::lowercase_name(default_interp) + ").")
+ Argument ("method").type_choice<MR::Interp::interp_type>()

+ Option ("metric",
"define the dissimilarity metric used to calculate the cost."
Expand Down Expand Up @@ -231,8 +232,7 @@ using MaskType = Image<bool>;

void run() {
const space_t space = get_option_choice<space_t>("space", default_space);
const MR::Interp::interp_type interp =
MR::Interp::interp_type(get_option_value<ssize_t>("interp", static_cast<ssize_t>(default_interp)));
const MR::Interp::interp_type interp = get_option_choice<MR::Interp::interp_type>("interp", default_interp);
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: no header providing "MR::App::get_option_choice" is directly included [misc-include-cleaner]

  const MR::Interp::interp_type interp = get_option_choice<MR::Interp::interp_type>("interp", default_interp);
                                         ^


MetricType metric_type = MetricType::MeanSquared;
const MetricChoice metric_choice = get_option_choice<MetricChoice>("metric", MetricChoice::DIFF);
Expand Down
78 changes: 15 additions & 63 deletions cpp/cmd/mrregister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <filesystem>
#include <optional>

#include "app.h"
#include "command.h"
#include "dwi/directions/predefined.h"
#include "dwi/directions/validate.h"
Expand Down Expand Up @@ -402,12 +403,14 @@ void run() {
if (!opt.empty()) {
if (init_rigid_matrix_set)
throw Exception("options -rigid_init_matrix and -rigid_init_translation are mutually exclusive");
Registration::set_init_translation_model_from_option(rigid_registration, static_cast<int>(opt[0][0]));
Registration::set_init_translation_model_from_option(
rigid_registration, MR::Enum::from_name<Registration::init_translation_t>(opt[0][0]));
}

opt = get_options("rigid_init_rotation");
if (!opt.empty())
Registration::set_init_rotation_model_from_option(rigid_registration, static_cast<int>(opt[0][0]));
Registration::set_init_rotation_model_from_option(rigid_registration,
MR::Enum::from_name<Registration::init_rotation_t>(opt[0][0]));

opt = get_options("rigid_scale");
if (!opt.empty()) {
Expand All @@ -430,20 +433,8 @@ void run() {
rigid_registration.set_max_iter(parse_ints<uint32_t>(opt[0][0]));
}

opt = get_options("rigid_metric");
Registration::LinearMetricType rigid_metric = Registration::Diff;
if (!opt.empty()) {
switch (static_cast<int>(opt[0][0])) {
case 0:
rigid_metric = Registration::Diff;
break;
case 1:
rigid_metric = Registration::NCC;
break;
default:
break;
}
}
const Registration::LinearMetricType rigid_metric =
get_option_choice<Registration::LinearMetricType>("rigid_metric", Registration::Diff);
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: no header providing "MR::App::get_option_choice" is directly included [misc-include-cleaner]

      get_option_choice<Registration::LinearMetricType>("rigid_metric", Registration::Diff);
      ^


if (rigid_metric == Registration::NCC)
throw Exception("TODO: cross correlation metric not yet implemented");
Expand All @@ -453,21 +444,7 @@ void run() {
if (!opt.empty()) {
if (rigid_metric != Registration::Diff)
throw Exception("rigid_metric.diff.estimator set but cost function is not diff.");
switch (static_cast<int>(opt[0][0])) {
case 0:
rigid_estimator = Registration::L1;
break;
case 1:
rigid_estimator = Registration::L2;
break;
case 2:
rigid_estimator = Registration::LP;
break;
case 3:
rigid_estimator = Registration::None;
default:
assert(false);
}
rigid_estimator = MR::Enum::from_name<Registration::LinearRobustMetricEstimatorType>(opt[0][0]);
}

opt = get_options("rigid_lmax");
Expand Down Expand Up @@ -534,14 +511,16 @@ void run() {
if (!opt.empty()) {
if (init_affine_matrix_set)
throw Exception("options -affine_init_matrix and -affine_init_translation are mutually exclusive");
Registration::set_init_translation_model_from_option(affine_registration, static_cast<int>(opt[0][0]));
Registration::set_init_translation_model_from_option(
affine_registration, MR::Enum::from_name<Registration::init_translation_t>(opt[0][0]));
}

opt = get_options("affine_init_rotation");
if (!opt.empty()) {
if (init_affine_matrix_set)
throw Exception("options -affine_init_matrix and -affine_init_rotation are mutually exclusive");
Registration::set_init_rotation_model_from_option(affine_registration, static_cast<int>(opt[0][0]));
Registration::set_init_rotation_model_from_option(affine_registration,
MR::Enum::from_name<Registration::init_rotation_t>(opt[0][0]));
}

opt = get_options("affine_scale");
Expand All @@ -558,20 +537,8 @@ void run() {
affine_registration.set_loop_density(parse_floats(opt[0][0]));
}

opt = get_options("affine_metric");
Registration::LinearMetricType affine_metric = Registration::Diff;
if (!opt.empty()) {
switch (static_cast<int>(opt[0][0])) {
case 0:
affine_metric = Registration::Diff;
break;
case 1:
affine_metric = Registration::NCC;
break;
default:
break;
}
}
const Registration::LinearMetricType affine_metric =
get_option_choice<Registration::LinearMetricType>("affine_metric", Registration::Diff);

if (affine_metric == Registration::NCC)
throw Exception("TODO cross correlation metric not yet implemented");
Expand All @@ -581,22 +548,7 @@ void run() {
if (!opt.empty()) {
if (affine_metric != Registration::Diff)
throw Exception("affine_metric.diff.estimator set but cost function is not diff.");
switch (static_cast<int>(opt[0][0])) {
case 0:
affine_estimator = Registration::L1;
break;
case 1:
affine_estimator = Registration::L2;
break;
case 2:
affine_estimator = Registration::LP;
break;
case 3:
affine_estimator = Registration::None;
break;
default:
assert(false);
}
affine_estimator = MR::Enum::from_name<Registration::LinearRobustMetricEstimatorType>(opt[0][0]);
}

opt = get_options("affine_niter");
Expand Down
7 changes: 5 additions & 2 deletions cpp/cmd/mrstats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
*/

#include <iomanip>
#include <vector>

#include "command.h"
#include "datatype.h"
#include "enum.h"
#include "image.h"
#include "image_helpers.h"
#include "memory.h"
Expand Down Expand Up @@ -108,10 +110,11 @@ void run() {
check_dimensions(mask, header, 0, 3);
}

std::vector<std::string> fields;
std::vector<Stats::field_t> fields;
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: no header providing "std::vector" is directly included [misc-include-cleaner]

cpp/cmd/mrstats.cpp:17:

+ #include <vector>

opt = get_options("output");
fields.reserve(opt.size());
for (size_t n = 0; n < opt.size(); ++n)
fields.push_back(opt[n][0]);
fields.push_back(MR::Enum::from_name<Stats::field_t>(opt[n][0]));
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: 'push_back' is called inside a loop; consider pre-allocating the container capacity before the loop [performance-inefficient-vector-operation]

cpp/cmd/mrstats.cpp:113:

-   for (size_t n = 0; n < opt.size(); ++n)
+   fields.reserve(opt.size());
+ for (size_t n = 0; n < opt.size(); ++n)


if (App::log_level && fields.empty())
Stats::print_header(is_complex);
Expand Down
18 changes: 8 additions & 10 deletions cpp/cmd/mrtransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
#include "algo/copy.h"
#include "algo/loop.h"
#include "algo/threaded_copy.h"
#include "app.h"
#include "command.h"
#include "debug.h"
#include "dwi/directions/predefined.h"
#include "dwi/directions/validate.h"
#include "dwi/gradient.h"
#include "enum.h"
#include "file/matrix.h"
#include "file/nifti_utils.h"
#include "filter/reslice.h"
Expand Down Expand Up @@ -156,9 +158,9 @@ void usage() {

+ Option ("interp",
std::string("set the interpolation method to use when reslicing")
+ " (choices: " + join(MR::Interp::interp_choices, ", ") + ";"
+ " default: " + MR::Interp::interp_choices[static_cast<ssize_t>(default_interp)] + ").")
+ Argument ("method").type_choice(MR::Interp::interp_choices)
+ " (choices: " + MR::Enum::join<MR::Interp::interp_type>() + ";"
+ " default: " + MR::Enum::lowercase_name(default_interp) + ").")
+ Argument ("method").type_choice<MR::Interp::interp_type>()

+ Option ("oversample",
"set the amount of over-sampling (in the target space) to perform when regridding."
Expand Down Expand Up @@ -584,13 +586,9 @@ void run() {
}

// Interpolator
MR::Interp::interp_type interp = default_interp;
opt = get_options("interp");
if (!opt.empty()) {
interp = MR::Interp::interp_type(static_cast<MR::App::ParsedArgument::IntType>(opt[0][0]));
if (!warp && !template_header)
WARN("interpolator choice ignored since the input image will not be regridded");
}
const MR::Interp::interp_type interp = get_option_choice<MR::Interp::interp_type>("interp", default_interp);
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: no header providing "MR::App::get_option_choice" is directly included [misc-include-cleaner]

  const MR::Interp::interp_type interp = get_option_choice<MR::Interp::interp_type>("interp", default_interp);
                                         ^

if (!get_options("interp").empty() && !warp && !template_header)
WARN("interpolator choice ignored since the input image will not be regridded");

// over-sampling
std::vector<uint32_t> oversample = Adapter::AutoOverSample;
Expand Down
7 changes: 3 additions & 4 deletions cpp/cmd/tck2connectome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include <set>

#include "app.h"
#include "command.h"
#include "image.h"
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: included header enum.h is not used directly [misc-include-cleaner]

Suggested change
#include "image.h"
#include "image.h"

#include "thread_queue.h"
Expand Down Expand Up @@ -154,9 +155,7 @@ void execute(Image<node_t> &node_image, const node_t max_node_index, const std::
Metric metric;
Tractography::Connectome::setup_metric(metric, node_image);
std::unique_ptr<Tck2nodes_base> tck2nodes(load_assignment_mode(node_image));
auto opt = get_options("stat_edge");
const stat_edge statistic =
!opt.empty() ? stat_edge(static_cast<MR::App::ParsedArgument::IntType>(opt[0][0])) : stat_edge::SUM;
const stat_edge statistic = get_option_choice<stat_edge>("stat_edge", stat_edge::SUM);
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: no header providing "MR::App::get_option_choice" is directly included [misc-include-cleaner]

  const stat_edge statistic = get_option_choice<stat_edge>("stat_edge", stat_edge::SUM);
                              ^


// Prepare for reading the track data
Tractography::Properties properties;
Expand Down Expand Up @@ -191,7 +190,7 @@ void execute(Image<node_t> &node_image, const node_t max_node_index, const std::
get_options("symmetric").size(),
get_options("zero_diagonal").size());

opt = get_options("out_assignments");
auto opt = get_options("out_assignments");
if (!opt.empty())
connectome.write_assignments(opt[0][0]);
}
Expand Down
Loading
Loading