improved compatibility with Renderman Interface Specific 3.2

refactoring of code and several bug fix
This commit is contained in:
Paolo Cignoni cignoni 2009-12-23 11:47:11 +00:00
parent be5f06a622
commit 980faa04c9
9 changed files with 768 additions and 478 deletions

View File

@ -1,19 +1,17 @@
#include "RibFileStack.h"
RibFileStack::RibFileStack(QString dir) {
ribProc = ribParser::initHash(); //hash of rib procedure
stack = new QStack< QPair<QFile*, QTextStream*>* >();
this->templateDir = dir;
templateDir = dir;
subDir.append("."); //to search in the same dir
};
RibFileStack::~RibFileStack() {
//close all file
delete ribProc;
while(!stack->isEmpty())
popFile();
popFile(); //close all file
delete stack; //it's enough?
/*
while(popFile()); delete stack;
*/
};
//open file and push the text stream to stack
@ -27,12 +25,18 @@ bool RibFileStack::pushFile(QString* path) {
};
bool RibFileStack::pushFile(QFile* file) {
//add file to stack and open it
if(!(*file).open(QIODevice::ReadOnly)) {
return false;
}
QTextStream* stream = new QTextStream(file);
QPair<QFile*, QTextStream*>* p = new QPair<QFile*, QTextStream*>(file, stream);
stack->push(p);
if(stack->count() == 1) { //if it's the first prepare next line
bool end;
nextLine = topNextLine(&end);
nextLineType = isRibProcedure(nextLine);
}
return true;
};
@ -48,52 +52,153 @@ bool RibFileStack::popFile() {
//return the next line from file at top of stack
//if it's the end of this file, pop it and take the line of next
//if it's a ReadArchive statement, add the new file at the top of stack
QString RibFileStack::topNextLine() {
if(stack->isEmpty())
return QString::null;
QString RibFileStack::topNextLine(bool* end) {
if(stack->isEmpty()) {
*end = true;
return "";
}
//take the top element from stack
QPair<QFile*, QTextStream*>* p = stack->top();
//the stream of file
QTextStream* s = (p->second);
if(!s->atEnd()) {
QString line = s->readLine();
QStringList token = line.split(' ');
//test if it's a statement to open a new file
if(token[0].trimmed() == "ReadArchive") {
//if it's a ReadArchive statement search the next file to parse
//search in subdir list
bool found = false;
//token[1] is the file name
for(int i=0; i<subDir.size() && !found; i++) {
token[1] = token[1].trimmed();
QString str(templateDir + QDir::separator() + (subDir)[i] + QDir::separator() + token[1].remove('\"'));
if(pushFile(&str)) {
found = true;
}
}
if(found)
//recursive call (the top is changed)
return topNextLine();
//else
//return the line "ReadArchive ..."
}
return line;
*end = false;
QString str = s->readLine();
if(str == "")
return topNextLine(end); //ignore empty line
else
return str;
} else {
//close and remove from stack the file
popFile();
//recursive call (the top is changed)
return topNextLine();
return topNextLine(end);
}
};
bool RibFileStack::isEmpty() const {
//return the next statement of file stack (maybe on more line)
QString RibFileStack::nextStatement(int* type, bool manageReadArchive) {
if(nextLine == "") {
bool end = false;
nextLine = topNextLine(&end);
if(end) {
*type = ribParser::NOMORESTATEMENT;
return nextLine; //no more line to be readable
}
else
*type = isRibProcedure(nextLine);
}
QString str = nextLine; //nextline is a rib procedure
*type = nextLineType;
if(*type == ribParser::READARCHIVE) {
qDebug("is a ReadArchive");
QStringList token = ribParser::splitStatement(&str);
//0: ReadArchive,
//1: " ,
//2: <string> ,
//3: "
bool end;
while(token.size() < 4 && !end) {
QString line = topNextLine(&end);
str += " " + line;
token = ribParser::splitStatement(&str);
}
if(manageReadArchive) {
if(readArchive(str)) { //add the new file to stack
nextLine = topNextLine(&end);
nextLineType = isRibProcedure(nextLine);
//qDebug("Readed: %s Type: %d",qPrintable(str), *type);
//qDebug("nextline: %s type: %d",qPrintable(nextLine),nextLineType);
return nextStatement(type, manageReadArchive); //read the first line of new file, if found it
}
else
return str;
}
else
return str;
}
else { //it isn't a ReadArchive procedure
bool end;
nextLine = topNextLine(&end); //take next line
if(!inString(str))
nextLineType = isRibProcedure(nextLine);
else //maybe a string with a procedure name
nextLineType = ribParser::NOTAPROCEDURE;
while(nextLine != "" && nextLineType == ribParser::NOTAPROCEDURE ) {
//qDebug("nextline: %s type: %d",qPrintable(nextLine),nextLineType);
str += "\n" + nextLine; //if isn't a rib procedure append to str
nextLine = topNextLine(&end);
if(!inString(str))
nextLineType = isRibProcedure(nextLine); //if there's a string opened, don't test if it's a procedure
}
//qDebug("Readed: %s Type: %d",qPrintable(str), *type);
//qDebug("nextline: %s type: %d",qPrintable(nextLine),nextLineType);
return str;
}
}
//parse the statement, search and add the new file to stack
bool RibFileStack::readArchive(QString line) {
QStringList token = ribParser::splitStatement(&line);
//test if it's a statement to open a new file
if(ribProc->value(token[0]) == ribParser::READARCHIVE) {
//if it's a ReadArchive statement search the next file to parse
//search in subdir list
QString filename = token[2];
//token[2] is the file name
for(int i=0; i<subDir.size(); i++) {
QString str(templateDir + QDir::separator() + (subDir)[i] + QDir::separator() + filename);
//qDebug("looking for: %s",qPrintable(str));
if(pushFile(&str)) {
return true;
}
}
}
return false;
}
//true if in line there's a string opened and not closed
bool RibFileStack::inString(QString line) const {
if(!line.contains('\"'))
return false;
line = line.trimmed();
int a = 0;
bool slash = false;
for(int i=0; i<line.size(); i++) {
if(!slash && line[i] == '\"') {
a++;
slash = false;
}
else {
if(!slash && line[i] == '\\')
slash = true;
else
slash = false;
}
}
return a%2 != 0;
}
//check if is't a rib procedure (in ribProc table)
int RibFileStack::isRibProcedure(QString line) const {
if(line == "")
return ribParser::NOTAPROCEDURE;
if(line.trimmed().startsWith('#')) //RibProcedure " ...\n#..." how does appen?
return ribParser::COMMENT;
QString token = line.left(line.indexOf(' ')).trimmed();
return ribProc->value(token);
}
bool RibFileStack::hasNext() const {
return stack->isEmpty();
};
//append a directory list to the list of stack
bool RibFileStack::addSubDirs(QStringList dirs) {
foreach(QString dir,dirs)
subDir.append(dir);
return true;
};

View File

@ -5,6 +5,7 @@
#include <QPair>
#include <QString>
#include <QStringList>
#include "ribProcedure.h"
class RibFileStack {
@ -13,12 +14,22 @@ public:
~RibFileStack();
bool pushFile(QString* path);
bool pushFile(QFile* file);
QString topNextLine();
bool isEmpty() const;
bool addSubDirs(QStringList dirs);
bool hasNext() const;
bool addSubDirs(QStringList dirs);
QString nextStatement(int* type, bool manageReadArchive = true);
bool readArchive(QString line);
private:
QStack< QPair<QFile*, QTextStream*>* >* stack;
QString templateDir;
bool popFile();
QStringList subDir;
bool popFile();
int isRibProcedure(QString line) const;
bool inString(QString line) const;
QString nextLine;
int nextLineType;
QString topNextLine(bool* end);
QHash<QString, int>* ribProc;
};

View File

@ -85,18 +85,7 @@ void FilterHighQualityRender::initParameterSet(QAction *action, MeshModel &m, Ri
{
switch(ID(action)) {
case FP_HIGHQUALITY_RENDER :
{
//parlst.addParam(new RichInt("FormatX", 800, "Format X"));
//parlst.addParam(new RichInt("FormatY", 600, "Format Y"));
parlst.addParam(new RichInt("FormatX", 320, "Format X"));
parlst.addParam(new RichInt("FormatY", 200, "Format Y"));
parlst.addParam(new RichFloat("PixelAspectRatio", 1.0, "Pixel aspect ratio"));
parlst.addParam(new RichBool("Autoscale",true,"Auto-scale mesh","Check if the object will be scaled on render scene"));
QStringList alignValueList = (QStringList() << "Center" << "Top" << "Bottom");
parlst.addParam(new RichEnum("AlignX",0,alignValueList,"Align X"));
parlst.addParam(new RichEnum("AlignY",0,alignValueList,"Align Y"));
parlst.addParam(new RichEnum("AlignZ",0,alignValueList,"Align Z"));
{
//update the template list
templates = QStringList();
foreach(QString subDir, templatesDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) {
@ -110,18 +99,24 @@ void FilterHighQualityRender::initParameterSet(QAction *action, MeshModel &m, Ri
qDebug(qPrintable(this->errorMessage));
}
parlst.addParam(new RichEnum("scene",0,templates,"Select scene"));
//parlst.addParam(new RichInt("frames",0, "Number of frames for animation (0 for no animation)"));
//parlst.addParam(new RichInt("frames",0, "Number of frames for animation (0 for no animation)"));
parlst.addParam(new RichString("ImageName", "default", "Name of output image"));
parlst.addParam(new RichEnum("ImageFormat", 0, imageFormatsSupported, "Output image format"));
//DON'T WORK!!not implemented
//delRibFiles = true;
//FileValue fv("");
//parlst.addParam(new RichSaveFile("SceneName",&fv,&FileDecoration(&fv,".rib","Name of file rib to save","If not specified, the files will be removed")));
parlst.addParam(new RichBool("ShowResult",true,"Show the images created?","If checked a window with the created images will be showed at finish"));
//parlst.addParam(new RichInt("FormatX", 800, "Format X"));
//parlst.addParam(new RichInt("FormatY", 600, "Format Y"));
parlst.addParam(new RichInt("FormatX", 320, "Format X"));
parlst.addParam(new RichInt("FormatY", 200, "Format Y"));
parlst.addParam(new RichFloat("PixelAspectRatio", 1.0, "Pixel aspect ratio"));
parlst.addParam(new RichBool("Autoscale",true,"Auto-scale mesh","Check if the object will be scaled on render scene"));
QStringList alignValueList = (QStringList() << "Center" << "Top" << "Bottom");
parlst.addParam(new RichEnum("AlignX",0,alignValueList,"Align X"));
parlst.addParam(new RichEnum("AlignY",0,alignValueList,"Align Y"));
parlst.addParam(new RichEnum("AlignZ",0,alignValueList,"Align Z"));
parlst.addParam(new RichBool("SaveScene",false,"Save the files created for rendering?",
"If checked the scene will be created in the same directory of mesh, else in the temporary system folder and then removed"));
break;
}
}
default : assert(0);
}
}
@ -129,13 +124,8 @@ void FilterHighQualityRender::initParameterSet(QAction *action, MeshModel &m, Ri
// The Real Core Function doing the actual mesh processing.
bool FilterHighQualityRender::applyFilter(QAction *filter, MeshModel &m, RichParameterSet & par, vcg::CallBackPos *cb)
{
// Typical usage of the callback for showing a nice progress bar in the bottom.
// First parameter is a 0..100 number indicating percentage of completion, the second is an info string.
//cb(100*i/m.cm.vert.size(), "Randomly Displacing...");
// Log function dump textual info in the lower part of the MeshLab screen.
//Log(GLLogStream::FILTER,"Successfully displaced %i vertices",m.cm.vn);
this->cb = cb;
QTime tt; tt.start(); //debug
QTime tt; tt.start(); //time for debuging
qDebug("Starting apply filter");
QString templateName = templates.at(par.getEnum("scene"));
@ -154,6 +144,7 @@ bool FilterHighQualityRender::applyFilter(QAction *filter, MeshModel &m, RichPar
//creating of destination directory
bool delRibFiles = !par.getBool("SaveScene");
//if SaveScene is true create in same mesh directory, otherwise in system temporary directry
QDir destDir = QDir::temp(); //system temporary directry
if(!delRibFiles) {
//destDir = QDir(par.getSaveFileName("SceneName"));
@ -208,14 +199,14 @@ bool FilterHighQualityRender::applyFilter(QAction *filter, MeshModel &m, RichPar
//check if the final rib file will render any image
if(imagesRendered.size() == 0) {
this->errorMessage = "The template hasn't statement to render any image";
this->errorMessage = "The template hasn't a statement to render any image";
return false;
}
//copy the rest of template (shaders, textures, procedural..)
copyFiles(templateDir, destDir, textureDirs);
copyFiles(templateDir, destDir, shaderDirs);
copyFiles(templateDir, destDir, proceduralDirs);
copyFiles(&templateDir, &destDir, &textureDirs);
copyFiles(&templateDir, &destDir, &shaderDirs);
copyFiles(&templateDir, &destDir, &proceduralDirs);
qDebug("Copied needed file at %i",tt.elapsed());
QStringList aqsisEnv = QProcess::systemEnvironment();
@ -383,26 +374,27 @@ bool FilterHighQualityRender::applyFilter(QAction *filter, MeshModel &m, RichPar
cb(100, qPrintable("Created " + QString::number(imagesRendered.size())+" images"));
//run piqls with rendered image
QProcess piqslProcess;
piqslProcess.setWorkingDirectory(destDirString);
piqslProcess.setEnvironment(aqsisEnv);
toRun = aqsisDir + aqsisBinPath() + QDir::separator() + piqslName();
//if there'isnt image, it stops before...
foreach(QString img, imagesRendered) {
toRun += " " + img;
if(par.getBool("ShowResult")) {
QProcess piqslProcess;
piqslProcess.setWorkingDirectory(destDirString);
piqslProcess.setEnvironment(aqsisEnv);
toRun = aqsisDir + aqsisBinPath() + QDir::separator() + piqslName();
//if there'isnt image, it stops before...
foreach(QString img, imagesRendered) {
toRun += " " + img;
}
qDebug("Runnig piqsl command: %s", qPrintable(toRun));
piqslProcess.start(toRun);
piqslProcess.waitForFinished(-1); //no check error...
piqslProcess.terminate();
}
qDebug("Runnig piqsl command: %s", qPrintable(toRun));
piqslProcess.start(toRun);
piqslProcess.waitForFinished(-1); //no check error...
piqslProcess.terminate();
//only now we can delete recursively all created files (if it's required)
if(delRibFiles) {
QString dirName = destDir.dirName();
QDir temp = destDir;
temp.cdUp();
delDir(temp, dirName);
delDir(&temp, &dirName);
delRibFiles = false;
}
qDebug("finsish to apply filter at %i",tt.elapsed());
@ -417,7 +409,7 @@ void FilterHighQualityRender::updateOutputProcess() {
QString out = QString::fromLocal8Bit(renderProcess.readAllStandardOutput().data());
//qDebug("aqsis.exe output: %s",qPrintable(out));
out = QStringList(out.trimmed().split(' ')).last(); //take only the last
qDebug("aqsis output taken: %s",qPrintable(out));
//qDebug("aqsis output taken: %s",qPrintable(out));
int currentCb = int(out.toFloat());
if(currentCb < lastCb)
worldBeginRendered++;
@ -425,7 +417,7 @@ void FilterHighQualityRender::updateOutputProcess() {
QString::number(worldBeginRendered) + "/" + QString::number(numOfWorldBegin) + ")";
int value = int( (100 * (worldBeginRendered - 1) + currentCb ) / numOfWorldBegin );
cb(value, qPrintable(msg)); //update progress bar
qDebug("cb value: worldBeginRendered %i last %i current %i effective %i" ,worldBeginRendered,lastCb,currentCb,value);
//qDebug("cb value: worldBeginRendered %i last %i current %i effective %i" ,worldBeginRendered,lastCb,currentCb,value);
lastCb = currentCb;
//restore the signal handling
connect(&renderProcess, SIGNAL(readyReadStandardOutput()),this, SLOT(updateOutputProcess()));

View File

@ -1,113 +1,114 @@
#ifndef FILTER_HQRENDER_H
#define FILTER_HQRENDER_H
#include <QObject>
#include <QDir>
#include <QString>
#include <QStringList>
#ifndef FILTER_HQRENDER_H
#define FILTER_HQRENDER_H
#include <QObject>
#include <QDir>
#include <QString>
#include <QStringList>
#include <QProcess>
#include "RibFileStack.h"
#include "export_rib.h"
#include "utilities_hqrender.h"
#include <common/meshmodel.h>
#include <common/interfaces.h>
class FilterHighQualityRender : public QObject, public MeshFilterInterface
{
Q_OBJECT
Q_INTERFACES(MeshFilterInterface)
public:
enum { FP_HIGHQUALITY_RENDER } ;
FilterHighQualityRender();
//filter_hqrender.cpp
virtual QString filterName(FilterIDType filter) const;
virtual QString filterInfo(FilterIDType filter) const;
virtual bool autoDialog(QAction *) {return true;}
virtual void initParameterSet(QAction *,MeshModel &m, RichParameterSet & param);
virtual bool applyFilter(QAction *filter, MeshModel &m, RichParameterSet & param, vcg::CallBackPos * cb) ;
virtual FilterClass getClass(QAction *a);
private slots:
void updateOutputProcess();
void errSgn();
private:
vcg::CallBackPos * cb;
int worldBeginRendered, numOfWorldBegin, lastCb; //for progress bar update
QProcess renderProcess;
QDir templatesDir; //directory of templates ("render_template")
QStringList templates; //list of templates found
QStringList imageFormatsSupported; //list of image formats supported by qt for conversion of final image
enum alignValue { CENTER, TOP, BOTTOM };
bool convertedGeometry;
inline const QString aqsisName()
{
#if defined(Q_OS_WIN)
return QString("aqsis.exe");
#elif defined(Q_OS_MAC)
return QString("aqsis");
#endif
}
inline const QString aqslName()
{
#if defined(Q_OS_WIN)
return QString("aqsl.exe");
#elif defined(Q_OS_MAC)
return QString("aqsl");
#endif
}
inline const QString teqserName()
{
#if defined(Q_OS_WIN)
return QString("teqser.exe");
#elif defined(Q_OS_MAC)
return QString("teqser");
#endif
}
inline const QString piqslName()
{
#if defined(Q_OS_WIN)
return QString("piqsl.exe");
#elif defined(Q_OS_MAC)
return QString("piqsl");
#endif
}
inline const QString aqsisBinPath()
{
#if defined(Q_OS_WIN)
return QString("bin");
#elif defined(Q_OS_MAC)
return QString("/Contents/Resources/bin/");
#endif
}
inline const QString mainFileName() { return QString("scene.rib"); }
//parser_rib.cpp
int numberOfDummies, numOfObject;
struct ObjValues {
vcg::Matrix44f objectMatrix;
float objectBound[6]; // xmin, xmax, ymin, ymax, zmin, zmax
QStringList objectShader;
QString objectId;
QString objectDisplacementbound;
};
bool makeScene(MeshModel &m, QStringList* textureList, RichParameterSet &par, QString templatePath, QString destDirString, QStringList* shaderDirs, QStringList* textureDirs, QStringList* proceduralDirs, QStringList* imagesRendered);
QString parseObject(RibFileStack* files, QString destDir, int currentFrame, MeshModel &m, RichParameterSet &par, QStringList* textureList);
int convertObject(FILE* fout, QString destDir, MeshModel &m, RichParameterSet &par, QStringList* textureList, ObjValues* dummyValues);
int makeAnimation(FILE* fout, int numOfFrame, vcg::Matrix44f initialCamera, QStringList frameDeclaration, QString imageName);
int writeMatrix(FILE* fout, vcg::Matrix44f matrix, bool transposed = true);
QString readArray(RibFileStack* files,QString arrayString = "");
vcg::Matrix44f getMatrix(QString matrixString);
enum searchType{ ERR, ARCHIVE, SHADER, TEXTURE, PROCEDURAL };
QStringList readSearchPath(RibFileStack* files,QString line, int* type);
};
#endif
#include "RibFileStack.h"
#include "export_rib.h"
#include "utilities_hqrender.h"
#include <common/meshmodel.h>
#include <common/interfaces.h>
class FilterHighQualityRender : public QObject, public MeshFilterInterface
{
Q_OBJECT
Q_INTERFACES(MeshFilterInterface)
public:
enum { FP_HIGHQUALITY_RENDER } ;
FilterHighQualityRender();
//filter_hqrender.cpp
virtual QString filterName(FilterIDType filter) const;
virtual QString filterInfo(FilterIDType filter) const;
virtual bool autoDialog(QAction *) {return true;}
virtual void initParameterSet(QAction *,MeshModel &m, RichParameterSet & param);
virtual bool applyFilter(QAction *filter, MeshModel &m, RichParameterSet & param, vcg::CallBackPos * cb) ;
virtual FilterClass getClass(QAction *a);
private slots:
void updateOutputProcess();
void errSgn();
private:
vcg::CallBackPos * cb;
int worldBeginRendered, numOfWorldBegin, lastCb; //for progress bar update
QProcess renderProcess;
QDir templatesDir; //directory of templates ("render_template")
QStringList templates; //list of templates found
QStringList imageFormatsSupported; //list of image formats supported by qt for conversion of final image
enum alignValue { CENTER, TOP, BOTTOM };
bool convertedGeometry;
inline const QString aqsisName()
{
#if defined(Q_OS_WIN)
return QString("aqsis.exe");
#elif defined(Q_OS_MAC)
return QString("aqsis");
#endif
}
inline const QString aqslName()
{
#if defined(Q_OS_WIN)
return QString("aqsl.exe");
#elif defined(Q_OS_MAC)
return QString("aqsl");
#endif
}
inline const QString teqserName()
{
#if defined(Q_OS_WIN)
return QString("teqser.exe");
#elif defined(Q_OS_MAC)
return QString("teqser");
#endif
}
inline const QString piqslName()
{
#if defined(Q_OS_WIN)
return QString("piqsl.exe");
#elif defined(Q_OS_MAC)
return QString("piqsl");
#endif
}
inline const QString aqsisBinPath()
{
#if defined(Q_OS_WIN)
return QString("bin");
#elif defined(Q_OS_MAC)
return QString("/Contents/Resources/bin/");
#endif
}
inline const QString mainFileName() { return QString("scene.rib"); }
//parser_rib.cpp
int numberOfDummies, numOfObject;
struct ObjValues {
vcg::Matrix44f objectMatrix;
float objectBound[6]; // xmin, xmax, ymin, ymax, zmin, zmax
QStringList objectShader;
QString objectId;
QString objectDisplacementbound;
};
bool makeScene(MeshModel &m, QStringList* textureList, RichParameterSet &par, QString templatePath, QString destDirString, QStringList* shaderDirs, QStringList* textureDirs, QStringList* proceduralDirs, QStringList* imagesRendered);
QString parseObject(RibFileStack* files, QString destDir, int currentFrame, MeshModel &m, RichParameterSet &par, QStringList* textureList);
int convertObject(FILE* fout, QString destDir, MeshModel &m, RichParameterSet &par, QStringList* textureList, ObjValues* dummyValues);
int makeAnimation(FILE* fout, int numOfFrame, vcg::Matrix44f initialCamera, QStringList frameDeclaration, QString imageName);
int writeMatrix(FILE* fout, vcg::Matrix44f matrix, bool transposed = true);
//QString readArray(RibFileStack* files,QString arrayString = "");
vcg::Matrix44f getMatrix(QString matrixString);
enum searchType{ ERR, ARCHIVE, SHADER, TEXTURE, PROCEDURAL };
//QStringList readSearchPath(RibFileStack* files,QString line, int* type);
QStringList readSearchPath(const QStringList* token, int* type);
};
#endif

View File

@ -3,7 +3,8 @@ include (../../shared.pri)
HEADERS += filter_hqrender.h \
export_rib.h \
RibFileStack.h \
utilities_hqrender.h
utilities_hqrender.h \
ribProcedure.h
SOURCES += filter_hqrender.cpp \

View File

@ -1,4 +1,4 @@
#include "filter_hqrender.h"
#include "filter_hqrender.h"
#include <limits>
using namespace UtilitiesHQR;
@ -48,140 +48,166 @@ bool FilterHighQualityRender::makeScene(MeshModel &m,
numOfObject = 0;
//reading cycle
//int debugCount = 0;
while(!files.isEmpty() && !stop) {
while(!files.hasNext() && !stop) {
//if((++debugCount)%200 == 0) qDebug("Time after %i statement: %i",debugCount,tt.elapsed());
bool writeLine = true;
QString line = files.topNextLine();
int statementType = 0;
QString line = files.nextStatement(&statementType);
//the ReadArchive statement is already handled
QStringList token = line.split(' ');
//statement to declare other directory for the template
if(token[0].trimmed() == "Option" && token[1].trimmed() == "\"searchpath\"") {
int type = 0;
QStringList dirList = readSearchPath(&files,line,&type);
switch(type) {
case FilterHighQualityRender::ARCHIVE:
files.addSubDirs(dirList);
break;
case FilterHighQualityRender::SHADER:
*shaderDirs = dirList;
break;
case FilterHighQualityRender::TEXTURE:
*textureDirs = dirList;
break;
case FilterHighQualityRender::PROCEDURAL:
*proceduralDirs = dirList;
break;
case FilterHighQualityRender::ERR:
//ignore: maybe an error or another searchpath type (not in RISpec3.2)
break;
}
}
//there are some statement that make an output. It's need to create the path
if(token[0].trimmed().startsWith("Make")) {
QString path = token[2]; //for MakeTexture, MakeShadow, MakeLatLongEnvironment
if(token[0].trimmed() == "MakeCubeFaceEnvironment")
path = token[7];
path = getDirFromPath(&path);
//qDebug("check dir! line: %s\npath: %s",qPrintable(line),qPrintable(path));
checkDir(destDirString,path);
}
if(token[0].trimmed() == "FrameBegin") {
currentFrame = token[1].trimmed().toInt(); //no check on cast
if(currentFrame == 1) { //questo è casino con animazioni
if(numOfFrames > 0)
isFrameDeclaration = true;
}
}
//if there's an animation, stop the processing of other possible frame
if(numOfFrames > 0 && currentFrame == 1 && token[0].trimmed() == "FrameEnd") {
fprintf(fout,"%s\n",qPrintable(line));
writeLine = false;
makeAnimation(fout,numOfFrames,transfCamera,frameDeclaration,par.getString("ImageName"));
stop = true;
}
//if output is not a file the format must be the same!!framebuffer is ignored and commented
if(token[0].trimmed() == "Display") {
//create the path if needed
QString path = token[1].trimmed();
path = getDirFromPath(&path);
//qDebug("check dir! line: %s\npath: %s",qPrintable(line),qPrintable(path));
checkDir(destDirString,path);
//if there's more "Display" statement with one that's "file" is not considered a final image
if(token[2].trimmed() != "\"framebuffer\"")
if (!anyOtherDisplayType && token[2].trimmed() == "\"file\"") {
currentDisplayTypeIsFile = true;
QString img = token[1].trimmed().remove('\"');
if(img.startsWith('+'))
img = img.mid(1,img.size());
*imagesRendered << img;
switch(statementType) {
case ribParser::OPTION: {
QStringList token = ribParser::splitStatement(&line);
//statement to declare other directory for the template
if(token[2] == "searchpath") {
int type = 0;
QStringList dirList = readSearchPath(&token,&type);
switch(type) {
case FilterHighQualityRender::ARCHIVE:
files.addSubDirs(dirList);
break;
case FilterHighQualityRender::SHADER:
*shaderDirs = dirList;
break;
case FilterHighQualityRender::TEXTURE:
*textureDirs = dirList;
break;
case FilterHighQualityRender::PROCEDURAL:
*proceduralDirs = dirList;
break;
case FilterHighQualityRender::ERR:
//ignore: maybe an error or another searchpath type (not in RISpec3.2)
break;
}
}
break;
}
case ribParser::MAKE:
case ribParser::MAKECUBEFACEENVIRONMENT:
{
QStringList token = ribParser::splitStatement(&line);
QString path = token[2]; //for MakeTexture, MakeShadow, MakeLatLongEnvironment
if(statementType == ribParser::MAKECUBEFACEENVIRONMENT)
path = token[7];
path = getDirFromPath(&path);
//qDebug("check dir! line: %s\npath: %s",qPrintable(line),qPrintable(path));
checkDir(&destDirString,&path);
break;
}
case ribParser::FRAMEBEGIN:
{
QStringList token = ribParser::splitStatement(&line);
currentFrame = token[1].toInt(); //no check on cast
if(currentFrame == 1) { //questo è casino con animazioni
if(numOfFrames > 0)
isFrameDeclaration = true;
}
break;
}
case ribParser::FRAMEEND:
{
//if there's an animation, stop the processing of other possible frame
if(numOfFrames > 0 && currentFrame == 1) {
fprintf(fout,"%s\n",qPrintable(line));
writeLine = false;
makeAnimation(fout,numOfFrames,transfCamera,frameDeclaration,par.getString("ImageName"));
stop = true;
}
break;
}
case ribParser::DISPLAY:
{
//if output is not a file the format must be the same!! framebuffer is ignored and commented
QStringList token = ribParser::splitStatement(&line);
//create the path if needed
QString path = token[2];
path = getDirFromPath(&path);
//qDebug("check dir! line: %s\npath: %s",qPrintable(line),qPrintable(path));
checkDir(&destDirString,&path);
//if there's more "Display" statement with one that's "file" is not considered a final image
if(token[5] != "framebuffer")
if (!anyOtherDisplayType && token[5] == "file") {
currentDisplayTypeIsFile = true;
QString img = token[2];
if(img.startsWith('+'))
img = img.mid(1,img.size());
*imagesRendered << img;
}
else
anyOtherDisplayType = true;
else
anyOtherDisplayType = true;
else
line = "#" + line; //if there's a framebuffer will be open pqsl automatically
}
//transformation camera
if(numOfFrames > 0 && token[0].trimmed() == "Transform") {
line = readArray(&files,line);
transfCamera = getMatrix(line);
/*transfCamera = readMatrix(&files, line);
writeMatrix(fout,transfCamera);
writeLine = false;*/
}
//make another file if there is an animation
if(token[0].trimmed() == "WorldBegin") {
numOfWorldBegin++;
//if there's another type of display the format is not change
if(!anyOtherDisplayType && currentDisplayTypeIsFile) {
fprintf(fout,"%s\n", qPrintable(newFormat));
frameDeclaration << newFormat;
line = "#" + line; //if there's a framebuffer will be open pqsl automatically
break;
}
currentDisplayTypeIsFile = false;
anyOtherDisplayType = false;
//is right?yes,because before the next WorldBegin will there be a new Display statement
if(numOfFrames > 0) {
isFrameDeclaration = false;
//it's certainly the first WorldBegin
QString filename = destDirString + QDir::separator() + "world.rib";
fprintf(fout,"ReadArchive \"world.rib\"\n");
fout = fopen(qPrintable(filename),"wb");
if(fout == NULL) {
case ribParser::TRANSFORM:
{
//transformation camera
if(numOfFrames > 0) {
//line = readArray(&files,line); ////
transfCamera = getMatrix(line);
}
break;
}
case ribParser::WORLDBEGIN:
{
numOfWorldBegin++;
//if there's another type of display the format is not change
if(!anyOtherDisplayType && currentDisplayTypeIsFile) {
fprintf(fout,"%s\n", qPrintable(newFormat));
frameDeclaration << newFormat;
}
currentDisplayTypeIsFile = false;
anyOtherDisplayType = false;
//is right?yes,because before the next WorldBegin will there be a new Display statement
//make another file if there is an animation
if(numOfFrames > 0) {
isFrameDeclaration = false;
//it's certainly the first WorldBegin
QString filename = destDirString + QDir::separator() + "world.rib";
fprintf(fout,"ReadArchive \"world.rib\"\n");
fout = fopen(qPrintable(filename),"wb");
if(fout == NULL) {
}
}
break;
}
case ribParser::WORLDEND:
{
if(numOfFrames > 0) {
//it's certainly the first WorldEnd
fprintf(fout,"%s\n",qPrintable(line));
fclose(fout);
fout = fmain;
writeLine = false;
}
break;
}
case ribParser::ATTRIBUTEBEGIN:
{
//is an object
//write it (o convert it if it's named dummy) to another file
QString filename = parseObject(&files, destDirString, currentFrame, m, par, textureList);
qDebug("fuori: %s",qPrintable(filename));
writeLine = false;
fprintf(fout,"ReadArchive \"%s\"\n",qPrintable(filename));
break;
}
case ribParser::NOMORESTATEMENT:
{
qDebug("Stack empty");
stop = true;
writeLine = false;
}
}
if(numOfFrames > 0 && token[0].trimmed() == "WorldEnd") {
//it's certainly the first WorldEnd
fprintf(fout,"%s\n",qPrintable(line));
fclose(fout);
fout = fmain;
writeLine = false;
}
//is an object
if(token[0].trimmed() == "AttributeBegin") {
//write it (o convert it if it's named dummy) to another file
QString filename = parseObject(&files, destDirString, currentFrame, m, par, textureList);
qDebug("fuori: %s",qPrintable(filename));
writeLine = false;
fprintf(fout,"ReadArchive \"%s\"\n",qPrintable(filename));
}
if(writeLine) {
//copy the same line in file
fprintf(fout,"%s\n",qPrintable(line));
}
if(isFrameDeclaration && token[0].trimmed() != "FrameBegin" && token[0].trimmed() != "Transform")
if(isFrameDeclaration && statementType != ribParser::FRAMEBEGIN && statementType != ribParser::TRANSFORM)
frameDeclaration << line;
}
fclose(fout);
@ -194,105 +220,97 @@ QString FilterHighQualityRender::parseObject(RibFileStack* files, QString destDi
FILE* fout = fopen(qPrintable(destDirString + QDir::separator() + name),"wb");
if(fout == NULL) {
}
qDebug("parse object");
//if it's a dummy object, i need the the follow value:
ObjValues* current = new ObjValues();
current->objectMatrix = vcg::Matrix44f::Identity();
//default RIS bound is infinite
for(int i=0; i< 6; i=i+2)
current->objectBound[i] = std::numeric_limits<int>::min();
current->objectBound[i] = std::numeric_limits<float>::min();
for(int i=1; i<6; i=i+2)
current->objectBound[i] = std::numeric_limits<int>::max();
current->objectBound[i] = std::numeric_limits<float>::max();
//write AttributeBegin statement
//write AttributeBegin statement (already readed)
fprintf(fout,"AttributeBegin\n");
//write next statement and looking for an object called "dummy"...
int c = 1; //number of nestled "AttributeBegin"
bool isDummy = false;
while(!files->isEmpty() && c != 0) {
QString line = files->topNextLine();
QStringList token = line.split(' ');
bool isDummy = false; //if is dummy stops to write
while(c != 0 && !files->hasNext()) {
int statementType = 0;
QString line = files->nextStatement(&statementType);
//the surface shader remain the same of template (maybe many line and many shader)
if(token[0].trimmed() == "Surface") {
current->objectShader << line;
fprintf(fout,"%s\n",qPrintable(line));
line = files->topNextLine();
while(line.trimmed().startsWith('\"'))
{
current->objectShader << line;
fprintf(fout,"%s\n",qPrintable(line));
line = files->topNextLine();
switch(statementType) {
case ribParser::ATTRIBUTEBEGIN:
++c;
break;
case ribParser::ATTRIBUTEEND:
--c;
break;
case ribParser::SURFACE:
{
//the surface shader remain the same of template
current->objectShader << line;
break;
}
token = line.split(' ');
}
//from previous "if", if condition is true, exit a new line
if(token[0].trimmed() == "AttributeEnd")
--c;
if(token[0].trimmed() == "AttributeBegin")
++c;
//take the transformation matrix of object
if(token[0].trimmed() == "Transform") {
line = readArray(files,line);
current->objectMatrix = getMatrix(line);
}
//take the transformation bound
if(token[0].trimmed() == "Bound") {
if(line.contains('['))
line = readArray(files, line);
line.remove('[');
line.remove(']');
token = line.split(' ');
for(int i=0; i<6; i++) {
current->objectBound[i] = token[i+1].toFloat();
case ribParser::TRANSFORM:
{
current->objectMatrix = getMatrix(line);
break;
}
}
if(token[0].trimmed() == "Attribute")
{
qDebug("%s\n",qPrintable(line));
line = readArray(files, line); //if there's an array, maybe contains '\n'
token = line.split(' ');
qDebug("%s\n",qPrintable(line));
//RISpec3.2 not specify how many attribute are there in renderman
//"user id" and "displacemetbound" don't be needed (perhaps)
if(token[1].trimmed() == "\"user\"" && current->objectId == "")
current->objectId = line; //only first time (can be nestled id attributes)
if(token[1].trimmed() == "\"displacementbound\"")
current->objectDisplacementbound = line;
if(token[1].trimmed() == "\"identifier\"") {
int index = 2;
if(token[2].trimmed() == "\"string")
index++; //is "string name"..
if(token[index].trimmed() == "\"name\"" || token[index].trimmed() == "name\"") {
QString str = token[++index];
if(token.size()>(index+1))
for(int i = index + 1; i < token.size(); i++) {
str += " " + token[i]; //the remainig tokens are joined together
}
str = readArray(files, str);
//remove the character [ ] "
str.remove('[');
str.remove(']');
str.remove('\"');
str = str.simplified();
if(str.toLower() == "dummy") //found a dummy object?
isDummy = true;
case ribParser::BOUND:
{
//take the transformation bound
QStringList token = ribParser::splitStatement(&line);
int index = 1;
if(token[index] == "[")
index++;
for(int i=0; i<6; i++) {
bool isNumber;
float number = token[index+i].toFloat(&isNumber);
if(isNumber)
current->objectBound[i] = number;
}
break;
}
case ribParser::ATTRIBUTE:
{
QStringList token = ribParser::splitStatement(&line);
QString deb = "";
foreach(QString s,token)
deb += "str: " + s + "\n";
qDebug(qPrintable(deb));
//RISpec3.2 not specify what and how many attributes are there in renderman
//"user id" and "displacemetbound" don't be needed (perhaps)
if(token[2] == "user" && current->objectId == "")
current->objectId = line; //only first time (can be nestled id attributes)
if(token[2] == "displacementbound")
current->objectDisplacementbound = line;
if(token[2] == "identifier") {
//Attribute "identifier" "string name" [ "object name" ]
if(token[5] == "string name" || token[5] == "name") {
int index = 7;
if(token[index] == "[")
index++;
if(token[index] == "\"")
index++;
if(token[index].trimmed().toLower() == "dummy") {//found a dummy object?
qDebug("object name is dummy");
isDummy = true;
}
}
}
break;
}
case ribParser::NOMORESTATEMENT:
{
c = 0;
break;
}
}
if(!isDummy) {
fprintf(fout,"%s\n",qPrintable(line));
}
@ -300,6 +318,7 @@ QString FilterHighQualityRender::parseObject(RibFileStack* files, QString destDi
fclose(fout);
if(isDummy) {
qDebug("Found dummy object");
//delete the previous file
QDir tmp = QDir(destDirString);
tmp.remove(name);
@ -325,7 +344,8 @@ int FilterHighQualityRender::convertObject(FILE* fout, QString destDir, MeshMode
//name
fprintf(fout,"Attribute \"identifier\" \"string name\" [ \"dummy\" ]\n");
//id
fprintf(fout,"%s\n",dummyValues->objectId);
if(dummyValues->objectId != "")
fprintf(fout,"%s\n",qPrintable(dummyValues->objectId.trimmed()));
//modify the transformation matrix
vcg::Matrix44f scaleMatrix = vcg::Matrix44f::Identity();
@ -373,7 +393,7 @@ int FilterHighQualityRender::convertObject(FILE* fout, QString destDir, MeshMode
}
vcg::Matrix44f alignMatrix;
alignMatrix = alignMatrix.SetTranslate(dx,dy,dz);
vcg::Matrix44f templateMatrix = dummyValues->objectMatrix;
vcg::Matrix44f templateMatrix = dummyValues->objectMatrix; //by default is identity
vcg::Matrix44f result = templateMatrix * alignMatrix * scaleMatrix * translateBBMatrix;
//write transformation matrix (after transpose it)
@ -392,17 +412,18 @@ int FilterHighQualityRender::convertObject(FILE* fout, QString destDir, MeshMode
//force the shading interpolation to smooth
fprintf(fout,"ShadingInterpolation \"smooth\"\n");
//displacementBound
fprintf(fout,"%s\n",dummyValues->objectDisplacementbound);
if(dummyValues->objectDisplacementbound != "")
fprintf(fout,"%s\n",qPrintable(dummyValues->objectDisplacementbound.trimmed()));
//shader
foreach(QString line, dummyValues->objectShader) {
fprintf(fout,"%s\n",line);
fprintf(fout,"%s\n",qPrintable(line.trimmed()));
}
//texture mapping (are TexCoord needed for texture mapping?)
if(!textureList->empty() > 0 && (m.cm.HasPerWedgeTexCoord() || m.cm.HasPerVertexTexCoord())) {
//multi-texture don't work!I need ad-hoc shader and to read the texture index for vertex..
//foreach(QString textureName, *textureList) {
//read only the one texture
//read only the first texture
QString textureName = textureList->first();
fprintf(fout,"Surface \"paintedplastic\" \"Kd\" 1.0 \"Ks\" 0.0 \"texturename\" [\"%s.tx\"]\n", qPrintable(getFileNameFromPath(&textureName,false)));
}
@ -456,49 +477,30 @@ int FilterHighQualityRender::makeAnimation(FILE* fout, int numOfFrame,vcg::Matri
}
//return an a list of directory (separated by ':' character)
QStringList FilterHighQualityRender::readSearchPath(RibFileStack* files,QString line, int* type) {
QStringList dirs;
QStringList token = line.split(" ");
if(!(token[0].trimmed() == "Option" && token[1].trimmed() == "\"searchpath\"")) {
*type = FilterHighQualityRender::ERR;
return dirs;
}
QStringList FilterHighQualityRender::readSearchPath(const QStringList* token, int* type) {
//the line maybe: Option "searchpath" "string type" [ ..values..]
// or: Option "searchpath" "type" [ ..values..]
int index = 2;
if(token[2].trimmed() == "\"string")
index++; //is "string type"..
if(token[index].trimmed() == "\"archive\"" || token[index].trimmed() == "archive\"")
int index = 5;
*type = FilterHighQualityRender::ERR;
if((*token)[index] == "archive" || (*token)[index] == "string archive")
*type = FilterHighQualityRender::ARCHIVE;
if(token[index].trimmed() == "\"shader\"" || token[index].trimmed() == "shader\"")
if((*token)[index] == "shader" || (*token)[index] == "string shader")
*type = FilterHighQualityRender::SHADER;
if(token[index].trimmed() == "\"texture\"" || token[index].trimmed() == "texture\"")
if((*token)[index] == "texture" || (*token)[index] == "string texture")
*type = FilterHighQualityRender::TEXTURE;
if(token[index].trimmed() == "\"procedural\"" || token[index].trimmed() == "procedural\"")
if((*token)[index] == "procedural" || (*token)[index] == "string procedural")
*type = FilterHighQualityRender::PROCEDURAL;
QString str = token[++index];
if(token.size()>(index+1)) {
for(int i = index + 1; i < token.size(); i++) {
str += " " + token[i]; //the remainig tokens are joined together
}
}
//maybe that the array is defined over more line
str = readArray(files,str);
str = str.simplified();
if(str.startsWith('[') && str.endsWith(']')) {
//remove the character [ ] "
str.remove('[');
str.remove(']');
str.remove('\"');
str = str.simplified();
dirs = str.split(':'); //it's the standard method divide dirs with character ':' ?
} else {
*type = FilterHighQualityRender::ERR;
}
index = 7;
if((*token)[index] == "[")
index++;
if((*token)[index] == "\"")
index++;
//else err?
QStringList dirs = (*token)[index].split(':'); //it's the standard method divide dirs with character ':' ?
return dirs;
}
//write a vcg::Matrix44f to file
int FilterHighQualityRender::writeMatrix(FILE* fout, vcg::Matrix44f matrix, bool transposed) {
fprintf(fout,"Transform [ ");
for(int i = 0; i<4; i++)
@ -508,7 +510,7 @@ int FilterHighQualityRender::writeMatrix(FILE* fout, vcg::Matrix44f matrix, bool
return 0;
}
//get a matrix from line (and transpose it)
//get a vcg::Matrix44f from line (and transpose it)
vcg::Matrix44f FilterHighQualityRender::getMatrix(QString matrixString) {
float t[16];
int k=0;
@ -525,12 +527,4 @@ vcg::Matrix44f FilterHighQualityRender::getMatrix(QString matrixString) {
}
vcg::Matrix44f tempMatrix(t);
return tempMatrix.transpose();
}
//read array from the rib stack (an array can be contain '\n' character)
QString FilterHighQualityRender::readArray(RibFileStack* files, QString arrayString) {
QString str = arrayString;
while( (str.count('[') - str.count(']')) > 0 && !files->isEmpty())
str += " " + files->topNextLine();
return str; //a string with array
}
}

View File

@ -0,0 +1,186 @@
#include <QHash>
#include <QString>
class ribParser {
public:
enum ribProcedure {
NOTAPROCEDURE,
ATTRIBUTE,
ATTRIBUTEBEGIN,
ATTRIBUTEEND,
BOUND,
DISPLAY,
FRAMEBEGIN,
FRAMEEND,
MAKE,
MAKECUBEFACEENVIRONMENT,
OPTION,
READARCHIVE,
SURFACE,
TRANSFORM,
WORLDBEGIN,
WORLDEND,
COMMENT,
OTHER,
NOMORESTATEMENT
};
static QHash<QString, int>* initHash() {
QHash<QString, int>* proc = new QHash<QString,int>();
proc->insert("ArchiveRecord", ribParser::OTHER);
proc->insert("AreaLightSource", ribParser::OTHER);
proc->insert("Atmosphere", ribParser::OTHER);
proc->insert("Attribute", ribParser::ATTRIBUTE);
proc->insert("AttributeBegin", ribParser::ATTRIBUTEBEGIN);
proc->insert("AttributeEnd", ribParser::ATTRIBUTEEND);
proc->insert("Basis", ribParser::OTHER);
proc->insert("Begin", ribParser::OTHER);
proc->insert("Blobby", ribParser::OTHER);
proc->insert("Bound", ribParser::BOUND);
proc->insert("Clipping", ribParser::OTHER);
proc->insert("ClippingPlane", ribParser::OTHER);
proc->insert("Color", ribParser::OTHER);
proc->insert("ColorSamples", ribParser::OTHER);
proc->insert("ConcatTransform", ribParser::OTHER);
proc->insert("Cone", ribParser::OTHER);
proc->insert("Context", ribParser::OTHER);
proc->insert("CoordinateSystem", ribParser::OTHER);
proc->insert("CoordSysTransform", ribParser::OTHER);
proc->insert("CropWindow", ribParser::OTHER);
proc->insert("Curves", ribParser::OTHER);
proc->insert("Cylinder", ribParser::OTHER);
proc->insert("Declare", ribParser::OTHER);
proc->insert("DepthOfField", ribParser::OTHER);
proc->insert("Detail", ribParser::OTHER);
proc->insert("DetailRange", ribParser::OTHER);
proc->insert("Disk", ribParser::OTHER);
proc->insert("Displacement", ribParser::OTHER);
proc->insert("Display", ribParser::DISPLAY);
proc->insert("End", ribParser::OTHER);
proc->insert("ErrorHandler", ribParser::OTHER);
proc->insert("Exposure", ribParser::OTHER);
proc->insert("Exterior", ribParser::OTHER);
proc->insert("Format", ribParser::OTHER);
proc->insert("FrameAspectRatio", ribParser::OTHER);
proc->insert("FrameBegin", ribParser::FRAMEBEGIN);
proc->insert("FrameEnd", ribParser::FRAMEEND);
proc->insert("GeneralPolygon", ribParser::OTHER);
proc->insert("GeometricApproximation", ribParser::OTHER);
proc->insert("Geometry", ribParser::OTHER);
proc->insert("GetContext", ribParser::OTHER);
proc->insert("Hider", ribParser::OTHER);
proc->insert("Hyperboloid", ribParser::OTHER);
proc->insert("Identity", ribParser::OTHER);
proc->insert("Illuminate", ribParser::OTHER);
proc->insert("Imager", ribParser::OTHER);
proc->insert("Interior", ribParser::OTHER);
proc->insert("LightSource", ribParser::OTHER);
proc->insert("MakeCubeFaceEnvironment", ribParser::MAKECUBEFACEENVIRONMENT);
proc->insert("MakeLatLongEnvironment", ribParser::MAKE);
proc->insert("MakeShadow", ribParser::MAKE);
proc->insert("MakeTexture", ribParser::MAKE);
proc->insert("Matte", ribParser::OTHER);
proc->insert("MotionBegin", ribParser::OTHER);
proc->insert("MotionEnd", ribParser::OTHER);
proc->insert("NuPatch", ribParser::OTHER);
proc->insert("ObjectBegin", ribParser::OTHER);
proc->insert("ObjectEnd", ribParser::OTHER);
proc->insert("ObjectInstance", ribParser::OTHER);
proc->insert("Opacity", ribParser::OTHER);
proc->insert("Option", ribParser::OPTION);
proc->insert("Orientation", ribParser::OTHER);
proc->insert("Paraboloid", ribParser::OTHER);
proc->insert("Patch", ribParser::OTHER);
proc->insert("PatchMesh", ribParser::OTHER);
proc->insert("Perspective", ribParser::OTHER);
proc->insert("PixelFilter", ribParser::OTHER);
proc->insert("PixelSamples", ribParser::OTHER);
proc->insert("PixelVariance", ribParser::OTHER);
proc->insert("Points", ribParser::OTHER);
proc->insert("PointsGeneralPolygons", ribParser::OTHER);
proc->insert("PointsPolygons", ribParser::OTHER);
proc->insert("Polygon", ribParser::OTHER);
proc->insert("Procedural", ribParser::OTHER);
proc->insert("Projection", ribParser::OTHER);
proc->insert("Quantize", ribParser::OTHER);
proc->insert("ReadArchive", ribParser::READARCHIVE);
proc->insert("RelativeDetail", ribParser::OTHER);
proc->insert("ReverseOrientation", ribParser::OTHER);
proc->insert("Rotate", ribParser::OTHER);
proc->insert("Scale", ribParser::OTHER);
proc->insert("ScreenWindow", ribParser::OTHER);
proc->insert("ShadingInterpolation", ribParser::OTHER);
proc->insert("ShadingRate", ribParser::OTHER);
proc->insert("Shutter", ribParser::OTHER);
proc->insert("Sides", ribParser::OTHER);
proc->insert("Skew", ribParser::OTHER);
proc->insert("SolidBegin", ribParser::OTHER);
proc->insert("SolidEnd", ribParser::OTHER);
proc->insert("Sphere", ribParser::OTHER);
proc->insert("SubdivisionMesh", ribParser::OTHER);
proc->insert("Surface", ribParser::SURFACE);
proc->insert("TextureCoordinates", ribParser::OTHER);
proc->insert("Torus", ribParser::OTHER);
proc->insert("Transform", ribParser::TRANSFORM);
proc->insert("TransformBegin", ribParser::OTHER);
proc->insert("TransformEnd", ribParser::OTHER);
proc->insert("TransformPoints", ribParser::OTHER);
proc->insert("Translate", ribParser::OTHER);
proc->insert("TrimCurve", ribParser::OTHER);
proc->insert("version", ribParser::OTHER); //not a procedure, but a keyword
proc->insert("WorldBegin", ribParser::WORLDBEGIN);
proc->insert("WorldEnd", ribParser::WORLDEND);
return proc;
}
//split a statement in word (strings are unique word, like '\"' , '[' and ']' )
static QStringList splitStatement(const QString* line) {
QString str = line->trimmed();
QStringList list = QStringList();
QString word = "";
bool string = false, slash = false;
for(int i = 0; i<str.size(); i++) {
if(str[i] != ' ' && str[i] != '\n') {
if(str[i] == '\\') {
slash = true;
}
if(!slash && str[i] == '\"') {
if(word != "")
list << word.simplified();
list << "\"";
word = "";
string = !string;
}
else {
if((str[i] == '[' || str[i] == ']') && !string) {
if(word != "")
list << word.simplified();
list << QString(str[i]);
word = "";
}
else
word += str[i];
}
}
else { //is a ' ' or \n
if(string) {
word += str[i];
}
else {
if(word != "") { //it's a sequence of
list << word.simplified();
word = "";
}
}
slash = false;
}
}
word = word.simplified();
if(word != "")
list << word;
//foreach(QString s,list)
// qDebug(qPrintable(s));
return list;
}
};

View File

@ -1,14 +1,14 @@
#include "utilities_hqrender.h"
//path must have the filename
QString UtilitiesHQR::getDirFromPath(QString* path) {
QString UtilitiesHQR::getDirFromPath(const QString* path) {
//return path->left(path->lastIndexOf(QDir::separator())); //don't work :/
if(path->lastIndexOf('\\') == -1 && path->lastIndexOf('/') == -1)
return ".";
return path->left(std::max<int>(path->lastIndexOf('\\'),path->lastIndexOf('/')));
}
QString UtilitiesHQR::getFileNameFromPath(QString* path, bool type) {
QString UtilitiesHQR::getFileNameFromPath(const QString* path, bool type) {
//return path->right(path->size() - 1 - path->lastIndexOf(QDir::separator())); //don't work :/
QString temp = path->right(path->size() - 1 - std::max<int>(path->lastIndexOf('\\'),path->lastIndexOf('/')));
if(type)
@ -18,7 +18,7 @@ QString UtilitiesHQR::getFileNameFromPath(QString* path, bool type) {
}
//if path contains a space, is wrapped in quotes (e.g. ..\"Program files"\..)
QString UtilitiesHQR::quotesPath(QString* path) {
QString UtilitiesHQR::quotesPath(const QString* path) {
QStringList dirs = path->split(QDir::separator());
QString temp("");
for(int i = 0; i < dirs.size(); i++) {
@ -33,9 +33,9 @@ QString UtilitiesHQR::quotesPath(QString* path) {
}
//if dir not exist, create it
bool UtilitiesHQR::checkDir(QString destDirString, QString path) {
QDir destDir(destDirString);
QStringList pathDirs = path.split('/');
bool UtilitiesHQR::checkDir(const QString* destDirString, const QString* path) {
QDir destDir(*destDirString);
QStringList pathDirs = path->split('/');
foreach(QString dir, pathDirs) {
if(!destDir.cd(dir)) {
destDir.mkdir(dir);
@ -47,9 +47,9 @@ bool UtilitiesHQR::checkDir(QString destDirString, QString path) {
}
//take all files in fromDir/[dirs] directories and copy them in dest/[dirs]
bool UtilitiesHQR::copyFiles(QDir fromDir, QDir destDir, QStringList dirs) {
QDir src = fromDir, dest = destDir;
foreach(QString dir, dirs) {
bool UtilitiesHQR::copyFiles(const QDir* fromDir, const QDir* destDir, const QStringList* dirs) {
QDir src = *fromDir, dest = *destDir;
foreach(QString dir, *dirs) {
if(dir != "." && src.cd(dir)) {
if(!dest.mkdir(dir)) {
if(!dest.cd(dir))
@ -71,26 +71,26 @@ bool UtilitiesHQR::copyFiles(QDir fromDir, QDir destDir, QStringList dirs) {
}
//delete a directory and all file and subdirectory (recursive calls)
bool UtilitiesHQR::delDir(QDir dir, QString toDel) {
qDebug("Deleting: %s in %s", qPrintable(toDel), qPrintable(dir.absolutePath()));
if(!dir.rmdir(toDel)) {
dir.cd(toDel);
qDebug("I'm in %s", qPrintable(dir.absolutePath()));
QStringList dirs = dir.entryList(QDir::Files|QDir::NoDotAndDotDot);
bool UtilitiesHQR::delDir(QDir* dir, const QString* toDel) {
qDebug("Deleting: %s in %s", qPrintable(*toDel), qPrintable(dir->absolutePath()));
if(!dir->rmdir(*toDel)) {
dir->cd(*toDel);
qDebug("I'm in %s", qPrintable(dir->absolutePath()));
QStringList dirs = dir->entryList(QDir::Files|QDir::NoDotAndDotDot);
foreach(QString entry, dirs) {
qDebug("Cycle1 deleting file: %s in %s", qPrintable(entry), qPrintable(dir.absolutePath()));
dir.remove(entry);
qDebug("Cycle1 deleting file: %s in %s", qPrintable(entry), qPrintable(dir->absolutePath()));
dir->remove(entry);
}
dirs = dir.entryList(QDir::Dirs|QDir::NoDotAndDotDot);
dirs = dir->entryList(QDir::Dirs|QDir::NoDotAndDotDot);
foreach(QString entry, dirs) {
qDebug("Cycle2 deleting dir: %s in %s", qPrintable(entry), qPrintable(dir.absolutePath()));
if(!dir.rmdir(entry)) {
QDir temp = dir;
delDir(temp, entry);
qDebug("Cycle2 deleting dir: %s in %s", qPrintable(entry), qPrintable(dir->absolutePath()));
if(!dir->rmdir(entry)) {
QDir temp = *dir;
delDir(&temp, &entry);
}
}
dir.cdUp();
if(!dir.rmdir(toDel))
dir->cdUp();
if(!dir->rmdir(*toDel))
return false;
}
return true;

View File

@ -4,11 +4,11 @@
#include <math.h>
namespace UtilitiesHQR {
QString getDirFromPath(QString* path);
QString getFileNameFromPath(QString* path, bool type = true);
QString quotesPath(QString* path);
bool checkDir(QString destDirString, QString path);
bool copyFiles(QDir templateDir,QDir destDir,QStringList dirs);
bool delDir(QDir dir, QString toDel);
QString getDirFromPath(const QString* path);
QString getFileNameFromPath(const QString* path, bool type = true);
QString quotesPath(const QString* path);
bool checkDir(const QString* destDirString, const QString* path);
bool copyFiles(const QDir* templateDir, const QDir* destDir, const QStringList* dirs);
bool delDir(QDir* dir, const QString* toDel);
int numberOfCiphers(int number);
};