Skip to content

Commit

Permalink
api: Add TypeDesc::Vector3i (#4316)
Browse files Browse the repository at this point in the history
Like the existing Vector2i, but, you know, 3.

Along the way, fixed a bug in the way the Vector2i type is represented
as a string.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
  • Loading branch information
lgritz authored Jul 2, 2024
1 parent 7c486a1 commit 14a395b
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/doc/imageioapi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ in the outer OpenImageIO scope:
TypeMatrix33 TypeMatrix44 TypeMatrix TypeHalf
TypeInt TypeUInt TypeInt32 TypeUInt32 TypeInt64 TypeUInt64
TypeInt16 TypeUInt16 TypeInt8 TypeUInt8
TypeFloat2 TypeVector2 TypeVector2i TypeFloat4
TypeFloat2 TypeVector2 TypeVector2i TypeVector3i TypeFloat4
TypeString TypeTimeCode TypeKeyCode
TypeBox2 TypeBox2i TypeBox3 TypeBox3i
TypeRational TypePointer
Expand Down
3 changes: 2 additions & 1 deletion src/doc/pythonbindings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ described in detail in Section :ref:`sec-typedesc`, is replicated for Python.
.. py:data:: TypeUnknown TypeString TypeFloat TypeHalf
TypeInt TypeUInt TypeInt16 TypeUInt16
TypeColor TypePoint TypeVector TypeNormal
TypeFloat2 TypeVector2 TypeFloat4 TypeVector2i
TypeFloat2 TypeVector2 TypeFloat4
TypeVector2i TypeVector3i
TypeMatrix TypeMatrix33
TypeTimeCode TypeKeyCode TypeRational TypePointer
Expand Down
2 changes: 2 additions & 0 deletions src/include/OpenImageIO/typedesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ OIIO_INLINE_CONSTEXPR TypeDesc TypeUInt8 (TypeDesc::UINT8);
OIIO_INLINE_CONSTEXPR TypeDesc TypeInt64 (TypeDesc::INT64);
OIIO_INLINE_CONSTEXPR TypeDesc TypeUInt64 (TypeDesc::UINT64);
OIIO_INLINE_CONSTEXPR TypeDesc TypeVector2i(TypeDesc::INT, TypeDesc::VEC2);
OIIO_INLINE_CONSTEXPR TypeDesc TypeVector3i(TypeDesc::INT, TypeDesc::VEC3);
OIIO_INLINE_CONSTEXPR TypeDesc TypeBox2(TypeDesc::FLOAT, TypeDesc::VEC2, TypeDesc::BOX, 2);
OIIO_INLINE_CONSTEXPR TypeDesc TypeBox3(TypeDesc::FLOAT, TypeDesc::VEC3, TypeDesc::BOX, 2);
OIIO_INLINE_CONSTEXPR TypeDesc TypeBox2i(TypeDesc::INT, TypeDesc::VEC2, TypeDesc::BOX, 2);
Expand Down Expand Up @@ -483,6 +484,7 @@ template<> struct TypeDescFromC<Imath::V3f> { static const constexpr TypeDesc va
template<> struct TypeDescFromC<Imath::V2f> { static const constexpr TypeDesc value() { return TypeVector2; } };
template<> struct TypeDescFromC<Imath::V4f> { static const constexpr TypeDesc value() { return TypeVector4; } };
template<> struct TypeDescFromC<Imath::V2i> { static const constexpr TypeDesc value() { return TypeVector2i; } };
template<> struct TypeDescFromC<Imath::V3i> { static const constexpr TypeDesc value() { return TypeVector3i; } };
#endif
#ifdef INCLUDED_IMATHCOLOR_H
template<> struct TypeDescFromC<Imath::Color3f> { static const constexpr TypeDesc value() { return TypeColor; } };
Expand Down
18 changes: 17 additions & 1 deletion src/libutil/typedesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ TypeDesc::c_str() const
// result = "float2";
// else if (aggregate == VEC4 && basetype == FLOAT && vecsemantics == NOXFORM)
// result = "float4";
else if (vecsemantics == NOXFORM) {
else if (vecsemantics == NOXFORM && basetype == FLOAT) {
switch (aggregate) {
case VEC2: result = "float2"; break;
case VEC3: result = "float3"; break;
Expand All @@ -198,6 +198,22 @@ TypeDesc::c_str() const
}
if (basetype != FLOAT)
result += basetype_code[basetype];
} else if (vecsemantics == NOXFORM) {
switch (aggregate) {
case VEC2:
case VEC3:
case VEC4:
result = Strutil::fmt::format("vector{}{}", int(aggregate),
basetype_code[basetype]);
break;
case MATRIX33:
result = Strutil::fmt::format("matrix33{}",
basetype_code[basetype]);
break;
case MATRIX44:
result = Strutil::fmt::format("matrix{}", basetype_code[basetype]);
break;
}
} else {
// Special names for vector semantics
const char* vec = "";
Expand Down
2 changes: 2 additions & 0 deletions src/python/py_typedesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ declare_typedesc(py::module& m)
.def_readonly_static("TypeFloat2", &TypeFloat2)
.def_readonly_static("TypeVector2", &TypeVector2)
.def_readonly_static("TypeVector2i", &TypeVector2i)
.def_readonly_static("TypeVector3i", &TypeVector3i)
.def_readonly_static("TypeFloat4", &TypeFloat4)
.def_readonly_static("TypeVector4", &TypeVector4);

Expand Down Expand Up @@ -192,6 +193,7 @@ declare_typedesc(py::module& m)
m.attr("TypeFloat4") = TypeFloat4;
m.attr("TypeVector4") = TypeVector4;
m.attr("TypeVector2i") = TypeVector2i;
m.attr("TypeVector3i") = TypeVector3i;
m.attr("TypeBox2") = TypeBox2;
m.attr("TypeBox3") = TypeBox3;
m.attr("TypeBox2i") = TypeBox2i;
Expand Down
8 changes: 6 additions & 2 deletions testsuite/python-typedesc/ref/out-python2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ type 'TypeFloat4'
type 'TypeVector4'
c_str "float4"
type 'TypeVector2i'
c_str "float2i"
c_str "int2"
type 'TypeVector3i'
c_str "int3"
type 'TypeHalf'
c_str "half"

Expand Down Expand Up @@ -249,7 +251,9 @@ type 'TypeFloat4'
type 'TypeVector4'
c_str "float4"
type 'TypeVector2i'
c_str "float2i"
c_str "vector2i"
type 'TypeVector3i'
c_str "vector3i"
type 'TypeHalf'
c_str "half"
type 'TypeRational'
Expand Down
8 changes: 6 additions & 2 deletions testsuite/python-typedesc/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ type 'TypeFloat4'
type 'TypeVector4'
c_str "float4"
type 'TypeVector2i'
c_str "float2i"
c_str "vector2i"
type 'TypeVector3i'
c_str "vector3i"
type 'TypeHalf'
c_str "half"

Expand Down Expand Up @@ -249,7 +251,9 @@ type 'TypeFloat4'
type 'TypeVector4'
c_str "float4"
type 'TypeVector2i'
c_str "float2i"
c_str "vector2i"
type 'TypeVector3i'
c_str "vector3i"
type 'TypeHalf'
c_str "half"
type 'TypeRational'
Expand Down
2 changes: 2 additions & 0 deletions testsuite/python-typedesc/src/test_typedesc.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def breakdown_test(t, name="", verbose=True):
breakdown_test (oiio.TypeDesc.TypeFloat4, "TypeFloat4", verbose=False)
breakdown_test (oiio.TypeDesc.TypeVector4, "TypeVector4", verbose=False)
breakdown_test (oiio.TypeDesc.TypeVector2i, "TypeVector2i", verbose=False)
breakdown_test (oiio.TypeDesc.TypeVector3i, "TypeVector3i", verbose=False)
breakdown_test (oiio.TypeDesc.TypeHalf, "TypeHalf", verbose=False)
print ("")

Expand Down Expand Up @@ -189,6 +190,7 @@ def breakdown_test(t, name="", verbose=True):
breakdown_test (oiio.TypeFloat4, "TypeFloat4", verbose=False)
breakdown_test (oiio.TypeVector4, "TypeVector4", verbose=False)
breakdown_test (oiio.TypeVector2i, "TypeVector2i", verbose=False)
breakdown_test (oiio.TypeVector3i, "TypeVector3i", verbose=False)
breakdown_test (oiio.TypeHalf, "TypeHalf", verbose=False)
breakdown_test (oiio.TypeRational, "TypeRational", verbose=False)
breakdown_test (oiio.TypeUInt, "TypeUInt", verbose=False)
Expand Down

0 comments on commit 14a395b

Please sign in to comment.