From: El Hadi Moussi Date: Wed, 7 Aug 2024 16:40:48 +0000 (+0200) Subject: Add Torus test X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=dd3915d96dcc45f2699d2bf8c76560c15645b1a4;p=tools%2Fmedcoupling.git Add Torus test --- diff --git a/resources/CMakeLists.txt b/resources/CMakeLists.txt index 9d5f66c98..cf6ec2481 100644 --- a/resources/CMakeLists.txt +++ b/resources/CMakeLists.txt @@ -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 index 000000000..7623db578 Binary files /dev/null and b/resources/ShapeRecognTorus.med differ diff --git a/src/ShapeRecogn/Test/CMakeLists.txt b/src/ShapeRecogn/Test/CMakeLists.txt index e957ba522..2dc29d57c 100644 --- a/src/ShapeRecogn/Test/CMakeLists.txt +++ b/src/ShapeRecogn/Test/CMakeLists.txt @@ -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") diff --git a/src/ShapeRecogn/Test/TestShapeRecogn.cxx b/src/ShapeRecogn/Test/TestShapeRecogn.cxx index 6c09cba82..b7cd2af14 100644 --- a/src/ShapeRecogn/Test/TestShapeRecogn.cxx +++ b/src/ShapeRecogn/Test/TestShapeRecogn.cxx @@ -22,11 +22,13 @@ #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 index 000000000..612913881 --- /dev/null +++ b/src/ShapeRecogn/Test/TorusTest.cxx @@ -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 centerRef = {7.687022, -3.726887, -9.02}; + std::array 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 index 000000000..4999f579b --- /dev/null +++ b/src/ShapeRecogn/Test/TorusTest.hxx @@ -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 +#include + +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__