1 // Copyright (C) 2007-2012 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 #ifndef __POINTLOCATORINTERSECTOR_TXX__
20 #define __POINTLOCATORINTERSECTOR_TXX__
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"
30 #include "InterpKernelGeo2DQuadraticPolygon.hxx"
31 #include "PointLocatorAlgos.txx"
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>
36 namespace INTERP_KERNEL
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)
47 double PTLOC2D_INTERSECTOR::intersectGeometry(ConnType icellT, ConnType icellS,
48 ConnType nbNodesT, ConnType nbNodesS)
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);
59 if(PointLocatorAlgos<MyMeshType>::isElementContainsPointAlg2D(baryT,&CoordsS[0],nbNodesS,InterpType<MyMeshType,MyMatrix,PTLOC2D_INTERSECTOR >::_precision))
65 double PTLOC2D_INTERSECTOR::intersectGeometryWithQuadrangle(const double * quadrangle,
66 const std::vector<double>& sourceCoords,
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]);
75 p2=QuadraticPolygon::BuildLinearPolygon(nodes2);
77 p2=QuadraticPolygon::BuildArcCirclePolygon(nodes2);
78 double bary[SPACEDIM];
79 p2->getBarycenter(bary);
81 if( PointLocatorAlgos<MyMeshType>::isElementContainsPointAlg2D(bary,quadrangle,4) )
87 double PTLOC2D_INTERSECTOR::intersectGeometryGeneral(const std::vector<double>& targetCoords,
88 const std::vector<double>& sourceCoords)
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);
99 if( PointLocatorAlgos<MyMeshType>::isElementContainsPointAlg2D(bary,&targetCoords[0],nbOfTargetNodes) )
104 //================================================================================
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
112 //================================================================================
115 double PTLOC2D_INTERSECTOR::intersectGeoBary(const std::vector<double>& targetCell,
116 bool targetCellQuadratic,
117 const double * sourceTria,
118 std::vector<double>& res)
120 throw INTERP_KERNEL::Exception("intersectGeoBary incompatible with PointLocator. Desactivate P1P0Bary to avoid the problem");
125 QuadraticPolygon *PTLOC2D_INTERSECTOR::buildPolygonFrom(const std::vector<double>& coords, NormalizedCellType type)
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);
134 return QuadraticPolygon::BuildArcCirclePolygon(nodes);
138 QuadraticPolygon *PTLOC2D_INTERSECTOR::buildPolygonAFrom(ConnType cell, int nbOfPoints, NormalizedCellType type)
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);
147 return QuadraticPolygon::BuildArcCirclePolygon(nodes);
151 QuadraticPolygon *PTLOC2D_INTERSECTOR::buildPolygonBFrom(ConnType cell, int nbOfPoints, NormalizedCellType type)
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);
160 return QuadraticPolygon::BuildArcCirclePolygon(nodes);