diff --git a/src/fgt/filter_scan_merging/filter_scan_merging.cpp b/src/fgt/filter_scan_merging/filter_scan_merging.cpp index c20aeb3d3..8e381927c 100644 --- a/src/fgt/filter_scan_merging/filter_scan_merging.cpp +++ b/src/fgt/filter_scan_merging/filter_scan_merging.cpp @@ -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 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::CompactVertexVector(mmp->cm); tri::UpdatePosition::Matrix(mmp->cm, mmp->cm.Tr, true); - tri::Append::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::Mesh(tempMesh[0], mmp->cm); tri::UpdatePosition::Matrix(mmp->cm, Inverse(mmp->cm.Tr), true); nOp++; } } - tri::Allocator::CompactVertexVector(tempMesh[0]); + vertices[1].resize(vertices[0].size()); +// tri::Allocator::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::Mesh(destMesh->cm, tempMesh[0]); + tri::Allocator::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::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::Matrix(mmp->cm, mmp->cm.Tr, true); - tri::Append::Mesh(tempMesh[0], mmp->cm); +// tri::Append::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::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* vert, int numOfIterations, int numOfNeighbors) { Plane3 fittingPlane; std::vector pointToFit; - std::vector::iterator it; +// std::vector::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 ww(m[act]); +// VertexConstDataWrapper ww(m[act]); + ConstDataWrapper ww(&(vert[act][0]), vert[act].size(), sizeof(Point3f)); KdTree tree(ww); tree.setMaxNofNeighbors(numOfNeighbors); - CMeshO::VertexIterator vertices = tri::Allocator::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::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::Mesh(m[0], m[1]); + vert[0] = vert[1]; +// tri::Append::Mesh(m[0], m[1]); return; } } diff --git a/src/fgt/filter_scan_merging/filter_scan_merging.h b/src/fgt/filter_scan_merging/filter_scan_merging.h index 915ce7535..3ec52458e 100644 --- a/src/fgt/filter_scan_merging/filter_scan_merging.h +++ b/src/fgt/filter_scan_merging/filter_scan_merging.h @@ -27,6 +27,7 @@ #include #include +#include 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* vert, int numOfIterations, int numOfNeighbors); }; #endif