Commit e9f09660 by Sylvain Thery

### Merge branch 'problem_explode'

parents 2ccf806b 916836d9
 ... @@ -54,6 +54,21 @@ namespace Geometry ... @@ -54,6 +54,21 @@ namespace Geometry template template EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs, unsigned int thread = 0); EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs, unsigned int thread = 0); /** * Compute volume centroid weighted by edge length (generic version) * Pre: closed volume & embedded vertices * Template param: * PFP: as usual * EMBV: attributes vector type or cell type (VertexCell, FaceCell, ...) * EMB: type of attribute (Geom::Vec3f) or cell type (VertexCell, FaceCell, ...) * @param map the map * @param d a dart of the face * @param attributs the vector of attribute or cell */ template EMB volumeCentroidELWGen(typename PFP::MAP& map, Dart d, const EMBV& attributs, unsigned int thread = 0); /** /** * Compute volume centroid * Compute volume centroid * Pre: closed volume & embedded vertices * Pre: closed volume & embedded vertices ... @@ -62,11 +77,25 @@ EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs, uns ... @@ -62,11 +77,25 @@ EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs, uns * @param position the vector of attribute * @param position the vector of attribute */ */ template template typename PFP::VEC3 volumeCentroid(typename PFP::MAP& map, Dart d, const VertexAttribute& position, unsigned int thread = 0) inline typename PFP::VEC3 volumeCentroid(typename PFP::MAP& map, Dart d, const VertexAttribute& position, unsigned int thread = 0) { { return volumeCentroidGen, typename PFP::VEC3>(map, d, position, thread); return volumeCentroidGen, typename PFP::VEC3>(map, d, position, thread); } } /** * Compute volume centroid weighted by edge length * Pre: closed volume & embedded vertices * @param map the map * @param d a dart of the face * @param position the vector of attribute */ template inline typename PFP::VEC3 volumeCentroidELW(typename PFP::MAP& map, Dart d, const VertexAttribute& position, unsigned int thread = 0) { return volumeCentroidELWGen, typename PFP::VEC3>(map, d, position, thread); } /** /** * Compute face centroid (generic version) * Compute face centroid (generic version) * Template param: * Template param: ... @@ -80,6 +109,19 @@ typename PFP::VEC3 volumeCentroid(typename PFP::MAP& map, Dart d, const VertexAt ... @@ -80,6 +109,19 @@ typename PFP::VEC3 volumeCentroid(typename PFP::MAP& map, Dart d, const VertexAt template template EMB faceCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs); EMB faceCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs); /** * Compute face centroid weighted by edge length (generic version) * Template param: * PFP: as usual * EMBV: attributes vector type or cell type (VertexCell, FaceCell, ...) * EMB: type of attribute (Geom::Vec3f) or cell type (VertexCell, FaceCell, ...) * @param map the map * @param d a dart of the face * @param attributs the vector of attribute or cell */ template EMB faceCentroidELWGen(typename PFP::MAP& map, Dart d, const EMBV& attributs); /** /** * Compute face centroid * Compute face centroid * Pre: closed face & embedded vertices * Pre: closed face & embedded vertices ... @@ -93,6 +135,20 @@ typename PFP::VEC3 faceCentroid(typename PFP::MAP& map, Dart d, const VertexAttr ... @@ -93,6 +135,20 @@ typename PFP::VEC3 faceCentroid(typename PFP::MAP& map, Dart d, const VertexAttr return faceCentroidGen, typename PFP::VEC3>(map, d, position); return faceCentroidGen, typename PFP::VEC3>(map, d, position); } } /** * Compute face centroid weighted by edge length * Pre: closed face & embedded vertices * @param map the map * @param d a dart of the face * @param position the vector of attribute */ template typename PFP::VEC3 faceCentroidELW(typename PFP::MAP& map, Dart d, const VertexAttribute& position) { return faceCentroidELWGen, typename PFP::VEC3>(map, d, position); } /** /** * Compute vertex neighbours centroid (generic version) * Compute vertex neighbours centroid (generic version) * Template param: * Template param: ... @@ -118,11 +174,41 @@ typename PFP::VEC3 vertexNeighborhoodCentroid(typename PFP::MAP& map, Dart d, co ... @@ -118,11 +174,41 @@ typename PFP::VEC3 vertexNeighborhoodCentroid(typename PFP::MAP& map, Dart d, co return vertexNeighborhoodCentroidGen, typename PFP::VEC3>(map, d, position); return vertexNeighborhoodCentroidGen, typename PFP::VEC3>(map, d, position); } } /** * Compute centroid of all faces * @param map the map * @param position position vertex attribute * @param face_centroid centroid face attribute * @param select the selector * @param thread the thread id (default 0) */ template template void computeCentroidFaces(typename PFP::MAP& map, void computeCentroidFaces(typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& face_centroid, const VertexAttribute& position, FaceAttribute& face_centroid, const FunctorSelect& select = allDarts, unsigned int thread = 0) ; const FunctorSelect& select = allDarts, unsigned int thread = 0) ; /** * Compute centroid of all faces (Edge Length Weighted) * @param map the map * @param position position vertex attribute * @param face_centroid centroid face attribute * @param select the selector * @param thread the thread id (default 0) */ template void computeCentroidELWFaces(typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& face_centroid, const FunctorSelect& select = allDarts, unsigned int thread = 0) ; /** * Compute neighborhood centroid of all vertices * @param map the map * @param position position vertex attribute * @param vertex_centroid centroid vertex attribute * @param select the selector * @param thread the thread id (default 0) */ template template void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vertex_centroid, const VertexAttribute& position, VertexAttribute& vertex_centroid, ... @@ -131,11 +217,40 @@ void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, ... @@ -131,11 +217,40 @@ void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, namespace Parallel namespace Parallel { { /** * Compute centroid of all faces * @param map the map * @param position position vertex attribute * @param face_centroid centroid face attribute * @param select the selector * @param nbth the number of threads */ template template void computeCentroidFaces(typename PFP::MAP& map, void computeCentroidFaces(typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& face_centroid, const VertexAttribute& position, FaceAttribute& face_centroid, const FunctorSelect& select = allDarts, unsigned int nbth = 0) ; const FunctorSelect& select = allDarts, unsigned int nbth = 0) ; /** * Compute centroid of all faces (Edge Length Weighted) * @param map the map * @param position position vertex attribute * @param face_centroid centroid face attribute * @param select the selector * @param nbth the number of threads */ template void computeCentroidELWFaces(typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& face_centroid, const FunctorSelect& select = allDarts, unsigned int nbth = 0) ; /** * Compute neighborhood centroid of all vertices (in parallel) * @param map the map * @param position position vertex attribute * @param vertex_centroid centroid vertex attribute * @param select the selector * @param nbth the number of threads */ template template void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vertex_centroid, const VertexAttribute& position, VertexAttribute& vertex_centroid, ... @@ -185,6 +300,11 @@ void computeCentroidVolumes(typename PFP::MAP& map, ... @@ -185,6 +300,11 @@ void computeCentroidVolumes(typename PFP::MAP& map, const VertexAttribute& position, VolumeAttribute& vol_centroid, const VertexAttribute& position, VolumeAttribute& vol_centroid, const FunctorSelect& select = allDarts, unsigned int thread = 0) ; const FunctorSelect& select = allDarts, unsigned int thread = 0) ; template void computeCentroidELWVolumes(typename PFP::MAP& map, const VertexAttribute& position, VolumeAttribute& vol_centroid, const FunctorSelect& select = allDarts, unsigned int thread = 0) ; /** /** * compute centroid of all vertices * compute centroid of all vertices * @param map the map * @param map the map ... @@ -206,6 +326,12 @@ void computeCentroidVolumes(typename PFP::MAP& map, ... @@ -206,6 +326,12 @@ void computeCentroidVolumes(typename PFP::MAP& map, const VertexAttribute& position, VolumeAttribute& vol_centroid, const VertexAttribute& position, VolumeAttribute& vol_centroid, const FunctorSelect& select = allDarts, unsigned int nbth = 0) ; const FunctorSelect& select = allDarts, unsigned int nbth = 0) ; template void computeCentroidELWVolumes(typename PFP::MAP& map, const VertexAttribute& position, VolumeAttribute& vol_centroid, const FunctorSelect& select = allDarts, unsigned int nbth = 0) ; template template void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vertex_centroid, const VertexAttribute& position, VertexAttribute& vertex_centroid, ... ...
 ... @@ -59,6 +59,25 @@ EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs, uns ... @@ -59,6 +59,25 @@ EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs, uns return center ; return center ; } } template EMB volumeCentroidELWGen(typename PFP::MAP& map, Dart d, const EMBV& attributs, unsigned int thread) { EMB center = AttribOps::zero(); double count=0.0; Traversor3WE t(map, d,false,thread) ; for(Dart it = t.begin(); it != t.end();it = t.next()) { EMB e1 = attributs[it]; EMB e2 = attributs[map.phi1(it)]; double l = (e2-e1).norm(); center += (e1+e2)*l; count += 2.0*l ; } center /= double(count); return center ; } template template EMB faceCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs) EMB faceCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs) { { ... @@ -74,6 +93,26 @@ EMB faceCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs) ... @@ -74,6 +93,26 @@ EMB faceCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs) return center ; return center ; } } template EMB faceCentroidELWGen(typename PFP::MAP& map, Dart d, const EMBV& attributs) { EMB center = AttribOps::zero(); double count=0.0; Traversor2FE t(map, d) ; for(Dart it = t.begin(); it != t.end(); it = t.next()) { EMB e1 = attributs[it]; EMB e2 = attributs[map.phi1(it)]; double l = (e2-e1).norm(); center += (e1+e2)*l; count += 2.0*l ; } center /= double(count); return center ; } template template EMB vertexNeighborhoodCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs) EMB vertexNeighborhoodCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs) { { ... @@ -98,6 +137,14 @@ void computeCentroidFaces(typename PFP::MAP& map, const VertexAttribute(map, d, position) ; face_centroid[d] = faceCentroid(map, d, position) ; } } template void computeCentroidELWFaces(typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& face_centroid, const FunctorSelect& select, unsigned int thread) { TraversorF t(map, select,thread) ; for(Dart d = t.begin(); d != t.end(); d = t.next()) face_centroid[d] = faceCentroidELW(map, d, position) ; } template template void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vertex_centroid, const FunctorSelect& select, unsigned int thread) void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vertex_centroid, const FunctorSelect& select, unsigned int thread) { { ... @@ -127,6 +174,23 @@ public: ... @@ -127,6 +174,23 @@ public: } } }; }; template class FunctorComputeCentroidELWFaces: public FunctorMapThreaded { const VertexAttribute& m_position; FaceAttribute& m_fcentroid; public: FunctorComputeCentroidELWFaces( typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& fcentroid): FunctorMapThreaded(map), m_position(position), m_fcentroid(fcentroid) { } void run(Dart d, unsigned int threadID) { m_fcentroid[d] = faceCentroidELW(this->m_map, d, m_position) ; } }; template template void computeCentroidFaces(typename PFP::MAP& map, void computeCentroidFaces(typename PFP::MAP& map, ... @@ -137,6 +201,15 @@ void computeCentroidFaces(typename PFP::MAP& map, ... @@ -137,6 +201,15 @@ void computeCentroidFaces(typename PFP::MAP& map, Algo::Parallel::foreach_cell(map, funct, nbth, false, select, current_thread); Algo::Parallel::foreach_cell(map, funct, nbth, false, select, current_thread); } } template void computeCentroidELWFaces(typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& face_centroid, const FunctorSelect& select, unsigned int nbth, unsigned int current_thread) { FunctorComputeCentroidELWFaces funct(map,position,face_centroid); Algo::Parallel::foreach_cell(map, funct, nbth, false, select, current_thread); } template template class FunctorComputeNeighborhoodCentroidVertices: public FunctorMapThreaded class FunctorComputeNeighborhoodCentroidVertices: public FunctorMapThreaded ... @@ -195,6 +268,15 @@ void computeCentroidVolumes(typename PFP::MAP& map, const VertexAttribute(map, d, position,thread) ; vol_centroid[d] = Surface::Geometry::volumeCentroid(map, d, position,thread) ; } } template void computeCentroidELWVolumes(typename PFP::MAP& map, const VertexAttribute& position, VolumeAttribute& vol_centroid, const FunctorSelect& select, unsigned int thread) { TraversorW t(map, select,thread) ; for(Dart d = t.begin(); d != t.end(); d = t.next()) vol_centroid[d] = Surface::Geometry::volumeCentroidELW(map, d, position,thread) ; } namespace Parallel namespace Parallel { { template template ... @@ -212,6 +294,22 @@ public: ... @@ -212,6 +294,22 @@ public: m_vol_centroid[d] = Surface::Geometry::volumeCentroid(this->m_map, d, m_position,threadID) ; m_vol_centroid[d] = Surface::Geometry::volumeCentroid(this->m_map, d, m_position,threadID) ; } } }; }; template class FunctorComputeCentroidELWVolumes: public FunctorMapThreaded { const VertexAttribute& m_position; VolumeAttribute& m_vol_centroid; public: FunctorComputeCentroidELWVolumes( typename PFP::MAP& map, const VertexAttribute& position, VolumeAttribute& vol_centroid): FunctorMapThreaded(map), m_position(position), m_vol_centroid(vol_centroid) { } void run(Dart d, unsigned int threadID) { m_vol_centroid[d] = Surface::Geometry::volumeCentroidELW(this->m_map, d, m_position,threadID) ; } }; template template void computeCentroidVolumes(typename PFP::MAP& map, void computeCentroidVolumes(typename PFP::MAP& map, ... @@ -223,6 +321,16 @@ void computeCentroidVolumes(typename PFP::MAP& map, ... @@ -223,6 +321,16 @@ void computeCentroidVolumes(typename PFP::MAP& map, } } template void computeCentroidELWVolumes(typename PFP::MAP& map, const VertexAttribute& position, VolumeAttribute& vol_centroid, const FunctorSelect& select, unsigned int nbth) { FunctorComputeCentroidELWVolumes funct(map,position,vol_centroid); Algo::Parallel::foreach_cell(map, funct, nbth, true, select); } template template class FunctorComputeNeighborhoodCentroidVertices: public FunctorMapThreaded class FunctorComputeNeighborhoodCentroidVertices: public FunctorMapThreaded { { ... @@ -256,8 +364,6 @@ void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, ... @@ -256,8 +364,6 @@ void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, } // namespace Algo } // namespace Algo } // namespace CGoGN } // namespace CGoGN
 ... @@ -28,7 +28,7 @@ ... @@ -28,7 +28,7 @@ #include "Topology/generic/cellmarker.h" #include "Topology/generic/cellmarker.h" #include "Algo/Geometry/centroid.h" #include "Algo/Geometry/centroid.h" #include "Topology/generic/autoAttributeHandler.h" #include "Topology/generic/autoAttributeHandler.h" #include "Algo/Geometry/normal.h" #include "Algo/Geometry/basic.h" #include "Algo/Geometry/basic.h" namespace CGoGN namespace CGoGN ... @@ -99,7 +99,7 @@ void ExplodeVolumeRender::updateSmooth(typename PFP::MAP& map, const VertexAttri ... @@ -99,7 +99,7 @@ void ExplodeVolumeRender::updateSmooth(typename PFP::MAP& map, const VertexAttri typedef typename PFP::REAL REAL; typedef typename PFP::REAL REAL; VolumeAutoAttribute centerVolumes(map, "centerVolumes"); VolumeAutoAttribute centerVolumes(map, "centerVolumes"); Algo::Volume::Geometry::Parallel::computeCentroidVolumes(map, positions, centerVolumes, good); Algo::Volume::Geometry::computeCentroidELWVolumes(map, positions, centerVolumes, good); std::vector buffer; std::vector buffer; buffer.reserve(16384); buffer.reserve(16384); ... @@ -108,57 +108,97 @@ void ExplodeVolumeRender::updateSmooth(typename PFP::MAP& map, const VertexAttri ... @@ -108,57 +108,97 @@ void ExplodeVolumeRender::updateSmooth(typename PFP::MAP& map, const VertexAttri bufferColors.reserve(16384); bufferColors.reserve(16384); std::vector bufferNormals; std::vector bufferNormals; bufferNormals.reserve(16384); bufferNormals.reserve(16384); std::vector normals; std::vector normals; bufferNormals.reserve(20); bufferNormals.reserve(20); std::vector vertices; bufferNormals.reserve(20); TraversorCell traFace(map, good); TraversorCell traFace(map, good); for (Dart d = traFace.begin(); d != traFace.end(); d = traFace.next()) for (Dart d = traFace.begin(); d != traFace.end(); d = traFace.next()) { { // compute normals // compute normals normals.clear(); normals.clear(); VEC3 centerFace(0); vertices.clear(); unsigned int nbs=0; VEC3 centerFace = Algo::Surface::Geometry::faceCentroid(map, d, positions); VEC3 centerNormalFace = Algo::Surface::Geometry::newellNormal(map,d,positions); Dart a = d; Dart a = d; do do { { VEC3 v1 = Algo::Surface::Geometry::vectorOutOfDart(map,a,positions); VEC3 v1 = positions[a] - centerFace; v1.normalize(); Dart e = map.phi1(a); Dart e = map.phi1(a); VEC3 v2 = Algo::Surface::Geometry::vectorOutOfDart(map,e,positions); VEC3 v2 = positions[map.phi1(e)] - centerFace; v2.normalize(); VEC3 N = v1^v2; VEC3 N = v1^v2; N.normalize(); double l = N.norm(); if (l<0.01) N = centerNormalFace; else { N /= l; if (N*centerNormalFace < 0.707) N = centerNormalFace; } normals.push_back(N); normals.push_back(N); vertices.push_back(positions[e]); a = e; a = e; centerFace += positions[a]; nbs++; } while (a != d); } while (a != d); centerFace /= float(nbs); VEC3 volCol = colorPerXXX[d]; typename std::vector::iterator in = normals.begin(); unsigned int nbs = vertices.size(); a = d; // just to have more easy algo further Dart b = map.phi1(a); vertices.push_back(vertices.front()); Dart c = map.phi1(b); normals.push_back(normals.front()); // loop to cut a polygon in triangle on the fly (works only with convex faces) do typename std::vector::iterator iv = vertices.begin(); typename std::vector::iterator in = normals.begin(); if (nbs == 3) { { buffer.push_back(centerVolumes[d]); buffer.push_back(centerVolumes[d]); bufferColors.push_back(centerFace); bufferColors.push_back(centerFace); bufferNormals.push_back(centerFace); // unsused just for fill bufferNormals.push_back(centerNormalFace); // unsused just for fill buffer.push_back(positions[d]); bufferColors.push_back(colorPerXXX[d]); buffer.push_back(*iv++); bufferNormals.push_back(normals.back()); buffer.push_back(positions[b]); bufferColors.push_back(colorPerXXX[b]); bufferNormals.push_back(*in++); bufferNormals.push_back(*in++); buffer.push_back(positions[c]); bufferColors.push_back(volCol); bufferColors.push_back(colorPerXXX[c]); bufferNormals.push_back(*in); buffer.push_back(*iv++); b = c; bufferNormals.push_back(*in++); c = map.phi1(b); bufferColors.push_back(volCol); } while (c != d); buffer.push_back(*iv++); bufferNormals.push_back(*in++); bufferColors.push_back(volCol); } else {