Skip to content
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.

Commit

Permalink
Make viewer more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
tenko committed Oct 25, 2012
1 parent 3a061ef commit b3d0ad2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
15 changes: 15 additions & 0 deletions occmodel/occmodel.pyx
Expand Up @@ -37,9 +37,16 @@ cdef class Tesselation:
args = self.nvertices(), self.nranges()
return "(nvertices = %d, ranges = %d)" % args

cpdef bint isValid(self):
cdef c_OCCTesselation *occ = <c_OCCTesselation *>self.thisptr
return occ.vertices.size() > 0 and occ.ranges.size() > 0

cdef setArrays(self):
cdef c_OCCTesselation *occ = <c_OCCTesselation *>self.thisptr

if not self.isValid():
return

self.verticesItemSize = sizeof(float)
self.rangesItemSize = sizeof(unsigned int)

Expand Down Expand Up @@ -106,9 +113,17 @@ cdef class Mesh:
args = self.nvertices(), self.ntriangles(), self.nnormals()
return "(nvertices = %d, ntriangles = %d, nnormals = %d)" % args

cpdef bint isValid(self):
cdef c_OCCMesh *occ = <c_OCCMesh *>self.thisptr
return occ.vertices.size() > 0 and occ.normals.size() > 0 and \
occ.triangles.size() > 0

cdef setArrays(self):
cdef c_OCCMesh *occ = <c_OCCMesh *>self.thisptr

if not self.isValid():
return

self.verticesItemSize = sizeof(float)
self.normalsItemSize = sizeof(float)
self.trianglesItemSize = sizeof(unsigned int)
Expand Down
25 changes: 19 additions & 6 deletions occmodel/occmodelviewer.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
import math
import array
Expand Down Expand Up @@ -145,7 +146,9 @@ def addObject(self, obj, color = None):
res.color = color

tess = obj.tesselate()

if not tess.isValid():
return False

# update bounding box
bbox = obj.boundingBox()
self.bbox.addPoint(bbox.min)
Expand All @@ -170,7 +173,9 @@ def addObject(self, obj, color = None):
res = FaceObj()

mesh = obj.createMesh()

if not mesh.isValid():
return False

# update bounding box
bbox = obj.boundingBox()
self.bbox.addPoint(bbox.min)
Expand Down Expand Up @@ -227,7 +232,9 @@ def addObject(self, obj, color = None):
res = SolidObj()

mesh = obj.createMesh()

if not mesh.isValid():
return False

# update bounding box
bbox = obj.boundingBox()
self.bbox.addPoint(bbox.min)
Expand Down Expand Up @@ -272,6 +279,11 @@ def addObject(self, obj, color = None):
)

self.objects.add(res)

else:
raise GLError('unknown object type')

return True

def onSetup(self):
self.ui = gl.UI()
Expand Down Expand Up @@ -651,7 +663,7 @@ def onIsoView(self):
self.onZoomExtents()


def viewer(objs, colors = None):
def viewer(objs, colors = None, logger = sys.stderr):
if not isinstance(objs, (tuple,list)):
objs = (objs,)

Expand All @@ -668,10 +680,11 @@ def viewer(objs, colors = None):
for obj, color in itertools.izip(objs, itertools.cycle(colors)):
# skip Null objects.
if obj.isNull():
print("skipped object: '%s'" % str(obj))
print("skipped Null object", file=logger)
continue

mw.addObject(obj, color)
if not mw.addObject(obj, color):
print("skipped object", file=logger)

mw.onIsoView()
mw.mainLoop()
Expand Down

0 comments on commit b3d0ad2

Please sign in to comment.