]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
[EDF30834] : break medloader dependancy of libshaperecogn.so
authorAnthony Geay <anthony.geay@edf.fr>
Thu, 29 Aug 2024 10:43:22 +0000 (12:43 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Thu, 29 Aug 2024 10:43:22 +0000 (12:43 +0200)
16 files changed:
src/MEDCoupling/MCAuto.hxx
src/ShapeRecogn/CMakeLists.txt
src/ShapeRecogn/README.md
src/ShapeRecogn/ShapeRecognMesh.cxx
src/ShapeRecogn/ShapeRecognMesh.hxx
src/ShapeRecogn/ShapeRecognMeshBuilder.cxx
src/ShapeRecogn/ShapeRecognMeshBuilder.hxx
src/ShapeRecogn/Test/CMakeLists.txt
src/ShapeRecogn/Test/ConeTest.cxx
src/ShapeRecogn/Test/CylinderTest.cxx
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/TorusTest.cxx

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 b56f10df519fca2bd0ce6872a88b82efb7679195..331c5bde643339ec459512d6d88cd874116a88f0 100644 (file)
@@ -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
@@ -53,7 +52,7 @@ SET(shaperecogn_SOURCES
 
 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")
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 9398705b9df897fb2c9ddaba0725cdfbec4c0345..9cd4bc7c236e3dadcee0179e27059c654596bfd6 100644 (file)
 
 #include "ShapeRecognMesh.hxx"
 
-#include "MEDLoader.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)
+    : 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)
 {
 }
 
@@ -60,38 +58,6 @@ 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);
-}
-
 const MEDCouplingFieldDouble *ShapeRecognMesh::getNodeK1() const
 {
     return nodeK1;
index 26b1f06d575e09da0815122b61bdd541d9ce9d4b..63252a0ac1f2eec539d316602c63ab6a5ec3cfef 100644 (file)
@@ -36,8 +36,6 @@ 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
         const MEDCouplingFieldDouble *getNodeK1() const;
         const MEDCouplingFieldDouble *getNodeK2() const;
index 14de38ecdae9fe0aa8a60b6fa32570b67b28bfe5..4f1895c5573447e12636889eaa54da4beb14c379 100644 (file)
 
 #include "NodesBuilder.hxx"
 #include "AreasBuilder.hxx"
-#include "MEDLoader.hxx"
 #include "ShapeRecognMesh.hxx"
 #include "MEDCouplingFieldDouble.hxx"
 
 using namespace MEDCoupling;
 
-ShapeRecognMeshBuilder::ShapeRecognMeshBuilder(const std::string &fileName, int meshDimRelToMax)
+ShapeRecognMeshBuilder::ShapeRecognMeshBuilder(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())
index 45ea3ce42be0446afb587df010bf4e44856e16a4..6bd1853c8d5aea9c148e6a173807b985883c78a2 100644 (file)
@@ -36,7 +36,7 @@ namespace MEDCoupling
     class ShapeRecognMeshBuilder
     {
     public:
-        ShapeRecognMeshBuilder(const std::string &fileName, int meshDimRelToMax = 0);
+        ShapeRecognMeshBuilder(MCAuto< MEDCouplingUMesh > mesh);
         ~ShapeRecognMeshBuilder() = default;
 
         const Nodes *getNodes() const;
index 0be94ce862fb2dfb273d19fc65746925f9bc4e5e..4206fa0c00e7bdd55993bc8905256dde466ae2e4 100644 (file)
@@ -32,6 +32,7 @@ INCLUDE_DIRECTORIES(
 SET(TestShapeRecogn_SOURCES
   TestShapeRecogn.cxx
   MathOpsTest.cxx
+  ShapeRecognTest.cxx
   PlaneTest.cxx
   CylinderTest.cxx
   ConeTest.cxx
@@ -43,7 +44,7 @@ SALOME_ACCUMULATE_ENVIRONMENT(MEDCOUPLING_RESOURCE_DIR "${CMAKE_BINARY_DIR}/reso
 SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env)
 
 ADD_EXECUTABLE(TestShapeRecogn ${TestShapeRecogn_SOURCES})
-TARGET_LINK_LIBRARIES(TestShapeRecogn shaperecogn InterpKernelTestUtils ${CPPUNIT_LIBRARIES} ${PLATFORM_LIBS})
+TARGET_LINK_LIBRARIES(TestShapeRecogn shaperecogn InterpKernelTestUtils medloader ${MEDFILE_C_LIBRARIES} ${HDF5_LIBRARIES} ${CPPUNIT_LIBRARIES} ${PLATFORM_LIBS})
 
 INSTALL(TARGETS TestShapeRecogn DESTINATION ${MEDCOUPLING_INSTALL_BINS})
 
index bf5ef1d1ff50fdb93cfe9abc02a8ddb5d5bc7701..2da2193b79fde75c769f8d0a32eecd1e86763e67 100644 (file)
 #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.reset( new ShapeRecognMeshBuilder(file) );
+    srMesh = BuildShapeRecognMeshBuilderFromFile(file);
     srMesh->recognize();
     areas = srMesh->getAreas();
 }
index b0b3b47747e905b76aac163534370327e29b6222..2e08bdf10479f20ebf59493dc05a1f7c3045a9e4 100644 (file)
 #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.reset( new ShapeRecognMeshBuilder(file) );
+    srMesh = BuildShapeRecognMeshBuilderFromFile(file);
     srMesh->recognize();
     areas = srMesh->getAreas();
 }
index f3f4c96cabc5dc691e31209b4a5cf1efb439c1d3..8f41a30f4e431d537982c1ba8ec5a9732820fb02 100644 (file)
 #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.reset( new ShapeRecognMeshBuilder(file) );
+    srMesh = BuildShapeRecognMeshBuilderFromFile(file);
     srMesh->recognize();
     areas = srMesh->getAreas();
 }
index 036e3c7bdcc507650728a4595c6c52f23280c2f8..63e00706315b366b14eeea6e50ee4430643e0361 100644 (file)
@@ -23,6 +23,7 @@
 #include <cppunit/extensions/HelperMacros.h>
 
 #include "ShapeRecognMeshBuilder.hxx"
+#include "ShapeRecognTest.hxx"
 
 #include <memory>
 
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 70f0c6e63ed0b571d1325b0f505df84bcbe1b6a4..b219e1ad8edf9c3fa644ba71c095b8e4a48fb700 100644 (file)
 #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.reset( new ShapeRecognMeshBuilder(file) );
+    srMesh = BuildShapeRecognMeshBuilderFromFile(file);
     srMesh->recognize();
     areas = srMesh->getAreas();
 }
index 585d56ee3cdb2d31e25ab760607f961a0943c088..fecb7b3642900c11a95a8722493f437bb879ca4c 100644 (file)
 #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.reset( new ShapeRecognMeshBuilder(file) );
+    srMesh = BuildShapeRecognMeshBuilderFromFile(file);
     srMesh->recognize();
     areas = srMesh->getAreas();
 }