mirror of
https://github.com/lucaspalomodevelop/meshlab.git
synced 2026-03-19 19:14:42 +00:00
Reduced the amount of space used during the computation
This commit is contained in:
parent
71ea5242b9
commit
b60a5049b2
@ -81,7 +81,9 @@ bool FilterScanMergingPlugin::applyFilter(QAction *filter, MeshDocument &md, Ric
|
||||
|
||||
MeshModel *destMesh = md.addNewMesh("","MergedMesh");
|
||||
|
||||
CMeshO tempMesh[2];
|
||||
//CMeshO tempMesh[2];
|
||||
|
||||
std::vector<Point3f> vertices[2];
|
||||
|
||||
/* Compute the low frequencies mesh taking into account the union of the complete set of layers */
|
||||
cb(0, "High Fidelity Scan Merging: merging visible layers");
|
||||
@ -89,19 +91,28 @@ bool FilterScanMergingPlugin::applyFilter(QAction *filter, MeshDocument &md, Ric
|
||||
if (mmp->visible) {
|
||||
tri::Allocator<CMeshO>::CompactVertexVector(mmp->cm);
|
||||
tri::UpdatePosition<CMeshO>::Matrix(mmp->cm, mmp->cm.Tr, true);
|
||||
tri::Append<CMeshO, CMeshO>::Mesh(tempMesh[0], mmp->cm);
|
||||
for (CMeshO::VertexIterator vi = mmp->cm.vert.begin(); vi != mmp->cm.vert.end(); vi++) {
|
||||
vertices[0].push_back(vi->cP());
|
||||
}
|
||||
// tri::Append<CMeshO, CMeshO>::Mesh(tempMesh[0], mmp->cm);
|
||||
tri::UpdatePosition<CMeshO>::Matrix(mmp->cm, Inverse(mmp->cm.Tr), true);
|
||||
nOp++;
|
||||
}
|
||||
}
|
||||
tri::Allocator<CMeshO>::CompactVertexVector(tempMesh[0]);
|
||||
vertices[1].resize(vertices[0].size());
|
||||
// tri::Allocator<CMeshO>::CompactVertexVector(tempMesh[0]);
|
||||
nOp += 2;
|
||||
|
||||
cb(100/nOp, "High Fidelity Scan Merging: computing low frequencies base");
|
||||
|
||||
toLowFreq(tempMesh, nIterations, nNeighbors);
|
||||
toLowFreq(vertices, nIterations, nNeighbors);
|
||||
// toLowFreq(tempMesh, nIterations, nNeighbors);
|
||||
|
||||
tri::Append<CMeshO, CMeshO>::Mesh(destMesh->cm, tempMesh[0]);
|
||||
tri::Allocator<CMeshO>::AddVertices(destMesh->cm, vertices[0].size());
|
||||
for (int i = 0; i < vertices[0].size(); i++) {
|
||||
destMesh->cm.vert[i].P() = vertices[0][i];
|
||||
}
|
||||
// tri::Append<CMeshO, CMeshO>::Mesh(destMesh->cm, tempMesh[0]);
|
||||
|
||||
/* Compute the high frequencies mesh taking into account one layer at time */
|
||||
long vertexCnt = 0;
|
||||
@ -110,24 +121,39 @@ bool FilterScanMergingPlugin::applyFilter(QAction *filter, MeshDocument &md, Ric
|
||||
if (mmp != destMesh && mmp->visible) {
|
||||
cb((nMesh+2)*100 / nOp, "High Fidelity Scan Merging: computing high frequencies");
|
||||
|
||||
tempMesh[0].Clear();
|
||||
tempMesh[1].Clear();
|
||||
vertices[0].clear();
|
||||
vertices[1].clear();
|
||||
// tempMesh[0].Clear();
|
||||
// tempMesh[1].Clear();
|
||||
|
||||
tri::UpdatePosition<CMeshO>::Matrix(mmp->cm, mmp->cm.Tr, true);
|
||||
tri::Append<CMeshO, CMeshO>::Mesh(tempMesh[0], mmp->cm);
|
||||
// tri::Append<CMeshO, CMeshO>::Mesh(tempMesh[0], mmp->cm);
|
||||
for (CMeshO::VertexIterator vi = mmp->cm.vert.begin(); vi != mmp->cm.vert.end(); vi++) {
|
||||
vertices[0].push_back(vi->cP());
|
||||
}
|
||||
vertices[1].resize(vertices[0].size());
|
||||
|
||||
toLowFreq(tempMesh, nIterations, nNeighbors);
|
||||
// toLowFreq(tempMesh, nIterations, nNeighbors);
|
||||
toLowFreq(vertices, nIterations, nNeighbors);
|
||||
|
||||
int localVertexCnt = 0;
|
||||
|
||||
/* Correct the low frequencies mesh with high frequencies features */
|
||||
for (CMeshO::VertexIterator vi = tempMesh[0].vert.begin(); vi != tempMesh[0].vert.end(); vi++) {
|
||||
destMesh->cm.vert[vertexCnt].P() = destMesh->cm.vert[vertexCnt].P() - (vi->cP() - mmp->cm.vert[localVertexCnt].cP());
|
||||
for (int i = 0; i < vertices[0].size(); i++) {
|
||||
destMesh->cm.vert[vertexCnt].P() = destMesh->cm.vert[vertexCnt].P() - (vertices[0][i] - mmp->cm.vert[localVertexCnt].cP());
|
||||
destMesh->cm.vert[vertexCnt].N() = mmp->cm.vert[localVertexCnt].N();
|
||||
if(modifyOriginalMeshFlag)
|
||||
mmp->cm.vert[localVertexCnt].P() = destMesh->cm.vert[vertexCnt].P();
|
||||
vertexCnt++;
|
||||
localVertexCnt++;
|
||||
}
|
||||
// for (CMeshO::VertexIterator vi = tempMesh[0].vert.begin(); vi != tempMesh[0].vert.end(); vi++) {
|
||||
// destMesh->cm.vert[vertexCnt].P() = destMesh->cm.vert[vertexCnt].P() - (vi->cP() - mmp->cm.vert[localVertexCnt].cP());
|
||||
// if(modifyOriginalMeshFlag)
|
||||
// mmp->cm.vert[localVertexCnt].P() = destMesh->cm.vert[vertexCnt].P();
|
||||
// vertexCnt++;
|
||||
// localVertexCnt++;
|
||||
// }
|
||||
tri::UpdatePosition<CMeshO>::Matrix(mmp->cm, Inverse(mmp->cm.Tr), true);
|
||||
|
||||
nMesh++;
|
||||
@ -148,10 +174,10 @@ FilterScanMergingPlugin::FilterClass FilterScanMergingPlugin::getClass(QAction *
|
||||
For each vertex the projection operator needs numOfNeighbors neighbors to find the fitting plane.
|
||||
Once the function returns the result is in m[0]
|
||||
**/
|
||||
void FilterScanMergingPlugin::toLowFreq(CMeshO* m, int numOfIterations, int numOfNeighbors) {
|
||||
void FilterScanMergingPlugin::toLowFreq(vector<Point3f>* vert, int numOfIterations, int numOfNeighbors) {
|
||||
Plane3<CMeshO::ScalarType> fittingPlane;
|
||||
std::vector<CMeshO::CoordType> pointToFit;
|
||||
std::vector<CVertexO*>::iterator it;
|
||||
// std::vector<CVertexO*>::iterator it;
|
||||
int act;
|
||||
int next;
|
||||
|
||||
@ -159,29 +185,46 @@ void FilterScanMergingPlugin::toLowFreq(CMeshO* m, int numOfIterations, int numO
|
||||
act = i%2;
|
||||
next = (i+1)%2;
|
||||
|
||||
VertexConstDataWrapper<CMeshO> ww(m[act]);
|
||||
// VertexConstDataWrapper<CMeshO> ww(m[act]);
|
||||
ConstDataWrapper<CMeshO::CoordType> ww(&(vert[act][0]), vert[act].size(), sizeof(Point3f));
|
||||
KdTree<float> tree(ww);
|
||||
tree.setMaxNofNeighbors(numOfNeighbors);
|
||||
CMeshO::VertexIterator vertices = tri::Allocator<CMeshO>::AddVertices(m[next], m[act].VertexNumber());
|
||||
|
||||
for (CMeshO::VertexIterator vi = m[act].vert.begin(); vi != m[act].vert.end(); vi++) {
|
||||
tree.doQueryK( vi->cP() );
|
||||
// CMeshO::VertexIterator vertices = tri::Allocator<CMeshO>::AddVertices(m[next], m[act].VertexNumber());
|
||||
|
||||
//perror("iteration\n");
|
||||
for (int j = 0; j < vert[act].size(); j++) {
|
||||
tree.doQueryK(vert[act][j]);
|
||||
int neighbours = tree.getNofFoundNeighbors();
|
||||
pointToFit.clear();
|
||||
for (int j = 0; j < neighbours; j++) {
|
||||
int neightId = tree.getNeighborId(j);
|
||||
pointToFit.push_back(m[act].vert[neightId].cP() );
|
||||
for (int k = 0; k < neighbours; k++) {
|
||||
int neightId = tree.getNeighborId(k);
|
||||
pointToFit.push_back(vert[act][neightId]);
|
||||
}
|
||||
vcg::FitPlaneToPointSet(pointToFit, fittingPlane);
|
||||
vertices->P() = fittingPlane.Projection(vi->cP());
|
||||
vertices->N() = vi->cN();
|
||||
vertices++;
|
||||
vert[next][j] = fittingPlane.Projection(vert[act][j]);
|
||||
}
|
||||
m[act].Clear();
|
||||
//perror("iteration end\n");
|
||||
|
||||
// for (CMeshO::VertexIterator vi = m[act].vert.begin(); vi != m[act].vert.end(); vi++) {
|
||||
// tree.doQueryK( vi->cP() );
|
||||
// int neighbours = tree.getNofFoundNeighbors();
|
||||
// pointToFit.clear();
|
||||
// for (int j = 0; j < neighbours; j++) {
|
||||
// int neightId = tree.getNeighborId(j);
|
||||
// pointToFit.push_back(m[act].vert[neightId].cP() );
|
||||
// }
|
||||
// vcg::FitPlaneToPointSet(pointToFit, fittingPlane);
|
||||
// vertices->P() = fittingPlane.Projection(vi->cP());
|
||||
// vertices->N() = vi->cN();
|
||||
// vertices++;
|
||||
// }
|
||||
// m[act].Clear();
|
||||
}
|
||||
if (act == 1) return;
|
||||
else {
|
||||
tri::Append<CMeshO, CMeshO>::Mesh(m[0], m[1]);
|
||||
vert[0] = vert[1];
|
||||
// tri::Append<CMeshO, CMeshO>::Mesh(m[0], m[1]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,6 +27,7 @@
|
||||
#include <QObject>
|
||||
|
||||
#include <common/interfaces.h>
|
||||
#include <vector>
|
||||
|
||||
class FilterScanMergingPlugin : public QObject, public MeshFilterInterface
|
||||
{
|
||||
@ -45,7 +46,8 @@ public:
|
||||
virtual bool applyFilter(QAction *filter, MeshDocument &md, RichParameterSet & /*parent*/, vcg::CallBackPos * cb) ;
|
||||
|
||||
private:
|
||||
void toLowFreq(CMeshO* m, int numOfIterations, int numOfNeighbors);
|
||||
//void toLowFreq(CMeshO* m, int numOfIterations, int numOfNeighbors);
|
||||
void toLowFreq(std::vector<vcg::Point3f>* vert, int numOfIterations, int numOfNeighbors);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user