Salome HOME
Merge from V6_main (04/10/2012)
[modules/med.git] / src / INTERP_KERNEL / CurveIntersectorP1P1.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 // Author : Anthony Geay (CEA/DEN)
20 #ifndef __CurveIntersectorP1P1_TXX__
21 #define __CurveIntersectorP1P1_TXX__
22
23 #include "CurveIntersectorP1P1.hxx"
24 #include "CurveIntersector.txx"
25
26 #define BASE_INTERSECTOR  CurveIntersector<MyMeshType,MyMatrix>
27
28 namespace INTERP_KERNEL
29 {
30   template<class MyMeshType, class MyMatrix>
31   CurveIntersectorP1P1<MyMeshType,MyMatrix>
32     ::CurveIntersectorP1P1(const MyMeshType& meshT, const MyMeshType& meshS,
33                            double precision, double tolerance,
34                            double medianLine, int printLevel):
35     BASE_INTERSECTOR (meshT, meshS, precision, tolerance, medianLine, printLevel)
36   {
37   }
38
39   template<class MyMeshType, class MyMatrix>
40   int CurveIntersectorP1P1<MyMeshType,MyMatrix>
41   ::getNumberOfRowsOfResMatrix() const
42   {
43     return BASE_INTERSECTOR::_meshT.getNumberOfNodes();
44   }
45
46   template<class MyMeshType, class MyMatrix>
47   int CurveIntersectorP1P1<MyMeshType,MyMatrix>
48   ::getNumberOfColsOfResMatrix() const
49   {
50     return BASE_INTERSECTOR::_meshS.getNumberOfNodes();
51   }
52
53   template<class MyMeshType, class MyMatrix>
54   void CurveIntersectorP1P1<MyMeshType,MyMatrix>
55   ::intersectCells(ConnType icellT, const std::vector<ConnType>& icellsS, MyMatrix& res)
56   {
57     std::vector<typename BASE_INTERSECTOR::TDualSegment> segmentsT, segmentsS;
58     BASE_INTERSECTOR::getDualSegments( icellT, BASE_INTERSECTOR::_meshT, segmentsT);
59     for ( int t = 0; t < (int)segmentsT.size(); ++t )
60       {
61         typename MyMatrix::value_type& resRow = res[ OTT<ConnType,numPol>::ind2C( segmentsT[t]._nodeId )];
62         for(typename std::vector<ConnType>::const_iterator
63               iter=icellsS.begin(); iter!=icellsS.end(); iter++)
64           {
65             int iS = *iter;
66             BASE_INTERSECTOR::getDualSegments( OTT<ConnType,numPol>::ind2C(iS),
67                                                BASE_INTERSECTOR::_meshS, segmentsS);
68             for ( int s = 0; s < (int)segmentsS.size(); ++s )
69               {
70                 double surf = BASE_INTERSECTOR::intersectSegments(&segmentsT[t]._coords[0],
71                                                                   &segmentsS[s]._coords[0]);
72                 if(surf!=0.)
73                   {
74                     int nS = segmentsS[s]._nodeId;
75                     typename MyMatrix::value_type::const_iterator iterRes=resRow.find(nS);
76                     if(iterRes==resRow.end())
77                       resRow.insert(std::make_pair(nS,surf));
78                     else
79                       {
80                         surf+=(*iterRes).second;
81                         resRow.erase(nS);
82                         resRow.insert(std::make_pair(nS,surf));
83                       }
84                   }
85               }
86           }
87       }
88   }
89 }
90 #undef BASE_INTERSECTOR
91
92 #endif