Skip to content

Commit

Permalink
Add Header::ndim() assignment proxy
Browse files Browse the repository at this point in the history
As discussed on MRtrix3#697.
  • Loading branch information
jdtournier committed Jul 1, 2016
1 parent 01c8f96 commit 888105d
Show file tree
Hide file tree
Showing 69 changed files with 134 additions and 118 deletions.
2 changes: 1 addition & 1 deletion cmd/5tt2gmwmi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void run ()
H.datatype().set_byte_order_native();
} else {
H = input;
H.set_ndim (3);
H.ndim() = 3;
}
auto output = Image<float>::create (argument[1], H);

Expand Down
2 changes: 1 addition & 1 deletion cmd/5tt2vis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void run ()
DWI::Tractography::ACT::verify_5TT_image (input);

Header H (input);
H.set_ndim (3);
H.ndim() = 3;

const float bg_multiplier = get_option_value ("bg", VALUE_DEFAULT_BG);
const float cgm_multiplier = get_option_value ("cgm", VALUE_DEFAULT_CGM);
Expand Down
2 changes: 1 addition & 1 deletion cmd/dwi2adc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void run () {

Header header (dwi);
header.datatype() = DataType::Float32;
header.set_ndim (4);
header.ndim() = 4;
header.size(3) = 2;

auto adc = Image<value_type>::create (argument[1], header);
Expand Down
2 changes: 1 addition & 1 deletion cmd/dwi2fod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ void run ()

auto header_in = Header::open (argument[1]);
Header header_out (header_in);
header_out.set_ndim (4);
header_out.ndim() = 4;
header_out.datatype() = DataType::Float32;
header_out.datatype().set_byte_order_native();
Stride::set_from_command_line (header_out, Stride::contiguous_along_axis (3, header_in));
Expand Down
2 changes: 1 addition & 1 deletion cmd/dwi2noise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void run ()
auto dwi_in = Image<value_type>::open (argument[0]);

auto header = Header (dwi_in);
header.set_ndim (3);
header.ndim() = 3;
header.datatype() = DataType::Float32;
auto noise = Image<value_type>::create (argument[1], header);

Expand Down
6 changes: 3 additions & 3 deletions cmd/dwi2tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void run ()

Header header (dwi);
header.datatype() = DataType::Float32;
header.set_ndim (4);
header.ndim() = 4;

Image<value_type>* predict = nullptr;
opt = get_options ("predicted_signal");
Expand All @@ -194,14 +194,14 @@ void run ()
Image<value_type>* b0 = nullptr;
opt = get_options ("b0");
if (opt.size()) {
header.set_ndim (3);
header.ndim() = 3;
b0 = new Image<value_type> (Image<value_type>::create (opt[0][0], header));
}

Image<value_type>* dkt = nullptr;
opt = get_options ("dkt");
if (opt.size()) {
header.set_ndim (4);
header.ndim() = 4;
header.size(3) = 15;
dkt = new Image<value_type> (Image<value_type>::create (opt[0][0], header));
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/dwidenoise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ void run ()
Image<value_type> noise;
opt = get_options("noise");
if (opt.size()) {
header.set_ndim(3);
header.ndim() = 3;
noise = Image<value_type>::create (opt[0][0], header);
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/fixel2sh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void run ()
H_out.datatype() = DataType::Float32;
H_out.datatype().set_byte_order_native();
const size_t sh_dim = H_in.ndim();
H_out.set_ndim (H_in.ndim() + 1);
H_out.ndim() = H_in.ndim() + 1;
H_out.size (sh_dim) = N;

auto sh = Image<float>::create (argument[1], H_out);
Expand Down
4 changes: 2 additions & 2 deletions cmd/fixel2voxel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,10 +655,10 @@ void run ()
if (op == 10) { // count
H_out.datatype() = DataType::UInt8;
} else if (op == 13 || op == 14) { // dec
H_out.set_ndim (4);
H_out.ndim() = 4;
H_out.size (3) = 3;
} else if (op == 15 || op == 16 || op == 17) { // split_*
H_out.set_ndim (4);
H_out.ndim() = 4;
uint32_t max_count = 0;
for (auto l = Loop ("determining largest fixel count", in) (in); l; ++l)
max_count = std::max (max_count, in.value().size());
Expand Down
2 changes: 1 addition & 1 deletion cmd/fixelcfestats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ void run() {

// Create an image to store the fixel indices, if we had a fixel scratch buffer this would be cleaner
Header index_header (input_header);
index_header.set_ndim(4);
index_header.ndim() = 4;
index_header.size(3) = 2;
auto fixel_index_image = Image<int32_t>::scratch (index_header);
for (auto i = Loop ()(fixel_index_image);i; ++i)
Expand Down
4 changes: 2 additions & 2 deletions cmd/fod2dec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ void run () {
auto fod_img = fod_hdr.get_image<value_type>().with_direct_io(3);

auto dec_hdr = Header(fod_img);
dec_hdr.set_ndim(4);
dec_hdr.ndim() = 4;
dec_hdr.size(3) = 3;
Stride::set (dec_hdr, Stride::contiguous_along_axis (3, dec_hdr));
dec_img = Image<value_type>::scratch(dec_hdr,"DEC map");
Expand All @@ -284,7 +284,7 @@ void run () {

auto out_hdr = map_hdr.valid() ? Header(map_hdr) : Header(dec_img);
out_hdr.datatype() = DataType::Float32;
out_hdr.set_ndim(4);
out_hdr.ndim() = 4;
out_hdr.size(3) = 3;
Stride::set (out_hdr, Stride::contiguous_along_axis (3, out_hdr));
out_img = Image<value_type>::create(argument[1],out_hdr);
Expand Down
2 changes: 1 addition & 1 deletion cmd/fod2fixel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class Segmented_FOD_receiver
Segmented_FOD_receiver (const Header& header) :
H (header)
{
H.set_ndim (3);
H.ndim() = 3;
H.datatype() = DataType::UInt64;
H.datatype().set_byte_order_native();
H.keyval()[Sparse::name_key] = str(typeid(FixelMetric).name());
Expand Down
2 changes: 1 addition & 1 deletion cmd/label2colour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void run ()
}
}

H.set_ndim (4);
H.ndim() = 4;
H.size (3) = 3;
H.datatype() = DataType::UInt8;
add_line (H.keyval()["comments"], "Coloured parcellation image generated by label2colour");
Expand Down
2 changes: 1 addition & 1 deletion cmd/mraverageheader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void run ()
auto H = compute_minimum_average_header (headers_in, resolution, padding, transform_header_with);
H.datatype() = DataType::Bit;
if (fill) {
H.set_ndim(dim);
H.ndim() = dim;
if (dim == 4)
H.size(3) = headers_in.back().size(3);
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/mrcalc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,8 @@ void get_header (const StackEntry& entry, Header& header)
}

if (header.ndim() < entry.image->ndim())
header.set_ndim (entry.image->ndim());
for (size_t n = 0; n < std::min (header.ndim(), entry.image->ndim()); ++n) {
header.ndim() = entry.image->ndim();
for (size_t n = 0; n < std::min<size_t> (header.ndim(), entry.image->ndim()); ++n) {
if (header.size(n) > 1 && entry.image->size(n) > 1 && header.size(n) != entry.image->size(n))
throw Exception ("dimensions of input images do not match - aborting");
header.size(n) = std::max (header.size(n), entry.image->size(n));
Expand Down
4 changes: 2 additions & 2 deletions cmd/mrcat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void run () {
if (axis >= ndims) ndims = axis+1;

Header header_out (in[0]);
header_out.set_ndim (ndims);
header_out.ndim() = ndims;

for (size_t i = 0; i < header_out.ndim(); i++) {
if (header_out.size (i) <= 1) {
Expand Down Expand Up @@ -152,7 +152,7 @@ void run () {
out.value() = in.value();
};

ThreadedLoop ("concatenating \"" + image_in.name() + "\"...", image_in, 0, std::min (image_in.ndim(), image_out.ndim()))
ThreadedLoop ("concatenating \"" + image_in.name() + "\"...", image_in, 0, std::min<size_t> (image_in.ndim(), image_out.ndim()))
.run (copy_func, image_in, image_out);
if (axis < int(image_in.ndim()))
axis_offset += image_in.size (axis);
Expand Down
6 changes: 3 additions & 3 deletions cmd/mrconvert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void permute_DW_scheme (Header& H, const std::vector<int>& axes)
template <class ImageType>
inline std::vector<int> set_header (Header& header, const ImageType& input)
{
header.set_ndim (input.ndim());
header.ndim() = input.ndim();
for (size_t n = 0; n < header.ndim(); ++n) {
header.size(n) = input.size(n);
header.spacing(n) = input.spacing(n);
Expand All @@ -126,15 +126,15 @@ inline std::vector<int> set_header (Header& header, const ImageType& input)
std::vector<int> axes;
if (opt.size()) {
axes = opt[0][0];
header.set_ndim (axes.size());
header.ndim() = axes.size();
for (size_t i = 0; i < axes.size(); ++i) {
if (axes[i] >= static_cast<int> (input.ndim()))
throw Exception ("axis supplied to option -axes is out of bounds");
header.size(i) = axes[i] < 0 ? 1 : input.size (axes[i]);
}
permute_DW_scheme (header, axes);
} else {
header.set_ndim (input.ndim());
header.ndim() = input.ndim();
axes.assign (input.ndim(), 0);
for (size_t i = 0; i < axes.size(); ++i) {
axes[i] = i;
Expand Down
2 changes: 1 addition & 1 deletion cmd/mrmath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ void run ()

// Wipe any excess unary-dimensional axes
while (header.size (header.ndim() - 1) == 1)
header.set_ndim (header.ndim() - 1);
header.ndim() = header.ndim() - 1;

// Verify that dimensions of all input images adequately match
for (size_t i = 1; i != num_inputs; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/mrmetric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ void run ()
output2mask = Header::scratch (midway_image_header, "-").get_image<bool>();

Header new_header;
new_header.set_ndim(input1.ndim());
new_header.ndim() = input1.ndim();
for (ssize_t dim=0; dim < 3; ++dim){
new_header.size(dim) = midway_image_header.size(dim);
new_header.spacing(dim) = midway_image_header.spacing(dim);
Expand Down
8 changes: 4 additions & 4 deletions cmd/mrregister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ void run ()

if (warp1_filename.size()) {
Header output_header (im2_image);
output_header.set_ndim(4);
output_header.ndim() = 4;
output_header.size(3) =3;
nl_registration.write_params_to_header (output_header);
output_header.datatype() = DataType::from_command_line (DataType::Float32);
Expand All @@ -800,7 +800,7 @@ void run ()

if (warp2_filename.size()) {
Header output_header (im1_image);
output_header.set_ndim(4);
output_header.ndim() = 4;
output_header.size(3) = 3;
nl_registration.write_params_to_header (output_header);
output_header.datatype() = DataType::from_command_line (DataType::Float32);
Expand All @@ -819,7 +819,7 @@ void run ()

if (do_nonlinear) {
Header deform_header (im1_transformed);
deform_header.set_ndim(4);
deform_header.ndim() = 4;
deform_header.size(3) = 3;
Image<default_type> deform_field = Image<default_type>::scratch (deform_header);
Registration::Warp::compute_full_deformation (nl_registration.get_im2_to_mid_linear().inverse(),
Expand Down Expand Up @@ -859,7 +859,7 @@ void run ()
if (do_nonlinear) {
Header midway_header (*nl_registration.get_im1_to_mid());
midway_header.datatype() = DataType::from_command_line (DataType::Float32);
midway_header.set_ndim (im1_image.ndim());
midway_header.ndim() = im1_image.ndim();
if (midway_header.ndim() == 4)
midway_header.size(3) = im1_image.size(3);

Expand Down
2 changes: 1 addition & 1 deletion cmd/sh2power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void run () {
if (spectrum)
power_header.size (3) = 1 + lmax/2;
else
power_header.set_ndim(3);
power_header.ndim() = 3;
power_header.datatype() = DataType::Float32;

auto power_data = Image<float>::create(argument[1], power_header);
Expand Down
2 changes: 1 addition & 1 deletion cmd/shbasis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void check_and_update (Header& H, const conv_t conversion)

// Need to mask out voxels where the DC term is zero
Header header_mask (H);
header_mask.set_ndim (3);
header_mask.ndim() = 3;
header_mask.datatype() = DataType::Bit;
auto mask = Image<bool>::scratch (header_mask);
size_t voxel_count = 0;
Expand Down
2 changes: 1 addition & 1 deletion cmd/tckglobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ void run ()
opt = get_options("eext");
if (opt.size()) {
INFO("Saving external energy to file");
header.set_ndim(3);
header.ndim() = 3;
auto EextI = Image<float>::create (opt[0][0], header);
threaded_copy(Eext->getEext(), EextI);
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/tckmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ void run () {
}

if (header.ndim() > 3) {
header.set_ndim (3);
header.ndim() = 3;
header.sanitise();
}

Expand Down Expand Up @@ -328,7 +328,7 @@ void run () {
opt = get_options ("dec");
if (opt.size()) {
writer_type = DEC;
header.set_ndim (4);
header.ndim() = 4;
header.size (3) = 3;
header.sanitise();
Stride::set (header, Stride::contiguous_along_axis (3, header));
Expand All @@ -344,7 +344,7 @@ void run () {
dirs.reset (new DWI::Directions::FastLookupSet (str(opt[0][0])));
else
dirs.reset (new DWI::Directions::FastLookupSet (to<size_t>(opt[0][0])));
header.set_ndim (4);
header.ndim() = 4;
header.size(3) = dirs->size();
header.sanitise();
Stride::set (header, Stride::contiguous_along_axis (3, header));
Expand All @@ -367,7 +367,7 @@ void run () {
const size_t lmax = opt[0][0];
if (lmax % 2)
throw Exception ("lmax for TODI must be an even number");
header.set_ndim (4);
header.ndim() = 4;
header.size(3) = Math::SH::NforL (lmax);
header.sanitise();
Stride::set (header, Stride::contiguous_along_axis (3, header));
Expand Down
Loading

0 comments on commit 888105d

Please sign in to comment.