CVB++ 15.0
decl_image_plane.hpp
1#pragma once
2
3#include <algorithm>
4#include <memory>
5#include <new>
6#include <system_error>
7#include <utility>
8
9#include "../_cexports/c_img.h"
10#include "../_cexports/c_utilities.h"
11
12#include "../global.hpp"
13#include "../point_2d.hpp"
14
15#include "../data_type.hpp"
16#include "../iarray.hpp"
17#include "../image_plane_contiguous_iterator.hpp"
18#include "../image_plane_linear_iterator.hpp"
19#include "../image_plane_vpat_iterator.hpp"
20
21
22namespace Cvb
23{
24
25CVB_BEGIN_INLINE_NS
26
27
28
30
31class ImagePlane final
32 : public IArray
33{
35 friend Image;
37
38 public:
39
40
41
42
43
44
46
52 explicit ImagePlane(const class Plane & plane);
53
54 ImagePlane(const ImagePlane& other) = delete;
55 ImagePlane& operator=(const ImagePlane& other) = delete;
56 ImagePlane(ImagePlane&& other) noexcept = default;
57 ImagePlane& operator=(ImagePlane&& other) noexcept = default;
58 virtual ~ImagePlane() = default;
59
60
61
62
64
70 void* Handle() const noexcept override;
71
73
82 bool TryContiguousAccess(std::uint8_t *&basePtr) const noexcept;
83
85
93
95
106 bool TryLinearAccess(LinearAccessData & linearAccessData) const noexcept;
107
109
117
118
119
120 class DataType DataType() const noexcept override;
121
122 int Rank() const noexcept override
123 {
124 return 2;
125 }
126
128
132 const Image& Parent() const noexcept;
133
135
144 class Vpat Vpat() const;
145
146
147
149
153 std::unique_ptr<Image> Map() const;
154
155
156
158
163 double GetPixel(Point2D<int> position) const;
164
165
167 int Plane() const noexcept
168 {
169 return plane_;
170 }
171
173
179 template <class Type>
180 ContiguousIterator<Type> BeginContiguous();
181
183
189 template <class Type>
190 ContiguousIterator<Type> EndContiguous();
191
193
199 template <class Type>
201
203
209 template <class Type>
211
213
219 template <class Type>
220 ContiguousConstIterator<Type> CBeginContiguous() const;
221
223
229 template <class Type>
230 ContiguousConstIterator<Type> BeginContiguous() const
231 {
232 return CBeginContiguous<Type>();
233 }
234
236
242 template <class Type>
243 ContiguousConstIterator<Type> CEndContiguous() const;
244
246
252 template <class Type>
253 ContiguousConstIterator<Type> EndContiguous() const
254 {
255 return CEndContiguous<Type>();
256 }
257
259
265 template <class Type>
267
269
275 template <class Type>
277 {
278 return CRBeginContiguous<Type>();
279 }
280
282
288 template <class Type>
290
292
298 template <class Type>
300 {
301 return CEndContiguous<Type>();
302 }
303
305
311 template <class Type>
312 LinearIterator<Type> BeginLinear();
313
315
321 template <class Type>
322 LinearIterator<Type> EndLinear();
323
325
331 template <class Type>
333
335
341 template <class Type>
343
345
351 template <class Type>
352 LinearConstIterator<Type> CBeginLinear() const;
353
355
361 template <class Type>
362 LinearConstIterator<Type> BeginLinear() const
363 {
364 return CBeginLinear<Type>();
365 }
366
368
374 template <class Type>
375 LinearConstIterator<Type> CEndLinear() const;
376
378
384 template <class Type>
385 LinearConstIterator<Type> EndLinear() const
386 {
387 return CEndLinear<Type>();
388 }
389
391
397 template <class Type>
399
401
407 template <class Type>
409 {
410 return CRBeginLinear<Type>();
411 }
412
414
420 template <class Type>
422
424
430 template <class Type>
432 {
433 return CREndLinear<Type>();
434 }
435
437
443 template <class Type>
444 VpatIterator<Type> BeginVpat();
445
447
453 template <class Type>
454 VpatIterator<Type> EndVpat();
455
457
463 template <class Type>
465
467
473 template <class Type>
475
477
483 template <class Type>
484 VpatConstIterator<Type> CBeginVpat() const;
485
487
493 template <class Type>
494 VpatConstIterator<Type> BeginVpat() const
495 {
496 return CBeginVpat<Type>();
497 }
498
500
506 template <class Type>
507 VpatConstIterator<Type> CEndVpat() const;
508
510
516 template <class Type>
517 VpatConstIterator<Type> EndVpat() const
518 {
519 return CEndVpat<Type>();
520 }
521
523
529 template <class Type>
531
533
539 template <class Type>
541 {
542 return CRBeginVpat<Type>();
543 }
544
546
552 template <class Type>
554
556
562 template <class Type>
564 {
565 return CREndVpat<Type>();
566 }
567
568 private:
569
570
571
572 ImagePlane(int plane, const Image & image) noexcept
573 : plane_(plane)
574 , parentImage_(&image)
575 {
576 }
577
578 int plane_;
579
580 const Image * parentImage_ = nullptr;
581
583};
584
585template <>
586struct PlaneTraits<ImagePlane>
587{
588 using PlaneT = ImagePlane;
589 using TypeList = DispatchableTypeList<std::uint8_t, std::int8_t, std::uint16_t, std::int16_t, std::uint32_t,
590 std::int32_t, std::uint64_t, std::int64_t, float, double>;
591
592 static constexpr bool HasVpat = true;
593
594 static int GetWidth(const ImagePlane &plane);
595 static int GetHeight(const ImagePlane &plane);
596
597 static Cvb::DataType GetDataType(const ImagePlane &plane)
598 {
599 return plane.DataType();
600 }
601
602 static constexpr int GetRank(const ImagePlane &)
603 {
604 return 2;
605 }
606
607 static Cvb::Vpat GetVpat(const ImagePlane &plane)
608 {
609 return plane.Vpat();
610 }
611};
612
613CVB_END_INLINE_NS
614
615}
616
617
618
619
620
Data type description for an image plane.
Definition: data_type.hpp:28
Array interface.
Definition: iarray.hpp:16
The Common Vision Blox image.
Definition: decl_image.hpp:45
Image plane information container.
Definition: decl_image_plane.hpp:33
std::uint8_t * ContiguousAccess() const
Attempt a contiguous access on the plane's pixels.
Definition: detail_image_plane.hpp:56
VpatConstIterator< Type > EndVpat() const
Get iterator access to the plane.
Definition: decl_image_plane.hpp:517
VpatConstIterator< Type > BeginVpat() const
Get iterator access to the plane.
Definition: decl_image_plane.hpp:494
std::reverse_iterator< LinearConstIterator< Type > > REndLinear() const
Get iterator access to the plane.
Definition: decl_image_plane.hpp:431
VpatIterator< Type > EndVpat()
Get iterator access to the plane.
Definition: detail_image_plane.hpp:295
LinearConstIterator< Type > BeginLinear() const
Get iterator access to the plane.
Definition: decl_image_plane.hpp:362
ContiguousConstIterator< Type > CBeginContiguous() const
Get iterator access to the plane.
Definition: detail_image_plane.hpp:214
std::reverse_iterator< LinearIterator< Type > > RBeginLinear()
Get iterator access to the plane.
Definition: detail_image_plane.hpp:252
std::reverse_iterator< ContiguousConstIterator< Type > > RBeginContiguous() const
Get iterator access to the plane.
Definition: decl_image_plane.hpp:276
std::reverse_iterator< ContiguousIterator< Type > > REndContiguous()
Get iterator access to the plane.
Definition: detail_image_plane.hpp:208
VpatConstIterator< Type > CEndVpat() const
Get iterator access to the plane.
Definition: detail_image_plane.hpp:321
ContiguousIterator< Type > BeginContiguous()
Get iterator access to the plane.
Definition: detail_image_plane.hpp:189
ContiguousIterator< Type > EndContiguous()
Get iterator access to the plane.
Definition: detail_image_plane.hpp:195
std::reverse_iterator< VpatConstIterator< Type > > RBeginVpat() const
Get iterator access to the plane.
Definition: decl_image_plane.hpp:540
LinearAccessData LinearAccess() const
Attempt a linear access on the plane's pixels.
Definition: detail_image_plane.hpp:79
LinearConstIterator< Type > EndLinear() const
Get iterator access to the plane.
Definition: decl_image_plane.hpp:385
bool TryLinearAccess(LinearAccessData &linearAccessData) const noexcept
Attempt a linear access on the plane's pixels.
Definition: detail_image_plane.hpp:64
int Rank() const noexcept override
Gets the number of dimensions for this array.
Definition: decl_image_plane.hpp:122
std::reverse_iterator< VpatConstIterator< Type > > CRBeginVpat() const
Get iterator access to the plane.
Definition: detail_image_plane.hpp:328
VpatConstIterator< Type > CBeginVpat() const
Get iterator access to the plane.
Definition: detail_image_plane.hpp:315
std::reverse_iterator< LinearConstIterator< Type > > CREndLinear() const
Get iterator access to the plane.
Definition: detail_image_plane.hpp:283
LinearConstIterator< Type > CEndLinear() const
Get iterator access to the plane.
Definition: detail_image_plane.hpp:270
VpatIterator< Type > BeginVpat()
Get iterator access to the plane.
Definition: detail_image_plane.hpp:289
std::reverse_iterator< LinearConstIterator< Type > > CRBeginLinear() const
Get iterator access to the plane.
Definition: detail_image_plane.hpp:277
std::reverse_iterator< VpatConstIterator< Type > > CREndVpat() const
Get iterator access to the plane.
Definition: detail_image_plane.hpp:334
std::reverse_iterator< LinearConstIterator< Type > > RBeginLinear() const
Get iterator access to the plane.
Definition: decl_image_plane.hpp:408
std::reverse_iterator< ContiguousConstIterator< Type > > CRBeginContiguous() const
Get iterator access to the plane.
Definition: detail_image_plane.hpp:227
LinearIterator< Type > EndLinear()
Get iterator access to the plane.
Definition: detail_image_plane.hpp:245
std::unique_ptr< Image > Map() const
Create a map from a single image plane that shares its memory with the original plane.
Definition: detail_image_plane.hpp:100
ContiguousConstIterator< Type > BeginContiguous() const
Get iterator access to the plane.
Definition: decl_image_plane.hpp:230
void * Handle() const noexcept override
Classic API image handle.
Definition: detail_image_plane.hpp:36
bool TryContiguousAccess(std::uint8_t *&basePtr) const noexcept
Attempt a contiguous access on the plane's pixels.
Definition: detail_image_plane.hpp:41
std::reverse_iterator< VpatIterator< Type > > REndVpat()
Get iterator access to the plane.
Definition: detail_image_plane.hpp:308
ImagePlane(const class Plane &plane)
Implicitly convert a plane to an image plane.
Definition: detail_image_plane.hpp:27
std::reverse_iterator< ContiguousIterator< Type > > RBeginContiguous()
Get iterator access to the plane.
Definition: detail_image_plane.hpp:202
std::reverse_iterator< VpatConstIterator< Type > > REndVpat() const
Get iterator access to the plane.
Definition: decl_image_plane.hpp:563
double GetPixel(Point2D< int > position) const
Gets the pixel value at the given position.
Definition: detail_image_plane.hpp:108
ContiguousConstIterator< Type > CEndContiguous() const
Get iterator access to the plane.
Definition: detail_image_plane.hpp:220
ContiguousConstIterator< Type > EndContiguous() const
Get iterator access to the plane.
Definition: decl_image_plane.hpp:253
std::reverse_iterator< VpatIterator< Type > > RBeginVpat()
Get iterator access to the plane.
Definition: detail_image_plane.hpp:302
const Image & Parent() const noexcept
Image to which this plane descriptor refers to.
Definition: detail_image_plane.hpp:87
LinearIterator< Type > BeginLinear()
Get iterator access to the plane.
Definition: detail_image_plane.hpp:239
LinearConstIterator< Type > CBeginLinear() const
Get iterator access to the plane.
Definition: detail_image_plane.hpp:264
std::reverse_iterator< LinearIterator< Type > > REndLinear()
Get iterator access to the plane.
Definition: detail_image_plane.hpp:258
std::reverse_iterator< ContiguousConstIterator< Type > > REndContiguous() const
Get iterator access to the plane.
Definition: decl_image_plane.hpp:299
std::reverse_iterator< ContiguousConstIterator< Type > > CREndContiguous() const
Get iterator access to the plane.
Definition: detail_image_plane.hpp:233
Linear access properties.
Definition: decl_linear_access.hpp:25
Plane information container.
Definition: decl_plane.hpp:28
Multi-purpose 2D vector class.
Definition: point_2d.hpp:20
Virtual Pixel Access Table.
Definition: decl_vpat.hpp:24
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24