diff --git a/src/common/filter_parameter/rich_parameter.cpp b/src/common/filter_parameter/rich_parameter.cpp index e68d3e87e..b5159af50 100644 --- a/src/common/filter_parameter/rich_parameter.cpp +++ b/src/common/filter_parameter/rich_parameter.cpp @@ -1,5 +1,5 @@ #include "rich_parameter.h" -#include "../mesh_data_structures/mesh_model.h" +#include "../mesh_data_structures/mesh_document.h" /**** RichParameter Class ****/ diff --git a/src/common/filter_parameter/value.cpp b/src/common/filter_parameter/value.cpp index e9b4c6e7b..597a578e9 100644 --- a/src/common/filter_parameter/value.cpp +++ b/src/common/filter_parameter/value.cpp @@ -1,6 +1,6 @@ #include "value.h" -#include "../mesh_data_structures/mesh_model.h" +#include "../mesh_data_structures/mesh_document.h" void BoolValue::fillToXMLElement(QDomElement& element) const { diff --git a/src/common/interfaces/edit_plugin_interface.h b/src/common/interfaces/edit_plugin_interface.h index 9300d4693..e134fb874 100644 --- a/src/common/interfaces/edit_plugin_interface.h +++ b/src/common/interfaces/edit_plugin_interface.h @@ -27,7 +27,7 @@ #include #include "plugin_interface.h" -#include "../mesh_data_structures/mesh_model.h" +#include "../mesh_data_structures/mesh_document.h" class GLArea; diff --git a/src/common/interfaces/filter_plugin_interface.h b/src/common/interfaces/filter_plugin_interface.h index 1fdf71a59..29b41cc5c 100644 --- a/src/common/interfaces/filter_plugin_interface.h +++ b/src/common/interfaces/filter_plugin_interface.h @@ -25,7 +25,7 @@ #define MESHLAB_FILTER_PLUGIN_INTERFACE_H #include "plugin_interface.h" -#include "../mesh_data_structures/mesh_model.h" +#include "../mesh_data_structures/mesh_document.h" /** \brief The MeshFilterInterface class provide the interface of the filter plugins. diff --git a/src/common/mesh_data_structures/mesh_document.cpp b/src/common/mesh_data_structures/mesh_document.cpp index 9993fefcb..b54d70b9b 100644 --- a/src/common/mesh_data_structures/mesh_document.cpp +++ b/src/common/mesh_data_structures/mesh_document.cpp @@ -23,3 +23,286 @@ #include "mesh_document.h" +template +QString NameDisambiguator(QList &elemList, QString meshLabel ) +{ + QString newName=std::move(meshLabel); + typename QList::iterator mmi; + + for(mmi=elemList.begin(); mmi!=elemList.end(); ++mmi) + { + if((*mmi)->label() == newName) // if duplicated name found + { + QFileInfo fi((*mmi)->label()); + QString baseName = fi.baseName(); // all characters in the file up to the first '.' Eg "/tmp/archive.tar.gz" -> "archive" + QString suffix = fi.suffix(); + bool ok; + + // if name ends with a number between parenthesis (XXX), + // it was himself a duplicated name, and we need to + // just increase the number between parenthesis + int numDisamb; + int startDisamb; + int endDisamb; + + startDisamb = baseName.lastIndexOf("("); + endDisamb = baseName.lastIndexOf(")"); + if((startDisamb!=-1)&&(endDisamb!=-1)) + numDisamb = (baseName.mid((startDisamb+1),(endDisamb-startDisamb-1))).toInt(&ok); + else + numDisamb = 0; + + if(startDisamb!=-1) + newName = baseName.left(startDisamb)+ "(" + QString::number(numDisamb+1) + ")"; + else + newName = baseName + "(" + QString::number(numDisamb+1) + ")"; + + if (suffix != QString("")) + newName = newName + "." + suffix; + + // now recurse to see if the new name is free + newName = NameDisambiguator(elemList, newName); + } + } + return newName; +} + +MeshDocument::MeshDocument() +{ + meshIdCounter=0; + rasterIdCounter=0; + currentMesh = nullptr; + currentRaster = nullptr; + busy=false; +} + +//deletes each meshModel +MeshDocument::~MeshDocument() +{ + foreach(MeshModel *mmp, meshList) + delete mmp; + foreach(RasterModel* rmp,rasterList) + delete rmp; +} + +void MeshDocument::clear() +{ + for(MeshModel *mmp : meshList) + delete mmp; + meshList.clear(); + + for(RasterModel* rmp :rasterList) + delete rmp; + rasterList.clear(); + + meshIdCounter=0; + rasterIdCounter=0; + currentMesh = nullptr; + currentRaster = nullptr; + busy=false; + filterHistory.clear(); + fullPathFilename = ""; + documentLabel = ""; + meshDocStateData().clear(); +} + +const MeshModel* MeshDocument::getMesh(int id) const +{ + for (const MeshModel* m : meshList) + if (m->id() == id) + return m; + return nullptr; +} + +//returns the mesh ata given position in the list +MeshModel* MeshDocument::getMesh(int id) +{ + for (MeshModel* m : meshList) + if (m->id() == id) + return m; + return nullptr; +} + +const MeshModel* MeshDocument::getMesh(const QString& name) const +{ + for (const MeshModel* m : meshList) + if (m->shortName() == name) + return m; + return nullptr; +} + +MeshModel* MeshDocument::getMesh(const QString& name) +{ + for (MeshModel* m : meshList) + if (m->shortName() == name) + return m; + return nullptr; +} + +const MeshModel* MeshDocument::getMeshByFullName(const QString& pathName) const +{ + for (const MeshModel* m : meshList) + if (m->fullName() == pathName) + return m; + return nullptr; +} + +MeshModel* MeshDocument::getMeshByFullName(const QString& pathName) +{ + for (MeshModel* m : meshList) + if (m->fullName() == pathName) + return m; + return nullptr; +} + + +void MeshDocument::setCurrentMesh(int new_curr_id) +{ + if(new_curr_id<0) + { + currentMesh=0; + return; + } + currentMesh = getMesh(new_curr_id); + emit currentMeshChanged(new_curr_id); + assert(currentMesh); +} + +//returns the raster at a given position in the list +RasterModel *MeshDocument::getRaster(int i) +{ + foreach(RasterModel *rmp, rasterList) + { + if(rmp->id() == i) return rmp; + } + //assert(0); + return 0; +} + +//if i is <0 it means that no currentRaster is set +void MeshDocument::setCurrentRaster( int new_curr_id) +{ + if(new_curr_id<0) + { + currentRaster=0; + return; + } + + foreach(RasterModel *rmp, rasterList) + { + if(rmp->id() == new_curr_id) + { + currentRaster = rmp; + return; + } + } + assert(0); +} + +void MeshDocument::requestUpdatingPerMeshDecorators(int mesh_id) +{ + emit updateDecorators(mesh_id); +} + +MeshModel * MeshDocument::addNewMesh(QString fullPath, QString label, bool setAsCurrent) +{ + QString newlabel = NameDisambiguator(this->meshList,std::move(label)); + + if(!fullPath.isEmpty()) + { + QFileInfo fi(fullPath); + fullPath = fi.absoluteFilePath(); + } + + MeshModel *newMesh = new MeshModel(this,fullPath,newlabel); + meshList.push_back(newMesh); + + if(setAsCurrent) + this->setCurrentMesh(newMesh->id()); + + emit meshSetChanged(); + emit meshAdded(newMesh->id()); + return newMesh; +} + +MeshModel * MeshDocument::addOrGetMesh(QString fullPath, const QString& label, bool setAsCurrent) +{ + MeshModel *newMesh = getMesh(label); + if(newMesh) { + if(setAsCurrent) + this->setCurrentMesh(newMesh->id()); + return newMesh; + } + return addNewMesh(std::move(fullPath),label,setAsCurrent); +} + +bool MeshDocument::delMesh(MeshModel *mmToDel) +{ + if(!meshList.removeOne(mmToDel)) + return false; + if((currentMesh == mmToDel) && (!meshList.empty())) + setCurrentMesh(this->meshList.at(0)->id()); + else if (meshList.empty()) + setCurrentMesh(-1); + + int index = mmToDel->id(); + delete mmToDel; + + emit meshSetChanged(); + emit meshRemoved(index); + return true; +} + +RasterModel * MeshDocument::addNewRaster(/*QString fullPathFilename*/) +{ + QFileInfo info(fullPathFilename); + QString newLabel=info.fileName(); + QString newName = NameDisambiguator(this->rasterList, newLabel); + + RasterModel *newRaster=new RasterModel(this, newLabel); + rasterList.push_back(newRaster); + + //Add new plane + //Plane *plane = new Plane(newRaster, fullPathFilename, QString()); + //newRaster->addPlane(plane); + + this->setCurrentRaster(newRaster->id()); + + emit rasterSetChanged(); + return newRaster; +} + +bool MeshDocument::delRaster(RasterModel *rasterToDel) +{ + QMutableListIterator i(rasterList); + + while (i.hasNext()) + { + RasterModel *r = i.next(); + + if (r==rasterToDel) + { + i.remove(); + delete rasterToDel; + } + } + + if(currentRaster == rasterToDel) + { + if (!rasterList.empty()) + setCurrentRaster(rasterList.at(0)->id()); + else + setCurrentRaster(-1); + } + emit rasterSetChanged(); + + return true; +} + +bool MeshDocument::hasBeenModified() +{ + foreach(MeshModel *m, meshList) + if(m->meshModified()) return true; + return false; +} + diff --git a/src/common/mesh_data_structures/mesh_document.h b/src/common/mesh_data_structures/mesh_document.h index d87c0ef48..18920768d 100644 --- a/src/common/mesh_data_structures/mesh_document.h +++ b/src/common/mesh_data_structures/mesh_document.h @@ -21,9 +21,218 @@ * * ****************************************************************************/ -#ifndef MESHDOCUMENT_H -#define MESHDOCUMENT_H +#ifndef MESH_DOCUMENT_H +#define MESH_DOCUMENT_H + +#include "mesh_model.h" + +class MeshDocument : public QObject +{ + Q_OBJECT + +public: + + MeshDocument(); + + //deletes each meshModel + ~MeshDocument(); + + void clear(); + + ///returns the mesh with the given unique id + const MeshModel* getMesh(int id) const; + MeshModel *getMesh(int id); + const MeshModel *getMesh(const QString& name) const; + MeshModel *getMesh(const QString& name); + const MeshModel *getMeshByFullName(const QString& pathName) const; + MeshModel *getMeshByFullName(const QString& pathName); + + //set the current mesh to be the one with the given ID + void setCurrentMesh( int new_curr_id ); + + void setVisible(int meshId, bool val); + + /// returns the raster with the given unique id + RasterModel *getRaster(int i); + + //set the current raster to be the one with the given ID + void setCurrentRaster( int new_curr_id ); + void setCurrent(MeshModel *newCur) { setCurrentMesh(newCur->id());} + void setCurrent(RasterModel *newCur) { setCurrentRaster(newCur->id());} + + /// methods to access the set of Meshes in a ordered fashion. + MeshModel *nextVisibleMesh(MeshModel *_m = NULL) + { + MeshModel *newM = nextMesh(_m); + if(newM==0) + return newM; + + if(newM->isVisible()) + return newM; + else + return nextVisibleMesh(newM); + } + + MeshModel *nextMesh(MeshModel *_m = NULL) + { + if(_m==0 && meshList.size()>0) + return meshList.at(0); + for (int i = 0; i < meshList.size(); ++i) { + if (meshList.at(i) == _m) + { + if(i+1 < meshList.size()) + return meshList.at(i+1); + } + } + return 0; + } + /// methods to access the set of Meshes in a ordered fashion. + RasterModel *nextRaster(RasterModel *_rm = NULL) { + for (int i = 0; i < rasterList.size(); ++i) { + if (rasterList.at(i) == _rm) + { + if(i+1 < rasterList.size()) + return rasterList.at(i+1); + } + } + return 0; + } + + MeshModel* mm() { + return currentMesh; + } + + const MeshModel* mm() const { + return currentMesh; + } + + //Could return 0 if no raster has been selected + RasterModel *rm(){ + return currentRaster; + } + + /// The very important member: + /// The list of MeshModels. + QList meshList; + /// The list of the raster models of the project + QList rasterList; + int newMeshId() {return meshIdCounter++;} + int newRasterId() {return rasterIdCounter++;} + + //functions to update the document entities (meshes and/or rasters) during the filters execution + //WARNING! please note that if you have to update both meshes and rasters calling updateRenderState function it's far more efficient + //than calling in sequence updateRenderRasterStateMeshes and updateRenderStateRasters. Use them only if you have to update only rasters or only meshes. + /*void updateRenderState(const QList& mm,const int meshupdatemask,const QList& rm,const int rasterupdatemask); + + void updateRenderStateMeshes(const QList& mm,const int meshupdatemask); + void updateRenderStateRasters(const QList& rm,const int rasterupdatemask);*/ + void requestUpdatingPerMeshDecorators(int mesh_id); + +private: + int meshIdCounter; + int rasterIdCounter; + + /** + All the files referred in a document are relative to the folder containing the project file. + this is the full path to the document. + */ + QString fullPathFilename; + + //it is the label of the document. it should only be something like Project_n (a temporary name for a new empty document) or the fullPathFilename. + QString documentLabel; + + MeshDocumentStateData mdstate; +public: + + inline MeshDocumentStateData& meshDocStateData() { return mdstate; } + void setDocLabel(const QString& docLb) {documentLabel = docLb;} + QString docLabel() const {return documentLabel;} + QString pathName() const {QFileInfo fi(fullPathFilename); return fi.absolutePath();} + void setFileName(const QString& newFileName) {fullPathFilename = newFileName;} + GLLogStream Log; + FilterScript filterHistory; + QStringList xmlhistory; + + int size() const {return meshList.size();} + bool isBusy() { return busy;} // used in processing. To disable access to the mesh by the rendering thread + void setBusy(bool _busy) + { + /*if(busy && _busy==false) + { + emit meshDocumentModified(); + }*/ + busy=_busy; + } + +private: + bool busy; + +public: + ///add a new mesh with the given name + MeshModel *addNewMesh(QString fullPath, QString Label, bool setAsCurrent=true); + MeshModel *addOrGetMesh(QString fullPath, const QString& Label, bool setAsCurrent=true); + + + ///remove the mesh from the list and delete it from memory + bool delMesh(MeshModel *mmToDel); + + ///add a new raster model + RasterModel *addNewRaster(/*QString rasterName*/); + + ///remove the raster from the list and delete it from memory + bool delRaster(RasterModel *rasterToDel); + + int vn() /// Sum of all the vertices of all the meshes + { + int tot=0; + foreach(MeshModel *mmp, meshList) + tot+= mmp->cm.vn; + return tot; + } + int fn() { + int tot=0; + foreach(MeshModel *mmp, meshList) + tot+= mmp->cm.fn; + return tot; + } + + Box3m bbox() + { + Box3m FullBBox; + foreach(MeshModel * mp, meshList) + FullBBox.Add(mp->cm.Tr,mp->cm.bbox); + return FullBBox; + } + + bool hasBeenModified(); + +private: + MeshModel *currentMesh; + //the current raster model + RasterModel* currentRaster; + +signals: + ///whenever the current mesh is changed (e.g. the user click on a different mesh) + // this signal will send out with the index of the newest mesh + void currentMeshChanged(int index); + + /// whenever the document (or even a single mesh) is modified by a filter + void meshDocumentModified(); + + ///whenever the meshList is changed + void meshSetChanged(); + + void meshAdded(int index); + void meshRemoved(int index); + + ///whenever the rasterList is changed + void rasterSetChanged(); + + //this signal is emitted when a filter request to update the mesh in the renderingState + void documentUpdated(); + void updateDecorators(int mesh_id); + +};// end class MeshDocument - -#endif // MESHDOCUMENT_H +#endif // MESH_DOCUMENT_H diff --git a/src/common/mesh_data_structures/mesh_model.cpp b/src/common/mesh_data_structures/mesh_model.cpp index 2b863e377..35050f8a8 100644 --- a/src/common/mesh_data_structures/mesh_model.cpp +++ b/src/common/mesh_data_structures/mesh_model.cpp @@ -27,6 +27,7 @@ #include #include "mesh_model.h" +#include "mesh_document.h" #include @@ -35,348 +36,6 @@ using namespace vcg; -MeshDocument::MeshDocument() -{ - meshIdCounter=0; - rasterIdCounter=0; - currentMesh = nullptr; - currentRaster = nullptr; - busy=false; -} - -//deletes each meshModel -MeshDocument::~MeshDocument() -{ - foreach(MeshModel *mmp, meshList) - delete mmp; - foreach(RasterModel* rmp,rasterList) - delete rmp; -} - -void MeshDocument::clear() -{ - for(MeshModel *mmp : meshList) - delete mmp; - meshList.clear(); - - for(RasterModel* rmp :rasterList) - delete rmp; - rasterList.clear(); - - meshIdCounter=0; - rasterIdCounter=0; - currentMesh = nullptr; - currentRaster = nullptr; - busy=false; - filterHistory.clear(); - fullPathFilename = ""; - documentLabel = ""; - meshDocStateData().clear(); -} - -const MeshModel* MeshDocument::getMesh(int id) const -{ - for (const MeshModel* m : meshList) - if (m->id() == id) - return m; - return nullptr; -} - -//returns the mesh ata given position in the list -MeshModel* MeshDocument::getMesh(int id) -{ - for (MeshModel* m : meshList) - if (m->id() == id) - return m; - return nullptr; -} - -const MeshModel* MeshDocument::getMesh(const QString& name) const -{ - for (const MeshModel* m : meshList) - if (m->shortName() == name) - return m; - return nullptr; -} - -MeshModel* MeshDocument::getMesh(const QString& name) -{ - for (MeshModel* m : meshList) - if (m->shortName() == name) - return m; - return nullptr; -} - -const MeshModel* MeshDocument::getMeshByFullName(const QString& pathName) const -{ - for (const MeshModel* m : meshList) - if (m->fullName() == pathName) - return m; - return nullptr; -} - -MeshModel* MeshDocument::getMeshByFullName(const QString& pathName) -{ - for (MeshModel* m : meshList) - if (m->fullName() == pathName) - return m; - return nullptr; -} - - -void MeshDocument::setCurrentMesh(int new_curr_id) -{ - if(new_curr_id<0) - { - currentMesh=0; - return; - } - currentMesh = getMesh(new_curr_id); - emit currentMeshChanged(new_curr_id); - assert(currentMesh); -} - -//returns the raster at a given position in the list -RasterModel *MeshDocument::getRaster(int i) -{ - foreach(RasterModel *rmp, rasterList) - { - if(rmp->id() == i) return rmp; - } - //assert(0); - return 0; -} - -//if i is <0 it means that no currentRaster is set -void MeshDocument::setCurrentRaster( int new_curr_id) -{ - if(new_curr_id<0) - { - currentRaster=0; - return; - } - - foreach(RasterModel *rmp, rasterList) - { - if(rmp->id() == new_curr_id) - { - currentRaster = rmp; - return; - } - } - assert(0); -} - -void MeshDocument::requestUpdatingPerMeshDecorators(int mesh_id) -{ - emit updateDecorators(mesh_id); -} - -template -QString NameDisambiguator(QList &elemList, QString meshLabel ) -{ - QString newName=std::move(meshLabel); - typename QList::iterator mmi; - - for(mmi=elemList.begin(); mmi!=elemList.end(); ++mmi) - { - if((*mmi)->label() == newName) // if duplicated name found - { - QFileInfo fi((*mmi)->label()); - QString baseName = fi.baseName(); // all characters in the file up to the first '.' Eg "/tmp/archive.tar.gz" -> "archive" - QString suffix = fi.suffix(); - bool ok; - - // if name ends with a number between parenthesis (XXX), - // it was himself a duplicated name, and we need to - // just increase the number between parenthesis - int numDisamb; - int startDisamb; - int endDisamb; - - startDisamb = baseName.lastIndexOf("("); - endDisamb = baseName.lastIndexOf(")"); - if((startDisamb!=-1)&&(endDisamb!=-1)) - numDisamb = (baseName.mid((startDisamb+1),(endDisamb-startDisamb-1))).toInt(&ok); - else - numDisamb = 0; - - if(startDisamb!=-1) - newName = baseName.left(startDisamb)+ "(" + QString::number(numDisamb+1) + ")"; - else - newName = baseName + "(" + QString::number(numDisamb+1) + ")"; - - if (suffix != QString("")) - newName = newName + "." + suffix; - - // now recurse to see if the new name is free - newName = NameDisambiguator(elemList, newName); - } - } - return newName; -} - - -MeshModel * MeshDocument::addNewMesh(QString fullPath, QString label, bool setAsCurrent) -{ - QString newlabel = NameDisambiguator(this->meshList,std::move(label)); - - if(!fullPath.isEmpty()) - { - QFileInfo fi(fullPath); - fullPath = fi.absoluteFilePath(); - } - - MeshModel *newMesh = new MeshModel(this,fullPath,newlabel); - meshList.push_back(newMesh); - - if(setAsCurrent) - this->setCurrentMesh(newMesh->id()); - - emit meshSetChanged(); - emit meshAdded(newMesh->id()); - return newMesh; -} - -MeshModel * MeshDocument::addOrGetMesh(QString fullPath, const QString& label, bool setAsCurrent) -{ - MeshModel *newMesh = getMesh(label); - if(newMesh) { - if(setAsCurrent) - this->setCurrentMesh(newMesh->id()); - return newMesh; - } - return addNewMesh(std::move(fullPath),label,setAsCurrent); -} - -bool MeshDocument::delMesh(MeshModel *mmToDel) -{ - if(!meshList.removeOne(mmToDel)) - return false; - if((currentMesh == mmToDel) && (!meshList.empty())) - setCurrentMesh(this->meshList.at(0)->id()); - else if (meshList.empty()) - setCurrentMesh(-1); - - int index = mmToDel->id(); - delete mmToDel; - - emit meshSetChanged(); - emit meshRemoved(index); - return true; -} - -RasterModel * MeshDocument::addNewRaster(/*QString fullPathFilename*/) -{ - QFileInfo info(fullPathFilename); - QString newLabel=info.fileName(); - QString newName = NameDisambiguator(this->rasterList, newLabel); - - RasterModel *newRaster=new RasterModel(this, newLabel); - rasterList.push_back(newRaster); - - //Add new plane - //Plane *plane = new Plane(newRaster, fullPathFilename, QString()); - //newRaster->addPlane(plane); - - this->setCurrentRaster(newRaster->id()); - - emit rasterSetChanged(); - return newRaster; -} - -bool MeshDocument::delRaster(RasterModel *rasterToDel) -{ - QMutableListIterator i(rasterList); - - while (i.hasNext()) - { - RasterModel *r = i.next(); - - if (r==rasterToDel) - { - i.remove(); - delete rasterToDel; - } - } - - if(currentRaster == rasterToDel) - { - if (!rasterList.empty()) - setCurrentRaster(rasterList.at(0)->id()); - else - setCurrentRaster(-1); - } - emit rasterSetChanged(); - - return true; -} - -bool MeshDocument::hasBeenModified() -{ - foreach(MeshModel *m, meshList) - if(m->meshModified()) return true; - return false; -} - -//void MeshDocument::updateRenderStateMeshes(const QList& mm,const int meshupdatemask) -//{ -// static QTime currTime = QTime::currentTime(); -// if(currTime.elapsed()< 100) -// return; -// for (QList::const_iterator mit = mm.begin();mit != mm.end();++mit) -// { -// MeshModel* mesh = getMesh(*mit); -// if (mesh != NULL) -// mesh->bor.update(mesh->cm,meshupdatemask); -// } -// if ((mm.size() > 0) && (meshupdatemask != MeshModel::MM_NONE)) -// emit documentUpdated(); -// currTime.start(); -//} - -//void MeshDocument::updateRenderStateRasters(const QList& rm,const int rasterupdatemask) -//{ -// static QTime currTime = QTime::currentTime(); -// if(currTime.elapsed()< 100) -// return; -// for (QList::const_iterator rit = rm.begin();rit != rm.end();++rit) -// { -// RasterModel* raster = getRaster(*rit); -// -// /**********READD*****/ -// /* if (raster != NULL) -// renderState().update(raster->id(),*raster,rasterupdatemask);*/ -// /********************/ -// } -// if ((rm.size() > 0) && (rasterupdatemask != RasterModel::RM_NONE)) -// emit documentUpdated(); -// currTime.start(); -//} -// -//void MeshDocument::updateRenderState(const QList& mm,const int meshupdatemask,const QList& rm,const int rasterupdatemask) -//{ -// static QTime currTime = QTime::currentTime(); -// if(currTime.elapsed()< 100) -// return; -// /* for (QList::const_iterator mit = mm.begin();mit != mm.end();++mit) -// { -// MeshModel* mesh = getMesh(*mit); -// if (mesh != NULL) -// renderState().update(mesh->id(),mesh->cm,meshupdatemask); -// } -// for (QList::const_iterator rit = rm.begin();rit != rm.end();++rit) -// { -// RasterModel* raster = getRaster(*rit); -// if (raster != NULL) -// renderState().update(raster->id(),*raster,rasterupdatemask); -// }*/ -// if (((mm.size() > 0) && (meshupdatemask != MeshModel::MM_NONE)) || (rm.size() > 0 && (rasterupdatemask != RasterModel::RM_NONE))) -// emit documentUpdated(); -// currTime.start(); -//} - - void MeshModel::Clear() { setMeshModified(false); diff --git a/src/common/mesh_data_structures/mesh_model.h b/src/common/mesh_data_structures/mesh_model.h index e716a0e4f..628d91077 100644 --- a/src/common/mesh_data_structures/mesh_model.h +++ b/src/common/mesh_data_structures/mesh_model.h @@ -472,213 +472,6 @@ private: QMap _existingmeshesbeforeoperation; }; -class MeshDocument : public QObject -{ - Q_OBJECT - -public: - - MeshDocument(); - - //deletes each meshModel - ~MeshDocument(); - - void clear(); - - ///returns the mesh with the given unique id - const MeshModel* getMesh(int id) const; - MeshModel *getMesh(int id); - const MeshModel *getMesh(const QString& name) const; - MeshModel *getMesh(const QString& name); - const MeshModel *getMeshByFullName(const QString& pathName) const; - MeshModel *getMeshByFullName(const QString& pathName); - - //set the current mesh to be the one with the given ID - void setCurrentMesh( int new_curr_id ); - - void setVisible(int meshId, bool val); - - /// returns the raster with the given unique id - RasterModel *getRaster(int i); - - //set the current raster to be the one with the given ID - void setCurrentRaster( int new_curr_id ); - void setCurrent(MeshModel *newCur) { setCurrentMesh(newCur->id());} - void setCurrent(RasterModel *newCur) { setCurrentRaster(newCur->id());} - - /// methods to access the set of Meshes in a ordered fashion. - MeshModel *nextVisibleMesh(MeshModel *_m = NULL) - { - MeshModel *newM = nextMesh(_m); - if(newM==0) - return newM; - - if(newM->isVisible()) - return newM; - else - return nextVisibleMesh(newM); - } - - MeshModel *nextMesh(MeshModel *_m = NULL) - { - if(_m==0 && meshList.size()>0) - return meshList.at(0); - for (int i = 0; i < meshList.size(); ++i) { - if (meshList.at(i) == _m) - { - if(i+1 < meshList.size()) - return meshList.at(i+1); - } - } - return 0; - } - /// methods to access the set of Meshes in a ordered fashion. - RasterModel *nextRaster(RasterModel *_rm = NULL) { - for (int i = 0; i < rasterList.size(); ++i) { - if (rasterList.at(i) == _rm) - { - if(i+1 < rasterList.size()) - return rasterList.at(i+1); - } - } - return 0; - } - - MeshModel* mm() { - return currentMesh; - } - - const MeshModel* mm() const { - return currentMesh; - } - - //Could return 0 if no raster has been selected - RasterModel *rm(){ - return currentRaster; - } - - /// The very important member: - /// The list of MeshModels. - QList meshList; - /// The list of the raster models of the project - QList rasterList; - int newMeshId() {return meshIdCounter++;} - int newRasterId() {return rasterIdCounter++;} - - //functions to update the document entities (meshes and/or rasters) during the filters execution - //WARNING! please note that if you have to update both meshes and rasters calling updateRenderState function it's far more efficient - //than calling in sequence updateRenderRasterStateMeshes and updateRenderStateRasters. Use them only if you have to update only rasters or only meshes. - /*void updateRenderState(const QList& mm,const int meshupdatemask,const QList& rm,const int rasterupdatemask); - - void updateRenderStateMeshes(const QList& mm,const int meshupdatemask); - void updateRenderStateRasters(const QList& rm,const int rasterupdatemask);*/ - void requestUpdatingPerMeshDecorators(int mesh_id); - -private: - int meshIdCounter; - int rasterIdCounter; - - /** - All the files referred in a document are relative to the folder containing the project file. - this is the full path to the document. - */ - QString fullPathFilename; - - //it is the label of the document. it should only be something like Project_n (a temporary name for a new empty document) or the fullPathFilename. - QString documentLabel; - - MeshDocumentStateData mdstate; -public: - - inline MeshDocumentStateData& meshDocStateData() { return mdstate; } - void setDocLabel(const QString& docLb) {documentLabel = docLb;} - QString docLabel() const {return documentLabel;} - QString pathName() const {QFileInfo fi(fullPathFilename); return fi.absolutePath();} - void setFileName(const QString& newFileName) {fullPathFilename = newFileName;} - GLLogStream Log; - FilterScript filterHistory; - QStringList xmlhistory; - - int size() const {return meshList.size();} - bool isBusy() { return busy;} // used in processing. To disable access to the mesh by the rendering thread - void setBusy(bool _busy) - { - /*if(busy && _busy==false) - { - emit meshDocumentModified(); - }*/ - busy=_busy; - } - -private: - bool busy; - -public: - ///add a new mesh with the given name - MeshModel *addNewMesh(QString fullPath, QString Label, bool setAsCurrent=true); - MeshModel *addOrGetMesh(QString fullPath, const QString& Label, bool setAsCurrent=true); - - - ///remove the mesh from the list and delete it from memory - bool delMesh(MeshModel *mmToDel); - - ///add a new raster model - RasterModel *addNewRaster(/*QString rasterName*/); - - ///remove the raster from the list and delete it from memory - bool delRaster(RasterModel *rasterToDel); - - int vn() /// Sum of all the vertices of all the meshes - { - int tot=0; - foreach(MeshModel *mmp, meshList) - tot+= mmp->cm.vn; - return tot; - } - int fn() { - int tot=0; - foreach(MeshModel *mmp, meshList) - tot+= mmp->cm.fn; - return tot; - } - - Box3m bbox() - { - Box3m FullBBox; - foreach(MeshModel * mp, meshList) - FullBBox.Add(mp->cm.Tr,mp->cm.bbox); - return FullBBox; - } - - bool hasBeenModified(); - -private: - MeshModel *currentMesh; - //the current raster model - RasterModel* currentRaster; - -signals: - ///whenever the current mesh is changed (e.g. the user click on a different mesh) - // this signal will send out with the index of the newest mesh - void currentMeshChanged(int index); - - /// whenever the document (or even a single mesh) is modified by a filter - void meshDocumentModified(); - - ///whenever the meshList is changed - void meshSetChanged(); - - void meshAdded(int index); - void meshRemoved(int index); - - ///whenever the rasterList is changed - void rasterSetChanged(); - - //this signal is emitted when a filter request to update the mesh in the renderingState - void documentUpdated(); - void updateDecorators(int mesh_id); - -};// end class MeshDocument /* A class designed to save partial aspects of the state of a mesh, such as vertex colors, current selections, vertex positions diff --git a/src/common/meshlabdocumentbundler.cpp b/src/common/meshlabdocumentbundler.cpp index a9fbf58a1..89d7ed05d 100644 --- a/src/common/meshlabdocumentbundler.cpp +++ b/src/common/meshlabdocumentbundler.cpp @@ -6,7 +6,7 @@ #include #include -#include "mesh_data_structures/mesh_model.h" +#include "mesh_data_structures/mesh_document.h" #include #include "meshlabdocumentbundler.h" diff --git a/src/common/meshlabdocumentxml.h b/src/common/meshlabdocumentxml.h index e36e184d3..d7b7328f1 100644 --- a/src/common/meshlabdocumentxml.h +++ b/src/common/meshlabdocumentxml.h @@ -4,7 +4,7 @@ #include #include "ml_shared_data_context.h" -#include "mesh_data_structures/mesh_model.h" +#include "mesh_data_structures/mesh_document.h" #include diff --git a/src/common/ml_shared_data_context.cpp b/src/common/ml_shared_data_context.cpp index de722aa4f..086346988 100644 --- a/src/common/ml_shared_data_context.cpp +++ b/src/common/ml_shared_data_context.cpp @@ -4,7 +4,7 @@ #include #include -#include "mesh_data_structures/mesh_model.h" +#include "mesh_data_structures/mesh_document.h" MLSceneGLSharedDataContext::MLSceneGLSharedDataContext(MeshDocument& md,vcg::QtThreadSafeMemoryInfo& gpumeminfo,bool highprecision,size_t perbatchtriangles, size_t minfacespersmoothrendering) :QGLWidget(),_md(md),_gpumeminfo(gpumeminfo),_perbatchtriangles(perbatchtriangles), _minfacessmoothrendering(minfacespersmoothrendering),_highprecision(highprecision) diff --git a/src/meshlab/multiViewer_Container.h b/src/meshlab/multiViewer_Container.h index aa4aa9143..772b492d8 100644 --- a/src/meshlab/multiViewer_Container.h +++ b/src/meshlab/multiViewer_Container.h @@ -31,7 +31,7 @@ #include #include -#include +#include #include // Class list diff --git a/src/meshlab/rich_parameter_gui/richparameterwidgets.cpp b/src/meshlab/rich_parameter_gui/richparameterwidgets.cpp index 6de4d24bd..272658612 100644 --- a/src/meshlab/rich_parameter_gui/richparameterwidgets.cpp +++ b/src/meshlab/rich_parameter_gui/richparameterwidgets.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include /******************************************/ // MeshLabWidget Implementation diff --git a/src/meshlabplugins/io_3ds/meshio.cpp b/src/meshlabplugins/io_3ds/meshio.cpp index 716f95520..b4c885a61 100644 --- a/src/meshlabplugins/io_3ds/meshio.cpp +++ b/src/meshlabplugins/io_3ds/meshio.cpp @@ -42,7 +42,7 @@ #include #include -#include +#include using namespace std; using namespace vcg;