]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
Add Torus test
authorEl Hadi Moussi <moussi@phimeca.com>
Wed, 7 Aug 2024 16:40:48 +0000 (18:40 +0200)
committerEl Hadi Moussi <moussi@phimeca.com>
Wed, 7 Aug 2024 16:40:48 +0000 (18:40 +0200)
resources/CMakeLists.txt
resources/ShapeRecognTorus.med [new file with mode: 0755]
src/ShapeRecogn/Test/CMakeLists.txt
src/ShapeRecogn/Test/TestShapeRecogn.cxx
src/ShapeRecogn/Test/TorusTest.cxx [new file with mode: 0644]
src/ShapeRecogn/Test/TorusTest.hxx [new file with mode: 0644]

index 9d5f66c985ebf18465d0b8bd0f0a5207598002cc..cf6ec248139e68536fa9e8e788c500e482bea9e0 100644 (file)
@@ -98,6 +98,7 @@ SET(MED_other_FILES
   ShapeRecognCylinder.med
   ShapeRecognCone.med
   ShapeRecognSphere.med
+  ShapeRecognTorus.med
   )
 
 SET(MED_RESOURCES_FILES ${MED_test_fig_files})
diff --git a/resources/ShapeRecognTorus.med b/resources/ShapeRecognTorus.med
new file mode 100755 (executable)
index 0000000..7623db5
Binary files /dev/null and b/resources/ShapeRecognTorus.med differ
index e957ba522a4506f93f5a4831854b12120c428d89..2dc29d57c8630fcc3e4ca8e56b70aa17288d585a 100644 (file)
@@ -36,6 +36,7 @@ SET(TestShapeRecogn_SOURCES
   CylinderTest.cxx
   ConeTest.cxx
   SphereTest.cxx
+  TorusTest.cxx
 )
 
 SALOME_ACCUMULATE_ENVIRONMENT(MEDCOUPLING_RESOURCE_DIR "${CMAKE_BINARY_DIR}/resources")
index 6c09cba822e2002bfc5dc98b886283f5baddbbee..b7cd2af14c8f60c160bd7a185fcbc88aa1e43903 100644 (file)
 #include "CylinderTest.hxx"
 #include "ConeTest.hxx"
 #include "SphereTest.hxx"
+#include "TorusTest.hxx"
 
 CPPUNIT_TEST_SUITE_REGISTRATION(MEDCoupling::MathOpsTest);
 CPPUNIT_TEST_SUITE_REGISTRATION(MEDCoupling::PlaneTest);
 CPPUNIT_TEST_SUITE_REGISTRATION(MEDCoupling::CylinderTest);
 CPPUNIT_TEST_SUITE_REGISTRATION(MEDCoupling::ConeTest);
 CPPUNIT_TEST_SUITE_REGISTRATION(MEDCoupling::SphereTest);
+CPPUNIT_TEST_SUITE_REGISTRATION(MEDCoupling::TorusTest);
 
 #include "BasicMainTest.hxx"
diff --git a/src/ShapeRecogn/Test/TorusTest.cxx b/src/ShapeRecogn/Test/TorusTest.cxx
new file mode 100644 (file)
index 0000000..6129138
--- /dev/null
@@ -0,0 +1,38 @@
+#include "TorusTest.hxx"
+
+#include "ShapeRecognMesh.hxx"
+#include "Areas.hxx"
+#include "MathOps.hxx"
+#include "TestInterpKernelUtils.hxx" // getResourceFile()
+
+using namespace MEDCoupling;
+
+void TorusTest::setUp()
+{
+    std::string file = INTERP_TEST::getResourceFile("ShapeRecognTorus.med", 3);
+    srMesh = new ShapeRecognMesh(file);
+    srMesh->recognize();
+    areas = srMesh->getAreas();
+}
+
+void TorusTest::tearDown()
+{
+    if (srMesh != 0)
+        delete srMesh;
+    areas = 0;
+}
+
+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));
+    // Some nodes are unknown
+    CPPUNIT_ASSERT_EQUAL(272, (int)areas->getNumberOfNodes(0));
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(0.843297, areas->getMinorRadius(0), 1E-2);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(1.156428, areas->getRadius(0), 1E-1);
+    std::array<double, 3> centerRef = {7.687022, -3.726887, -9.02};
+    std::array<double, 3> center = areas->getCenter(0);
+    for (size_t j = 0; j < 3; ++j)
+        CPPUNIT_ASSERT_DOUBLES_EQUAL(centerRef[j], center[j], 1E-2);
+}
diff --git a/src/ShapeRecogn/Test/TorusTest.hxx b/src/ShapeRecogn/Test/TorusTest.hxx
new file mode 100644 (file)
index 0000000..4999f57
--- /dev/null
@@ -0,0 +1,49 @@
+// 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 __TORUSTEST_HXX__
+#define __TORUSTEST_HXX__
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+namespace MEDCoupling
+{
+    class ShapeRecognMesh;
+    class Areas;
+
+    class TorusTest : public CppUnit::TestFixture
+    {
+        CPPUNIT_TEST_SUITE(TorusTest);
+        CPPUNIT_TEST(testArea);
+        CPPUNIT_TEST_SUITE_END();
+
+    public:
+        void setUp() override;
+        void tearDown() override;
+
+        void testArea();
+
+    private:
+        ShapeRecognMesh *srMesh = 0;
+        const Areas *areas;
+    };
+};
+
+#endif // __TORUSTEST_HXX__