]> SALOME platform Git repositories - plugins/blsurfplugin.git/commitdiff
Salome HOME
Fix crash with some attractors
authorChristophe Bourcier <christophe.bourcier@cea.fr>
Thu, 31 Aug 2017 13:47:08 +0000 (15:47 +0200)
committerChristophe Bourcier <christophe.bourcier@cea.fr>
Thu, 31 Aug 2017 13:47:08 +0000 (15:47 +0200)
src/BLSURFPlugin/BLSURFPlugin_Attractor.cxx
tests/attractor.py [new file with mode: 0644]
tests/tests.set

index 585b3eecceb3085c49b685bbf75f8f2d0ccd0bf9..d06617b1cdfc808b02a37eb417b486c14493ebc9 100644 (file)
@@ -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 (file)
index 0000000..fd69c4c
--- /dev/null
@@ -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)
index b1dde311fae55d87fa75f825465e26c9dbee04f2..bcc05da6ac109126866be5d35b5ed7c9473f3739 100644 (file)
@@ -18,6 +18,7 @@
 #
 
 SET(TEST_NAMES
+  attractor
   enforced_internal_vertex
   enforced_vertex
   multithread