big fixed on copy mesh and filter csg

This commit is contained in:
alemuntoni 2020-11-26 10:59:28 +01:00
parent 264c3f625d
commit 077cf54660
8 changed files with 137 additions and 143 deletions

View File

@ -46,7 +46,7 @@ typedef vcg::Similarity<MESHLAB_SCALAR> Similaritym;
template<typename T>
struct MeshLabScalarTest
{
};
template<>
@ -67,36 +67,36 @@ struct MeshLabScalarTest<double>
namespace vcg
{
namespace vertex
{
template <class T> class Coord3m: public Coord<vcg::Point3<MESHLAB_SCALAR>, T> {
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Coord3m"));T::Name(name);}
};
namespace vertex
{
template <class T> class Coord3m: public Coord<vcg::Point3<MESHLAB_SCALAR>, T> {
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Coord3m"));T::Name(name);}
};
template <class T> class Normal3m: public Normal<vcg::Point3<MESHLAB_SCALAR>, T> {
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Normal3m"));T::Name(name);}
};
template <class T> class Normal3m: public Normal<vcg::Point3<MESHLAB_SCALAR>, T> {
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Normal3m"));T::Name(name);}
};
template <class T> class CurvatureDirmOcf: public CurvatureDirOcf<CurvatureDirTypeOcf<MESHLAB_SCALAR>, T> {
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("CurvatureDirmOcf"));T::Name(name);}
};
template <class T> class CurvatureDirmOcf: public CurvatureDirOcf<CurvatureDirTypeOcf<MESHLAB_SCALAR>, T> {
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("CurvatureDirmOcf"));T::Name(name);}
};
template <class T> class RadiusmOcf: public RadiusOcf<MESHLAB_SCALAR, T> {
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("RadiusmOcf"));T::Name(name);}
};
template <class T> class RadiusmOcf: public RadiusOcf<MESHLAB_SCALAR, T> {
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("RadiusmOcf"));T::Name(name);}
};
}//end namespace vertex
namespace face
{
template <class T> class Normal3m: public NormalAbs<vcg::Point3<MESHLAB_SCALAR>, T> {
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Normal3m"));T::Name(name);}
};
}//end namespace vertex
namespace face
{
template <class T> class Normal3m: public NormalAbs<vcg::Point3<MESHLAB_SCALAR>, T> {
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("Normal3m"));T::Name(name);}
};
template <class T> class CurvatureDirmOcf: public CurvatureDirOcf<CurvatureDirOcfBaseType<MESHLAB_SCALAR>, T> {
public: static void Name(std::vector<std::string> & name){name.push_back(std::string("CurvatureDirdOcf"));T::Name(name);}
};
template <class T> class CurvatureDirmOcf: public CurvatureDirOcf<CurvatureDirOcfBaseType<MESHLAB_SCALAR>, T> {
public: static void Name(std::vector<std::string> & 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<CVertexO>::AsVertexType,
vcg::Use<CEdgeO >::AsEdgeType,
vcg::Use<CFaceO >::AsFaceType >{};
vcg::Use<CEdgeO >::AsEdgeType,
vcg::Use<CFaceO >::AsFaceType >{};
// The Main Vertex Class
@ -115,88 +115,102 @@ class CUsedTypesO: public vcg::UsedTypes < vcg::Use<CVertexO>::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<CUsedTypesO,
vcg::edge::BitFlags, /* 4b */
vcg::edge::EVAdj,
vcg::edge::EEAdj
>{
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<CVertexO>, vcg::face::vector_ocf<CFaceO> > vcgTriMesh;
class CMeshO : public vcg::tri::TriMesh< vcg::vertex::vector_ocf<CVertexO>, vcg::face::vector_ocf<CFaceO> >
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<CVertexO>, vcg::face::vector_ocf<CFaceO> >(),
sfn(0), svn(0), pvn(0), pfn(0)
{
}
CMeshO(const CMeshO& oth) : CMeshO() {
vcg::tri::Append<CMeshO, CMeshO>::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<CMeshO, CMeshO>::Mesh(*this, oth);
}
//TODO should change also this and use the copy&swap idiom
CMeshO& operator=(const CMeshO& oth) {
Clear();
vcg::tri::Append<CMeshO, CMeshO>::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<vcgTriMesh, vcgTriMesh>::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<vcgTriMesh, vcgTriMesh>::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<vcgTriMesh, vcgTriMesh>::MeshCopyConst(*this, oth);
sfn = oth.sfn;
svn = oth.svn;
pvn = oth.pvn;
pfn = oth.pfn;
Tr = oth.Tr;
return *this;
}
};
#endif //CMESH_H

View File

@ -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;
}

View File

@ -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<int>& mm,const int meshupdatemask,const QList<int>& rm,const int rasterupdatemask);
void updateRenderStateMeshes(const QList<int>& mm,const int meshupdatemask);
void updateRenderStateRasters(const QList<int>& 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

View File

@ -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<CMeshO, CMeshO>::MeshCopy(cm, cp->cm);
}
QString MeshModel::relativePathName() const
{
QDir documentDir (documentPathName());

View File

@ -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:

View File

@ -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;

View File

@ -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;}

View File

@ -151,17 +151,19 @@ bool FilterCSG::applyFilter(const QAction *filter, MeshDocument &md, std::map<st
firstMesh->updateDataMask(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<CMeshO>::Box(tmpfirstmesh.cm);
vcg::tri::UpdateNormal<CMeshO>::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<CMeshO>::Box(tmpfirstmesh);
vcg::tri::UpdateNormal<CMeshO>::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<CMeshO>::Box(tmpsecondmesh.cm);
vcg::tri::UpdateNormal<CMeshO>::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<CMeshO>::Box(tmpsecondmesh);
vcg::tri::UpdateNormal<CMeshO>::PerVertexNormalizedPerFaceNormalized(tmpfirstmesh);
// typedef CMeshO::ScalarType scalar;
typedef Intercept<mpq_class,Scalarm> intercept;
@ -169,9 +171,9 @@ bool FilterCSG::applyFilter(const QAction *filter, MeshDocument &md, std::map<st
const Point3m delta(d, d, d);
const int subFreq = par.getInt("SubDelta");
log(GLLogStream::SYSTEM, "Rasterizing first volume...");
InterceptVolume<intercept> v = InterceptSet3<intercept>(tmpfirstmesh.cm, delta, subFreq, cb);
InterceptVolume<intercept> v = InterceptSet3<intercept>(tmpfirstmesh, delta, subFreq, cb);
log(GLLogStream::SYSTEM, "Rasterizing second volume...");
InterceptVolume<intercept> tmp = InterceptSet3<intercept>(tmpsecondmesh.cm, delta, subFreq, cb);
InterceptVolume<intercept> tmp = InterceptSet3<intercept>(tmpsecondmesh, delta, subFreq, cb);
MeshModel *mesh;
switch(par.getEnum("Operator")){