Skip to content

Commit 3655cd3

Browse files
committed
added smesh unittest
1 parent 3dfdd0f commit 3655cd3

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

test/core_smesh_unittest.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env python
2+
3+
##Copyright 2009-2013 Thomas Paviot (tpaviot@gmail.com)
4+
##
5+
##This file is part of pythonOCC.
6+
##
7+
##pythonOCC is free software: you can redistribute it and/or modify
8+
##it under the terms of the GNU Lesser General Public License as published by
9+
##the Free Software Foundation, either version 3 of the License, or
10+
##(at your option) any later version.
11+
##
12+
##pythonOCC is distributed in the hope that it will be useful,
13+
##but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
##GNU Lesser General Public License for more details.
16+
##
17+
##You should have received a copy of the GNU Lesser General Public License
18+
##along with pythonOCC. If not, see <http://www.gnu.org/licenses/>.
19+
20+
from __future__ import print_function
21+
22+
import unittest
23+
import os
24+
25+
from OCC.BRepPrimAPI import BRepPrimAPI_MakeSphere
26+
27+
from OCC.SMESH import SMESH_Gen, SMESH_MeshVSLink
28+
from OCC.StdMeshers import (StdMeshers_Arithmetic1D, StdMeshers_TrianglePreference,
29+
StdMeshers_Regular_1D, StdMeshers_Quadrangle_2D)
30+
31+
class TestSMESH(unittest.TestCase):
32+
def test_mesh_sphere_quadrangle(self):
33+
aShape = BRepPrimAPI_MakeSphere(10.).Shape()
34+
# Create the Mesh
35+
aMeshGen = SMESH_Gen()
36+
aMesh = aMeshGen.CreateMesh(0, True)
37+
# 1D
38+
an1DHypothesis = StdMeshers_Arithmetic1D(0, 0, aMeshGen)#discretization of the wire
39+
an1DHypothesis.SetLength(0.1, False) #the smallest distance between 2 points
40+
an1DHypothesis.SetLength(0.5, True) # the longest distance between 2 points
41+
an1DAlgo = StdMeshers_Regular_1D(1, 0, aMeshGen) # interpolation
42+
# 2D
43+
a2dHypothseis = StdMeshers_TrianglePreference(2, 0, aMeshGen) #define the boundary
44+
a2dAlgo = StdMeshers_Quadrangle_2D(3, 0, aMeshGen) # the 2D mesh
45+
#Calculate mesh
46+
aMesh.ShapeToMesh(aShape)
47+
#Assign hyptothesis to mesh
48+
aMesh.AddHypothesis(aShape, 0)
49+
aMesh.AddHypothesis(aShape, 1)
50+
aMesh.AddHypothesis(aShape, 2)
51+
aMesh.AddHypothesis(aShape, 3)
52+
#Compute the data
53+
aMeshGen.Compute(aMesh, aMesh.GetShapeToMesh())
54+
55+
56+
def suite():
57+
suite = unittest.TestSuite()
58+
suite.addTest(unittest.makeSuite(TestSMESH))
59+
return suite
60+
61+
if __name__ == "__main__":
62+
unittest.main()

test/run_tests.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@
2929
HAVE_OCAF = False
3030
# Create test suite
3131
import core_webgl_unittest
32-
32+
try:
33+
import core_smesh_unittest
34+
HAVE_SMESH = True
35+
except:
36+
HAVE_SMESH = False
3337
suite = unittest.TestSuite()
3438

3539
# Get all test suites from modules
@@ -42,6 +46,9 @@
4246
tests.append(suite4)
4347
suite5 = core_webgl_unittest.suite()
4448
tests.append(suite5)
49+
if HAVE_SMESH:
50+
suite6 = core_smesh_unittest.suite()
51+
tests.append(suite6)
4552
# Add test cases
4653
suite.addTests(tests)
4754

0 commit comments

Comments
 (0)