Developer documentation
Version 3.0.3-105-gd3941f44
threaded_copy.h
Go to the documentation of this file.
1/* Copyright (c) 2008-2022 the MRtrix3 contributors.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 *
7 * Covered Software is provided under this License on an "as is"
8 * basis, without warranty of any kind, either expressed, implied, or
9 * statutory, including, without limitation, warranties that the
10 * Covered Software is free of defects, merchantable, fit for a
11 * particular purpose or non-infringing.
12 * See the Mozilla Public License v. 2.0 for more details.
13 *
14 * For more details, see http://www.mrtrix.org/.
15 */
16
17#ifndef __algo_threaded_copy_h__
18#define __algo_threaded_copy_h__
19
20#include "algo/threaded_loop.h"
21
22namespace MR
23{
24
26 namespace {
27
28 struct __copy_func { NOMEMALIGN
29 template <class InputImageType, class OutputImageType>
30 FORCE_INLINE void operator() (InputImageType& in, OutputImageType& out) const {
31 out.value() = in.value();
32 }
33 };
34
35 }
36
38
39
40
41
42 template <class InputImageType, class OutputImageType>
43 inline void threaded_copy (
44 InputImageType& source,
45 OutputImageType& destination,
46 const vector<size_t>& axes,
47 size_t num_axes_in_thread = 1)
48 {
49 ThreadedLoop (source, axes, num_axes_in_thread)
50 .run (__copy_func(), source, destination);
51 }
52
53 template <class InputImageType, class OutputImageType>
54 inline void threaded_copy (
55 InputImageType& source,
56 OutputImageType& destination,
57 size_t from_axis = 0,
58 size_t to_axis = std::numeric_limits<size_t>::max(),
59 size_t num_axes_in_thread = 1)
60 {
61 ThreadedLoop (source, from_axis, to_axis, num_axes_in_thread)
62 .run (__copy_func(), source, destination);
63 }
64
65
66
67
68 template <class InputImageType, class OutputImageType>
70 const std::string& message,
71 InputImageType& source,
72 OutputImageType& destination,
73 const vector<size_t>& axes,
74 size_t num_axes_in_thread = 1)
75 {
76 ThreadedLoop (message, source, axes, num_axes_in_thread)
77 .run (__copy_func(), source, destination);
78 }
79
80 template <class InputImageType, class OutputImageType>
82 const std::string& message,
83 InputImageType& source,
84 OutputImageType& destination,
85 size_t from_axis = 0,
86 size_t to_axis = std::numeric_limits<size_t>::max(),
87 size_t num_axes_in_thread = 1)
88 {
89 ThreadedLoop (message, source, from_axis, to_axis, num_axes_in_thread)
90 .run (__copy_func(), source, destination);
91 }
92
93
94 template <class InputImageType, class OutputImageType>
96 InputImageType& source,
97 OutputImageType& destination,
98 const vector<size_t>& axes,
99 size_t num_axes_in_thread = 1)
100 {
101 threaded_copy_with_progress_message ("copying from \"" + shorten (source.name()) + "\" to \"" + shorten (destination.name()) + "\"",
102 source, destination, axes, num_axes_in_thread);
103 }
104
105 template <class InputImageType, class OutputImageType>
107 InputImageType& source,
108 OutputImageType& destination,
109 size_t from_axis = 0,
110 size_t to_axis = std::numeric_limits<size_t>::max(),
111 size_t num_axes_in_thread = 1)
112 {
113 threaded_copy_with_progress_message ("copying from \"" + shorten (source.name()) + "\" to \"" + shorten (destination.name()) + "\"",
114 source, destination, from_axis, to_axis, num_axes_in_thread);
115 }
116
117}
118
119#endif
120
#define NOMEMALIGN
Definition: memory.h:22
Definition: base.h:24
void threaded_copy_with_progress(InputImageType &source, OutputImageType &destination, const vector< size_t > &axes, size_t num_axes_in_thread=1)
Definition: threaded_copy.h:95
ThreadedLoopRunOuter< decltype(Loop(vector< size_t >()))> ThreadedLoop(const HeaderType &source, const vector< size_t > &outer_axes, const vector< size_t > &inner_axes)
Multi-threaded loop object.
std::string shorten(const std::string &text, size_t longest=40, size_t prefix=10)
convert a long string to 'beginningofstring...endofstring' for display
Definition: mrtrix.h:88
void threaded_copy(InputImageType &source, OutputImageType &destination, const vector< size_t > &axes, size_t num_axes_in_thread=1)
Definition: threaded_copy.h:43
void threaded_copy_with_progress_message(const std::string &message, InputImageType &source, OutputImageType &destination, const vector< size_t > &axes, size_t num_axes_in_thread=1)
Definition: threaded_copy.h:69
#define FORCE_INLINE
Definition: types.h:156