/******************************************************************************* * CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps * * version 0.1 * * Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg * * * * This library is free software; you can redistribute it and/or modify it * * under the terms of the GNU Lesser General Public License as published by the * * Free Software Foundation; either version 2.1 of the License, or (at your * * option) any later version. * * * * This library is distributed in the hope that it will be useful, but WITHOUT * * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * * for more details. * * * * You should have received a copy of the GNU Lesser General Public License * * along with this library; if not, write to the Free Software Foundation, * * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * * * Web site: http://cgogn.unistra.fr/ * * Contact information: cgogn@unistra.fr * * * *******************************************************************************/ #include "Topology/generic/traversorCell.h" #include "Topology/generic/traversor2.h" #include "Topology/generic/cellmarker.h" #include "Topology/generic/traversorCell.h" #include "Topology/generic/traversor3.h" #include "Algo/Parallel/parallel_foreach.h" namespace CGoGN { namespace Algo { namespace Surface { namespace Geometry { template EMB volumeCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs, unsigned int thread) { EMB center = AttribOps::zero() ; unsigned int count = 0 ; Traversor3WV tra(map,d,false,thread); for (Dart d = tra.begin(); d != tra.end(); d = tra.next()) { center += attributs[d]; ++count; } center /= double(count) ; 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 EMB faceCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs) { EMB center = AttribOps::zero(); unsigned int count = 0 ; Traversor2FV t(map, d) ; for(Dart it = t.begin(); it != t.end(); it = t.next()) { center += attributs[it]; ++count ; } center /= double(count); 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 EMB vertexNeighborhoodCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs) { EMB center = AttribOps::zero(); unsigned int count = 0 ; Traversor2VVaE t(map, d) ; for(Dart it = t.begin(); it != t.end(); it = t.next()) { center += attributs[it]; ++count ; } center /= count ; return center ; } template void computeCentroidFaces(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] = 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 void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vertex_centroid, const FunctorSelect& select, unsigned int thread) { TraversorV t(map, select, thread) ; for(Dart d = t.begin(); d != t.end(); d = t.next()) vertex_centroid[d] = vertexNeighborhoodCentroid(map, d, position) ; } namespace Parallel { template class FunctorComputeCentroidFaces: public FunctorMapThreaded { const VertexAttribute& m_position; FaceAttribute& m_fcentroid; public: FunctorComputeCentroidFaces( 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] = faceCentroid(this->m_map, d, m_position) ; } }; 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 void computeCentroidFaces(typename PFP::MAP& map, const VertexAttribute& position, FaceAttribute& face_centroid, const FunctorSelect& select, unsigned int nbth, unsigned int current_thread) { FunctorComputeCentroidFaces funct(map,position,face_centroid); 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 class FunctorComputeNeighborhoodCentroidVertices: public FunctorMapThreaded { const VertexAttribute& m_position; VertexAttribute& m_vcentroid; public: FunctorComputeNeighborhoodCentroidVertices( typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vcentroid): FunctorMapThreaded(map), m_position(position), m_vcentroid(vcentroid) { } void run(Dart d, unsigned int threadID) { m_vcentroid[d] = vertexNeighborhoodCentroid(this->m_map, d, m_position) ; } }; template void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vertex_centroid, const FunctorSelect& select, unsigned int nbth, unsigned int current_thread) { FunctorComputeNeighborhoodCentroidVertices funct(map,position,vertex_centroid); Algo::Parallel::foreach_cell(map, funct, nbth, false, select, current_thread); } } } // namespace Geometry } // namespace Surface namespace Volume { namespace Geometry { template EMB vertexNeighborhoodCentroidGen(typename PFP::MAP& map, Dart d, const EMBV& attributs) { EMB center = AttribOps::zero(); unsigned int count = 0 ; Traversor3VVaE t(map, d) ; for(Dart it = t.begin(); it != t.end(); it = t.next()) { center += attributs[it]; ++count ; } center /= count ; return center ; } template void computeCentroidVolumes(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::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 { template class FunctorComputeCentroidVolumes: public FunctorMapThreaded { const VertexAttribute& m_position; VolumeAttribute& m_vol_centroid; public: FunctorComputeCentroidVolumes( 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::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 void computeCentroidVolumes(typename PFP::MAP& map, const VertexAttribute& position, VolumeAttribute& vol_centroid, const FunctorSelect& select, unsigned int nbth) { FunctorComputeCentroidVolumes funct(map,position,vol_centroid); Algo::Parallel::foreach_cell(map, funct, nbth, true, select); } 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 class FunctorComputeNeighborhoodCentroidVertices: public FunctorMapThreaded { const VertexAttribute& m_position; VertexAttribute& m_vcentroid; public: FunctorComputeNeighborhoodCentroidVertices( typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vcentroid): FunctorMapThreaded(map), m_position(position), m_vcentroid(vcentroid) { } void run(Dart d, unsigned int threadID) { m_vcentroid[d] = vertexNeighborhoodCentroid(this->m_map, d, m_position) ; } }; template void computeNeighborhoodCentroidVertices(typename PFP::MAP& map, const VertexAttribute& position, VertexAttribute& vertex_centroid, const FunctorSelect& select, unsigned int nbth, unsigned int current_thread) { FunctorComputeNeighborhoodCentroidVertices funct(map,position,vertex_centroid); Algo::Parallel::foreach_cell(map, funct, nbth, false, select, current_thread); } } // namespace Parallel } // namespace Geometry } // namespace Volume } // namespace Algo } // namespace CGoGN