33#include "SerializationFwd.h"
37#ifndef DOXYGEN_SHOULD_SKIP_THIS
98 std::swap(m_size, other.m_size);
141 return pos.col < m_size.col && pos.row < m_size.row && (std::is_unsigned<I>::value || (0 <= pos.col && 0 <= pos.row));
151 return {
static_cast<I>(index % m_size.col),
static_cast<I>(index / m_size.col) };
161 return pos.row * m_size.col + pos.col;
177 return { 0,
static_cast<std::size_t
>(m_size.col) *
static_cast<std::size_t
>(m_size.row) };
186 return { 0, m_size.row };
195 return { 0, m_size.col };
204 return { getColRange(), getRowRange() };
214 return getNeighborSquareRange(pos, 1);
224 return getNeighborSquareRange(pos, 2);
234 return getNeighborDiamondRange(pos, 1);
244 return getNeighborDiamondRange(pos, 2);
251 assert(isValid(pos));
253 auto colMin = pos.col - std::min(pos.col, n);
254 auto colMax = pos.col + std::min(m_size.col - pos.col - 1, n);
255 auto rowMin = pos.row - std::min(pos.row, n);
256 auto rowMax = pos.row + std::min(m_size.row - pos.row - 1, n);
261 NeighborDiamondRange<I> getNeighborDiamondRange(Vector<I, 2> pos, I n)
const noexcept {
262 assert(isValid(pos));
264 auto colMin = pos.col - std::min(pos.col, n);
265 auto colMax = pos.col + std::min(m_size.col - pos.col - 1, n);
266 auto rowMin = pos.row - std::min(pos.row, n);
267 auto rowMax = pos.row + std::min(m_size.row - pos.row - 1, n);
269 return NeighborDiamondRange<I>{ Range<I>{ colMin, colMax + 1 }, Range<I>{ rowMin, rowMax + 1 }, pos, n };
303 template<
typename T,
typename I =
unsigned>
323 , m_data(static_cast<std::size_t>(size.width) * static_cast<std::size_t>(size.height))
335 , m_data(static_cast<std::size_t>(size.width) * static_cast<std::size_t>(size.height), value)
366 std::swap(m_data, other.m_data);
396 return m_data.data();
405 return m_data.size();
417 return m_data.empty();
443 return m_data[index];
462 return m_data[index];
480 return m_data.data();
489 const T *
end() const noexcept {
490 return m_data.data() + m_data.size();
500 return m_data.data();
510 return m_data.data() + m_data.size();
517 return m_data[toIndex(pos)];
520 const T& get(Vector<I, 2> pos)
const {
521 return m_data[toIndex(pos)];
525 std::vector<T> m_data;
532 template<
typename T,
typename I>
537 if (lhsSize.width != rhsSize.width || lhsSize.height != rhsSize.height) {
548 template<
typename T,
typename I>
551 ar | size.width | size.height;
553 for (
auto& item : array) {
554 ar |
const_cast<T&
>(item);
564 template<
typename T,
typename I>
567 ar | size.width | size.height;
571 for (
auto& item : tmp) {
575 array = std::move(tmp);
580#ifndef DOXYGEN_SHOULD_SKIP_THIS
A two-dimensional array.
Definition: Array2D.h:304
std::size_t getDataSize() const noexcept
Get the raw data size.
Definition: Array2D.h:404
Array2D()
Default constructor.
Definition: Array2D.h:311
const T & operator()(std::size_t index) const
Get the element at a given 1D index.
Definition: Array2D.h:461
const T * getDataPtr() const noexcept
Get the pointer to raw data.
Definition: Array2D.h:395
Array2D(Vector< I, 2 > size)
Constructor with a size.
Definition: Array2D.h:321
T * end() noexcept
Get an iterator to the element following the last element of the array.
Definition: Array2D.h:509
Array2D & operator=(const Array2D &)=default
Default copy assignment.
T & operator()(std::size_t index)
Get the element at a given 1D index.
Definition: Array2D.h:442
Array2D & operator=(Array2D &&)=default
Default move assignement.
Serializer & operator|(Serializer &ar, const Array2D< T, I > &array)
Serialize a 2D array.
Definition: Array2D.h:549
void swap(Array2D &other)
Swap with another array.
Definition: Array2D.h:364
T & operator()(Vector< I, 2 > pos)
Get the element at a given 2D position.
Definition: Array2D.h:432
bool operator==(const Array2D< T, I > &lhs, const Array2D< T, I > &rhs)
Equality operator for 2D array.
Definition: Array2D.h:533
const T * end() const noexcept
Get an iterator to the element following the last element of the array.
Definition: Array2D.h:489
constexpr bool isEmpty() const noexcept
Check if the array is empty.
Definition: Array2D.h:416
T * begin() noexcept
Get an iterator to the first element of the array.
Definition: Array2D.h:499
const T & operator()(Vector< I, 2 > pos) const
Get the element at a given 2D position.
Definition: Array2D.h:451
Array2D(Vector< I, 2 > size, const T &value)
Constructor with a size and a value.
Definition: Array2D.h:333
Array2D(Array2D &&)=default
Default move constructor.
Array2D(const Array2D &)=default
Default copy constructor.
const T * begin() const noexcept
Get an iterator to the first element of the array.
Definition: Array2D.h:479
Deserializer & operator|(Deserializer &ar, Array2D< T, I > &array)
Deserialize a 2D array.
Definition: Array2D.h:565
A deserializer from a binary file.
Definition: Serialization.h:151
A two-dimensional array with no data.
Definition: Array2D.h:50
Index2D & operator=(const Index2D &)=default
Default copy assignment.
void swap(Index2D &other)
Swap with another array.
Definition: Array2D.h:97
constexpr Range< I > getColRange() const noexcept
Get the column range.
Definition: Array2D.h:194
constexpr RangeZ getIndexRange() const noexcept
Get the 1D index range of the array.
Definition: Array2D.h:176
constexpr Vector< I, 2 > getSize() const noexcept
Get the size of the array.
Definition: Array2D.h:111
constexpr Vector< I, 2 > toPosition(std::size_t index) const noexcept
Transform a 1D position into a 2D position.
Definition: Array2D.h:150
Index2D(const Index2D &)=default
Default copy constructor.
Index2D & operator=(Index2D &&)=default
Default move assignement.
NeighborDiamondRange< I > get12NeighborsRange(Vector< I, 2 > pos) const noexcept
Get a range for 12 neighbors (at most)
Definition: Array2D.h:243
NeighborDiamondRange< I > get4NeighborsRange(Vector< I, 2 > pos) const noexcept
Get a range for 4 neighbors (at most)
Definition: Array2D.h:233
constexpr PositionRange< I > getPositionRange() const noexcept
Get the position range.
Definition: Array2D.h:203
Index2D(Vector< I, 2 > size)
Constructor with a size.
Definition: Array2D.h:67
constexpr bool isValid(Vector< I, 2 > pos) const noexcept
Check if a position is valid.
Definition: Array2D.h:140
constexpr I getRows() const noexcept
Get the number of rows.
Definition: Array2D.h:129
constexpr I getCols() const noexcept
Get the number of columns.
Definition: Array2D.h:120
Index2D(Index2D &&)=default
Default move constructor.
Index2D()
Default constructor.
Definition: Array2D.h:57
constexpr Range< I > getRowRange() const noexcept
Get the row range.
Definition: Array2D.h:185
NeighborSquareRange< I > get8NeighborsRange(Vector< I, 2 > pos) const noexcept
Get a range for 8 neighbors (at most)
Definition: Array2D.h:213
NeighborSquareRange< I > get24NeighborsRange(Vector< I, 2 > pos) const noexcept
Get a range for 24 neighbors (at most)
Definition: Array2D.h:223
constexpr std::size_t toIndex(Vector< I, 2 > pos) const noexcept
Transform a 2D position into a 1D position.
Definition: Array2D.h:160
A serializer to a binary file.
Definition: Serialization.h:43
The namespace for gf classes.
template class GF_CORE_API Index2D< int >
template class GF_CORE_API Index2D< unsigned >
A 2D range.
Definition: Range.h:595
A 2D range.
Definition: Range.h:426
A 2D range.
Definition: Range.h:278
A half-open range of values.
Definition: Range.h:44