101#include <type_traits>
105 template<
class PixelFormat>
112 ZIVID_CORE_EXPORT std::string array2DToString(std::size_t width, std::size_t height);
126 template<
typename DataFormat>
185 return *(
data() + idx);
234 typename T = DataFormat,
235 typename std::enable_if<
236 std::is_convertible<typename std::iterator_traits<Iterator>::value_type, T>::value,
237 std::nullptr_t>::type =
nullptr>
242 const auto inputSize = std::distance(beginIt, endIt);
245 throw std::out_of_range(
246 "Array2D constructor got input that does not match image size. Expected "
247 + std::to_string(
resolution.
size()) +
" items, got " + std::to_string(inputSize)
251 std::copy(beginIt, endIt,
data.get());
252 return data.release();
254 std::default_delete<DataFormat[]>() }
258 typename T = DataFormat,
259 typename std::enable_if<std::is_trivial<T>::value, std::nullptr_t>::type =
nullptr>
260 Array2D(
const Resolution &
resolution,
const unsigned char *
begin,
const unsigned char *
end)
264 const auto byteCount = std::distance(
begin,
end);
266 const auto expectedByteCount =
static_cast<std::ptrdiff_t
>(
resolution.
size() *
sizeof(DataFormat));
267 if(expectedByteCount != byteCount)
269 std::ostringstream errorMessage;
271 <<
"The provided input buffer size does not match the expected size. The provided input buffer size is "
272 << byteCount <<
" bytes. Expected " << expectedByteCount <<
" bytes (" <<
resolution.
width()
273 <<
" x " <<
resolution.
height() <<
" x " <<
sizeof(DataFormat) <<
" bytes).";
274 throw std::logic_error(std::move(errorMessage).str());
277 std::shared_ptr<DataFormat> data(
new DataFormat[
resolution.
size()], std::default_delete<DataFormat[]>{});
281 std::memcpy(data.get(),
begin, byteCount);
284 m_data = std::move(data);
287 friend class Array2DFactory;
288 friend class Image<DataFormat>;
290 Array2D(std::size_t width, std::size_t height, std::unique_ptr<DataFormat[]> data)
297 std::default_delete<DataFormat[]>()
302 std::size_t m_height;
303 std::shared_ptr<const DataFormat> m_data;
324 return array.
begin();
#define ZIVID_CORE_EXPORT
Definition: CoreExport.h:101
Two-dimensional container of data
Definition: Array2D.h:128
ConstIterator cbegin() const
Iterator to the beginning of the array
Definition: Array2D.h:214
const DataFormat * ConstIterator
The iterator type for immutable access. It iterates over individual Array2D elements in row major ord...
Definition: Array2D.h:136
const DataFormat & operator()(size_t i, size_t j) const
Constant reference to an element given by row and column
Definition: Array2D.h:196
ConstIterator cend() const
Iterator to the end of the array
Definition: Array2D.h:220
const DataFormat & operator()(size_t idx) const
Constant reference to an element given by a 1D linear index
Definition: Array2D.h:183
size_t height() const
Get the height of the array (number of rows)
Definition: Array2D.h:151
const DataFormat * data() const
Pointer to the first data element of the array
Definition: Array2D.h:171
bool isEmpty() const
Check if the array is empty
Definition: Array2D.h:164
std::string toString() const
Get array information as string
Definition: Array2D.h:226
ConstIterator end() const
Iterator to the end of the array
Definition: Array2D.h:208
DataFormat ValueType
The type of the elements stored in the Array2D
Definition: Array2D.h:131
size_t size() const
Get the number of elements in the array
Definition: Array2D.h:158
size_t width() const
Get the width of the array (number of columns)
Definition: Array2D.h:145
ConstIterator begin() const
Iterator to the beginning of the array
Definition: Array2D.h:202
Array2D()
Create an empty Array2D
Definition: Array2D.h:139
A 2-dimensional image
Definition: Image.h:115
Class describing a given resolution
Definition: Resolution.h:101
ZIVID_CORE_EXPORT size_t size() const
Get the size value of the resolution
ZIVID_CORE_EXPORT size_t height() const
Get the height value of the resolution
ZIVID_CORE_EXPORT size_t width() const
Get the width value of the resolution
ZIVID_CORE_EXPORT Resolution resolution(const CameraInfo &cameraInfo, const Settings &settings)
The main Zivid namespace. All Zivid code is found here
Definition: Application.h:99
Array2D< T >::ConstIterator end(const Array2D< T > &array)
Iterator to the end of the array
Definition: Array2D.h:336
Array2D< T >::ConstIterator cbegin(const Array2D< T > &array)
Iterator to the beginning of the array
Definition: Array2D.h:315
std::ostream & operator<<(std::ostream &stream, const Array2D< T > &array)
Serialize array information to a stream
Definition: Array2D.h:308
Array2D< T >::ConstIterator cend(const Array2D< T > &array)
Iterator to the end of the array
Definition: Array2D.h:329
Array2D< T >::ConstIterator begin(const Array2D< T > &array)
Iterator to the beginning of the array
Definition: Array2D.h:322