OCC: interface to open-cascade
Preamble
OCC performs CAD operations and surface meshing using open-cascade.
To use the module with the Converter.array interface:
import OCC
To use the module with the CGNS/Python interface:
import OCC.PyTree as OCC
List of functions
– CAD to surface mesh
Get a first TRI meshed tree linked to CAD. |
– CAD to surface mesh (legacy functions)
Convert a CAD (IGES or STEP) file to arrays. |
|
Convert a CAD (IGES or STEP) file to pyTree. |
– CAD manipulation
Read CAD file and return a CAD hook. |
|
Write CAD file. |
|
Return the number of edges in CAD hook. |
|
Return the number of faces in CAD hook. |
|
Return the area of given faces. |
|
Translate all or given faces. |
|
Rotate all or given faces. |
|
Split all faces to be less than area. |
|
Merge some faces. |
|
Sew some faces (suppress redundant edges). |
Contents
CAD to surface mesh
- OCC.PyTree.meshAll(hook, hmin=-1, hmax=-1., hausd=-1.)
Mesh a CAD with triangles. If hmin=hmax, mesh with a regular h. If hmin, hmax and hausd are set, mesh with isotropic triangles with local size adapted to curvature. hausd is the max chordal error of mesh to CAD. This function returns a tree with two bases (EDGES and FACES). EDGES contains discretized edges with a link to the global edge number in CAD. FACES contains discretized faces with a link to the global face number in CAD.
- Parameters:
hook (CAD hook) – CAD hook
- Return type:
mesh
CAD to surface mesh (legacy functions)
- OCC.convertCAD2Arrays(fileName, format='fmt_iges', h=0., chordal_err=0., growth_ratio=0., algo=1)
Read a CAD and return arrays.
- Parameters:
fileName (string) – CAD file name
format (string) – file format (‘fmt_iges’ or ‘fmt_step’)
h (float) – step size on output mesh. If 0., automatic setting [algo=1,2].
chordal_error (float) – max error between CAD and mesh. Result in curvature adaptation. If 0., automatic setting.
growth_ratio (float) – max growth ratio between adjacent triangles [algo=1,2].
algo (int) – algo=0: mesh with only respect to curvature, algo=1 or algo=2: mesh with regular triangles.
- Return type:
a list of TRI arrays
Example of use:
# - convertCAD2Arrays (arrays) - import Converter as C import OCC # IGES avec T3Mesher A = OCC.convertCAD2Arrays('hammer.iges', format='fmt_iges', h=0., chordal_err=0., growth_ratio=0.8, algo=1) C.convertArrays2File(A, 'hammer1.plt') # IGES avec OCC A = OCC.convertCAD2Arrays('hammer.iges', format='fmt_iges', chordal_err=1, algo=0) C.convertArrays2File(A, 'hammer2.plt') # STEP avec T3Mesher A = OCC.convertCAD2Arrays('as1-oc-214.stp', format='fmt_step', h=0., chordal_err=0., growth_ratio=0.8, algo=1) C.convertArrays2File(A, 'as1.plt') # STEP avec OCC A = OCC.convertCAD2Arrays('as1-oc-214.stp', format='fmt_step', chordal_err=1, algo=0) C.convertArrays2File(A, 'as2.plt')
- OCC.PyTree.convertCAD2PyTree(fileName, format='fmt_iges', h=0., chordal_err=0., growth_ratio=0., algo=1)
Read a CAD and return a zone.
- Parameters:
fileName (string) – CAD file name
format (string) – file format (‘fmt_iges’ or ‘fmt_step’)
h (float) – step size on output mesh. If 0., automatic setting [algo=1,2].
chordal_error (float) – max error between CAD and mesh. Result in curvature adaptation. If 0., automatic setting.
growth_ratio (float) – max growth ratio between adjacent triangles [algo=1,2].
algo (int) – algo=0: mesh with only respect to curvature, algo=1 or algo=2: mesh with regular triangles.
- Return type:
CGNS pyTree
Example of use:
# - convertIGES2PyTree (PyTree) - import OCC.PyTree as OCC import Converter.PyTree as C t = OCC.convertCAD2PyTree('hammer.iges', h=0., chordal_err=0., algo=1) C.convertPyTree2File(t, 'out.cgns')
CAD manipulation
- OCC.readCAD(fileName, format='fmt_step')
Read a CAD file and return a CAD hook.
- Parameters:
fileName (string) – CAD file name
format (string) – file format (‘fmt_iges’ or ‘fmt_step’)
- Return type:
CAD hook
Example of use:
# - readCAD (pyTree) - import OCC.PyTree as OCC hook = OCC.readCAD("cube.step", "fmt_step")
- OCC.writeCAD(hook, fileName, format='fmt_step')
Write a CAD hook to a file.
- Parameters:
hook (CAD hook) – CAD hook
fileName (string) – CAD file name
format (string) – file format (‘fmt_iges’ or ‘fmt_step’)
Example of use:
# - writeCAD (pyTree) - import OCC.PyTree as OCC hook = OCC.readCAD("cube.step", "fmt_step") OCC.writeCAD(hook, "out.step", "fmt_step")
- OCC.getNbEdges(hook)
Return the total number of edges in a CAD hook.
- Parameters:
hook (CAD hook) – CAD hook
- Return type:
int
Example of use:
# - getNbEdges (pyTree) - import OCC.PyTree as OCC hook = OCC.readCAD("cube.step", "fmt_step") print(OCC.getNbEdges(hook)) #> 12
- OCC.getNbFaces(hook)
Return the number of faces in a CAD hook.
- Parameters:
hook (CAD hook) – CAD hook
- Return type:
int
Example of use:
# - getNbFaces (pyTree) - import OCC.PyTree as OCC hook = OCC.readCAD("cube.step", "fmt_step") print(OCC.getNbFaces(hook)) #> 6
- OCC.getFaceArea(hook, listFaces=[])
Return the area of given faces.
- Parameters:
hook (CAD hook) – CAD hook
listFaces (list of face index (starts 1)) – list of faces number to calculate the area
- Return type:
float
Example of use:
# - getFaceArea (pyTree) - import OCC.PyTree as OCC h = OCC.readCAD('cube.step', 'fmt_step') # Area of all model print(OCC.getFaceArea(h)) # Area of seome faces print(OCC.getFaceArea(h, [1,2]))
- OCC._translate(hook, vector, listOfFaces=None)
Translate a CAD hook by a given vector.
- Parameters:
hook (CAD hook) – CAD hook
vector (tuple of floats) – translation vector (dx, dy, dz)
listOfFaces (list of face indices (starts 1)) – if None, translate all else translate only given faces
Example of use:
# - translate (pyTre) - import OCC.PyTree as OCC hook = OCC.readCAD("cube.step", "fmt_step") OCC._translate(hook, (1,0,0)) OCC.writeCAD(hook, 'out.step', 'fmt_step')
- OCC._rotate(hook, Xc, axis, angle, listOfFaces=None)
Rotate a CAD hook around a given axis by a given angle.
- Parameters:
hook (CAD hook) – CAD hook
Xc (tuple of floats) – rotation center (x, y, z)
axis (tuple of floats) – rotation axis
angle (float) – rotation angle in degrees
listOfFaces (list of face indices (starts 1)) – if None, rotate all else rotate only given faces
Example of use:
# - rotate (pyTree) - import OCC.PyTree as OCC hook = OCC.readCAD("cube.step", "fmt_step") OCC._rotate(hook, (0,0,0), (0,0,1), 30.) OCC.writeCAD(hook, 'out.step', 'fmt_step')
- OCC._splitFaces(hook, area)
Split faces in a CAD hook.
- Parameters:
hook (CAD hook) – CAD hook
area (float) – split each face if area greater than this value
Example of use:
# - splitFaces (pyTree) - import OCC.PyTree as OCC hook = OCC.readCAD("cube.step", "fmt_step") OCC._splitFaces(hook, 20.) OCC.writeCAD(hook, "out.step", "fmt_step")
- OCC._mergeFaces(hook, listFaces=None)
Merge faces in a CAD hook.
- Parameters:
hook (CAD hook) – CAD hook
listFaces (list of face indices (starts 1)) – if None, merge all faces else list of faces indices to merge
Example of use:
# - mergeFaces (array) - import OCC.PyTree as OCC hook = OCC.readCAD("cube.step", "fmt_step") OCC._splitFaces(hook, 200.) # merge given faces OCC._mergeFaces(hook, [1,2,3]) # merge all faces OCC._mergeFaces(hook) OCC.writeCAD(hook, "out.step", "fmt_step")
- OCC._sewing(hook, listFaces=None, tol=1.e-6)
Sew faces. Supress redundant edges.
- Parameters:
hook (CAD hook) – CAD hook
listFaces (list of face indices (starts 1)) – if None, merge all faces else list of faces indices to merge
tol (float) – tolerance for sewing
Example of use:
# - sewing (pyTree) - import OCC.PyTree as OCC hook = OCC.readCAD("cube.step", "fmt_step") OCC._sewing(hook, tol=1.e-6, listFaces=[1,2]) OCC._sewing(hook, tol=1.) OCC.writeCAD(hook, 'out.step', 'fmt_step')