]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/INTERP_KERNEL/PlanarIntersectorP1P1.txx
Salome HOME
Merge from V6_main_20120808 08Aug12
[tools/medcoupling.git] / src / INTERP_KERNEL / PlanarIntersectorP1P1.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 __PLANARINTERSECTORP1P1_TXX__
20 #define __PLANARINTERSECTORP1P1_TXX__
21
22 #include "PlanarIntersectorP1P1.hxx"
23 #include "InterpolationUtils.hxx"
24 #include "CellModel.hxx"
25
26 namespace INTERP_KERNEL
27 {
28   template<class MyMeshType, class MyMatrix, class ConcreteP1P1Intersector>
29   PlanarIntersectorP1P1<MyMeshType,MyMatrix,ConcreteP1P1Intersector>::PlanarIntersectorP1P1(const MyMeshType& meshT, const MyMeshType& meshS,
30                                                                                             double dimCaracteristic, double precision, double md3DSurf, double medianPlane,
31                                                                                             bool doRotate, int orientation, int printLevel):
32     PlanarIntersector<MyMeshType,MyMatrix>(meshT,meshS,dimCaracteristic,precision,md3DSurf,medianPlane,doRotate,orientation,printLevel)
33   {
34   }
35
36   template<class MyMeshType, class MyMatrix, class ConcreteP1P1Intersector>
37   int PlanarIntersectorP1P1<MyMeshType,MyMatrix,ConcreteP1P1Intersector>::getNumberOfRowsOfResMatrix() const
38   {
39     return PlanarIntersector<MyMeshType,MyMatrix>::_meshT.getNumberOfNodes();
40   }
41
42   template<class MyMeshType, class MyMatrix, class ConcreteP1P1Intersector>
43   int PlanarIntersectorP1P1<MyMeshType,MyMatrix,ConcreteP1P1Intersector>::getNumberOfColsOfResMatrix() const
44   {
45     return PlanarIntersector<MyMeshType,MyMatrix>::_meshS.getNumberOfNodes();
46   }
47
48   /*!
49    * 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).
50    */
51   template<class MyMeshType, class MyMatrix, class ConcreteP1P1Intersector>
52   void PlanarIntersectorP1P1<MyMeshType,MyMatrix,ConcreteP1P1Intersector>::intersectCells(ConnType icellT, const std::vector<ConnType>& icellsS, MyMatrix& res)
53   {
54     int nbNodesT=PlanarIntersector<MyMeshType,MyMatrix>::_connIndexT[icellT+1]-PlanarIntersector<MyMeshType,MyMatrix>::_connIndexT[icellT];
55     int orientation=1;
56     const ConnType *startOfCellNodeConn=PlanarIntersector<MyMeshType,MyMatrix>::_connectT+OTT<ConnType,numPol>::conn2C(PlanarIntersector<MyMeshType,MyMatrix>::_connIndexT[icellT]);
57     std::vector<double> polygT;
58     PlanarIntersector<MyMeshType,MyMatrix>::getRealTargetCoordinates(OTT<ConnType,numPol>::indFC(icellT),polygT);
59     for(int nodeIdT=0;nodeIdT<nbNodesT;nodeIdT++)
60       {
61         ConnType curNodeTInCmode=OTT<ConnType,numPol>::coo2C(startOfCellNodeConn[nodeIdT]);
62         PlanarIntersector<MyMeshType,MyMatrix>::getRealTargetCoordinatesPermute(OTT<ConnType,numPol>::indFC(icellT),nodeIdT,polygT);
63         std::vector<double> polygDualT(SPACEDIM*2*(nbNodesT-1));
64         fillDualCellOfPolyg<SPACEDIM>(&polygT[0],polygT.size()/SPACEDIM,&polygDualT[0]);
65         typename MyMatrix::value_type& resRow=res[curNodeTInCmode];
66         for(typename std::vector<ConnType>::const_iterator iter=icellsS.begin();iter!=icellsS.end();iter++)
67           {
68             int iS=*iter;
69             int nbNodesS=PlanarIntersector<MyMeshType,MyMatrix>::_connIndexS[iS+1]-PlanarIntersector<MyMeshType,MyMatrix>::_connIndexS[iS];
70             const ConnType *startOfCellNodeConnS=PlanarIntersector<MyMeshType,MyMatrix>::_connectS+OTT<ConnType,numPol>::conn2C(PlanarIntersector<MyMeshType,MyMatrix>::_connIndexS[iS]);
71             for(int nodeIdS=0;nodeIdS<nbNodesS;nodeIdS++)
72               {
73                 ConnType curNodeSInCmode=OTT<ConnType,numPol>::coo2C(startOfCellNodeConnS[nodeIdS]);
74                 std::vector<double> polygS;
75                 PlanarIntersector<MyMeshType,MyMatrix>::getRealSourceCoordinatesPermute(OTT<ConnType,numPol>::indFC(iS),nodeIdS,polygS);
76                 std::vector<double> polygDualS(SPACEDIM*2*(nbNodesS-1));
77                 fillDualCellOfPolyg<SPACEDIM>(&polygS[0],polygS.size()/SPACEDIM,&polygDualS[0]);
78                 std::vector<double> polygDualTTmp(polygDualT);
79                 if(SPACEDIM==3)
80                   orientation=PlanarIntersector<MyMeshType,MyMatrix>::projectionThis(&polygDualS[0],&polygDualTTmp[0],polygDualS.size()/SPACEDIM,polygDualT.size()/SPACEDIM);
81                 double surf=orientation*intersectGeometryGeneral(polygDualTTmp,polygDualS);
82                 surf=PlanarIntersector<MyMeshType,MyMatrix>::getValueRegardingOption(surf);
83                 if(surf!=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