Raytracing: Added function to rescale a luxrender matrix

This commit is contained in:
Yorik van Havre 2013-09-25 18:26:04 -03:00
parent 382a12f55f
commit 66d8950d57
3 changed files with 36 additions and 2 deletions

View File

@ -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}
};

View File

@ -37,7 +37,9 @@
#include <Base/Console.h>
#include <Base/Exception.h>
#include <Base/Sequencer.h>
#include <Base/Matrix.h>
#include <App/ComplexGeoData.h>
#include <boost/regex.hpp>
#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();
}

View File

@ -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