9 #ifndef CUBBYFLOW_ARRAY_UTILS_IMPL_H 10 #define CUBBYFLOW_ARRAY_UTILS_IMPL_H 21 template <
typename ArrayType,
typename T>
22 void SetRange1(
size_t size,
const T& value, ArrayType* output)
27 template <
typename ArrayType,
typename T>
28 void SetRange1(
size_t begin,
size_t end,
const T& value, ArrayType* output)
36 template <
typename ArrayType1,
typename ArrayType2>
37 void CopyRange1(
const ArrayType1& input,
size_t size, ArrayType2* output)
42 template <
typename ArrayType1,
typename ArrayType2>
43 void CopyRange1(
const ArrayType1& input,
size_t begin,
size_t end, ArrayType2* output)
47 (*output)[i] = input[i];
51 template <
typename ArrayType1,
typename ArrayType2>
52 void CopyRange2(
const ArrayType1& input,
size_t sizeX,
size_t sizeY, ArrayType2* output)
57 template <
typename ArrayType1,
typename ArrayType2>
58 void CopyRange2(
const ArrayType1& input,
size_t beginX,
size_t endX,
size_t beginY,
size_t endY, ArrayType2* output)
60 ParallelFor(beginX, endX, beginY, endY, [&input, &output](
size_t i,
size_t j)
62 (*output)(i, j) = input(i, j);
66 template <
typename ArrayType1,
typename ArrayType2>
67 void CopyRange3(
const ArrayType1& input,
size_t sizeX,
size_t sizeY,
size_t sizeZ, ArrayType2* output)
72 template <
typename ArrayType1,
typename ArrayType2>
73 void CopyRange3(
const ArrayType1& input,
size_t beginX,
size_t endX,
size_t beginY,
size_t endY,
size_t beginZ,
size_t endZ, ArrayType2* output)
75 ParallelFor(beginX, endX, beginY, endY, beginZ, endZ, [&input, &output](
size_t i,
size_t j,
size_t k)
77 (*output)(i, j, k) = input(i, j, k);
86 assert(size == valid.
size());
87 assert(size == output.
size());
92 valid0.ParallelForEachIndex([&](
size_t i,
size_t j)
94 valid0(i, j) = valid(i, j);
95 output(i, j) = input(i, j);
98 for (
unsigned int iter = 0; iter < numberOfIterations; ++iter)
100 valid0.ForEachIndex([&](
size_t i,
size_t j)
103 unsigned int count = 0;
107 if (i + 1 < size.
x && valid0(i + 1, j))
109 sum += output(i + 1, j);
113 if (i > 0 && valid0(i - 1, j))
115 sum += output(i - 1, j);
119 if (j + 1 < size.
y && valid0(i, j + 1))
121 sum += output(i, j + 1);
125 if (j > 0 && valid0(i, j - 1))
127 sum += output(i, j - 1);
147 template <
typename T>
152 assert(size == valid.
size());
153 assert(size == output.
size());
158 valid0.ParallelForEachIndex([&](
size_t i,
size_t j,
size_t k)
160 valid0(i, j, k) = valid(i, j, k);
161 output(i, j, k) = input(i, j, k);
164 for (
unsigned int iter = 0; iter < numberOfIterations; ++iter)
166 valid0.ForEachIndex([&](
size_t i,
size_t j,
size_t k)
169 unsigned int count = 0;
171 if (!valid0(i, j, k))
173 if (i + 1 < size.
x && valid0(i + 1, j, k))
175 sum += output(i + 1, j, k);
179 if (i > 0 && valid0(i - 1, j, k))
181 sum += output(i - 1, j, k);
185 if (j + 1 < size.
y && valid0(i, j + 1, k))
187 sum += output(i, j + 1, k);
191 if (j > 0 && valid0(i, j - 1, k))
193 sum += output(i, j - 1, k);
197 if (k + 1 < size.
z && valid0(i, j, k + 1))
199 sum += output(i, j, k + 1);
203 if (k > 0 && valid0(i, j, k - 1))
205 sum += output(i, j, k - 1);
224 template <
typename ArrayType>
227 Size2 size = data.size();
229 for (
size_t j = 0; j < size.
y; ++j)
231 for (
size_t i = 0; i < size.
x; ++i)
233 auto val = data(i, j);
236 if constexpr (
sizeof(decltype(val)) == 1)
238 *stream << static_cast<int>(val);
251 *stream << std::endl;
2-D read-only array accessor class.
Definition: ArrayAccessor2.h:261
3-D array accessor class.
Definition: ArrayAccessor3.h:31
void CopyRange3(const ArrayType1 &input, size_t sizeX, size_t sizeY, size_t sizeZ, ArrayType2 *output)
Copies 3-D input array to output array with sizeX and sizeY.
Definition: ArrayUtils-Impl.h:67
3-D read-only array accessor class.
Definition: ArrayAccessor3.h:269
T x
X (or the first) component of the point.
Definition: Point2.h:28
void CopyRange2(const ArrayType1 &input, size_t sizeX, size_t sizeY, ArrayType2 *output)
Copies 2-D input array to output array with sizeX and sizeY.
Definition: ArrayUtils-Impl.h:52
T value
Definition: TypeHelpers.h:18
void ExtrapolateToRegion(const ConstArrayAccessor2< T > &input, const ConstArrayAccessor2< char > &valid, unsigned int numberOfIterations, ArrayAccessor2< T > output)
Extrapolates 2-D input data from 'valid' (1) to 'invalid' (0) region.
Definition: ArrayUtils-Impl.h:82
void ConvertToCSV(const ArrayType &data, std::ostream *stream)
Converts 2-D array to Comma Separated Value (CSV) stream.
Definition: ArrayUtils-Impl.h:225
2-D point class.
Definition: Point2.h:25
3-D point class.
Definition: Point3.h:26
2-D array accessor class.
Definition: ArrayAccessor2.h:31
T y
Y (or the second) component of the point.
Definition: Point2.h:34
Definition: pybind11Utils.h:24
void ParallelFor(IndexType beginIndex, IndexType endIndex, const Function &function, ExecutionPolicy policy)
Makes a for-loop from beginIndex to endIndex in parallel.
Definition: Parallel-Impl.h:201
T z
Z (or the third) component of the point.
Definition: Point3.h:38
Size2 size() const
Returns the size of the array.
Definition: ArrayAccessor2-Impl.h:129
T y
Y (or the second) component of the point.
Definition: Point3.h:35
constexpr size_t ZERO_SIZE
Zero size_t.
Definition: Constants.h:18
T x
X (or the first) component of the point.
Definition: Point3.h:29
Size3 size() const
Returns the size of the array.
Definition: ArrayAccessor3-Impl.h:129
Size3 size() const
Returns the size of the array.
Definition: ArrayAccessor3-Impl.h:347
3-D array class.
Definition: Array3.h:45
2-D array class.
Definition: Array2.h:42
void SetRange1(size_t size, const T &value, ArrayType *output)
Assigns value to 1-D array output with size.
Definition: ArrayUtils-Impl.h:22
Size2 size() const
Returns the size of the array.
Definition: ArrayAccessor2-Impl.h:333
void CopyRange1(const ArrayType1 &input, size_t size, ArrayType2 *output)
Copies input array to output array with size.
Definition: ArrayUtils-Impl.h:37