From 300cf3d0f689c16802bb7c3a52d913e4afc34762 Mon Sep 17 00:00:00 2001 From: Christophe Bourcier Date: Thu, 31 Aug 2017 15:47:08 +0200 Subject: [PATCH] Fix crash with some attractors --- src/BLSURFPlugin/BLSURFPlugin_Attractor.cxx | 13 ++++ tests/attractor.py | 77 +++++++++++++++++++++ tests/tests.set | 1 + 3 files changed, 91 insertions(+) create mode 100644 tests/attractor.py diff --git a/src/BLSURFPlugin/BLSURFPlugin_Attractor.cxx b/src/BLSURFPlugin/BLSURFPlugin_Attractor.cxx index 585b3ee..d06617b 100644 --- a/src/BLSURFPlugin/BLSURFPlugin_Attractor.cxx +++ b/src/BLSURFPlugin/BLSURFPlugin_Attractor.cxx @@ -222,6 +222,19 @@ double BLSURFPlugin_Attractor::_distanceFromMap(double u, double v){ int i = floor ( (u - _u1) * _gridU / (_u2 - _u1) + 0.5 ); int j = floor ( (v - _v1) * _gridV / (_v2 - _v1) + 0.5 ); + // avoid out of bounds of _DMap + if (i > _DMap.size()) + i = _DMap.size()-1; + + if (i < 0) + i = 0; + + if (j > _DMap[i].size()) + j = _DMap[i].size()-1; + + if (j < 0) + j = 0; + return _DMap[i][j]; } diff --git a/tests/attractor.py b/tests/attractor.py new file mode 100644 index 0000000..fd69c4c --- /dev/null +++ b/tests/attractor.py @@ -0,0 +1,77 @@ +# -*- coding: utf-8 -*- + +import sys +import salome + +salome.salome_init() +theStudy = salome.myStudy + +import SMESH, SALOMEDS + +## Compute the minimum area of the faces of the mesh +def getMinArea(mesh): + faces = mesh.GetElementsByType(SMESH.FACE) + areas = [mesh.GetArea(face) for face in faces] + return min(areas) + +### +### GEOM component +### + +import GEOM +from salome.geom import geomBuilder +import math +import SALOMEDS + + +geompy = geomBuilder.New(theStudy) + +O = geompy.MakeVertex(0, 0, 0) +OX = geompy.MakeVectorDXDYDZ(1, 0, 0) +OY = geompy.MakeVectorDXDYDZ(0, 1, 0) +OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) +Face_1 = geompy.MakeFaceHW(100, 100, 1) +Circle_1 = geompy.MakeCircle(None, None, 20) +geompy.addToStudy( O, 'O' ) +geompy.addToStudy( OX, 'OX' ) +geompy.addToStudy( OY, 'OY' ) +geompy.addToStudy( OZ, 'OZ' ) +geompy.addToStudy( Face_1, 'Face_1' ) +geompy.addToStudy( Circle_1, 'Circle_1' ) + +### +### SMESH component +### + +from salome.smesh import smeshBuilder + +smesh = smeshBuilder.New(theStudy) +Mesh_1 = smesh.Mesh(Face_1) +MG_CADSurf = Mesh_1.Triangle(algo=smeshBuilder.MG_CADSurf) +MG_CADSurf_Parameters_1 = MG_CADSurf.Parameters() +MG_CADSurf_Parameters_1.SetPhySize( 14.1421 ) +MG_CADSurf_Parameters_1.SetMinSize( 0.141421 ) +MG_CADSurf_Parameters_1.SetMaxSize( 28.2843 ) +MG_CADSurf_Parameters_1.SetChordalError( 7.07107 ) +#MG_CADSurf_Parameters_1.SetAttractorGeom( Face_1, Circle_1, 1, 14.1421, 5, 5 ) + +Mesh_1.Compute() + +min_area_without_attractor = getMinArea(Mesh_1) + +print "min_area_without_attractor: ", min_area_without_attractor + +MG_CADSurf_Parameters_1.SetAttractorGeom( Face_1, Circle_1, 1, 14.1421, 5, 5 ) + +Mesh_1.Compute() + +min_area_with_attractor = getMinArea(Mesh_1) + +print "min_area_with_attractor: ", min_area_with_attractor + +assert min_area_with_attractor < min_area_without_attractor + +assert min_area_with_attractor < 1 + +if salome.sg.hasDesktop(): + salome.sg.updateObjBrowser(True) diff --git a/tests/tests.set b/tests/tests.set index b1dde31..bcc05da 100644 --- a/tests/tests.set +++ b/tests/tests.set @@ -18,6 +18,7 @@ # SET(TEST_NAMES + attractor enforced_internal_vertex enforced_vertex multithread -- 2.39.2