mirror of
https://github.com/lucaspalomodevelop/meshlab.git
synced 2026-03-19 19:14:42 +00:00
iXMLfilter member function removed
This commit is contained in:
parent
b6bd1e1751
commit
cf6abffe0c
@ -52,38 +52,19 @@ QDomDocument FilterScript::xmlDoc()
|
||||
|
||||
for(FilterScript::iterator ii=filtparlist.begin();ii!= filtparlist.end();++ii)
|
||||
{
|
||||
if (!(*ii)->isXMLFilter())
|
||||
OldFilterNameParameterValuesPair* oldpv = reinterpret_cast<OldFilterNameParameterValuesPair*>(*ii);
|
||||
QDomElement tag = doc.createElement("filter");
|
||||
QPair<QString,RichParameterSet>& pair = oldpv->pair;
|
||||
tag.setAttribute(QString("name"),pair.first);
|
||||
RichParameterSet &par=pair.second;
|
||||
QList<RichParameter*>::iterator jj;
|
||||
RichParameterXMLVisitor v(doc);
|
||||
for(jj=par.paramList.begin();jj!=par.paramList.end();++jj)
|
||||
{
|
||||
OldFilterNameParameterValuesPair* oldpv = reinterpret_cast<OldFilterNameParameterValuesPair*>(*ii);
|
||||
QDomElement tag = doc.createElement("filter");
|
||||
QPair<QString,RichParameterSet>& pair = oldpv->pair;
|
||||
tag.setAttribute(QString("name"),pair.first);
|
||||
RichParameterSet &par=pair.second;
|
||||
QList<RichParameter*>::iterator jj;
|
||||
RichParameterXMLVisitor v(doc);
|
||||
for(jj=par.paramList.begin();jj!=par.paramList.end();++jj)
|
||||
{
|
||||
(*jj)->accept(v);
|
||||
tag.appendChild(v.parElem);
|
||||
}
|
||||
root.appendChild(tag);
|
||||
}
|
||||
else
|
||||
{
|
||||
XMLFilterNameParameterValuesPair* xmlpv = reinterpret_cast<XMLFilterNameParameterValuesPair*>(*ii);
|
||||
QDomElement tag = doc.createElement("xmlfilter");
|
||||
QPair<QString, QMap<QString,QString> >& pair = xmlpv->pair;
|
||||
tag.setAttribute(QString("name"),pair.first);
|
||||
QMap<QString,QString>& tmpmap = pair.second;
|
||||
for(QMap<QString,QString>::const_iterator itm = tmpmap.constBegin();itm != tmpmap.constEnd();++itm)
|
||||
{
|
||||
QDomElement partag = doc.createElement("xmlparam");
|
||||
partag.setAttribute("name",itm.key());
|
||||
partag.setAttribute("value",itm.value());
|
||||
tag.appendChild(partag);
|
||||
}
|
||||
root.appendChild(tag);
|
||||
(*jj)->accept(v);
|
||||
tag.appendChild(v.parElem);
|
||||
}
|
||||
root.appendChild(tag);
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
|
||||
@ -35,7 +35,6 @@ class FilterNameParameterValuesPair
|
||||
{
|
||||
public:
|
||||
virtual QString filterName() const = 0;
|
||||
virtual bool isXMLFilter() const = 0;
|
||||
virtual ~FilterNameParameterValuesPair() {}
|
||||
};
|
||||
|
||||
@ -43,7 +42,6 @@ class XMLFilterNameParameterValuesPair : public FilterNameParameterValuesPair
|
||||
{
|
||||
public:
|
||||
~XMLFilterNameParameterValuesPair() {}
|
||||
bool isXMLFilter() const { return true; }
|
||||
QString filterName() const { return pair.first; }
|
||||
QPair< QString, QMap<QString, QString> > pair;
|
||||
};
|
||||
@ -52,7 +50,6 @@ class OldFilterNameParameterValuesPair : public FilterNameParameterValuesPair
|
||||
{
|
||||
public:
|
||||
~OldFilterNameParameterValuesPair() {}
|
||||
bool isXMLFilter() const { return false; }
|
||||
QString filterName() const { return pair.first; }
|
||||
QPair< QString, RichParameterSet > pair;
|
||||
};
|
||||
@ -80,4 +77,4 @@ public slots:
|
||||
void addExecutedXMLFilter(const QString& name, const QMap<QString, QString>& parvalue);
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -29,7 +29,7 @@
|
||||
#include "GLLogStream.h"
|
||||
//#include "meshmodel.h"
|
||||
#include "scriptinterface.h"
|
||||
#include "xmlfilterinfo.h"
|
||||
//#include "xmlfilterinfo.h"
|
||||
|
||||
#include <QtCore>
|
||||
#include <QApplication>
|
||||
|
||||
@ -180,9 +180,7 @@ void FilterScriptDialog::editSelectedFilterParameters()
|
||||
QString filtername = ui->scriptListWidget->currentItem()->text();
|
||||
FilterNameParameterValuesPair* pair = scriptPtr->filtparlist.at(currentRow);
|
||||
if (pair->filterName() == filtername) {
|
||||
if (!pair->isXMLFilter()) {
|
||||
editOldParameters(currentRow);
|
||||
}
|
||||
editOldParameters(currentRow);
|
||||
}
|
||||
else {
|
||||
throw MLException("Something bad happened: A filter item has been selected in filterScriptDialog being NOT a XML filter or old-fashioned c++ filter.");
|
||||
|
||||
@ -782,216 +782,96 @@ void MainWindow::runFilterScript()
|
||||
QString filtnm = (*ii)->filterName();
|
||||
int classes = 0;
|
||||
int postCondMask = 0;
|
||||
if (!(*ii)->isXMLFilter())
|
||||
QAction *action = PM.actionFilterMap[ filtnm];
|
||||
MeshFilterInterface *iFilter = qobject_cast<MeshFilterInterface *>(action->parent());
|
||||
|
||||
int req=iFilter->getRequirements(action);
|
||||
if (meshDoc()->mm() != NULL)
|
||||
meshDoc()->mm()->updateDataMask(req);
|
||||
iFilter->setLog(&meshDoc()->Log);
|
||||
OldFilterNameParameterValuesPair* old = reinterpret_cast<OldFilterNameParameterValuesPair*>(*ii);
|
||||
RichParameterSet ¶meterSet = old->pair.second;
|
||||
|
||||
for(int i = 0; i < parameterSet.paramList.size(); i++)
|
||||
{
|
||||
QAction *action = PM.actionFilterMap[ filtnm];
|
||||
MeshFilterInterface *iFilter = qobject_cast<MeshFilterInterface *>(action->parent());
|
||||
//get a modifieable reference
|
||||
RichParameter* parameter = parameterSet.paramList[i];
|
||||
|
||||
int req=iFilter->getRequirements(action);
|
||||
if (meshDoc()->mm() != NULL)
|
||||
meshDoc()->mm()->updateDataMask(req);
|
||||
iFilter->setLog(&meshDoc()->Log);
|
||||
OldFilterNameParameterValuesPair* old = reinterpret_cast<OldFilterNameParameterValuesPair*>(*ii);
|
||||
RichParameterSet ¶meterSet = old->pair.second;
|
||||
|
||||
for(int i = 0; i < parameterSet.paramList.size(); i++)
|
||||
//if this is a mesh paramter and the index is valid
|
||||
if(parameter->val->isMesh())
|
||||
{
|
||||
//get a modifieable reference
|
||||
RichParameter* parameter = parameterSet.paramList[i];
|
||||
|
||||
//if this is a mesh paramter and the index is valid
|
||||
if(parameter->val->isMesh())
|
||||
{
|
||||
RichMesh* md = reinterpret_cast<RichMesh*>(parameter);
|
||||
if( md->meshindex < meshDoc()->size() &&
|
||||
RichMesh* md = reinterpret_cast<RichMesh*>(parameter);
|
||||
if( md->meshindex < meshDoc()->size() &&
|
||||
md->meshindex >= 0 )
|
||||
{
|
||||
RichMesh* rmesh = new RichMesh(parameter->name,md->meshindex,meshDoc());
|
||||
parameterSet.paramList.replace(i,rmesh);
|
||||
} else
|
||||
{
|
||||
printf("Meshes loaded: %i, meshes asked for: %i \n", meshDoc()->size(), md->meshindex );
|
||||
printf("One of the filters in the script needs more meshes than you have loaded.\n");
|
||||
return;
|
||||
}
|
||||
delete parameter;
|
||||
{
|
||||
RichMesh* rmesh = new RichMesh(parameter->name,md->meshindex,meshDoc());
|
||||
parameterSet.paramList.replace(i,rmesh);
|
||||
} else
|
||||
{
|
||||
printf("Meshes loaded: %i, meshes asked for: %i \n", meshDoc()->size(), md->meshindex );
|
||||
printf("One of the filters in the script needs more meshes than you have loaded.\n");
|
||||
return;
|
||||
}
|
||||
delete parameter;
|
||||
}
|
||||
}
|
||||
//iFilter->applyFilter( action, *(meshDoc()->mm()), (*ii).second, QCallBack );
|
||||
|
||||
bool created = false;
|
||||
MLSceneGLSharedDataContext* shar = NULL;
|
||||
if (currentViewContainer() != NULL)
|
||||
{
|
||||
shar = currentViewContainer()->sharedDataContext();
|
||||
//GLA() is only the parent
|
||||
QGLWidget* filterWidget = new QGLWidget(GLA(),shar);
|
||||
QGLFormat defForm = QGLFormat::defaultFormat();
|
||||
iFilter->glContext = new MLPluginGLContext(defForm,filterWidget->context()->device(),*shar);
|
||||
created = iFilter->glContext->create(filterWidget->context());
|
||||
shar->addView(iFilter->glContext);
|
||||
MLRenderingData dt;
|
||||
MLRenderingData::RendAtts atts;
|
||||
atts[MLRenderingData::ATT_NAMES::ATT_VERTPOSITION] = true;
|
||||
atts[MLRenderingData::ATT_NAMES::ATT_VERTNORMAL] = true;
|
||||
|
||||
|
||||
if (iFilter->filterArity(action) == MeshFilterInterface::SINGLE_MESH)
|
||||
{
|
||||
MLRenderingData::PRIMITIVE_MODALITY pm = MLPoliciesStandAloneFunctions::bestPrimitiveModalityAccordingToMesh(meshDoc()->mm());
|
||||
if ((pm != MLRenderingData::PR_ARITY) && (meshDoc()->mm() != NULL))
|
||||
{
|
||||
dt.set(pm,atts);
|
||||
shar->setRenderingDataPerMeshView(meshDoc()->mm()->id(),iFilter->glContext,dt);
|
||||
}
|
||||
}
|
||||
//iFilter->applyFilter( action, *(meshDoc()->mm()), (*ii).second, QCallBack );
|
||||
|
||||
bool created = false;
|
||||
MLSceneGLSharedDataContext* shar = NULL;
|
||||
if (currentViewContainer() != NULL)
|
||||
else
|
||||
{
|
||||
shar = currentViewContainer()->sharedDataContext();
|
||||
//GLA() is only the parent
|
||||
QGLWidget* filterWidget = new QGLWidget(GLA(),shar);
|
||||
QGLFormat defForm = QGLFormat::defaultFormat();
|
||||
iFilter->glContext = new MLPluginGLContext(defForm,filterWidget->context()->device(),*shar);
|
||||
created = iFilter->glContext->create(filterWidget->context());
|
||||
shar->addView(iFilter->glContext);
|
||||
MLRenderingData dt;
|
||||
MLRenderingData::RendAtts atts;
|
||||
atts[MLRenderingData::ATT_NAMES::ATT_VERTPOSITION] = true;
|
||||
atts[MLRenderingData::ATT_NAMES::ATT_VERTNORMAL] = true;
|
||||
|
||||
|
||||
if (iFilter->filterArity(action) == MeshFilterInterface::SINGLE_MESH)
|
||||
for(int ii = 0;ii < meshDoc()->meshList.size();++ii)
|
||||
{
|
||||
MLRenderingData::PRIMITIVE_MODALITY pm = MLPoliciesStandAloneFunctions::bestPrimitiveModalityAccordingToMesh(meshDoc()->mm());
|
||||
if ((pm != MLRenderingData::PR_ARITY) && (meshDoc()->mm() != NULL))
|
||||
MeshModel* mm = meshDoc()->meshList[ii];
|
||||
MLRenderingData::PRIMITIVE_MODALITY pm = MLPoliciesStandAloneFunctions::bestPrimitiveModalityAccordingToMesh(mm);
|
||||
if ((pm != MLRenderingData::PR_ARITY) && (mm != NULL))
|
||||
{
|
||||
dt.set(pm,atts);
|
||||
shar->setRenderingDataPerMeshView(meshDoc()->mm()->id(),iFilter->glContext,dt);
|
||||
shar->setRenderingDataPerMeshView(mm->id(),iFilter->glContext,dt);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int ii = 0;ii < meshDoc()->meshList.size();++ii)
|
||||
{
|
||||
MeshModel* mm = meshDoc()->meshList[ii];
|
||||
MLRenderingData::PRIMITIVE_MODALITY pm = MLPoliciesStandAloneFunctions::bestPrimitiveModalityAccordingToMesh(mm);
|
||||
if ((pm != MLRenderingData::PR_ARITY) && (mm != NULL))
|
||||
{
|
||||
dt.set(pm,atts);
|
||||
shar->setRenderingDataPerMeshView(mm->id(),iFilter->glContext,dt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if ((!created) || (!iFilter->glContext->isValid()))
|
||||
throw MLException("A valid GLContext is required by the filter to work.\n");
|
||||
meshDoc()->setBusy(true);
|
||||
//WARNING!!!!!!!!!!!!
|
||||
/* to be changed */
|
||||
iFilter->applyFilter( action, *meshDoc(), old->pair.second, QCallBack );
|
||||
for (MeshModel* mm = meshDoc()->nextMesh(); mm != NULL; mm = meshDoc()->nextMesh(mm))
|
||||
vcg::tri::Allocator<CMeshO>::CompactEveryVector(mm->cm);
|
||||
meshDoc()->setBusy(false);
|
||||
if (shar != NULL)
|
||||
shar->removeView(iFilter->glContext);
|
||||
delete iFilter->glContext;
|
||||
classes = int(iFilter->getClass(action));
|
||||
postCondMask = iFilter->postCondition(action);
|
||||
}
|
||||
else
|
||||
{
|
||||
MeshLabXMLFilterContainer& cont = PM.stringXMLFilterMap[ filtnm];
|
||||
MLXMLPluginInfo* info = cont.xmlInfo;
|
||||
MeshLabFilterInterface* cppfilt = cont.filterInterface;
|
||||
try
|
||||
{
|
||||
if (cppfilt != NULL)
|
||||
{
|
||||
cppfilt->setLog(&meshDoc()->Log);
|
||||
|
||||
Env env ;
|
||||
QMap<QString, QString> persistentparam;
|
||||
foreach(RichParameter* rp, currentGlobalPars().paramList)
|
||||
{
|
||||
if (rp != NULL)
|
||||
persistentparam[rp->name] = RichParameterAdapter::convertToStringValue(*rp);
|
||||
}
|
||||
|
||||
QScriptValue val = env.loadMLScriptEnv(*meshDoc(), PM, persistentparam);
|
||||
XMLFilterNameParameterValuesPair* xmlfilt = reinterpret_cast<XMLFilterNameParameterValuesPair*>(*ii);
|
||||
QMap<QString,QString>& parmap = xmlfilt->pair.second;
|
||||
for(QMap<QString,QString>::const_iterator it = parmap.constBegin();it != parmap.constEnd();++it)
|
||||
env.insertExpressionBinding(it.key(),it.value());
|
||||
|
||||
EnvWrap envwrap(env);
|
||||
MLXMLPluginInfo::XMLMapList params = info->filterParameters(filtnm);
|
||||
for(int i = 0; i < params.size(); ++i)
|
||||
{
|
||||
MLXMLPluginInfo::XMLMap& parinfo = params[i];
|
||||
|
||||
//if this is a mesh parameter and the index is valid
|
||||
if(parinfo[MLXMLElNames::paramType] == MLXMLElNames::meshType)
|
||||
{
|
||||
QString& parnm = parinfo[MLXMLElNames::paramName];
|
||||
MeshModel* meshmdl = envwrap.evalMesh(parnm);
|
||||
if( meshmdl == NULL)
|
||||
{
|
||||
//parnm is associated with ,
|
||||
printf("Meshes loaded: %i, meshes asked for: %i \n", meshDoc()->size(), envwrap.evalInt(parnm) );
|
||||
printf("One of the filters in the script needs more meshes than you have loaded.\n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
disconnect(meshDoc(),SIGNAL(documentUpdated()),GLA(),SLOT(completeUpdateRequested()));
|
||||
MLSceneGLSharedDataContext* shar = NULL;
|
||||
bool created = false;
|
||||
if (currentViewContainer() != NULL)
|
||||
{
|
||||
shar = currentViewContainer()->sharedDataContext();
|
||||
//GLA() is only the parent
|
||||
QGLWidget* filterWidget = new QGLWidget(GLA(),shar);
|
||||
QGLFormat defForm = QGLFormat::defaultFormat();
|
||||
cppfilt->glContext = new MLPluginGLContext(defForm,filterWidget->context()->device(),*shar);
|
||||
created = cppfilt->glContext->create(filterWidget->context());
|
||||
|
||||
MLRenderingData dt;
|
||||
MLRenderingData::RendAtts atts;
|
||||
atts[MLRenderingData::ATT_NAMES::ATT_VERTPOSITION] = true;
|
||||
atts[MLRenderingData::ATT_NAMES::ATT_VERTNORMAL] = true;
|
||||
|
||||
|
||||
if (info->filterAttribute(filtnm,MLXMLElNames::filterArity) == MLXMLElNames::singleMeshArity)
|
||||
{
|
||||
MLRenderingData::PRIMITIVE_MODALITY pm = MLPoliciesStandAloneFunctions::bestPrimitiveModalityAccordingToMesh(meshDoc()->mm());
|
||||
if ((pm != MLRenderingData::PR_ARITY) && (meshDoc()->mm() != NULL))
|
||||
{
|
||||
dt.set(pm,atts);
|
||||
shar->setRenderingDataPerMeshView(meshDoc()->mm()->id(),cppfilt->glContext,dt);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int ii = 0;ii < meshDoc()->meshList.size();++ii)
|
||||
{
|
||||
MeshModel* mm = meshDoc()->meshList[ii];
|
||||
MLRenderingData::PRIMITIVE_MODALITY pm = MLPoliciesStandAloneFunctions::bestPrimitiveModalityAccordingToMesh(mm);
|
||||
if ((pm != MLRenderingData::PR_ARITY) && (mm != NULL))
|
||||
{
|
||||
dt.set(pm,atts);
|
||||
shar->setRenderingDataPerMeshView(mm->id(),cppfilt->glContext,dt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((!created) || (!cppfilt->glContext->isValid()))
|
||||
throw MLException("A valid GLContext is required by the filter to work.\n");
|
||||
|
||||
|
||||
//WARNING!!!!!!!!!!!!
|
||||
/* IT SHOULD INVOKE executeFilter function. Unfortunately this function create a different thread for each invoked filter, and the MeshLab synchronization mechanisms are quite naive. Better to invoke the filters list in the same thread*/
|
||||
meshDoc()->setBusy(true);
|
||||
cppfilt->applyFilter( filtnm, *meshDoc(), envwrap, QCallBack );
|
||||
for (MeshModel* mm = meshDoc()->nextMesh(); mm != NULL; mm = meshDoc()->nextMesh(mm))
|
||||
vcg::tri::Allocator<CMeshO>::CompactEveryVector(mm->cm);
|
||||
meshDoc()->setBusy(false);
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
if ((currentViewContainer() != NULL) && (currentViewContainer()->sharedDataContext() != NULL))
|
||||
currentViewContainer()->sharedDataContext()->removeView(cppfilt->glContext);
|
||||
delete cppfilt->glContext;
|
||||
GLA()->completeUpdateRequested();
|
||||
connect(meshDoc(),SIGNAL(documentUpdated()),GLA(),SLOT(completeUpdateRequested()));
|
||||
QStringList filterClassesList = cont.xmlInfo->filterAttribute(filtnm,MLXMLElNames::filterClass).split(QRegExp("\\W+"), QString::SkipEmptyParts);
|
||||
classes = MeshLabFilterInterface::convertStringListToCategoryEnum(filterClassesList);
|
||||
QString postCond = cont.xmlInfo->filterAttribute(filtnm, MLXMLElNames::filterPostCond);
|
||||
QStringList postCondList = postCond.split(QRegExp("\\W+"), QString::SkipEmptyParts);
|
||||
postCondMask = MeshLabFilterInterface::convertStringListToMeshElementEnum(postCondList);
|
||||
}
|
||||
else
|
||||
throw MLException("WARNING! The MeshLab Script System is able to manage just the C++ XML filters.");
|
||||
}
|
||||
catch (MLException& e)
|
||||
{
|
||||
meshDoc()->Log.Log(GLLogStream::WARNING,e.what());
|
||||
}
|
||||
|
||||
}
|
||||
if ((!created) || (!iFilter->glContext->isValid()))
|
||||
throw MLException("A valid GLContext is required by the filter to work.\n");
|
||||
meshDoc()->setBusy(true);
|
||||
//WARNING!!!!!!!!!!!!
|
||||
/* to be changed */
|
||||
iFilter->applyFilter( action, *meshDoc(), old->pair.second, QCallBack );
|
||||
for (MeshModel* mm = meshDoc()->nextMesh(); mm != NULL; mm = meshDoc()->nextMesh(mm))
|
||||
vcg::tri::Allocator<CMeshO>::CompactEveryVector(mm->cm);
|
||||
meshDoc()->setBusy(false);
|
||||
if (shar != NULL)
|
||||
shar->removeView(iFilter->glContext);
|
||||
delete iFilter->glContext;
|
||||
classes = int(iFilter->getClass(action));
|
||||
postCondMask = iFilter->postCondition(action);
|
||||
if (meshDoc()->mm() != NULL)
|
||||
{
|
||||
if(classes & MeshFilterInterface::FaceColoring )
|
||||
@ -999,7 +879,7 @@ void MainWindow::runFilterScript()
|
||||
meshDoc()->mm()->updateDataMask(MeshModel::MM_FACECOLOR);
|
||||
}
|
||||
if(classes & MeshFilterInterface::VertexColoring )
|
||||
{
|
||||
{
|
||||
meshDoc()->mm()->updateDataMask(MeshModel::MM_VERTCOLOR);
|
||||
}
|
||||
if(classes & MeshModel::MM_COLOR)
|
||||
@ -1010,11 +890,11 @@ void MainWindow::runFilterScript()
|
||||
meshDoc()->mm()->updateDataMask(MeshModel::MM_CAMERA);
|
||||
}
|
||||
|
||||
bool newmeshcreated = false;
|
||||
if (classes & MeshFilterInterface::MeshCreation)
|
||||
newmeshcreated = true;
|
||||
updateSharedContextDataAfterFilterExecution(postCondMask, classes, newmeshcreated);
|
||||
meshDoc()->meshDocStateData().clear();
|
||||
bool newmeshcreated = false;
|
||||
if (classes & MeshFilterInterface::MeshCreation)
|
||||
newmeshcreated = true;
|
||||
updateSharedContextDataAfterFilterExecution(postCondMask, classes, newmeshcreated);
|
||||
meshDoc()->meshDocStateData().clear();
|
||||
|
||||
if(classes & MeshFilterInterface::MeshCreation)
|
||||
GLA()->resetTrackBall();
|
||||
@ -1023,8 +903,8 @@ void MainWindow::runFilterScript()
|
||||
qb->reset();
|
||||
GLA()->update();
|
||||
GLA()->Logf(GLLogStream::SYSTEM,"Re-Applied filter %s",qUtf8Printable((*ii)->filterName()));
|
||||
if (_currviewcontainer != NULL)
|
||||
_currviewcontainer->updateAllDecoratorsForAllViewers();
|
||||
if (_currviewcontainer != NULL)
|
||||
_currviewcontainer->updateAllDecoratorsForAllViewers();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -333,237 +333,122 @@ public:
|
||||
//RichParameterSet &par = (*ii).second;
|
||||
QString fname = (*ii)->filterName();
|
||||
fprintf(fp,"filter: %s\n", qUtf8Printable(fname));
|
||||
if (!(*ii)->isXMLFilter())
|
||||
QAction *action = PM.actionFilterMap[ fname];
|
||||
if (action == NULL)
|
||||
{
|
||||
QAction *action = PM.actionFilterMap[ fname];
|
||||
if (action == NULL)
|
||||
fprintf(fp,"filter %s not found", qUtf8Printable(fname));
|
||||
return false;
|
||||
}
|
||||
|
||||
MeshFilterInterface *iFilter = qobject_cast<MeshFilterInterface *>(action->parent());
|
||||
iFilter->setLog(&log);
|
||||
int req = iFilter->getRequirements(action);
|
||||
if (mm != NULL)
|
||||
mm->updateDataMask(req);
|
||||
//make sure the PARMESH parameters are initialized
|
||||
|
||||
//A filter in the script file couldn't have all the required parameter not defined (a script file not generated by MeshLab).
|
||||
//So we have to ask to the filter the default values for all the parameters and integrate them with the parameters' values
|
||||
//defined in the script file.
|
||||
RichParameterSet required;
|
||||
iFilter->initParameterSet(action,meshDocument,required);
|
||||
OldFilterNameParameterValuesPair* pairold = reinterpret_cast<OldFilterNameParameterValuesPair*>(*ii);
|
||||
RichParameterSet ¶meterSet = pairold->pair.second;
|
||||
|
||||
//The parameters in the script file are more than the required parameters of the filter. The script file is not correct.
|
||||
if (required.paramList.size() < parameterSet.paramList.size())
|
||||
{
|
||||
fprintf(fp,"The parameters in the script file are more than the filter %s requires.\n", qUtf8Printable(fname));
|
||||
return false;
|
||||
}
|
||||
|
||||
for(int i = 0; i < required.paramList.size(); i++)
|
||||
{
|
||||
RichParameterCopyConstructor v;
|
||||
if (!parameterSet.hasParameter(required.paramList[i]->name))
|
||||
{
|
||||
fprintf(fp,"filter %s not found", qUtf8Printable(fname));
|
||||
return false;
|
||||
required.paramList[i]->accept(v);
|
||||
parameterSet.addParam(v.lastCreated);
|
||||
}
|
||||
|
||||
MeshFilterInterface *iFilter = qobject_cast<MeshFilterInterface *>(action->parent());
|
||||
iFilter->setLog(&log);
|
||||
int req = iFilter->getRequirements(action);
|
||||
if (mm != NULL)
|
||||
mm->updateDataMask(req);
|
||||
//make sure the PARMESH parameters are initialized
|
||||
|
||||
//A filter in the script file couldn't have all the required parameter not defined (a script file not generated by MeshLab).
|
||||
//So we have to ask to the filter the default values for all the parameters and integrate them with the parameters' values
|
||||
//defined in the script file.
|
||||
RichParameterSet required;
|
||||
iFilter->initParameterSet(action,meshDocument,required);
|
||||
OldFilterNameParameterValuesPair* pairold = reinterpret_cast<OldFilterNameParameterValuesPair*>(*ii);
|
||||
RichParameterSet ¶meterSet = pairold->pair.second;
|
||||
|
||||
//The parameters in the script file are more than the required parameters of the filter. The script file is not correct.
|
||||
if (required.paramList.size() < parameterSet.paramList.size())
|
||||
assert(parameterSet.paramList.size() == required.paramList.size());
|
||||
RichParameter* parameter = parameterSet.paramList[i];
|
||||
//if this is a mesh parameter and the index is valid
|
||||
if(parameter->val->isMesh())
|
||||
{
|
||||
fprintf(fp,"The parameters in the script file are more than the filter %s requires.\n", qUtf8Printable(fname));
|
||||
return false;
|
||||
}
|
||||
|
||||
for(int i = 0; i < required.paramList.size(); i++)
|
||||
{
|
||||
RichParameterCopyConstructor v;
|
||||
if (!parameterSet.hasParameter(required.paramList[i]->name))
|
||||
{
|
||||
required.paramList[i]->accept(v);
|
||||
parameterSet.addParam(v.lastCreated);
|
||||
}
|
||||
assert(parameterSet.paramList.size() == required.paramList.size());
|
||||
RichParameter* parameter = parameterSet.paramList[i];
|
||||
//if this is a mesh parameter and the index is valid
|
||||
if(parameter->val->isMesh())
|
||||
{
|
||||
RichMesh* md = reinterpret_cast<RichMesh*>(parameter);
|
||||
if( md->meshindex < meshDocument.size() &&
|
||||
RichMesh* md = reinterpret_cast<RichMesh*>(parameter);
|
||||
if( md->meshindex < meshDocument.size() &&
|
||||
md->meshindex >= 0 )
|
||||
{
|
||||
RichMesh* rmesh = new RichMesh(parameter->name,meshDocument.getMesh(md->meshindex),&meshDocument);
|
||||
parameterSet.paramList.replace(i,rmesh);
|
||||
} else
|
||||
{
|
||||
fprintf(fp,"Meshes loaded: %i, meshes asked for: %i \n", meshDocument.size(), md->meshindex );
|
||||
fprintf(fp,"One of the filters in the script needs more meshes than you have loaded.\n");
|
||||
exit(-1);
|
||||
}
|
||||
delete parameter;
|
||||
}
|
||||
}
|
||||
|
||||
QGLWidget* wid = NULL;
|
||||
if (shared != NULL)
|
||||
{
|
||||
wid = new QGLWidget(NULL,shared);
|
||||
iFilter->glContext = new MLPluginGLContext(QGLFormat::defaultFormat(), wid->context()->device(),*shared);
|
||||
bool created = iFilter->glContext->create(wid->context());
|
||||
if ((!created) || (!iFilter->glContext->isValid()))
|
||||
{
|
||||
fprintf(fp, "A valid GLContext is required by the filter to work.\n");
|
||||
return false;
|
||||
}
|
||||
MLRenderingData dt;
|
||||
MLRenderingData::RendAtts atts;
|
||||
atts[MLRenderingData::ATT_NAMES::ATT_VERTPOSITION] = true;
|
||||
atts[MLRenderingData::ATT_NAMES::ATT_VERTNORMAL] = true;
|
||||
|
||||
if (iFilter->filterArity(action) == MeshFilterInterface::SINGLE_MESH)
|
||||
{
|
||||
MLRenderingData::PRIMITIVE_MODALITY pm = MLPoliciesStandAloneFunctions::bestPrimitiveModalityAccordingToMesh(meshDocument.mm());
|
||||
if ((pm != MLRenderingData::PR_ARITY) && (meshDocument.mm() != NULL))
|
||||
{
|
||||
dt.set(pm, atts);
|
||||
iFilter->glContext->initPerViewRenderingData(meshDocument.mm()->id(), dt);
|
||||
}
|
||||
|
||||
if (meshDocument.mm() != NULL)
|
||||
{
|
||||
meshDocument.mm()->cm.svn = int(vcg::tri::UpdateSelection<CMeshO>::VertexCount(meshDocument.mm()->cm));
|
||||
meshDocument.mm()->cm.sfn = int(vcg::tri::UpdateSelection<CMeshO>::FaceCount(meshDocument.mm()->cm));
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int ii = 0; ii < meshDocument.meshList.size(); ++ii)
|
||||
{
|
||||
MeshModel* mm = meshDocument.meshList[ii];
|
||||
MLRenderingData::PRIMITIVE_MODALITY pm = MLPoliciesStandAloneFunctions::bestPrimitiveModalityAccordingToMesh(mm);
|
||||
if ((pm != MLRenderingData::PR_ARITY) && (mm != NULL))
|
||||
{
|
||||
dt.set(pm, atts);
|
||||
iFilter->glContext->initPerViewRenderingData(mm->id(), dt);
|
||||
}
|
||||
|
||||
if (mm != NULL)
|
||||
{
|
||||
mm->cm.svn = int(vcg::tri::UpdateSelection<CMeshO>::VertexCount(mm->cm));
|
||||
mm->cm.sfn = int(vcg::tri::UpdateSelection<CMeshO>::FaceCount(mm->cm));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
meshDocument.setBusy(true);
|
||||
ret = iFilter->applyFilter( action, meshDocument, pairold->pair.second, filterCallBack);
|
||||
meshDocument.setBusy(false);
|
||||
if (shared != NULL)
|
||||
delete iFilter->glContext;
|
||||
delete wid;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
MeshLabXMLFilterContainer cont = PM.stringXMLFilterMap[ fname];
|
||||
MLXMLPluginInfo* info = cont.xmlInfo;
|
||||
MeshLabFilterInterface* cppfilt = cont.filterInterface;
|
||||
try
|
||||
{
|
||||
if (cppfilt != NULL)
|
||||
{
|
||||
cppfilt->setLog(&log);
|
||||
|
||||
Env env;
|
||||
env.loadMLScriptEnv(meshDocument,PM);
|
||||
XMLFilterNameParameterValuesPair* xmlfilt = reinterpret_cast<XMLFilterNameParameterValuesPair*>(*ii);
|
||||
QMap<QString,QString>& parmap = xmlfilt->pair.second;
|
||||
for(QMap<QString,QString>::const_iterator it = parmap.constBegin();it != parmap.constEnd();++it)
|
||||
env.insertExpressionBinding(it.key(),it.value());
|
||||
|
||||
EnvWrap envwrap(env);
|
||||
MLXMLPluginInfo::XMLMapList params = info->filterParameters(fname);
|
||||
for(int i = 0; i < params.size(); ++i)
|
||||
{
|
||||
MLXMLPluginInfo::XMLMap& parinfo = params[i];
|
||||
|
||||
//if this is a mesh parameter and the index is valid
|
||||
if(parinfo[MLXMLElNames::paramType] == MLXMLElNames::meshType)
|
||||
{
|
||||
QString& parnm = parinfo[MLXMLElNames::paramName];
|
||||
MeshModel* meshmdl = envwrap.evalMesh(parnm);
|
||||
if( meshmdl == NULL)
|
||||
{
|
||||
//parnm is associated with ,
|
||||
printf("Meshes loaded: %i, meshes asked for: %i \n", meshDocument.size(), envwrap.evalInt(parnm) );
|
||||
printf("One of the filters in the script needs more meshes than you have loaded.\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
QGLWidget* wid = NULL;
|
||||
if (shared != NULL)
|
||||
{
|
||||
wid = new QGLWidget(NULL, shared);
|
||||
cppfilt->glContext = new MLPluginGLContext(QGLFormat::defaultFormat(), wid->context()->device(), *shared);
|
||||
bool created = cppfilt->glContext->create(wid->context());
|
||||
if ((!created) || (!cppfilt->glContext->isValid()))
|
||||
{
|
||||
fprintf(fp, "A valid GLContext is required by the filter to work.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
MLRenderingData dt;
|
||||
MLRenderingData::RendAtts atts;
|
||||
atts[MLRenderingData::ATT_NAMES::ATT_VERTPOSITION] = true;
|
||||
atts[MLRenderingData::ATT_NAMES::ATT_VERTNORMAL] = true;
|
||||
|
||||
if (info->filterAttribute(fname, MLXMLElNames::filterArity) == MLXMLElNames::singleMeshArity)
|
||||
{
|
||||
MLRenderingData::PRIMITIVE_MODALITY pm = MLPoliciesStandAloneFunctions::bestPrimitiveModalityAccordingToMesh(meshDocument.mm());
|
||||
if ((pm != MLRenderingData::PR_ARITY) && (meshDocument.mm() != NULL))
|
||||
{
|
||||
dt.set(pm, atts);
|
||||
cppfilt->glContext->initPerViewRenderingData(meshDocument.mm()->id(), dt);
|
||||
}
|
||||
|
||||
if (meshDocument.mm() != NULL)
|
||||
{
|
||||
meshDocument.mm()->cm.svn = int(vcg::tri::UpdateSelection<CMeshO>::VertexCount(meshDocument.mm()->cm));
|
||||
meshDocument.mm()->cm.sfn = int(vcg::tri::UpdateSelection<CMeshO>::FaceCount(meshDocument.mm()->cm));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int ii = 0; ii < meshDocument.meshList.size(); ++ii)
|
||||
{
|
||||
MeshModel* mm = meshDocument.meshList[ii];
|
||||
MLRenderingData::PRIMITIVE_MODALITY pm = MLPoliciesStandAloneFunctions::bestPrimitiveModalityAccordingToMesh(mm);
|
||||
if ((pm != MLRenderingData::PR_ARITY) && (mm != NULL))
|
||||
{
|
||||
dt.set(pm, atts);
|
||||
cppfilt->glContext->initPerViewRenderingData(mm->id(), dt);
|
||||
}
|
||||
|
||||
if (mm != NULL)
|
||||
{
|
||||
mm->cm.svn = int(vcg::tri::UpdateSelection<CMeshO>::VertexCount(mm->cm));
|
||||
mm->cm.sfn = int(vcg::tri::UpdateSelection<CMeshO>::FaceCount(mm->cm));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//WARNING!!!!!!!!!!!!
|
||||
/* IT SHOULD INVOKE executeFilter function. Unfortunately this function create a different thread for each invoked filter, and the MeshLab synchronization mechanisms are quite naive. Better to invoke the filters list in the same thread*/
|
||||
meshDocument.setBusy(true);
|
||||
ret = cppfilt->applyFilter( fname, meshDocument, envwrap, filterCallBack );
|
||||
meshDocument.setBusy(false);
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
if (shared != NULL)
|
||||
delete cppfilt->glContext;
|
||||
delete wid;
|
||||
RichMesh* rmesh = new RichMesh(parameter->name,meshDocument.getMesh(md->meshindex),&meshDocument);
|
||||
parameterSet.paramList.replace(i,rmesh);
|
||||
} else
|
||||
{
|
||||
fprintf(fp,"Meshes loaded: %i, meshes asked for: %i \n", meshDocument.size(), md->meshindex );
|
||||
fprintf(fp,"One of the filters in the script needs more meshes than you have loaded.\n");
|
||||
exit(-1);
|
||||
}
|
||||
else
|
||||
throw MLException("WARNING! The MeshLab Script System is able to manage just the C++ XML filters.");
|
||||
}
|
||||
catch (MLException& e)
|
||||
{
|
||||
meshDocument.Log.Log(GLLogStream::WARNING,e.what());
|
||||
delete parameter;
|
||||
}
|
||||
}
|
||||
|
||||
QGLWidget* wid = NULL;
|
||||
if (shared != NULL)
|
||||
{
|
||||
wid = new QGLWidget(NULL,shared);
|
||||
iFilter->glContext = new MLPluginGLContext(QGLFormat::defaultFormat(), wid->context()->device(),*shared);
|
||||
bool created = iFilter->glContext->create(wid->context());
|
||||
if ((!created) || (!iFilter->glContext->isValid()))
|
||||
{
|
||||
fprintf(fp, "A valid GLContext is required by the filter to work.\n");
|
||||
return false;
|
||||
}
|
||||
MLRenderingData dt;
|
||||
MLRenderingData::RendAtts atts;
|
||||
atts[MLRenderingData::ATT_NAMES::ATT_VERTPOSITION] = true;
|
||||
atts[MLRenderingData::ATT_NAMES::ATT_VERTNORMAL] = true;
|
||||
|
||||
if (iFilter->filterArity(action) == MeshFilterInterface::SINGLE_MESH)
|
||||
{
|
||||
MLRenderingData::PRIMITIVE_MODALITY pm = MLPoliciesStandAloneFunctions::bestPrimitiveModalityAccordingToMesh(meshDocument.mm());
|
||||
if ((pm != MLRenderingData::PR_ARITY) && (meshDocument.mm() != NULL))
|
||||
{
|
||||
dt.set(pm, atts);
|
||||
iFilter->glContext->initPerViewRenderingData(meshDocument.mm()->id(), dt);
|
||||
}
|
||||
|
||||
if (meshDocument.mm() != NULL)
|
||||
{
|
||||
meshDocument.mm()->cm.svn = int(vcg::tri::UpdateSelection<CMeshO>::VertexCount(meshDocument.mm()->cm));
|
||||
meshDocument.mm()->cm.sfn = int(vcg::tri::UpdateSelection<CMeshO>::FaceCount(meshDocument.mm()->cm));
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int ii = 0; ii < meshDocument.meshList.size(); ++ii)
|
||||
{
|
||||
MeshModel* mm = meshDocument.meshList[ii];
|
||||
MLRenderingData::PRIMITIVE_MODALITY pm = MLPoliciesStandAloneFunctions::bestPrimitiveModalityAccordingToMesh(mm);
|
||||
if ((pm != MLRenderingData::PR_ARITY) && (mm != NULL))
|
||||
{
|
||||
dt.set(pm, atts);
|
||||
iFilter->glContext->initPerViewRenderingData(mm->id(), dt);
|
||||
}
|
||||
|
||||
if (mm != NULL)
|
||||
{
|
||||
mm->cm.svn = int(vcg::tri::UpdateSelection<CMeshO>::VertexCount(mm->cm));
|
||||
mm->cm.sfn = int(vcg::tri::UpdateSelection<CMeshO>::FaceCount(mm->cm));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
meshDocument.setBusy(true);
|
||||
ret = iFilter->applyFilter( action, meshDocument, pairold->pair.second, filterCallBack);
|
||||
meshDocument.setBusy(false);
|
||||
if (shared != NULL)
|
||||
delete iFilter->glContext;
|
||||
delete wid;
|
||||
QStringList logOutput;
|
||||
log.print(logOutput);
|
||||
foreach(QString logEntry, logOutput)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user