]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/INTERP_KERNEL/PlanarIntersectorP1P0.txx
Salome HOME
Merge from BR_V5_DEV 16Feb09
[tools/medcoupling.git] / src / INTERP_KERNEL / PlanarIntersectorP1P0.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 #ifndef __PLANARINTERSECTORP1P0_TXX__
19 #define __PLANARINTERSECTORP1P0_TXX__
20
21 #include "PlanarIntersectorP1P0.hxx"
22 #include "InterpolationUtils.hxx"
23
24 namespace INTERP_KERNEL
25 {
26   template<class MyMeshType, class MyMatrix, class ConcreteP1P0Intersector>
27   PlanarIntersectorP1P0<MyMeshType,MyMatrix,ConcreteP1P0Intersector>::PlanarIntersectorP1P0(const MyMeshType& meshT, const MyMeshType& meshS,
28                                                                                               double dimCaracteristic, double precision, double medianPlane,
29                                                                                               bool doRotate, int orientation, int printLevel):
30     PlanarIntersector<MyMeshType,MyMatrix>(meshT,meshS,dimCaracteristic,precision,medianPlane,doRotate,orientation,printLevel)
31   {
32   }
33
34   template<class MyMeshType, class MyMatrix, class ConcreteP1P0Intersector>
35   int PlanarIntersectorP1P0<MyMeshType,MyMatrix,ConcreteP1P0Intersector>::getNumberOfRowsOfResMatrix() const
36   {
37     return PlanarIntersector<MyMeshType,MyMatrix>::_meshT.getNumberOfElements();
38   }
39
40   template<class MyMeshType, class MyMatrix, class ConcreteP1P0Intersector>
41   int PlanarIntersectorP1P0<MyMeshType,MyMatrix,ConcreteP1P0Intersector>::getNumberOfColsOfResMatrix() const
42   {
43     return PlanarIntersector<MyMeshType,MyMatrix>::_meshS.getNumberOfNodes();
44   }
45
46   /*!
47    * This methods split on the fly, into triangles in order to compute dual mesh of target cell (with icellT id in target mesh in C mode).
48    */
49   template<class MyMeshType, class MyMatrix, class ConcreteP1P0Intersector>
50   void PlanarIntersectorP1P0<MyMeshType,MyMatrix,ConcreteP1P0Intersector>::intersectCells(ConnType icellT, const std::vector<ConnType>& icellsS, MyMatrix& res)
51   {
52     double triangle[9];
53     double quadrangle[12];
54     std::vector<double> targetCellCoords;
55     int orientation=1;
56     PlanarIntersector<MyMeshType,MyMatrix>::getRealTargetCoordinates(OTT<ConnType,numPol>::indFC(icellT),targetCellCoords);
57     NormalizedCellType tT=PlanarIntersector<MyMeshType,MyMatrix>::_meshT.getTypeOfElement(icellT);
58     bool isTargetQuad=CellModel::getCellModel(tT).isQuadratic();
59     typename MyMatrix::value_type& resRow=res[icellT];
60     for(typename std::vector<ConnType>::const_iterator iter=icellsS.begin();iter!=icellsS.end();iter++)
61       {
62         int iS=*iter;
63         int nbNodesS=PlanarIntersector<MyMeshType,MyMatrix>::_connIndexS[iS+1]-PlanarIntersector<MyMeshType,MyMatrix>::_connIndexS[iS];
64         const ConnType *startOfCellNodeConn=PlanarIntersector<MyMeshType,MyMatrix>::_connectS+OTT<ConnType,numPol>::conn2C(PlanarIntersector<MyMeshType,MyMatrix>::_connIndexS[iS]);
65         for(int nodeIdS=0;nodeIdS<nbNodesS;nodeIdS++)
66           {
67             ConnType curNodeSInCmode=OTT<ConnType,numPol>::coo2C(startOfCellNodeConn[nodeIdS]);
68             std::copy(PlanarIntersector<MyMeshType,MyMatrix>::_coordsS+curNodeSInCmode*SPACEDIM,
69                       PlanarIntersector<MyMeshType,MyMatrix>::_coordsS+curNodeSInCmode*SPACEDIM+SPACEDIM,triangle);
70             for(int subTriS=1;subTriS<=nbNodesS-2;subTriS++)
71               {
72                 std::copy(PlanarIntersector<MyMeshType,MyMatrix>::_coordsS+OTT<ConnType,numPol>::coo2C(startOfCellNodeConn[(nodeIdS+subTriS)%nbNodesS])*SPACEDIM,
73                           PlanarIntersector<MyMeshType,MyMatrix>::_coordsS+OTT<ConnType,numPol>::coo2C(startOfCellNodeConn[(nodeIdS+subTriS)%nbNodesS])*SPACEDIM+SPACEDIM,
74                           triangle+SPACEDIM);
75                 std::copy(PlanarIntersector<MyMeshType,MyMatrix>::_coordsS+OTT<ConnType,numPol>::coo2C(startOfCellNodeConn[(nodeIdS+subTriS+1)%nbNodesS])*SPACEDIM,
76                           PlanarIntersector<MyMeshType,MyMatrix>::_coordsS+OTT<ConnType,numPol>::coo2C(startOfCellNodeConn[(nodeIdS+subTriS+1)%nbNodesS])*SPACEDIM+SPACEDIM,
77                           triangle+2*SPACEDIM);
78                 fillDualCellOfTri<SPACEDIM>(triangle,quadrangle);
79                 std::vector<double> targetCellCoordsTmp(targetCellCoords);
80                 if(SPACEDIM==3)
81                   orientation=PlanarIntersector<MyMeshType,MyMatrix>::projectionThis(&targetCellCoordsTmp[0],quadrangle,targetCellCoords.size()/SPACEDIM,4);
82                 double surf=orientation*intersectGeometryWithQuadrangle(quadrangle,targetCellCoordsTmp,isTargetQuad);
83                 if (( surf > 0.0 && PlanarIntersector<MyMeshType,MyMatrix>::_orientation >=0 ) || ( surf < 0.0 && PlanarIntersector<MyMeshType,MyMatrix>::_orientation <=0 ))
84                   {
85                     typename MyMatrix::value_type::const_iterator iterRes=resRow.find(OTT<ConnType,numPol>::indFC(curNodeSInCmode));
86                     if(iterRes==resRow.end())
87                       resRow.insert(std::make_pair(OTT<ConnType,numPol>::indFC(curNodeSInCmode),surf));
88                     else
89                       {
90                         double val=(*iterRes).second+surf;
91                         resRow.erase(OTT<ConnType,numPol>::indFC(curNodeSInCmode));
92                         resRow.insert(std::make_pair(OTT<ConnType,numPol>::indFC(curNodeSInCmode),val));
93                       }
94                   }
95               }
96           }
97       }
98   }
99 }
100
101 #endif