From 55a6475e6c8dba2df6322ea469a5bf03e9e2de6b Mon Sep 17 00:00:00 2001 From: Gregorio Palmas palmas Date: Tue, 26 Jan 2010 17:40:04 +0000 Subject: [PATCH] Added sphere resolution and max recursion parameters --- src/fgt/filter_ssynth/filter_ssynth.cpp | 109 +++++++++++----------- src/fgt/filter_ssynth/filter_ssynth.h | 9 +- src/fgt/filter_ssynth/filter_ssynth.pro | 7 +- src/fgt/filter_ssynth/mytrenderer.cpp | 10 +- src/fgt/filter_ssynth/ssynthres.qrc | 8 ++ src/fgt/filter_ssynth/x3d.rendertemplate | 27 +----- src/fgt/filter_ssynth/x3d2.rendertemplate | 69 ++++++++++++++ src/fgt/filter_ssynth/x3d3.rendertemplate | 70 ++++++++++++++ src/fgt/filter_ssynth/x3d4.rendertemplate | 70 ++++++++++++++ 9 files changed, 293 insertions(+), 86 deletions(-) create mode 100644 src/fgt/filter_ssynth/ssynthres.qrc create mode 100644 src/fgt/filter_ssynth/x3d2.rendertemplate create mode 100644 src/fgt/filter_ssynth/x3d3.rendertemplate create mode 100644 src/fgt/filter_ssynth/x3d4.rendertemplate diff --git a/src/fgt/filter_ssynth/filter_ssynth.cpp b/src/fgt/filter_ssynth/filter_ssynth.cpp index c4c1ddce4..8318c9d8b 100644 --- a/src/fgt/filter_ssynth/filter_ssynth.cpp +++ b/src/fgt/filter_ssynth/filter_ssynth.cpp @@ -21,18 +21,8 @@ using namespace SyntopiaCore::Exceptions; FilterSSynth::FilterSSynth(){ typeList<< CR_SSYNTH; FilterIDType tt; - this->renderTemplate= QString("%1 %2 %3 %4 %5 %6 %7 %8 %9 %10") - .arg(""); - foreach(tt , types()) + this->renderTemplate= ""; + foreach(tt , types()) actionList << new QAction(filterName(tt), this); //num=0; } @@ -63,23 +53,10 @@ QString FilterSSynth::filterInfo(FilterIDType filterId) const } void FilterSSynth::initParameterSet(QAction* filter,MeshDocument &md, RichParameterSet &par) { - RichOpenFile* opens=new RichOpenFile(tr("openfile"),tr(""),tr("*.*"),tr(""),tr(""),tr("")); - - //FileDecoration * fc=new FileDecoration() - // RichSaveFile* saves=new RichSaveFile(tr("exportg"),v,) - //par.addParam(new RichOpenFile(QString("openf"),QString(""),QString(".es"))); - //RichString* str=new RichString("oioin","","",""); - //str->accept(opens->pd); - RichString* grammar=new RichString("grammar","set maxdepth 40 R1 R2 rule R1 { { x 1 rz 6 ry 6 s 0.99 } R1 { s 2 } sphere } rule R2 {{ x -1 rz 6 ry 6 s 0.99 } R2 { s 2 } sphere} ","Eisen Script grammar","Write a grammar according to Eisen Script specification and using the primitives box, sphere, mesh, dot and triangle "); - /*FileValue* v=new FileValue(tr("exportedgrammar")); - v->set(*(grammar->val)); - FileDecoration* fc=new FileDecoration(v,tr("ES"),tr("Exported EisenScript grammar"),QString::Null()); - RichSaveFile* saves=new RichSaveFile(tr("expg"),v,fc);*/ - //par.addParam(new RichString("grammar","set maxdepth 40 R1 R2 rule R1 { { x 1 rz 6 ry 6 s 0.99 } R1 { s 2 } sphere } rule R2 {{ x -1 rz 6 ry 6 s 0.99 } R2 { s 2 } sphere} ","Eisen Script grammar","Write a grammar according to Eisen Script specification and using the primitives box, sphere, mesh, dot and triangle ")); - par.addParam(grammar); - par.addParam(new RichInt("seed",1,"seed for random construction","")); - // par.addParam(saves); - return; + par.addParam(new RichString("grammar","set maxdepth 40 R1 R2 rule R1 { { x 1 rz 6 ry 6 s 0.99 } R1 { s 2 } sphere } rule R2 {{ x -1 rz 6 ry 6 s 0.99 } R2 { s 2 } sphere} ","Eisen Script grammar","Write a grammar according to Eisen Script specification and using the primitives box, sphere, mesh, dot and triangle ")); + par.addParam(new RichInt("seed",1,"seed for random construction","Seed needed to build the mesh")); + par.addParam(new RichInt("sphereres",1,"set maximum resolution of sphere primitves, it must be included between 1 and 4","increasing the resolution of the spheres will improve the quality of the mesh ")); + return; } void FilterSSynth::openX3D(const QString &fileName, MeshModel &m, int& mask, vcg::CallBackPos *cb, QWidget* parent) { @@ -94,38 +71,38 @@ void FilterSSynth::openX3D(const QString &fileName, MeshModel &m, int& mask, vcg } bool FilterSSynth::applyFilter(QAction* filter, MeshDocument &md, RichParameterSet & par, vcg::CallBackPos *cb) { + QWidget * parent=(QWidget*)this->parent(); RichParameter* grammar=par.findParameter(QString("grammar")); RichParameter* seed=par.findParameter(QString("seed")); - QString path=ssynth(grammar->val->getString(),seed->val->getInt(),cb); + int sphereres=par.findParameter("sphereres")->val->getInt(); + this->renderTemplate=GetTemplate(sphereres); + if(this->renderTemplate!=QString::Null()){ + QString path=ssynth(grammar->val->getString(),-50,seed->val->getInt(),cb); if(QFile::exists(path)){ QFile file(path); - //CMeshO cm=md.mm()->cm; - //MeshModel m=*(md.mm()); - //grammars[m]=grammar->val->getString(); int mask; const QString name(file.fileName()); - openX3D(name,*(md.mm()),mask,cb); file.remove(); return true; } else{ - QWidget * parent=(QWidget*)this->parent(); - QMessageBox::critical(parent,tr("Error"),tr("An error occurred during the mesh generation: ").append(path)); + QString message=QString("An error occurred during the mesh generation:" ).append(path); + QMessageBox::critical(parent,"Error",message); return false; } + } + else{ + QMessageBox::critical(parent,"Error","Sphere resolution must be between 1 and 4"); return false; + } } int FilterSSynth::getRequirements(QAction *) { return MeshModel::MM_NONE; } - QString FilterSSynth::ssynth(QString grammar,int seed,CallBackPos *cb){ + QString FilterSSynth::ssynth(QString grammar,int maxdepth,int seed,CallBackPos *cb){ QString path(""); - QString tdir = QApplication::applicationDirPath(); - // QFile filer(tdir.append(tr("/x3d.rendertemplate")));//il file per ora va messo nella cartella dove c'è l'eseguibile di meshlab - //if(filer.exists()){ - if (cb != NULL) (*cb)(0, "Loading..."); - //Template templ(filer); + if (cb != NULL) (*cb)(0, "Loading..."); Template templ(this->renderTemplate); MyTrenderer renderer(templ); renderer.begin(); @@ -136,9 +113,10 @@ int FilterSSynth::getRequirements(QAction *) try { RuleSet* rs=parser.parseRuleset(); + if(maxdepth>0) + rs->setRulesMaxDepth(maxdepth); rs->resolveNames(); rs->dumpInfo(); - RandomStreams::SetSeed(seed); Builder b(&renderer,rs,false); b.build(); @@ -158,8 +136,6 @@ int FilterSSynth::getRequirements(QAction *) catch(ParseError& ex){ return ex.getMessage(); } - /*} - else path=QString("");*/ return path; } int FilterSSynth::postCondition(QAction* filter) const @@ -183,16 +159,16 @@ QList FilterSSynth::importFormats() const } bool FilterSSynth::open(const QString &formatName, const QString &fileName, MeshModel &m, int& mask, const RichParameterSet & par, CallBackPos *cb, QWidget *parent) { - //if (cb != NULL) (*cb)(0, "Loading..."); - this->seed=par.findParameter("seed")->val->getInt(); + int maxrec=par.findParameter("maxrec")->val->getInt(); + int sphereres=par.findParameter("sphereres")->val->getInt(); + this->renderTemplate=GetTemplate(sphereres); + if(this->renderTemplate!=QString::Null()){ QFile grammar(fileName); - grammar.open(QFile::ReadOnly|QFile::Text); + grammar.open(QFile::ReadOnly|QFile::Text); QString gcontent(grammar.readAll()); grammar.close(); - // CMeshO cm=m.cm; - // grammars[m]=gcontent; - QString x3dfile(FilterSSynth::ssynth(gcontent,this->seed,cb)); + QString x3dfile(FilterSSynth::ssynth(gcontent,maxrec,this->seed,cb)); if(QFile::exists(x3dfile)){ openX3D(x3dfile,m,mask,cb); QFile x3df(x3dfile); @@ -203,6 +179,8 @@ QList FilterSSynth::importFormats() const QMessageBox::critical(parent,tr("Error"),tr("An error occurred during the mesh generation: ").append(x3dfile)); return false; } + } + else{ QMessageBox::critical(parent,"Error","Sphere resolution must be between 1 and 4"); return false;} } bool FilterSSynth::save(const QString &formatName, const QString &fileName, MeshModel &m, const int mask, const RichParameterSet &, vcg::CallBackPos *cb, QWidget *parent) { @@ -210,9 +188,36 @@ QList FilterSSynth::importFormats() const } void FilterSSynth::GetExportMaskCapability(QString &format, int &capability, int &defaultBits) const{} void FilterSSynth::initPreOpenParameter(const QString &formatName, const QString &filename, RichParameterSet &parlst){ - parlst.addParam(new RichInt(tr("seed"),1,tr("Seed for random mesh generation"))); + parlst.addParam(new RichInt(tr("seed"),1,tr("Seed for random mesh generation"),tr("write a seed for the random generation of the mesh"))); + parlst.addParam(new RichInt("maxrec",0,"set the maximum recursion","the mesh is built recursively according to the productions of the grammar, so a limit is needed. If set to 0 meshlab will generate the mesh according to the maximum recursion set in the file")); + parlst.addParam(new RichInt("sphereres",1,"set maximum resolution of sphere primitves, it must be included between 1 and 4","increasing the resolution of the spheres will improve the quality of the mesh ")); + } + QString FilterSSynth::GetTemplate(int sphereres){ + QString filen; + switch(sphereres){ + case 1: + filen=":/x3d.rendertemplate"; + break; + case 2: + filen=":/x3d2.rendertemplate"; + break; + case 3: + filen=":/x3d3.rendertemplate"; + break; + case 4: + filen=":/x3d4.rendertemplate"; + break; + default: + return QString::Null(); + break; + } + QFile tr(filen); + tr.open(QFile::ReadOnly|QFile::Text); + QString templateR(tr.readAll()); + return templateR; } + Q_EXPORT_PLUGIN(FilterSSynth) diff --git a/src/fgt/filter_ssynth/filter_ssynth.h b/src/fgt/filter_ssynth/filter_ssynth.h index 5870d120b..965511019 100644 --- a/src/fgt/filter_ssynth/filter_ssynth.h +++ b/src/fgt/filter_ssynth/filter_ssynth.h @@ -51,9 +51,7 @@ class FilterSSynth : public QObject,public MeshIOInterface, public MeshFilterInt virtual FilterClass getClass(QAction* filter); void setAttributes(CMeshO::VertexIterator &vi, CMeshO &m); static void openX3D(const QString &fileName, MeshModel &m, int& mask, vcg::CallBackPos *cb, QWidget *parent=0); - virtual int postCondition(QAction* filter) const; - - + virtual int postCondition(QAction* filter) const; QList importFormats() const; QList exportFormats() const; @@ -64,8 +62,11 @@ class FilterSSynth : public QObject,public MeshIOInterface, public MeshFilterInt bool save(const QString &formatName, const QString &fileName, MeshModel &m, const int mask, const RichParameterSet &, vcg::CallBackPos *cb, QWidget *parent); private: - QString ssynth(QString grammar,int seed,vcg::CallBackPos *cb); + QString ssynth(QString grammar,int maxdepth,int seed,vcg::CallBackPos *cb); + QString GetTemplate(int sphereres); + // bool HasRec(QString *grammar); int seed; QString renderTemplate; + QString spheres[6]; }; #endif // FILTER_SSYNTH_H diff --git a/src/fgt/filter_ssynth/filter_ssynth.pro b/src/fgt/filter_ssynth/filter_ssynth.pro index 4f4c970fa..570abeb2b 100644 --- a/src/fgt/filter_ssynth/filter_ssynth.pro +++ b/src/fgt/filter_ssynth/filter_ssynth.pro @@ -15,8 +15,13 @@ win32-msvc2005:LIBS += ../../external/lib/win32-msvc2005/ssynth.lib win32-msvc2008:LIBS += ../../external/lib/win32-msvc2008/ssynth.lib win32-g++:LIBS += ../../external/lib/win32-gcc/libssynth.a linux-g++:LIBS += ../../external/lib/linux-g++/libssynth.a +macx:DESTDIR = ../../external/lib/macx/libssynth.a TARGET = filter_ssynth TEMPLATE = lib QT += opengl CONFIG += plugin -OTHER_FILES += +OTHER_FILES += x3d.rendertemplate \ + x3d2.rendertemplate \ + x3d3.rendertemplate \ + x3d4.rendertemplate +RESOURCES += ssynthres.qrc diff --git a/src/fgt/filter_ssynth/mytrenderer.cpp b/src/fgt/filter_ssynth/mytrenderer.cpp index 5bb080f2b..f8e57db77 100644 --- a/src/fgt/filter_ssynth/mytrenderer.cpp +++ b/src/fgt/filter_ssynth/mytrenderer.cpp @@ -41,12 +41,12 @@ void MyTrenderer::drawSphere(SyntopiaCore::Math::Vector3f center, float radius, QString scale=QString("%1 %2 %3") .arg(diff).arg(diff).arg(diff); t.substitute("{x3dsphscale}",scale); - QString colors(""); - for(int i=0;i<126;i++){ - colors.append(QString::number(rgb.x())).append(" ").append(QString::number(rgb.y())).append(" ").append(QString::number(rgb.z())).append(" ").append(QString::number(alpha)).append(" "); - } - t.substitute("{x3dspherecol}",colors); + } + t.substitute("{r}", QString::number(rgb.x())); + t.substitute("{g}", QString::number(rgb.y())); + t.substitute("{b}", QString::number(rgb.z())); + t.substitute("{alpha}", QString::number(alpha)); t.substitute("{rad}", QString::number(radius)); output.append(t.getText()); } diff --git a/src/fgt/filter_ssynth/ssynthres.qrc b/src/fgt/filter_ssynth/ssynthres.qrc new file mode 100644 index 000000000..79bb518b7 --- /dev/null +++ b/src/fgt/filter_ssynth/ssynthres.qrc @@ -0,0 +1,8 @@ + + + x3d.rendertemplate + x3d2.rendertemplate + x3d3.rendertemplate + x3d4.rendertemplate + + diff --git a/src/fgt/filter_ssynth/x3d.rendertemplate b/src/fgt/filter_ssynth/x3d.rendertemplate index ae915de6a..79090b193 100644 --- a/src/fgt/filter_ssynth/x3d.rendertemplate +++ b/src/fgt/filter_ssynth/x3d.rendertemplate @@ -21,7 +21,7 @@ - + @@ -42,6 +42,7 @@ + ]]> @@ -63,28 +64,6 @@ - -]]> +]]> - - - - - - - -]]> - - \ No newline at end of file diff --git a/src/fgt/filter_ssynth/x3d2.rendertemplate b/src/fgt/filter_ssynth/x3d2.rendertemplate new file mode 100644 index 000000000..61370091e --- /dev/null +++ b/src/fgt/filter_ssynth/x3d2.rendertemplate @@ -0,0 +1,69 @@ + \ No newline at end of file diff --git a/src/fgt/filter_ssynth/x3d3.rendertemplate b/src/fgt/filter_ssynth/x3d3.rendertemplate new file mode 100644 index 000000000..2adc73885 --- /dev/null +++ b/src/fgt/filter_ssynth/x3d3.rendertemplate @@ -0,0 +1,70 @@ + \ No newline at end of file diff --git a/src/fgt/filter_ssynth/x3d4.rendertemplate b/src/fgt/filter_ssynth/x3d4.rendertemplate new file mode 100644 index 000000000..50f28818f --- /dev/null +++ b/src/fgt/filter_ssynth/x3d4.rendertemplate @@ -0,0 +1,70 @@ + \ No newline at end of file