60 template<
class PixelFormat>
67 ZIVID_CORE_EXPORT std::string array2DToString(std::size_t width, std::size_t height);
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<
213 std::is_convertible<typename std::iterator_traits<Iterator>::value_type, T>::value,
214 std::nullptr_t>::type =
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[]>() }
235 typename T = DataFormat,
236 typename std::enable_if<std::is_trivial<T>::value, std::nullptr_t>::type =
nullptr>
237 Array2D(
const Resolution &resolution,
const unsigned char *
begin,
const unsigned char *
end)
241 const auto byteCount = std::distance(
begin,
end);
243 const auto expectedByteCount =
static_cast<std::ptrdiff_t
>(
resolution.
size() *
sizeof(DataFormat));
244 if(expectedByteCount != byteCount)
246 std::ostringstream errorMessage;
248 <<
"The provided input buffer size does not match the expected size. The provided input buffer size is "
249 << byteCount <<
" bytes. Expected " << expectedByteCount <<
" bytes (" <<
resolution.
width()
250 <<
" x " <<
resolution.
height() <<
" x " <<
sizeof(DataFormat) <<
" bytes).";
251 throw std::logic_error(std::move(errorMessage).str());
254 std::shared_ptr<DataFormat> data(
new DataFormat[
resolution.
size()], std::default_delete<DataFormat[]>{});
258 std::memcpy(data.get(),
begin, byteCount);
261 m_data = std::move(data);
264 friend class Array2DFactory;
265 friend class Image<DataFormat>;
267 Array2D(std::size_t width, std::size_t height, std::unique_ptr<DataFormat[]> data)
274 std::default_delete<DataFormat[]>()
279 std::size_t m_height;
280 std::shared_ptr<const DataFormat> m_data;
301 return array.
begin();
#define ZIVID_CORE_EXPORT
Definition CoreExport.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_CORE_EXPORT size_t size() const
Get the size (area) that is the product of the width and height.
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:56
Array2D< T >::ConstIterator end(const Array2D< T > &array)
Iterator to the end of the array.
Definition Array2D.h:313
Array2D< T >::ConstIterator cbegin(const Array2D< T > &array)
Iterator to the beginning of the array.
Definition Array2D.h:292
std::ostream & operator<<(std::ostream &stream, const Array2D< T > &array)
Serialize array information to a stream.
Definition Array2D.h:285
Array2D< T >::ConstIterator cend(const Array2D< T > &array)
Iterator to the end of the array.
Definition Array2D.h:306
Array2D< T >::ConstIterator begin(const Array2D< T > &array)
Iterator to the beginning of the array.
Definition Array2D.h:299