Skip to content

Commit

Permalink
Replace MR::make_unique/shared with std::make_unique/shared
Browse files Browse the repository at this point in the history
  • Loading branch information
MRtrixBot committed Nov 30, 2023
1 parent ed54822 commit bf33a98
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 44 deletions.
13 changes: 7 additions & 6 deletions cmd/fod2fixel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void Segmented_FOD_receiver::commit() {
index_header.size(3) = 2;
index_header.datatype() = DataType::from<index_type>();
index_header.datatype().set_byte_order_native();
index_image = make_unique<IndexImage>(IndexImage::create(index_filepath, index_header));
index_image = std::make_unique<IndexImage>(IndexImage::create(index_filepath, index_header));

auto fixel_data_header(H);
fixel_data_header.ndim() = 3;
Expand All @@ -191,32 +191,33 @@ void Segmented_FOD_receiver::commit() {
if (dir_path.size()) {
auto dir_header(fixel_data_header);
dir_header.size(1) = 3;
dir_image = make_unique<DataImage>(DataImage::create(Path::join(fixel_directory_path, dir_path), dir_header));
dir_image = std::make_unique<DataImage>(DataImage::create(Path::join(fixel_directory_path, dir_path), dir_header));
dir_image->index(1) = 0;
Fixel::check_fixel_size(*index_image, *dir_image);
}

if (afd_path.size()) {
auto afd_header(fixel_data_header);
afd_header.size(1) = 1;
afd_image = make_unique<DataImage>(DataImage::create(Path::join(fixel_directory_path, afd_path), afd_header));
afd_image = std::make_unique<DataImage>(DataImage::create(Path::join(fixel_directory_path, afd_path), afd_header));
afd_image->index(1) = 0;
Fixel::check_fixel_size(*index_image, *afd_image);
}

if (peak_amp_path.size()) {
auto peak_amp_header(fixel_data_header);
peak_amp_header.size(1) = 1;
peak_amp_image =
make_unique<DataImage>(DataImage::create(Path::join(fixel_directory_path, peak_amp_path), peak_amp_header));
peak_amp_image = std::make_unique<DataImage>(
DataImage::create(Path::join(fixel_directory_path, peak_amp_path), peak_amp_header));
peak_amp_image->index(1) = 0;
Fixel::check_fixel_size(*index_image, *peak_amp_image);
}

if (disp_path.size()) {
auto disp_header(fixel_data_header);
disp_header.size(1) = 1;
disp_image = make_unique<DataImage>(DataImage::create(Path::join(fixel_directory_path, disp_path), disp_header));
disp_image =
std::make_unique<DataImage>(DataImage::create(Path::join(fixel_directory_path, disp_path), disp_header));
disp_image->index(1) = 0;
Fixel::check_fixel_size(*index_image, *disp_image);
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/meshconvert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void run() {
auto opt = get_options("transform");
if (opt.size()) {
auto H = Header::open(opt[0][1]);
auto transform = make_unique<Surface::Filter::VertexTransform>(H);
auto transform = std::make_unique<Surface::Filter::VertexTransform>(H);
switch (int(opt[0][0])) {
case 0:
transform->set_first2real();
Expand Down
2 changes: 1 addition & 1 deletion cmd/mrclusterstats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void run() {
auto mask_header = Header::open(argument[3]);
check_effective_dimensionality(mask_header, 3);
auto mask_image = mask_header.get_image<bool>();
std::shared_ptr<Voxel2Vector> v2v = make_shared<Voxel2Vector>(mask_image, mask_header);
std::shared_ptr<Voxel2Vector> v2v = std::make_shared<Voxel2Vector>(mask_image, mask_header);
SubjectVoxelImport::set_mapping(v2v);
Filter::Connector connector;
connector.adjacency.set_26_adjacency(do_26_connectivity);
Expand Down
2 changes: 1 addition & 1 deletion core/filter/dilate.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Dilate : public Base {
std::shared_ptr<ProgressBar> progress(message.size() ? new ProgressBar(message, npass + 1) : nullptr);

for (unsigned int pass = 0; pass < npass; pass++) {
out = make_shared<Image<bool>>(Image<bool>::scratch(input));
out = std::make_shared<Image<bool>>(Image<bool>::scratch(input));
for (auto l = Loop(*in)(*in, *out); l; ++l)
out->value() = dilate(*in);
if (pass < npass - 1)
Expand Down
4 changes: 2 additions & 2 deletions core/filter/erode.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ class Erode : public Base {

template <class InputImageType, class OutputImageType>
void operator()(InputImageType &input, OutputImageType &output) {
std::shared_ptr<Image<bool>> in = make_shared<Image<bool>>(Image<bool>::scratch(input));
std::shared_ptr<Image<bool>> in = std::make_shared<Image<bool>>(Image<bool>::scratch(input));
copy(input, *in);
std::shared_ptr<Image<bool>> out;
std::shared_ptr<ProgressBar> progress(message.size() ? new ProgressBar(message, npass + 1) : nullptr);

for (unsigned int pass = 0; pass < npass; pass++) {
out = make_shared<Image<bool>>(Image<bool>::scratch(input));
out = std::make_shared<Image<bool>>(Image<bool>::scratch(input));
for (auto l = Loop(*in)(*in, *out); l; ++l)
out->value() = erode(*in);

Expand Down
4 changes: 2 additions & 2 deletions core/filter/smooth.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class Smooth : public Base {
//! Smooth the input image. Both input and output images can be the same image
template <class InputImageType, class OutputImageType, typename ValueType = float>
void operator()(InputImageType &input, OutputImageType &output) {
std::shared_ptr<Image<ValueType>> in(make_shared<Image<ValueType>>(Image<ValueType>::scratch(input)));
std::shared_ptr<Image<ValueType>> in(std::make_shared<Image<ValueType>>(Image<ValueType>::scratch(input)));
threaded_copy(input, *in);
std::shared_ptr<Image<ValueType>> out;

Expand All @@ -120,7 +120,7 @@ class Smooth : public Base {
for (size_t dim = 0; dim < 3; dim++) {
if (stdev[dim] > 0) {
DEBUG("creating scratch image for smoothing image along dimension " + str(dim));
out = make_shared<Image<ValueType>>(Image<ValueType>::scratch(input));
out = std::make_shared<Image<ValueType>>(Image<ValueType>::scratch(input));
Adapter::Gaussian1D<Image<ValueType>> gaussian(*in, stdev[dim], dim, extent[dim], zero_boundary);
threaded_copy(gaussian, *out, 0, input.ndim(), 2);
in = out;
Expand Down
2 changes: 1 addition & 1 deletion core/header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ Header Header::scratch(const Header &template_header, const std::string &label)
H.reset_intensity_scaling();
H.sanitise();
H.format_ = "scratch image";
H.io = make_unique<ImageIO::Scratch>(H);
H.io = std::make_unique<ImageIO::Scratch>(H);
return H;
}

Expand Down
8 changes: 0 additions & 8 deletions core/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,6 @@ template <class ValueType>
struct is_data_type
: std::integral_constant<bool, std::is_arithmetic<ValueType>::value || is_complex<ValueType>::value> {};

template <typename X, typename... Args> inline std::shared_ptr<X> make_shared(Args &&...args) {
return std::shared_ptr<X>(new X(std::forward<Args>(args)...));
}

template <typename X, typename... Args> inline std::unique_ptr<X> make_unique(Args &&...args) {
return std::unique_ptr<X>(new X(std::forward<Args>(args)...));
}

// required to allow use of abs() call on unsigned integers in template
// functions, etc, since the standard labels such calls ill-formed:
// http://en.cppreference.com/w/cpp/numeric/math/abs
Expand Down
2 changes: 1 addition & 1 deletion src/dwi/tractography/GT/mhsampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class MHSampler {
T(dwi),
dims{size_t(dwi.size(0)), size_t(dwi.size(1)), size_t(dwi.size(2))},
mask(m),
lock(make_shared<SpatialLock<float>>(5 * Particle::L)),
lock(std::make_shared<SpatialLock<float>>(5 * Particle::L)),
sigpos(Particle::L / 8.),
sigdir(0.2) {
DEBUG("Initialise Metropolis Hastings sampler.");
Expand Down
8 changes: 4 additions & 4 deletions src/registration/metric/evaluate.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ template <class MetricType, class ParamType> class Evaluate {
DEBUG("Reorienting FODs...");
std::shared_ptr<Image<default_type>> im1_image_reoriented;
std::shared_ptr<Image<default_type>> im2_image_reoriented;
im1_image_reoriented = make_shared<Image<default_type>>(Image<default_type>::scratch(params.im1_image));
im2_image_reoriented = make_shared<Image<default_type>>(Image<default_type>::scratch(params.im2_image));
im1_image_reoriented = std::make_shared<Image<default_type>>(Image<default_type>::scratch(params.im1_image));
im2_image_reoriented = std::make_shared<Image<default_type>>(Image<default_type>::scratch(params.im2_image));

{
if (params.mc_settings.size()) {
Expand Down Expand Up @@ -183,8 +183,8 @@ template <class MetricType, class ParamType> class Evaluate {
DEBUG("Reorienting FODs...");
std::shared_ptr<Image<default_type>> im1_image_reoriented;
std::shared_ptr<Image<default_type>> im2_image_reoriented;
im1_image_reoriented = make_shared<Image<default_type>>(Image<default_type>::scratch(params.im1_image));
im2_image_reoriented = make_shared<Image<default_type>>(Image<default_type>::scratch(params.im2_image));
im1_image_reoriented = std::make_shared<Image<default_type>>(Image<default_type>::scratch(params.im1_image));
im2_image_reoriented = std::make_shared<Image<default_type>>(Image<default_type>::scratch(params.im2_image));

{
if (params.mc_settings.size()) {
Expand Down
31 changes: 16 additions & 15 deletions src/registration/nonlinear.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,19 +175,19 @@ class NonLinear {
field_header.ndim() = 4;
field_header.size(3) = 3;

im1_to_mid_new = make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));
im2_to_mid_new = make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));
im1_update = make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));
im2_update = make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));
im1_update_new = make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));
im2_update_new = make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));
im1_to_mid_new = std::make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));
im2_to_mid_new = std::make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));
im1_update = std::make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));
im2_update = std::make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));
im1_update_new = std::make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));
im2_update_new = std::make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));

if (!is_initialised) {
if (level == 0) {
im1_to_mid = make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));
im2_to_mid = make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));
mid_to_im1 = make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));
mid_to_im2 = make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));
im1_to_mid = std::make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));
im2_to_mid = std::make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));
mid_to_im1 = std::make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));
mid_to_im2 = std::make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));
} else {
DEBUG("Upsampling fields");
{
Expand Down Expand Up @@ -383,22 +383,22 @@ class NonLinear {
field_header.ndim() = 4;
field_header.size(3) = 3;

im1_to_mid = make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));
im1_to_mid = std::make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));
input_warps.index(4) = 0;
threaded_copy(input_warps, *im1_to_mid, 0, 4);
Registration::Warp::deformation2displacement(*im1_to_mid, *im1_to_mid);

mid_to_im1 = make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));
mid_to_im1 = std::make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));
input_warps.index(4) = 1;
threaded_copy(input_warps, *mid_to_im1, 0, 4);
Registration::Warp::deformation2displacement(*mid_to_im1, *mid_to_im1);

im2_to_mid = make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));
im2_to_mid = std::make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));
input_warps.index(4) = 2;
threaded_copy(input_warps, *im2_to_mid, 0, 4);
Registration::Warp::deformation2displacement(*im2_to_mid, *im2_to_mid);

mid_to_im2 = make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));
mid_to_im2 = std::make_shared<Image<default_type>>(Image<default_type>::scratch(field_header));
input_warps.index(4) = 3;
threaded_copy(input_warps, *mid_to_im2, 0, 4);
Registration::Warp::deformation2displacement(*mid_to_im2, *mid_to_im2);
Expand Down Expand Up @@ -508,7 +508,8 @@ class NonLinear {

protected:
std::shared_ptr<Image<default_type>> reslice(Image<default_type> &image, Header &header) {
std::shared_ptr<Image<default_type>> temp = make_shared<Image<default_type>>(Image<default_type>::scratch(header));
std::shared_ptr<Image<default_type>> temp =
std::make_shared<Image<default_type>>(Image<default_type>::scratch(header));
Filter::reslice<Interp::Linear>(image, *temp);
return temp;
}
Expand Down
4 changes: 2 additions & 2 deletions src/registration/warp/compose.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ FORCE_INLINE void update_displacement_scaling_and_squaring(Image<default_type> &
scale_factor = std::pow(2, std::ceil(std::log((max_norm * step) / (min_vox_size / 2.0)) / std::log(2.0)));

std::shared_ptr<Image<default_type>> scaled_update =
make_shared<Image<default_type>>(Image<default_type>::scratch(update));
std::make_shared<Image<default_type>>(Image<default_type>::scratch(update));
std::shared_ptr<Image<default_type>> composed =
make_shared<Image<default_type>>(Image<default_type>::scratch(update));
std::make_shared<Image<default_type>>(Image<default_type>::scratch(update));

// Scaling
default_type scaled_step = step / scale_factor; // apply the step size and scale factor at once
Expand Down

0 comments on commit bf33a98

Please sign in to comment.