Salome HOME
d997fa7be7500ce103d7277fb0ded05135c501c9
[tools/medcoupling.git] / src / INTERP_KERNEL / Geometric2DIntersector.txx
1 //  Copyright (C) 2007-2008  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 #ifndef __GEOMETRIC2DINTERSECTOR_TXX__
20 #define __GEOMETRIC2DINTERSECTOR_TXX__
21
22 #include "Geometric2DIntersector.hxx"
23 #include "PlanarIntersectorP0P0.txx"
24 #include "PlanarIntersectorP0P1.txx"
25 #include "PlanarIntersectorP1P0.txx"
26 #include "CellModel.hxx"
27
28 #include "QuadraticPolygon.hxx"
29 #include "EdgeArcCircle.hxx"
30 #include "EdgeLin.hxx"
31 #include "Node.hxx"
32
33 namespace INTERP_KERNEL
34 {
35   template<class MyMeshType, class MyMatrix, template <class MeshType, class TheMatrix, class ThisIntersector> class InterpType>
36   Geometric2DIntersector<MyMeshType,MyMatrix,InterpType>::Geometric2DIntersector(const MyMeshType& meshT, const MyMeshType& meshS,
37                                                                           double dimCaracteristic, double medianPlane, double precision, int orientation):
38     InterpType<MyMeshType,MyMatrix,Geometric2DIntersector<MyMeshType,MyMatrix,InterpType> >(meshT,meshS,dimCaracteristic, precision, medianPlane, true, orientation, 0)
39   {
40     QUADRATIC_PLANAR::_precision=dimCaracteristic*precision;
41   }
42   
43   template<class MyMeshType, class MyMatrix, template <class MeshType, class TheMatrix, class ThisIntersector> class InterpType>
44   double Geometric2DIntersector<MyMeshType,MyMatrix,InterpType>::intersectGeometry(ConnType icellT, ConnType icellS, ConnType nbNodesT, ConnType nbNodesS)
45   {
46     int orientation = 1;
47     std::vector<double> CoordsT;
48     std::vector<double> CoordsS;
49     PlanarIntersector<MyMeshType,MyMatrix>::getRealCoordinates(icellT,icellS,nbNodesT,nbNodesS,CoordsT,CoordsS,orientation);
50     NormalizedCellType tT=PlanarIntersector<MyMeshType,MyMatrix>::_meshT.getTypeOfElement(icellT);
51     NormalizedCellType tS=PlanarIntersector<MyMeshType,MyMatrix>::_meshS.getTypeOfElement(icellS);
52     QuadraticPolygon *p1=buildPolygonFrom(CoordsT,tT);
53     QuadraticPolygon *p2=buildPolygonFrom(CoordsS,tS);
54     double ret=p1->intersectWith(*p2);
55     delete p1; delete p2;
56     return ret;
57   }
58
59   template<class MyMeshType, class MyMatrix, template <class MeshType, class TheMatrix, class ThisIntersector> class InterpType>
60   double Geometric2DIntersector<MyMeshType,MyMatrix,InterpType>::intersectGeometryWithQuadrangle(const double *quadrangle, const std::vector<double>& sourceCoords, bool isSourceQuad)
61   {
62     std::vector<Node *> nodes(4);
63     nodes[0]=new Node(quadrangle[0],quadrangle[1]);
64     nodes[1]=new Node(quadrangle[SPACEDIM],quadrangle[SPACEDIM+1]);
65     nodes[2]=new Node(quadrangle[2*SPACEDIM],quadrangle[2*SPACEDIM+1]);
66     nodes[3]=new Node(quadrangle[3*SPACEDIM],quadrangle[3*SPACEDIM+1]);
67     int nbOfSourceNodes=sourceCoords.size()/SPACEDIM;
68     std::vector<Node *> nodes2(nbOfSourceNodes);
69     for(int i=0;i<nbOfSourceNodes;i++)
70       nodes2[i]=new Node(sourceCoords[i*SPACEDIM],sourceCoords[i*SPACEDIM+1]);
71     QuadraticPolygon *p1=QuadraticPolygon::buildLinearPolygon(nodes);
72     QuadraticPolygon *p2;
73     if(!isSourceQuad)
74       p2=QuadraticPolygon::buildLinearPolygon(nodes2);
75     else
76       p2=QuadraticPolygon::buildArcCirclePolygon(nodes2);
77     double ret=p1->intersectWith(*p2);
78     delete p1; delete p2;
79     return ret;
80   }
81
82   template<class MyMeshType, class MyMatrix, template <class MeshType, class TheMatrix, class ThisIntersector> class InterpType>
83   QuadraticPolygon *Geometric2DIntersector<MyMeshType,MyMatrix,InterpType>::buildPolygonFrom(const std::vector<double>& coords, NormalizedCellType type)
84   {
85     int nbNodes=coords.size()/SPACEDIM;
86     std::vector<Node *> nodes(nbNodes);
87     for(int i=0;i<nbNodes;i++)
88       nodes[i]=new Node(coords[i*SPACEDIM],coords[i*SPACEDIM+1]);
89     if(!CellModel::getCellModel(type).isQuadratic())
90       return QuadraticPolygon::buildLinearPolygon(nodes);
91     else
92       return QuadraticPolygon::buildArcCirclePolygon(nodes);
93   }
94
95   template<class MyMeshType, class MyMatrix, template <class MeshType, class TheMatrix, class ThisIntersector> class InterpType>
96   QuadraticPolygon *Geometric2DIntersector<MyMeshType,MyMatrix,InterpType>::buildPolygonAFrom(ConnType cell, int nbOfPoints, NormalizedCellType type)
97   {
98     const ConnType *startOfCellNodeConn=PlanarIntersector<MyMeshType,MyMatrix>::_connectT+OTT<ConnType,numPol>::conn2C(PlanarIntersector<MyMeshType,MyMatrix>::_connIndexT[OTT<ConnType,numPol>::ind2C(cell)]);
99     std::vector<Node *> nodes(nbOfPoints);
100     for(int i=0;i<nbOfPoints;i++)
101       nodes[i]=new Node(PlanarIntersector<MyMeshType,MyMatrix>::_coordsT+OTT<ConnType,numPol>::coo2C(startOfCellNodeConn[i])*SPACEDIM);
102     if(CellModel::getCellModel(type).isQuadratic())
103       return QuadraticPolygon::buildLinearPolygon(nodes);
104     else
105       return QuadraticPolygon::buildArcCirclePolygon(nodes);
106   }
107
108   template<class MyMeshType, class MyMatrix, template <class MeshType, class TheMatrix, class ThisIntersector> class InterpType>
109   QuadraticPolygon *Geometric2DIntersector<MyMeshType,MyMatrix,InterpType>::buildPolygonBFrom(ConnType cell, int nbOfPoints, NormalizedCellType type)
110   {
111     const ConnType *startOfCellNodeConn=PlanarIntersector<MyMeshType,MyMatrix>::_connectS+OTT<ConnType,numPol>::conn2C(PlanarIntersector<MyMeshType,MyMatrix>::_connIndexS[OTT<ConnType,numPol>::ind2C(cell)]);
112     std::vector<Node *> nodes(nbOfPoints);
113     for(int i=0;i<nbOfPoints;i++)
114       nodes[i]=new Node(PlanarIntersector<MyMeshType,MyMatrix>::_coordsS+OTT<ConnType,numPol>::coo2C(startOfCellNodeConn[i])*SPACEDIM);
115     if(type!=NORM_TRI6 && type!=NORM_QUAD8)
116       return QuadraticPolygon::buildLinearPolygon(nodes);
117     else
118       return QuadraticPolygon::buildArcCirclePolygon(nodes);
119   }
120 }
121
122 #endif