1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
20 #ifndef __POINTLOCATORINTERSECTOR_TXX__
21 #define __POINTLOCATORINTERSECTOR_TXX__
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"
31 #include "InterpKernelGeo2DQuadraticPolygon.hxx"
32 #include "PointLocatorAlgos.txx"
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>
37 namespace INTERP_KERNEL
40 PTLOC2D_INTERSECTOR::PointLocator2DIntersector(const MyMeshType& meshT, const MyMeshType& meshS,
41 double dimCaracteristic, double md3DSurf, double medianPlane,
42 double precision, int orientation):
43 InterpType<MyMeshType,MyMatrix,PTLOC2D_INTERSECTOR >(meshT,meshS,dimCaracteristic, precision, md3DSurf, medianPlane, true, orientation, 0)
48 double PTLOC2D_INTERSECTOR::intersectGeometry(ConnType icellT, ConnType icellS,
49 ConnType nbNodesT, ConnType nbNodesS)
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);
60 if(PointLocatorAlgos<MyMeshType>::isElementContainsPointAlg2D(baryT,&CoordsS[0],nbNodesS,InterpType<MyMeshType,MyMatrix,PTLOC2D_INTERSECTOR >::_precision))
66 double PTLOC2D_INTERSECTOR::intersectGeometryWithQuadrangle(const double * quadrangle,
67 const std::vector<double>& sourceCoords,
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]);
76 p2=QuadraticPolygon::BuildLinearPolygon(nodes2);
78 p2=QuadraticPolygon::BuildArcCirclePolygon(nodes2);
79 double bary[SPACEDIM];
80 p2->getBarycenter(bary);
82 if( PointLocatorAlgos<MyMeshType>::isElementContainsPointAlg2D(bary,quadrangle,4) )
88 double PTLOC2D_INTERSECTOR::intersectGeometryGeneral(const std::vector<double>& targetCoords,
89 const std::vector<double>& sourceCoords)
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);
100 if( PointLocatorAlgos<MyMeshType>::isElementContainsPointAlg2D(bary,&targetCoords[0],nbOfTargetNodes) )
105 //================================================================================
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
113 //================================================================================
116 double PTLOC2D_INTERSECTOR::intersectGeoBary(const std::vector<double>& targetCell,
117 bool targetCellQuadratic,
118 const double * sourceTria,
119 std::vector<double>& res)
121 throw INTERP_KERNEL::Exception("intersectGeoBary incompatible with PointLocator. Desactivate P1P0Bary to avoid the problem");
126 QuadraticPolygon *PTLOC2D_INTERSECTOR::buildPolygonFrom(const std::vector<double>& coords, NormalizedCellType type)
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);
135 return QuadraticPolygon::BuildArcCirclePolygon(nodes);
139 QuadraticPolygon *PTLOC2D_INTERSECTOR::buildPolygonAFrom(ConnType cell, int nbOfPoints, NormalizedCellType type)
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);
148 return QuadraticPolygon::BuildArcCirclePolygon(nodes);
152 QuadraticPolygon *PTLOC2D_INTERSECTOR::buildPolygonBFrom(ConnType cell, int nbOfPoints, NormalizedCellType type)
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);
161 return QuadraticPolygon::BuildArcCirclePolygon(nodes);