]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
[EDF30834] : Finalization of Swig of recognition shape + python wrapping testing... agy/shaperecogn
authorAnthony Geay <anthony.geay@edf.fr>
Fri, 30 Aug 2024 12:04:52 +0000 (14:04 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Fri, 30 Aug 2024 12:04:52 +0000 (14:04 +0200)
src/PyWrapping/CMakeLists.txt
src/PyWrapping/TestPyWrapGathered_medcoupling.py
src/PyWrapping/medcoupling.i
src/ShapeRecogn/Areas.cxx
src/ShapeRecogn/PrimitiveType.cxx
src/ShapeRecogn/PrimitiveType.hxx
src/ShapeRecogn/ShapeRecognMeshBuilder.cxx
src/ShapeRecogn/Swig/ShapeRecognImpl.i
src/ShapeRecogn/Test/CMakeLists.txt
src/ShapeRecogn/Test/CTestTestfileInstall.cmake
src/ShapeRecogn/Test/TestShapeRecogn.py

index c37d6780d8b2b645b4500dfe53c3061b55853cfb..bb387825a77dc13c41781c0369fed052d2e708b0 100644 (file)
@@ -37,10 +37,6 @@ IF(MEDCOUPLING_USE_64BIT_IDS)
   STRING(APPEND SWIG_MODULE_medcoupling_EXTRA_FLAGS ";-DMEDCOUPLING_USE_64BIT_IDS")
 ENDIF(MEDCOUPLING_USE_64BIT_IDS)
 
-IF(MEDCOUPLING_ENABLE_SHAPERECOGN)
-  LIST(APPEND SWIG_MODULE_medcoupling_EXTRA_FLAGS -DWITH_SHAPE_RECOGN)
-ENDIF(MEDCOUPLING_ENABLE_SHAPERECOGN)
-
 SET(medcoupling_SWIG_DPYS_FILES medcoupling.i)
 
 INCLUDE_DIRECTORIES(
@@ -67,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 OR CYGWIN)
+  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 29e2a82c7db103ef9238ce33d3e74a12b9af53fb..ae66a385b3d7b842337c320bec50b34a7b7e3ed6 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;
 
     return false;
 #endif
   }
+
+  bool HasShapeRecognitionExt()
+  {
+#ifdef WITH_SHAPE_RECOGN
+    return true;
+#else
+    return false;
+#endif
+  }
   
   std::vector<std::string> ActiveExtensions()
   {
index 31d5d39bba620c969d676a805e4ac5e23a7f06b9..2cc82210fefe358da7b26c4255624b81c760186b 100644 (file)
@@ -128,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
index 28038fe35025ee46dad1298353ed0fb8cf47cbdc..d380e996b3edd3956e4b8c7d0d0f7b930a67ae9b 100644 (file)
 #include <iterator>
 #include <algorithm>
 
-std::vector<std::string> MEDCoupling::allManagedPrimitivesStr()
+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::copy();
+  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 8341c8af6364ad264b2f386c40c697d53389cc3c..88f42893214550cd93d538c400b01894f70cc0b5 100644 (file)
 
 #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::vector<PrimitiveType> allManagedPrimitives()
-    {
-        return {Plane,Sphere,Cylinder,Cone,Torus,Unknown};
-    }
+  std::vector<PrimitiveType> AllManagedPrimitives();
 
-    std::vector<std::string> allManagedPrimitivesStr();
+  std::vector<std::string> AllManagedPrimitivesStr();
 
-    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::string ConvertPrimitiveToString(PrimitiveType type);
+  
+  PrimitiveType ConvertStringToPrimitive(const std::string& type);
 
-    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;
-    };
+  int ConvertPrimitiveToInt(PrimitiveType type);
 };
index fea8abe428ac830d9ce716fe9fb87a584f481907..8b817eb2e51cbbc6ef91d83c85d76fbccae7d1a3 100644 (file)
@@ -28,6 +28,7 @@
 #include "MEDCouplingFieldInt32.hxx"
 
 #include <algorithm>
+#include <iterator>
 #include <limits>
 
 using namespace MEDCoupling;
@@ -190,8 +191,9 @@ MEDCouplingFieldDouble *ShapeRecognMeshBuilder::buildNodeK2() const
 MEDCouplingFieldInt32 *ShapeRecognMeshBuilder::buildNodePrimitiveType() const
 {
     checkNodesBeforeBuildingField();
-    const std::vector<PrimitiveType> tmp( nodes->getPrimitiveType() );
-    return buildField<Int32>("Primitive Type (Node)", 1, {tmp.begin(),tmp.end()}, mesh);
+    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
index b1fdeab34c921258c5465bb29a2625fc0e08ca54..0d894c7ce83c8caa8f98ba9414659ed418b27abf 100644 (file)
@@ -21,6 +21,8 @@
 #include "ShapeRecognMesh.hxx"
 #include "ShapeRecognMeshBuilder.hxx"
 #include "Areas.hxx"
+ #include <type_traits>                
 %}
 
 %feature("unref") ShapeRecognMesh "$this->decrRef();"
 %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
 {
@@ -53,6 +62,7 @@ public:
     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
     {
@@ -72,6 +82,21 @@ private:
 
 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:
index 57247a660be812d8eda27f3ac76a9668187a5bff..a7df4179afd49f28bcd474b29c3721e641e4f2bc 100644 (file)
@@ -50,7 +50,10 @@ IF(NOT MEDCOUPLING_MICROMED)
   TARGET_LINK_LIBRARIES(${TESTSHAPE_RECOGN0} shaperecogn InterpKernelTestUtils medloader ${MEDFILE_C_LIBRARIES} ${HDF5_LIBRARIES} ${CPPUNIT_LIBRARIES} ${PLATFORM_LIBS})
 
   INSTALL(TARGETS ${TESTSHAPE_RECOGN0} DESTINATION ${MEDCOUPLING_INSTALL_BINS})
+  
+  #### Test section
 
+  SET(TEST_INSTALL_DIRECTORY ${MEDCOUPLING_INSTALL_TESTS}/ShapeRecogn)
   SET(BASE_TESTS ${TESTSHAPE_RECOGN0})
 
   FOREACH(test ${BASE_TESTS})
@@ -58,13 +61,19 @@ IF(NOT MEDCOUPLING_MICROMED)
             COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${test})
     SET_TESTS_PROPERTIES(${test} PROPERTIES ENVIRONMENT "${tests_env}")
   ENDFOREACH()
+  INSTALL(TARGETS ${TESTSHAPE_RECOGN0} DESTINATION ${TEST_INSTALL_DIRECTORY})
 
-  # Application tests
 
-  SET(TEST_INSTALL_DIRECTORY ${MEDCOUPLING_INSTALL_TESTS}/ShapeRecogn)
-  INSTALL(TARGETS ${TESTSHAPE_RECOGN0} DESTINATION ${TEST_INSTALL_DIRECTORY})
+  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 b636c20a0f509847652569538fa8479db7277c50..ae6f6c409887411618af0e6ff6bdd66e058842e3 100644 (file)
 # 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} ${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 508fc43874d419ffcd521d72332a135e623bdaea..6d6142d96d5fa963ca2665515481105f72e05cc6 100644 (file)
@@ -50,16 +50,20 @@ class MEDCouplingIterativeStatisticsTest(unittest.TestCase):
     """
     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()
-    assert( areas.getNumberOfAreas() == 1 )
-    assert( areas.getNumberOfNodes(0) == 36 )
+    self.assertEqual( areas.getNumberOfAreas(), 1 )
+    self.assertEqual( areas.getNumberOfNodes(0), 36 )
     nodeIds = areas.getNodeIds(0)
     f = rem.getAreaPrimitiveType()
-    assert( areas.getPrimitiveTypeName(0) == "Plane")
+    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] ]