STIR 6.4.0
copy_fill.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2020, 2024 University College London
3 This file is part of STIR.
4
5 SPDX-License-Identifier: Apache-2.0
6
7 See STIR/LICENSE.txt for details
8*/
9#ifndef __stir_copy_fill__H__
10#define __stir_copy_fill__H__
11
18
19#include "stir/Array.h"
21
22START_NAMESPACE_STIR
30
32
34template <typename T>
36{
37 template <typename iterT>
38 static iterT copy_to(const T& stir_object, iterT iter)
39 {
40 return std::copy(stir_object.begin_all(), stir_object.end_all(), iter);
41 }
42 template <typename iterT>
43 static void fill_from(T& stir_object, iterT iter, iterT iter_end)
44 {
45 std::copy(iter, iter_end, stir_object.begin_all());
46 }
47};
48
50
52template <int num_dimensions, class elemT>
53struct CopyFill<Array<num_dimensions, elemT>>
54{
55 typedef Array<num_dimensions, elemT> Array_type;
56
57 template <typename iterT>
58 static iterT copy_to(const Array_type& stir_array, iterT iter)
59 {
60 if (stir_array.is_contiguous())
61 {
62 // std::cerr << "Using 1D std::copy for copy_to\n";
63 auto beg = stir_array.get_const_full_data_ptr();
64 auto ret = std::copy(beg, beg + stir_array.size_all(), iter);
65 stir_array.release_const_full_data_ptr();
66 return ret;
67 }
68 else
69 {
70 // std::cerr<<"Using normal std::copy for copy_to\n";
71 return std::copy(stir_array.begin_all(), stir_array.end_all(), iter);
72 }
73 }
74
75 template <typename iterT>
76 static void fill_from(Array_type& stir_array, iterT iter, iterT iter_end)
77 {
78 if (stir_array.is_contiguous())
79 {
80 // std::cerr << "Using 1D std::copy for fill_from\n";
81 std::copy(iter, iter_end, stir_array.get_full_data_ptr());
82 stir_array.release_full_data_ptr();
83 }
84 else
85 {
86 // std::cerr<<"Using normal std::copy for fill_from\n";
87 std::copy(iter, iter_end, stir_array.begin_all());
88 }
89 }
90};
91
93
95template <>
97{
98 template <typename iterT>
99 static iterT copy_to(const ProjData& stir_object, iterT iter)
100 {
101#if 1
102 if (auto pdm_ptr = dynamic_cast<ProjDataInMemory const*>(&stir_object))
103 {
104 // std::cerr<<"Using stir::copy_to\n";
105 return CopyFill<ProjDataInMemory>::copy_to(*pdm_ptr, iter);
106 }
107 else
108#endif
109 {
110 // std::cerr<<"Using member copy_to\n";
111 return stir_object.copy_to(iter);
112 }
113 }
114
115 template <typename iterT>
116 static void fill_from(ProjData& stir_object, iterT iter, iterT iter_end)
117 {
118 if (auto pdm_ptr = dynamic_cast<ProjDataInMemory*>(&stir_object))
119 CopyFill<ProjDataInMemory>::fill_from(*pdm_ptr, iter, iter_end);
120 else
121 stir_object.fill_from(iter);
122 }
123};
124
126
131template <typename T, typename iterT>
132inline iterT
133copy_to(const T& stir_object, iterT iter)
134{
135 return CopyFill<T>::copy_to(stir_object, iter);
136}
137
139
142template <typename T, typename iterT>
143inline void
144fill_from(T& stir_object, iterT iter, iterT iter_end)
145{
146 // return
147 CopyFill<T>::fill_from(stir_object, iter, iter_end);
148}
149
151
152END_NAMESPACE_STIR
153
154#endif
defines the stir::Array class for multi-dimensional (numeric) arrays
Declaration of class stir::ProjDataInMemory.
This class defines multi-dimensional (numeric) arrays.
Definition Array.h:78
full_iterator begin_all()
start value for iterating through all elements in the array, see full_iterator
Definition Array.inl:213
bool is_contiguous() const
return if the array is contiguous in memory
Definition Array.inl:44
size_t size_all() const
return the total number of elements in this array
Definition Array.inl:262
const elemT * get_const_full_data_ptr() const
member function for access to the data via a const elemT*
Definition Array.inl:311
void release_full_data_ptr()
signal end of access to elemT*
Definition Array.inl:329
elemT * get_full_data_ptr()
member function for access to the data via a elemT*
Definition Array.inl:292
void release_const_full_data_ptr() const
signal end of access to const elemT*
Definition Array.inl:345
full_iterator end_all()
end value for iterating through all elements in the array, see full_iterator
Definition Array.inl:185
A class which reads/writes projection data from/to memory.
Definition ProjDataInMemory.h:39
The (abstract) base class for the projection data.
Definition ProjData.h:105
iterT copy_to(iterT array_iter) const
Copy all bins to a range specified by a (forward) iterator.
Definition ProjData.h:310
iterT fill_from(iterT array_iter)
set all bins from an array iterator
Definition ProjData.h:277
iterT copy_to(const T &stir_object, iterT iter)
Copy all bins to a range specified by a iterator.
Definition copy_fill.h:133
void fill_from(T &stir_object, iterT iter, iterT iter_end)
set all elements of stir_object from an iterator
Definition copy_fill.h:144
Helper class for stir::copy_to and stir::fill_from.
Definition copy_fill.h:36