11#include "namespace.hpp"
13#include "_cexports/c_core.h"
14#include "_cexports/c_driver.h"
17# define CVB_FORCE_INLINE inline
21# define CVB_FORCE_INLINE __forceinline
23# elif __GNUC__ && __cplusplus
25# define CVB_FORCE_INLINE inline __attribute__((always_inline))
120 const double CVB_M_PI = 3.14159265358979323846;
398 Ok = CExports::CVDWS_Ok,
432 PixHSV_S = CExports::CVCPR_PixHSV_S,
511 enum class CompositePurpose
538 AsyncRef() =
default;
543 auto ref = weakRef_.lock();
552 void Reset()
noexcept
566 HandlerCarrier() noexcept = default;
567 HandlerCarrier(const HandlerCarrier &other) noexcept = default;
568 HandlerCarrier &operator=(const HandlerCarrier &other) noexcept = default;
569 HandlerCarrier(HandlerCarrier &&other) noexcept = default;
570 HandlerCarrier &operator=(HandlerCarrier &&other) noexcept = default;
571 virtual ~HandlerCarrier() = default;
574 typedef std::shared_ptr<HandlerCarrier> HandlerCarrierPtr;
575 typedef std::weak_ptr<HandlerCarrier> HandlerCarrierWPtr;
577 class CarrierContainer;
593 friend Internal::CarrierContainer;
607 explicit operator
bool() const noexcept
609 return !handlerCarrier_.expired();
607 explicit operator
bool() const noexcept {
…}
613 explicit EventCookie(
const Internal::HandlerCarrierPtr &handlerCarrier) noexcept
614 : handlerCarrier_(handlerCarrier)
618 Internal::HandlerCarrierWPtr handlerCarrier_;
624 typedef void(REL_CB)(
void *handle);
628 template <
class T, Internal::REL_CB CB>
629 class SharedHandleGuard;
631 template <
class T, Internal::REL_CB CB =
nullptr>
636 explicit HandleGuard(
void *handle) noexcept
637 : handle_(handle, CB)
639 static_assert(std::is_same<T, void>::value,
640 "CVB: HandleGuard need specialization, or type void with release callback!");
643 HandleGuard(
void *handle, std::function<
void(
void *)> deleter) noexcept
644 : handle_(handle, deleter)
648 void *Handle() const noexcept
650 return handle_.get();
653 void Reset(
void *handle =
nullptr) noexcept
655 handle_.reset(handle);
658 void *Release() noexcept
660 return handle_.release();
664 std::unique_ptr<void, std::function<void(
void *)>> handle_;
666 friend class SharedHandleGuard<T, CB>;
669 typedef HandleGuard<void, CVB_CALL_CAPI(ReleaseObjectVoid)> ReleaseObjectGuard;
671 template <
class T, Internal::REL_CB CB =
nullptr>
672 class SharedHandleGuard
675 explicit SharedHandleGuard(HandleGuard<T, CB> &&uniqueGuard)
676 : shandle_(std::
move(uniqueGuard.handle_))
680 SharedHandleGuard(
const SharedHandleGuard &other)
noexcept =
default;
681 SharedHandleGuard &operator=(
const SharedHandleGuard &)
noexcept =
default;
682 SharedHandleGuard(SharedHandleGuard &&other)
noexcept =
default;
683 SharedHandleGuard &operator=(SharedHandleGuard &&other)
noexcept =
default;
684 ~SharedHandleGuard() =
default;
686 void *Handle() const noexcept
688 return shandle_.get();
692 std::shared_ptr<void> shandle_;
695 typedef SharedHandleGuard<void, CVB_CALL_CAPI(ReleaseObjectVoid)> SharedReleaseObjectGuard;
703 void ThrowLastError();
704 void ThrowLastError(
int errorCode);
714 class CbCarrier :
public HandlerCarrier
718 static std::shared_ptr<CbCarrier> Create(std::function<T> cb)
720 return std::make_shared<CbCarrier<T>>(cb);
723 explicit CbCarrier(std::function<T> cb) noexcept
728 std::function<T> CB() const noexcept
734 std::function<T> cb_;
737 class CarrierContainer
740 CarrierContainer() noexcept {}
742 CarrierContainer(
const CarrierContainer &other) =
delete;
743 CarrierContainer &operator=(
const CarrierContainer &other) =
delete;
744 CarrierContainer(CarrierContainer &&other)
noexcept
748 carrierList_ = std::move(other.carrierList_);
755 CarrierContainer &operator=(CarrierContainer &&other) =
delete;
756 ~CarrierContainer() =
default;
758 EventCookie Register(
const HandlerCarrierPtr &handlerBase)
760 std::unique_lock<std::mutex> guard(carrierListMutex_);
761 carrierList_.push_back(handlerBase);
762 return EventCookie{handlerBase};
765 void Unregister(EventCookie eventCookie)
noexcept
768 auto handlerBase = eventCookie.handlerCarrier_.lock();
772 std::unique_lock<std::mutex> guard(carrierListMutex_);
773 carrierList_.remove(handlerBase);
776 template <
class T,
class... Args>
777 void Call(Args &&...args)
const
779 std::list<HandlerCarrierPtr> carrierList;
781 std::unique_lock<std::mutex> guard(carrierListMutex_);
782 carrierList.insert(carrierList.end(), carrierList_.begin(), carrierList_.end());
784 for (
auto &carrier : carrierList)
786 auto holder = std::dynamic_pointer_cast<CbCarrier<T>>(carrier);
787 holder->CB()(std::forward<Args>(args)...);
792 mutable std::mutex carrierListMutex_;
793 std::list<HandlerCarrierPtr> carrierList_;
796 template <
class OBJ,
class RES,
class... ARGS>
797 inline std::unique_ptr<OBJ> DoCallObjectOut(std::function<RES(
void *&handle)> call, ARGS &&...args)
799 void *handle =
nullptr;
800 auto code = CExports::MakeErrorCode(call(handle));
803 Utilities::SystemInfo::ThrowLastError(code);
805 return OBJ::FromHandle(HandleGuard<OBJ>(handle), std::forward<ARGS>(args)...);
808 template <
class OBJ,
class... ARGS>
809 inline std::unique_ptr<OBJ> DoBoolCallObjectOut(std::function<CExports::cvbbool_t(
void *&handle)> call,
812 return DoCallObjectOut<
OBJ, CExports::cvbbool_t, ARGS...>(call, std::forward<ARGS>(args)...);
815 template <
class OBJ,
class... ARGS>
816 inline std::unique_ptr<OBJ> DoResCallObjectOut(std::function<CExports::cvbres_t(
void *&handle)> call,
819 return DoCallObjectOut<
OBJ, CExports::cvbres_t, ARGS...>(call, std::forward<ARGS>(args)...);
823 inline std::unique_ptr<OBJ> DoHandleCallObjectOut(
void *result)
825 return DoCallObjectOut<OBJ, void *>([=](
void *&handle) {
return (handle = result); });
828 template <
class OBJ,
class RES,
class... ARGS>
829 inline std::shared_ptr<OBJ> DoCallShareOut(std::function<RES(
void *&handle)> call, ARGS &&...args)
831 void *handle =
nullptr;
832 auto code = CExports::MakeErrorCode(call(handle));
835 Utilities::SystemInfo::ThrowLastError(code);
837 return OBJ::template FromHandle<OBJ>(
typename OBJ::GuardType(handle), std::forward<ARGS>(args)...);
840 template <
class OBJ,
class... ARGS>
841 inline std::shared_ptr<OBJ> DoBoolCallShareOut(std::function<CExports::cvbbool_t(
void *&handle)> call,
844 return DoCallShareOut<
OBJ, CExports::cvbbool_t, ARGS...>(call, std::forward<ARGS>(args)...);
847 template <
class OBJ,
class... ARGS>
848 inline std::shared_ptr<OBJ> DoResCallShareOut(std::function<CExports::cvbres_t(
void *&handle)> call, ARGS &&...args)
850 return DoCallShareOut<
OBJ, CExports::cvbres_t, ARGS...>(call, std::forward<ARGS>(args)...);
853 template <
class T,
class RES>
854 inline T DoCallValueOut(std::function<RES(T &handle)> call)
857 auto code = CExports::MakeErrorCode(call(value));
860 Utilities::SystemInfo::ThrowLastError(code);
866 inline T DoBoolCallValueOut(std::function<CExports::cvbbool_t(T &handle)> call)
868 return DoCallValueOut<T, CExports::cvbbool_t>(call);
872 inline T DoResCallValueOut(std::function<CExports::cvbres_t(T &value)> call)
874 return DoCallValueOut<T, CExports::cvbres_t>(call);
878 inline void DoCall(std::function<RES()> call)
880 auto code = CExports::MakeErrorCode(call());
882 Utilities::SystemInfo::ThrowLastError(code);
885 inline void DoBoolCall(std::function<CExports::cvbbool_t()> call)
887 DoCall<CExports::cvbbool_t>(call);
890 inline void DoResCall(std::function<CExports::cvbres_t()> call)
892 DoCall<CExports::cvbres_t>(call);
895 class SmartBool final
898 SmartBool() noexcept = default;
899 SmartBool(
bool val) noexcept
905 SmartBool(CExports::cvbbool_t val) noexcept
911 operator bool() const noexcept
913 return ((cVal_) ?
true :
false);
916 CExports::cvbbool_t *Ptr() noexcept
922 CExports::cvbbool_t cVal_ = 0;
929 std::integral_constant<bool, std::is_same<double, T>::value || std::is_same<float, T>::value
930 || std::is_same<std::int64_t, T>::value || std::is_same<std::int32_t, T>::value
931 || std::is_same<std::int16_t, T>::value || std::is_same<std::int8_t, T>::value>;
934 using EnableIfNumeric = std::enable_if<IsNumeric<T>::value>;
937 using EnableIfArithmetic = std::enable_if<std::is_arithmetic<T>::value>;
939 template <
class T,
class... ARGS>
942 template <
class T,
class ARG>
943 struct AllOfType<T, ARG>
945 static constexpr bool Value =
946 std::is_same<typename std::remove_const<typename std::remove_reference<T>::type>::type, ARG>::value
947 || std::is_base_of<typename std::remove_const<typename std::remove_reference<T>::type>::type, ARG>::value;
950 template <
class T,
class ARG,
class... ARGS>
951 struct AllOfType<T, ARG, ARGS...>
953 static constexpr bool Value =
954 (std::is_same<typename std::remove_const<typename std::remove_reference<T>::type>::type, ARG>::value
955 || std::is_base_of<typename std::remove_const<typename std::remove_reference<T>::type>::type, ARG>::value)
956 && AllOfType<T, ARGS...>::Value;
959 template <
typename RET,
typename TYPE,
class RANGE>
961 std::enable_if<std::is_same<TYPE,
typename std::remove_const<
typename std::remove_reference<
decltype(*std::begin(
962 std::declval<RANGE &>()))>::type>::type>::value,
965 template <
class RET,
class TYPE,
class... ARGS>
966 using VarArgRange =
typename std::enable_if<AllOfType<TYPE, ARGS...>::Value, RET>;
968 template <
class TYPE,
class RANGE>
974 explicit RangeAdapter(
const RANGE &range)
978 std::is_same<
typename std::remove_const<
979 typename std::remove_reference<decltype(*std::begin(std::declval<RANGE &>()))>::type>::type,
981 "Unexpected range value type");
987 return const_cast<TYPE *
>(Data(inputRef_.get()));
991 std::size_t Size()
const
993 return std::distance(std::begin(inputRef_.get()), std::end(inputRef_.get()));
999 const TYPE *Data(
const TYPE (&carray)[N])
const
1005 const TYPE *Data(
const std::array<TYPE, N> &stdarray)
const
1007 return stdarray.data();
1010 const TYPE *Data(
const std::vector<TYPE> &stdvec)
const
1012 return stdvec.data();
1015 template <
class LIST>
1016 const TYPE *Data(
const LIST &list)
const
1018 if (convertedRange_.empty())
1020 convertedRange_.assign(std::begin(list), std::end(list));
1022 return convertedRange_.data();
1026 const std::reference_wrapper<const RANGE> inputRef_;
1027 mutable std::vector<TYPE> convertedRange_;
1030 template <
class TYPE,
class RANGE>
1031 RangeAdapter<TYPE, RANGE> MakeRangeAdapter(
const RANGE &range, std::size_t minSize = 1)
1033 RangeAdapter<TYPE, RANGE> rangeAdapter(range);
1034 if (minSize != 0 && rangeAdapter.Size() < minSize)
1035 throw std::runtime_error(
"insufficient number of input range values");
1036 return rangeAdapter;
1040 struct DispatchableTypeList
1044 template <
class DT,
class... DTS>
1045 struct DispatchableTypeList<DT, DTS...>
1047 using DefaultType = DT;
1079 template <
class PLANE_T>
Base class of all buffers.
Definition buffer_base.hpp:21
Buffer class implementing a buffer.
Definition buffer.hpp:13
A token to enable cancellation on wait operations.
Definition cancellation_token.hpp:20
Provides tokens and signals tokens cancellation.
Definition cancellation_token_source.hpp:20
Point components of the point cloud.
Definition components_pointers_3d.hpp:18
Component class is a container for CVB objects.
Definition decl_composite.hpp:45
PFNC buffer class implementing a compressed pfnc buffer.
Definition compressed_pfnc_buffer.hpp:13
Data type description for an image plane.
Definition data_type.hpp:23
Point components of a dense point cloud.
Definition dense_components_pointers_3d.hpp:15
Factory object for creating device objects.
Definition decl_device_factory.hpp:31
Generic CVB physical device.
Definition decl_device.hpp:39
Cookie used to unregister event handlers.
Definition global.hpp:591
EventCookie() noexcept=default
Creates an empty cookie for convenience.
HandleOnly class is as it says a handle only.
Definition handle_only.hpp:21
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:29
Linear access properties.
Definition decl_linear_access.hpp:25
PFNC buffer class implementing a pfnc buffer.
Definition pfnc_buffer.hpp:15
Mapped image of two merged source images.
Definition panoramic_mapped_image.hpp:19
Lazy enumeration of planes.
Definition decl_plane_enumerator.hpp:27
Plane information container.
Definition decl_plane.hpp:25
Point components of a sparse point cloud.
Definition sparse_components_pointers_3d.hpp:14
Virtual Pixel Access Table.
Definition decl_vpat.hpp:24
A wrapped image wraps another pixel buffer without owning it.
Definition decl_wrapped_image.hpp:28
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
std::shared_ptr< HandleOnly > HandleOnlyPtr
Convenience shared pointer for HandleOnly.
Definition global.hpp:106
std::shared_ptr< PFNCBuffer > PFNCBufferPtr
Convenience shared pointer for PFNCBuffer.
Definition global.hpp:70
RotationMap
Amount of rotation to apply when mapping an image.
Definition global.hpp:377
@ By180Degrees
Definition global.hpp:386
@ By270Degrees
Definition global.hpp:391
@ By90Degrees
Definition global.hpp:381
@ Float
Definition core_3d.hpp:94
std::shared_ptr< Buffer > BufferPtr
Convenience shared pointer for Buffer.
Definition global.hpp:62
PanoramaDirection
Defines the direction of the panoramic image.
Definition global.hpp:493
@ Vertical
Images are stitched vertically.
Definition global.hpp:497
@ Horizontal
Images are stitched horizontally.
Definition global.hpp:495
SubPixelMode
Method for determining sub pixel accuracy when working with the FindLocalMaxima functions.
Definition global.hpp:312
@ ParabolicFast
Definition global.hpp:318
@ ParabolicAccurate
Definition global.hpp:323
@ Gaussian
Definition global.hpp:328
ConversionMode
Mode used by conversion to dense point cloud.
Definition global.hpp:524
@ Automatic
Definition global.hpp:528
MappingOption
Mapping options when creating a (potentially) mapped image.
Definition global.hpp:361
@ LinkPixels
Definition global.hpp:372
@ CopyPixels
Definition global.hpp:365
WaitStatus
Status after waiting for an image to be returned.
Definition global.hpp:396
@ Abort
The acquisition has been stopped asynchronously, there is no image buffer.
Definition global.hpp:402
@ Ok
Everything is fine, a new image arrived.
Definition global.hpp:398
@ Timeout
A timeout occurred, no image buffer has been returned.
Definition global.hpp:400
std::shared_ptr< Image > ImagePtr
Convenience shared pointer for Image.
Definition global.hpp:86
std::shared_ptr< CancellationToken > CancellationTokenPtr
Convenience shared pointer for CancellationToken.
Definition global.hpp:110
PixelDataType
Defines the numeric data type of one pixel.
Definition global.hpp:149
@ UInt
Definition global.hpp:159
@ Int
Definition global.hpp:163
@ ComplexPackedFloat
Definition global.hpp:171
@ Undefined
Definition global.hpp:155
std::shared_ptr< PlaneEnumerator > PlaneEnumeratorPtr
Convenience shared pointer for PlaneEnumerator.
Definition global.hpp:82
ColorModel
Color model that this image is using.
Definition global.hpp:176
@ CieLUV
Definition global.hpp:216
@ HLS
Definition global.hpp:224
@ CieLab
Definition global.hpp:220
@ MonoGuess
Definition global.hpp:184
@ HSI
Definition global.hpp:208
@ Mono
Definition global.hpp:192
@ HSV
Definition global.hpp:232
@ CieXYZ
Definition global.hpp:236
@ RGB
Definition global.hpp:200
@ YUV
Definition global.hpp:204
@ YCC
Definition global.hpp:228
@ YCbCr
Definition global.hpp:212
@ RGBGuess
Definition global.hpp:180
std::shared_ptr< CancellationTokenSource > CancellationTokenSourcePtr
Convenience shared pointer for CancellationTokenSource.
Definition global.hpp:114
CoordinateSystemType
Enumeration of the different available coordinate systems that an Area of interest may be defined in.
Definition global.hpp:290
@ PixelCoordinates
Definition global.hpp:298
@ ImageCoordinates
Definition global.hpp:307
std::shared_ptr< WrappedImage > WrappedImagePtr
Convenience shared pointer for WrappedImage.
Definition global.hpp:90
ConnectionState
Current connection state of the Device.
Definition global.hpp:502
@ Connected
The Device object is currently connected to the remote hardware.
Definition global.hpp:506
@ NotSupported
Connection state handling is not supported by the Device.
Definition global.hpp:504
@ Disconnected
The Device object is currently disconnected from the remote hardware.
Definition global.hpp:508
std::shared_ptr< Device > DevicePtr
Convenience shared pointer for Device.
Definition global.hpp:98
Neighborhood
Neighborhood to use in sub pixel calculation of local maxima.
Definition global.hpp:337
@ Use3x3
Definition global.hpp:341
@ Use7x7
Definition global.hpp:351
@ Use5x5
Definition global.hpp:346
@ Use9x9
Definition global.hpp:356
std::shared_ptr< CompressedPFNCBuffer > CompressedPFNCBufferPtr
Convenience shared pointer for a compressed PFNCBuffer.
Definition global.hpp:74
CompressedBufferType
The possible image compression types a CVB buffer can transport within GenDC.
Definition global.hpp:132
@ Unknown
Definition global.hpp:136
@ JPEG
Definition global.hpp:140
@ JPEG2000
Definition global.hpp:144
DeviceUpdateMode
Defines how to treat the optional device image, when the device itself is updated.
Definition global.hpp:252
@ NewDeviceImage
Definition global.hpp:272
@ UpdateDeviceImage
Definition global.hpp:261
PlaneNormalization
Plane handling for normalization.
Definition global.hpp:277
@ Individual
Definition global.hpp:281
@ Identical
Definition global.hpp:285
std::shared_ptr< BufferBase > BufferBasePtr
Convenience shared pointer for BufferBase.
Definition global.hpp:66
std::shared_ptr< PixelFormatConverter > PixelFormatConverterPtr
Convenience shared pointer for PixelFormatConverter.
Definition global.hpp:118
PlaneRole
A plane role describes the components of the plane. They can coarsely be separated in two sets.
Definition global.hpp:411
@ PixYUV_Y
Same as PixMono, but to distinguish YUV model.
Definition global.hpp:424
@ PixLAB_A
Green-red chrominance channel.
Definition global.hpp:438
@ PixRGB_R
Red channel value.
Definition global.hpp:418
@ PointVariation
Variation of points in cloud.
Definition global.hpp:479
@ CoordCartesian_W
Cartesian W axis component (homogeneous coordinates).
Definition global.hpp:453
@ CoordCartesian_Y
Cartesian Y axis component.
Definition global.hpp:449
@ PointPlanarity
Planarity of points in cloud.
Definition global.hpp:477
@ CoordCartesian_X
Cartesian X axis component.
Definition global.hpp:447
@ CoordPolar_Phi
Polar azimuth angle component.
Definition global.hpp:457
@ PixConfidence
Confidence(probability density / percentage) or consistency(Boolean) value.
Definition global.hpp:442
@ Normal_Z
Normal in Z.
Definition global.hpp:475
@ PixLAB_B
Blue-yellow chrominance channel.
Definition global.hpp:440
@ PointSphericity
Sphericity of points in cloud.
Definition global.hpp:481
@ PointCurvature
Curvature of points in cloud.
Definition global.hpp:485
@ PixRGB_B
Blue channel value.
Definition global.hpp:422
@ CoordCylindrical_Phi
Cylindrical azimuth angle component.
Definition global.hpp:461
@ CoordCylindrical_Rho
Cylindrical radius component.
Definition global.hpp:459
@ Normal_X
Normal in X.
Definition global.hpp:471
@ Custom
Custom roles.
Definition global.hpp:488
@ CoordCartesian_Z
Cartesian Z axis component.
Definition global.hpp:451
@ CoordSpherical_Phi
Spherical azimuth angle component.
Definition global.hpp:467
@ PointLinearity
Linearity of points in cloud.
Definition global.hpp:483
@ PixRGB_RGB
Red-green-blue channel value.
Definition global.hpp:444
@ PixYUV_V
Red chrominance channel.
Definition global.hpp:428
@ CoordPolar_Rho
Polar radius component.
Definition global.hpp:455
@ PixHSV_V
Value(luminance) channel value.
Definition global.hpp:434
@ PixYUV_U
Blue chrominance channel.
Definition global.hpp:426
@ Normal_Y
Normal in Y.
Definition global.hpp:473
@ PixLAB_L
Lightness channel value.
Definition global.hpp:436
@ CoordCylindrical_Z
Cylindrical Z axis component.
Definition global.hpp:463
@ PixRGB_G
Green channel value.
Definition global.hpp:420
@ PixHSV_H
Hue channel value.
Definition global.hpp:430
@ CoordSpherical_Theta
Spherical inclination/polar angle component.
Definition global.hpp:469
@ PixMono
Monochromatic, linear luminance value.
Definition global.hpp:416
@ CoordSpherical_Rho
Spherical radius component.
Definition global.hpp:465
std::shared_ptr< Composite > CompositePtr
Convenience shared pointer for Composite.
Definition global.hpp:102
std::shared_ptr< Plane > PlanePtr
Convenience shared pointer for Plane.
Definition global.hpp:78
std::shared_ptr< PanoramicMappedImage > PanoramicMappedImagePtr
Convenience shared pointer for PanoramicMappedImageImage.
Definition global.hpp:94
Definition global.hpp:1080