From 92da77d8da6256ca824faa6bc87cd102a8d4ee17 Mon Sep 17 00:00:00 2001 From: geay Date: Fri, 20 Jun 2014 17:19:30 +0200 Subject: [PATCH] Retrieve refactor from abn/intersect_1D --- .../InterpKernelGeo2DComposedEdge.cxx | 8 ++-- .../InterpKernelGeo2DComposedEdge.hxx | 7 ++- .../InterpKernelGeo2DElementaryEdge.cxx | 5 +- .../InterpKernelGeo2DElementaryEdge.hxx | 2 +- .../InterpKernelGeo2DQuadraticPolygon.cxx | 48 +++++++++---------- .../InterpKernelGeo2DQuadraticPolygon.hxx | 4 +- src/MEDCoupling/MEDCouplingUMesh.cxx | 2 +- 7 files changed, 40 insertions(+), 36 deletions(-) diff --git a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.cxx b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.cxx index e3a738530..3ae85292f 100644 --- a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.cxx +++ b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.cxx @@ -137,17 +137,17 @@ void ComposedEdge::initLocations() const } /** - * Reset the status of all edges (OUT, IN, ON) because they were potentially assignated + * Reset the status of all edges (OUT, IN, ON) because they were potentially assigned * by the previous candidate processing. */ -void ComposedEdge::initLocationsWithOther(const ComposedEdge& other) const +void ComposedEdge::InitLocationsWithOther(const ComposedEdge& first, const ComposedEdge& other) { std::set s1,s2; - for(std::list::const_iterator it1=_sub_edges.begin();it1!=_sub_edges.end();it1++) + for(std::list::const_iterator it1=first._sub_edges.begin();it1!=first._sub_edges.end();it1++) s1.insert((*it1)->getPtr()); for(std::list::const_iterator it2=other._sub_edges.begin();it2!=other._sub_edges.end();it2++) s2.insert((*it2)->getPtr()); - initLocations(); + first.initLocations(); other.initLocations(); std::vector s3; std::set_intersection(s1.begin(),s1.end(),s2.begin(),s2.end(),std::back_insert_iterator< std::vector >(s3)); diff --git a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.hxx b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.hxx index e014d5942..8d815c501 100644 --- a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.hxx +++ b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DComposedEdge.hxx @@ -37,6 +37,11 @@ namespace INTERP_KERNEL class ElementaryEdge; class IteratorOnComposedEdge; + /** + * A set of quadratic or linear edges, described mainly by their connectivity + * The set is assumed to be connected, but not necessarily closed (i.e. not necessarily forming a closed polygon). + * Some methods however requires a closed form. + */ class ComposedEdge { friend class IteratorOnComposedEdge; @@ -51,7 +56,7 @@ namespace INTERP_KERNEL INTERPKERNEL_EXPORT bool presenceOfOn() const; INTERPKERNEL_EXPORT bool presenceOfQuadraticEdge() const; INTERPKERNEL_EXPORT void initLocations() const; - INTERPKERNEL_EXPORT void initLocationsWithOther(const ComposedEdge& other) const; + INTERPKERNEL_EXPORT static void InitLocationsWithOther(const ComposedEdge& first, const ComposedEdge& other); INTERPKERNEL_EXPORT ComposedEdge *clone() const; INTERPKERNEL_EXPORT bool isNodeIn(Node *n) const; INTERPKERNEL_EXPORT double getArea() const; diff --git a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DElementaryEdge.cxx b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DElementaryEdge.cxx index 45088dbef..8bee0e144 100644 --- a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DElementaryEdge.cxx +++ b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DElementaryEdge.cxx @@ -223,10 +223,9 @@ void ElementaryEdge::fillGlobalInfoAbs2(const std::map& edgesThis, std::vector& addCoo, std::map mapAddCoo) const; INTERPKERNEL_EXPORT void fillGlobalInfoAbs2(const std::map& mapThis, const std::map& mapOther, int offset1, int offset2, double fact, double baryX, double baryY, std::vector& edgesOther, std::vector& addCoo, std::map& mapAddCoo) const; - INTERPKERNEL_EXPORT static ElementaryEdge *BuildEdgeFromCrudeDataArray(bool direction, INTERP_KERNEL::Node *start, INTERP_KERNEL::Node *end); + INTERPKERNEL_EXPORT static ElementaryEdge *BuildEdgeFromStartEndDir(bool direction, INTERP_KERNEL::Node *start, INTERP_KERNEL::Node *end); private: bool _direction; Edge *_ptr; diff --git a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DQuadraticPolygon.cxx b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DQuadraticPolygon.cxx index 5df47c7fc..e2cc20288 100644 --- a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DQuadraticPolygon.cxx +++ b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DQuadraticPolygon.cxx @@ -415,7 +415,7 @@ void QuadraticPolygon::appendSubEdgeFromCrudeDataArray(Edge *baseEdge, std::size {//it is not a quadratic subedge Node *start=(*mapp.find(direct?subEdge[2*j]:subEdge[2*nbOfSubEdges-2*j-1])).second; Node *end=(*mapp.find(direct?subEdge[2*j+1]:subEdge[2*nbOfSubEdges-2*j-2])).second; - ElementaryEdge *e=ElementaryEdge::BuildEdgeFromCrudeDataArray(true,start,end); + ElementaryEdge *e=ElementaryEdge::BuildEdgeFromStartEndDir(true,start,end); pushBack(e); } else @@ -530,7 +530,7 @@ void QuadraticPolygon::buildFromCrudeDataArray2(const std::map } /*! - * This method make the hypothesis that 'this' and 'other' are splited at the minimum into edges that are fully IN, OUT or ON. - * This method returns newly created polygons in 'conn' and 'connI' and the corresponding ids ('idThis','idOther') are stored respectively into 'nbThis' and 'nbOther'. - * @param [in,out] edgesThis, parameter that keep informed the caller abount the edges in this not shared by the result of intersection of \a this with \a other - * @param [in,out] edgesBoundaryOther, parameter that strores all edges in result of intersection that are not + * This method make the hypothesis that \a this and \a other are split at the minimum into edges that are fully IN, OUT or ON. + * This method returns newly created polygons in \a conn and \a connI and the corresponding ids ( \a idThis, \a idOther) are stored respectively into \a nbThis and \a nbOther. + * @param [in,out] edgesThis, parameter that keep informed the caller about the edges in this not shared by the result of intersection of \a this with \a other + * @param [in,out] edgesBoundaryOther, parameter that stores all edges in result of intersection that are not */ void QuadraticPolygon::buildPartitionsAbs(QuadraticPolygon& other, std::set& edgesThis, std::set& edgesBoundaryOther, const std::map& mapp, int idThis, int idOther, int offset, std::vector& addCoordsQuadratic, std::vector& conn, std::vector& connI, std::vector& nbThis, std::vector& nbOther) { double xBaryBB, yBaryBB; double fact=normalizeExt(&other, xBaryBB, yBaryBB); - //Locate 'this' relative to 'other' + //Locate \a this relative to \a other (edges of \a this, aka \a pol1 are marked as IN or OUT) other.performLocatingOperationSlow(*this); // without any assumption std::vector res=buildIntersectionPolygons(other,*this); for(std::vector::iterator it=res.begin();it!=res.end();it++) @@ -931,14 +931,14 @@ void QuadraticPolygon::SplitPolygonsEachOther(QuadraticPolygon& pol1, QuadraticP Delete(c2); } -void QuadraticPolygon::performLocatingOperation(QuadraticPolygon& pol2) const +void QuadraticPolygon::performLocatingOperation(QuadraticPolygon& pol1) const { - IteratorOnComposedEdge it(&pol2); + IteratorOnComposedEdge it(&pol1); TypeOfEdgeLocInPolygon loc=FULL_ON_1; for(it.first();!it.finished();it.next()) { ElementaryEdge *cur=it.current(); - loc=cur->locateFullyMySelf(*this,loc); + loc=cur->locateFullyMySelf(*this,loc);//*this=pol2=other } } @@ -953,18 +953,18 @@ void QuadraticPolygon::performLocatingOperationSlow(QuadraticPolygon& pol2) cons } /*! - * Given 2 polygons 'pol1' and 'pol2' (localized) the resulting polygons are returned. + * Given 2 polygons \a pol1 and \a pol2 (localized) the resulting polygons are returned. * * this : pol2 simplified. - * @param pol1 pol1 split. - * @param pol2 pol2 split. + * @param [in] pol1 pol1 split. + * @param [in] pol2 pol2 split. */ std::vector QuadraticPolygon::buildIntersectionPolygons(const QuadraticPolygon& pol1, const QuadraticPolygon& pol2) const { std::vector ret; std::list pol2Zip=pol2.zipConsecutiveInSegments(); if(!pol2Zip.empty()) - closePolygons(pol2Zip,pol1,ret); + ClosePolygons(pol2Zip,pol1,*this,ret); else {//borders of pol2 do not cross pol1,and pol2 borders are outside of pol1. That is to say, either pol2 and pol1 //do not overlap or pol1 is fully inside pol2. So in the first case no intersection, in the other case @@ -1015,13 +1015,13 @@ std::list QuadraticPolygon::zipConsecutiveInSegments() const } /*! - * 'this' should be considered as pol2Simplified. - * @param pol2zip is a list of set of edges (openned polygon) coming from split polygon 2. - * @param pol1 is split pol1. - * @param results the resulting \b CLOSED polygons. + * @param [in] pol2zip is a list of set of edges (=an opened polygon) coming from split polygon 2. + * @param [in] pol1 is split pol1. + * @param [in] pol2 should be considered as pol2Simplified. + * @param [out] results the resulting \b CLOSED polygons. */ -void QuadraticPolygon::closePolygons(std::list& pol2Zip, const QuadraticPolygon& pol1, - std::vector& results) const +void QuadraticPolygon::ClosePolygons(std::list& pol2Zip, const QuadraticPolygon& pol1, const QuadraticPolygon& pol2, + std::vector& results) { bool directionKnownInPol1=false; bool directionInPol1; @@ -1036,7 +1036,7 @@ void QuadraticPolygon::closePolygons(std::list& pol2Zip, con } if(!directionKnownInPol1) { - if(!(*iter)->amIAChanceToBeCompletedBy(pol1,*this,directionInPol1)) + if(!(*iter)->haveIAChanceToBeCompletedBy(pol1,pol2,directionInPol1)) { delete *iter; iter=pol2Zip.erase(iter); continue; } else directionKnownInPol1=true; @@ -1055,7 +1055,7 @@ void QuadraticPolygon::closePolygons(std::list& pol2Zip, con /*! * 'this' is expected to be set of edges (not closed) of pol2 split. */ -bool QuadraticPolygon::amIAChanceToBeCompletedBy(const QuadraticPolygon& pol1Splitted,const QuadraticPolygon& pol2NotSplitted, bool& direction) +bool QuadraticPolygon::haveIAChanceToBeCompletedBy(const QuadraticPolygon& pol1Splitted,const QuadraticPolygon& pol2NotSplitted, bool& direction) { IteratorOnComposedEdge it(const_cast(&pol1Splitted)); bool found=false; @@ -1069,7 +1069,7 @@ bool QuadraticPolygon::amIAChanceToBeCompletedBy(const QuadraticPolygon& pol1Spl it.next(); } if(!found) - throw Exception("Internal error : polygons uncompatible each others. Should never happend"); + throw Exception("Internal error: polygons incompatible with each others. Should never happen!"); //Ok we found correspondance between this and pol1. Searching for right direction to close polygon. ElementaryEdge *e=_sub_edges.back(); if(e->getLoc()==FULL_ON_1) @@ -1099,7 +1099,7 @@ bool QuadraticPolygon::amIAChanceToBeCompletedBy(const QuadraticPolygon& pol1Spl } /*! - * This method fills as much as possible 'this' (part of pol2 split) with edges of 'pol1Splitted'. + * This method fills as much as possible \a this (a sub-part of pol2 split) with edges of \a pol1Splitted. */ std::list::iterator QuadraticPolygon::fillAsMuchAsPossibleWith(const QuadraticPolygon& pol1Splitted, std::list::iterator iStart, diff --git a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DQuadraticPolygon.hxx b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DQuadraticPolygon.hxx index 670ac6745..99a33fefe 100644 --- a/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DQuadraticPolygon.hxx +++ b/src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DQuadraticPolygon.hxx @@ -90,13 +90,13 @@ namespace INTERP_KERNEL INTERPKERNEL_EXPORT void performLocatingOperationSlow(QuadraticPolygon& pol2) const; INTERPKERNEL_EXPORT static void SplitPolygonsEachOther(QuadraticPolygon& pol1, QuadraticPolygon& pol2, int& nbOfSplits); INTERPKERNEL_EXPORT std::vector buildIntersectionPolygons(const QuadraticPolygon& pol1, const QuadraticPolygon& pol2) const; - INTERPKERNEL_EXPORT bool amIAChanceToBeCompletedBy(const QuadraticPolygon& pol1Splitted, const QuadraticPolygon& pol2NotSplitted, bool& direction); + INTERPKERNEL_EXPORT bool haveIAChanceToBeCompletedBy(const QuadraticPolygon& pol1Splitted, const QuadraticPolygon& pol2NotSplitted, bool& direction); INTERPKERNEL_EXPORT static void ComputeResidual(const QuadraticPolygon& pol1, const std::set& notUsedInPol1, const std::set& edgesInPol2OnBoundary, const std::map& mapp, int offset, int idThis, std::vector& addCoordsQuadratic, std::vector& conn, std::vector& connI, std::vector& nb1, std::vector& nb2); protected: std::list zipConsecutiveInSegments() const; void dumpInXfigFile(std::ostream& stream, int resolution, const Bounds& box) const; - void closePolygons(std::list& pol2Zip, const QuadraticPolygon& pol1, std::vector& results) const; + static void ClosePolygons(std::list& pol2Zip, const QuadraticPolygon& pol1, const QuadraticPolygon& pol2, std::vector& results); template static void UpdateNeighbours(const MergePoints& merger, IteratorOnComposedEdge it1, IteratorOnComposedEdge it2, const EDGES *e1, const EDGES *e2); diff --git a/src/MEDCoupling/MEDCouplingUMesh.cxx b/src/MEDCoupling/MEDCouplingUMesh.cxx index be6bac00e..c5205445f 100644 --- a/src/MEDCoupling/MEDCouplingUMesh.cxx +++ b/src/MEDCoupling/MEDCouplingUMesh.cxx @@ -8820,7 +8820,7 @@ void MEDCouplingUMesh::BuildIntersecting2DCellsFromEdges(double eps, const MEDCo ii=0; for(std::vector::const_iterator it2=candidates2.begin();it2!=candidates2.end();it2++,ii++) { - pol1.initLocationsWithOther(pol2s[ii]); + INTERP_KERNEL::ComposedEdge::InitLocationsWithOther(pol1,pol2s[ii]); pol2s[ii].updateLocOfEdgeFromCrudeDataArray2(desc2+descIndx2[*it2],desc2+descIndx2[*it2+1],intesctEdges2,pol1,desc1+descIndx1[i],desc1+descIndx1[i+1],intesctEdges1,colinear2); //MEDCouplingUMeshAssignOnLoc(pol1,pol2,desc1+descIndx1[i],desc1+descIndx1[i+1],intesctEdges1,desc2+descIndx2[*it2],desc2+descIndx2[*it2+1],intesctEdges2,colinear2); pol1.buildPartitionsAbs(pol2s[ii],edges1,edgesBoundary2,mapp,i,*it2,offset3,addCoordsQuadratic,cr,crI,cNb1,cNb2); -- 2.39.2