diff --git a/src/common/ml_document/cmesh.h b/src/common/ml_document/cmesh.h index 6f7eb700b..3bbd29a25 100644 --- a/src/common/ml_document/cmesh.h +++ b/src/common/ml_document/cmesh.h @@ -46,7 +46,7 @@ typedef vcg::Similarity Similaritym; template struct MeshLabScalarTest { - + }; template<> @@ -67,36 +67,36 @@ struct MeshLabScalarTest namespace vcg { - namespace vertex - { - template class Coord3m: public Coord, T> { - public: static void Name(std::vector & name){name.push_back(std::string("Coord3m"));T::Name(name);} - }; +namespace vertex +{ +template class Coord3m: public Coord, T> { +public: static void Name(std::vector & name){name.push_back(std::string("Coord3m"));T::Name(name);} +}; - template class Normal3m: public Normal, T> { - public: static void Name(std::vector & name){name.push_back(std::string("Normal3m"));T::Name(name);} - }; +template class Normal3m: public Normal, T> { +public: static void Name(std::vector & name){name.push_back(std::string("Normal3m"));T::Name(name);} +}; - template class CurvatureDirmOcf: public CurvatureDirOcf, T> { - public: static void Name(std::vector & name){name.push_back(std::string("CurvatureDirmOcf"));T::Name(name);} - }; +template class CurvatureDirmOcf: public CurvatureDirOcf, T> { +public: static void Name(std::vector & name){name.push_back(std::string("CurvatureDirmOcf"));T::Name(name);} +}; - template class RadiusmOcf: public RadiusOcf { - public: static void Name(std::vector & name){name.push_back(std::string("RadiusmOcf"));T::Name(name);} - }; +template class RadiusmOcf: public RadiusOcf { +public: static void Name(std::vector & name){name.push_back(std::string("RadiusmOcf"));T::Name(name);} +}; - }//end namespace vertex - namespace face - { - template class Normal3m: public NormalAbs, T> { - public: static void Name(std::vector & name){name.push_back(std::string("Normal3m"));T::Name(name);} - }; +}//end namespace vertex +namespace face +{ +template class Normal3m: public NormalAbs, T> { +public: static void Name(std::vector & name){name.push_back(std::string("Normal3m"));T::Name(name);} +}; - template class CurvatureDirmOcf: public CurvatureDirOcf, T> { - public: static void Name(std::vector & name){name.push_back(std::string("CurvatureDirdOcf"));T::Name(name);} - }; +template class CurvatureDirmOcf: public CurvatureDirOcf, T> { +public: static void Name(std::vector & name){name.push_back(std::string("CurvatureDirdOcf"));T::Name(name);} +}; - }//end namespace face +}//end namespace face }//end namespace vcg // Forward declarations needed for creating the used types @@ -106,8 +106,8 @@ class CFaceO; // Declaration of the semantic of the used types class CUsedTypesO: public vcg::UsedTypes < vcg::Use::AsVertexType, - vcg::Use::AsEdgeType, - vcg::Use::AsFaceType >{}; + vcg::Use::AsEdgeType, + vcg::Use::AsFaceType >{}; // The Main Vertex Class @@ -115,88 +115,102 @@ class CUsedTypesO: public vcg::UsedTypes < vcg::Use::AsVertexType, // Each vertex needs 40 byte, on 32bit arch. and 44 byte on 64bit arch. class CVertexO : public vcg::Vertex< CUsedTypesO, - vcg::vertex::InfoOcf, /* 4b */ - vcg::vertex::Coord3m, /* 12b */ - vcg::vertex::BitFlags, /* 4b */ - vcg::vertex::Normal3m, /* 12b */ - vcg::vertex::Qualityf, /* 4b */ - vcg::vertex::Color4b, /* 4b */ - vcg::vertex::VFAdjOcf, /* 0b */ - vcg::vertex::MarkOcf, /* 0b */ - vcg::vertex::TexCoordfOcf, /* 0b */ - vcg::vertex::CurvaturefOcf, /* 0b */ - vcg::vertex::CurvatureDirmOcf, /* 0b */ - vcg::vertex::RadiusmOcf /* 0b */ ->{ + vcg::vertex::InfoOcf, /* 4b */ + vcg::vertex::Coord3m, /* 12b */ + vcg::vertex::BitFlags, /* 4b */ + vcg::vertex::Normal3m, /* 12b */ + vcg::vertex::Qualityf, /* 4b */ + vcg::vertex::Color4b, /* 4b */ + vcg::vertex::VFAdjOcf, /* 0b */ + vcg::vertex::MarkOcf, /* 0b */ + vcg::vertex::TexCoordfOcf, /* 0b */ + vcg::vertex::CurvaturefOcf, /* 0b */ + vcg::vertex::CurvatureDirmOcf, /* 0b */ + vcg::vertex::RadiusmOcf /* 0b */ + >{ }; // The Main Edge Class class CEdgeO : public vcg::Edge{ + vcg::edge::BitFlags, /* 4b */ + vcg::edge::EVAdj, + vcg::edge::EEAdj + >{ }; // Each face needs 32 byte, on 32bit arch. and 48 byte on 64bit arch. class CFaceO : public vcg::Face< CUsedTypesO, - vcg::face::InfoOcf, /* 4b */ - vcg::face::VertexRef, /*12b */ - vcg::face::BitFlags, /* 4b */ - vcg::face::Normal3m, /*12b */ - vcg::face::QualityfOcf, /* 0b */ - vcg::face::MarkOcf, /* 0b */ - vcg::face::Color4bOcf, /* 0b */ - vcg::face::FFAdjOcf, /* 0b */ - vcg::face::VFAdjOcf, /* 0b */ - vcg::face::CurvatureDirmOcf, /* 0b */ - vcg::face::WedgeTexCoordfOcf /* 0b */ -> {}; + vcg::face::InfoOcf, /* 4b */ + vcg::face::VertexRef, /*12b */ + vcg::face::BitFlags, /* 4b */ + vcg::face::Normal3m, /*12b */ + vcg::face::QualityfOcf, /* 0b */ + vcg::face::MarkOcf, /* 0b */ + vcg::face::Color4bOcf, /* 0b */ + vcg::face::FFAdjOcf, /* 0b */ + vcg::face::VFAdjOcf, /* 0b */ + vcg::face::CurvatureDirmOcf, /* 0b */ + vcg::face::WedgeTexCoordfOcf /* 0b */ + > {}; +typedef vcg::tri::TriMesh< vcg::vertex::vector_ocf, vcg::face::vector_ocf > vcgTriMesh; -class CMeshO : public vcg::tri::TriMesh< vcg::vertex::vector_ocf, vcg::face::vector_ocf > +class CMeshO : public vcgTriMesh { public : - int sfn; //The number of selected faces. - int svn; //The number of selected vertices. - + int sfn; //The number of selected faces. + int svn; //The number of selected vertices. + int pvn; //the number of the polygonal vertices int pfn; //the number of the polygonal faces - + Matrix44m Tr; // Usually it is the identity. It is applied in rendering and filters can or cannot use it. (most of the filter will ignore this) - + const Box3m &trBB() const - { - static Box3m bb; - bb.SetNull(); - bb.Add(Tr,bbox); - return bb; - } - - CMeshO() : - vcg::tri::TriMesh< vcg::vertex::vector_ocf, vcg::face::vector_ocf >(), - sfn(0), svn(0), pvn(0), pfn(0) - { - } - - CMeshO(const CMeshO& oth) : CMeshO() { - vcg::tri::Append::MeshAppendConst(*this, oth); - } - - //TODO need to change this - CMeshO(CMeshO&& oth) : CMeshO() { - //I could take everything from oth and place it in - //this mesh - vcg::tri::Append::Mesh(*this, oth); - } - - //TODO should change also this and use the copy&swap idiom - CMeshO& operator=(const CMeshO& oth) { - Clear(); - vcg::tri::Append::MeshCopyConst(*this, oth); - return *this; - } + { + static Box3m bb; + bb.SetNull(); + bb.Add(Tr,bbox); + return bb; + } + + CMeshO() : + vcgTriMesh(), + sfn(0), svn(0), pvn(0), pfn(0) + { + } + + CMeshO(const CMeshO& oth) : + vcgTriMesh(), sfn(oth.sfn), svn(oth.svn), + pvn(oth.pvn), pfn(oth.pfn), Tr(oth.Tr) + { + vcg::tri::Append::MeshAppendConst(*this, oth); + } + + //TODO need to change this + CMeshO(CMeshO&& oth) : + vcgTriMesh(), sfn(oth.sfn), svn(oth.svn), + pvn(oth.pvn), pfn(oth.pfn), Tr(oth.Tr) + { + //I could take everything from oth and place it in + //this mesh + vcg::tri::Append::Mesh(*this, oth); + bbox = oth.bbox; + } + + //TODO should change also this and use the copy&swap idiom + CMeshO& operator=(const CMeshO& oth) + { + Clear(); + vcg::tri::Append::MeshCopyConst(*this, oth); + sfn = oth.sfn; + svn = oth.svn; + pvn = oth.pvn; + pfn = oth.pfn; + Tr = oth.Tr; + return *this; + } }; #endif //CMESH_H diff --git a/src/common/ml_document/mesh_document.cpp b/src/common/ml_document/mesh_document.cpp index 30f54ec2e..84a142e05 100644 --- a/src/common/ml_document/mesh_document.cpp +++ b/src/common/ml_document/mesh_document.cpp @@ -230,12 +230,12 @@ RasterModel* MeshDocument::rm() return currentRaster; } -int MeshDocument::newMeshId() +unsigned int MeshDocument::newMeshId() { return meshIdCounter++; } -int MeshDocument::newRasterId() +unsigned int MeshDocument::newRasterId() { return rasterIdCounter++; } @@ -296,7 +296,7 @@ MeshModel * MeshDocument::addNewMesh(QString fullPath, QString label, bool setAs fullPath = fi.absoluteFilePath(); } - MeshModel *newMesh = new MeshModel(this,fullPath,newlabel); + MeshModel *newMesh = new MeshModel(this, newMeshId(), fullPath,newlabel); meshList.push_back(newMesh); if(setAsCurrent) @@ -344,7 +344,7 @@ RasterModel * MeshDocument::addNewRaster(/*QString fullPathFilename*/) QString newLabel=info.fileName(); QString newName = NameDisambiguator(this->rasterList, newLabel); - RasterModel *newRaster=new RasterModel(this, newLabel); + RasterModel *newRaster=new RasterModel(this, newRasterId(), newLabel); rasterList.push_back(newRaster); //Add new plane @@ -410,7 +410,7 @@ Box3m MeshDocument::bbox() bool MeshDocument::hasBeenModified() { - foreach(MeshModel *m, meshList) + for(MeshModel *m : meshList) if(m->meshModified()) return true; return false; } diff --git a/src/common/ml_document/mesh_document.h b/src/common/ml_document/mesh_document.h index 46cdcdbc8..6ece771e8 100644 --- a/src/common/ml_document/mesh_document.h +++ b/src/common/ml_document/mesh_document.h @@ -71,17 +71,7 @@ public: //Could return 0 if no raster has been selected RasterModel *rm(); - - int newMeshId(); - int newRasterId(); - - //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); MeshDocumentStateData& meshDocStateData(); @@ -147,6 +137,9 @@ private: //the current raster model RasterModel* currentRaster; + unsigned int newMeshId(); + unsigned int newRasterId(); + 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 diff --git a/src/common/ml_document/mesh_model.cpp b/src/common/ml_document/mesh_model.cpp index 808bf5a92..75e942201 100644 --- a/src/common/ml_document/mesh_model.cpp +++ b/src/common/ml_document/mesh_model.cpp @@ -59,31 +59,16 @@ void MeshModel::UpdateBoxAndNormals() } } -MeshModel::MeshModel(MeshDocument *_parent, const QString& fullFileName, const QString& labelName) +MeshModel::MeshModel(MeshDocument *_parent, unsigned int id, const QString& fullFileName, const QString& labelName) { /*glw.m = &(cm);*/ Clear(); parent=_parent; - _id=parent->newMeshId(); + _id=id; if(!fullFileName.isEmpty()) this->fullPathFileName=fullFileName; if(!labelName.isEmpty()) this->_label=labelName; } -MeshModel::MeshModel(MeshModel* cp) -{ - if (cp == NULL) - return; - parent = cp->parent; - if (parent != NULL) - _id = parent->newMeshId(); - cm.Tr = cp->cm.Tr; - cm.sfn = cp->cm.sfn; - cm.svn = cp->cm.svn; - visible = cp->visible; - updateDataMask(cp->currentDataMask); - vcg::tri::Append::MeshCopy(cm, cp->cm); -} - QString MeshModel::relativePathName() const { QDir documentDir (documentPathName()); diff --git a/src/common/ml_document/mesh_model.h b/src/common/ml_document/mesh_model.h index 8f08b2d05..8db563696 100644 --- a/src/common/ml_document/mesh_model.h +++ b/src/common/ml_document/mesh_model.h @@ -127,8 +127,8 @@ public: MM_ALL = 0xffffffff }; - MeshModel(MeshDocument *parent, const QString& fullFileName, const QString& labelName); - MeshModel(MeshModel* cp); + MeshModel(MeshDocument *parent, unsigned int id, const QString& fullFileName, const QString& labelName); + //MeshModel(MeshModel* cp); ~MeshModel() { } @@ -163,7 +163,7 @@ private: int currentDataMask; QString fullPathFileName; QString _label; - int _id; + unsigned int _id; bool modified; public: diff --git a/src/common/ml_document/raster_model.cpp b/src/common/ml_document/raster_model.cpp index f3c41bd56..256775fed 100644 --- a/src/common/ml_document/raster_model.cpp +++ b/src/common/ml_document/raster_model.cpp @@ -25,9 +25,9 @@ #include "mesh_document.h" -RasterModel::RasterModel(MeshDocument *parent, QString _rasterName) +RasterModel::RasterModel(MeshDocument *parent, unsigned int id, QString _rasterName) { - _id=parent->newRasterId(); + _id=id; par = parent; this->_label= std::move(_rasterName); visible=true; diff --git a/src/common/ml_document/raster_model.h b/src/common/ml_document/raster_model.h index 94c233583..20098a7f6 100644 --- a/src/common/ml_document/raster_model.h +++ b/src/common/ml_document/raster_model.h @@ -49,7 +49,7 @@ public: bool visible; inline int id() const {return _id;} - RasterModel(MeshDocument *parent, QString _rasterName=QString()); + RasterModel(MeshDocument *parent, unsigned int id, QString _rasterName=QString()); void setLabel(QString newLabel) {_label = newLabel;} diff --git a/src/meshlabplugins/filter_csg/filter_csg.cpp b/src/meshlabplugins/filter_csg/filter_csg.cpp index b881b947e..b5f24851e 100644 --- a/src/meshlabplugins/filter_csg/filter_csg.cpp +++ b/src/meshlabplugins/filter_csg/filter_csg.cpp @@ -151,17 +151,19 @@ bool FilterCSG::applyFilter(const QAction *filter, MeshDocument &md, std::mapupdateDataMask(MeshModel::MM_FACENORMAL | MeshModel::MM_FACEQUALITY); secondMesh->updateDataMask(MeshModel::MM_FACENORMAL | MeshModel::MM_FACEQUALITY); - MeshModel tmpfirstmesh(firstMesh); - for (size_t ii = 0; ii < (size_t)tmpfirstmesh.cm.VN(); ++ii) - tmpfirstmesh.cm.vert[ii].P() = tmpfirstmesh.cm.Tr * tmpfirstmesh.cm.vert[ii].P(); - vcg::tri::UpdateBounding::Box(tmpfirstmesh.cm); - vcg::tri::UpdateNormal::PerVertexNormalizedPerFaceNormalized(tmpfirstmesh.cm); + CMeshO tmpfirstmesh(firstMesh->cm); + tmpfirstmesh.face.EnableQuality(); + for (size_t ii = 0; ii < (size_t)tmpfirstmesh.VN(); ++ii) + tmpfirstmesh.vert[ii].P() = tmpfirstmesh.Tr * tmpfirstmesh.vert[ii].P(); + vcg::tri::UpdateBounding::Box(tmpfirstmesh); + vcg::tri::UpdateNormal::PerVertexNormalizedPerFaceNormalized(tmpfirstmesh); - MeshModel tmpsecondmesh(secondMesh); - for (size_t ii = 0; ii < (size_t)tmpsecondmesh.cm.VN(); ++ii) - tmpsecondmesh.cm.vert[ii].P() = tmpsecondmesh.cm.Tr * tmpsecondmesh.cm.vert[ii].P(); - vcg::tri::UpdateBounding::Box(tmpsecondmesh.cm); - vcg::tri::UpdateNormal::PerVertexNormalizedPerFaceNormalized(tmpfirstmesh.cm); + CMeshO tmpsecondmesh(secondMesh->cm); + tmpsecondmesh.face.EnableQuality(); + for (size_t ii = 0; ii < (size_t)tmpsecondmesh.VN(); ++ii) + tmpsecondmesh.vert[ii].P() = tmpsecondmesh.Tr * tmpsecondmesh.vert[ii].P(); + vcg::tri::UpdateBounding::Box(tmpsecondmesh); + vcg::tri::UpdateNormal::PerVertexNormalizedPerFaceNormalized(tmpfirstmesh); // typedef CMeshO::ScalarType scalar; typedef Intercept intercept; @@ -169,9 +171,9 @@ bool FilterCSG::applyFilter(const QAction *filter, MeshDocument &md, std::map v = InterceptSet3(tmpfirstmesh.cm, delta, subFreq, cb); + InterceptVolume v = InterceptSet3(tmpfirstmesh, delta, subFreq, cb); log(GLLogStream::SYSTEM, "Rasterizing second volume..."); - InterceptVolume tmp = InterceptSet3(tmpsecondmesh.cm, delta, subFreq, cb); + InterceptVolume tmp = InterceptSet3(tmpsecondmesh, delta, subFreq, cb); MeshModel *mesh; switch(par.getEnum("Operator")){