Salome HOME
[Intersect2D] Bug fix: residual cell construction
[tools/medcoupling.git] / src / INTERP_KERNEL / InterpolationCurve.hxx
1 // Copyright (C) 2007-2021  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, or (at your option) any later version.
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)\r
20 \r
21 #ifndef __INTERPOLATIONCURVE_HXX__\r
22 #define __INTERPOLATIONCURVE_HXX__\r
23 \r
24 #include "Interpolation.hxx"\r
25 #include "InterpolationOptions.hxx"\r
26 \r
27 #include "BBTree.txx"\r
28 \r
29 #include <functional>\r
30 \r
31 namespace INTERP_KERNEL\r
32 {
33   /**
34    * \defgroup interpolationCurve InterpolationCurve
35    *
36    * \class InterpolationCurve
37    * \brief Class used to compute the coefficients of the interpolation matrix between
38    * two local meshes in two dimensions.
39    */
40
41   template<class RealCurve>\r
42   class InterpolationCurve : public Interpolation< InterpolationCurve<RealCurve> >\r
43   {\r
44   public:\r
45     InterpolationCurve();\r
46     InterpolationCurve(const InterpolationOptions & io);\r
47 \r
48     // Main function to interpolate\r
49     template<class MyMeshType, class MatrixType>\r
50     typename MyMeshType::MyConnType interpolateMeshesInternal(const MyMeshType& meshS, const MyMeshType& meshT,\r
51                                                               MatrixType& result, const std::string& method,\r
52                                                               std::function< void(const BBTree< MyMeshType::MY_SPACEDIM , typename MyMeshType::MyConnType>&, const double*, std::vector<typename MyMeshType::MyConnType>&) > bbtreeMethod);\r
53     template<class MyMeshType, class MatrixType>\r
54     typename MyMeshType::MyConnType interpolateMeshes(const MyMeshType& meshS, const MyMeshType& meshT,\r
55                                                       MatrixType& result, const std::string& method)\r
56     {\r
57       std::function< void(const BBTree< MyMeshType::MY_SPACEDIM , typename MyMeshType::MyConnType>&, const double*, std::vector<typename MyMeshType::MyConnType>&) > bbtreeMethod =\r
58         [](const BBTree< MyMeshType::MY_SPACEDIM , typename MyMeshType::MyConnType>& bbtree, const double *bb, std::vector<typename MyMeshType::MyConnType>& intersecting_elems)\r
59         { bbtree.getIntersectingElems(bb, intersecting_elems); };\r
60       return this->interpolateMeshesInternal(meshS,meshT,result,method,bbtreeMethod);\r
61     }\r
62     \r
63     template<class MyMeshType, class MatrixType>\r
64     typename MyMeshType::MyConnType interpolateMeshes0D(const MyMeshType& meshS, const MyMeshType& meshT,\r
65                                                         MatrixType& result, const std::string& method)\r
66     {\r
67       std::function< void(const BBTree< MyMeshType::MY_SPACEDIM , typename MyMeshType::MyConnType>&, const double*, std::vector<typename MyMeshType::MyConnType>&) > bbtreeMethod =\r
68         [](const BBTree< MyMeshType::MY_SPACEDIM , typename MyMeshType::MyConnType>& bbtree, const double *bb, std::vector<typename MyMeshType::MyConnType>& intersecting_elems)\r
69         {\r
70           double TMP[MyMeshType::MY_SPACEDIM];\r
71           for(int i=0;i<MyMeshType::MY_SPACEDIM;++i)\r
72             TMP[i] = bb[2*i];\r
73           bbtree.getElementsAroundPoint(TMP, intersecting_elems);\r
74         };\r
75       return this->interpolateMeshesInternal(meshS,meshT,result,method,bbtreeMethod);\r
76     }\r
77   };\r
78 }\r
79 \r
80 #endif\r