60 template<
class PixelFormat>
81 template<
typename DataFormat>
141# if __has_warning("-Wunsafe-buffer-usage")
142# pragma clang diagnostic push
143# pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
146 return *(
data() + idx);
148# if __has_warning("-Wunsafe-buffer-usage")
149# pragma clang diagnostic pop
177# if __has_warning("-Wunsafe-buffer-usage")
178# pragma clang diagnostic push
179# pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
184# if __has_warning("-Wunsafe-buffer-usage")
185# pragma clang diagnostic pop
211 typename T = DataFormat,
212 typename std::enable_if_t<
213 std::is_convertible_v<typename std::iterator_traits<Iterator>::value_type, T>,
214 std::nullptr_t> =
nullptr>
216 : m_width{ resolution.
width() }
217 , m_height{ resolution.
height() }
219 const auto inputSize = std::distance(beginIt, endIt);
220 if(inputSize !=
static_cast<std::ptrdiff_t
>(resolution.
size()))
222 throw std::out_of_range(
223 "Array2D constructor got input that does not match image size. Expected "
224 + std::to_string(resolution.
size()) +
" items, got " + std::to_string(inputSize)
227 std::unique_ptr<DataFormat[]>
data{
new DataFormat[resolution.
size()] };
228 std::copy(beginIt, endIt,
data.get());
229 return data.release();
231 std::default_delete<DataFormat[]>() }
234 template<
typename T = DataFormat,
typename std::enable_if_t<std::is_trivial_v<T>, std::
nullptr_t> =
nullptr>
235 Array2D(
const Resolution &resolution,
const unsigned char *
begin,
const unsigned char *
end)
239 const auto byteCount = std::distance(
begin,
end);
241 const auto expectedByteCount =
static_cast<std::ptrdiff_t
>(
resolution.
size() *
sizeof(DataFormat));
242 if(expectedByteCount != byteCount)
244 std::ostringstream errorMessage;
246 <<
"The provided input buffer size does not match the expected size. The provided input buffer size is "
247 << byteCount <<
" bytes. Expected " << expectedByteCount <<
" bytes (" <<
resolution.
width()
248 <<
" x " <<
resolution.
height() <<
" x " <<
sizeof(DataFormat) <<
" bytes).";
249 throw std::logic_error(std::move(errorMessage).str());
252 std::shared_ptr<DataFormat> data(
new DataFormat[
resolution.
size()], std::default_delete<DataFormat[]>{});
256 std::memcpy(data.get(),
begin, byteCount);
259 m_data = std::move(data);
262 friend class Array2DFactory;
263 friend class Image<DataFormat>;
265 Array2D(std::size_t width, std::size_t height, std::unique_ptr<DataFormat[]> data)
272 std::default_delete<DataFormat[]>()
277 std::size_t m_height;
278 std::shared_ptr<const DataFormat> m_data;
299 return array.
begin();
#define ZIVID_UTILS_EXPORT
Definition UtilsExport.h:56
Two-dimensional container of data.
Definition Array2D.h:83
ConstIterator cbegin() const
Iterator to the beginning of the array.
Definition Array2D.h:191
const DataFormat * ConstIterator
The iterator type for immutable access. It iterates over individual Array2D elements in row major ord...
Definition Array2D.h:91
const DataFormat & operator()(size_t i, size_t j) const
Constant reference to an element given by row and column.
Definition Array2D.h:162
ConstIterator cend() const
Iterator to the end of the array.
Definition Array2D.h:197
const DataFormat & operator()(size_t idx) const
Constant reference to an element given by a 1D linear index.
Definition Array2D.h:138
size_t height() const
Get the height of the array (number of rows)
Definition Array2D.h:106
const DataFormat * data() const
Pointer to the first data element of the array.
Definition Array2D.h:126
bool isEmpty() const
Check if the array is empty.
Definition Array2D.h:119
std::string toString() const
Get array information as string.
Definition Array2D.h:203
ConstIterator end() const
Iterator to the end of the array.
Definition Array2D.h:174
DataFormat ValueType
The type of the elements stored in the Array2D.
Definition Array2D.h:86
size_t size() const
Get the number of elements in the array.
Definition Array2D.h:113
size_t width() const
Get the width of the array (number of columns)
Definition Array2D.h:100
ConstIterator begin() const
Iterator to the beginning of the array.
Definition Array2D.h:168
Array2D()
Create an empty Array2D.
Definition Array2D.h:94
A 2-dimensional image.
Definition Image.h:85
Class describing a resolution with a width and a height.
Definition Resolution.h:56
ZIVID_UTILS_EXPORT size_t height() const
Get the height value of the resolution.
ZIVID_UTILS_EXPORT size_t width() const
Get the width value of the resolution.
ZIVID_UTILS_EXPORT size_t size() const
Get the size (area) that is the product of the width and height.
ZIVID_CORE_EXPORT Resolution resolution(const CameraInfo &cameraInfo, const Settings &settings)
Returns the resolution of captured frames according to the provided camera information and settings.
The main Zivid namespace. All Zivid code is found here.
Definition Application.h:84
Array2D< T >::ConstIterator end(const Array2D< T > &array)
Iterator to the end of the array.
Definition Array2D.h:311
Array2D< T >::ConstIterator cbegin(const Array2D< T > &array)
Iterator to the beginning of the array.
Definition Array2D.h:290
std::ostream & operator<<(std::ostream &stream, const Array2D< T > &array)
Serialize array information to a stream.
Definition Array2D.h:283
Array2D< T >::ConstIterator cend(const Array2D< T > &array)
Iterator to the end of the array.
Definition Array2D.h:304
Array2D< T >::ConstIterator begin(const Array2D< T > &array)
Iterator to the beginning of the array.
Definition Array2D.h:297