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