3#include "../../affine_matrix_2d.hpp"
4#include "../../affine_matrix_3d.hpp"
5#include "../../angle.hpp"
6#include "../../circle.hpp"
7#include "../../composite.hpp"
8#include "../../cuboid.hpp"
9#include "../../data_type.hpp"
10#include "../../dense_point_cloud.hpp"
11#include "../../driver/buffer_image.hpp"
12#include "../../driver/composite_stream.hpp"
13#include "../../driver/emu_image.hpp"
14#include "../../driver/genicam_device.hpp"
15#include "../../driver/image_stream.hpp"
16#include "../../driver/multi_part_image.hpp"
17#include "../../driver/point_cloud_stream.hpp"
18#include "../../driver/video_image.hpp"
19#include "../../genapi/boolean_node.hpp"
20#include "../../genapi/category_node.hpp"
21#include "../../genapi/command_node.hpp"
22#include "../../genapi/enum_entry_node.hpp"
23#include "../../genapi/enumeration_node.hpp"
24#include "../../genapi/float_node.hpp"
25#include "../../genapi/float_reg_node.hpp"
26#include "../../genapi/int_reg_node.hpp"
27#include "../../genapi/integer_node.hpp"
28#include "../../genapi/node_map.hpp"
29#include "../../genapi/node_map_enumerator.hpp"
30#include "../../genapi/string_node.hpp"
31#include "../../genapi/string_reg_node.hpp"
32#include "../../image.hpp"
33#include "../../line_2d.hpp"
34#include "../../matrix_2d.hpp"
35#include "../../matrix_3d.hpp"
36#include "../../matrix_3d_h.hpp"
37#include "../../pfnc_buffer.hpp"
38#include "../../plane.hpp"
39#include "../../plane_3d.hpp"
40#include "../../point_2d.hpp"
41#include "../../point_3d.hpp"
42#include "../../point_3d_h.hpp"
43#include "../../rect.hpp"
44#include "../../rect_lt.hpp"
45#include "../../sparse_point_cloud.hpp"
46#include "../py_script.hpp"
56 inline HandleGuard<PyScript::Object>::HandleGuard(
void *handle) noexcept
57 : HandleGuard<PyScript::Object>(handle, [](
void *handle) { CVB_CALL_CAPI(
ReleaseObject(handle)); })
66 struct IsPod : std::false_type
71 struct IsPod<bool> : std::true_type
73 using StorageType = bool;
74 static constexpr auto TypeId = CExports::CVPYSOTY_Bool;
75 static constexpr size_t Size =
sizeof(bool);
79 struct IsPod<int8_t> : std::true_type
81 using StorageType = int64_t;
82 static constexpr auto TypeId = CExports::CVPYSOTY_Int64;
83 static constexpr size_t Size =
sizeof(int64_t);
87 struct IsPod<uint8_t> : std::true_type
89 using StorageType = uint64_t;
90 static constexpr auto TypeId = CExports::CVPYSOTY_UInt64;
91 static constexpr size_t Size =
sizeof(uint64_t);
95 struct IsPod<int16_t> : std::true_type
97 using StorageType = int64_t;
98 static constexpr auto TypeId = CExports::CVPYSOTY_Int64;
99 static constexpr size_t Size =
sizeof(int64_t);
103 struct IsPod<uint16_t> : std::true_type
105 using StorageType = uint64_t;
106 static constexpr auto TypeId = CExports::CVPYSOTY_UInt64;
107 static constexpr size_t Size =
sizeof(uint64_t);
111 struct IsPod<int32_t> : std::true_type
113 using StorageType = int64_t;
114 static constexpr auto TypeId = CExports::CVPYSOTY_Int64;
115 static constexpr size_t Size =
sizeof(int64_t);
119 struct IsPod<uint32_t> : std::true_type
121 using StorageType = uint64_t;
122 static constexpr auto TypeId = CExports::CVPYSOTY_UInt64;
123 static constexpr size_t Size =
sizeof(uint64_t);
127 struct IsPod<int64_t> : std::true_type
129 using StorageType = int64_t;
130 static constexpr auto TypeId = CExports::CVPYSOTY_Int64;
131 static constexpr size_t Size =
sizeof(int64_t);
135 struct IsPod<uint64_t> : std::true_type
137 using StorageType = uint64_t;
138 static constexpr auto TypeId = CExports::CVPYSOTY_UInt64;
139 static constexpr size_t Size =
sizeof(uint64_t);
143 struct IsPod<float> : std::true_type
145 using StorageType = double;
146 static constexpr auto TypeId = CExports::CVPYSOTY_Float64;
147 static constexpr size_t Size =
sizeof(double);
151 struct IsPod<double> : std::true_type
153 using StorageType = double;
154 static constexpr auto TypeId = CExports::CVPYSOTY_Float64;
155 static constexpr size_t Size =
sizeof(double);
158 template <
typename T>
159 struct IsHandleType : std::false_type
164 struct IsHandleType<Composite> : std::true_type
166 static constexpr auto TypeId = CExports::CVPYSOTY_Composite;
170 struct IsHandleType<DensePointCloud> : std::true_type
172 static constexpr auto TypeId = CExports::CVPYSOTY_DensePointCloud;
176 struct IsHandleType<Image> : std::true_type
178 static constexpr auto TypeId = CExports::CVPYSOTY_Image;
182 struct IsHandleType<MultiPartImage> : std::true_type
184 static constexpr auto TypeId = CExports::CVPYSOTY_MultiPartImage;
188 struct IsHandleType<PFNCBuffer> : std::true_type
190 static constexpr auto TypeId = CExports::CVPYSOTY_PfncBuffer;
194 struct IsHandleType<Plane> : std::true_type
196 static constexpr auto TypeId = CExports::CVPYSOTY_Plane;
200 struct IsHandleType<SparsePointCloud> : std::true_type
202 static constexpr auto TypeId = CExports::CVPYSOTY_SparsePointCloud;
206 struct IsHandleType<GenICamDevice> : std::true_type
208 static constexpr auto TypeId = CExports::CVPYSOTY_GenICamDevice;
212 struct IsHandleType<CompositeStream> : std::true_type
214 static constexpr auto TypeId = CExports::CVPYSOTY_CompositeStream;
218 struct IsHandleType<ImageStream> : std::true_type
220 static constexpr auto TypeId = CExports::CVPYSOTY_ImageStream;
224 struct IsHandleType<PointCloudStream> : std::true_type
226 static constexpr auto TypeId = CExports::CVPYSOTY_PointCloudStream;
230 struct IsHandleType<BooleanNode> : std::true_type
232 static constexpr auto TypeId = CExports::CVPYSOTY_BooleanNode;
236 struct IsHandleType<CategoryNode> : std::true_type
238 static constexpr auto TypeId = CExports::CVPYSOTY_CategoryNode;
242 struct IsHandleType<CommandNode> : std::true_type
244 static constexpr auto TypeId = CExports::CVPYSOTY_CommandNode;
248 struct IsHandleType<EnumEntryNode> : std::true_type
250 static constexpr auto TypeId = CExports::CVPYSOTY_EnumEntryNode;
254 struct IsHandleType<EnumerationNode> : std::true_type
256 static constexpr auto TypeId = CExports::CVPYSOTY_EnumerationNode;
260 struct IsHandleType<FloatNode> : std::true_type
262 static constexpr auto TypeId = CExports::CVPYSOTY_FloatNode;
266 struct IsHandleType<FloatRegNode> : std::true_type
268 static constexpr auto TypeId = CExports::CVPYSOTY_FloatRegNode;
272 struct IsHandleType<IntRegNode> : std::true_type
274 static constexpr auto TypeId = CExports::CVPYSOTY_IntRegNode;
278 struct IsHandleType<IntegerNode> : std::true_type
280 static constexpr auto TypeId = CExports::CVPYSOTY_IntegerNode;
284 struct IsHandleType<NodeMap> : std::true_type
286 static constexpr auto TypeId = CExports::CVPYSOTY_NodeMap;
290 struct IsHandleType<NodeMapEnumerator> : std::true_type
292 static constexpr auto TypeId = CExports::CVPYSOTY_NodeMapEnumerator;
296 struct IsHandleType<StringNode> : std::true_type
298 static constexpr auto TypeId = CExports::CVPYSOTY_StringNode;
302 struct IsHandleType<StringRegNode> : std::true_type
304 static constexpr auto TypeId = CExports::CVPYSOTY_StringRegNode;
307 template <
typename T>
308 struct IsCvbType : std::false_type
313 struct IsCvbType<
DataType> : std::true_type
315 static constexpr auto TypeId = CExports::CVPYSOTY_DataType;
319 struct IsCvbType<Circle> : std::true_type
321 static constexpr auto TypeId = CExports::CVPYSOTY_Circle;
325 struct IsCvbType<AffineMatrix2D> : std::true_type
327 static constexpr auto TypeId = CExports::CVPYSOTY_AffineMatrix2D;
331 struct IsCvbType<AffineMatrix3D> : std::true_type
333 static constexpr auto TypeId = CExports::CVPYSOTY_AffineMatrix3D;
337 struct IsCvbType<Angle> : std::true_type
339 static constexpr auto TypeId = CExports::CVPYSOTY_Angle;
343 struct IsCvbType<Cuboid> : std::true_type
345 static constexpr auto TypeId = CExports::CVPYSOTY_Cuboid;
349 struct IsCvbType<Line2D> : std::true_type
351 static constexpr auto TypeId = CExports::CVPYSOTY_Line2D;
355 struct IsCvbType<Matrix2D> : std::true_type
357 static constexpr auto TypeId = CExports::CVPYSOTY_Matrix2D;
361 struct IsCvbType<Matrix3DH> : std::true_type
363 static constexpr auto TypeId = CExports::CVPYSOTY_Matrix3DH;
367 struct IsCvbType<Matrix3D> : std::true_type
369 static constexpr auto TypeId = CExports::CVPYSOTY_Matrix3D;
373 struct IsCvbType<Plane3D> : std::true_type
375 static constexpr auto TypeId = CExports::CVPYSOTY_Plane3D;
379 struct IsCvbType<Point2D<double>> : std::true_type
381 static constexpr auto TypeId = CExports::CVPYSOTY_Point2D;
385 struct IsCvbType<Point3D<double>> : std::true_type
387 static constexpr auto TypeId = CExports::CVPYSOTY_Point3D;
391 struct IsCvbType<Point3DH<double>> : std::true_type
393 static constexpr auto TypeId = CExports::CVPYSOTY_Point3DH;
397 struct IsCvbType<Rect<double>> : std::true_type
399 static constexpr auto TypeId = CExports::CVPYSOTY_Rect;
403 struct IsCvbType<RectLT<double>> : std::true_type
405 static constexpr auto TypeId = CExports::CVPYSOTY_RectLT;
409 struct IsCvbType<Size2D<double>> : std::true_type
411 static constexpr auto TypeId = CExports::CVPYSOTY_Size2D;
415 struct IsCvbType<ValueRange<double>> : std::true_type
417 static constexpr auto TypeId = CExports::CVPYSOTY_ValueRange;
420 template <
typename T>
421 struct CanCastCvbType : std::false_type
426 struct CanCastCvbType<Point2D<int>> : std::true_type
428 using StorageType = Point2D<double>;
432 struct CanCastCvbType<Point3D<int>> : std::true_type
434 using StorageType = Point3D<double>;
438 struct CanCastCvbType<Rect<int>> : std::true_type
440 using StorageType = Rect<double>;
444 struct CanCastCvbType<RectLT<int>> : std::true_type
446 using StorageType = RectLT<double>;
450 struct CanCastCvbType<Size2D<int>> : std::true_type
452 using StorageType = Size2D<double>;
455 template <
typename T>
456 struct CanHandleUpCastType : std::false_type
461 struct CanHandleUpCastType<Image> : std::true_type
463 using StorageType = Image;
467 struct CanHandleUpCastType<RingBufferImage> : std::true_type
469 using StorageType = Image;
473 struct CanHandleUpCastType<BufferImage> : std::true_type
475 using StorageType = Image;
479 struct CanHandleUpCastType<StreamImage> : std::true_type
481 using StorageType = Image;
485 struct CanHandleUpCastType<WrappedImage> : std::true_type
487 using StorageType = Image;
491 struct CanHandleUpCastType<VinImage> : std::true_type
493 using StorageType = Image;
497 struct CanHandleUpCastType<VideoImage> : std::true_type
499 using StorageType = Image;
503 struct CanHandleUpCastType<EmuImage> : std::true_type
505 using StorageType = Image;
509 struct CanHandleUpCastType<DeviceImage> : std::true_type
511 using StorageType = Image;
515 struct CanHandleUpCastType<IntegerNode> : std::true_type
517 using StorageType = IntegerNode;
521 struct CanHandleUpCastType<FloatNode> : std::true_type
523 using StorageType = FloatNode;
527 struct CanHandleUpCastType<StringNode> : std::true_type
529 using StorageType = StringNode;
532 template <
class... T>
537 template <
typename T>
538 struct CanHandleDownCastType : std::false_type
543 struct CanHandleDownCastType<Image> : std::true_type
545 using List = DownCastList<MultiPartImage>;
549 struct CanHandleDownCastType<StreamImage> : std::true_type
551 using List = DownCastList<MultiPartImage>;
555 struct CanHandleDownCastType<Node> : std::true_type
557 using List = DownCastList<BooleanNode, CategoryNode, CommandNode, EnumerationNode, EnumEntryNode, FloatRegNode,
558 FloatNode, IntRegNode, IntegerNode, StringRegNode, StringNode>;
562 struct CanHandleDownCastType<ValueNode> : std::true_type
564 using List = DownCastList<BooleanNode, CategoryNode, CommandNode, EnumerationNode, EnumEntryNode, FloatRegNode,
565 FloatNode, IntRegNode, IntegerNode, StringRegNode, StringNode>;
569 struct CanHandleDownCastType<SelectorNode> : std::true_type
571 using List = DownCastList<EnumerationNode, IntRegNode, IntegerNode>;
575 struct CanHandleDownCastType<FloatNode> : std::true_type
577 using List = DownCastList<FloatRegNode>;
581 struct CanHandleDownCastType<IntegerNode> : std::true_type
583 using List = DownCastList<IntRegNode>;
587 struct CanHandleDownCastType<StringNode> : std::true_type
589 using List = DownCastList<StringRegNode>;
593 struct CanHandleDownCastType<PointCloud> : std::true_type
595 using List = DownCastList<SparsePointCloud, DensePointCloud>;
620 using GuardType = HandleGuard<Object>;
622 static ObjectPtr FromHandle(HandleGuard<Object> &&guard)
628 static ObjectPtr FromHandle(HandleGuard<Object> &&guard)
644 return CreateImpl(value, SelectCategory<T>{});
650 static_assert(Private::IsHandleType<T>::value || Private::CanHandleUpCastType<T>::value
651 || Private::CanHandleDownCastType<T>::value,
652 "T must be a handle type or castable");
681 template <
typename... T>
701 Object(HandleGuard<Object> &&guard, PrivateTag) noexcept
705 Object(
const Object &other) =
delete;
706 Object &operator=(
const Object &other) =
delete;
707 Object(Object &&other) =
delete;
708 Object &operator=(Object &&other) =
delete;
721 return Internal::DoResCallShareOut<Object>([
this, &attributeName](
void *&handle) {
722 return CVB_CALL_CAPI(CVPYSObjGetAttributeTyped(handle_.Handle(), attributeName.c_str(), handle));
734 return Internal::DoResCallShareOut<Object>([
this, &args](
void *&handle) {
735 return CVB_CALL_CAPI(CVPYSObjRun(handle_.Handle(), args.
Handle(), handle));
746 return Internal::DoResCallShareOut<Object>(
747 [
this](
void *&handle) {
return CVB_CALL_CAPI(CVPYSObjRun(handle_.Handle(),
nullptr, handle)); });
759 size_t elementCount = 0;
760 CVB_CALL_CAPI_CHECKED(CVPYSObjElementCount(handle_.Handle(), elementCount));
772 void Set(
size_t index,
const Object &obj)
774 CVB_CALL_CAPI_CHECKED(CVPYSObjElementSet(handle_.Handle(), index, obj.
Handle()));
787 return Internal::DoResCallShareOut<Object>([
this, index](
void *&handle) {
788 return CVB_CALL_CAPI(CVPYSObjElementGet(handle_.Handle(), index, handle));
803 return AsImpl<T>::Run(*
this, SelectCategory<T>{});
814 return handle_.Handle();
818 template <
class LAST>
819 void ImplMakeTuple(
size_t &index, LAST &&last)
825 template <
class FIRST,
class... T>
826 void ImplMakeTuple(
size_t &index, FIRST &&first, T &&...args)
840 struct HandleDownCastTag
843 struct HandleUpCastTag
865 using SelectCategory =
typename std::conditional<
866 Private::IsPod<T>::value, PodTag,
867 typename std::conditional<
868 std::is_enum<T>::value, EnumTag,
869 typename std::conditional<
870 Private::IsCvbType<T>::value, CvbTag,
871 typename std::conditional<
872 Private::CanCastCvbType<T>::value, CanCastCvbTag,
873 typename std::conditional<
874 Private::CanHandleDownCastType<T>::value, HandleDownCastTag,
875 typename std::conditional<Private::CanHandleUpCastType<T>::value, HandleUpCastTag,
876 typename std::conditional<Private::IsHandleType<T>::value,
877 HandleTag, DefaultTag>::type>::type>::
878 type>::type>::type>::type>::type;
884 static T
Run(
const Object &
object, PodTag)
886 CExports::CVPYSObjType type = Private::IsPod<T>::TypeId;
887 typename Private::IsPod<T>::StorageType value = {};
888 size_t size = Private::IsPod<T>::Size;
889 CVB_CALL_CAPI_CHECKED(CVPYSObjToBuffer(
object.
Handle(), type, &value, size));
890 return static_cast<T
>(value);
893 static T
Run(
const Object &
object, EnumTag)
895 return static_cast<T
>(
object.As<int64_t>());
898 static T
Run(
const Object &
object, CvbTag)
900 CExports::CVPYSObjType type = Private::IsCvbType<T>::TypeId;
902 size_t size =
sizeof(T);
903 CVB_CALL_CAPI_CHECKED(CVPYSObjToBuffer(
object.
Handle(), type, &value, size));
907 static T
Run(
const Object &
object, CanCastCvbTag)
909 return Cvb::Round(AsImpl<
typename Private::CanCastCvbType<T>::StorageType>
::Run(
object, CvbTag{}));
914 struct AsImpl<std::shared_ptr<T>>
916 static std::shared_ptr<T>
Run(
const Object &
object, DefaultTag)
918 static_assert(Private::IsHandleType<T>::value,
"T must be a handle type");
919 return Internal::DoResCallShareOut<T>([&
object](
void *&handle) {
920 CExports::CVPYSObjType type = Private::IsHandleType<T>::TypeId;
921 size_t size =
sizeof(
void *);
922 return CVPYSObjToBuffer(
object.
Handle(), type, &handle, size);
929 static ObjectPtr CreateImpl(
const T &value, PodTag);
932 static std::shared_ptr<Object> CreateImpl(
const T &value, HandleTag);
935 static std::shared_ptr<Object> CreateImpl(
const T &value, EnumTag);
938 static std::shared_ptr<Object> CreateImpl(
const T &value, CvbTag);
941 static std::shared_ptr<Object> CreateImpl(
const T &value, CanCastCvbTag)
943 return CreateImpl(
static_cast<typename Private::CanCastCvbType<T>::StorageType
>(value), CvbTag{});
947 static std::shared_ptr<Object> CreateImpl(
const T &value, HandleUpCastTag)
949 return CreateImpl(
dynamic_cast<const typename Private::CanHandleUpCastType<T>::StorageType &
>(value),
956 static std::shared_ptr<Object> CreateImpl(
const T &value, HandleDownCastTag)
958 return CreateImpl(value,
typename Private::CanHandleDownCastType<T>::List{});
961 template <
class T,
class DCT_FIRST,
class... DCT_TAIL>
962 static std::shared_ptr<Object> CreateImpl(
const T &value, Private::DownCastList<DCT_FIRST, DCT_TAIL...>)
964 if (
auto *ptr =
dynamic_cast<const DCT_FIRST *
>(&value))
965 return CreateImpl(*ptr, HandleTag{});
967 return CreateImpl(value, Private::DownCastList<DCT_TAIL...>{});
971# pragma warning(push)
972# pragma warning(disable : 4702)
974 template <
class T,
class DCT_LAST>
975 static std::shared_ptr<Object> CreateImpl(
const T &value, Private::DownCastList<DCT_LAST>)
979 if (
auto *ptr =
dynamic_cast<const DCT_LAST *
>(&value))
980 return CreateImpl(*ptr, HandleTag{});
982 return CreateImpl(value, HandleUpCastTag{});
988 HandleGuard<Object> handle_;
992 struct Object::AsImpl<std::shared_ptr<Image>>
994 static std::shared_ptr<Image>
Run(
const Object &
object, DefaultTag)
996 CExports::CVPYSObjType type = CExports::CVPYSOTY_Image;
997 void *handle =
nullptr;
998 size_t size =
sizeof(
void *);
999 CVB_CALL_CAPI_CHECKED(CVPYSObjToBuffer(
object.
Handle(), type, &handle, size));
1003 throw std::runtime_error(
"invalid image");
1005 case CExports::CVPYSOTY_Image:
1007 case CExports::CVPYSOTY_MultiPartImage:
1014 struct Object::AsImpl<std::shared_ptr<Node>>
1016 static std::shared_ptr<Node>
Run(
const Object &
object, DefaultTag)
1018 CExports::CVPYSObjType type = CExports::CVPYSOTY_Node;
1019 void *handle =
nullptr;
1020 size_t size =
sizeof(
void *);
1021 CVB_CALL_CAPI_CHECKED(CVPYSObjToBuffer(
object.
Handle(), type, &handle, size));
1025 throw std::runtime_error(
"invalid node");
1027 case CExports::CVPYSOTY_BooleanNode:
1028 return BooleanNode::FromHandle<BooleanNode>(HandleGuard<Node>(handle));
1029 case CExports::CVPYSOTY_CategoryNode:
1030 return CategoryNode::FromHandle<CategoryNode>(HandleGuard<Node>(handle));
1031 case CExports::CVPYSOTY_CommandNode:
1032 return CommandNode::FromHandle<CommandNode>(HandleGuard<Node>(handle));
1033 case CExports::CVPYSOTY_EnumerationNode:
1034 return EnumerationNode::FromHandle<EnumerationNode>(HandleGuard<Node>(handle));
1035 case CExports::CVPYSOTY_EnumEntryNode:
1036 return EnumEntryNode::FromHandle<EnumEntryNode>(HandleGuard<Node>(handle));
1037 case CExports::CVPYSOTY_FloatRegNode:
1038 return FloatRegNode::FromHandle<FloatRegNode>(HandleGuard<Node>(handle));
1039 case CExports::CVPYSOTY_FloatNode:
1040 return FloatNode::FromHandle<FloatNode>(HandleGuard<Node>(handle));
1041 case CExports::CVPYSOTY_IntRegNode:
1042 return IntRegNode::FromHandle<IntRegNode>(HandleGuard<Node>(handle));
1043 case CExports::CVPYSOTY_IntegerNode:
1044 return IntegerNode::FromHandle<IntegerNode>(HandleGuard<Node>(handle));
1045 case CExports::CVPYSOTY_StringRegNode:
1046 return StringRegNode::FromHandle<StringRegNode>(HandleGuard<Node>(handle));
1047 case CExports::CVPYSOTY_StringNode:
1048 return StringNode::FromHandle<StringNode>(HandleGuard<Node>(handle));
1054 struct Object::AsImpl<std::shared_ptr<ValueNode>>
1056 static std::shared_ptr<ValueNode>
Run(
const Object &
object, DefaultTag tag)
1058 auto node = std::dynamic_pointer_cast<ValueNode>(AsImpl<std::shared_ptr<Node>>
::Run(
object, tag));
1060 throw std::runtime_error(
"no valid value node");
1066 struct Object::AsImpl<std::shared_ptr<FloatNode>>
1068 static std::shared_ptr<FloatNode>
Run(
const Object &
object, DefaultTag tag)
1070 auto node = std::dynamic_pointer_cast<FloatNode>(AsImpl<std::shared_ptr<Node>>
::Run(
object, tag));
1072 throw std::runtime_error(
"no valid float node");
1078 struct Object::AsImpl<std::shared_ptr<IntegerNode>>
1080 static std::shared_ptr<IntegerNode>
Run(
const Object &
object, DefaultTag tag)
1082 auto node = std::dynamic_pointer_cast<IntegerNode>(AsImpl<std::shared_ptr<Node>>
::Run(
object, tag));
1084 throw std::runtime_error(
"no valid integer node");
1090 struct Object::AsImpl<std::shared_ptr<SelectorNode>>
1092 static std::shared_ptr<SelectorNode>
Run(
const Object &
object, DefaultTag tag)
1094 auto node = std::dynamic_pointer_cast<SelectorNode>(AsImpl<std::shared_ptr<Node>>
::Run(
object, tag));
1096 throw std::runtime_error(
"no valid selector node");
1102 struct Object::AsImpl<std::shared_ptr<StringNode>>
1104 static std::shared_ptr<StringNode>
Run(
const Object &
object, DefaultTag tag)
1106 auto node = std::dynamic_pointer_cast<StringNode>(AsImpl<std::shared_ptr<Node>>
::Run(
object, tag));
1108 throw std::runtime_error(
"no valid string node");
1114 struct Object::AsImpl<std::shared_ptr<PointCloud>>
1116 static std::shared_ptr<PointCloud>
Run(
const Object &
object, DefaultTag)
1118 CExports::CVPYSObjType type = CExports::CVPYSOTY_PointCloud;
1119 void *handle =
nullptr;
1120 size_t size =
sizeof(
void *);
1121 CVB_CALL_CAPI_CHECKED(CVPYSObjToBuffer(
object.
Handle(), type, &handle, size));
1125 throw std::runtime_error(
"invalid point cloud");
1127 case CExports::CVPYSOTY_DensePointCloud:
1128 return DensePointCloud::FromHandle<DensePointCloud>(HandleGuard<PointCloud>(handle));
1129 case CExports::CVPYSOTY_SparsePointCloud:
1130 return SparsePointCloud::FromHandle<SparsePointCloud>(HandleGuard<PointCloud>(handle));
1137 [[noreturn]]
inline std::shared_ptr<Object> Object::CreateImpl<Node>(
const Node &value, HandleUpCastTag)
1140 throw std::runtime_error(
"cannot create from Cvb::Node");
1145 [[noreturn]]
inline std::shared_ptr<Object> Object::CreateImpl<ValueNode>(
const ValueNode &value, HandleUpCastTag)
1148 throw std::runtime_error(
"cannot create from Cvb::ValueNode");
1153 [[noreturn]]
inline std::shared_ptr<Object> Object::CreateImpl<SelectorNode>(
const SelectorNode &value,
1157 throw std::runtime_error(
"cannot create from Cvb::SelectorNode");
1162 [[noreturn]]
inline std::shared_ptr<Object> Object::CreateImpl<PointCloud>(
const PointCloud &value, HandleUpCastTag)
1165 throw std::runtime_error(
"cannot create from Cvb::PointClouds");
static std::unique_ptr< Image > FromHandle(HandleGuard< Image > &&guard)
Creates an image from a classic API handle.
Definition decl_image.hpp:160
Variant like python object.
Definition decl_object.hpp:614
ObjectPtr Get(size_t index) const
Get an element from this object.
Definition decl_object.hpp:785
ObjectPtr Run(const Object &args)
Runs the object as callable.
Definition decl_object.hpp:732
void Set(size_t index, const Object &obj)
Set an element in this object.
Definition decl_object.hpp:772
static ObjectPtr MakeTuple(T &&...args)
Creates tuple with the given types.
Definition decl_object.hpp:682
static std::shared_ptr< Object > MakeVoidList(size_t size)
Creates list with a specified size.
Definition detail_object.hpp:21
ObjectPtr Attribute(const Cvb::String &attributeName)
Gets an attribute of the object as object.
Definition decl_object.hpp:719
static std::shared_ptr< Object > Create(const T &value)
Creates a object form any supported type.
Definition decl_object.hpp:642
T As() const
Get an type from this object.
Definition decl_object.hpp:801
ObjectPtr Run()
Runs the object as callable.
Definition decl_object.hpp:744
size_t ElementCount() const
Number of elements in this object.
Definition decl_object.hpp:757
void * Handle() const noexcept
Classic API buffer handle.
Definition decl_object.hpp:812
static ObjectPtr MakeVoidTuple(size_t size)
Creates tuple with a specified size.
Definition detail_object.hpp:14
cvbbool_t ReleaseObject(OBJ &Object)
@ Size
Area of the blob in pixels.
Definition blob.hpp:56
Namespace for the python scripting package.
Definition decl_context.hpp:21
std::shared_ptr< Object > ObjectPtr
Convenience shared pointer for Object.
Definition py_script.hpp:127
@ DataType
Definition spectral.hpp:148
Root namespace for the Image Manager interface.
Definition version.hpp:11
std::string String
String for wide characters or unicode characters.
Definition string.hpp:49
Point2D< int > Round(const Point2D< T > &rhs) noexcept
Round to an integer point.
Definition point_2d.hpp:371