Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/med.git] / src / INTERP_KERNEL / Geometric2D / InterpKernelGeo2DQuadraticPolygon.hxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef __INTERPKERNELGEO2DQUADRATICPOLYGON_HXX__
21 #define __INTERPKERNELGEO2DQUADRATICPOLYGON_HXX__
22
23 #include "INTERPKERNELDefines.hxx"
24
25 #include "InterpKernelGeo2DComposedEdge.hxx"
26 #include "InterpKernelGeo2DAbstractEdge.hxx"
27 #include "InterpKernelGeo2DElementaryEdge.hxx"
28
29 #include <list>
30 #include <vector>
31
32 namespace INTERP_KERNEL
33 {
34   class Edge;
35   class MergePoints;
36
37   class INTERPKERNEL_EXPORT QuadraticPolygon : public ComposedEdge
38   {
39   public:
40     QuadraticPolygon() { }
41     QuadraticPolygon(const QuadraticPolygon& other):ComposedEdge(other) { }
42     QuadraticPolygon(const char *fileName);
43     static QuadraticPolygon *BuildLinearPolygon(std::vector<Node *>& nodes);
44     static QuadraticPolygon *BuildArcCirclePolygon(std::vector<Node *>& nodes);
45     static void BuildDbgFile(const std::vector<Node *>& nodes, const char *fileName);
46     ~QuadraticPolygon();
47     void closeMe() const;
48     void circularPermute();
49     bool isButterflyAbs();
50     bool isButterfly() const;
51     void dumpInXfigFile(const char *fileName) const;
52     void dumpInXfigFileWithOther(const ComposedEdge& other, const char *fileName) const;
53     //! Before intersecting as intersectWith a normalization is done.
54     double intersectWithAbs(QuadraticPolygon& other);
55     double intersectWithAbs1D(QuadraticPolygon& other, bool& isColinear);
56     //! Before intersecting as intersectWith a normalization is done.
57     double intersectWithAbs(QuadraticPolygon& other, double* barycenter);
58     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,
59                   std::vector<int>& edgesThis, int cellIdThis, std::vector< std::vector<int> >& edgesInOtherColinearWithThis, std::vector< std::vector<int> >& subDivOther, std::vector<double>& addCoo);
60     void buildFromCrudeDataArray(const std::map<int,INTERP_KERNEL::Node *>& mapp, bool isQuad, const int *nodalBg, const double *coords,
61                                  const int *descBg, const int *descEnd, const std::vector<std::vector<int> >& intersectEdges);
62     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,
63                                   const INTERP_KERNEL::QuadraticPolygon& pol1, const int *descBg1, const int *descEnd1, const std::vector<std::vector<int> >& intersectEdges1,
64                                   const std::vector< std::vector<int> >& colinear1);
65     void appendEdgeFromCrudeDataArray(std::size_t edgeId, const std::map<int,INTERP_KERNEL::Node *>& mapp, bool isQuad, const int *nodalBg, const double *coords,
66                                       const int *descBg,  const int *descEnd, const std::vector<std::vector<int> >& intersectEdges);
67     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);
68     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;
69     void buildPartitionsAbs(QuadraticPolygon& other, const std::map<INTERP_KERNEL::Node *,int>& mapp, int idThis, int idOther, int offset,
70                             std::vector<double>& addCoordsQuadratic, std::vector<int>& conn, std::vector<int>& connI, std::vector<int>& nb1, std::vector<int>& nb2);
71     //
72     double intersectWith(const QuadraticPolygon& other) const;
73     double intersectWith(const QuadraticPolygon& other, double* barycenter) const;
74     std::vector<QuadraticPolygon *> intersectMySelfWith(const QuadraticPolygon& other) const;
75     void intersectForPerimeter(const QuadraticPolygon& other, double& perimeterThisPart, double& perimeterOtherPart, double& perimeterCommonPart) const;
76     void intersectForPerimeterAdvanced(const QuadraticPolygon& other, std::vector< double >& polThis, std::vector< double >& polOther) const;
77     void intersectForPoint(const QuadraticPolygon& other, std::vector< int >& numberOfCreatedPointsPerEdge) const;
78   public://Only public for tests reasons
79     void performLocatingOperation(QuadraticPolygon& pol2) const;
80     static void SplitPolygonsEachOther(QuadraticPolygon& pol1, QuadraticPolygon& pol2, int& nbOfSplits);
81     std::vector<QuadraticPolygon *> buildIntersectionPolygons(const QuadraticPolygon& pol1, const QuadraticPolygon& pol2) const;
82     bool amIAChanceToBeCompletedBy(const QuadraticPolygon& pol1Splitted, const QuadraticPolygon& pol2NotSplitted, bool& direction);
83   protected:
84     std::list<QuadraticPolygon *> zipConsecutiveInSegments() const;
85     void dumpInXfigFile(std::ostream& stream, int resolution, const Bounds& box) const;
86     void closePolygons(std::list<QuadraticPolygon *>& pol2Zip, const QuadraticPolygon& pol1, std::vector<QuadraticPolygon *>& results) const;
87     template<class EDGES>
88     static void UpdateNeighbours(const MergePoints& merger, IteratorOnComposedEdge it1, IteratorOnComposedEdge it2,
89                                  const EDGES *e1, const EDGES *e2);
90     std::list<QuadraticPolygon *>::iterator fillAsMuchAsPossibleWith(const QuadraticPolygon& pol1Splitted,
91                                                                      std::list<QuadraticPolygon *>::iterator iStart,
92                                                                      std::list<QuadraticPolygon *>::iterator iEnd,
93                                                                      bool direction);
94     static std::list<QuadraticPolygon *>::iterator CheckInList(Node *n, std::list<QuadraticPolygon *>::iterator iStart,
95                                                                std::list<QuadraticPolygon *>::iterator iEnd);
96   };
97 }
98
99 namespace INTERP_KERNEL
100 {
101   template<class EDGES>
102   void QuadraticPolygon::UpdateNeighbours(const MergePoints& merger, IteratorOnComposedEdge it1, IteratorOnComposedEdge it2,
103                                           const EDGES *e1, const EDGES *e2)
104   {
105     it1.previousLoop(); it2.previousLoop();
106     ElementaryEdge *curE1=it1.current(); ElementaryEdge *curE2=it2.current();
107     curE1->changeEndNodeWith(e1->getStartNode()); curE2->changeEndNodeWith(e2->getStartNode());
108     it1.nextLoop(); it1.nextLoop(); it2.nextLoop(); it2.nextLoop();
109     curE1->changeStartNodeWith(e1->getEndNode()); curE2->changeStartNodeWith(e2->getEndNode());
110   }
111 }
112
113 #endif