]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
[EDF30834] : Work b4 integration. Redefinition of dependancies. RAII usage. Templatin...
authorAnthony Geay <anthony.geay@edf.fr>
Wed, 28 Aug 2024 12:50:31 +0000 (14:50 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Fri, 30 Aug 2024 12:17:35 +0000 (14:17 +0200)
48 files changed:
CMakeLists.txt
src/CMakeLists.txt
src/CTestTestfileInstall.cmake.in
src/MEDCoupling/MCAuto.hxx
src/PyWrapping/CMakeLists.txt
src/PyWrapping/TestPyWrapGathered_medcoupling.py
src/PyWrapping/medcoupling.i
src/ShapeRecogn/Areas.cxx
src/ShapeRecogn/Areas.hxx
src/ShapeRecogn/AreasBuilder.cxx
src/ShapeRecogn/AreasBuilder.hxx
src/ShapeRecogn/CMakeLists.txt
src/ShapeRecogn/MathOps.cxx
src/ShapeRecogn/MathOps.hxx
src/ShapeRecogn/Nodes.cxx
src/ShapeRecogn/Nodes.hxx
src/ShapeRecogn/NodesBuilder.cxx
src/ShapeRecogn/NodesBuilder.hxx
src/ShapeRecogn/PrimitiveType.cxx [new file with mode: 0644]
src/ShapeRecogn/PrimitiveType.hxx
src/ShapeRecogn/README.md
src/ShapeRecogn/ShapeRecognMesh.cxx
src/ShapeRecogn/ShapeRecognMesh.hxx
src/ShapeRecogn/ShapeRecognMeshBuilder.cxx
src/ShapeRecogn/ShapeRecognMeshBuilder.hxx
src/ShapeRecogn/ShapeRecongConstants.hxx
src/ShapeRecogn/Swig/CMakeLists.txt
src/ShapeRecogn/Swig/ShapeRecogn.i
src/ShapeRecogn/Swig/ShapeRecognCommon.i [new file with mode: 0644]
src/ShapeRecogn/Swig/ShapeRecognImpl.i [new file with mode: 0644]
src/ShapeRecogn/Test/CMakeLists.txt
src/ShapeRecogn/Test/CTestTestfileInstall.cmake
src/ShapeRecogn/Test/ConeTest.cxx
src/ShapeRecogn/Test/ConeTest.hxx
src/ShapeRecogn/Test/CylinderTest.cxx
src/ShapeRecogn/Test/CylinderTest.hxx
src/ShapeRecogn/Test/MathOpsTest.cxx
src/ShapeRecogn/Test/MathOpsTest.hxx
src/ShapeRecogn/Test/PlaneTest.cxx
src/ShapeRecogn/Test/PlaneTest.hxx
src/ShapeRecogn/Test/ShapeRecognTest.cxx [new file with mode: 0644]
src/ShapeRecogn/Test/ShapeRecognTest.hxx [new file with mode: 0644]
src/ShapeRecogn/Test/SphereTest.cxx
src/ShapeRecogn/Test/SphereTest.hxx
src/ShapeRecogn/Test/TestShapeRecogn.cxx
src/ShapeRecogn/Test/TestShapeRecogn.py [new file with mode: 0644]
src/ShapeRecogn/Test/TorusTest.cxx
src/ShapeRecogn/Test/TorusTest.hxx

index c080f174a5dd9163e6afe3ed4cdd8bd50c3a1796..fff7065d3164c46fa3d3770488c132e9af241c3b 100644 (file)
@@ -88,7 +88,7 @@ OPTION(MEDCOUPLING_MICROMED "Build MED without MED file dependency." OFF)
 OPTION(MEDCOUPLING_ENABLE_PYTHON "Build PYTHON bindings." ON)
 OPTION(MEDCOUPLING_ENABLE_PARTITIONER "Build MEDPartitioner." ON)
 OPTION(MEDCOUPLING_ENABLE_RENUMBER "Build Renumber." ON)
-OPTION(MEDCOUPLING_ENABLE_SHAPERECOGN "Build ShapeRecogn" OFF)
+OPTION(MEDCOUPLING_ENABLE_SHAPERECOGN "Build Shape Recognition module." OFF)
 OPTION(MEDCOUPLING_WITH_FILE_EXAMPLES "Install examples of files containing meshes and fields of different formats." ON)
 OPTION(MEDCOUPLING_USE_MPI "(Use MPI containers) - For MED this triggers the build of ParaMEDMEM." OFF)
 OPTION(MEDCOUPLING_BUILD_TESTS "Build MEDCoupling C++ tests." ON)
@@ -121,17 +121,17 @@ CMAKE_DEPENDENT_OPTION(MEDCOUPLING_BUILD_FRENCH_DOC "Generate MEDCOUPLING French
 IF(MEDCOUPLING_BUILD_STATIC)
     SET(BUILD_SHARED_LIBS 0)
     SET(CMAKE_POSITION_INDEPENDENT_CODE 1) # -fPIC option
-ELSE()
+ELSE(MEDCOUPLING_BUILD_STATIC)
     SET(BUILD_SHARED_LIBS 1)
-ENDIF()
+ENDIF(MEDCOUPLING_BUILD_STATIC)
 
 IF(${MEDCOUPLING_PARTITIONER_PARMETIS} AND ${MEDCOUPLING_PARTITIONER_METIS})
     MESSAGE(FATAL_ERROR "ParMetis and Metis are mutually exclusive! Make a choice (options MEDCOUPLING_PARTITIONER_METIS and MEDCOUPLING_PARTITIONER_PARMETIS).")
-ENDIF()
+ENDIF(${MEDCOUPLING_PARTITIONER_PARMETIS} AND ${MEDCOUPLING_PARTITIONER_METIS})
 
 IF(${MEDCOUPLING_PARTITIONER_PTSCOTCH} AND ${MEDCOUPLING_PARTITIONER_SCOTCH})
     MESSAGE(FATAL_ERROR "PTScotch and Scotch are mutually exclusive! Make a choice (options MEDCOUPLING_PARTITIONER_SCOTCH and MEDCOUPLING_PARTITIONER_PTSCOTCH).")
-ENDIF()
+ENDIF(${MEDCOUPLING_PARTITIONER_PTSCOTCH} AND ${MEDCOUPLING_PARTITIONER_SCOTCH})
 
 #
 # Set list of prerequisites
index e4d70409cf116a871c2cede9001e84d4f41f2b64..5edb2b3b28550e93a538c3beebe4c541fc17df02 100644 (file)
@@ -31,6 +31,11 @@ ENDIF(MEDCOUPLING_BUILD_TESTS)
 ADD_SUBDIRECTORY(MEDCoupling)
 ADD_SUBDIRECTORY(ICoCo)
 
+# Shape recognition
+IF(MEDCOUPLING_ENABLE_SHAPERECOGN)
+  ADD_SUBDIRECTORY(ShapeRecogn)
+ENDIF(MEDCOUPLING_ENABLE_SHAPERECOGN)
+
 IF(MEDCOUPLING_ENABLE_PYTHON)
   ADD_SUBDIRECTORY(MEDCoupling_Swig)
   
@@ -82,9 +87,6 @@ IF(MEDCOUPLING_USE_MPI)
   ENDIF(MEDCOUPLING_BUILD_TESTS)
 ENDIF(MEDCOUPLING_USE_MPI)
 
-IF(MEDCOUPLING_ENABLE_SHAPERECOGN)
-  ADD_SUBDIRECTORY(ShapeRecogn)
-ENDIF(MEDCOUPLING_ENABLE_SHAPERECOGN)
 
 # Application tests
 configure_file(CTestTestfileInstall.cmake.in "CTestTestfileST.cmake" @ONLY)
index f71d5f0f2955d9606020fd267b3aa1551bb27cdf..b0cf5538ccb2dd67ad46f61f2fb78c60d29fa72b 100644 (file)
@@ -21,6 +21,7 @@ SET(COMPONENT_NAME MEDCOUPLING)
 SET(TIMEOUT        120)
 SET(MEDCOUPLING_BUILD_PY_TESTS $<BOOL:@MEDCOUPLING_BUILD_PY_TESTS@>)
 SET(MEDCOUPLING_USE_MPI_BOOL $<BOOL:@MEDCOUPLING_USE_MPI@>)
+SET(MEDCOUPLING_ENABLE_SHAPERECOGN $<BOOL:@MEDCOUPLING_ENABLE_SHAPERECOGN@>)
 
 SUBDIRS(INTERP_KERNELTest)
 SUBDIRS(MEDCoupling)
@@ -35,6 +36,10 @@ if(MEDCOUPLING_USE_MPI_BOOL)
     SUBDIRS(ParaMEDMEM_Swig)
 endif()
 
+if(MEDCOUPLING_ENABLE_SHAPERECOGN)
+    SUBDIRS(ShapeRecogn)
+endif()
+
 SUBDIRS(MEDPartitioner_Swig)
 SUBDIRS(RENUMBER_Swig)
 SUBDIRS(PyWrapping)
index 4b6347704444d30d964d50830e5ff635a451c304..0774928b09b646685887d64004e11f79b5ff3b4f 100644 (file)
@@ -139,6 +139,7 @@ namespace MEDCoupling
     bool operator==(const MCConstAuto& other) const { return _ptr==other._ptr; }
     bool operator==(const T *other) const { return _ptr==other; }
     MCConstAuto &operator=(const MCConstAuto& other) { if(_ptr!=other._ptr) { destroyPtr(); referPtr(other._ptr); } return *this; }
+    MCConstAuto &operator=(const typename MEDCoupling::MCAuto<T>& other) { if(_ptr!=(const T*)other) { destroyPtr(); referPtr((const T*)other); } return *this; }
     MCConstAuto &operator=(const T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; } return *this; }
     void takeRef(const T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; if(_ptr) _ptr->incrRef(); } }
     const T *operator->() { return _ptr ; }
index 642ce08f51c6f8bc77d071665661422ecf0db9d0..e1b4e2f5a7efe312f725cf40ec177de8bae6c743 100644 (file)
@@ -63,16 +63,23 @@ INCLUDE_DIRECTORIES(
   ${CMAKE_CURRENT_SOURCE_DIR}/../ParaMEDMEM
   ${CMAKE_CURRENT_SOURCE_DIR}/../ParaMEDMEM/MPIAccess
   ${CMAKE_CURRENT_SOURCE_DIR}/../ParaMEDMEM_Swig
+  ${CMAKE_CURRENT_SOURCE_DIR}/../ShapeRecogn
+  ${CMAKE_CURRENT_SOURCE_DIR}/../ShapeRecogn/Swig
   ${PROJECT_BINARY_DIR}/doc
   )
-
-IF(WIN32 OR CYGWIN)
+  
+  IF(WIN32 OR CYGWIN)
   SET(medcoupling_LIB_dependancies ${PYTHON_LIBRARIES} ${PLATFORM_LIBS} medcouplingremapper medicoco)
-ELSE(WIN32)
+  ELSE(WIN32 OR CYGWIN)
   # ${PYTHON_LIBRARIES} not needed see https://www.python.org/dev/peps/pep-0513/#libpythonx-y-so-1
   SET(medcoupling_LIB_dependancies ${PLATFORM_LIBS} medcouplingremapper medicoco)
-ENDIF(WIN32 OR CYGWIN)
+  ENDIF(WIN32 OR CYGWIN)
   
+  IF(MEDCOUPLING_ENABLE_SHAPERECOGN)
+    LIST(APPEND SWIG_MODULE_medcoupling_EXTRA_FLAGS -DWITH_SHAPE_RECOGN)
+    LIST(APPEND medcoupling_LIB_dependancies shaperecogn)
+  ENDIF(MEDCOUPLING_ENABLE_SHAPERECOGN)
+
 IF(NOT MEDCOUPLING_MICROMED)
   LIST(APPEND SWIG_MODULE_medcoupling_EXTRA_FLAGS -DWITH_MED_FILE)
   LIST(APPEND medcoupling_LIB_dependancies medloader)
index 10ce28a1b439b2fecf6bd3dbeab50cd26b7ece5f..553fefc966607db5610eea90458e6179cb4bb82b 100644 (file)
@@ -141,7 +141,17 @@ class medcouplingTest(unittest.TestCase):
         a,b,c=f3.getTime()
         self.assertEqual(b,10) ; self.assertEqual(c,13) ; self.assertAlmostEqual(a,10.75,14);
         pass
-        
+
+    @unittest.skipUnless(HasShapeRecognitionExt(),"Requires Shape recognition extension activated")
+    def test6(self):
+        m = MEDCouplingCMesh()
+        arr = DataArrayDouble(5) ; arr.iota()
+        m.setCoords(arr,arr)
+        m = m.buildUnstructured()
+        m.simplexize(0)
+        m.changeSpaceDimension(3,0.)
+        srMesh = ShapeRecognMeshBuilder( m )
+        rem = srMesh.recognize()
 
     def partitionerTesterHelper(self,algoSelected):
         arr=DataArrayDouble(10) ; arr.iota()
index 4e9436cae932de2abd4f811921715431892c67c4..c8f20df05c324f228fa9e007c133d960ea194b0d 100644 (file)
 %include "ParaMEDMEMCommon.i"
 #endif
 
+#ifdef WITH_SHAPE_RECOGN
+%include "ShapeRecognCommon.i"
+#endif
+
 %constant const char __version__[]=MEDCOUPLING_GIT_SHA1;
 %constant const char __config_datetime__[]=MEDCOUPLING_CONFIG_DT;
 
   static const char RENUM_EXT[]="Renumberer";
   static const char PART_EXT[]="Partitioner";
   static const char PAR_INTERPOL_EXT[]="Parallel interpolator (SPMD paradigm)";
-  static const char IT_STATS_EXT[] = "Iterative statistics";
-  
-  static const char *EXTENSIONS[]={SEQ_INTERPOL_EXT,MEDFILEIO_EXT,RENUM_EXT,PART_EXT,PAR_INTERPOL_EXT,IT_STATS_EXT};
+  static const char IT_STATS_EXT[]="Iterative statistics";
+  static const char SHAPE_RECOGNITION_EXT[]="Shape Recognition";
+
+  static const char *EXTENSIONS[]={SEQ_INTERPOL_EXT,MEDFILEIO_EXT,RENUM_EXT,PART_EXT,PAR_INTERPOL_EXT,IT_STATS_EXT,SHAPE_RECOGNITION_EXT};
   static const int NB_OF_EXTENSIONS=sizeof(EXTENSIONS)/sizeof(const char *);
 %}
 
     return false;
 #endif
   }
+
+  bool HasShapeRecognitionExt()
+  {
+#ifdef WITH_SHAPE_RECOGN
+    return true;
+#else
+    return false;
+#endif
+  }
   
   std::vector<std::string> ActiveExtensions()
   {
 #endif
 #ifdef WITH_ITERATIVE_STATISTICS
     ret.push_back(std::string(IT_STATS_EXT));
+#endif
+#ifdef WITH_SHAPE_RECOGN
+    ret.push_back(std::string(SHAPE_RECOGNITION_EXT));
 #endif
     return ret;
   }
index f8441cb48df6e663626f647e763fcc056beb9904..2cc82210fefe358da7b26c4255624b81c760186b 100644 (file)
@@ -1,3 +1,22 @@
+// Copyright (C) 2024  CEA, EDF
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
 #include "Areas.hxx"
 #include "MathOps.hxx"
 
@@ -45,7 +64,7 @@ void Areas::removeArea(mcIdType areaId)
 void Areas::addNode(mcIdType areaId, mcIdType nodeId)
 {
     removeNode(nodeId);
-    areaIdByNodes[nodeId] = areaId;
+    areaIdByNodes[nodeId] = FromIdType<Int32>(areaId);
     Area &area = areas[areaId];
     area.nodeIds.push_back(nodeId);
     size_t nbNodes = area.nodeIds.size();
@@ -109,12 +128,12 @@ PrimitiveType Areas::getPrimitiveType(mcIdType areaId) const
 
 std::string Areas::getPrimitiveTypeName(mcIdType areaId) const
 {
-    return convertPrimitiveToString(getPrimitiveType(areaId));
+    return ConvertPrimitiveToString(getPrimitiveType(areaId));
 }
 
 int Areas::getPrimitiveTypeInt(mcIdType areaId) const
 {
-    return convertPrimitiveToInt(getPrimitiveType(areaId));
+    return ConvertPrimitiveToInt(getPrimitiveType(areaId));
 }
 
 const std::vector<mcIdType> &Areas::getNodeIds(mcIdType areaId) const
@@ -219,7 +238,7 @@ void Areas::cleanArea(mcIdType areaId, mcIdType newAreaId = -1)
 {
     Area &area = areas[areaId];
     for (mcIdType nodeId : area.nodeIds)
-        areaIdByNodes[nodeId] = newAreaId;
+        areaIdByNodes[nodeId] = FromIdType<Int32>( newAreaId );
     area.primitive = PrimitiveType::Unknown;
     area.k1 = 0.0;
     area.k2 = 0.0;
@@ -479,7 +498,7 @@ void Areas::computeTorusProperties(mcIdType areaId)
         area.center[i] = xc * base2d[i] + yc * base2d[3 + i] + meanMajorRadiusNodes[i];
 }
 
-const std::vector<mcIdType> &Areas::getAreaIdByNodes() const
+const std::vector<Int32> &Areas::getAreaIdByNodes() const
 {
     return areaIdByNodes;
 }
index b1b6f6bca438b5fc81e4aed5e985ba599be53da2..8e3158a56b28cd76525ce529e4b90db7446a8559 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2024  CEA, EDF
+// Copyright (C) 2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -17,8 +17,7 @@
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#ifndef __AREAS_HXX__
-#define __AREAS_HXX__
+#pragma once
 
 #include "PrimitiveType.hxx"
 #include "Nodes.hxx"
@@ -60,7 +59,7 @@ namespace MEDCoupling
         void cleanInvalidNodeAreas();
 
         mcIdType getAreaId(mcIdType nodeId) const;
-        const std::vector<mcIdType> &getAreaIdByNodes() const;
+        const std::vector<Int32> &getAreaIdByNodes() const;
 
         bool isEmpty(mcIdType areaId) const;
         size_t getNumberOfAreas() const;
@@ -101,8 +100,6 @@ namespace MEDCoupling
 
         std::vector<Area> areas;
         const Nodes *nodes;
-        std::vector<mcIdType> areaIdByNodes;
+        std::vector<Int32> areaIdByNodes;
     };
-};
-
-#endif // __AREAS_HXX__
+}
index 947a54ed0dbcc40f8c637dedd2d070c01de2cb8d..a09174170a3f9e1a8376bee23f023e0bfa3c7bbd 100644 (file)
@@ -1,3 +1,22 @@
+// Copyright (C) 2024  CEA, EDF
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
 #include "AreasBuilder.hxx"
 #include "MathOps.hxx"
 #include "ShapeRecongConstants.hxx"
index 9742af648fe1f5aa476f694b2ed35a1f18c270fb..679a93570b0a462fae8dbeb9616e3b4e8cf37ba1 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2024  CEA, EDF
+// Copyright (C) 2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -17,8 +17,7 @@
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#ifndef __AREASBUILDER_HXX__
-#define __AREASBUILDER_HXX__
+#pragma once
 
 #include "Nodes.hxx"
 #include "Areas.hxx"
@@ -69,6 +68,4 @@ namespace MEDCoupling
 
         size_t threshold = 5;
     };
-};
-
-#endif // __AREASBUILDER_HXX__
\ No newline at end of file
+}
index 1f63ae163bc1e79642f274c13cdd9f689afa69ea..b312932e1aa9b267543316158df3f69b6c7b5369 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2024  CEA, EDF
+# Copyright (C) 2024  CEA, EDF
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -35,7 +35,6 @@ INCLUDE_DIRECTORIES(
   ${MEDFILE_INCLUDE_DIRS}
   ${HDF5_INCLUDE_DIRS}
   ${LAPACKE_INCLUDE_DIRS}
-  ${CMAKE_CURRENT_SOURCE_DIR}/../MEDLoader
   ${CMAKE_CURRENT_SOURCE_DIR}/../MEDCoupling
   ${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL
   ${CMAKE_CURRENT_SOURCE_DIR}/../INTERP_KERNEL/Bases
@@ -49,15 +48,15 @@ SET(shaperecogn_SOURCES
   AreasBuilder.cxx
   ShapeRecognMeshBuilder.cxx
   ShapeRecognMesh.cxx
+  PrimitiveType.cxx
 )
 
 ADD_LIBRARY(shaperecogn ${shaperecogn_SOURCES})
 SET_TARGET_PROPERTIES(shaperecogn PROPERTIES COMPILE_FLAGS "")
-TARGET_LINK_LIBRARIES(shaperecogn medcouplingcpp medloader ${MEDFILE_C_LIBRARIES} ${HDF5_LIBRARIES} ${LAPACK_LIBRARIES})
+TARGET_LINK_LIBRARIES(shaperecogn medcouplingcpp ${LAPACK_LIBRARIES})
 INSTALL(TARGETS shaperecogn EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${MEDCOUPLING_INSTALL_LIBS})
 
 FILE(GLOB shaperecogn_HEADERS_HXX "${CMAKE_CURRENT_SOURCE_DIR}/*.hxx")
-INSTALL(FILES ${shaperecogn_HEADERS_HXX} DESTINATION ${MEDCOUPLING_INSTALL_HEADERS})
 
 # To allow usage as SWIG dependencies:
 SET(shaperecogn_HEADERS_HXX PARENT_SCOPE)
index 8f1705ace4d49e69732e4929858a1c876f4b5c04..099d7da1efe3a419d0a991710ac04cb5df80d8b0 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2024  CEA, EDF
+// Copyright (C) 2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 
 #include "MathOps.hxx"
+#include "MCIdType.hxx"
 
 #include <algorithm>
 #include <lapacke.h>
 #include <cblas.h>
 #include <iostream>
 #include <cfloat>
+#include <cmath>
+#include <cstdlib>
 
 using namespace MEDCoupling;
 
@@ -64,11 +67,11 @@ std::vector<double> MathOps::lstsqRow(
     std::vector<double> &a,
     const std::vector<double> &b)
 {
-    int m = b.size();
-    int n = 3;
-    int nrhs = 1;
-    int ldb = std::max<int>(m, n);
-    int lds = std::min<int>(m, n);
+    auto m = b.size();
+    std::size_t n = 3;
+    std::size_t nrhs = 1;
+    std::size_t ldb = std::max<std::size_t>(m, n);
+    std::size_t lds = std::min<std::size_t>(m, n);
     std::vector<double> x(ldb, 0.0);
     for (size_t i = 0; i < b.size(); ++i)
         x[i] = b[i];
@@ -77,9 +80,9 @@ std::vector<double> MathOps::lstsqRow(
     int rank = 0;
     int info = LAPACKE_dgelsd(
         LAPACK_ROW_MAJOR,
-        m, n, nrhs,
-        a.data(), n,
-        x.data(), nrhs,
+        FromIdType<int>(m), FromIdType<int>(n), FromIdType<int>(nrhs),
+        a.data(), FromIdType<int>(n),
+        x.data(), FromIdType<int>(nrhs),
         s.data(),
         rcond,
         &rank);
@@ -152,7 +155,7 @@ double MathOps::mean(const std::vector<double> &values)
     double mean = 0.0;
     for (double value : values)
         mean += value;
-    return mean / values.size();
+    return mean / double( values.size() );
 }
 
 std::array<double, 3> MathOps::meanCoordinates(const std::vector<double> &coordinates)
@@ -165,9 +168,9 @@ std::array<double, 3> MathOps::meanCoordinates(const std::vector<double> &coordi
         coordsMean[1] += coordinates[3 * nodeId + 1];
         coordsMean[2] += coordinates[3 * nodeId + 2];
     }
-    coordsMean[0] /= nbNodes;
-    coordsMean[1] /= nbNodes;
-    coordsMean[2] /= nbNodes;
+    coordsMean[0] /= double( nbNodes );
+    coordsMean[1] /= double( nbNodes );
+    coordsMean[2] /= double( nbNodes );
     return coordsMean;
 }
 
@@ -234,13 +237,13 @@ double MathOps::computeQuantile(const std::vector<double> &values, double q)
 {
     std::vector<double> sortedValues(values);
     std::sort(sortedValues.begin(), sortedValues.end());
-    double pos = q * (sortedValues.size() - 1);
+    double pos = q * double(sortedValues.size() - 1);
     size_t index = static_cast<size_t>(pos);
-    if (pos == index)
+    if ( std::abs( pos - double(index) ) < 1e-12 )
         return sortedValues[index];
     else
     {
-        double frac = pos - index;
+        double frac = pos - double(index);
         return sortedValues[index] * (1 - frac) + sortedValues[index + 1] * frac;
     }
 }
@@ -265,7 +268,7 @@ std::vector<double> MathOps::computeAngles(
     cblas_dgemv(
         CBLAS_LAYOUT::CblasRowMajor,
         CBLAS_TRANSPOSE::CblasNoTrans,
-        nbDirections, 3, 1.0,
+        int(nbDirections), 3, 1.0,
         directions.data(), 3,
         axis.data(), 1,
         0.0, angles.data(), 1);
index e511845da16639aa48ac30f69ef68cc3541b429a..a0ba03e3d576ddd92ee85174c367756157ef5685 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2024  CEA, EDF
+// Copyright (C) 2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -17,8 +17,7 @@
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#ifndef __MATHOPS_HXX__
-#define __MATHOPS_HXX__
+#pragma once
 
 #include <vector>
 #include <array>
@@ -66,6 +65,4 @@ namespace MEDCoupling
         static double computeVariance(std::vector<double> values);
         static std::array<double, 6> computeBaseFromNormal(std::array<double, 3> normal);
     };
-};
-
-#endif //__MATHOPS_HXX__
+}
index 615971ad4c1d3ea427c34634786a65ca0769988c..885c908682aa2929d85e8a101abd2d2c3590afe0 100644 (file)
@@ -1,3 +1,22 @@
+// Copyright (C) 2024  CEA, EDF
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
 #include "Nodes.hxx"
 
 using namespace MEDCoupling;
@@ -10,13 +29,6 @@ Nodes::Nodes(
 {
 }
 
-Nodes::~Nodes()
-{
-    mesh->decrRef();
-    neighbors->decrRef();
-    neighborsIdx->decrRef();
-}
-
 mcIdType Nodes::getNbNodes() const
 {
     return coords->getNumberOfTuples();
index 1d47d3060a923b3c8844b74e642747f9c397dd81..fbd445736396ffb5c3eae5c0dc03f77c6979b339 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2024  CEA, EDF
+// Copyright (C) 2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -17,8 +17,7 @@
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#ifndef __NODES_HXX__
-#define __NODES_HXX__
+#pragma once
 
 #include <vector>
 #include "MEDCouplingUMesh.hxx"
@@ -33,7 +32,7 @@ namespace MEDCoupling
         Nodes(const MEDCouplingUMesh *mesh,
               const DataArrayInt64 *neighbors,
               const DataArrayInt64 *neighborsIdx);
-        ~Nodes();
+        ~Nodes() = default;
 
         mcIdType getNbNodes() const;
         const std::vector<double> &getK1() const;
@@ -57,13 +56,13 @@ namespace MEDCoupling
         std::array<double, 3> getCoordinates(mcIdType nodeId) const;
 
     private:
-        const MEDCouplingUMesh *mesh;
+        MCConstAuto<MEDCouplingUMesh> mesh;
         const DataArrayDouble *coords;
         // normals 3 * nbNodes
         std::vector<double> normals;
         // neighbors
-        const DataArrayInt64 *neighbors;
-        const DataArrayInt64 *neighborsIdx;
+        MCConstAuto<DataArrayInt64> neighbors;
+        MCConstAuto<DataArrayInt64> neighborsIdx;
         // curvature
         std::vector<double> k1;
         std::vector<double> k2;
@@ -73,6 +72,4 @@ namespace MEDCoupling
         std::vector<double> mainDirections;
         std::vector<PrimitiveType> primitives;
     };
-};
-
-#endif //__NODES_HXX__
+}
index 1302d32033d5da0440d13181facb93d103248077..ced79eee027e02f8cbc52de62e0acd9120dcaa2f 100644 (file)
@@ -1,3 +1,22 @@
+// Copyright (C) 2024  CEA, EDF
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
 
 #include "NodesBuilder.hxx"
 #include "Nodes.hxx"
@@ -41,15 +60,15 @@ void NodesBuilder::computeNormals()
     }
     //
     nodes->normals.resize(3 * nbNodes, 1.0);
-    DataArrayInt64 *revNodal = DataArrayInt64::New();
-    DataArrayInt64 *revNodalIdx = DataArrayInt64::New();
+    MCAuto<DataArrayInt64> revNodal = DataArrayInt64::New();
+    MCAuto<DataArrayInt64> revNodalIdx = DataArrayInt64::New();
     mesh->getReverseNodalConnectivity(revNodal, revNodalIdx);
     for (size_t nodeId = 0; nodeId < (size_t)nbNodes; nodeId++)
     {
-        int nbCells = revNodalIdx->getIJ(nodeId + 1, 0) -
-                      revNodalIdx->getIJ(nodeId, 0);
+        mcIdType nbCells = revNodalIdx->getIJ(nodeId + 1, 0) -
+                           revNodalIdx->getIJ(nodeId, 0);
         std::vector<mcIdType> cellIds(nbCells, 0);
-        int start = revNodalIdx->getIJ(nodeId, 0);
+        mcIdType start = revNodalIdx->getIJ(nodeId, 0);
         for (size_t i = 0; i < cellIds.size(); ++i)
             cellIds[i] = revNodal->getIJ(start + i, 0);
         double normal = 0.0;
@@ -67,8 +86,6 @@ void NodesBuilder::computeNormals()
         for (size_t i = 0; i < 3; i++)
             nodes->normals[3 * nodeId + i] /= sqrt(normal);
     }
-    revNodal->decrRef();
-    revNodalIdx->decrRef();
 }
 
 void NodesBuilder::computeCurvatures(double tol)
index 19011806435a257859011bccecd0d320a6466fd3..a58e06538015ff29740c82df638f8956f1428d73 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2024  CEA, EDF
+// Copyright (C) 2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -17,8 +17,7 @@
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#ifndef __NODECURVATURECALCULATOR_HXX__
-#define __NODECURVATURECALCULATOR_HXX__
+#pragma once
 
 #include <string>
 #include <vector>
@@ -57,6 +56,4 @@ namespace MEDCoupling
         const MEDCouplingUMesh *mesh;
         Nodes *nodes;
     };
-};
-
-#endif //__NODECURVATURECALCULATOR_HXX__
\ No newline at end of file
+}
diff --git a/src/ShapeRecogn/PrimitiveType.cxx b/src/ShapeRecogn/PrimitiveType.cxx
new file mode 100644 (file)
index 0000000..d380e99
--- /dev/null
@@ -0,0 +1,116 @@
+// Copyright (C) 2024  CEA, EDF
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "PrimitiveType.hxx"
+
+#include <iterator>
+#include <algorithm>
+
+constexpr char PLANE_STR[] = "Plane";
+constexpr char SPHERE_STR[] = "Sphere";
+constexpr char CYLINDER_STR[] = "Cylinder";
+constexpr char CONE_STR[] = "Cone";
+constexpr char TORUS_STR[] = "Torus";
+constexpr char UNKNOWN_STR[] = "Unknown";
+
+std::vector<MEDCoupling::PrimitiveType> MEDCoupling::AllManagedPrimitives()
+{
+  return {PrimitiveType::Plane,PrimitiveType::Sphere,PrimitiveType::Cylinder,PrimitiveType::Cone,PrimitiveType::Torus,PrimitiveType::Unknown};
+}
+
+std::vector<std::string> MEDCoupling::AllManagedPrimitivesStr()
+{
+  std::vector<PrimitiveType> apt( AllManagedPrimitives() );
+  std::vector<std::string> ret;
+  std::transform(apt.begin(),apt.end(),std::back_inserter(ret),[](PrimitiveType type) { return MEDCoupling::ConvertPrimitiveToString(type); } );
+  return ret;
+}
+
+std::string MEDCoupling::ConvertPrimitiveToString(MEDCoupling::PrimitiveType type)
+{
+  std::string typeName;
+  switch (type)
+  {
+  case PrimitiveType::Plane:
+      typeName = PLANE_STR;
+      break;
+  case PrimitiveType::Sphere:
+      typeName = SPHERE_STR;
+      break;
+  case PrimitiveType::Cylinder:
+      typeName = CYLINDER_STR;
+      break;
+  case PrimitiveType::Cone:
+      typeName = CONE_STR;
+      break;
+  case PrimitiveType::Torus:
+      typeName = TORUS_STR;
+      break;
+  case PrimitiveType::Unknown:
+      typeName = UNKNOWN_STR;
+      break;
+  default:
+      break;
+  }
+  return typeName;
+};
+
+MEDCoupling::PrimitiveType MEDCoupling::ConvertStringToPrimitive(const std::string& type)
+{
+  if( type == PLANE_STR )
+    return PrimitiveType::Plane;
+  if( type == SPHERE_STR )
+    return PrimitiveType::Sphere;
+  if( type == CYLINDER_STR )
+    return PrimitiveType::Cylinder;
+  if( type == CONE_STR )
+    return PrimitiveType::Cone;
+  if( type == TORUS_STR )
+    return PrimitiveType::Torus;
+  if( type == UNKNOWN_STR )
+    return PrimitiveType::Unknown;
+  return PrimitiveType::Unknown;
+}
+
+int MEDCoupling::ConvertPrimitiveToInt(MEDCoupling::PrimitiveType type)
+{
+    int typeInt = 5;
+    switch (type)
+    {
+    case PrimitiveType::Plane:
+        typeInt = 0;
+        break;
+    case PrimitiveType::Sphere:
+        typeInt = 1;
+        break;
+    case PrimitiveType::Cylinder:
+        typeInt = 2;
+        break;
+    case PrimitiveType::Cone:
+        typeInt = 3;
+        break;
+    case PrimitiveType::Torus:
+        typeInt = 4;
+        break;
+    case PrimitiveType::Unknown:
+    default:
+        break;
+    }
+    return typeInt;
+}
index b131da84ab0f84c6619ea311052b49305d7c03c3..88f42893214550cd93d538c400b01894f70cc0b5 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2024  CEA, EDF
+// Copyright (C) 2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#ifndef __PRIMITIVETYPE_HXX__
-#define __PRIMITIVETYPE_HXX__
+#pragma once
 
+#include <vector>
 #include <string>
+#include <cstdint>
+
 namespace MEDCoupling
 {
-    enum PrimitiveType
-    {
-        Plane = 0,
-        Sphere = 1,
-        Cylinder = 2,
-        Cone = 3,
-        Torus = 4,
-        Unknown = 5
-    };
+  enum class PrimitiveType : std::uint8_t
+  {
+    Plane = 0,
+    Sphere = 1,
+    Cylinder = 2,
+    Cone = 3,
+    Torus = 4,
+    Unknown = 5
+  };
 
-    inline std::string convertPrimitiveToString(PrimitiveType type)
-    {
-        std::string typeName = "";
-        switch (type)
-        {
-        case PrimitiveType::Plane:
-            typeName = "Plane";
-            break;
-        case PrimitiveType::Sphere:
-            typeName = "Sphere";
-            break;
-        case PrimitiveType::Cylinder:
-            typeName = "Cylinder";
-            break;
-        case PrimitiveType::Cone:
-            typeName = "Cone";
-            break;
-        case PrimitiveType::Torus:
-            typeName = "Torus";
-            break;
-        case PrimitiveType::Unknown:
-            typeName = "Unknown";
-            break;
-        default:
-            break;
-        }
-        return typeName;
-    };
+  std::vector<PrimitiveType> AllManagedPrimitives();
 
-    inline int convertPrimitiveToInt(PrimitiveType type)
-    {
-        int typeInt = 5;
-        switch (type)
-        {
-        case PrimitiveType::Plane:
-            typeInt = 0;
-            break;
-        case PrimitiveType::Sphere:
-            typeInt = 1;
-            break;
-        case PrimitiveType::Cylinder:
-            typeInt = 2;
-            break;
-        case PrimitiveType::Cone:
-            typeInt = 3;
-            break;
-        case PrimitiveType::Torus:
-            typeInt = 4;
-            break;
-        case PrimitiveType::Unknown:
-        default:
-            break;
-        }
-        return typeInt;
-    };
-};
+  std::vector<std::string> AllManagedPrimitivesStr();
 
-#endif // __PRIMITIVETYPE_HXX__
\ No newline at end of file
+  std::string ConvertPrimitiveToString(PrimitiveType type);
+  
+  PrimitiveType ConvertStringToPrimitive(const std::string& type);
+
+  int ConvertPrimitiveToInt(PrimitiveType type);
+};
index 61b9eb4d0b9afb8569dd2899f37657eb9b50dadc..f0e2e39da43a7422fc39ee6bb1ab2c526d5cf8a4 100644 (file)
@@ -16,7 +16,7 @@ A tool leveraging the MEDCoupling library for recognizing canonical shapes in 3D
 >>
 >> shape_recogn_builder = sr.ShapeRecognMeshBuilder("resources/ShapeRecognCone.med")
 >> shape_recogn = shape_recogn_builder.recognize()
->> shape_recogn.save("ShapeRecognCone_areas.med")
+>> #shape_recogn.save("ShapeRecognCone_areas.med")
 ```
 
 ### Without output file
index 4c8ee5f9f894e79d1fefc515db64fb3885d7234d..61b664d097056ef24c00b93ea307e5817c8ad37d 100644 (file)
@@ -1,31 +1,32 @@
-#include "ShapeRecognMesh.hxx"
+// Copyright (C) 2024  CEA, EDF
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 
-#include "MEDLoader.hxx"
+#include "ShapeRecognMesh.hxx"
 
 using namespace MEDCoupling;
 
 ShapeRecognMesh::ShapeRecognMesh()
-    : nodeK1(0), nodeK2(0), nodePrimitiveType(0),
-      nodeNormal(0), areaId(0), areaPrimitiveType(0),
-      areaNormal(0), minorRadius(0), radius(0),
-      angle(0), center(0), axis(0), apex(0)
-{
-}
-ShapeRecognMesh::~ShapeRecognMesh()
+    : nodeK1(nullptr), nodeK2(nullptr), nodePrimitiveType(nullptr),
+      nodeNormal(nullptr), areaId(nullptr), areaPrimitiveType(nullptr),
+      areaNormal(nullptr), minorRadius(nullptr), radius(nullptr),
+      angle(nullptr), center(nullptr), axis(nullptr), apex(nullptr)
 {
-    nodeK1->decrRef();
-    nodeK2->decrRef();
-    nodePrimitiveType->decrRef();
-    nodeNormal->decrRef();
-    areaId->decrRef();
-    areaPrimitiveType->decrRef();
-    areaNormal->decrRef();
-    minorRadius->decrRef();
-    radius->decrRef();
-    angle->decrRef();
-    center->decrRef();
-    axis->decrRef();
-    apex->decrRef();
 }
 
 std::size_t ShapeRecognMesh::getHeapMemorySizeWithoutChildren() const
@@ -57,99 +58,67 @@ ShapeRecognMesh *ShapeRecognMesh::New()
     return new ShapeRecognMesh;
 }
 
-void ShapeRecognMesh::save(const std::string &outputFile, bool writeFromScratch) const
-{
-    // Nodes
-    // - k1
-    WriteField(outputFile, nodeK1, writeFromScratch);
-    // - k2
-    WriteField(outputFile, nodeK2, false);
-    // - primitive types
-    WriteField(outputFile, nodePrimitiveType, false);
-    // - Normal
-    WriteField(outputFile, nodeNormal, false);
-    // Areas
-    // - Area Id
-    WriteField(outputFile, areaId, false);
-    // - Primitive Types
-    WriteField(outputFile, areaPrimitiveType, false);
-    // - Normal
-    WriteField(outputFile, areaNormal, false);
-    // - Minor Radius
-    WriteField(outputFile, minorRadius, false);
-    // - Radius
-    WriteField(outputFile, radius, false);
-    // - Angle
-    WriteField(outputFile, angle, false);
-    // - Center
-    WriteField(outputFile, center, false);
-    // - Axis
-    WriteField(outputFile, axis, false);
-    // - Apex
-    WriteField(outputFile, apex, false);
-}
-
-MEDCouplingFieldDouble *ShapeRecognMesh::getNodeK1() const
+const MEDCouplingFieldDouble *ShapeRecognMesh::getNodeK1() const
 {
     return nodeK1;
 }
 
-MEDCouplingFieldDouble *ShapeRecognMesh::getNodeK2() const
+const MEDCouplingFieldDouble *ShapeRecognMesh::getNodeK2() const
 {
     return nodeK2;
 }
 
-MEDCouplingFieldDouble *ShapeRecognMesh::getNodePrimitiveType() const
+const MEDCouplingFieldInt32 *ShapeRecognMesh::getNodePrimitiveType() const
 {
     return nodePrimitiveType;
 }
 
-MEDCouplingFieldDouble *ShapeRecognMesh::getNodeNormal() const
+const MEDCouplingFieldDouble *ShapeRecognMesh::getNodeNormal() const
 {
     return nodeNormal;
 }
 
-MEDCouplingFieldDouble *ShapeRecognMesh::getAreaId() const
+const MEDCouplingFieldInt32 *ShapeRecognMesh::getAreaId() const
 {
     return areaId;
 }
 
-MEDCouplingFieldDouble *ShapeRecognMesh::getAreaPrimitiveType() const
+const MEDCouplingFieldInt32 *ShapeRecognMesh::getAreaPrimitiveType() const
 {
     return areaPrimitiveType;
 }
 
-MEDCouplingFieldDouble *ShapeRecognMesh::getAreaNormal() const
+const MEDCouplingFieldDouble *ShapeRecognMesh::getAreaNormal() const
 {
     return areaNormal;
 }
 
-MEDCouplingFieldDouble *ShapeRecognMesh::getMinorRadius() const
+const MEDCouplingFieldDouble *ShapeRecognMesh::getMinorRadius() const
 {
     return minorRadius;
 }
 
-MEDCouplingFieldDouble *ShapeRecognMesh::getRadius() const
+const MEDCouplingFieldDouble *ShapeRecognMesh::getRadius() const
 {
     return radius;
 }
 
-MEDCouplingFieldDouble *ShapeRecognMesh::getAngle() const
+const MEDCouplingFieldDouble *ShapeRecognMesh::getAngle() const
 {
     return angle;
 }
 
-MEDCouplingFieldDouble *ShapeRecognMesh::getCenter() const
+const MEDCouplingFieldDouble *ShapeRecognMesh::getCenter() const
 {
     return center;
 }
 
-MEDCouplingFieldDouble *ShapeRecognMesh::getAxis() const
+const MEDCouplingFieldDouble *ShapeRecognMesh::getAxis() const
 {
     return axis;
 }
 
-MEDCouplingFieldDouble *ShapeRecognMesh::getApex() const
+const MEDCouplingFieldDouble *ShapeRecognMesh::getApex() const
 {
     return apex;
 }
index 02983e34a888841217348eeca75b1874dc83cec8..efbb312e8bbc5c17b08e3c59b49d61c19567a591 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2024  CEA, EDF
+// Copyright (C) 2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#ifndef __SHAPERECOGNMESH_HXX__
-#define __SHAPERECOGNMESH_HXX__
+#pragma once
 
 #include <string>
 
 #include "MEDCouplingUMesh.hxx"
+#include "MEDCouplingFieldInt32.hxx"
 #include "MEDCouplingFieldDouble.hxx"
 #include "MEDCouplingRefCountObject.hxx"
 
@@ -37,44 +37,45 @@ namespace MEDCoupling
         std::size_t getHeapMemorySizeWithoutChildren() const;
         std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
 
-        void save(const std::string &outputFile, bool writeFromScratch = true) const;
-
         // Node properties
-        MEDCoupling::MEDCouplingFieldDouble *getNodeK1() const;
-        MEDCoupling::MEDCouplingFieldDouble *getNodeK2() const;
-        MEDCoupling::MEDCouplingFieldDouble *getNodePrimitiveType() const;
-        MEDCoupling::MEDCouplingFieldDouble *getNodeNormal() const;
+        const MEDCouplingFieldDouble *getNodeK1() const;
+        const MEDCouplingFieldDouble *getNodeK2() const;
+        const MEDCouplingFieldInt32  *getNodePrimitiveType() const;
+        const MEDCouplingFieldDouble *getNodeNormal() const;
+        // see ShapeRecognMeshBuilder::buildNodeWeakDirections
+        // see ShapeRecognMeshBuilder::buildNodeMainDirections
 
         // Area properties
-        MEDCoupling::MEDCouplingFieldDouble *getAreaId() const;
-        MEDCoupling::MEDCouplingFieldDouble *getAreaPrimitiveType() const;
-        MEDCoupling::MEDCouplingFieldDouble *getAreaNormal() const;
-        MEDCoupling::MEDCouplingFieldDouble *getMinorRadius() const;
-        MEDCoupling::MEDCouplingFieldDouble *getRadius() const;
-        MEDCoupling::MEDCouplingFieldDouble *getAngle() const;
-        MEDCoupling::MEDCouplingFieldDouble *getCenter() const;
-        MEDCoupling::MEDCouplingFieldDouble *getAxis() const;
-        MEDCoupling::MEDCouplingFieldDouble *getApex() const;
+        const MEDCouplingFieldInt32  *getAreaId() const;
+        const MEDCouplingFieldInt32  *getAreaPrimitiveType() const;
+        const MEDCouplingFieldDouble *getAreaNormal() const;
+        const MEDCouplingFieldDouble *getMinorRadius() const;
+        const MEDCouplingFieldDouble *getRadius() const;
+        const MEDCouplingFieldDouble *getAngle() const;
+        const MEDCouplingFieldDouble *getCenter() const;
+        const MEDCouplingFieldDouble *getAxis() const;
+        const MEDCouplingFieldDouble *getApex() const;
+        
+        // see ShapeRecognMeshBuilder::buildAreaAxisPoint
+        // see ShapeRecognMeshBuilder::buildAreaAffinePoint
 
     protected:
         ShapeRecognMesh();
-        ~ShapeRecognMesh();
+        ~ShapeRecognMesh() = default;
 
     private:
-        MEDCoupling::MEDCouplingFieldDouble *nodeK1;
-        MEDCoupling::MEDCouplingFieldDouble *nodeK2;
-        MEDCoupling::MEDCouplingFieldDouble *nodePrimitiveType;
-        MEDCoupling::MEDCouplingFieldDouble *nodeNormal;
-        MEDCoupling::MEDCouplingFieldDouble *areaId;
-        MEDCoupling::MEDCouplingFieldDouble *areaPrimitiveType;
-        MEDCoupling::MEDCouplingFieldDouble *areaNormal;
-        MEDCoupling::MEDCouplingFieldDouble *minorRadius;
-        MEDCoupling::MEDCouplingFieldDouble *radius;
-        MEDCoupling::MEDCouplingFieldDouble *angle;
-        MEDCoupling::MEDCouplingFieldDouble *center;
-        MEDCoupling::MEDCouplingFieldDouble *axis;
-        MEDCoupling::MEDCouplingFieldDouble *apex;
+        MCAuto<MEDCouplingFieldDouble> nodeK1;
+        MCAuto<MEDCouplingFieldDouble> nodeK2;
+        MCAuto<MEDCouplingFieldInt32>  nodePrimitiveType;
+        MCAuto<MEDCouplingFieldDouble> nodeNormal;
+        MCAuto<MEDCouplingFieldInt32>  areaId;
+        MCAuto<MEDCouplingFieldInt32>  areaPrimitiveType;
+        MCAuto<MEDCouplingFieldDouble> areaNormal;
+        MCAuto<MEDCouplingFieldDouble> minorRadius;
+        MCAuto<MEDCouplingFieldDouble> radius;
+        MCAuto<MEDCouplingFieldDouble> angle;
+        MCAuto<MEDCouplingFieldDouble> center;
+        MCAuto<MEDCouplingFieldDouble> axis;
+        MCAuto<MEDCouplingFieldDouble> apex;
     };
-};
-
-#endif // __SHAPERECOGNMESH_HXX__
+}
index f0a2b058180d7db897f057983666c85be7b3b90b..8b817eb2e51cbbc6ef91d83c85d76fbccae7d1a3 100644 (file)
@@ -1,39 +1,67 @@
+// Copyright (C) 2024  CEA, EDF
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
 #include "ShapeRecognMeshBuilder.hxx"
 
 #include "NodesBuilder.hxx"
 #include "AreasBuilder.hxx"
-#include "MEDLoader.hxx"
 #include "ShapeRecognMesh.hxx"
+
 #include "MEDCouplingFieldDouble.hxx"
+#include "MEDCouplingFieldInt64.hxx"
+#include "MEDCouplingFieldInt32.hxx"
+
+#include <algorithm>
+#include <iterator>
+#include <limits>
 
 using namespace MEDCoupling;
 
-ShapeRecognMeshBuilder::ShapeRecognMeshBuilder(const std::string &fileName, int meshDimRelToMax)
+ShapeRecognMeshBuilder::ShapeRecognMeshBuilder(MCAuto< MEDCouplingUMesh > mesh)
+{
+    assign( mesh );
+}
+
+ShapeRecognMeshBuilder::ShapeRecognMeshBuilder(MEDCouplingUMesh *mesh)
+{
+    MCAuto< MEDCouplingUMesh > meshIn = MCAuto< MEDCouplingUMesh >::TakeRef( mesh );
+    assign( meshIn );
+}
+
+void ShapeRecognMeshBuilder::assign(MCAuto< MEDCouplingUMesh > mesh)
 {
-    mesh = ReadUMeshFromFile(fileName, meshDimRelToMax);
+    this->mesh = mesh;
     if (mesh->getMeshDimension() != 2)
         throw INTERP_KERNEL::Exception("Expect a mesh with a dimension equal to 2");
     if (mesh->getNumberOfCellsWithType(INTERP_KERNEL::NORM_TRI3) != mesh->getNumberOfCells())
         throw INTERP_KERNEL::Exception("Expect a mesh containing exclusively triangular cells");
 }
 
-ShapeRecognMeshBuilder::~ShapeRecognMeshBuilder()
-{
-    if (areas != nullptr)
-        delete areas;
-    if (nodes != nullptr)
-        delete nodes;
-    mesh->decrRef();
-}
 
-ShapeRecognMesh *ShapeRecognMeshBuilder::recognize()
+MCAuto<ShapeRecognMesh> ShapeRecognMeshBuilder::recognize()
 {
     mesh->incrRef();
     NodesBuilder nodesBuilder(mesh);
-    nodes = nodesBuilder.build();
-    AreasBuilder areasBuilder(nodes);
+    nodes.reset( nodesBuilder.build() );
+    AreasBuilder areasBuilder(nodes.get());
     areasBuilder.build();
-    areas = areasBuilder.getAreas();
+    areas.reset( areasBuilder.getAreas() );
     MCAuto<ShapeRecognMesh> recognMesh = ShapeRecognMesh::New();
     recognMesh->nodeK1 = buildNodeK1();
     recognMesh->nodeK2 = buildNodeK2();
@@ -48,203 +76,253 @@ ShapeRecognMesh *ShapeRecognMeshBuilder::recognize()
     recognMesh->center = buildCenter();
     recognMesh->axis = buildAxis();
     recognMesh->apex = buildApex();
-    return recognMesh.retn();
+    return recognMesh;
 }
 
 const Nodes *ShapeRecognMeshBuilder::getNodes() const
 {
-    return nodes;
+    return nodes.get();
 }
 
 const Areas *ShapeRecognMeshBuilder::getAreas() const
 {
-    return areas;
+    return areas.get();
 }
 
-MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildNodeK1() const
+void ShapeRecognMeshBuilder::checkNodesBeforeBuildingField() const
 {
-    if (nodes == nullptr)
+    if ( ! nodes.get() )
         throw INTERP_KERNEL::Exception("recognize must be called before building any fields");
-    return buildField("K1 (Node)", 1, nodes->getK1());
 }
 
-MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildNodeK2() const
+void ShapeRecognMeshBuilder::checkAreasBeforeBuildingField() const
 {
-    if (nodes == nullptr)
+    if ( ! areas.get() )
         throw INTERP_KERNEL::Exception("recognize must be called before building any fields");
-    return buildField("K2 (Node)", 1, nodes->getK2());
 }
 
-MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildNodePrimitiveType() const
+template <typename T>
+typename Traits<T>::FieldType *buildField(
+    const std::string &name,
+    MCAuto<typename Traits<T>::ArrayType> data,
+    const MEDCouplingUMesh *mesh)
 {
-    if (nodes == nullptr)
-        throw INTERP_KERNEL::Exception("recognize must be called before building any fields");
-    return buildField("Primitive Type (Node)", 1, nodes->getPrimitiveType());
+    using ZeField = typename Traits<T>::FieldType;
+    ZeField *field = ZeField::New(ON_NODES);
+    mcIdType nbNodes = data->getNumberOfTuples();
+    size_t nbOfCompo = data->getNumberOfComponents();
+    field->setName(name);
+    field->setMesh(mesh);
+    if (nbOfCompo == 3)
+    {
+        data->setInfoOnComponent(0, "X");
+        data->setInfoOnComponent(1, "Y");
+        data->setInfoOnComponent(2, "Z");
+    }
+    field->setArray(data);
+    return field;
+}
+
+template <typename T>
+typename Traits<T>::FieldType *buildField(
+    const std::string &name,
+    size_t nbOfCompo,
+    const std::vector<T> &values,
+    const MEDCouplingUMesh *mesh)
+{
+    using ZeArray = typename Traits<T>::ArrayType;
+    mcIdType nbNodes = mesh->getNumberOfNodes();
+    MCAuto<ZeArray> data( ZeArray::New() );
+    data->setName(name);
+    data->alloc(nbNodes, nbOfCompo);
+    std::copy(values.begin(), values.end(), data->getPointer());
+    data->declareAsNew();
+    return buildField<T>(name, data, mesh);
+}
+
+template <typename T>
+typename Traits<T>::FieldType *buildField(
+    const std::string &name,
+    size_t nbOfCompo,
+    T *values,
+    const MEDCouplingUMesh *mesh)
+{
+    using ZeArray = typename Traits<T>::ArrayType;
+    mcIdType nbNodes = mesh->getNumberOfNodes();
+    ZeArray *data = ZeArray::New();
+    data->setName(name);
+    data->useArray(
+        values,
+        true,
+        MEDCoupling::DeallocType::CPP_DEALLOC,
+        nbNodes,
+        nbOfCompo);
+    return buildField<T>(name, data, mesh);
+}
+
+template<class T>
+T *buildAreaArrayT(Areas *areas, Nodes *nodes, std::function<T(Areas *, mcIdType)> areaFunc)
+{
+    const std::vector<Int32> &areaIdByNodes = areas->getAreaIdByNodes();
+    T *values = new T[nodes->getNbNodes()];
+    for (size_t nodeId = 0; nodeId < areaIdByNodes.size(); ++nodeId)
+    {
+        Int32 areaId = areaIdByNodes[nodeId];
+        if (areaId != -1)
+            values[nodeId] = areaFunc(areas, areaId);
+        else
+            values[nodeId] = std::numeric_limits<T>::max();
+    }
+    return values;
+}
+
+MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildNodeK1() const
+{
+    checkNodesBeforeBuildingField();
+    return buildField<double>("K1 (Node)", 1, nodes->getK1(), mesh);
+}
+
+MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildNodeK2() const
+{
+    checkNodesBeforeBuildingField();
+    return buildField<double>("K2 (Node)", 1, nodes->getK2(), mesh);
+}
+
+MEDCouplingFieldInt32 *ShapeRecognMeshBuilder::buildNodePrimitiveType() const
+{
+    checkNodesBeforeBuildingField();
+    std::vector<Int32> tmp;
+    std::transform(nodes->getPrimitiveType().begin(),nodes->getPrimitiveType().end(),std::back_inserter(tmp),[](const PrimitiveType& elt){ return Int32(elt); });
+    return buildField<Int32>("Primitive Type (Node)", 1, tmp, mesh);
 }
 
 MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildNodeNormal() const
 {
-    if (nodes == nullptr)
-        throw INTERP_KERNEL::Exception("recognize must be called before building any fields");
-    return buildField("Normal (Node)", 3, nodes->getNormals());
+    checkNodesBeforeBuildingField();
+    return buildField<double>("Normal (Node)", 3, nodes->getNormals(), mesh);
 }
 
-MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildAreaId() const
+MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ShapeRecognMeshBuilder::buildNodeWeakDirections() const
 {
-    if (areas == nullptr)
-        throw INTERP_KERNEL::Exception("recognize must be called before building any fields");
-    return buildField("Area Id", 1, areas->getAreaIdByNodes());
+    checkNodesBeforeBuildingField();
+    return MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble>(buildField<double>("WeakDirection (Node)", 3, nodes->getWeakDirections(), mesh));
 }
 
-MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildAreaPrimitiveType() const
+MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ShapeRecognMeshBuilder::buildNodeMainDirections() const
 {
-    if (areas == nullptr)
-        throw INTERP_KERNEL::Exception("recognize must be called before building any fields");
-    double *values = buildAreaArray([](Areas *areas, mcIdType areaId) -> double
-                                    { return (double)areas->getPrimitiveType(areaId); });
-    return buildField("Primitive Type (Area)", 1, values);
+    checkNodesBeforeBuildingField();
+    return MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble>(buildField<double>("MainDirection (Node)", 3, nodes->getMainDirections(), mesh));
+}
+
+MEDCouplingFieldInt32 *ShapeRecognMeshBuilder::buildAreaId() const
+{
+    checkAreasBeforeBuildingField();
+    return buildField<Int32>("Area Id", 1, areas->getAreaIdByNodes(), mesh);
+}
+
+MEDCouplingFieldInt32 *ShapeRecognMeshBuilder::buildAreaPrimitiveType() const
+{
+    checkAreasBeforeBuildingField();
+    Int32 *values = buildAreaArrayT<Int32>(areas.get(),nodes.get(),[](Areas *areas, mcIdType areaId) -> Int32
+                                    { return (Int32)areas->getPrimitiveType(areaId); });
+    return buildField<Int32>("Primitive Type (Area)", 1, values, mesh);
 }
 
 MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildAreaNormal() const
 {
-    if (areas == nullptr)
-        throw INTERP_KERNEL::Exception("recognize must be called before building any fields");
+    checkAreasBeforeBuildingField();
     double *values = buildArea3DArray([](Areas *areas, mcIdType areaId) -> const std::array<double, 3> &
                                       { return areas->getNormal(areaId); });
-    return buildField("Normal (Area)", 3, values);
+    return buildField<double>("Normal (Area)", 3, values, mesh);
 }
 
 MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildMinorRadius() const
 {
-    if (areas == nullptr)
-        throw INTERP_KERNEL::Exception("recognize must be called before building any fields");
+    checkAreasBeforeBuildingField();
     double *values = buildAreaArray([](Areas *areas, mcIdType areaId) -> double
                                     { return areas->getMinorRadius(areaId); });
-    return buildField("Minor Radius (Area)", 1, values);
+    return buildField<double>("Minor Radius (Area)", 1, values, mesh);
 }
 
 MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildRadius() const
 {
-    if (areas == nullptr)
-        throw INTERP_KERNEL::Exception("recognize must be called before building any fields");
+    checkAreasBeforeBuildingField();
     double *values = buildAreaArray([](Areas *areas, mcIdType areaId) -> double
                                     { return areas->getRadius(areaId); });
-    return buildField("Radius (Area)", 1, values);
+    return buildField<double>("Radius (Area)", 1, values, mesh);
 }
 
 MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildAngle() const
 {
-    if (areas == nullptr)
-        throw INTERP_KERNEL::Exception("recognize must be called before building any fields");
+    checkAreasBeforeBuildingField();
     double *values = buildAreaArray([](Areas *areas, mcIdType areaId) -> double
                                     { return areas->getAngle(areaId); });
-    return buildField("Angle (Area)", 1, values);
+    return buildField<double>("Angle (Area)", 1, values, mesh);
 }
 
 MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildCenter() const
 {
-    if (areas == nullptr)
-        throw INTERP_KERNEL::Exception("recognize must be called before building any fields");
-    double *values = buildArea3DArray([](Areas *areas, mcIdType areaId) -> const std::array<double, 3> &
+    checkAreasBeforeBuildingField();
+    double *values = buildArea3DArray([](Areas *areas, mcIdType areaId) -> std::array<double, 3>
                                       { return areas->getCenter(areaId); });
-    return buildField("Center (Area)", 3, values);
+    return buildField<double>("Center (Area)", 3, values, mesh);
 }
 
 MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildAxis() const
 {
-    if (areas == nullptr)
-        throw INTERP_KERNEL::Exception("recognize must be called before building any fields");
-    double *values = buildArea3DArray([](Areas *areas, mcIdType areaId) -> const std::array<double, 3> &
+    checkAreasBeforeBuildingField();
+    double *values = buildArea3DArray([](Areas *areas, mcIdType areaId) -> std::array<double, 3>
                                       { return areas->getAxis(areaId); });
-    return buildField("Axis (Area)", 3, values);
+    return buildField<double>("Axis (Area)", 3, values, mesh);
 }
 
 MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildApex() const
 {
-    if (areas == nullptr)
-        throw INTERP_KERNEL::Exception("recognize must be called before building any fields");
-    double *values = buildArea3DArray([](Areas *areas, mcIdType areaId) -> const std::array<double, 3> &
+    checkAreasBeforeBuildingField();
+    double *values = buildArea3DArray([](Areas *areas, mcIdType areaId) -> std::array<double, 3>
                                       { return areas->getApex(areaId); });
-    return buildField("Apex (Area)", 3, values);
-}
-
-template <typename T>
-MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildField(
-    const std::string &name,
-    size_t nbOfCompo,
-    const std::vector<T> &values) const
-{
-    DataArrayDouble *data = DataArrayDouble::New();
-    data->setName(name);
-    data->alloc(nodes->getNbNodes(), nbOfCompo);
-    std::copy(values.begin(), values.end(), data->getPointer());
-    data->declareAsNew();
-    return buildField(name, nbOfCompo, data);
+    return buildField<double>("Apex (Area)", 3, values, mesh);
 }
 
-MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildField(
-    const std::string &name,
-    size_t nbOfCompo,
-    double *values) const
+MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ShapeRecognMeshBuilder::buildAreaAxisPoint() const
 {
-    DataArrayDouble *data = DataArrayDouble::New();
-    data->setName(name);
-    data->useArray(
-        values,
-        true,
-        MEDCoupling::DeallocType::CPP_DEALLOC,
-        nodes->getNbNodes(),
-        nbOfCompo);
-    return buildField(name, nbOfCompo, data);
+    checkAreasBeforeBuildingField();
+    double *values = buildArea3DArray([](Areas *areas, mcIdType areaId) -> std::array<double, 3>
+                                      { return areas->getAxisPoint(areaId); });
+    return MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble>( buildField<double>("AxisPoint (Area)", 3, values, mesh) );
 }
 
-MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildField(
-    const std::string &name,
-    size_t nbOfCompo,
-    DataArrayDouble *data) const
+MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> ShapeRecognMeshBuilder::buildAreaAffinePoint() const
 {
-    MEDCouplingFieldDouble *field = MEDCouplingFieldDouble::New(ON_NODES);
-    field->setName(name);
-    field->setMesh(mesh);
-    if (nbOfCompo == 3)
-    {
-        data->setInfoOnComponent(0, "X");
-        data->setInfoOnComponent(1, "Y");
-        data->setInfoOnComponent(2, "Z");
-    }
-    field->setArray(data);
-    data->decrRef();
-    return field;
+    checkAreasBeforeBuildingField();
+    double *values = buildArea3DArray([](Areas *areas, mcIdType areaId) -> std::array<double, 3>
+                                      { return areas->getAffinePoint(areaId); });
+    return MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble>( buildField<double>("AffinePoint (Area)", 3, values, mesh) );
 }
 
-double *ShapeRecognMeshBuilder::buildArea3DArray(
-    const std::array<double, 3> &(*areaFunc)(Areas *, mcIdType)) const
+double *ShapeRecognMeshBuilder::buildArea3DArray(std::function<std::array<double, 3>(Areas *, Int32)> areaFunc) const
 {
     double *values = new double[3 * nodes->getNbNodes()];
-    const std::vector<mcIdType> &areaIdByNodes = areas->getAreaIdByNodes();
+    const std::vector<Int32> &areaIdByNodes = areas->getAreaIdByNodes();
     for (size_t nodeId = 0; nodeId < areaIdByNodes.size(); ++nodeId)
     {
-        mcIdType areaId = areaIdByNodes[nodeId];
+        Int32 areaId = areaIdByNodes[nodeId];
         if (areaId != -1)
         {
-            const std::array<double, 3> &areaValues = areaFunc(areas, areaId);
+            const std::array<double, 3> areaValues( areaFunc(areas.get(), areaId) );
             values[3 * nodeId] = areaValues[0];
             values[3 * nodeId + 1] = areaValues[1];
             values[3 * nodeId + 2] = areaValues[2];
         }
+        else
+        {
+            std::for_each(values + 3 * nodeId, values + 3 * (nodeId + 1), [](double& val) { val = std::numeric_limits<double>::max(); });
+        }
     }
     return values;
 }
 
-double *ShapeRecognMeshBuilder::buildAreaArray(double (*areaFunc)(Areas *, mcIdType)) const
+double *ShapeRecognMeshBuilder::buildAreaArray(std::function<double(Areas *, Int32)> areaFunc) const
 {
-    const std::vector<mcIdType> &areaIdByNodes = areas->getAreaIdByNodes();
-    double *values = new double[nodes->getNbNodes()];
-    for (size_t nodeId = 0; nodeId < areaIdByNodes.size(); ++nodeId)
-    {
-        mcIdType areaId = areaIdByNodes[nodeId];
-        if (areaId != -1)
-            values[nodeId] = areaFunc(areas, areaId);
-    }
-    return values;
+    return buildAreaArrayT<double>(areas.get(), nodes.get(), areaFunc );
 }
index eee7c150739ee06362ae2216d9ad53083e4336c0..ab20016ea23fcaec90223d909a0fface997a9352 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2024  CEA, EDF
+// Copyright (C) 2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#ifndef __SHAPERECOGNMESHBUILDER_HXX__
-#define __SHAPERECOGNMESHBUILDER_HXX__
+#pragma once
 
 #include <string>
 
 #include "MEDCouplingUMesh.hxx"
-#include "MEDCouplingFieldDouble.hxx"
+
+#include "Nodes.hxx"
+#include "Areas.hxx"
+
+#include <memory>
+#include <functional>
 
 namespace MEDCoupling
 {
-    class Nodes;
-    class Areas;
+    class MEDCouplingFieldInt32;
+    class MEDCouplingFieldInt64;
+    class MEDCouplingFieldDouble;
+
     class ShapeRecognMesh;
 
     class ShapeRecognMeshBuilder
     {
     public:
-        ShapeRecognMeshBuilder(const std::string &fileName, int meshDimRelToMax = 0);
-        ~ShapeRecognMeshBuilder();
+        ShapeRecognMeshBuilder(MCAuto< MEDCouplingUMesh > mesh);
+        ShapeRecognMeshBuilder(MEDCouplingUMesh *mesh);
+        ~ShapeRecognMeshBuilder() = default;
 
         const Nodes *getNodes() const;
         const Areas *getAreas() const;
 
-        ShapeRecognMesh *recognize();
+        MCAuto<ShapeRecognMesh> recognize();
+
+        // Node properties
+        MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> buildNodeWeakDirections() const;
+        MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> buildNodeMainDirections() const;
 
+        //Area properties
+        MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> buildAreaAxisPoint() const;
+        MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> buildAreaAffinePoint() const;
     private:
         // Node properties
         MEDCoupling::MEDCouplingFieldDouble *buildNodeK1() const;
         MEDCoupling::MEDCouplingFieldDouble *buildNodeK2() const;
-        MEDCoupling::MEDCouplingFieldDouble *buildNodePrimitiveType() const;
+        MEDCoupling::MEDCouplingFieldInt32  *buildNodePrimitiveType() const;
         MEDCoupling::MEDCouplingFieldDouble *buildNodeNormal() const;
-
+        
         // Area properties
-        MEDCoupling::MEDCouplingFieldDouble *buildAreaId() const;
-        MEDCoupling::MEDCouplingFieldDouble *buildAreaPrimitiveType() const;
+        MEDCoupling::MEDCouplingFieldInt32  *buildAreaId() const;
+        MEDCoupling::MEDCouplingFieldInt32  *buildAreaPrimitiveType() const;
         MEDCoupling::MEDCouplingFieldDouble *buildAreaNormal() const;
         MEDCoupling::MEDCouplingFieldDouble *buildMinorRadius() const;
         MEDCoupling::MEDCouplingFieldDouble *buildRadius() const;
@@ -60,26 +74,14 @@ namespace MEDCoupling
         MEDCoupling::MEDCouplingFieldDouble *buildAxis() const;
         MEDCoupling::MEDCouplingFieldDouble *buildApex() const;
 
-        template <typename T>
-        MEDCouplingFieldDouble *buildField(
-            const std::string &name,
-            size_t nbOfCompo,
-            const std::vector<T> &values) const;
-        MEDCouplingFieldDouble *buildField(
-            const std::string &name,
-            size_t nbOfCompo,
-            double *values) const;
-        MEDCouplingFieldDouble *buildField(
-            const std::string &name,
-            size_t nbOfCompo,
-            DataArrayDouble *values) const;
-        double *buildArea3DArray(const std::array<double, 3> &(*areaFunc)(Areas *, mcIdType)) const;
-        double *buildAreaArray(double (*areaFunc)(Areas *, mcIdType)) const;
-
-        const MEDCouplingUMesh *mesh;
-        Nodes *nodes = nullptr;
-        Areas *areas = nullptr;
+        double *buildArea3DArray(std::function<std::array<double, 3>(Areas *, Int32)> areaFunc) const;
+        double *buildAreaArray(std::function<double(Areas *, Int32)> areaFunc) const;
+        void assign(MCAuto< MEDCouplingUMesh > mesh);
+        void checkNodesBeforeBuildingField() const;
+        void checkAreasBeforeBuildingField() const;
+    private:
+        MCConstAuto< MEDCouplingUMesh > mesh;
+        std::unique_ptr<Nodes> nodes;
+        std::unique_ptr<Areas> areas;
     };
-};
-
-#endif // __SHAPERECOGNMESHBUILDER_HXX__
+}
index 801df4dfa7bf5da188094678bc7da8b55f3dc2aa..02062b44f06badfc965387a1f320a677a8716836 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2024  CEA, EDF
+// Copyright (C) 2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -17,8 +17,7 @@
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#ifndef __SHAPERECOGNCONSTANTS_HXX__
-#define __SHAPERECOGNCONSTANTS_HXX__
+#pragma once
 
 namespace MEDCoupling
 {
@@ -38,6 +37,4 @@ namespace MEDCoupling
     // - Thresholds
     constexpr int THRESHOLD_MIN_NB_NODES = 5;
     constexpr int THRESHOLD_MAX_NB_AREAS = 500;
-};
-
-#endif //__SHAPERECOGNCONSTANTS_HXX__
\ No newline at end of file
+}
index 8e839d15656bfe11bdbd90e3c93c5852f9735feb..1a73c982c3e7d5e64699d70b2263c6ce7351f9f7 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2024  CEA, EDF
+# Copyright (C) 2024  CEA, EDF
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -75,7 +75,6 @@ IF(WIN32)
 ENDIF(WIN32)
 
 INSTALL(TARGETS _ShapeRecogn DESTINATION ${MEDCOUPLING_INSTALL_PYTHON})
-INSTALL(FILES ShapeRecogn.i DESTINATION ${MEDCOUPLING_INSTALL_HEADERS})
 
 SALOME_INSTALL_SCRIPTS(
   ${CMAKE_CURRENT_BINARY_DIR}/ShapeRecogn.py 
index 58893b0c612bec1fc935debaa8e3ef2563075755..0b129593b065128c04bfaed421279f0d724eca1e 100644 (file)
+// Copyright (C) 2024  CEA, EDF
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
 %module ShapeRecogn
 
-%include "std_string.i"
-%include "MEDCouplingCommon.i"
+%include "ShapeRecognCommon.i"
 
-%{
-#include "ShapeRecognMesh.hxx"
-#include "ShapeRecognMeshBuilder.hxx"
-using namespace MEDCoupling;
+%pythoncode %{
+def MEDCouplingDataArrayDoubleIadd(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayDouble____iadd___(self, self, *args)
+def MEDCouplingDataArrayDoubleIsub(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayDouble____isub___(self, self, *args)
+def MEDCouplingDataArrayDoubleImul(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayDouble____imul___(self, self, *args)
+def MEDCouplingDataArrayDoubleIdiv(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayDouble____idiv___(self, self, *args)
+def MEDCouplingDataArrayDoubleIpow(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayDouble____ipow___(self, self, *args)
+def MEDCouplingDataArrayInt32Iadd(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayInt32____iadd___(self, self, *args)
+def MEDCouplingDataArrayInt32Isub(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayInt32____isub___(self, self, *args)
+def MEDCouplingDataArrayInt32Imul(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayInt32____imul___(self, self, *args)
+def MEDCouplingDataArrayInt32Idiv(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayInt32____idiv___(self, self, *args)
+def MEDCouplingDataArrayInt32Imod(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayInt32____imod___(self, self, *args)
+def MEDCouplingDataArrayInt32Ipow(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayInt32____ipow___(self, self, *args)
+def MEDCouplingDataArrayInt64Iadd(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayInt64____iadd___(self, self, *args)
+def MEDCouplingDataArrayInt64Isub(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayInt64____isub___(self, self, *args)
+def MEDCouplingDataArrayInt64Imul(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayInt64____imul___(self, self, *args)
+def MEDCouplingDataArrayInt64Idiv(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayInt64____idiv___(self, self, *args)
+def MEDCouplingDataArrayInt64Imod(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayInt64____imod___(self, self, *args)
+def MEDCouplingDataArrayInt64Ipow(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayInt64____ipow___(self, self, *args)
+def MEDCouplingDataArrayFloatIadd(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayFloat____iadd___(self, self, *args)
+def MEDCouplingDataArrayFloatIsub(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayFloat____isub___(self, self, *args)
+def MEDCouplingDataArrayFloatImul(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayFloat____imul___(self, self, *args)
+def MEDCouplingDataArrayFloatIdiv(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayFloat____idiv___(self, self, *args)
+def MEDCouplingDataArrayDoubleTupleIadd(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayDoubleTuple____iadd___(self, self, *args)
+def MEDCouplingDataArrayDoubleTupleIsub(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayDoubleTuple____isub___(self, self, *args)
+def MEDCouplingDataArrayDoubleTupleImul(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayDoubleTuple____imul___(self, self, *args)
+def MEDCouplingDataArrayDoubleTupleIdiv(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayDoubleTuple____idiv___(self, self, *args)
+def MEDCouplingDataArrayInt32TupleIadd(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayInt32Tuple____iadd___(self, self, *args)
+def MEDCouplingDataArrayInt32TupleIsub(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayInt32Tuple____isub___(self, self, *args)
+def MEDCouplingDataArrayInt32TupleImul(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayInt32Tuple____imul___(self, self, *args)
+def MEDCouplingDataArrayInt32TupleIdiv(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayInt32Tuple____idiv___(self, self, *args)
+def MEDCouplingDataArrayInt32TupleImod(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayInt32Tuple____imod___(self, self, *args)
+def MEDCouplingDataArrayInt64TupleIadd(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayInt64Tuple____iadd___(self, self, *args)
+def MEDCouplingDataArrayInt64TupleIsub(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayInt64Tuple____isub___(self, self, *args)
+def MEDCouplingDataArrayInt64TupleImul(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayInt64Tuple____imul___(self, self, *args)
+def MEDCouplingDataArrayInt64TupleIdiv(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayInt64Tuple____idiv___(self, self, *args)
+def MEDCouplingDataArrayInt64TupleImod(self,*args):
+    import _MEDRenumber
+    return _MEDRenumber.DataArrayInt64Tuple____imod___(self, self, *args)
 %}
 
-%ignore getAreas() const;
-%ignore getNodes() const;
-%include "ShapeRecognMesh.hxx"
-%include "ShapeRecognMeshBuilder.hxx"
+
+%pythoncode %{
+InterpKernelException.__reduce__=INTERPKERNELExceptionReduce
+DataArrayDouble.__reduce__=MEDCouplingDataArrayDoubleReduce
+DataArrayDouble.__iadd__=MEDCouplingDataArrayDoubleIadd
+DataArrayDouble.__isub__=MEDCouplingDataArrayDoubleIsub
+DataArrayDouble.__imul__=MEDCouplingDataArrayDoubleImul
+DataArrayDouble.__idiv__=MEDCouplingDataArrayDoubleIdiv
+DataArrayDouble.__ipow__=MEDCouplingDataArrayDoubleIpow
+
+DataArrayInt32.__reduce__=MEDCouplingDataArrayInt32Reduce
+DataArrayInt32.__iadd__=MEDCouplingDataArrayInt32Iadd
+DataArrayInt32.__isub__=MEDCouplingDataArrayInt32Isub
+DataArrayInt32.__imul__=MEDCouplingDataArrayInt32Imul
+DataArrayInt32.__idiv__=MEDCouplingDataArrayInt32Idiv
+DataArrayInt32.__imod__=MEDCouplingDataArrayInt32Imod
+DataArrayInt32.__ipow__=MEDCouplingDataArrayInt32Ipow
+DataArrayInt64.__reduce__=MEDCouplingDataArrayInt64Reduce
+DataArrayInt64.__iadd__=MEDCouplingDataArrayInt64Iadd
+DataArrayInt64.__isub__=MEDCouplingDataArrayInt64Isub
+DataArrayInt64.__imul__=MEDCouplingDataArrayInt64Imul
+DataArrayInt64.__idiv__=MEDCouplingDataArrayInt64Idiv
+DataArrayInt64.__imod__=MEDCouplingDataArrayInt64Imod
+DataArrayInt64.__ipow__=MEDCouplingDataArrayInt64Ipow
+
+DataArrayDoubleTuple.__iadd__=MEDCouplingDataArrayDoubleTupleIadd
+DataArrayDoubleTuple.__isub__=MEDCouplingDataArrayDoubleTupleIsub
+DataArrayDoubleTuple.__imul__=MEDCouplingDataArrayDoubleTupleImul
+DataArrayDoubleTuple.__idiv__=MEDCouplingDataArrayDoubleTupleIdiv
+
+DataArrayInt32Tuple.__iadd__=MEDCouplingDataArrayInt32TupleIadd
+DataArrayInt32Tuple.__isub__=MEDCouplingDataArrayInt32TupleIsub
+DataArrayInt32Tuple.__imul__=MEDCouplingDataArrayInt32TupleImul
+DataArrayInt32Tuple.__idiv__=MEDCouplingDataArrayInt32TupleIdiv
+DataArrayInt32Tuple.__itruediv__=MEDCouplingDataArrayInt32TupleIdiv
+DataArrayInt32Tuple.__ifloordiv__=MEDCouplingDataArrayInt32TupleIdiv
+DataArrayInt32Tuple.__imod__=MEDCouplingDataArrayInt32TupleImod
+
+DataArrayInt64Tuple.__iadd__=MEDCouplingDataArrayInt64TupleIadd
+DataArrayInt64Tuple.__isub__=MEDCouplingDataArrayInt64TupleIsub
+DataArrayInt64Tuple.__imul__=MEDCouplingDataArrayInt64TupleImul
+DataArrayInt64Tuple.__idiv__=MEDCouplingDataArrayInt64TupleIdiv
+DataArrayInt64Tuple.__itruediv__=MEDCouplingDataArrayInt64TupleIdiv
+DataArrayInt64Tuple.__ifloordiv__=MEDCouplingDataArrayInt64TupleIdiv
+DataArrayInt64Tuple.__imod__=MEDCouplingDataArrayInt64TupleImod
+
+
+
+
+del INTERPKERNELExceptionReduce
+del MEDCouplingDataArrayDoubleIadd
+del MEDCouplingDataArrayDoubleIdiv
+del MEDCouplingDataArrayDoubleImul
+del MEDCouplingDataArrayDoubleIpow
+del MEDCouplingDataArrayDoubleIsub
+del MEDCouplingDataArrayDoubleReduce
+del MEDCouplingDataArrayDoubleTupleIadd
+del MEDCouplingDataArrayDoubleTupleIdiv
+del MEDCouplingDataArrayDoubleTupleImul
+del MEDCouplingDataArrayDoubleTupleIsub
+del MEDCouplingDataArrayInt32Iadd
+del MEDCouplingDataArrayInt32Idiv
+del MEDCouplingDataArrayInt32Imod
+del MEDCouplingDataArrayInt32Imul
+del MEDCouplingDataArrayInt32Ipow
+del MEDCouplingDataArrayInt32Isub
+del MEDCouplingDataArrayInt32Reduce
+del MEDCouplingDataArrayInt32TupleIadd
+del MEDCouplingDataArrayInt32TupleIdiv
+del MEDCouplingDataArrayInt32TupleImod
+del MEDCouplingDataArrayInt32TupleImul
+del MEDCouplingDataArrayInt32TupleIsub
+del MEDCouplingDataArrayInt64Iadd
+del MEDCouplingDataArrayInt64Idiv
+del MEDCouplingDataArrayInt64Imod
+del MEDCouplingDataArrayInt64Imul
+del MEDCouplingDataArrayInt64Ipow
+del MEDCouplingDataArrayInt64Isub
+del MEDCouplingDataArrayInt64Reduce
+del MEDCouplingDataArrayInt64TupleIadd
+del MEDCouplingDataArrayInt64TupleIdiv
+del MEDCouplingDataArrayInt64TupleImod
+del MEDCouplingDataArrayInt64TupleImul
+del MEDCouplingDataArrayInt64TupleIsub
+
+%}
diff --git a/src/ShapeRecogn/Swig/ShapeRecognCommon.i b/src/ShapeRecogn/Swig/ShapeRecognCommon.i
new file mode 100644 (file)
index 0000000..66e9592
--- /dev/null
@@ -0,0 +1,61 @@
+// Copyright (C) 2024  CEA, EDF
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+%include "std_string.i"
+%include "MEDCouplingCommon.i"
+
+%{
+#include "MEDCouplingMemArray.txx"
+#include "MCAuto.hxx"
+#include "MEDCouplingDataArrayTypemaps.i"
+
+using namespace MEDCoupling;
+using namespace INTERP_KERNEL;
+%}
+
+#ifdef WITH_NUMPY
+%init %{ import_array(); %}
+#endif
+
+%init %{ initializeMe_shape_recogn(); %}
+
+%feature("autodoc", "1");
+%feature("docstring");
+
+%nodefaultctor;
+
+%rename (InterpKernelException) INTERP_KERNEL::Exception;
+
+%{
+  void initializeMe_shape_recogn()
+  {// AGY : here initialization of C++ traits in MEDCouplingDataArrayTypemaps.i for code factorization. Awful, I know, but no other solutions.
+    SWIGTITraits<double>::TI=SWIGTYPE_p_MEDCoupling__DataArrayDouble;
+    SWIGTITraits<float>::TI=SWIGTYPE_p_MEDCoupling__DataArrayFloat;
+  }
+%}
+
+%include "ShapeRecognImpl.i"
+
+%pythoncode %{
+import os
+__filename=os.environ.get('PYTHONSTARTUP')
+if __filename and os.path.isfile(__filename):
+  with open(__filename) as __fp:
+        exec(__fp.read())
+%}
diff --git a/src/ShapeRecogn/Swig/ShapeRecognImpl.i b/src/ShapeRecogn/Swig/ShapeRecognImpl.i
new file mode 100644 (file)
index 0000000..0d894c7
--- /dev/null
@@ -0,0 +1,246 @@
+// Copyright (C) 2024  CEA, EDF
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+%{
+#include "ShapeRecognMesh.hxx"
+#include "ShapeRecognMeshBuilder.hxx"
+#include "Areas.hxx"
+ #include <type_traits>                
+%}
+
+%feature("unref") ShapeRecognMesh "$this->decrRef();"
+
+%newobject Areas::getNodeIds;
+
+%newobject ShapeRecognMeshBuilder::recognize;
+
+%newobject ShapeRecognMesh::getNodeK1;
+%newobject ShapeRecognMesh::getNodeK2;
+%newobject ShapeRecognMesh::getNodePrimitiveType;
+%newobject ShapeRecognMesh::getNodeNormal;
+%newobject ShapeRecognMesh::getAreaId;
+%newobject ShapeRecognMesh::getAreaPrimitiveType;
+%newobject ShapeRecognMesh::getAreaNormal;
+%newobject ShapeRecognMesh::getMinorRadius;
+%newobject ShapeRecognMesh::getRadius;
+%newobject ShapeRecognMesh::getAngle;
+%newobject ShapeRecognMesh::getCenter;
+%newobject ShapeRecognMesh::getAxis;
+%newobject ShapeRecognMesh::getApex;
+%newobject ShapeRecognMeshBuilder::buildNodeWeakDirections;
+%newobject ShapeRecognMeshBuilder::buildNodeMainDirections;
+%newobject ShapeRecognMeshBuilder::buildAreaAxisPoint;
+%newobject ShapeRecognMeshBuilder::buildAreaAffinePoint;
+
+%rename (ConvertStringToPrimitive) ConvertStringToPrimitiveSwig;
+%rename (ConvertPrimitiveToString) ConvertPrimitiveToStringSwig;
+
+class Areas
+{
+public:
+    double getMinorRadius(mcIdType areaId) const;
+    double getRadius(mcIdType areaId) const;
+    double getAngle(mcIdType areaId) const;
+    //
+    bool isEmpty(mcIdType areaId) const;
+    size_t getNumberOfAreas() const;
+    size_t getNumberOfNodes(mcIdType areaId) const;
+    int getPrimitiveType(mcIdType areaId) const;
+    std::string getPrimitiveTypeName(mcIdType areaId) const;
+    %extend
+    {
+      DataArrayIdType *getNodeIds(mcIdType areaId) const
+      {
+        const std::vector<mcIdType> &res = self->getNodeIds(areaId);
+        MCAuto< DataArrayIdType > ret( DataArrayIdType::New() );
+        ret->alloc(res.size(),1);
+        std::copy(res.begin(),res.end(),ret->getPointer());
+        return ret.retn();
+      }
+    }
+private:
+    Areas();
+    ~Areas();
+};
+
+using namespace MEDCoupling;
+
+std::vector<std::string> AllManagedPrimitivesStr();
+
+%inline
+{
+  std::string ConvertPrimitiveToStringSwig(int type)
+  {
+    return ConvertPrimitiveToString(static_cast<PrimitiveType>(type));
+  }
+  
+  int ConvertStringToPrimitiveSwig(const std::string& type)
+  {
+    return static_cast<std::underlying_type_t<PrimitiveType>>( ConvertStringToPrimitive(type) );
+  }
+}
+
+class ShapeRecognMesh : public RefCountObject
+{
+public:
+    ~ShapeRecognMesh();
+    %extend
+    {
+      // Node properties
+      MEDCouplingFieldDouble *getNodeK1() const
+      {
+          MEDCouplingFieldDouble *ret = const_cast<MEDCouplingFieldDouble *>( self->getNodeK1() );
+          ret->incrRef();
+          return ret;
+      }
+
+      MEDCouplingFieldDouble *getNodeK2() const
+      {
+          MEDCouplingFieldDouble *ret = const_cast<MEDCouplingFieldDouble *>( self->getNodeK2() );
+          ret->incrRef();
+          return ret;
+      }
+
+      MEDCouplingFieldInt32 *getNodePrimitiveType() const
+      {
+          MEDCouplingFieldInt32 *ret = const_cast<MEDCouplingFieldInt32 *>( self->getNodePrimitiveType() );
+          ret->incrRef();
+          return ret;
+      }
+      
+      MEDCouplingFieldDouble *getNodeNormal() const
+      {
+          MEDCouplingFieldDouble *ret = const_cast<MEDCouplingFieldDouble *>( self->getNodeNormal() );
+          ret->incrRef();
+          return ret;
+      }
+
+      // Area properties
+
+      MEDCouplingFieldInt32 *getAreaId() const
+      {
+          MEDCouplingFieldInt32 *ret = const_cast<MEDCouplingFieldInt32 *>( self->getAreaId() );
+          ret->incrRef();
+          return ret;
+      }
+      
+      MEDCouplingFieldInt32 *getAreaPrimitiveType() const
+      {
+          MEDCouplingFieldInt32 *ret = const_cast<MEDCouplingFieldInt32 *>( self->getAreaPrimitiveType() );
+          ret->incrRef();
+          return ret;
+      }
+      
+      MEDCouplingFieldDouble *getAreaNormal() const
+      {
+          MEDCouplingFieldDouble *ret = const_cast<MEDCouplingFieldDouble *>( self->getAreaNormal() );
+          ret->incrRef();
+          return ret;
+      }
+      
+      MEDCouplingFieldDouble *getMinorRadius() const
+      {
+          MEDCouplingFieldDouble *ret = const_cast<MEDCouplingFieldDouble *>( self->getMinorRadius() );
+          ret->incrRef();
+          return ret;
+      }
+      
+      MEDCouplingFieldDouble *getRadius() const
+      {
+          MEDCouplingFieldDouble *ret = const_cast<MEDCouplingFieldDouble *>( self->getRadius() );
+          ret->incrRef();
+          return ret;
+      }
+
+      MEDCouplingFieldDouble *getAngle() const
+      {
+          MEDCouplingFieldDouble *ret = const_cast<MEDCouplingFieldDouble *>( self->getAngle() );
+          ret->incrRef();
+          return ret;
+      }
+      
+      MEDCouplingFieldDouble *getCenter() const
+      {
+          MEDCouplingFieldDouble *ret = const_cast<MEDCouplingFieldDouble *>( self->getCenter() );
+          ret->incrRef();
+          return ret;
+      }
+      
+      MEDCouplingFieldDouble *getAxis() const
+      {
+          MEDCouplingFieldDouble *ret = const_cast<MEDCouplingFieldDouble *>( self->getAxis() );
+          ret->incrRef();
+          return ret;
+      }
+
+      MEDCouplingFieldDouble *getApex() const
+      {
+          MEDCouplingFieldDouble *ret = const_cast<MEDCouplingFieldDouble *>( self->getApex() );
+          ret->incrRef();
+          return ret;
+      }
+    }
+private:
+    ShapeRecognMesh();
+};
+
+class ShapeRecognMeshBuilder
+{
+public:
+    ShapeRecognMeshBuilder(MEDCoupling::MEDCouplingUMesh *mesh);
+    ~ShapeRecognMeshBuilder();
+    const Areas *getAreas() const;
+    %extend
+    {
+      MEDCouplingFieldDouble *buildNodeWeakDirections() const
+      {
+          MCAuto<MEDCouplingFieldDouble> ret = self->buildNodeWeakDirections();
+          ret->incrRef();
+          return ret;
+      }
+
+      MEDCouplingFieldDouble *buildNodeMainDirections() const
+      {
+          MCAuto<MEDCouplingFieldDouble> ret = self->buildNodeMainDirections();
+          ret->incrRef();
+          return ret;
+      }
+
+      MEDCouplingFieldDouble *buildAreaAxisPoint() const
+      {
+          MCAuto<MEDCouplingFieldDouble> ret = self->buildAreaAxisPoint();
+          ret->incrRef();
+          return ret;
+      }
+
+      MEDCouplingFieldDouble *buildAreaAffinePoint() const
+      {
+          MCAuto<MEDCouplingFieldDouble> ret = self->buildAreaAffinePoint();
+          ret->incrRef();
+          return ret;
+      }
+    
+      ShapeRecognMesh *recognize()
+      {
+          MCAuto<ShapeRecognMesh> ret = self->recognize();
+          return ret.retn();
+      }
+    }
+};
index 2dc29d57c8630fcc3e4ca8e56b70aa17288d585a..a7df4179afd49f28bcd474b29c3721e641e4f2bc 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2024  CEA, EDF
+# Copyright (C) 2024  CEA, EDF
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -32,6 +32,7 @@ INCLUDE_DIRECTORIES(
 SET(TestShapeRecogn_SOURCES
   TestShapeRecogn.cxx
   MathOpsTest.cxx
+  ShapeRecognTest.cxx
   PlaneTest.cxx
   CylinderTest.cxx
   ConeTest.cxx
@@ -42,24 +43,37 @@ SET(TestShapeRecogn_SOURCES
 SALOME_ACCUMULATE_ENVIRONMENT(MEDCOUPLING_RESOURCE_DIR "${CMAKE_BINARY_DIR}/resources")
 SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env)
 
-ADD_EXECUTABLE(TestShapeRecogn ${TestShapeRecogn_SOURCES})
-TARGET_LINK_LIBRARIES(TestShapeRecogn shaperecogn InterpKernelTestUtils ${CPPUNIT_LIBRARIES} ${PLATFORM_LIBS})
 
-INSTALL(TARGETS TestShapeRecogn DESTINATION ${MEDCOUPLING_INSTALL_BINS})
+IF(NOT MEDCOUPLING_MICROMED)
+  SET(TESTSHAPE_RECOGN0 TestShapeRecogn)
+  ADD_EXECUTABLE(${TESTSHAPE_RECOGN0} ${TestShapeRecogn_SOURCES})
+  TARGET_LINK_LIBRARIES(${TESTSHAPE_RECOGN0} shaperecogn InterpKernelTestUtils medloader ${MEDFILE_C_LIBRARIES} ${HDF5_LIBRARIES} ${CPPUNIT_LIBRARIES} ${PLATFORM_LIBS})
 
-SET(BASE_TESTS TestShapeRecogn)
+  INSTALL(TARGETS ${TESTSHAPE_RECOGN0} DESTINATION ${MEDCOUPLING_INSTALL_BINS})
+  
+  #### Test section
 
-FOREACH(test ${BASE_TESTS})
-  ADD_TEST(NAME ${test}
-           COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/MCTestLauncher.py ${CMAKE_CURRENT_BINARY_DIR}/${test})
-  SET_TESTS_PROPERTIES(${test} PROPERTIES ENVIRONMENT "${tests_env}")
-ENDFOREACH()
+  SET(TEST_INSTALL_DIRECTORY ${MEDCOUPLING_INSTALL_TESTS}/ShapeRecogn)
+  SET(BASE_TESTS ${TESTSHAPE_RECOGN0})
 
-# Application tests
+  FOREACH(test ${BASE_TESTS})
+    ADD_TEST(NAME ${test}
+            COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${test})
+    SET_TESTS_PROPERTIES(${test} PROPERTIES ENVIRONMENT "${tests_env}")
+  ENDFOREACH()
+  INSTALL(TARGETS ${TESTSHAPE_RECOGN0} DESTINATION ${TEST_INSTALL_DIRECTORY})
 
-SET(TEST_INSTALL_DIRECTORY ${MEDCOUPLING_INSTALL_TESTS}/ShapeRecogn)
-INSTALL(TARGETS TestShapeRecogn DESTINATION ${TEST_INSTALL_DIRECTORY})
 
-INSTALL(FILES CTestTestfileInstall.cmake
-        DESTINATION ${TEST_INSTALL_DIRECTORY}
-        RENAME CTestTestfile.cmake)
+  SET(TESTSHAPE_RECOGN1 "TestShapeRecogn.py")
+  SET(test ${TESTSHAPE_RECOGN1})
+  SET(testname "TestShapeRecognPy")
+  ADD_TEST(NAME ${testname} COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${test})
+  SET_TESTS_PROPERTIES(${testname} PROPERTIES ENVIRONMENT "${tests_env}")
+  INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${TESTSHAPE_RECOGN1} DESTINATION ${TEST_INSTALL_DIRECTORY})
+
+  INSTALL(FILES CTestTestfileInstall.cmake
+          DESTINATION ${TEST_INSTALL_DIRECTORY}
+          RENAME CTestTestfile.cmake)
+
+  #### End Test section
+ENDIF(NOT MEDCOUPLING_MICROMED)
index ab32ede46c7d8957b858a423e68bbf883e7dcb80..ae6f6c409887411618af0e6ff6bdd66e058842e3 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 2015-2024  CEA, EDF
+# Copyright (C) 2024  CEA, EDF
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 
-SET(TEST_NAMES
-  TestShapeRecogn
-)
+SET(TEST_NAME "${COMPONENT_NAME}_ShapeRecogn")
+ADD_TEST(${TEST_NAME} TestShapeRecogn)
+SET_TESTS_PROPERTIES( ${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} )
 
-FOREACH(tfile ${TEST_NAMES})
-  SET(TEST_NAME ${COMPONENT_NAME}_${tfile})
-  ADD_TEST(${TEST_NAME} python3 MCTestLauncher.py ${tfile})
-  SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES
-    LABELS "${COMPONENT_NAME}"
-    TIMEOUT ${TIMEOUT}
-    )
-ENDFOREACH()
+SET(tfile "TestShapeRecogn.py")
+set(BASE_NAME "ShapeRecognPy")
+SET(TEST_NAME ${COMPONENT_NAME}_${BASE_NAME})
+ADD_TEST(${TEST_NAME} python3 ${tfile})
+SET_TESTS_PROPERTIES( ${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} )
index d25f4a792f1f98a8e5c34615490c26d1668b3740..2da2193b79fde75c769f8d0a32eecd1e86763e67 100644 (file)
@@ -1,24 +1,44 @@
+// Copyright (C) 2024  CEA, EDF
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
 #include "ConeTest.hxx"
 
 #include "ShapeRecognMeshBuilder.hxx"
+#include "ShapeRecognMesh.hxx"
 #include "Areas.hxx"
 #include "MathOps.hxx"
 #include "TestInterpKernelUtils.hxx" // getResourceFile()
 
+#include "ShapeRecognTest.hxx"
+
 using namespace MEDCoupling;
 
 void ConeTest::setUp()
 {
     std::string file = INTERP_TEST::getResourceFile("ShapeRecognCone.med", 3);
-    srMesh = new ShapeRecognMeshBuilder(file);
+    srMesh = BuildShapeRecognMeshBuilderFromFile(file);
     srMesh->recognize();
     areas = srMesh->getAreas();
 }
 
 void ConeTest::tearDown()
 {
-    if (srMesh != 0)
-        delete srMesh;
     areas = 0;
 }
 
index 20b1bef3fd02e514f77b2315d44c6c6bc6f8e046..5f6d6a154b2c995edb44b37b8f0fb1e86c4cd99b 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2024  CEA, EDF
+// Copyright (C) 2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#ifndef __CONETEST_HXX__
-#define __CONETEST_HXX__
+#pragma once
 
 #include <cppunit/TestFixture.h>
 #include <cppunit/extensions/HelperMacros.h>
 
+#include "ShapeRecognMeshBuilder.hxx"
+
+#include <memory>
+
 namespace MEDCoupling
 {
     class ShapeRecognMeshBuilder;
@@ -54,9 +57,7 @@ namespace MEDCoupling
         void testThirdArea();
 
     private:
-        ShapeRecognMeshBuilder *srMesh = 0;
+        std::unique_ptr<ShapeRecognMeshBuilder> srMesh;
         const Areas *areas;
     };
-};
-
-#endif // __CONETEST_HXX__
+}
index 47f6ac3d3bfd76c005f144e8ff10cd30753ff6d0..2e08bdf10479f20ebf59493dc05a1f7c3045a9e4 100644 (file)
@@ -1,24 +1,44 @@
+// Copyright (C) 2024  CEA, EDF
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
 #include "CylinderTest.hxx"
 
 #include "ShapeRecognMeshBuilder.hxx"
+#include "ShapeRecognMesh.hxx"
 #include "Areas.hxx"
 #include "MathOps.hxx"
 #include "TestInterpKernelUtils.hxx" // getResourceFile()
 
+#include "ShapeRecognTest.hxx"
+
 using namespace MEDCoupling;
 
 void CylinderTest::setUp()
 {
     std::string file = INTERP_TEST::getResourceFile("ShapeRecognCylinder.med", 3);
-    srMesh = new ShapeRecognMeshBuilder(file);
+    srMesh = BuildShapeRecognMeshBuilderFromFile(file);
     srMesh->recognize();
     areas = srMesh->getAreas();
 }
 
 void CylinderTest::tearDown()
 {
-    if (srMesh != 0)
-        delete srMesh;
     areas = 0;
 }
 
index a35ac14817921873150bf878e51c3b1499227e8d..351983b5c9fa292f09fcd1e04d82b1a184d4b16d 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2024  CEA, EDF
+// Copyright (C) 2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#ifndef __CYLINDERTEST_HXX__
-#define __CYLINDERTEST_HXX__
-
 #include <cppunit/TestFixture.h>
 #include <cppunit/extensions/HelperMacros.h>
 
+#include "ShapeRecognMeshBuilder.hxx"
+
+#include <memory>
+
 namespace MEDCoupling
 {
     class ShapeRecognMeshBuilder;
@@ -47,9 +48,7 @@ namespace MEDCoupling
         void testThirdArea();
 
     private:
-        ShapeRecognMeshBuilder *srMesh = 0;
+        std::unique_ptr< ShapeRecognMeshBuilder > srMesh;
         const Areas *areas;
     };
-};
-
-#endif // __CYLINDERTEST_HXX__
+}
index 033f9921b763c0327eee131a85f046020da0cf7e..6841fe097fcee786b0eae7eeaf538170b0ab5d9c 100644 (file)
@@ -1,3 +1,22 @@
+// Copyright (C) 2024  CEA, EDF
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
 #include "MathOpsTest.hxx"
 #include "MathOps.hxx"
 
index 2988a950be40784d4b976052596b664ce75f046e..8cbc635f127de3b1eca4a5cb1b8039cb29aea6f8 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2024  CEA, EDF
+// Copyright (C) 2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -17,8 +17,7 @@
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#ifndef __MATHOPSTEST_HXX__
-#define __MATHOPSTEST_HXX__
+#pragma once
 
 #include <cppunit/TestFixture.h>
 #include <cppunit/extensions/HelperMacros.h>
@@ -46,6 +45,4 @@ namespace MEDCoupling
         static void testComputeAngles();
         static void testComputeBaseFromNormal();
     };
-};
-
-#endif // __MATHOPSTEST_HXX__
+}
index 6f47f161c99e0587c5c7a0c778e03e7434c5c03b..8f41a30f4e431d537982c1ba8ec5a9732820fb02 100644 (file)
@@ -1,24 +1,44 @@
+// Copyright (C) 2024  CEA, EDF
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
 #include "PlaneTest.hxx"
 
 #include "ShapeRecognMeshBuilder.hxx"
+#include "ShapeRecognMesh.hxx"
 #include "Areas.hxx"
 #include "MathOps.hxx"
 #include "TestInterpKernelUtils.hxx" // getResourceFile()
 
+#include "ShapeRecognTest.hxx"
+
 using namespace MEDCoupling;
 
 void PlaneTest::setUp()
 {
     std::string file = INTERP_TEST::getResourceFile("ShapeRecognPlane.med", 3);
-    srMesh = new ShapeRecognMeshBuilder(file);
+    srMesh = BuildShapeRecognMeshBuilderFromFile(file);
     srMesh->recognize();
     areas = srMesh->getAreas();
 }
 
 void PlaneTest::tearDown()
 {
-    if (srMesh != 0)
-        delete srMesh;
     areas = 0;
 }
 
index af6eb47552294b512814f4bde47f6c66793f837c..63e00706315b366b14eeea6e50ee4430643e0361 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2024  CEA, EDF
+// Copyright (C) 2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#ifndef __PLANETEST_HXX__
-#define __PLANETEST_HXX__
+#pragma once
 
 #include <cppunit/TestFixture.h>
 #include <cppunit/extensions/HelperMacros.h>
 
+#include "ShapeRecognMeshBuilder.hxx"
+#include "ShapeRecognTest.hxx"
+
+#include <memory>
+
 namespace MEDCoupling
 {
     class ShapeRecognMeshBuilder;
@@ -41,9 +45,7 @@ namespace MEDCoupling
         void testArea();
 
     private:
-        ShapeRecognMeshBuilder *srMesh = 0;
+        std::unique_ptr<ShapeRecognMeshBuilder> srMesh;
         const Areas *areas;
     };
-};
-
-#endif // __PLANETEST_HXX__
+}
diff --git a/src/ShapeRecogn/Test/ShapeRecognTest.cxx b/src/ShapeRecogn/Test/ShapeRecognTest.cxx
new file mode 100644 (file)
index 0000000..c9faa14
--- /dev/null
@@ -0,0 +1,28 @@
+// Copyright (C) 2024  CEA, EDF
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "ShapeRecognTest.hxx"
+
+#include "MEDLoader.hxx"
+
+std::unique_ptr<MEDCoupling::ShapeRecognMeshBuilder> BuildShapeRecognMeshBuilderFromFile(const std::string& fileName, int meshDimRelToMax)
+{
+    MEDCoupling::MCAuto<MEDCoupling::MEDCouplingUMesh> mesh = MEDCoupling::ReadUMeshFromFile(fileName, 0);
+    return std::make_unique<MEDCoupling::ShapeRecognMeshBuilder>(mesh);
+}
\ No newline at end of file
diff --git a/src/ShapeRecogn/Test/ShapeRecognTest.hxx b/src/ShapeRecogn/Test/ShapeRecognTest.hxx
new file mode 100644 (file)
index 0000000..8f1e39e
--- /dev/null
@@ -0,0 +1,27 @@
+// Copyright (C) 2024  CEA, EDF
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#pragma once
+
+#include "ShapeRecognMeshBuilder.hxx"
+
+#include <string>
+#include <memory>
+
+std::unique_ptr<MEDCoupling::ShapeRecognMeshBuilder> BuildShapeRecognMeshBuilderFromFile(const std::string& fileName, int meshDimRelToMax = 0);
index 4d7f64ecb673aed1ed718acb7cc057f3f5e86041..b219e1ad8edf9c3fa644ba71c095b8e4a48fb700 100644 (file)
@@ -1,24 +1,44 @@
+// Copyright (C) 2024  CEA, EDF
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
 #include "SphereTest.hxx"
 
 #include "ShapeRecognMeshBuilder.hxx"
+#include "ShapeRecognMesh.hxx"
 #include "Areas.hxx"
 #include "MathOps.hxx"
 #include "TestInterpKernelUtils.hxx" // getResourceFile()
 
+#include "ShapeRecognTest.hxx"
+
 using namespace MEDCoupling;
 
 void SphereTest::setUp()
 {
     std::string file = INTERP_TEST::getResourceFile("ShapeRecognSphere.med", 3);
-    srMesh = new ShapeRecognMeshBuilder(file);
+    srMesh = BuildShapeRecognMeshBuilderFromFile(file);
     srMesh->recognize();
     areas = srMesh->getAreas();
 }
 
 void SphereTest::tearDown()
 {
-    if (srMesh != 0)
-        delete srMesh;
     areas = 0;
 }
 
index 6500def00b1561889adfc701ad561ddb70e51b72..833690f3e9419462192f5aaeb63bad9a423e04ec 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2024  CEA, EDF
+// Copyright (C) 2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#ifndef __SPHERETEST_HXX__
-#define __SPHERETEST_HXX__
+#pragma once
 
 #include <cppunit/TestFixture.h>
 #include <cppunit/extensions/HelperMacros.h>
 
+#include "ShapeRecognMeshBuilder.hxx"
+
+#include <memory>
+
 namespace MEDCoupling
 {
     class ShapeRecognMeshBuilder;
@@ -41,9 +44,7 @@ namespace MEDCoupling
         void testArea();
 
     private:
-        ShapeRecognMeshBuilder *srMesh = 0;
+        std::unique_ptr<ShapeRecognMeshBuilder> srMesh;
         const Areas *areas;
     };
-};
-
-#endif // __SPHERETEST_HXX__
+}
index b7cd2af14c8f60c160bd7a185fcbc88aa1e43903..8d07cce9d7db89f9aa93ae437059be091324a375 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2024  CEA, EDF
+// Copyright (C) 2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
diff --git a/src/ShapeRecogn/Test/TestShapeRecogn.py b/src/ShapeRecogn/Test/TestShapeRecogn.py
new file mode 100644 (file)
index 0000000..6d6142d
--- /dev/null
@@ -0,0 +1,80 @@
+#! /usr/bin/env python3
+#  -*- coding: utf-8 -*-
+# Copyright (C) 2024  CEA, EDF
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+import ShapeRecogn as sr
+import MEDLoader as ml
+from numpy.testing import assert_allclose
+import unittest
+
+def getResourceFile(filename, levelUp = 2):
+  ROOT_DIR_0 = "MEDCOUPLING_ROOT_DIR"
+  ROOT_DIR_1 = "MEDCOUPLING_RESOURCE_DIR"
+  import os
+  from pathlib import Path
+  if ROOT_DIR_0 in os.environ:
+      resourceFile = Path( os.environ[ROOT_DIR_0] ).absolute() / "share" / "resources" / "med" / filename
+      if resourceFile.exists():
+        return f"{resourceFile}"
+  if ROOT_DIR_1 in os.environ:
+      resourceFile = Path( os.environ[ROOT_DIR_1].split(":")[-1] ).absolute() / filename
+      if resourceFile.exists():
+        return f"{resourceFile}"
+  p = Path.cwd()
+  for i in range(levelUp):
+     p = p.parent
+  resourceFile = p / "resources" / filename
+  if not resourceFile.exists():
+     raise RuntimeError( f"getResourceFile: could not open resource test file {filename}" )
+  return f"{resourceFile}"
+
+class MEDCouplingIterativeStatisticsTest(unittest.TestCase):
+  def testPlane(self):
+    """
+    Direct translation of PlaneTest::testArea
+    """
+    self.assertEqual( sr.AllManagedPrimitivesStr() , ('Plane', 'Sphere', 'Cylinder', 'Cone', 'Torus', 'Unknown') )
+    fname = "ShapeRecognPlane.med"
+    mesh = ml.ReadUMeshFromFile( getResourceFile( fname, 3 ),0)
+    srMesh = sr.ShapeRecognMeshBuilder( mesh )
+    rem = srMesh.recognize()
+    areas = srMesh.getAreas()
+    self.assertEqual( areas.getNumberOfAreas(), 1 )
+    self.assertEqual( areas.getNumberOfNodes(0), 36 )
+    nodeIds = areas.getNodeIds(0)
+    f = rem.getAreaPrimitiveType()
+    self.assertEqual( areas.getPrimitiveType(0), 0)
+    self.assertEqual( areas.getPrimitiveTypeName(0), "Plane")
+    self.assertEqual( sr.ConvertStringToPrimitive("Plane"),0)
+    self.assertEqual( sr.ConvertPrimitiveToString(0),"Plane")
+    f_normal = rem.getNodeNormal()
+    affinePoint = srMesh.buildAreaAffinePoint().getArray()[ nodeIds[0] ]
+    normal = f_normal.getArray()[ nodeIds[0] ]
+    normalRef = sr.DataArrayDouble([0.781525, 0.310606, -0.541056],1,3)
+    proportion0 = normal[0,0] / normalRef[0,0]
+    proportion1 = normal[0,1] / normalRef[0,1]
+    proportion2 = normal[0,2] / normalRef[0,2]
+    proportion3 = sr.DataArrayDouble.Dot(normal,affinePoint)[0] / sr.DataArrayDouble.Dot(normalRef,affinePoint)[0]
+    assert_allclose([proportion0,proportion1,proportion2,proportion3],[1.0,1.0,1.0,1.0] , rtol = 1e-5)
+    angle = sr.DataArrayDouble.CrossProduct(normal,normalRef).magnitude()[0]
+    assert_allclose( [angle], [0.0], atol = 1e-6 )
+
+if __name__ == "__main__":
+    unittest.main()
index 6e24d10eeb4ad0a10be2ea64ca1f55dd3fa27fc6..fecb7b3642900c11a95a8722493f437bb879ca4c 100644 (file)
@@ -1,24 +1,44 @@
+// Copyright (C) 2024  CEA, EDF
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
 #include "TorusTest.hxx"
 
 #include "ShapeRecognMeshBuilder.hxx"
 #include "Areas.hxx"
 #include "MathOps.hxx"
 #include "TestInterpKernelUtils.hxx" // getResourceFile()
+#include "ShapeRecognMesh.hxx"
+
+#include "ShapeRecognTest.hxx"
 
 using namespace MEDCoupling;
 
 void TorusTest::setUp()
 {
     std::string file = INTERP_TEST::getResourceFile("ShapeRecognTorus.med", 3);
-    srMesh = new ShapeRecognMeshBuilder(file);
+    srMesh = BuildShapeRecognMeshBuilderFromFile(file);
     srMesh->recognize();
     areas = srMesh->getAreas();
 }
 
 void TorusTest::tearDown()
 {
-    if (srMesh != 0)
-        delete srMesh;
     areas = 0;
 }
 
index 07ae86d3aa722c599cec3e9edcd9013505f18131..65890908adb832a576c818a8b1f8b0767dc4197a 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2024  CEA, EDF
+// Copyright (C) 2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#ifndef __TORUSTEST_HXX__
-#define __TORUSTEST_HXX__
+#pragma once
 
 #include <cppunit/TestFixture.h>
 #include <cppunit/extensions/HelperMacros.h>
 
+#include "ShapeRecognMeshBuilder.hxx"
+
+#include <memory>
+
 namespace MEDCoupling
 {
     class ShapeRecognMeshBuilder;
@@ -41,9 +44,7 @@ namespace MEDCoupling
         void testArea();
 
     private:
-        ShapeRecognMeshBuilder *srMesh = 0;
+        std::unique_ptr< ShapeRecognMeshBuilder > srMesh;
         const Areas *areas;
     };
-};
-
-#endif // __TORUSTEST_HXX__
+}