PyObject* py_snapshot(PyObject* self, PyObject* args) { static PythonParameterParser tester(1); std::string filename, canvasName = ""; if (tester.parse(args, filename, canvasName)== -1) { return nullptr; } CanvasProcessor* canvas = nullptr; if (canvasName.size() != 0) { canvas = dynamic_cast<CanvasProcessor*>( InviwoApplication::getPtr()->getProcessorNetwork()->getProcessorByIdentifier( canvasName)); } else { if (InviwoApplication::getPtr() && InviwoApplication::getPtr()->getProcessorNetwork()) { std::vector<CanvasProcessor*> canvases = InviwoApplication::getPtr() ->getProcessorNetwork() ->getProcessorsByType<CanvasProcessor>(); if (canvases.size() != 0) canvas = InviwoApplication::getPtr() ->getProcessorNetwork() ->getProcessorsByType<CanvasProcessor>()[0]; } } if (!canvas) { PyErr_SetString(PyExc_TypeError, "snapshot() no canvas found"); return nullptr; } canvas->saveImageLayer(filename.c_str()); Py_RETURN_NONE; }
PyObject* py_snapshot(PyObject* /*self*/, PyObject* args) { static PySnapshotMethod p; if (!p.testParams(args)) return nullptr; std::string canvasName = ""; std::string filename = std::string(PyValueParser::parse<std::string>(PyTuple_GetItem(args, 0))); if (PyTuple_Size(args) == 2) { canvasName = std::string(PyValueParser::parse<std::string>(PyTuple_GetItem(args, 1))); } CanvasProcessor* canvas = nullptr; if (canvasName.size() != 0) { canvas = dynamic_cast<CanvasProcessor*>( InviwoApplication::getPtr()->getProcessorNetwork()->getProcessorByIdentifier(canvasName)); } else { if (InviwoApplication::getPtr() && InviwoApplication::getPtr()->getProcessorNetwork()) { std::vector<CanvasProcessor*> canvases = InviwoApplication::getPtr() ->getProcessorNetwork() ->getProcessorsByType<CanvasProcessor>(); if (canvases.size() != 0) canvas = InviwoApplication::getPtr() ->getProcessorNetwork() ->getProcessorsByType<CanvasProcessor>()[0]; } } if (!canvas) { PyErr_SetString(PyExc_TypeError, "snapshot() no canvas found"); return nullptr; } canvas->saveImageLayer(filename.c_str()); Py_RETURN_NONE; }
PyObject* py_resizecanvas(PyObject* /*self*/, PyObject* args) { static PythonParameterParser tester; PyObject* arg0; int w; int h; if (tester.parse(args,arg0, w, h) == -1) { return nullptr; } CanvasProcessor* canvas = nullptr; bool argIsString = PyValueParser::is<std::string>(arg0); if (argIsString) { std::string id = PyValueParser::parse<std::string>(arg0); Processor* processor = InviwoApplication::getPtr()->getProcessorNetwork()->getProcessorByIdentifier(id); if (!processor) { std::string msg = std::string("resizeCanvas(canvas,width,height) no processor with name: ") + id; PyErr_SetString(PyExc_TypeError, msg.c_str()); return nullptr; } canvas = dynamic_cast<CanvasProcessor*>(processor); if (!canvas) { std::string msg = std::string("resizeCanvas(canvas,width,height) processor with name: ") + id + " is not a canvas processor, it is a" + processor->getClassIdentifier(); PyErr_SetString(PyExc_TypeError, msg.c_str()); return nullptr; } } else { int id = PyValueParser::parse<int>(arg0); std::vector<CanvasProcessor*> canvases = InviwoApplication::getPtr() ->getProcessorNetwork() ->getProcessorsByType<CanvasProcessor>(); if (canvases.size() == 0) { std::string msg = std::string( "resizeCanvas(canvas,width,height) no canvases found in current network"); PyErr_SetString(PyExc_TypeError, msg.c_str()); return nullptr; } if (static_cast<int>(canvases.size()) <= id) { std::string msg = std::string( "resizeCanvas(canvas,width,height) index out of bounds, index given: ") + toString(id) + ", max index possible: " + toString(canvases.size() - 1); PyErr_SetString(PyExc_TypeError, msg.c_str()); return nullptr; } canvas = canvases[id]; } if (w <= 0 || h <= 0) { std::string msg = std::string( "resizeCanvas(canvas,width,height) width and height must have positive non-zero " "values"); PyErr_SetString(PyExc_TypeError, msg.c_str()); return nullptr; } canvas->setCanvasSize(ivec2(w, h)); //canvas->invalidate(InvalidationLevel::InvalidOutput); Py_RETURN_NONE; }