]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Update code to C++11
authorAnthony Geay <anthony.geay@edf.fr>
Fri, 19 Aug 2022 13:34:13 +0000 (15:34 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Fri, 19 Aug 2022 13:34:13 +0000 (15:34 +0200)
src/INTERP_KERNEL/Interpolation3D.txx

index 355217c96bad9b321c897cbd830fd37e03ed7ebc..38ca91132d9f3e558e9a178b6f871d7d577822fd 100755 (executable)
@@ -51,6 +51,8 @@
 
 #endif
 
+#include <memory>
+
 namespace INTERP_KERNEL
 {
   /**
@@ -84,28 +86,28 @@ namespace INTERP_KERNEL
 
     LOG(2, "Source mesh has " << numSrcElems << " elements and target mesh has " << numTargetElems << " elements ");
 
-    std::vector<MeshElement<ConnType>*> srcElems(numSrcElems);
-    std::vector<MeshElement<ConnType>*> targetElems(numTargetElems);
+    std::vector<std::unique_ptr<MeshElement<ConnType>>> srcElems(numSrcElems);
+    std::vector<std::unique_ptr<MeshElement<ConnType>>> targetElems(numTargetElems);
 
     std::map<MeshElement<ConnType>*, ConnType> indices;
 
     for(ConnType i = 0 ; i < numSrcElems ; ++i)
-      srcElems[i] = new MeshElement<ConnType>(i, srcMesh);       
+      srcElems[i].reset( new MeshElement<ConnType>(i, srcMesh) );
 
     for(ConnType i = 0 ; i < numTargetElems ; ++i)
-      targetElems[i] = new MeshElement<ConnType>(i, targetMesh);
+      targetElems[i].reset( new MeshElement<ConnType>(i, targetMesh) );
 
-    Intersector3D<MyMeshType,MatrixType>* intersector=0;
+    std::unique_ptr<Intersector3D<MyMeshType,MatrixType>> intersector;
     std::string methC = InterpolationOptions::filterInterpolationMethod(method);
     if(methC=="P0P0")
       {
         switch(InterpolationOptions::getIntersectionType())
           {
           case Triangulation:
-            intersector=new PolyhedronIntersectorP0P0<MyMeshType,MatrixType>(targetMesh, srcMesh, getSplittingPolicy());
+            intersector.reset( new PolyhedronIntersectorP0P0<MyMeshType,MatrixType>(targetMesh, srcMesh, getSplittingPolicy()) );
             break;
           case PointLocator:
-            intersector=new PointLocator3DIntersectorP0P0<MyMeshType,MatrixType>(targetMesh, srcMesh, getPrecision());
+            intersector.reset( new PointLocator3DIntersectorP0P0<MyMeshType,MatrixType>(targetMesh, srcMesh, getPrecision()) );
             break;
           default:
             throw INTERP_KERNEL::Exception("Invalid 3D intersection type for P0P0 interp specified : must be Triangle or PointLocator.");
@@ -116,10 +118,10 @@ namespace INTERP_KERNEL
         switch(InterpolationOptions::getIntersectionType())
           {
           case Triangulation:
-            intersector=new PolyhedronIntersectorP0P1<MyMeshType,MatrixType>(targetMesh, srcMesh, getSplittingPolicy());
+            intersector.reset( new PolyhedronIntersectorP0P1<MyMeshType,MatrixType>(targetMesh, srcMesh, getSplittingPolicy()) );
             break;
           case PointLocator:
-            intersector=new PointLocator3DIntersectorP0P1<MyMeshType,MatrixType>(targetMesh, srcMesh, getPrecision());
+            intersector.reset( new PointLocator3DIntersectorP0P1<MyMeshType,MatrixType>(targetMesh, srcMesh, getPrecision()) );
             break;
           default:
             throw INTERP_KERNEL::Exception("Invalid 3D intersection type for P0P1 interp specified : must be Triangle or PointLocator.");
@@ -130,13 +132,13 @@ namespace INTERP_KERNEL
         switch(InterpolationOptions::getIntersectionType())
           {
           case Triangulation:
-            intersector=new PolyhedronIntersectorP1P0<MyMeshType,MatrixType>(targetMesh, srcMesh, getSplittingPolicy());
+            intersector.reset( new PolyhedronIntersectorP1P0<MyMeshType,MatrixType>(targetMesh, srcMesh, getSplittingPolicy()) );
             break;
           case PointLocator:
-            intersector=new PointLocator3DIntersectorP1P0<MyMeshType,MatrixType>(targetMesh, srcMesh, getPrecision());
+            intersector.reset( new PointLocator3DIntersectorP1P0<MyMeshType,MatrixType>(targetMesh, srcMesh, getPrecision()) );
             break;
           case Barycentric:
-            intersector=new PolyhedronIntersectorP1P0Bary<MyMeshType,MatrixType>(targetMesh, srcMesh, getSplittingPolicy());
+            intersector.reset( new PolyhedronIntersectorP1P0Bary<MyMeshType,MatrixType>(targetMesh, srcMesh, getSplittingPolicy()) );
             break;
           default:
             throw INTERP_KERNEL::Exception("Invalid 3D intersection type for P1P0 interp specified : must be Triangle, PointLocator or Barycentric.");
@@ -147,16 +149,16 @@ namespace INTERP_KERNEL
         switch(InterpolationOptions::getIntersectionType())
           {
           case Triangulation:
-            intersector=new PolyhedronIntersectorP1P1<MyMeshType,MatrixType>(targetMesh, srcMesh, getSplittingPolicy());
+            intersector.reset( new PolyhedronIntersectorP1P1<MyMeshType,MatrixType>(targetMesh, srcMesh, getSplittingPolicy()) );
             break;
           case PointLocator:
-            intersector=new PointLocator3DIntersectorP1P1<MyMeshType,MatrixType>(targetMesh, srcMesh, getPrecision());
+            intersector.reset( new PointLocator3DIntersectorP1P1<MyMeshType,MatrixType>(targetMesh, srcMesh, getPrecision()) );
             break;
           case Barycentric:
-            intersector=new Barycentric3DIntersectorP1P1<MyMeshType,MatrixType>(targetMesh, srcMesh, getPrecision());
+            intersector.reset( new Barycentric3DIntersectorP1P1<MyMeshType,MatrixType>(targetMesh, srcMesh, getPrecision()) );
             break;
           case MappedBarycentric:
-            intersector=new MappedBarycentric3DIntersectorP1P1<MyMeshType,MatrixType>(targetMesh, srcMesh, getPrecision());
+            intersector.reset( new MappedBarycentric3DIntersectorP1P1<MyMeshType,MatrixType>(targetMesh, srcMesh, getPrecision()) );
             break;
           default:
             throw INTERP_KERNEL::Exception("Invalid 3D intersection type for P1P1 interp specified : must be Triangle, PointLocator, Barycentric or MappedBarycentric.");
@@ -306,8 +308,8 @@ namespace INTERP_KERNEL
 
       // create BBTree structure
       // - get bounding boxes
-    double* bboxes = new double[6 * numSrcElems];
-    ConnType* srcElemIdx = new ConnType[numSrcElems];
+    std::unique_ptr<double[]> bboxes( new double[6 * numSrcElems] );
+    std::unique_ptr<ConnType[]> srcElemIdx( new ConnType[numSrcElems] );
     for(ConnType i = 0; i < numSrcElems ; ++i)
       {
         // get source bboxes in right order
@@ -323,7 +325,7 @@ namespace INTERP_KERNEL
         srcElemIdx[i] = srcElems[i]->getIndex();
       }
 
-    BBTree<3,ConnType> tree(bboxes, srcElemIdx, 0, numSrcElems);
+    BBTree<3,ConnType> tree(bboxes.get(), srcElemIdx.get(), 0, numSrcElems);
 
     // for each target element, get source elements with which to calculate intersection
     // - calculate intersection by calling intersectCells
@@ -349,25 +351,8 @@ namespace INTERP_KERNEL
           intersector->intersectCells(targetIdx,intersectElems,result);
       }
 
-    delete [] bboxes;
-    delete [] srcElemIdx;
-
 #endif
-    // free allocated memory
-    ConnType ret=intersector->getNumberOfColsOfResMatrix();
-
-    delete intersector;
-
-    for(ConnType i = 0 ; i < numSrcElems ; ++i)
-      {
-        delete srcElems[i];
-      }
-    for(ConnType i = 0 ; i < numTargetElems ; ++i)
-      {
-        delete targetElems[i];
-      }
-    return ret;
-
+    return intersector->getNumberOfColsOfResMatrix();
   }
 }