From: eap Date: Tue, 29 Sep 2009 06:55:48 +0000 (+0000) Subject: 0020440: [CEA 349] P1P0 barycentric interpolators X-Git-Tag: V5_1_main_FINAL~338 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b5fc8dfe71d1775ce5198a37f3e0c4a1a6be08d8;p=tools%2Fmedcoupling.git 0020440: [CEA 349] P1P0 barycentric interpolators + double intersectWith(const QuadraticPolygon& other, double* barycenter) const; --- diff --git a/src/INTERP_KERNEL/Geometric2D/QuadraticPolygon.cxx b/src/INTERP_KERNEL/Geometric2D/QuadraticPolygon.cxx index f56424874..817c68477 100644 --- a/src/INTERP_KERNEL/Geometric2D/QuadraticPolygon.cxx +++ b/src/INTERP_KERNEL/Geometric2D/QuadraticPolygon.cxx @@ -197,6 +197,33 @@ double QuadraticPolygon::intersectWith(const QuadraticPolygon& other) const return ret; } +/*! + * \b WARNING this method is const and other is const too. \b BUT location of Edges in 'this' and 'other' are nevertheless modified. + * This is possible because loc attribute in Edge class is mutable. + * This implies that if 'this' or/and 'other' are reused for intersect* method initLocations has to be called on each of this/them. + */ +double QuadraticPolygon::intersectWith(const QuadraticPolygon& other, double* barycenter) const +{ + double ret=0., bary[2]; + barycenter[0] = barycenter[1] = 0.; + vector polygs=intersectMySelfWith(other); + for(vector::iterator iter=polygs.begin();iter!=polygs.end();iter++) + { + double area = fabs((*iter)->getArea()); + (*iter)->getBarycenter(bary); + delete *iter; + ret+=area; + barycenter[0] += bary[0]*area; + barycenter[1] += bary[1]*area; + } + if ( ret > std::numeric_limits::min() ) + { + barycenter[0] /= ret; + barycenter[1] /= ret; + } + return ret; +} + /*! * \b WARNING this method is const and other is const too. \b BUT location of Edges in 'this' and 'other' are nevertheless modified. * This is possible because loc attribute in Edge class is mutable. diff --git a/src/INTERP_KERNEL/Geometric2D/QuadraticPolygon.hxx b/src/INTERP_KERNEL/Geometric2D/QuadraticPolygon.hxx index 78977ecf5..fba577d8b 100644 --- a/src/INTERP_KERNEL/Geometric2D/QuadraticPolygon.hxx +++ b/src/INTERP_KERNEL/Geometric2D/QuadraticPolygon.hxx @@ -50,6 +50,7 @@ namespace INTERP_KERNEL //! Before intersecting as intersectWith a normalization is done. double intersectWithAbs(QuadraticPolygon& other); double intersectWith(const QuadraticPolygon& other) const; + double intersectWith(const QuadraticPolygon& other, double* barycenter) const; std::vector intersectMySelfWith(const QuadraticPolygon& other) const; void intersectForPerimeter(const QuadraticPolygon& other, double& perimeterThisPart, double& perimeterOtherPart, double& perimeterCommonPart) const; void intersectForPerimeterAdvanced(const QuadraticPolygon& other, std::vector< double >& polThis, std::vector< double >& polOther) const;