Back to index

salome-med  6.5.0
InterpKernelGeo2DQuadraticPolygon.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #ifndef __INTERPKERNELGEO2DQUADRATICPOLYGON_HXX__
00021 #define __INTERPKERNELGEO2DQUADRATICPOLYGON_HXX__
00022 
00023 #include "INTERPKERNELDefines.hxx"
00024 
00025 #include "InterpKernelGeo2DComposedEdge.hxx"
00026 #include "InterpKernelGeo2DAbstractEdge.hxx"
00027 #include "InterpKernelGeo2DElementaryEdge.hxx"
00028 
00029 #include <list>
00030 #include <vector>
00031 
00032 namespace INTERP_KERNEL
00033 {
00034   class Edge;
00035   class MergePoints;
00036 
00037   class INTERPKERNEL_EXPORT QuadraticPolygon : public ComposedEdge
00038   {
00039   public:
00040     QuadraticPolygon() { }
00041     QuadraticPolygon(const QuadraticPolygon& other):ComposedEdge(other) { }
00042     QuadraticPolygon(const char *fileName);
00043     static QuadraticPolygon *BuildLinearPolygon(std::vector<Node *>& nodes);
00044     static QuadraticPolygon *BuildArcCirclePolygon(std::vector<Node *>& nodes);
00045     static void BuildDbgFile(const std::vector<Node *>& nodes, const char *fileName);
00046     ~QuadraticPolygon();
00047     void closeMe() const;
00048     void circularPermute();
00049     bool isButterflyAbs();
00050     bool isButterfly() const;
00051     void dumpInXfigFile(const char *fileName) const;
00052     void dumpInXfigFileWithOther(const ComposedEdge& other, const char *fileName) const;
00054     double intersectWithAbs(QuadraticPolygon& other);
00055     double intersectWithAbs1D(QuadraticPolygon& other, bool& isColinear);
00057     double intersectWithAbs(QuadraticPolygon& other, double* barycenter);
00058     void splitAbs(QuadraticPolygon& other, const std::map<INTERP_KERNEL::Node *,int>& mapThis, const std::map<INTERP_KERNEL::Node *,int>& mapOther, int offset1, int offset2, const std::vector<int>& otherEdgeIds,
00059                   std::vector<int>& edgesThis, int cellIdThis, std::vector< std::vector<int> >& edgesInOtherColinearWithThis, std::vector< std::vector<int> >& subDivOther, std::vector<double>& addCoo);
00060     void buildFromCrudeDataArray(const std::map<int,INTERP_KERNEL::Node *>& mapp, bool isQuad, const int *nodalBg, const double *coords,
00061                                  const int *descBg, const int *descEnd, const std::vector<std::vector<int> >& intersectEdges);
00062     void buildFromCrudeDataArray2(const std::map<int,INTERP_KERNEL::Node *>& mapp, bool isQuad, const int *nodalBg, const double *coords, const int *descBg, const int *descEnd, const std::vector<std::vector<int> >& intersectEdges,
00063                                   const INTERP_KERNEL::QuadraticPolygon& pol1, const int *descBg1, const int *descEnd1, const std::vector<std::vector<int> >& intersectEdges1,
00064                                   const std::vector< std::vector<int> >& colinear1);
00065     void appendEdgeFromCrudeDataArray(std::size_t edgeId, const std::map<int,INTERP_KERNEL::Node *>& mapp, bool isQuad, const int *nodalBg, const double *coords,
00066                                       const int *descBg,  const int *descEnd, const std::vector<std::vector<int> >& intersectEdges);
00067     void appendSubEdgeFromCrudeDataArray(Edge *baseEdge, std::size_t j, bool direct, int edgeId, const std::vector<int>& subEdge, const std::map<int,INTERP_KERNEL::Node *>& mapp);
00068     void appendCrudeData(const std::map<INTERP_KERNEL::Node *,int>& mapp, double xBary, double yBary, double fact, int offset, std::vector<double>& addCoordsQuadratic, std::vector<int>& conn, std::vector<int>& connI) const;
00069     void buildPartitionsAbs(QuadraticPolygon& other, const std::map<INTERP_KERNEL::Node *,int>& mapp, int idThis, int idOther, int offset,
00070                             std::vector<double>& addCoordsQuadratic, std::vector<int>& conn, std::vector<int>& connI, std::vector<int>& nb1, std::vector<int>& nb2);
00071     //
00072     double intersectWith(const QuadraticPolygon& other) const;
00073     double intersectWith(const QuadraticPolygon& other, double* barycenter) const;
00074     std::vector<QuadraticPolygon *> intersectMySelfWith(const QuadraticPolygon& other) const;
00075     void intersectForPerimeter(const QuadraticPolygon& other, double& perimeterThisPart, double& perimeterOtherPart, double& perimeterCommonPart) const;
00076     void intersectForPerimeterAdvanced(const QuadraticPolygon& other, std::vector< double >& polThis, std::vector< double >& polOther) const;
00077     void intersectForPoint(const QuadraticPolygon& other, std::vector< int >& numberOfCreatedPointsPerEdge) const;
00078   public://Only public for tests reasons
00079     void performLocatingOperation(QuadraticPolygon& pol2) const;
00080     static void SplitPolygonsEachOther(QuadraticPolygon& pol1, QuadraticPolygon& pol2, int& nbOfSplits);
00081     std::vector<QuadraticPolygon *> buildIntersectionPolygons(const QuadraticPolygon& pol1, const QuadraticPolygon& pol2) const;
00082     bool amIAChanceToBeCompletedBy(const QuadraticPolygon& pol1Splitted, const QuadraticPolygon& pol2NotSplitted, bool& direction);
00083   protected:
00084     std::list<QuadraticPolygon *> zipConsecutiveInSegments() const;
00085     void dumpInXfigFile(std::ostream& stream, int resolution, const Bounds& box) const;
00086     void closePolygons(std::list<QuadraticPolygon *>& pol2Zip, const QuadraticPolygon& pol1, std::vector<QuadraticPolygon *>& results) const;
00087     template<class EDGES>
00088     static void UpdateNeighbours(const MergePoints& merger, IteratorOnComposedEdge it1, IteratorOnComposedEdge it2,
00089                                  const EDGES *e1, const EDGES *e2);
00090     std::list<QuadraticPolygon *>::iterator fillAsMuchAsPossibleWith(const QuadraticPolygon& pol1Splitted,
00091                                                                      std::list<QuadraticPolygon *>::iterator iStart,
00092                                                                      std::list<QuadraticPolygon *>::iterator iEnd,
00093                                                                      bool direction);
00094     static std::list<QuadraticPolygon *>::iterator CheckInList(Node *n, std::list<QuadraticPolygon *>::iterator iStart,
00095                                                                std::list<QuadraticPolygon *>::iterator iEnd);
00096   };
00097 }
00098 
00099 namespace INTERP_KERNEL
00100 {
00101   template<class EDGES>
00102   void QuadraticPolygon::UpdateNeighbours(const MergePoints& merger, IteratorOnComposedEdge it1, IteratorOnComposedEdge it2,
00103                                           const EDGES *e1, const EDGES *e2)
00104   {
00105     it1.previousLoop(); it2.previousLoop();
00106     ElementaryEdge *curE1=it1.current(); ElementaryEdge *curE2=it2.current();
00107     curE1->changeEndNodeWith(e1->getStartNode()); curE2->changeEndNodeWith(e2->getStartNode());
00108     it1.nextLoop(); it1.nextLoop(); it2.nextLoop(); it2.nextLoop();
00109     curE1->changeStartNodeWith(e1->getEndNode()); curE2->changeStartNodeWith(e2->getEndNode());
00110   }
00111 }
00112 
00113 #endif