Salome HOME
0f83435c61b41dd67ee77e4b6b056fa381d6e996
[tools/medcoupling.git] / src / INTERP_KERNEL / PointLocator2DIntersector.txx
1 // Copyright (C) 2007-2015  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, or (at your option) any later version.
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 // Author : Anthony Geay (CEA/DEN)
20 #ifndef __POINTLOCATORINTERSECTOR_TXX__
21 #define __POINTLOCATORINTERSECTOR_TXX__
22
23 #include "PointLocator2DIntersector.hxx"
24 #include "PlanarIntersectorP0P0.txx"
25 #include "PlanarIntersectorP0P1.txx"
26 #include "PlanarIntersectorP1P0.txx"
27 #include "PlanarIntersectorP1P1.txx"
28 #include "PlanarIntersectorP1P0Bary.txx"
29 #include "CellModel.hxx"
30
31 #include "InterpKernelGeo2DQuadraticPolygon.hxx"
32 #include "PointLocatorAlgos.txx"
33
34 #define PTLOC2D_INTERSECTOR PointLocator2DIntersector<MyMeshType,MyMatrix,InterpType>
35 #define INTERSECTOR_TEMPLATE template<class MyMeshType, class MyMatrix, template <class MeshType, class TheMatrix, class ThisIntersector> class InterpType>
36
37 namespace INTERP_KERNEL
38 {
39   INTERSECTOR_TEMPLATE
40   PTLOC2D_INTERSECTOR::PointLocator2DIntersector(const MyMeshType& meshT, const MyMeshType& meshS,
41                                                double dimCaracteristic, double md3DSurf, double minDot3DSurf, double medianPlane,
42                                                double precision, int orientation):
43     InterpType<MyMeshType,MyMatrix,PTLOC2D_INTERSECTOR >(meshT,meshS,dimCaracteristic, precision, md3DSurf, minDot3DSurf, medianPlane, true, orientation, 0)
44   {
45   }
46   
47   INTERSECTOR_TEMPLATE
48   double PTLOC2D_INTERSECTOR::intersectGeometry(ConnType icellT,   ConnType icellS,
49                                                 ConnType nbNodesT, ConnType nbNodesS)
50   {
51     int orientation = 1;
52     std::vector<double> CoordsT;
53     std::vector<double> CoordsS;
54     PlanarIntersector<MyMeshType,MyMatrix>::getRealCoordinates(icellT,icellS,nbNodesT,nbNodesS,CoordsT,CoordsS,orientation);
55     NormalizedCellType tT=PlanarIntersector<MyMeshType,MyMatrix>::_meshT.getTypeOfElement(icellT);
56     QuadraticPolygon *pT=buildPolygonFrom(CoordsT,tT);
57     double baryT[SPACEDIM];
58     pT->getBarycenterGeneral(baryT);
59     delete pT;
60     if(PointLocatorAlgos<MyMeshType>::isElementContainsPointAlg2D(baryT,&CoordsS[0],nbNodesS,InterpType<MyMeshType,MyMatrix,PTLOC2D_INTERSECTOR >::_precision))
61       return 1.;
62     return 0.;
63   }
64
65   INTERSECTOR_TEMPLATE
66   double PTLOC2D_INTERSECTOR::intersectGeometryWithQuadrangle(const double             * quadrangle,
67                                                               const std::vector<double>& sourceCoords,
68                                                               bool                       isSourceQuad)
69   {
70     int nbOfSourceNodes=sourceCoords.size()/SPACEDIM;
71     std::vector<Node *> nodes2(nbOfSourceNodes);
72     for(int i=0;i<nbOfSourceNodes;i++)
73       nodes2[i]=new Node(sourceCoords[i*SPACEDIM],sourceCoords[i*SPACEDIM+1]);
74     QuadraticPolygon *p2;
75     if(!isSourceQuad)
76       p2=QuadraticPolygon::BuildLinearPolygon(nodes2);
77     else
78       p2=QuadraticPolygon::BuildArcCirclePolygon(nodes2);
79     double bary[SPACEDIM];
80     p2->getBarycenter(bary);
81     delete p2;
82     if( PointLocatorAlgos<MyMeshType>::isElementContainsPointAlg2D(bary,quadrangle,4) )
83       return 1.;
84     return 0.;
85   }
86
87   INTERSECTOR_TEMPLATE
88   double PTLOC2D_INTERSECTOR::intersectGeometryGeneral(const std::vector<double>& targetCoords,
89                                                        const std::vector<double>& sourceCoords)
90   {
91     int nbOfTargetNodes=targetCoords.size()/SPACEDIM;
92     int nbOfSourceNodes=sourceCoords.size()/SPACEDIM;
93     std::vector<Node *> nodes2(nbOfSourceNodes);
94     for(int i=0;i<nbOfSourceNodes;i++)
95       nodes2[i]=new Node(sourceCoords[i*SPACEDIM],sourceCoords[i*SPACEDIM+1]);
96     QuadraticPolygon *p=QuadraticPolygon::BuildLinearPolygon(nodes2);
97     double bary[SPACEDIM];
98     p->getBarycenterGeneral(bary);
99     delete p;
100     if( PointLocatorAlgos<MyMeshType>::isElementContainsPointAlg2D(bary,&targetCoords[0],nbOfTargetNodes) )
101       return 1.;
102     return 0.;
103   }
104
105   //================================================================================
106   /*!
107    * \brief Intersect a triangle and a polygon for P1P0 barycentric algorithm
108    *  \param targetCell - list of coordinates of target polygon in full interlace
109    *  \param targetCellQuadratic - specifies if target polygon is quadratic or not
110    *  \param sourceTria - list of coordinates of source triangle
111    *  \param res - coefficients a,b and c associated to nodes of sourceTria
112    */
113   //================================================================================
114
115   INTERSECTOR_TEMPLATE
116   double PTLOC2D_INTERSECTOR::intersectGeoBary(const std::vector<double>& targetCell,
117                                                bool                       targetCellQuadratic,
118                                                const double *             sourceTria,
119                                                std::vector<double>&       res)
120   {
121     throw INTERP_KERNEL::Exception("intersectGeoBary incompatible with PointLocator. Desactivate P1P0Bary to avoid the problem");
122     return 0.;
123   }
124
125   INTERSECTOR_TEMPLATE
126   QuadraticPolygon *PTLOC2D_INTERSECTOR::buildPolygonFrom(const std::vector<double>& coords, NormalizedCellType type)
127   {
128     int nbNodes=coords.size()/SPACEDIM;
129     std::vector<Node *> nodes(nbNodes);
130     for(int i=0;i<nbNodes;i++)
131       nodes[i]=new Node(coords[i*SPACEDIM],coords[i*SPACEDIM+1]);
132     if(!CellModel::GetCellModel(type).isQuadratic())
133       return QuadraticPolygon::BuildLinearPolygon(nodes);
134     else
135       return QuadraticPolygon::BuildArcCirclePolygon(nodes);
136   }
137
138   INTERSECTOR_TEMPLATE
139   QuadraticPolygon *PTLOC2D_INTERSECTOR::buildPolygonAFrom(ConnType cell, int nbOfPoints, NormalizedCellType type)
140   {
141     const ConnType *startOfCellNodeConn=PlanarIntersector<MyMeshType,MyMatrix>::_connectT+OTT<ConnType,numPol>::conn2C(PlanarIntersector<MyMeshType,MyMatrix>::_connIndexT[OTT<ConnType,numPol>::ind2C(cell)]);
142     std::vector<Node *> nodes(nbOfPoints);
143     for(int i=0;i<nbOfPoints;i++)
144       nodes[i]=new Node(PlanarIntersector<MyMeshType,MyMatrix>::_coordsT+OTT<ConnType,numPol>::coo2C(startOfCellNodeConn[i])*SPACEDIM);
145     if(CellModel::GetCellModel(type).isQuadratic())
146       return QuadraticPolygon::BuildLinearPolygon(nodes);
147     else
148       return QuadraticPolygon::BuildArcCirclePolygon(nodes);
149   }
150
151   INTERSECTOR_TEMPLATE
152   QuadraticPolygon *PTLOC2D_INTERSECTOR::buildPolygonBFrom(ConnType cell, int nbOfPoints, NormalizedCellType type)
153   {
154     const ConnType *startOfCellNodeConn=PlanarIntersector<MyMeshType,MyMatrix>::_connectS+OTT<ConnType,numPol>::conn2C(PlanarIntersector<MyMeshType,MyMatrix>::_connIndexS[OTT<ConnType,numPol>::ind2C(cell)]);
155     std::vector<Node *> nodes(nbOfPoints);
156     for(int i=0;i<nbOfPoints;i++)
157       nodes[i]=new Node(PlanarIntersector<MyMeshType,MyMatrix>::_coordsS+OTT<ConnType,numPol>::coo2C(startOfCellNodeConn[i])*SPACEDIM);
158     if(type!=NORM_TRI6 && type!=NORM_QUAD8)
159       return QuadraticPolygon::BuildLinearPolygon(nodes);
160     else
161       return QuadraticPolygon::BuildArcCirclePolygon(nodes);
162   }
163 }
164
165 #endif