Geometry

Base

class occmodel.Base

Definition of virtual base object

boundingBox(self, double tolerance=1e-12) → AABBox

Return bounding box

Parameters:tolerance – Tolerance of calculation.
fromString(self, char *st)

Restore shape from string.

The format used is the OpenCASCADE internal BREP format.

hasPlane(self, Point origin=None, Vector normal=None, double tolerance=1e-12) → int

Check if object has plane defined. Optional pass origin and normal argument to fetch the plane definition.

Parameters:
  • origin – Plane origin
  • normal – Plane normal
  • tolerance – Plane tolerance
hashCode(self) → int

Shape hash code.

Orientation is not included in the hash calculation. Instances of the same object therfore return the same hash code.

isEqual(self, Base other) → int

Check object for equallity. Returns True only if both the underlying geometry and location is similar.

isNull(self) → int

Check if object is Null.

isValid(self) → int

Return if object is valid.

mirror(self, Plane plane, int copy=False)

Mirror object

Parameters:
  • plane – mirror plane
  • copy – If True the object is translated in place otherwise a new translated object is returned.
rotate(self, double angle, axis, center=(0.0, 0.0, 0.0), int copy=False)

Rotate object.

Parameters:
  • angle – rotation angle in radians
  • axis – axis vector
  • center – rotation center
  • copy – If True the object is transformed in place otherwise a new transformed object is returned.
scale(self, pnt, double scale, int copy=False)

Scale object.

Parameters:
  • pnt – reference point
  • scale – scale factor
  • copy – If True the object is translated in place otherwise a new translated object is returned.
shapeType(self)

Return class type or None if shape not known.

toString(self)

Seralize object to string.

The format used is the OpenCASCADE internal BREP format.

transform(self, Transform mat, int copy=False)

Apply transformation matrix to object.

Parameters:
  • mat – Transformation matrix
  • copy – If True the object is translated in place otherwise a new translated object is returned.
translate(self, delta, int copy=False)

Translate object.

Parameters:
  • delta – translation vector (dx,dy,dz)
  • copy – If True the object is translated in place otherwise a new translated object is returned.

Vertex

class occmodel.Vertex

Vertex(double x=0.0, double y=0.0, double z=0.0)

Vertex

X(self) → double
Y(self) → double
Z(self) → double

Edge

class occmodel.Edge

Edge()

Edge - represent a single curve.

boundingBox(self, double tolerance=1e-12) → AABBox

Return bounding box

copy(self, int deepCopy=False) → Edge

Create copy of edge

Parameters:deepCopy – If true a full copy of the underlying geometry is done. Defaults to False.
copyFrom(self, Edge edge, int deepCopy=False) → Edge

Set self from copy of edge

Parameters:
  • edge – Edge to copy
  • deepCopy – If true a full copy of the underlying geometry is done. Defaults to False.
createArc(self, start, end, center)

Create arc from given start, end and center points.

example:

e1 = Edge().createArc(start = (-.5,0.,0.), end = (.5,1.,0.), center = (.5,0.,0.))
createArc3P(self, start, end, pnt)

Create arc from start to end and fitting through given point.

example:

e1 = Edge().createArc3P(start = (1.,0.,0.), end = (-1.,0.,0.), pnt = (0.,1.,0.))
createBezier(self, Vertex start=None, Vertex end=None, points=None)

Create bezier curve. Optional start and end Vertex object can be given otherwise start and end are extracted from the points sequence.

example:

pnts = ((0.,0.,0.), (0.,1.,0.), (1.,.5,0.), (1.,0.,0.))
e1 = Edge().createBezier(points = pnts)
createCircle(self, center, normal, double radius)

Create circle from center, normal direction and radius.

example:

e1 = Edge().createCircle(center = (0.,.0,0.), normal = (0.,0.,1.), radius = 1.)
createEllipse(self, center, normal, double rMajor, double rMinor)

Create ellipse from center, normal direction and given major and minor axis.

example:

e1 = Edge().createEllipse(center=(0.,0.,0.),normal=(0.,0.,1.), rMajor = .5, rMinor=.2)
createHelix(self, double pitch, double height, double radius, double angle=0.0, int leftHanded=False)

Create helix curve.

example:

e1 = Edge().createHelix(pitch = .5, height = 1., radius = .25, angle = pi/5.)
createLine(self, start, end)

Create straight line from given start and end points

example:

e1 = Edge().createLine(start = (0.,0.,0.), end = (1.,1.,0.))
createNURBS(self, Vertex start=None, Vertex end=None, points=None, knots=None, weights=None, mults=None)

Create NURBS curve.

Parameters:
  • start – optional start Vertex
  • end – optional end Vertex
  • points – sequence of controll points
  • knots – sequence of kont values
  • weights – sequence of controll point weights
  • mults – sequence of knot multiplicity

If start and end Vertex objects are not given the start and end point is given by the points sequence.

createSpline(self, Vertex start=None, Vertex end=None, points=None, tolerance=1e-06)

Create interpolating spline.

Optional start and end Vertex object can be given otherwise start and end are extracted from the points sequence.

example:

pnts = ((0.,0.,0.), (0.,.5,0.), (1.,.25,0.),(1.,0.,0.))
e1 = Edge().createSpline(points = pnts)
isClosed(self) → int

Check if edge is closed

isDegenerated(self) → int

Check if edge is degenerated e.g. collapsed etc.

isSeam(self, Face face) → int

Check if edge is a seam on face

length(self) → double

Return edge length

numVertices(self) → int

Return number of vertices

tesselate(self, double factor=0.1, double angle=0.1) → Tesselation

Tesselate edge to given max angle or distance factor

Wire

class occmodel.Wire

Wire(edges=None)

Wire - represent wire geometry (composite of edges).

Wires defines boundaries of faces.

chamfer(self, distance, vertices=None)

Chamfer vertices inplace.

Parameters:
  • distance – sequence of distances or single distance.
  • vertices – sequence of vertices or single vertex. Setting the argument to None will select all vertices (default)
common(self, arg)

Create boolean intersection inplace. The wire must be planar and the operation must result in a single wire.

Multiple objects are supported.

Edges, wires and faces are extruded in the normal directions to intersect the wire.

copy(self, int deepCopy=False) → Wire

Create copy of wire

Parameters:deepCopy – If true a full copy of the underlying geometry is done. Defaults to False.
copyFrom(self, Wire wire, int deepCopy=False) → Wire

Set self from copy of wire

Parameters:
  • wire – Wire to copy
  • deepCopy – If true a full copy of the underlying geometry is done. Defaults to False.
createPolygon(self, points, int close=True)

Create a polygon from given points.

Parameters:
  • point – Point sequence.
  • close – Close the polygon.

example:

w1 = Wire().createPolygon((
    (0.,0.,0.),
    (0.,0.,1.),
    (.75,0.,1.),
    (.75,0.,0.)),
    close = False
)
createRectangle(self, double width=1.0, double height=1.0, double radius=0.0)

Create planar rectangle in the xy plan.

The rectangle is centered at 0,0 with given width, height and optional corner radius.

example:

w1 = Wire().createRectangle(width = 1., height = 0.75, radius = .25)
createRegularPolygon(self, double radius=1.0, int sides=6, mode=INSCRIBE)

Create a planar regular polygon in the xy plane centered at (0,0).

The polygon can either be inscribed or circumscribe the circle by setting the mode argument.

Parameters:
  • radius – circle radius
  • sides – number of sides (>3)
  • mode – INSCRIBE or CIRCUMSCRIBE the given circle radius.

example:

w1 = Wire().createRegularPolygon(radius = .5, sides = 6.)
createWire(self, edges)

Create wire by connecting edges or a single closed edge.

cut(self, arg)

Create boolean difference inplace. The wire must be planar and the operation must result in a single wire.

Multiple objects are supported.

Edges, wires and faces are extruded in the normal directions to intersect the wire.

fillet(self, radius, vertices=None)

Fillet vertices inplace.

Parameters:
  • radius – sequence of radiuses or single radius.
  • vertices – sequence of vertices or single vertex. Setting the argument to None will select all vertices (default)
isClosed(self) → int

Check if wire is closed

length(self) → double

Return wire length

numEdges(self) → int

Return number of edges

numVertices(self) → int

Return number of vertices

offset(self, double distance, int joinType=JOINTYPE_ARC)

Offset wire inplace the given distance.

project(self, Face face)

Project wire towards face.

tesselate(self, double factor=0.1, double angle=0.1) → Tesselation

Tesselate wire to given max angle or distance factor

Face

class occmodel.Face

Face(arg=None)

Face - Reprecent face geometry

The face geometry could be represented by several underlying faces (a OpenCASCADE shell) or a single face.

area(self)

Return face area

centreOfMass(self)

Return center of face

common(self, arg)

Create boolean intersection inplace. The face must be planar and the operation must result in a single face.

Multiple objects are supported.

Edges, wires and faces are extruded in the normal directions to intersect the face.

copy(self, int deepCopy=False) → Face

Create copy of face

Parameters:deepCopy – If true a full copy of the underlying geometry is done. Defaults to False.
createConstrained(self, edges, points=None)

Create general face constrained by edges and optional points.

Parameters:
  • edges – sequence of face edges
  • points – optional sequence of point constraints

example:

e1 = Edge().createCircle(center=(0.,0.,0.),normal=(0.,0.,1.),radius = .5)
f1 = Face().createConstrained(e1, ((0.,.0,.25),))
createFace(self, arg)

Create planar face from one or more wires or closed edges.

The first argument must be the outer contour. Additional arguments define holes in the face.

example:

w1 = Wire().createRectangle(width = 1., height = 1., radius = 0.)
e1 = Edge().createCircle(center=(0.,0.,0.),normal=(0.,0.,1.),radius = .25)
f1 = Face().createFace((w1, e1))
createMesh(self, double factor=0.01, double angle=0.25, int qualityNormals=False) → Mesh

Create triangle mesh of face.

Parameters:
  • factor – deflection from true position
  • angle – max angle
  • qualityNormals – create normals by evaluating surface parameters
createPolygonal(self, points)

Create polygonal face from given points. The points must lie in a common plane.

example:

pnts = ((-.5,-.5,0.), (0.,.5,0.), (1.,.5,0.), (.5,-.5,0.))
f1 = Face().createPolygonal(pnts)
cut(self, arg)

Create boolean difference inplace. The face must be planar and the operation must result in a single face.

Multiple objects are supported.

Edges, wires and faces are extruded in the normal directions to intersect the face.

extrude(self, Base shape, p1, p2)

Create extrusion face.

Parameters:
  • shape – Wire or edge
  • p1 – start point
  • p2 – end point.

example:

e1 = Edge().createArc(start = (-.5,-.25,0.), end = (.5,.75,0.), center = (.5,-.25,0.))
f1 = Face().extrude(e1, (0.,0.,0.), (0.,0.,1.))
inertia(self)

return intertia of face with respect to center of gravity.

Return Ixx, Iyy, Izz, Ixy, Ixz, Iyz

loft(self, profiles, int ruled=True, double tolerance=1e-06)

Create face by lofting through profiles.

Parameters:
  • profiles – sequence of edges, wires and optional a vertex at the start and end.
  • ruled – Smooth or ruled result shape
  • tolerance – Operation tolerance.

example:

e1 = Edge().createArc((0.,0.,0.),(1.,0.,1.),(1.,0.,0.))
e2 = Edge().createArc((0.,1.,0.),(2.,1.,2.),(2.,1.,0.))
f1 = Face().loft((e1,e2))
numFaces(self) → int

Return number of faces

numWires(self) → int

Return number of wires

offset(self, double offset, double tolerance=1e-06)

Offseting face given distance.

Parameters:offset – offset distance
revolve(self, Base shape, p1, p2, double angle)

Create by revolving shape.

Parameters:
  • shape – Edge or wire.
  • p1 – Start point of axis
  • p2 – End point of axis
  • angle – Angle in radians

example:

pnts = ((0.,0.,0.), (0.,1.,0.), (1.,.5,0.), (1.,0.,0.))
e1 = Edge().createBezier(points = pnts)
f1 = Face().revolve(e1, (0.,-1.,0.), (1.,-1.,0.), pi/2.)
sweep(self, spine, profiles, int cornerMode=0)

Create face by sweeping along spine through sequence of shapes. Optionally the start and end can be a vertex.

Parameters:
  • spine – Edge or wire to define sweep path
  • profiles – Sequence of edges, wires or optional start and end vertex.

example:

e1 = Edge().createArc((0.,0.,0.), (1.,0.,1.), (1.,0.,0.))
e2 = Edge().createCircle(center=(0.,0.,0.),normal=(0.,0.,1.),radius = .25)
f1 = Face().sweep(e1, e2)

Solid

class occmodel.Solid

Solid()

Geometry represention solid objects or compund solid.

addSolids(self, solids)

Create compund solid from sequence of solid objects.

This is usefull for accelerating boolean operation where multiple objects are used as the tool.

area(self)

Return solid area

centreOfMass(self)

return center of mass of solid.

chamfer(self, distances, edges=None)

Chamfer edges inplace.

Parameters:
  • distances – sequence of distances for each edge or single distance.
  • edges – sequence of edges or single edge. Setting the argument to None will select all edges (default)
common(self, arg)

Create boolean intersection inplace.

Multiple objects are supported.

Edges, wires and faces are extruded in the normal directions to intersect the solid.

Edges and wires allways cut through all, but faces are limited by the face itself.

copy(self, int deepCopy=False) → Solid

Create copy of solid

Parameters:deepCopy – If true a full copy of the underlying geometry is done. Defaults to False.
copyFrom(self, Solid solid, int deepCopy=False) → Solid

Set self from copy of solid

Parameters:
  • solid – Solid to copy
  • deepCopy – If true a full copy of the underlying geometry is done. Defaults to False.
createBox(self, p1, p2)

Create box from points defining diagonal.

example:

s1 = Solid().createBox((-.5,-.5,-.5),(.5,.5,.5))
createCone(self, p1, p2, double radius1, double radius2)

Create cone

Parameters:
  • p1 – axis start
  • p2 – axis end
  • radius1 – radius at start
  • radius2 – radius at end

example:

s1 = Solid().createCone((0.,0.,0.),(0.,0.,1.), .2, .5)
createCylinder(self, p1, p2, double radius)

Create cylinder

Parameters:
  • p1 – Axis start
  • p2 – Axis end
  • radius – Cylinder radius

example:

s1 = Solid().createCylinder((0.,0.,0.),(0.,0.,1.), .25)
createMesh(self, double factor=0.01, double angle=0.25, int qualityNormals=False) → Mesh

Create triangle mesh of solid.

Parameters:
  • factor – deflection from true position
  • angle – max angle
  • qualityNormals – create normals by evaluating surface parameters
createPrism(self, obj, normal, int isInfinite)

Create prism from edge/wire/face in direction of normal.

This solid is infinite/semi-infinite and usefull for cutting and intersection operations with regular solids.

createSolid(self, faces, double tolerance=0.0)

Create general solid by sewing together faces with the given tolerance.

Parameters:
  • faces – Sequence of faces
  • tolerance – Sewing operation tolerance.
createSphere(self, center, double radius)

Create sphere from center point and radius.

Parameters:
  • center – Center point
  • radius – Sphere radius

example:

s1 = Solid().createSphere((0.,0.,0.),.5)
createText(self, double height, double depth, text, fontpath=None)

Extrude TTF font data to solids

Height :font height
Depth :extrusion depth
Text :text content. Only single line of text (UTF-8)
Fontpath :path to TTF font file
createTorus(self, p1, p2, double ringRadius, double radius)

Create torus

Parameters:
  • p1 – axis start
  • p2 – axis end
  • ringRadius – ring radius
  • radius – radius tube section

example:

s1 = Solid().createTorus((0.,0.,0.),(0.,0.,.1), .5, .1)
cut(self, arg)

Create boolean difference inplace.

Multiple objects are supported.

Edges, wires and faces are extruded in the normal directions to intersect the solid.

Edges and wires allways cut through all, but faces are limited by the face itself.

extrude(self, obj, p1, p2)

Create solid by extruding edge, wire or face from p1 to p2.

Parameters:
  • p1 – start point
  • p2 – end point

example:

e1 = Edge().createLine((-.5,0.,0.),(.5,0.,0.))
e2 = Edge().createArc3P((.5,0.,0.),(-.5,0.,0.),(0.,.5,0.))
w1 = Wire().createWire((e1,e2))
f1 = Face().createFace(w1)
s1 = Solid().extrude(f1, (0.,0.,0.), (0.,0.,1.))
fillet(self, radius, edges=None)

Fillet edges inplace.

Parameters:
  • radius – sequence of radiuses or single radius.
  • edges – sequence of edges or single edge. Setting the argument to None will select all edges (default)
fuse(self, arg)

Create boolean union inplace.

Multiple solids are supported.

inertia(self)

return intertia of solid with respect to center of gravity.

Return Ixx, Iyy, Izz, Ixy, Ixz, Iyz

loft(self, profiles, int ruled=True, double tolerance=1e-06)

Create solid by lofting through sequence of wires or closed edges.

Parameters:
  • profiles – sequence of closed edges, closed wires and optional a vertex at the start and end.
  • ruled – Smooth or ruled result shape
  • tolerance – Operation tolerance.

example:

e1 = Edge().createCircle(center=(.25,0.,0.),normal=(0.,0.,1.),radius = .25)
e2 = Edge().createCircle(center=(.25,0.,.5),normal=(0.,0.,1.),radius = .5)
v1 = Vertex(.25,0.,1.)
s1 = Solid().loft((e1,e2,v1))
numFaces(self) → int

Return number of faces

numSolids(self) → int

Return number of solids

offset(self, Face face, double offset, double tolerance=1e-06)

Create solid by offseting face given distance.

Parameters:
  • face – face object
  • offset – offset distance
pipe(self, Face face, path)

Create pipe by extruding face along path. The path can be a Edge or Wire. Note that the path must be C1 continious.

example:

e1 = Edge().createHelix(.4, 1., .4)
e2 = Edge().createCircle(center=(.5,0.,0.),normal=(0.,1.,0.),radius = 0.1)
f1 = Face().createFace(e2)
s1 = Solid().pipe(f1, e1)
revolve(self, Face face, p1, p2, double angle)

Create solid by revolving face

Parameters:
  • p1 – start of axis
  • p2 – end of axis
  • angle – revolve angle in radians

example:

e1 = Edge().createEllipse(center=(0.,0.,0.),normal=(0.,0.,1.), rMajor = .5, rMinor=.2)
f1 = Face().createFace(e1)
s1 = Solid().revolve(f1, (1.,0.,0.), (1.,1.,0.), pi/2.)
section(self, Plane plane)

Apply section operation between solid and plane.

Parameters:plane – section plane

Result returned as a face.

shell(self, double offset, faces=None, double tolerance=0.0001)

Apply shell operation on solid.

Parameters:
  • faces – sequence of faces or single face. If no argument is supplied the first face is selected.
  • offset – shell offset distance
sweep(self, spine, profiles, int cornerMode=0)

Create solid by sweeping along spine through sequence of wires. Optionally the start and end can be a vertex.

Parameters:
  • spine – Edge or wire to define sweep path
  • profiles – Sequence of closed edges, closed wires or optional start and end vertex.

example:

w1 = Wire().createPolygon((
    (0.,0.,0.),
    (0.,0.,1.),
    (.75,0.,1.),
    (.75,0.,0.)),
    close = False
)
e1 = Edge().createCircle(center=(0.,0.,0.),normal=(0.,0.,1.),radius = .2)
s1 = Solid().sweep(w1, e1)
volume(self)

Return solid volume

Tools

class occmodel.Tools

Misc tools.

readBREP(filename)

Read shapes from a BREP file.

A sequence of shapes are returned.

readSTEP(filename)

Read shapes from a STEP file.

A sequence of shapes are returned.

writeBREP(filename, shapes)

Write a sequence of shapes or a single shape to a BREP file.

writeSTEP(filename, shapes)

Write a sequence of shapes or a single shape to a STEP file.

writeSTL(filename, shapes)

Write a sequence of shapes or a single shape to a STL file.

writeVRML(filename, shapes)

Write a sequence of shapes or a single shape to a VRML file.

Mesh

class occmodel.Mesh

Mesh()

Mesh - Represent triangle mesh for viewing purpose

isValid(self) → int
nedgeIndices(self) → size_t

Return number of edge indices

nedgeRanges(self) → size_t

Return number of edge ranges

nnormals(self) → size_t

Return number of normals

normal(self, size_t index)

Return normal at given vertex index

ntriangles(self) → size_t

Return number of triangles

nvertices(self) → size_t

Return number of vertices

optimize(self)

Vertex Cache Optimisation

triangle(self, size_t index)

Return triangle indices at given index

vertex(self, size_t index)

Return vertex at given index

edgeIndices

edgeIndices: View.MemoryView.array

edgeIndicesItemSize

edgeIndicesItemSize: ‘int’

edgeRanges

edgeRanges: View.MemoryView.array

edgeRangesItemSize

edgeRangesItemSize: ‘int’

normals

normals: View.MemoryView.array

normalsItemSize

normalsItemSize: ‘int’

triangles

triangles: View.MemoryView.array

trianglesItemSize

trianglesItemSize: ‘int’

vertices

vertices: View.MemoryView.array

verticesItemSize

verticesItemSize: ‘int’

Tesselation

class occmodel.Tesselation

Tesselation()

Tesselation - Representing Edge/Wire tesselation which result in
possible multiple disconnected polylines.
isValid(self) → int
nranges(self) → size_t

Return number of range values

nvertices(self) → size_t

Return number of vertices

ranges

ranges: View.MemoryView.array

rangesItemSize

rangesItemSize: ‘int’

vertices

vertices: View.MemoryView.array

verticesItemSize

verticesItemSize: ‘int’

Visualization

class occmodelviewer.Viewer
activeUI(self, x, y)
add(self, obj, color=None)

Add object

clear(self)

Remove all objects

hide(self, obj)

Hide object

onBackView(self)
onBottomView(self)
onChar(self, ch)
onClose(self)
onCursorPos(self, x, y)
onFlushUI(self)
onFrontView(self)
onGradient(self)
onIsoView(self)
onKey(self, key, action)
onLeftView(self)
onMouseButton(self, button, action)
onObjects(self)
onPick(self)
onRefresh(self)
onRightView(self)
onScreenShot(self, prefix='screenshot')
onScroll(self, scx, scy)
onSetup(self)
onSize(self, w, h)
onTopView(self)
onUI(self)
onUIHelp(self)
onUIQuit(self)
onZoomExtents(self)
redraw(self)

Redraw view

remove(self, obj)

Remove object

unHide(self, obj=None)

Unhide object

updateBounds(self)

Recalculate bounding box

occmodelviewer.viewer(objs, colors=None, interactive=False, logger=<???>)

Viewer

Objs :Single object or sequence of objects.
Colors :Color or sequence of colors. Defaults to COLORS. The object color is cycled from the seqence or set to single color.
Interactive :Install input hook for interactive use. Note that the returned reference to the viewer must be referenced to keep the viewer alive.
Logger :File to write error messages to. Defaults to stderr.

Table Of Contents

Previous topic

Introduction

This Page