Skip to content

Commit

Permalink
PyOCIO: Fix AllocationTransform __str__, cleanup params (#1042)
Browse files Browse the repository at this point in the history
* Add defStr to transform classes, cleanup param names

Signed-off-by: Michael Dolan <[email protected]>

* Update unit test params

Signed-off-by: Michael Dolan <[email protected]>

* Update param name in DisplayViewTransform test

Signed-off-by: Michael Dolan <[email protected]>
  • Loading branch information
michdolan authored Jul 1, 2020
1 parent 3ada94a commit b220590
Show file tree
Hide file tree
Showing 35 changed files with 205 additions and 168 deletions.
16 changes: 9 additions & 7 deletions src/bindings/python/PyAllocationTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ std::vector<float> getVarsStdVec(const AllocationTransformRcPtr & p)
return vars;
}

void setVars(const AllocationTransformRcPtr & p, const std::vector<float> & vars)
void setVars(AllocationTransformRcPtr & p, const std::vector<float> & vars)
{
if (vars.size() < 2 || vars.size() > 3)
{
Expand All @@ -31,28 +31,28 @@ void bindPyAllocationTransform(py::module & m)
{
AllocationTransformRcPtr DEFAULT = AllocationTransform::Create();

py::class_<AllocationTransform,
AllocationTransformRcPtr /* holder */,
Transform /* base */>(m, "AllocationTransform")
auto cls = py::class_<AllocationTransform,
AllocationTransformRcPtr /* holder */,
Transform /* base */>(m, "AllocationTransform")
.def(py::init(&AllocationTransform::Create))
.def(py::init([](Allocation allocation,
const std::vector<float> & vars,
TransformDirection dir)
{
AllocationTransformRcPtr p = AllocationTransform::Create();
p->setAllocation(allocation);
setVars(p, vars);
if (!vars.empty()) { setVars(p, vars); }
p->setDirection(dir);
p->validate();
return p;
}),
"allocation"_a = DEFAULT->getAllocation(),
"vars"_a = getVarsStdVec(DEFAULT),
"dir"_a = DEFAULT->getDirection())
"direction"_a = DEFAULT->getDirection())

.def("getAllocation", &AllocationTransform::getAllocation)
.def("setAllocation", &AllocationTransform::setAllocation, "allocation"_a)
.def("getVars", [](AllocationTransformRcPtr & self)
.def("getVars", [](AllocationTransformRcPtr self)
{
return getVarsStdVec(self);
})
Expand All @@ -61,6 +61,8 @@ void bindPyAllocationTransform(py::module & m)
setVars(self, vars);
},
"vars"_a);

defStr(cls);
}

} // namespace OCIO_NAMESPACE
4 changes: 2 additions & 2 deletions src/bindings/python/PyBaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ void bindPyBaker(py::module & m)
.def("getTargetSpace", &Baker::getTargetSpace)
.def("setTargetSpace", &Baker::setTargetSpace, "targetSpace"_a)
.def("getShaperSize", &Baker::getShaperSize)
.def("setShaperSize", &Baker::setShaperSize, "shapersize"_a)
.def("setShaperSize", &Baker::setShaperSize, "shaperSize"_a)
.def("getCubeSize", &Baker::getCubeSize)
.def("setCubeSize", &Baker::setCubeSize, "cubesize"_a)
.def("setCubeSize", &Baker::setCubeSize, "cubeSize"_a)
.def("bake", [](BakerRcPtr & self, const std::string & fileName)
{
std::ofstream f(fileName.c_str());
Expand Down
10 changes: 6 additions & 4 deletions src/bindings/python/PyBuiltinTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ void bindPyBuiltinTransform(py::module & m)
{
BuiltinTransformRcPtr DEFAULT = BuiltinTransform::Create();

py::class_<BuiltinTransform,
BuiltinTransformRcPtr /* holder */,
Transform /* base */>(m, "BuiltinTransform")
auto cls = py::class_<BuiltinTransform,
BuiltinTransformRcPtr /* holder */,
Transform /* base */>(m, "BuiltinTransform")
.def(py::init(&BuiltinTransform::Create))
.def(py::init([](const std::string & style, TransformDirection dir)
{
Expand All @@ -23,11 +23,13 @@ void bindPyBuiltinTransform(py::module & m)
return p;
}),
"style"_a = DEFAULT->getStyle(),
"dir"_a = DEFAULT->getDirection())
"direction"_a = DEFAULT->getDirection())

.def("setStyle", &BuiltinTransform::setStyle, "style"_a.none(false))
.def("getStyle", &BuiltinTransform::getStyle)
.def("getDescription", &BuiltinTransform::getDescription);

defStr(cls);
}

} // namespace OCIO_NAMESPACE
18 changes: 10 additions & 8 deletions src/bindings/python/PyCDLTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ void bindPyCDLTransform(py::module & m)
std::array<double, 3> DEFAULT_POWER;
DEFAULT->getPower(DEFAULT_POWER.data());

py::class_<CDLTransform,
CDLTransformRcPtr /* holder */,
Transform /* base */>(m, "CDLTransform")
auto cls = py::class_<CDLTransform,
CDLTransformRcPtr /* holder */,
Transform /* base */>(m, "CDLTransform")
.def(py::init(&CDLTransform::Create))
.def(py::init([](const std::string & xml, TransformDirection dir)
{
Expand All @@ -32,7 +32,7 @@ void bindPyCDLTransform(py::module & m)
return p;
}),
"xml"_a,
"dir"_a = DEFAULT->getDirection())
"direction"_a = DEFAULT->getDirection())
.def(py::init([](const std::array<double, 3> & slope,
const std::array<double, 3> & offset,
const std::array<double, 3> & power,
Expand All @@ -57,10 +57,10 @@ void bindPyCDLTransform(py::module & m)
"power"_a = DEFAULT_POWER,
"sat"_a = DEFAULT->getSat(),
"id"_a = DEFAULT->getID(),
"desc"_a = DEFAULT->getDescription(),
"dir"_a = DEFAULT->getDirection())
"description"_a = DEFAULT->getDescription(),
"direction"_a = DEFAULT->getDirection())

.def_static("CreateFromFile", &CDLTransform::CreateFromFile, "src"_a, "cccid"_a)
.def_static("CreateFromFile", &CDLTransform::CreateFromFile, "src"_a, "id"_a)

.def("getFormatMetadata",
(FormatMetadata & (CDLTransform::*)()) &CDLTransform::getFormatMetadata,
Expand Down Expand Up @@ -129,7 +129,9 @@ void bindPyCDLTransform(py::module & m)
.def("getID", &CDLTransform::getID)
.def("setID", &CDLTransform::setID, "id"_a)
.def("getDescription", &CDLTransform::getDescription)
.def("setDescription", &CDLTransform::setDescription, "desc"_a);
.def("setDescription", &CDLTransform::setDescription, "description"_a);

defStr(cls);
}

} // namespace OCIO_NAMESPACE
4 changes: 2 additions & 2 deletions src/bindings/python/PyColorSpace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ void bindPyColorSpace(py::module & m)
"vars"_a)

// Transform
.def("getTransform", &ColorSpace::getTransform, "dir"_a)
.def("setTransform", &ColorSpace::setTransform, "transform"_a, "dir"_a);
.def("getTransform", &ColorSpace::getTransform, "direction"_a)
.def("setTransform", &ColorSpace::setTransform, "transform"_a, "direction"_a);

defStr(cls);

Expand Down
8 changes: 4 additions & 4 deletions src/bindings/python/PyColorSpaceSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ void bindPyColorSpaceSet(py::module & m)
return ColorSpaceIterator(self);
})
.def("getColorSpace", &ColorSpaceSet::getColorSpace, "name"_a)
.def("addColorSpace", &ColorSpaceSet::addColorSpace, "cs"_a)
.def("addColorSpaces", &ColorSpaceSet::addColorSpaces, "cs"_a)
.def("removeColorSpace", &ColorSpaceSet::removeColorSpace, "cs"_a)
.def("removeColorSpaces", &ColorSpaceSet::removeColorSpaces, "cs"_a)
.def("addColorSpace", &ColorSpaceSet::addColorSpace, "colorSpace"_a)
.def("addColorSpaces", &ColorSpaceSet::addColorSpaces, "colorSpace"_a)
.def("removeColorSpace", &ColorSpaceSet::removeColorSpace, "colorSpace"_a)
.def("removeColorSpaces", &ColorSpaceSet::removeColorSpaces, "colorSpace"_a)
.def("clearColorSpaces", &ColorSpaceSet::clearColorSpaces);

py::class_<ColorSpaceNameIterator>(cls, "ColorSpaceNameIterator")
Expand Down
8 changes: 5 additions & 3 deletions src/bindings/python/PyColorSpaceTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ void bindPyColorSpaceTransform(py::module & m)
{
ColorSpaceTransformRcPtr DEFAULT = ColorSpaceTransform::Create();

py::class_<ColorSpaceTransform,
ColorSpaceTransformRcPtr /* holder */,
Transform /* base */>(m, "ColorSpaceTransform")
auto cls = py::class_<ColorSpaceTransform,
ColorSpaceTransformRcPtr /* holder */,
Transform /* base */>(m, "ColorSpaceTransform")
.def(py::init(&ColorSpaceTransform::Create))
.def(py::init([](const std::string & src,
const std::string & dst,
Expand All @@ -38,6 +38,8 @@ void bindPyColorSpaceTransform(py::module & m)
.def("setDst", &ColorSpaceTransform::setDst, "dst"_a)
.def("getDataBypass", &ColorSpaceTransform::getDataBypass)
.def("setDataBypass", &ColorSpaceTransform::setDataBypass, "dataBypass"_a);

defStr(cls);
}

} // namespace OCIO_NAMESPACE
6 changes: 3 additions & 3 deletions src/bindings/python/PyConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void bindPyConfig(py::module & m)

.def_static("CreateRaw", &Config::CreateRaw)
.def_static("CreateFromEnv", &Config::CreateFromEnv)
.def_static("CreateFromFile", &Config::CreateFromFile, "filename"_a)
.def_static("CreateFromFile", &Config::CreateFromFile, "fileName"_a)
.def_static("CreateFromStream", [](const std::string & str)
{
std::istringstream is(str);
Expand Down Expand Up @@ -119,7 +119,7 @@ void bindPyConfig(py::module & m)
.def("clearSearchPaths", &Config::clearSearchPaths)
.def("addSearchPath", &Config::addSearchPath, "path"_a)
.def("getWorkingDir", &Config::getWorkingDir)
.def("setWorkingDir", &Config::setWorkingDir, "dirname"_a)
.def("setWorkingDir", &Config::setWorkingDir, "dirName"_a)

// ColorSpaces
.def("getColorSpaces", &Config::getColorSpaces, "category"_a)
Expand All @@ -146,7 +146,7 @@ void bindPyConfig(py::module & m)
{
return ActiveColorSpaceIterator(self);
})
.def("addColorSpace", &Config::addColorSpace, "cs"_a)
.def("addColorSpace", &Config::addColorSpace, "colorSpace"_a)
.def("removeColorSpace", &Config::removeColorSpace, "name"_a)
.def("isColorSpaceUsed", &Config::isColorSpaceUsed, "name"_a)
.def("clearColorSpaces", &Config::clearColorSpaces)
Expand Down
6 changes: 3 additions & 3 deletions src/bindings/python/PyContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ void bindPyContext(py::module & m)
.def("clearSearchPaths", &Context::clearSearchPaths)
.def("addSearchPath", &Context::addSearchPath, "path"_a)
.def("getWorkingDir", &Context::getWorkingDir)
.def("setWorkingDir", &Context::setWorkingDir, "dirname"_a)
.def("setWorkingDir", &Context::setWorkingDir, "dirName"_a)
.def("getStringVars", [](ContextRcPtr & self) { return StringVarIterator(self); })
.def("clearStringVars", &Context::clearStringVars)
.def("getEnvironmentMode", &Context::getEnvironmentMode)
.def("setEnvironmentMode", &Context::setEnvironmentMode, "mode"_a)
.def("loadEnvironment", &Context::loadEnvironment)
.def("resolveStringVar", &Context::resolveStringVar, "val"_a)
.def("resolveFileLocation", &Context::resolveFileLocation, "filename"_a);
.def("resolveStringVar", &Context::resolveStringVar, "value"_a)
.def("resolveFileLocation", &Context::resolveFileLocation, "fileName"_a);

defStr(cls);

Expand Down
10 changes: 6 additions & 4 deletions src/bindings/python/PyDisplayViewTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ void bindPyDisplayViewTransform(py::module & m)
{
DisplayViewTransformRcPtr DEFAULT = DisplayViewTransform::Create();

py::class_<DisplayViewTransform,
DisplayViewTransformRcPtr /* holder */,
Transform /* base */>(m, "DisplayViewTransform")
auto cls = py::class_<DisplayViewTransform,
DisplayViewTransformRcPtr /* holder */,
Transform /* base */>(m, "DisplayViewTransform")
.def(py::init(&DisplayViewTransform::Create))
.def(py::init([](const std::string & src,
const std::string & display,
Expand All @@ -36,7 +36,7 @@ void bindPyDisplayViewTransform(py::module & m)
"view"_a = DEFAULT->getView(),
"looksBypass"_a = DEFAULT->getLooksBypass(),
"dataBypass"_a = DEFAULT->getDataBypass(),
"dir"_a = DEFAULT->getDirection())
"direction"_a = DEFAULT->getDirection())

.def("getSrc", &DisplayViewTransform::getSrc)
.def("setSrc", &DisplayViewTransform::setSrc, "src"_a)
Expand All @@ -48,6 +48,8 @@ void bindPyDisplayViewTransform(py::module & m)
.def("setLooksBypass", &DisplayViewTransform::setLooksBypass, "looksBypass"_a)
.def("getDataBypass", &DisplayViewTransform::getDataBypass)
.def("setDataBypass", &DisplayViewTransform::setDataBypass, "dataBypass"_a);

defStr(cls);
}

} // namespace OCIO_NAMESPACE
18 changes: 10 additions & 8 deletions src/bindings/python/PyExponentTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ void bindPyExponentTransform(py::module & m)
{
ExponentTransformRcPtr DEFAULT = ExponentTransform::Create();

std::array<double, 4> DEFAULT_VEC4;
DEFAULT->getValue(*reinterpret_cast<double(*)[4]>(DEFAULT_VEC4.data()));
std::array<double, 4> DEFAULT_VALUE;
DEFAULT->getValue(*reinterpret_cast<double(*)[4]>(DEFAULT_VALUE.data()));

py::class_<ExponentTransform,
ExponentTransformRcPtr /* holder */,
Transform /* base */>(m, "ExponentTransform")
auto cls = py::class_<ExponentTransform,
ExponentTransformRcPtr /* holder */,
Transform /* base */>(m, "ExponentTransform")
.def(py::init(&ExponentTransform::Create))
.def(py::init([](const std::array<double, 4> & vec4,
NegativeStyle negativeStyle,
Expand All @@ -28,9 +28,9 @@ void bindPyExponentTransform(py::module & m)
p->validate();
return p;
}),
"vec4"_a = DEFAULT_VEC4,
"value"_a = DEFAULT_VALUE,
"negativeStyle"_a = DEFAULT->getNegativeStyle(),
"dir"_a = DEFAULT->getDirection())
"direction"_a = DEFAULT->getDirection())

.def("getFormatMetadata",
(FormatMetadata & (ExponentTransform::*)()) &ExponentTransform::getFormatMetadata,
Expand All @@ -50,9 +50,11 @@ void bindPyExponentTransform(py::module & m)
{
self->setValue(*reinterpret_cast<const double(*)[4]>(vec4.data()));
},
"vec4"_a)
"value"_a)
.def("getNegativeStyle", &ExponentTransform::getNegativeStyle)
.def("setNegativeStyle", &ExponentTransform::setNegativeStyle, "style"_a);

defStr(cls);
}

} // namespace OCIO_NAMESPACE
10 changes: 6 additions & 4 deletions src/bindings/python/PyExponentWithLinearTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ void bindPyExponentWithLinearTransform(py::module & m)
std::array<double, 4> DEFAULT_OFFSET;
DEFAULT->getOffset(*reinterpret_cast<double(*)[4]>(DEFAULT_OFFSET.data()));

py::class_<ExponentWithLinearTransform,
ExponentWithLinearTransformRcPtr /* holder */,
Transform /* base */>(m, "ExponentWithLinearTransform")
auto cls = py::class_<ExponentWithLinearTransform,
ExponentWithLinearTransformRcPtr /* holder */,
Transform /* base */>(m, "ExponentWithLinearTransform")
.def(py::init(&ExponentWithLinearTransform::Create))
.def(py::init([](const std::array<double, 4> & gamma,
const std::array<double, 4> & offset,
Expand All @@ -36,7 +36,7 @@ void bindPyExponentWithLinearTransform(py::module & m)
"gamma"_a = DEFAULT_GAMMA,
"offset"_a = DEFAULT_OFFSET,
"negativeStyle"_a = DEFAULT->getNegativeStyle(),
"dir"_a = DEFAULT->getDirection())
"direction"_a = DEFAULT->getDirection())

.def("getFormatMetadata",
(FormatMetadata & (ExponentWithLinearTransform::*)())
Expand Down Expand Up @@ -73,6 +73,8 @@ void bindPyExponentWithLinearTransform(py::module & m)
"values"_a)
.def("getNegativeStyle", &ExponentWithLinearTransform::getNegativeStyle)
.def("setNegativeStyle", &ExponentWithLinearTransform::setNegativeStyle, "style"_a);

defStr(cls);
}

} // namespace OCIO_NAMESPACE
10 changes: 6 additions & 4 deletions src/bindings/python/PyExposureContrastTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ void bindPyExposureContrastTransform(py::module & m)
{
ExposureContrastTransformRcPtr DEFAULT = ExposureContrastTransform::Create();

py::class_<ExposureContrastTransform,
ExposureContrastTransformRcPtr /* holder */,
Transform /* base */>(m, "ExposureContrastTransform")
auto cls = py::class_<ExposureContrastTransform,
ExposureContrastTransformRcPtr /* holder */,
Transform /* base */>(m, "ExposureContrastTransform")
.def(py::init(&ExposureContrastTransform::Create))
.def(py::init([](ExposureContrastStyle style,
double exposure,
Expand Down Expand Up @@ -50,7 +50,7 @@ void bindPyExposureContrastTransform(py::module & m)
"dynamicExposure"_a = DEFAULT->isExposureDynamic(),
"dynamicContrast"_a = DEFAULT->isContrastDynamic(),
"dynamicGamma"_a = DEFAULT->isGammaDynamic(),
"dir"_a = DEFAULT->getDirection())
"direction"_a = DEFAULT->getDirection())

.def("getFormatMetadata",
(FormatMetadata & (ExposureContrastTransform::*)())
Expand Down Expand Up @@ -82,6 +82,8 @@ void bindPyExposureContrastTransform(py::module & m)
"logExposureStep"_a)
.def("getLogMidGray", &ExposureContrastTransform::getLogMidGray)
.def("setLogMidGray", &ExposureContrastTransform::setLogMidGray, "logMidGray"_a);

defStr(cls);
}

} // namespace OCIO_NAMESPACE
12 changes: 7 additions & 5 deletions src/bindings/python/PyFileTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,22 @@ void bindPyFileTransform(py::module & m)
return p;
}),
"src"_a = DEFAULT->getSrc(),
"id"_a = DEFAULT->getCCCId(),
"interp"_a = DEFAULT->getInterpolation(),
"dir"_a = DEFAULT->getDirection())
"cccId"_a = DEFAULT->getCCCId(),
"interpolation"_a = DEFAULT->getInterpolation(),
"direction"_a = DEFAULT->getDirection())

.def_static("getFormats", []() { return FormatIterator(nullptr); })

.def("getSrc", &FileTransform::getSrc)
.def("setSrc", &FileTransform::setSrc, "src"_a)
.def("getCCCId", &FileTransform::getCCCId)
.def("setCCCId", &FileTransform::setCCCId, "id"_a)
.def("setCCCId", &FileTransform::setCCCId, "cccId"_a)
.def("getCDLStyle", &FileTransform::getCDLStyle)
.def("setCDLStyle", &FileTransform::setCDLStyle, "style"_a)
.def("getInterpolation", &FileTransform::getInterpolation)
.def("setInterpolation", &FileTransform::setInterpolation, "interp"_a);
.def("setInterpolation", &FileTransform::setInterpolation, "interpolation"_a);

defStr(cls);

py::class_<FormatIterator>(cls, "FormatIterator")
.def("__len__", [](FormatIterator & it) { return FileTransform::getNumFormats(); })
Expand Down
Loading

0 comments on commit b220590

Please sign in to comment.