X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FINTERP_KERNEL%2FConvexIntersector.txx;h=3986a4a24c7f1275ca443527a89b8f79d88efe6d;hb=1a9af3cb21941312cdda3f0466677b61beba7ade;hp=c15bc3f0e1e0883103c09edd21c88e36df041dba;hpb=48782c06022ca2caa36f849cb5a29ea4fe2aaa83;p=tools%2Fmedcoupling.git diff --git a/src/INTERP_KERNEL/ConvexIntersector.txx b/src/INTERP_KERNEL/ConvexIntersector.txx index c15bc3f0e..3986a4a24 100644 --- a/src/INTERP_KERNEL/ConvexIntersector.txx +++ b/src/INTERP_KERNEL/ConvexIntersector.txx @@ -1,21 +1,22 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D +// Copyright (C) 2007-2013 CEA/DEN, EDF R&D // -// 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. +// 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. // -// 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. +// 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +// Author : Anthony Geay (CEA/DEN) #ifndef __CONVEXINTERSECTOR_TXX__ #define __CONVEXINTERSECTOR_TXX__ @@ -23,18 +24,24 @@ #include "PlanarIntersectorP0P0.txx" #include "PlanarIntersectorP0P1.txx" #include "PlanarIntersectorP1P0.txx" +#include "PlanarIntersectorP1P1.txx" +#include "PlanarIntersectorP1P0Bary.txx" +#include "PlanarIntersectorP0P1Bary.txx" #include "PolygonAlgorithms.txx" #include +#define CONVINTERSECTOR_TEMPLATE template class InterpType> +#define CONVEX_INTERSECTOR_ ConvexIntersector + namespace INTERP_KERNEL { - template class InterpType> - ConvexIntersector::ConvexIntersector(const MyMeshType& meshT, const MyMeshType& meshS, - double dimCaracteristic, double precision, - double medianPlane, bool doRotate , int oriantation, int printLevel) - :InterpType >(meshT,meshS,dimCaracteristic, precision, medianPlane, doRotate, oriantation, printLevel), + CONVINTERSECTOR_TEMPLATE + CONVEX_INTERSECTOR_::ConvexIntersector(const MyMeshType& meshT, const MyMeshType& meshS, + double dimCaracteristic, double precision, double md3DSurf, double minDot3DSurf, + double medianPlane, bool doRotate , int oriantation, int printLevel) + :InterpType(meshT,meshS,dimCaracteristic, precision, md3DSurf, minDot3DSurf, medianPlane, doRotate, oriantation, printLevel), _epsilon(precision*dimCaracteristic) { if(PlanarIntersector::_print_level >= 1) @@ -47,8 +54,9 @@ namespace INTERP_KERNEL } } - template class InterpType> - double ConvexIntersector::intersectGeometry(ConnType icellT, ConnType icellS, ConnType nbNodesT, ConnType nbNodesS) + CONVINTERSECTOR_TEMPLATE + double CONVEX_INTERSECTOR_::intersectGeometry(ConnType icellT, ConnType icellS, + ConnType nbNodesT, ConnType nbNodesS) { double result = 0; int orientation = 1; @@ -81,8 +89,10 @@ namespace INTERP_KERNEL return orientation*result; } - template class InterpType> - double ConvexIntersector::intersectGeometryWithQuadrangle(const double *quadrangle, const std::vector& sourceCoords, bool isSourceQuad) + CONVINTERSECTOR_TEMPLATE + double CONVEX_INTERSECTOR_::intersectGeometryWithQuadrangle(const double * quadrangle, + const std::vector& sourceCoords, + bool isSourceQuad) { double result = 0; int nbOfNodesS=sourceCoords.size()/SPACEDIM; @@ -110,6 +120,76 @@ namespace INTERP_KERNEL return result; } + + CONVINTERSECTOR_TEMPLATE + double CONVEX_INTERSECTOR_::intersectGeometryGeneral(const std::vector& targetCoords, + const std::vector& sourceCoords) + { + double result = 0; + int nbOfNodesS=sourceCoords.size()/SPACEDIM; + int nbOfNodesT=targetCoords.size()/SPACEDIM; + /*** Compute the intersection area ***/ + INTERP_KERNEL::PolygonAlgorithms P(_epsilon, PlanarIntersector::_precision); + std::deque inter = P.intersectConvexPolygons(&targetCoords[0], &sourceCoords[0], + nbOfNodesT, nbOfNodesS); + double area[SPACEDIM]; + int nb_inter =((int)inter.size())/SPACEDIM; + for(int i = 1; i(&inter[0],&inter[SPACEDIM*i],&inter[SPACEDIM*(i+1)],area); + result +=0.5*norm(area); + } + return result; + } + + //================================================================================ + /*! + * \brief Intersect a triangle and a polygon for P1P0 barycentric algorithm + * \param targetCell - list of coordinates of target polygon in full interlace + * \param targetCellQuadratic - specifies if target polygon is quadratic or not + * \param sourceTria - list of coordinates of source triangle + * \param res - coefficients a,b and c associated to nodes of sourceTria + */ + //================================================================================ + + CONVINTERSECTOR_TEMPLATE + double CONVEX_INTERSECTOR_::intersectGeoBary(const std::vector& targetCell, + bool targetCellQuadratic, + const double * sourceTria, + std::vector& res) + { + double area = 0; + double barycenter[SPACEDIM] = {0., 0.}; + int nbOfNodesT=targetCell.size()/SPACEDIM; + + /*** Compute the intersection area ***/ + INTERP_KERNEL::PolygonAlgorithms P(_epsilon, PlanarIntersector::_precision); + std::deque inter = P.intersectConvexPolygons(sourceTria, &targetCell[0], 3, nbOfNodesT); + double cross[SPACEDIM]; + int nb_inter =((int)inter.size())/SPACEDIM; + for(int i = 1; i(&inter[0],&inter[SPACEDIM*i],&inter[SPACEDIM*(i+1)],cross); + area += 0.5*norm(cross); + barycenter[0] += inter[SPACEDIM*i]; + barycenter[1] += inter[SPACEDIM*i+1]; + } + if ( area > std::numeric_limits::min() ) + { + barycenter[0] = ( barycenter[0] + inter[0] + inter[SPACEDIM*(nb_inter-1)] ) / nb_inter; + barycenter[1] = ( barycenter[1] + inter[1] + inter[SPACEDIM*(nb_inter-1)+1]) / nb_inter; + res.resize(3); + barycentric_coords<2>( sourceTria, &barycenter[0], &res[0]); + res[0] *= area; + res[1] *= area; + res[2] *= area; + } + else + { + area = 0; + } + return area; + } } #endif