99from scipy .spatial import Delaunay
1010from matplotlib import cm
1111from OCC .Core .MeshDS import MeshDS_DataSource
12- from OCC .Core .MeshVS import MeshVS_DMF_OCCMask , MeshVS_Mesh , MeshVS_ElementalColorPrsBuilder , MeshVS_DA_ShowEdges , MeshVS_DMF_ElementalColorDataPrs , MeshVS_DataMapOfIntegerColor
12+ from OCC .Core .MeshVS import (
13+ MeshVS_DMF_OCCMask ,
14+ MeshVS_Mesh ,
15+ MeshVS_ElementalColorPrsBuilder ,
16+ MeshVS_DA_ShowEdges ,
17+ MeshVS_DMF_ElementalColorDataPrs ,
18+ MeshVS_DataMapOfIntegerColor ,
19+ )
1320from OCC .Display .SimpleGui import init_display
1421from OCC .Core .Quantity import Quantity_Color , Quantity_TOC_RGB
1522
@@ -19,12 +26,13 @@ def getMesh(X=100, Y=100):
1926 x = np .linspace (- 5 , 5 , X )
2027 y = np .linspace (- 5 , 5 , Y )
2128 xx , yy = np .meshgrid (x , y , sparse = False )
22- z = ( np .sin (xx ** 2 + yy ** 2 ) / (xx ** 2 + yy ** 2 ) )
29+ z = np .sin (xx ** 2 + yy ** 2 ) / (xx ** 2 + yy ** 2 )
2330 xyz = np .column_stack ((xx .flatten (), yy .flatten (), z .flatten ()))
2431 tri = Delaunay (xyz [:, :2 ])
2532 return xyz , tri .simplices
2633
27- #get some mesh data
34+
35+ # get some mesh data
2836vertices , faces = getMesh ()
2937
3038# generate face values
@@ -33,7 +41,7 @@ def getMesh(X=100, Y=100):
3341z_min = np .min (vertices [:, 2 ])
3442z_ptp = np .ptp (vertices [:, 2 ])
3543
36- face_colors = [cmap ((value - z_min )/ z_ptp )[:3 ] for value in face_values ]
44+ face_colors = [cmap ((value - z_min ) / z_ptp )[:3 ] for value in face_values ]
3745
3846# Create the datasource. Data is taken directly from the numpy arrays. both have to be contiguous and Nx3 (double), Mx3 (int).
3947mesh_ds = MeshDS_DataSource (vertices , faces )
@@ -43,12 +51,14 @@ def getMesh(X=100, Y=100):
4351mesh_vs .SetDataSource (mesh_ds )
4452
4553# create nodal builder and assign to the mesh
46- element_builder = MeshVS_ElementalColorPrsBuilder (mesh_vs , MeshVS_DMF_ElementalColorDataPrs | MeshVS_DMF_OCCMask )
54+ element_builder = MeshVS_ElementalColorPrsBuilder (
55+ mesh_vs , MeshVS_DMF_ElementalColorDataPrs | MeshVS_DMF_OCCMask
56+ )
4757
4858# set normalized color intensity to node
4959for nFace in range (faces .shape [0 ]):
5060 color = Quantity_Color (* face_colors [nFace ], Quantity_TOC_RGB )
51- element_builder .SetColor1 (nFace + 1 , color ) # element indices are 1 based
61+ element_builder .SetColor1 (nFace + 1 , color ) # element indices are 1 based
5262
5363# Add the builder to the visualizer
5464mesh_vs .AddBuilder (element_builder , True )
0 commit comments