From 662e36ab559311524764df55f59c920351a10c1a Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Thu, 29 Aug 2024 12:43:22 +0200 Subject: [PATCH] [EDF30834] : break medloader dependancy of libshaperecogn.so --- src/MEDCoupling/MCAuto.hxx | 1 + src/ShapeRecogn/CMakeLists.txt | 3 +- src/ShapeRecogn/README.md | 2 +- src/ShapeRecogn/ShapeRecognMesh.cxx | 42 +++------------------- src/ShapeRecogn/ShapeRecognMesh.hxx | 2 -- src/ShapeRecogn/ShapeRecognMeshBuilder.cxx | 5 ++- src/ShapeRecogn/ShapeRecognMeshBuilder.hxx | 2 +- src/ShapeRecogn/Test/CMakeLists.txt | 3 +- src/ShapeRecogn/Test/ConeTest.cxx | 4 ++- src/ShapeRecogn/Test/CylinderTest.cxx | 4 ++- src/ShapeRecogn/Test/PlaneTest.cxx | 4 ++- src/ShapeRecogn/Test/PlaneTest.hxx | 1 + src/ShapeRecogn/Test/ShapeRecognTest.cxx | 28 +++++++++++++++ src/ShapeRecogn/Test/ShapeRecognTest.hxx | 27 ++++++++++++++ src/ShapeRecogn/Test/SphereTest.cxx | 4 ++- src/ShapeRecogn/Test/TorusTest.cxx | 4 ++- 16 files changed, 83 insertions(+), 53 deletions(-) create mode 100644 src/ShapeRecogn/Test/ShapeRecognTest.cxx create mode 100644 src/ShapeRecogn/Test/ShapeRecognTest.hxx diff --git a/src/MEDCoupling/MCAuto.hxx b/src/MEDCoupling/MCAuto.hxx index 4b6347704..0774928b0 100644 --- a/src/MEDCoupling/MCAuto.hxx +++ b/src/MEDCoupling/MCAuto.hxx @@ -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& 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 ; } diff --git a/src/ShapeRecogn/CMakeLists.txt b/src/ShapeRecogn/CMakeLists.txt index b56f10df5..331c5bde6 100644 --- a/src/ShapeRecogn/CMakeLists.txt +++ b/src/ShapeRecogn/CMakeLists.txt @@ -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") diff --git a/src/ShapeRecogn/README.md b/src/ShapeRecogn/README.md index 61b9eb4d0..f0e2e39da 100644 --- a/src/ShapeRecogn/README.md +++ b/src/ShapeRecogn/README.md @@ -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 diff --git a/src/ShapeRecogn/ShapeRecognMesh.cxx b/src/ShapeRecogn/ShapeRecognMesh.cxx index 9398705b9..9cd4bc7c2 100644 --- a/src/ShapeRecogn/ShapeRecognMesh.cxx +++ b/src/ShapeRecogn/ShapeRecognMesh.cxx @@ -19,15 +19,13 @@ #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; diff --git a/src/ShapeRecogn/ShapeRecognMesh.hxx b/src/ShapeRecogn/ShapeRecognMesh.hxx index 26b1f06d5..63252a0ac 100644 --- a/src/ShapeRecogn/ShapeRecognMesh.hxx +++ b/src/ShapeRecogn/ShapeRecognMesh.hxx @@ -36,8 +36,6 @@ namespace MEDCoupling std::size_t getHeapMemorySizeWithoutChildren() const; std::vector getDirectChildrenWithNull() const; - void save(const std::string &outputFile, bool writeFromScratch = true) const; - // Node properties const MEDCouplingFieldDouble *getNodeK1() const; const MEDCouplingFieldDouble *getNodeK2() const; diff --git a/src/ShapeRecogn/ShapeRecognMeshBuilder.cxx b/src/ShapeRecogn/ShapeRecognMeshBuilder.cxx index 14de38ecd..4f1895c55 100644 --- a/src/ShapeRecogn/ShapeRecognMeshBuilder.cxx +++ b/src/ShapeRecogn/ShapeRecognMeshBuilder.cxx @@ -21,15 +21,14 @@ #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()) diff --git a/src/ShapeRecogn/ShapeRecognMeshBuilder.hxx b/src/ShapeRecogn/ShapeRecognMeshBuilder.hxx index 45ea3ce42..6bd1853c8 100644 --- a/src/ShapeRecogn/ShapeRecognMeshBuilder.hxx +++ b/src/ShapeRecogn/ShapeRecognMeshBuilder.hxx @@ -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; diff --git a/src/ShapeRecogn/Test/CMakeLists.txt b/src/ShapeRecogn/Test/CMakeLists.txt index 0be94ce86..4206fa0c0 100644 --- a/src/ShapeRecogn/Test/CMakeLists.txt +++ b/src/ShapeRecogn/Test/CMakeLists.txt @@ -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}) diff --git a/src/ShapeRecogn/Test/ConeTest.cxx b/src/ShapeRecogn/Test/ConeTest.cxx index bf5ef1d1f..2da2193b7 100644 --- a/src/ShapeRecogn/Test/ConeTest.cxx +++ b/src/ShapeRecogn/Test/ConeTest.cxx @@ -25,12 +25,14 @@ #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(); } diff --git a/src/ShapeRecogn/Test/CylinderTest.cxx b/src/ShapeRecogn/Test/CylinderTest.cxx index b0b3b4774..2e08bdf10 100644 --- a/src/ShapeRecogn/Test/CylinderTest.cxx +++ b/src/ShapeRecogn/Test/CylinderTest.cxx @@ -25,12 +25,14 @@ #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(); } diff --git a/src/ShapeRecogn/Test/PlaneTest.cxx b/src/ShapeRecogn/Test/PlaneTest.cxx index f3f4c96ca..8f41a30f4 100644 --- a/src/ShapeRecogn/Test/PlaneTest.cxx +++ b/src/ShapeRecogn/Test/PlaneTest.cxx @@ -25,12 +25,14 @@ #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(); } diff --git a/src/ShapeRecogn/Test/PlaneTest.hxx b/src/ShapeRecogn/Test/PlaneTest.hxx index 036e3c7bd..63e007063 100644 --- a/src/ShapeRecogn/Test/PlaneTest.hxx +++ b/src/ShapeRecogn/Test/PlaneTest.hxx @@ -23,6 +23,7 @@ #include #include "ShapeRecognMeshBuilder.hxx" +#include "ShapeRecognTest.hxx" #include diff --git a/src/ShapeRecogn/Test/ShapeRecognTest.cxx b/src/ShapeRecogn/Test/ShapeRecognTest.cxx new file mode 100644 index 000000000..c9faa14ea --- /dev/null +++ b/src/ShapeRecogn/Test/ShapeRecognTest.cxx @@ -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 BuildShapeRecognMeshBuilderFromFile(const std::string& fileName, int meshDimRelToMax) +{ + MEDCoupling::MCAuto mesh = MEDCoupling::ReadUMeshFromFile(fileName, 0); + return std::make_unique(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 index 000000000..8f1e39e46 --- /dev/null +++ b/src/ShapeRecogn/Test/ShapeRecognTest.hxx @@ -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 +#include + +std::unique_ptr BuildShapeRecognMeshBuilderFromFile(const std::string& fileName, int meshDimRelToMax = 0); diff --git a/src/ShapeRecogn/Test/SphereTest.cxx b/src/ShapeRecogn/Test/SphereTest.cxx index 70f0c6e63..b219e1ad8 100644 --- a/src/ShapeRecogn/Test/SphereTest.cxx +++ b/src/ShapeRecogn/Test/SphereTest.cxx @@ -25,12 +25,14 @@ #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(); } diff --git a/src/ShapeRecogn/Test/TorusTest.cxx b/src/ShapeRecogn/Test/TorusTest.cxx index 585d56ee3..fecb7b364 100644 --- a/src/ShapeRecogn/Test/TorusTest.cxx +++ b/src/ShapeRecogn/Test/TorusTest.cxx @@ -25,12 +25,14 @@ #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(); } -- 2.39.2