diff --git a/include/Algo/Import/import.h b/include/Algo/Import/import.h index 628a435f8fff4983bfc111e12a667d33e841b16f..000b421f115885295d3487ef5178437ffd531eb2 100644 --- a/include/Algo/Import/import.h +++ b/include/Algo/Import/import.h @@ -51,7 +51,7 @@ namespace Import * @return a boolean indicating if import was successfull */ template -bool importMesh(typename PFP::MAP& map, const std::string& filename, std::vector& attrNames, ImportSurfacique::ImportType kind = ImportSurfacique::UNKNOWNSURFACE); +bool importMesh(typename PFP::MAP& map, const std::string& filename, std::vector& attrNames, ImportSurfacique::ImportType kind = ImportSurfacique::UNKNOWNSURFACE, bool mergeCloseVertices=false); /** * import a volumic mesh diff --git a/include/Algo/Import/import2tables.h b/include/Algo/Import/import2tables.h index 299e6dd5a42dc364565ece399c513697aaafed75..8a6d00cb3a02b65d5f2e2488a1cbb79aefb06d13 100644 --- a/include/Algo/Import/import2tables.h +++ b/include/Algo/Import/import2tables.h @@ -115,6 +115,8 @@ public: bool importCTM(const std::string& filename, std::vector& attrNames); bool importASSIMP(const std::string& filename, std::vector& attrNames); + + bool mergeCloseVertices(); /** * @param container container of vertex orbite diff --git a/include/Algo/Import/import2tablesSurface.hpp b/include/Algo/Import/import2tablesSurface.hpp index 0110d10f85cdef3b56d0cd46555af725a2745cce..1b2275c8644b8da5595b1ef5fd54bebbc1418fbb 100644 --- a/include/Algo/Import/import2tablesSurface.hpp +++ b/include/Algo/Import/import2tablesSurface.hpp @@ -23,6 +23,8 @@ *******************************************************************************/ #include "Algo/Import/importPlyData.h" +#include "Algo/Geometry/boundingbox.h" +#include "Topology/generic/autoAttributeHandler.h" #include "openctm.h" @@ -433,7 +435,7 @@ bool MeshTablesSurface::importObj(const std::string& filename, std::vector< m_emb.reserve(verticesID.size()*8); std::vector table; - table.reserve(64); // 64 cotes pour une face devrait suffire + table.reserve(64); // NBV cotes pour une face devrait suffire m_nbFaces = 0; do { @@ -931,6 +933,158 @@ bool MeshTablesSurface::importASSIMP(const std::string& filename, std::vect return true; } +template +bool MeshTablesSurface::mergeCloseVertices() +{ + const unsigned int NBV=64; // seems to be good + + const int NEIGH[27]={ + -NBV*NBV - NBV - 1, -NBV*NBV - NBV, -NBV*NBV - NBV + 1, + -NBV*NBV - 1, -NBV*NBV, -NBV*NBV + 1, + -NBV*NBV + NBV - 1, -NBV*NBV + NBV, - NBV*NBV + NBV + 1, + -NBV - 1, - NBV, -NBV + 1, + -1, 0, 1, + NBV - 1, NBV, NBV + 1, + NBV*NBV - NBV - 1, NBV*NBV - NBV, NBV*NBV - NBV + 1, + NBV*NBV - 1, NBV*NBV, NBV*NBV + 1, + NBV*NBV + NBV - 1, NBV*NBV + NBV, NBV*NBV + NBV + 1}; + + std::vector** grid; + grid = new std::vector*[NBV*NBV*NBV]; + + // init grid with null ptrs + for (unsigned int i=0; i positions = m_map.template getAttribute(VERTEX, "position"); + + // compute BB + Geom::BoundingBox bb(positions[ positions.begin() ]) ; + for (unsigned int i = positions.begin(); i != positions.end(); positions.next(i)) + { + bb.addPoint(positions[i]) ; + } + + // add one voxel around to avoid testing + typename PFP::VEC3 bbsize = (bb.max() - bb.min()); + typename PFP::VEC3 one = bbsize/(NBV-2); + one*= 1.001f; + bb.addPoint( bb.min() - one); + bb.addPoint( bb.max() + one); + bbsize = (bb.max() - bb.min()); + + + AutoAttributeHandler gridIndex(m_map,VERTEX, "gridIndex"); + AutoAttributeHandler newIndices(m_map,VERTEX, "newIndices"); + + + // Store each vertex in the grid and store voxel index in vertex attribute + for (unsigned int i = positions.begin(); i != positions.end(); positions.next(i)) + { + typename PFP::VEC3 P = positions[i]; + P -= bb.min(); + float pz = floor((P[2]/bbsize[2])*NBV); + float py = floor((P[1]/bbsize[1])*NBV); + float px = floor((P[0]/bbsize[0])*NBV); + + unsigned int index = NBV*NBV*pz + NBV*py + px; + + if (pz==63) + std::cout << "z 63 bb:"<