X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FINTERP_KERNELTest%2FUnitTetraIntersectionBaryTest.cxx;h=851685eaae4fc49f86dafa4fd1243aba79f952a6;hb=22180620a030d1e31592593fb396e3e2700986a7;hp=4a15c5bdb4cd1c4835119a356e11733ab207254d;hpb=10f37bf6f33a762626d7f1093b2f5450c1688667;p=tools%2Fmedcoupling.git diff --git a/src/INTERP_KERNELTest/UnitTetraIntersectionBaryTest.cxx b/src/INTERP_KERNELTest/UnitTetraIntersectionBaryTest.cxx index 4a15c5bdb..851685eaa 100644 --- a/src/INTERP_KERNELTest/UnitTetraIntersectionBaryTest.cxx +++ b/src/INTERP_KERNELTest/UnitTetraIntersectionBaryTest.cxx @@ -1,9 +1,9 @@ -// Copyright (C) 2007-2012 CEA/DEN, EDF R&D +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D // // 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. +// 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 @@ -301,15 +301,14 @@ namespace INTERP_TEST void UnitTetraIntersectionBaryTest::test_TetraAffineTransform_reverseApply() { - double nodes[4][3] = { {-4.0, 9.0, 3.0 }, - {11.0, 0.0, 2.0 }, - { 0.0, 0.0, 0.0 }, - { 2.0, 1.0,10.0 }}; + double nodes[12] = { -4.0, 9.0, 3.0, + 11.0, 0.0, 2.0, + 0.0, 0.0, 0.0, + 2.0, 1.0,10.0 }; // double pSrc[3] = { -4.0, 9.0, 3.0 }; double pSrc[3] = { 40., -20., 100. }; double pDest[] = {1,1,1}; - const double* n[4] = { &nodes[0][0], &nodes[1][0], &nodes[2][0], &nodes[3][0] }; - TetraAffineTransform a(&n[0]); + TetraAffineTransform a(nodes); a.apply( pDest, pSrc ); a.reverseApply( pDest, pDest ); CPPUNIT_ASSERT_DOUBLES_EQUAL( pSrc[0], pDest[0], 1e-12); @@ -343,5 +342,148 @@ namespace INTERP_TEST CPPUNIT_ASSERT_DOUBLES_EQUAL( p[0], p2[0], 1e-12); CPPUNIT_ASSERT_DOUBLES_EQUAL( p[1], p2[1], 1e-12); CPPUNIT_ASSERT_DOUBLES_EQUAL( p[2], p2[2], 1e-12); - } + } + + /* Conventions: + * - for HEXA8, point 5 is taken to be the origin (see med file ref connec): + * 0 ------ 3 + /| /| + / | / | + 1 ------ 2 | + | | | | + | | | | + | 4-----|- 7 + | / | / + 5 ------ 6 + */ + void UnitTetraIntersectionBaryTest::test_cuboid_mapped_coords_3D() + { + double nodes[8][3] = { { 0.0, 2.0, 4.0 }, //0 + { 0.0, 0.0, 4.0 }, + { 1.0, 0.0, 4.0 }, + { 1.0, 2.0, 4.0 }, + { 0.0, 2.0, 0.0 }, // 4 + { 0.0, 0.0, 0.0 }, + { 1.0, 0.0, 0.0 }, + { 1.0, 2.0, 0.0 } + }; + // Translate cube: + for (int i=0; i < 8; ++i) + for (int j=0; j < 3; ++j) + nodes[i][j] += 15.0; + + std::vector n (8); + for (int i=0; i<8; i++) + n[i] = &nodes[i][0]; + + { + // middle point + double p[3] = { 15.5, 16.0, 17.0 }, bc[3]; + cuboid_mapped_coords(n, p, bc); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, bc[0], 1e-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, bc[1], 1e-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, bc[2], 1e-12); + } + { + // point 1 + double p[3] = { 15.0, 15.0, 19.0 }, bc[3]; + cuboid_mapped_coords(n, p, bc); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, bc[0], 1e-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, bc[1], 1e-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, bc[2], 1e-12); + } + { + // point 7 + double p[3] = { 16.0, 17.0, 15.0 }, bc[3]; + cuboid_mapped_coords(n, p, bc); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, bc[0], 1e-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, bc[1], 1e-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, bc[2], 1e-12); + } + { + // point 3 + double p[3] = { 16.0, 17.0, 19.0 }, bc[3]; + cuboid_mapped_coords(n, p, bc); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, bc[0], 1e-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, bc[1], 1e-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, bc[2], 1e-12); + } + { + // point outside + double p[3] = { 2.0, 16.0, 18.0 }, bc[3]; + CPPUNIT_ASSERT_THROW(cuboid_mapped_coords(n, p, bc), INTERP_KERNEL::Exception); + } + + } + + /* Convention + - for QUAD4, point 0 is taken to be the origin (again see med file ref connec): + + 1------2 + | | + | | + 0------3 + */ + void UnitTetraIntersectionBaryTest::test_quad_mapped_coords_2D() + { + + double nodes[4][2] = { { 0.0, 0.0 }, + { 0.0, 1.0 }, + { 2.0, 3.0 }, + { 1.0, 0.0 } }; + + // Translate quad4: + for (int i=0; i < 4; ++i) + for (int j=0; j < 2; ++j) + nodes[i][j] += 15.0; + + std::vector n (4); + for (int i=0; i<4; i++) + n[i] = &nodes[i][0]; + + { + // middle point + double p[2] = { 15.75, 16.0 }, bc[2]; + quad_mapped_coords(n, p, bc); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, bc[0], 1e-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, bc[1], 1e-12); + } + + { + // middle point of seg + double p[2] = { 15.5, 15.0 }, bc[2]; + quad_mapped_coords(n, p, bc); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.5, bc[0], 1e-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, bc[1], 1e-12); + } + + { + // point 1 + double p[2] = { 15.0, 16.0 }, bc[2]; + quad_mapped_coords(n, p, bc); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, bc[0], 1e-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, bc[1], 1e-12); + } + { + // point 2 + double p[2] = { 17.0, 18.0 }, bc[2]; + quad_mapped_coords(n, p, bc); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, bc[0], 1e-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, bc[1], 1e-12); + } + { + // point 3 + double p[2] = { 16.0, 15.0 }, bc[2]; + quad_mapped_coords(n, p, bc); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, bc[0], 1e-12); + CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, bc[1], 1e-12); + } + { + // point outside + double p[2] = { 18.0, 18.0 }, bc[2]; + CPPUNIT_ASSERT_THROW(quad_mapped_coords(n, p, bc), INTERP_KERNEL::Exception); + } + } + + }