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