Salome HOME
05b5c94094ff4bb571bf1c56833f3fa6fe292eeb
[tools/medcoupling.git] / src / INTERP_KERNEL / Intersector3D.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 __INTERSECTOR3D_TXX__
20 #define __INTERSECTOR3D_TXX__
21
22 #include "Intersector3D.hxx"
23
24 #include <algorithm>
25
26 namespace INTERP_KERNEL
27 {
28   template<class MyMeshType, class MyMatrix>
29   Intersector3D<MyMeshType,MyMatrix>::Intersector3D(const MyMeshType& targetMesh, const MyMeshType& srcMesh):_target_mesh(targetMesh),_src_mesh(srcMesh)
30   {
31   }
32
33   /*!
34    * @param icellT in format of MyMeshType.
35    */
36   template<class MyMeshType, class MyMatrix>
37   void Intersector3D<MyMeshType,MyMatrix>::getRealTargetCoordinates(ConnType icellT, std::vector<double>& coordsT) const
38   {
39     int nbNodesT=_target_mesh.getNumberOfNodesOfElement(icellT);
40     coordsT.resize(SPACEDIM*nbNodesT);
41     std::vector<double>::iterator iter=coordsT.begin();
42     for (ConnType iT=0; iT<nbNodesT; iT++)
43       {
44         const double *coordsCur=getCoordsOfNode(iT,icellT,_target_mesh);
45         iter=std::copy(coordsCur,coordsCur+SPACEDIM,iter);
46       }
47   }
48
49   /*!
50    * @param icellT in format of MyMeshType.
51    */
52   template<class MyMeshType, class MyMatrix>
53   void Intersector3D<MyMeshType,MyMatrix>::getRealSourceCoordinates(ConnType icellS, std::vector<double>& coordsS) const
54   {
55     int nbNodesS=_src_mesh.getNumberOfNodesOfElement(icellS);
56     coordsS.resize(SPACEDIM*nbNodesS);
57     std::vector<double>::iterator iter=coordsS.begin();
58     for (ConnType iS=0; iS<nbNodesS; iS++)
59       {
60         const double *coordsCur=getCoordsOfNode(iS,icellS,_src_mesh);
61         iter=std::copy(coordsCur,coordsCur+SPACEDIM,iter);
62       }
63   }
64
65   /*!
66    * @param icellT in C format.
67    * @return is in format of MyMeshType
68    */
69   template<class MyMeshType, class MyMatrix>
70   const typename MyMeshType::MyConnType *Intersector3D<MyMeshType,MyMatrix>::getStartConnOfTargetCell(ConnType icellT) const
71   {
72     const ConnType *myConectT=_target_mesh.getConnectivityPtr();
73     const ConnType *myConIndexT=_target_mesh.getConnectivityIndexPtr();
74     return myConectT+OTT<ConnType,numPol>::conn2C(myConIndexT[icellT]);
75   }
76
77   /*!
78    * @param icellT in C format.
79    * @return is in format of MyMeshType
80    */
81   template<class MyMeshType, class MyMatrix>
82   const typename MyMeshType::MyConnType *Intersector3D<MyMeshType,MyMatrix>::getStartConnOfSourceCell(ConnType icellS) const
83   {
84     const ConnType *myConectS=_src_mesh.getConnectivityPtr();
85     const ConnType *myConIndexS=_src_mesh.getConnectivityIndexPtr();
86     return myConectS+OTT<ConnType,numPol>::conn2C(myConIndexS[icellS]);
87   }
88
89   /*!
90    * @param icellS in format of MyMeshType.
91    * @param res ; out param in format of MyMeshType.
92    */
93   template<class MyMeshType, class MyMatrix>
94   void Intersector3D<MyMeshType,MyMatrix>::getConnOfSourceCell(ConnType icellS, typename std::vector<ConnType>& res) const
95   {
96     const ConnType *myConectS=_src_mesh.getConnectivityPtr();
97     const ConnType *myConIndexS=_src_mesh.getConnectivityIndexPtr();
98     ConnType start=myConIndexS[OTT<ConnType,numPol>::ind2C(icellS)];
99     ConnType end=myConIndexS[OTT<ConnType,numPol>::ind2C(icellS)+1];
100     int nbNodesS=end-start;
101     res.resize(nbNodesS);
102     std::copy(myConectS+OTT<ConnType,numPol>::conn2C(start),myConectS+OTT<ConnType,numPol>::conn2C(end),res.begin());
103   }
104 }
105
106 #endif