From 66d8950d57b64940055d433a86c499beb9dcab48 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Wed, 25 Sep 2013 18:26:04 -0300 Subject: [PATCH] Raytracing: Added function to rescale a luxrender matrix --- src/Mod/Raytracing/App/AppRaytracingPy.cpp | 18 ++++++++++++++++-- src/Mod/Raytracing/App/LuxTools.cpp | 18 ++++++++++++++++++ src/Mod/Raytracing/App/LuxTools.h | 2 ++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/Mod/Raytracing/App/AppRaytracingPy.cpp b/src/Mod/Raytracing/App/AppRaytracingPy.cpp index 8891db4885..e759eb4343 100644 --- a/src/Mod/Raytracing/App/AppRaytracingPy.cpp +++ b/src/Mod/Raytracing/App/AppRaytracingPy.cpp @@ -238,6 +238,19 @@ copyResource(PyObject *self, PyObject *args) Py_Return; } +/// rescales a lux matrix +static PyObject * +scaleLuxMatrix(PyObject *self, PyObject *args) +{ + float factor; + const char *mat; + if (! PyArg_ParseTuple(args, "sf", &mat, &factor)) + return NULL; + std::string result, luxmatrix(mat); + result = LuxTools::rescaleMatrix(luxmatrix, factor); + return Py::new_reference_to(Py::String(result)); +} + /* registration table */ struct PyMethodDef Raytracing_methods[] = { {"writeProjectFile", writeProjectFile, 1}, @@ -245,9 +258,10 @@ struct PyMethodDef Raytracing_methods[] = { {"writePartFile", writePartFile , 1}, {"writePartFileCSV", writePartFileCSV, 1}, {"getPartAsPovray", getPartAsPovray , 1}, - {"getPartAsLux", getPartAsLux , 1}, - {"writeDataFile", writeDataFile , 1}, + {"getPartAsLux", getPartAsLux , 1}, + {"writeDataFile", writeDataFile , 1}, {"writeCameraFile", writeCameraFile , 1}, {"copyResource", copyResource , 1}, + {"scaleLuxMatrix", scaleLuxMatrix , 1}, {NULL, NULL} }; diff --git a/src/Mod/Raytracing/App/LuxTools.cpp b/src/Mod/Raytracing/App/LuxTools.cpp index 22eef40480..861f0a8bae 100644 --- a/src/Mod/Raytracing/App/LuxTools.cpp +++ b/src/Mod/Raytracing/App/LuxTools.cpp @@ -37,7 +37,9 @@ #include #include #include +#include #include +#include #include "PovTools.h" @@ -135,3 +137,19 @@ void LuxTools::writeShape(std::ostream &out, const char *PartName, const TopoDS_ out << " \"string name\" [\"" << PartName << "\"]" << endl; out << "AttributeEnd # \"\"" << endl; } + +std::string LuxTools::rescaleMatrix(std::string mat, float factor) +{ + // clean the input string + std::string matstring = mat.substr(11); + unsigned pos = matstring.find("]"); + matstring = matstring.substr(0,pos); + // create a matrix and rescale it + Base::Matrix4D trans; + trans.fromString(matstring); + trans.scale(factor,factor,factor); + // create output + std::stringstream result; + result << "Transform [" << trans.toString() << "]" << endl; + return result.str(); +} diff --git a/src/Mod/Raytracing/App/LuxTools.h b/src/Mod/Raytracing/App/LuxTools.h index d00cae657d..c02e2de0fe 100644 --- a/src/Mod/Raytracing/App/LuxTools.h +++ b/src/Mod/Raytracing/App/LuxTools.h @@ -41,6 +41,8 @@ namespace Raytracing static std::string getCamera(const CamDef& Cam); /// returns the given shape as luxrender material + shape data static void writeShape(std::ostream &out, const char *PartName, const TopoDS_Shape& Shape, float fMeshDeviation=0.1); + /// rescales a lux matrix by the given factor + static std::string rescaleMatrix(std::string mat, float factor); }; } // namespace Raytracing