]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
bos #42837: shape recognition - ensure compilation on different os
authorNabil Ghodbane <nabil.ghodbane@cea.fr>
Fri, 20 Sep 2024 07:56:19 +0000 (09:56 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Tue, 24 Sep 2024 08:47:23 +0000 (10:47 +0200)
20 files changed:
CMakeLists.txt
src/ShapeRecogn/Areas.hxx
src/ShapeRecogn/AreasBuilder.hxx
src/ShapeRecogn/MathOps.cxx
src/ShapeRecogn/MathOps.hxx
src/ShapeRecogn/Nodes.hxx
src/ShapeRecogn/NodesBuilder.hxx
src/ShapeRecogn/PrimitiveType.hxx
src/ShapeRecogn/ShapeRecognDefines.hxx [new file with mode: 0644]
src/ShapeRecogn/ShapeRecognMesh.hxx
src/ShapeRecogn/ShapeRecognMeshBuilder.hxx
src/ShapeRecogn/Swig/ShapeRecognImpl.i
src/ShapeRecogn/Test/CMakeLists.txt
src/ShapeRecogn/Test/ConeTest.cxx
src/ShapeRecogn/Test/CylinderTest.cxx
src/ShapeRecogn/Test/MathOpsTest.cxx
src/ShapeRecogn/Test/MathOpsTest.hxx
src/ShapeRecogn/Test/SphereTest.cxx
src/ShapeRecogn/Test/TestShapeRecogn.cxx
src/ShapeRecogn/Test/TorusTest.cxx

index cf1a05b5fea17cf413c91cae55c49f8c86b837af..f817bca189b6f5ec82d041ffa517b8499850b2af 100644 (file)
@@ -203,7 +203,19 @@ IF(MEDCOUPLING_ENABLE_RENUMBER)
 ENDIF(MEDCOUPLING_ENABLE_RENUMBER)
 
 IF(MEDCOUPLING_ENABLE_SHAPERECOGN)
-  FIND_PACKAGE(BLAS REQUIRED)
+IF(UNIX)
+  SET(CBLAS_ROOT_DIR $ENV{CBLAS_ROOT_DIR} CACHE PATH "Path to the LAPACK/CBLAS.")
+  IF(CBLAS_ROOT_DIR)
+    LIST(APPEND CMAKE_PREFIX_PATH "${CBLAS_ROOT_DIR}")
+    FIND_PACKAGE(CBLAS REQUIRED)
+  ELSE(CBLAS_ROOT_DIR)
+    FIND_PACKAGE(BLAS REQUIRED)
+  ENDIF(CBLAS_ROOT_DIR)
+  SET(LAPACK_ROOT_DIR $ENV{LAPACK_ROOT_DIR} CACHE PATH "Path to the LAPACKE")
+  IF(LAPACK_ROOT_DIR)
+    SET(LAPACK_ROOT_DIR $ENV{LAPACK_ROOT_DIR} CACHE PATH "Path to the LAPACK.")
+    LIST(APPEND CMAKE_PREFIX_PATH "${LAPACK_ROOT_DIR}")
+  ENDIF(LAPACK_ROOT_DIR)
   FIND_PACKAGE(LAPACK REQUIRED)
   FIND_LIBRARY(LAPACKE_LIB NAMES lapacke REQUIRED)
   SET(LAPACK_LIBRARIES ${LAPACKE_LIB} ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES})
@@ -215,6 +227,34 @@ IF(MEDCOUPLING_ENABLE_SHAPERECOGN)
     MESSAGE(FATAL_ERROR "Error in Lapacke detection ! lapacke not found !") 
   ENDIF(LAPACK_FOUND)
   SALOME_LOG_OPTIONAL_PACKAGE(Lapack MEDCOUPLING_ENABLE_SHAPERECOGN)
+ELSEIF (MSVC)
+  SET(OPENBLAS_ROOT_DIR $ENV{OPENBLAS_ROOT_DIR} CACHE PATH "Path to the OpenBLAS.")
+  IF(OPENBLAS_ROOT_DIR)
+    LIST(APPEND CMAKE_PREFIX_PATH "${OPENBLAS_ROOT_DIR}")
+    FIND_PACKAGE(OpenBLAS REQUIRED)
+  ELSE(OPENBLAS_ROOT_DIR)
+    MESSAGE(FATAL "Could not find OpenBLAS")
+  ENDIF(OPENBLAS_ROOT_DIR)
+  SET(LAPACK_ROOT_DIR $ENV{LAPACK_ROOT_DIR} CACHE PATH "Path to the LAPACKE")
+  IF(LAPACK_ROOT_DIR)
+    SET(LAPACK_ROOT_DIR $ENV{LAPACK_ROOT_DIR} CACHE PATH "Path to the LAPACK.")
+    LIST(APPEND CMAKE_PREFIX_PATH "${LAPACK_ROOT_DIR}")
+  ENDIF(LAPACK_ROOT_DIR)
+  FIND_PACKAGE(LAPACK REQUIRED)
+  FIND_LIBRARY(LAPACKE_LIB NAMES openblas REQUIRED)
+  SET(LAPACK_LIBRARIES ${LAPACKE_LIB} ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES})
+  FIND_PATH(LAPACKE_INCLUDE_DIRS NAMES lapacke.h HINTS ${LAPACK_LIBRARIES})
+  IF(LAPACK_FOUND)
+    MESSAGE(STATUS "Lapacke libraries: ${LAPACK_LIBRARIES}")
+    MESSAGE(STATUS "Lapacke include dirs: ${LAPACKE_INCLUDE_DIRS}")
+  ELSE()
+    MESSAGE(FATAL_ERROR "Error in Lapacke detection ! lapacke not found !") 
+  ENDIF(LAPACK_FOUND)
+  SALOME_LOG_OPTIONAL_PACKAGE(Lapack MEDCOUPLING_ENABLE_SHAPERECOGN)
+
+ElSE()
+  MESSAGE(FATAL "Not implemented")
+ENDIF()
 ENDIF(MEDCOUPLING_ENABLE_SHAPERECOGN)
 
 IF(MEDCOUPLING_ENABLE_PYTHON)
index 8e3158a56b28cd76525ce529e4b90db7446a8559..fb55d683f95371d272041c6cc9f15f69d41318bb 100644 (file)
@@ -18,7 +18,7 @@
 //
 
 #pragma once
-
+#include "ShapeRecognDefines.hxx"
 #include "PrimitiveType.hxx"
 #include "Nodes.hxx"
 
@@ -46,7 +46,7 @@ namespace MEDCoupling
         std::vector<mcIdType> nodeIds;
     };
 
-    class Areas
+    class SHAPE_RECOGNITION_EXPORT Areas
     {
     public:
         Areas(const Nodes *nodes);
index 679a93570b0a462fae8dbeb9616e3b4e8cf37ba1..90b79b65e8082d57df1c55c7758f44045d68e90e 100644 (file)
 
 #include "Nodes.hxx"
 #include "Areas.hxx"
-
+#include "ShapeRecognDefines.hxx"
 namespace MEDCoupling
 {
-    class AreasBuilder
+    class SHAPE_RECOGNITION_EXPORT AreasBuilder
     {
     public:
         AreasBuilder(const Nodes *nodes);
index 099d7da1efe3a419d0a991710ac04cb5df80d8b0..224d3c9df719b2b00df40d435088171b69e35ac7 100644 (file)
 #include "MCIdType.hxx"
 
 #include <algorithm>
-#include <lapacke.h>
-#include <cblas.h>
+#if defined(_MSC_VER)
+  #include <complex.h>
+  #define LAPACK_COMPLEX_CUSTOM
+  #define lapack_complex_float _Fcomplex
+  #define lapack_complex_double _Dcomplex
+  #include <openblas/lapacke.h>
+  #include <openblas/cblas.h>
+  //#include <lapacke.h>
+  //#include <cblas.h>
+#else
+  #include <lapacke.h>
+  #include <cblas.h>
+#endif
 #include <iostream>
 #include <cfloat>
 #include <cmath>
index a0ba03e3d576ddd92ee85174c367756157ef5685..90b2e59c8c2701a60a288bfc46c4066238553028 100644 (file)
 
 #include <vector>
 #include <array>
-
+#include "ShapeRecognDefines.hxx"
 namespace MEDCoupling
 {
-    class MathOps
+    class SHAPE_RECOGNITION_EXPORT MathOps
     {
     public:
         static std::vector<double> lstsq(std::vector<double> &a, const std::vector<double> &b);
index fbd445736396ffb5c3eae5c0dc03f77c6979b339..4122fd303d2d0f890cc35f931c26dee7c432382f 100644 (file)
 #include <vector>
 #include "MEDCouplingUMesh.hxx"
 #include "PrimitiveType.hxx"
+#include <array>
+#include "ShapeRecognDefines.hxx"
 
 namespace MEDCoupling
 {
-    class Nodes
+    class SHAPE_RECOGNITION_EXPORT Nodes
     {
     public:
         friend class NodesBuilder;
         Nodes(const MEDCouplingUMesh *mesh,
               const DataArrayInt64 *neighbors,
               const DataArrayInt64 *neighborsIdx);
-        ~Nodes() = default;
 
         mcIdType getNbNodes() const;
         const std::vector<double> &getK1() const;
index a58e06538015ff29740c82df638f8956f1428d73..c61a98bde322196c6d0cbb43123aeaeee69de7ed 100644 (file)
 #include <array>
 #include "MEDCouplingUMesh.hxx"
 #include "PrimitiveType.hxx"
-
+#include "ShapeRecognDefines.hxx"
 namespace MEDCoupling
 {
     class Nodes;
 
-    class NodesBuilder
+    class SHAPE_RECOGNITION_EXPORT NodesBuilder
     {
     public:
         NodesBuilder(const MEDCouplingUMesh *);
index 88f42893214550cd93d538c400b01894f70cc0b5..ffa3be4dfdb3935ae34ea6b317ed2f4c07e7aed3 100644 (file)
 #include <vector>
 #include <string>
 #include <cstdint>
-
+#include "ShapeRecognDefines.hxx"
 namespace MEDCoupling
 {
-  enum class PrimitiveType : std::uint8_t
+  enum class SHAPE_RECOGNITION_EXPORT PrimitiveType : unsigned char
   {
     Plane = 0,
     Sphere = 1,
@@ -35,13 +35,13 @@ namespace MEDCoupling
     Unknown = 5
   };
 
-  std::vector<PrimitiveType> AllManagedPrimitives();
+  SHAPE_RECOGNITION_EXPORT std::vector<PrimitiveType> AllManagedPrimitives();
 
-  std::vector<std::string> AllManagedPrimitivesStr();
+  SHAPE_RECOGNITION_EXPORT std::vector<std::string> AllManagedPrimitivesStr();
 
-  std::string ConvertPrimitiveToString(PrimitiveType type);
+  SHAPE_RECOGNITION_EXPORT std::string ConvertPrimitiveToString(PrimitiveType type);
   
-  PrimitiveType ConvertStringToPrimitive(const std::string& type);
+  SHAPE_RECOGNITION_EXPORT PrimitiveType ConvertStringToPrimitive(const std::string& type);
 
-  int ConvertPrimitiveToInt(PrimitiveType type);
+  SHAPE_RECOGNITION_EXPORT int ConvertPrimitiveToInt(PrimitiveType type);
 };
diff --git a/src/ShapeRecogn/ShapeRecognDefines.hxx b/src/ShapeRecogn/ShapeRecognDefines.hxx
new file mode 100644 (file)
index 0000000..ff9e55d
--- /dev/null
@@ -0,0 +1,33 @@
+// Copyright (C) 2007-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
+//
+
+#ifndef __SHAPE_RECOGNITION_DEFINES_HXX__
+#define __SHAPE_RECOGNITION_DEFINES_HXX__
+
+#ifdef WIN32
+# if defined shaperecogn_EXPORTS || TestShapeRecogn_EXPORTS
+#  define SHAPE_RECOGNITION_EXPORT __declspec(dllexport)
+# else
+#  define SHAPE_RECOGNITION_EXPORT __declspec(dllimport)
+# endif
+#else
+# define SHAPE_RECOGNITION_EXPORT
+#endif 
+
+#endif
index efbb312e8bbc5c17b08e3c59b49d61c19567a591..c6df41fb5f63baf946c7f8210439d51467e365b5 100644 (file)
 #include "MEDCouplingFieldInt32.hxx"
 #include "MEDCouplingFieldDouble.hxx"
 #include "MEDCouplingRefCountObject.hxx"
-
+#include "ShapeRecognDefines.hxx"
 namespace MEDCoupling
 {
-    class ShapeRecognMesh : public RefCountObject
+    class SHAPE_RECOGNITION_EXPORT ShapeRecognMesh : public RefCountObject
     {
         friend class ShapeRecognMeshBuilder;
 
@@ -61,7 +61,6 @@ namespace MEDCoupling
 
     protected:
         ShapeRecognMesh();
-        ~ShapeRecognMesh() = default;
 
     private:
         MCAuto<MEDCouplingFieldDouble> nodeK1;
index ab20016ea23fcaec90223d909a0fface997a9352..4021319056ab037cbe582856bb4468c79edea1b4 100644 (file)
@@ -28,7 +28,7 @@
 
 #include <memory>
 #include <functional>
-
+#include "ShapeRecognDefines.hxx"
 namespace MEDCoupling
 {
     class MEDCouplingFieldInt32;
@@ -37,12 +37,11 @@ namespace MEDCoupling
 
     class ShapeRecognMesh;
 
-    class ShapeRecognMeshBuilder
+    class SHAPE_RECOGNITION_EXPORT ShapeRecognMeshBuilder
     {
     public:
         ShapeRecognMeshBuilder(MCAuto< MEDCouplingUMesh > mesh);
         ShapeRecognMeshBuilder(MEDCouplingUMesh *mesh);
-        ~ShapeRecognMeshBuilder() = default;
 
         const Nodes *getNodes() const;
         const Areas *getAreas() const;
index 0d894c7ce83c8caa8f98ba9414659ed418b27abf..6d2b97f075c2f4997c74e2a721d2eaa5fa114195 100644 (file)
 //
 
 %{
+#include <vector>
+#include <string>
 #include "ShapeRecognMesh.hxx"
 #include "ShapeRecognMeshBuilder.hxx"
+#include "PrimitiveType.hxx"
 #include "Areas.hxx"
  
  #include <type_traits>                
index a7df4179afd49f28bcd474b29c3721e641e4f2bc..be71456647bf92363faeffa585967edb68b1627b 100644 (file)
@@ -47,7 +47,7 @@ SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env)
 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})
+  TARGET_LINK_LIBRARIES(${TESTSHAPE_RECOGN0} shaperecogn InterpKernelTestUtils medloader medcouplingcpp ${CPPUNIT_LIBRARIES} ${PLATFORM_LIBS} ${CBLAS_LIBRARIES})
 
   INSTALL(TARGETS ${TESTSHAPE_RECOGN0} DESTINATION ${MEDCOUPLING_INSTALL_BINS})
   
index 2da2193b79fde75c769f8d0a32eecd1e86763e67..ca71391d4c9dc5e72f4ac81310659a1f489d3f52 100644 (file)
@@ -26,6 +26,9 @@
 #include "TestInterpKernelUtils.hxx" // getResourceFile()
 
 #include "ShapeRecognTest.hxx"
+#include <vector>
+#include <array>
+#include <string>
 
 using namespace MEDCoupling;
 
@@ -192,7 +195,7 @@ void ConeTest::testComputeConeProperties()
 void ConeTest::testFirstArea()
 {
     // primitive type
-    CPPUNIT_ASSERT_EQUAL(PrimitiveType::Plane, areas->getPrimitiveType(0));
+    CPPUNIT_ASSERT_EQUAL((int)PrimitiveType::Plane, (int)areas->getPrimitiveType(0));
     // node ids
     std::vector<mcIdType> nodeIdsRef{
         549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559,
@@ -213,7 +216,7 @@ void ConeTest::testFirstArea()
 void ConeTest::testSecondArea()
 {
     // primitive type
-    CPPUNIT_ASSERT_EQUAL(PrimitiveType::Plane, areas->getPrimitiveType(0));
+    CPPUNIT_ASSERT_EQUAL((int)PrimitiveType::Plane, (int)areas->getPrimitiveType(0));
     // node ids
     std::vector<mcIdType> nodeIdsRef = {
         572, 573, 574, 575, 576, 577, 578, 579, 580, 581, 582, 583,
@@ -264,7 +267,7 @@ void ConeTest::testSecondArea()
 void ConeTest::testThirdArea()
 {
     // primitive type
-    CPPUNIT_ASSERT_EQUAL(PrimitiveType::Cone, areas->getPrimitiveType(2));
+    CPPUNIT_ASSERT_EQUAL((int)PrimitiveType::Cone, (int)areas->getPrimitiveType(2));
     // node ids
     std::vector<mcIdType> nodeIdsRef{
         0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
index 2e08bdf10479f20ebf59493dc05a1f7c3045a9e4..6b7fc7fb96e25edbf06c517456b0f9b1f977507d 100644 (file)
@@ -50,7 +50,7 @@ void CylinderTest::testNumberOfAreas()
 void CylinderTest::testFirstArea()
 {
     // primitive type
-    CPPUNIT_ASSERT_EQUAL(PrimitiveType::Cylinder, areas->getPrimitiveType(0));
+    CPPUNIT_ASSERT_EQUAL((int)PrimitiveType::Cylinder, (int) areas->getPrimitiveType(0));
     // node ids
     std::vector<mcIdType> nodeIdsRef{
         0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
@@ -108,7 +108,7 @@ void CylinderTest::testFirstArea()
 void CylinderTest::testSecondArea()
 {
     // primitive type
-    CPPUNIT_ASSERT_EQUAL(PrimitiveType::Plane, areas->getPrimitiveType(1));
+    CPPUNIT_ASSERT_EQUAL((int)PrimitiveType::Plane, (int)areas->getPrimitiveType(1));
     // node ids
     std::vector<mcIdType> nodeIdsRef{
         370, 371, 372, 373, 374, 375, 376, 377, 378, 379,
@@ -134,7 +134,7 @@ void CylinderTest::testSecondArea()
 void CylinderTest::testThirdArea()
 {
     // primitive type
-    CPPUNIT_ASSERT_EQUAL(PrimitiveType::Plane, areas->getPrimitiveType(2));
+    CPPUNIT_ASSERT_EQUAL((int)PrimitiveType::Plane, (int)areas->getPrimitiveType(2));
     // node ids
     std::vector<mcIdType> nodeIdsRef{
         443, 444, 445, 446, 447, 448, 449, 450, 451, 452,
index 6841fe097fcee786b0eae7eeaf538170b0ab5d9c..82a27b96b46af46f0f9317fef2885f4e6be11073 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "MathOpsTest.hxx"
 #include "MathOps.hxx"
-
+#include <cblas.h>
 using namespace MEDCoupling;
 
 void MathOpsTest::testLstsq()
index 8cbc635f127de3b1eca4a5cb1b8039cb29aea6f8..8b5b3fd27704641766d66da97fa7707f59e65688 100644 (file)
@@ -37,12 +37,12 @@ namespace MEDCoupling
         CPPUNIT_TEST_SUITE_END();
 
     public:
-        static void testLstsq();
-        static void testLstsq2();
-        static void testLstsqBig();
-        static void testComputeCov();
-        static void testComputePCAFirstAxis();
-        static void testComputeAngles();
-        static void testComputeBaseFromNormal();
+        void testLstsq();
+        void testLstsq2();
+        void testLstsqBig();
+        void testComputeCov();
+        void testComputePCAFirstAxis();
+        void testComputeAngles();
+        void testComputeBaseFromNormal();
     };
 }
index b219e1ad8edf9c3fa644ba71c095b8e4a48fb700..630f55c8c3165b4d6d01b6b3d34f21570a2b0e88 100644 (file)
@@ -47,7 +47,7 @@ void SphereTest::testArea()
     CPPUNIT_ASSERT_EQUAL(1, (int)areas->getNumberOfAreas());
     // 8 double nodes so 147 - 6 nodes
     CPPUNIT_ASSERT_EQUAL(141, (int)areas->getNumberOfNodes(0));
-    CPPUNIT_ASSERT_EQUAL(PrimitiveType::Sphere, areas->getPrimitiveType(0));
+    CPPUNIT_ASSERT_EQUAL((int)PrimitiveType::Sphere, (int)areas->getPrimitiveType(0));
     CPPUNIT_ASSERT_DOUBLES_EQUAL(1.0, areas->getRadius(0), 1E-2);
     std::array<double, 3> centerRef = {5.3, -6.7, -9.02};
     std::array<double, 3> center = areas->getCenter(0);
index 8d07cce9d7db89f9aa93ae437059be091324a375..fb2e25e34b78b524d8de19b4c192caad285cc94a 100644 (file)
@@ -17,6 +17,7 @@
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
+#include "CppUnitTest.hxx"
 #include "MathOpsTest.hxx"
 #include "PlaneTest.hxx"
 #include "CylinderTest.hxx"
index fecb7b3642900c11a95a8722493f437bb879ca4c..32ab1c26c885d89bbb8eaefa04839ef3ca675e5b 100644 (file)
@@ -46,7 +46,7 @@ void TorusTest::testArea()
 {
     CPPUNIT_ASSERT_EQUAL(275, (int)srMesh->getNodes()->getNbNodes());
     CPPUNIT_ASSERT_EQUAL(1, (int)areas->getNumberOfAreas());
-    CPPUNIT_ASSERT_EQUAL(PrimitiveType::Torus, areas->getPrimitiveType(0));
+    CPPUNIT_ASSERT_EQUAL((int)PrimitiveType::Torus, (int)areas->getPrimitiveType(0));
     // Some nodes are unknown
     CPPUNIT_ASSERT_EQUAL(272, (int)areas->getNumberOfNodes(0));
     CPPUNIT_ASSERT_DOUBLES_EQUAL(0.843297, areas->getMinorRadius(0), 1E-2);