void Node::deleteNodeVariableToPython(const std::string& nodeName) { #ifdef NATRON_RUN_WITHOUT_PYTHON return; #endif if (getScriptName_mt_safe().empty()) { return; } AppInstancePtr app = getApp(); if (!app) { return; } QString appID = QString::fromUtf8( getApp()->getAppIDString().c_str() ); std::string nodeFullName = appID.toStdString() + "." + nodeName; bool alreadyDefined = false; PyObject* nodeObj = NATRON_PYTHON_NAMESPACE::getAttrRecursive(nodeFullName, appPTR->getMainModule(), &alreadyDefined); assert(nodeObj); Q_UNUSED(nodeObj); if (alreadyDefined) { std::string script = "del " + nodeFullName; std::string err; if ( !appPTR->isBackground() ) { getApp()->printAutoDeclaredVariable(script); } if ( !NATRON_PYTHON_NAMESPACE::interpretPythonScript(script, &err, 0) ) { qDebug() << err.c_str(); } } }
void QtWriter::initializeKnobs() { Dialogs::warningDialog( getScriptName_mt_safe(), QObject::tr("This plugin exists only to help the developpers team to test %1" ". You cannot use it to render a project.").arg(NATRON_APPLICATION_NAME).toStdString() ); _premultKnob = getNode()->createKnob<KnobBool>( QObject::tr("Premultiply by alpha").toStdString() ); _premultKnob->setAnimationEnabled(false); _premultKnob->setDefaultValue(false, 0); _fileKnob = getNode()->createKnob<KnobOutputFile>("File"); _fileKnob->setAsOutputImageFile(); _frameRangeChoosal = getNode()->createKnob<KnobChoice>( QObject::tr("Frame range").toStdString() ); _frameRangeChoosal->setAnimationEnabled(false); std::vector<std::string> frameRangeChoosalEntries; frameRangeChoosalEntries.push_back( QObject::tr("Union of input ranges").toStdString() ); frameRangeChoosalEntries.push_back( QObject::tr("Timeline bounds").toStdString() ); frameRangeChoosalEntries.push_back( QObject::tr("Manual").toStdString() ); _frameRangeChoosal->populateChoices(frameRangeChoosalEntries); _frameRangeChoosal->setDefaultValue(1, 0); _firstFrameKnob = getNode()->createKnob<KnobInt>( QObject::tr("First frame").toStdString() ); _firstFrameKnob->setAnimationEnabled(false); _firstFrameKnob->setSecretByDefault(true); _lastFrameKnob = getNode()->createKnob<KnobInt>( QObject::tr("Last frame").toStdString() ); _lastFrameKnob->setAnimationEnabled(false); _lastFrameKnob->setSecretByDefault(true); _renderKnob = getNode()->createKnob<KnobButton>( QObject::tr("Render").toStdString() ); _renderKnob->setAsRenderButton(); }
void Node::declareTablePythonFields() { KnobItemsTablePtr table = _imp->effect->getItemsTable(); if (!table) { return; } if (getScriptName_mt_safe().empty()) { return; } table->declareItemsToPython(); }
void Node::declareNodeVariableToPython(const std::string& nodeName) { #ifdef NATRON_RUN_WITHOUT_PYTHON return; #endif if (getScriptName_mt_safe().empty()) { return; } PythonGILLocker pgl; PyObject* mainModule = appPTR->getMainModule(); assert(mainModule); std::string appID = getApp()->getAppIDString(); std::string nodeFullName = appID + "." + nodeName; bool alreadyDefined = false; PyObject* nodeObj = NATRON_PYTHON_NAMESPACE::getAttrRecursive(nodeFullName, mainModule, &alreadyDefined); assert(nodeObj); Q_UNUSED(nodeObj); if (!alreadyDefined) { std::stringstream ss; ss << nodeFullName << " = " << appID << ".getNode(\"" << nodeName << "\")\n"; #ifdef DEBUG ss << "if not " << nodeFullName << ":\n"; ss << " print \"[BUG]: " << nodeFullName << " does not exist!\""; #endif std::string script = ss.str(); std::string output; std::string err; if ( !appPTR->isBackground() ) { getApp()->printAutoDeclaredVariable(script); } if ( !NATRON_PYTHON_NAMESPACE::interpretPythonScript(script, &err, &output) ) { qDebug() << err.c_str(); } } }
void Node::setNodeVariableToPython(const std::string& oldName, const std::string& newName) { #ifdef NATRON_RUN_WITHOUT_PYTHON return; #endif if (getScriptName_mt_safe().empty()) { return; } QString appID = QString::fromUtf8( getApp()->getAppIDString().c_str() ); QString str = QString( appID + QString::fromUtf8(".%1 = ") + appID + QString::fromUtf8(".%2\ndel ") + appID + QString::fromUtf8(".%2\n") ).arg( QString::fromUtf8( newName.c_str() ) ).arg( QString::fromUtf8( oldName.c_str() ) ); std::string script = str.toStdString(); std::string err; if ( !appPTR->isBackground() ) { getApp()->printAutoDeclaredVariable(script); } if ( !NATRON_PYTHON_NAMESPACE::interpretPythonScript(script, &err, 0) ) { qDebug() << err.c_str(); } }
void Node::removeParameterFromPython(const std::string& parameterName) { #ifdef NATRON_RUN_WITHOUT_PYTHON return; #endif if (getScriptName_mt_safe().empty()) { return; } PythonGILLocker pgl; std::string appID = getApp()->getAppIDString(); std::string nodeName; if (getIOContainer()) { nodeName = getIOContainer()->getFullyQualifiedName(); } else { nodeName = getFullyQualifiedName(); } std::string nodeFullName = appID + "." + nodeName; bool alreadyDefined = false; PyObject* nodeObj = NATRON_PYTHON_NAMESPACE::getAttrRecursive(nodeFullName, NATRON_PYTHON_NAMESPACE::getMainModule(), &alreadyDefined); assert(nodeObj); Q_UNUSED(nodeObj); if (!alreadyDefined) { qDebug() << QString::fromUtf8("removeParameterFromPython(): attribute ") + QString::fromUtf8( nodeFullName.c_str() ) + QString::fromUtf8(" is not defined"); throw std::logic_error(std::string("removeParameterFromPython(): attribute ") + nodeFullName + " is not defined"); } assert( PyObject_HasAttrString( nodeObj, parameterName.c_str() ) ); std::string script = "del " + nodeFullName + "." + parameterName; if ( !appPTR->isBackground() ) { getApp()->printAutoDeclaredVariable(script); } std::string err; if ( !NATRON_PYTHON_NAMESPACE::interpretPythonScript(script, &err, 0) ) { qDebug() << err.c_str(); } }
void Node::declarePythonKnobs() { #ifdef NATRON_RUN_WITHOUT_PYTHON return; #endif if (getScriptName_mt_safe().empty()) { return; } PythonGILLocker pgl; if ( !getGroup() ) { return; } std::locale locale; std::string nodeName; if (getIOContainer()) { nodeName = getIOContainer()->getFullyQualifiedName(); } else { nodeName = getFullyQualifiedName(); } std::string appID = getApp()->getAppIDString(); bool alreadyDefined = false; std::string nodeFullName = appID + "." + nodeName; PyObject* nodeObj = NATRON_PYTHON_NAMESPACE::getAttrRecursive(nodeFullName, NATRON_PYTHON_NAMESPACE::getMainModule(), &alreadyDefined); assert(nodeObj); Q_UNUSED(nodeObj); if (!alreadyDefined) { qDebug() << QString::fromUtf8("declarePythonKnobs(): attribute ") + QString::fromUtf8( nodeFullName.c_str() ) + QString::fromUtf8(" is not defined"); throw std::logic_error(std::string("declarePythonKnobs(): attribute ") + nodeFullName + " is not defined"); } std::stringstream ss; #ifdef DEBUG ss << "if not " << nodeFullName << ":\n"; ss << " print \"[BUG]: " << nodeFullName << " is not defined!\"\n"; #endif const KnobsVec& knobs = getKnobs(); for (U32 i = 0; i < knobs.size(); ++i) { const std::string& knobName = knobs[i]->getName(); if ( !knobName.empty() && (knobName.find(" ") == std::string::npos) && !std::isdigit(knobName[0], locale) ) { if ( PyObject_HasAttrString( nodeObj, knobName.c_str() ) ) { continue; } ss << nodeFullName << "." << knobName << " = "; ss << nodeFullName << ".getParam(\"" << knobName << "\")\n"; } } std::string script = ss.str(); if ( !script.empty() ) { if ( !appPTR->isBackground() ) { getApp()->printAutoDeclaredVariable(script); } std::string err; std::string output; if ( !NATRON_PYTHON_NAMESPACE::interpretPythonScript(script, &err, &output) ) { qDebug() << err.c_str(); } } } // Node::declarePythonFields
void OutputEffectInstance::reportStats(int time, ViewIdx view, double wallTime, const std::map<NodePtr, NodeRenderStats > & stats) { std::string filename; KnobPtr fileKnob = getKnobByName(kOfxImageEffectFileParamName); if (fileKnob) { KnobOutputFile* strKnob = dynamic_cast<KnobOutputFile*>( fileKnob.get() ); if (strKnob) { QString qfileName = QString::fromUtf8( SequenceParsing::generateFileNameFromPattern(strKnob->getValue( 0, ViewIdx(view) ), getApp()->getProject()->getProjectViewNames(), time, view).c_str() ); QtCompat::removeFileExtension(qfileName); qfileName.append( QString::fromUtf8("-stats.txt") ); filename = qfileName.toStdString(); } } //If there's no filename knob, do not write anything if ( filename.empty() ) { std::cout << tr("Cannot write render statistics file: " "%1 does not seem to have a parameter named \"filename\" " "to determine the location where to write the stats file.") .arg( QString::fromUtf8( getScriptName_mt_safe().c_str() ) ).toStdString(); return; } FStreamsSupport::ofstream ofile; FStreamsSupport::open(&ofile, filename); if (!ofile) { std::cout << tr("Failure to write render statistics file.").toStdString() << std::endl; return; } ofile << "Time spent to render frame (wall clock time): " << Timer::printAsTime(wallTime, false).toStdString() << std::endl; for (std::map<NodePtr, NodeRenderStats >::const_iterator it = stats.begin(); it != stats.end(); ++it) { ofile << "------------------------------- " << it->first->getScriptName_mt_safe() << "------------------------------- " << std::endl; ofile << "Time spent rendering: " << Timer::printAsTime(it->second.getTotalTimeSpentRendering(), false).toStdString() << std::endl; const RectD & rod = it->second.getRoD(); ofile << "Region of definition: x1 = " << rod.x1 << " y1 = " << rod.y1 << " x2 = " << rod.x2 << " y2 = " << rod.y2 << std::endl; ofile << "Is Identity to Effect? "; NodePtr identity = it->second.getInputImageIdentity(); if (identity) { ofile << "Yes, to " << identity->getScriptName_mt_safe() << std::endl; } else { ofile << "No" << std::endl; } ofile << "Has render-scale support? "; if ( it->second.isRenderScaleSupportEnabled() ) { ofile << "Yes"; } else { ofile << "No"; } ofile << std::endl; ofile << "Has tiles support? "; if ( it->second.isTilesSupportEnabled() ) { ofile << "Yes"; } else { ofile << "No"; } ofile << std::endl; ofile << "Channels processed: "; std::bitset<4> processChannels = it->second.getChannelsRendered(); if (processChannels[0]) { ofile << "red "; } if (processChannels[1]) { ofile << "green "; } if (processChannels[2]) { ofile << "blue "; } if (processChannels[3]) { ofile << "alpha"; } ofile << std::endl; ofile << "Output alpha premultiplication: "; switch ( it->second.getOutputPremult() ) { case eImagePremultiplicationOpaque: ofile << "opaque"; break; case eImagePremultiplicationPremultiplied: ofile << "premultiplied"; break; case eImagePremultiplicationUnPremultiplied: ofile << "unpremultiplied"; break; } ofile << std::endl; ofile << "Mipmap level(s) rendered: "; for (std::set<unsigned int>::const_iterator it2 = it->second.getMipMapLevelsRendered().begin(); it2 != it->second.getMipMapLevelsRendered().end(); ++it2) { ofile << *it2 << ' '; } ofile << std::endl; int nbCacheMiss, nbCacheHit, nbCacheHitButDownscaled; it->second.getCacheAccessInfos(&nbCacheMiss, &nbCacheHit, &nbCacheHitButDownscaled); ofile << "Nb cache hit: " << nbCacheMiss << std::endl; ofile << "Nb cache miss: " << nbCacheMiss << std::endl; ofile << "Nb cache hit requiring mipmap downscaling: " << nbCacheHitButDownscaled << std::endl; const std::set<std::string> & planes = it->second.getPlanesRendered(); ofile << "Plane(s) rendered: "; for (std::set<std::string>::const_iterator it2 = planes.begin(); it2 != planes.end(); ++it2) { ofile << *it2 << ' '; } ofile << std::endl; std::list<std::pair<RectI, NodePtr > > identityRectangles = it->second.getIdentityRectangles(); const std::list<RectI> & renderedRectangles = it->second.getRenderedRectangles(); ofile << "Identity rectangles: " << identityRectangles.size() << std::endl; for (std::list<std::pair<RectI, NodePtr > > ::iterator it2 = identityRectangles.begin(); it2 != identityRectangles.end(); ++it2) { ofile << "Origin: " << it2->second->getScriptName_mt_safe() << ", rect: x1 = " << it2->first.x1 << " y1 = " << it2->first.y1 << " x2 = " << it2->first.x2 << " y2 = " << it2->first.y2 << std::endl; } ofile << "Rectangles rendered: " << renderedRectangles.size() << std::endl; for (std::list<RectI>::const_iterator it2 = renderedRectangles.begin(); it2 != renderedRectangles.end(); ++it2) { ofile << "x1 = " << it2->x1 << " y1 = " << it2->y1 << " x2 = " << it2->x2 << " y2 = " << it2->y2 << std::endl; } } } // OutputEffectInstance::reportStats