Skip to content

Commit 4e4d499

Browse files
peter-targettrameshm
authored and
rameshm
committed
Add AnyDictionary and AnyVector support for V2d and Box2d (#1811)
* Add AnyDictionary and AnyVector support for V2d and Box2d Signed-off-by: Peter Targett <[email protected]> --------- Signed-off-by: Peter Targett <[email protected]>
1 parent 13b5454 commit 4e4d499

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

src/py-opentimelineio/opentimelineio-bindings/otio_bindings.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "opentimelineio/typeRegistry.h"
1515
#include "opentimelineio/stackAlgorithm.h"
1616

17+
#include <ImathBox.h>
18+
1719
namespace py = pybind11;
1820
using namespace pybind11::literals;
1921

@@ -270,6 +272,8 @@ PYBIND11_MODULE(_otio, m) {
270272
.def(py::init([](RationalTime rt) { return new PyAny(rt); }))
271273
.def(py::init([](TimeRange tr) { return new PyAny(tr); }))
272274
.def(py::init([](TimeTransform tt) { return new PyAny(tt); }))
275+
.def(py::init([](IMATH_NAMESPACE::V2d v2d) { return new PyAny(v2d); }))
276+
.def(py::init([](IMATH_NAMESPACE::Box2d box2d) { return new PyAny(box2d); }))
273277
.def(py::init([](AnyVectorProxy* p) { return new PyAny(p->fetch_any_vector()); }))
274278
.def(py::init([](AnyDictionaryProxy* p) { return new PyAny(p->fetch_any_dictionary()); }))
275279
;

src/py-opentimelineio/opentimelineio-bindings/otio_utils.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include "opentimelineio/safely_typed_any.h"
1212
#include "opentimelineio/stringUtils.h"
1313

14+
#include <ImathBox.h>
15+
1416
#include <map>
1517
#include <cstring>
1618

@@ -60,6 +62,8 @@ void _build_any_to_py_dispatch_table() {
6062
t[&typeid(RationalTime)] = [](std::any const& a, bool) { return py::cast(safely_cast_rational_time_any(a)); };
6163
t[&typeid(TimeRange)] = [](std::any const& a, bool) { return py::cast(safely_cast_time_range_any(a)); };
6264
t[&typeid(TimeTransform)] = [](std::any const& a, bool) { return py::cast(safely_cast_time_transform_any(a)); };
65+
t[&typeid(IMATH_NAMESPACE::V2d)] = [](std::any const& a, bool) { return py::cast(safely_cast_point_any(a)); };
66+
t[&typeid(IMATH_NAMESPACE::Box2d)] = [](std::any const& a, bool) { return py::cast(safely_cast_box_any(a)); };
6367
t[&typeid(SerializableObject::Retainer<>)] = [](std::any const& a, bool) {
6468
SerializableObject* so = safely_cast_retainer_any(a);
6569
return py::cast(managing_ptr<SerializableObject>(so)); };

tests/test_composable.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ def test_constructor(self):
1919
self.assertEqual(seqi.metadata, {'foo': 'bar'})
2020

2121
def test_serialize(self):
22+
b = otio.schema.Box2d(
23+
otio.schema.V2d(0.0, 0.0), otio.schema.V2d(16.0, 9.0))
2224
seqi = otio.core.Composable(
2325
name="test",
24-
metadata={"foo": "bar"}
26+
metadata={"box": b}
2527
)
2628
encoded = otio.adapters.otio_json.write_to_string(seqi)
2729
decoded = otio.adapters.otio_json.read_from_string(encoded)

tests/test_serializable_object.py

+10
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,16 @@ def test_cycle_detection(self):
136136
with self.assertRaises(ValueError):
137137
o.clone()
138138

139+
def test_imath(self):
140+
b = otio.schema.Box2d(
141+
otio.schema.V2d(0.0, 0.0), otio.schema.V2d(16.0, 9.0))
142+
so = otio.core.SerializableObjectWithMetadata()
143+
so.metadata["box"] = b
144+
self.assertEqual(repr(so.metadata["box"]), repr(b))
145+
v = [b.min, b.max]
146+
so.metadata["vectors"] = v
147+
self.assertEqual(repr(so.metadata["vectors"]), repr(v))
148+
139149

140150
class VersioningTests(unittest.TestCase, otio_test_utils.OTIOAssertions):
141151
def test_schema_definition(self):

0 commit comments

Comments
 (0)