[vtkusers] Python bug?

James Urquhart j_urquhart at btinternet.com
Wed Jan 14 07:27:43 EST 2004


Hi there,

I recently came across an odd bug when attempting to use my python script on 
another machine with the following installed :

VTK 4.2
Python 2.2
Gentoo Linux (flags "-mcpu=athlon-xp -O3 -pipe")

        def windStrip(self):
                # If we do not have VTK, we cannot use this code
                global hasVtk
                if hasVtk != 1:
                        print "Warning - triangle strips disabled due to lack 
of VTK."
                        return
                # We want to strip primitives per material index
                flags = self.calcFlags()

                stripLists = []
                newIndices = array('H')
                newPrimitives = []
                for i in range(0, len(flags)):
                        stripLists.append(array('H'))

                # Dump triangles
                for p in self.primitives:
                        for f in range(0, len(flags)):
                                if flags[f] == p.matindex:
                                        idx = f
                                        break
                        for ind in 
self.indices[p.firstElement:p.firstElement+p.numElements]:
                                stripLists[idx].append(ind)


                # Convert mesh points to VTK points
                points = vtkpython.vtkPoints()
                for vert in self.verts:
                        points.InsertNextPoint(vert[0], vert[1], vert[2])

                count = 0
                # Use VTK to strip each set of primitives
                for s in stripLists:
                        # Set up vtk
                        # Copy in mesh data

                        # Faces (triangles in vert list)
                        faces = vtkpython.vtkCellArray()
                        for st in range(0, len(s) / 3):
                                faces.InsertNextCell(3) # All triangles

                                # This maps from strip indices -> mesh indices 
(into mesh points list)
                                faces.InsertCellPoint(s[(st*3)])
                                faces.InsertCellPoint(s[(st*3)+1])
                                faces.InsertCellPoint(s[(st*3)+2])

                        newmesh = None
                        mesh = vtkpython.vtkPolyData()
                        mesh.SetPoints(points)
                        mesh.SetPolys(faces)

                        if mesh.GetNumberOfPolys() > 0:
                                strip = vtkpython.vtkStripper()
                                strip.DebugOn()
                                strip.SetInput(mesh)
                                strip.SetMaximumLength(self.maxStripSize)
                                strip.Update()
                                # Calculate max length of indices
                                maxInds = self.maxStripSize + 2
                                newmesh = strip.GetOutput()
                                del strip # clear stripper

However, i get a PythonError on strip.SetInput(mesh) :

Traceback (most recent call last):
  File "Dts_Test.py", line 399, in ?
    test7()     # uncomment if you have a obj to test against
  File "Dts_Test.py", line 357, in test7
    msh.windStrip() # Make the strip
  File "Dts_Mesh.py", line 846, in windStrip
    strip.SetInput(mesh)
ValueError: method requires a VTK object
Debug: In /home/jurquhart/open_source/VTK/Common/vtkObject.cxx, line 235
vtkStripper (0x827ff60): UnRegistered by NULL, ReferenceCount = 2

Debug: In /home/jurquhart/open_source/VTK/Common/vtkObject.cxx, line 235
vtkStripper (0x827ff60): UnRegistered by NULL, ReferenceCount = 2

Debug: In /home/jurquhart/open_source/VTK/Common/vtkObject.cxx, line 230
vtkStripper (0x827ff60): UnRegistered by vtkPolyData (0x827ffd0), 
ReferenceCount = 1

Debug: In /home/jurquhart/open_source/VTK/Common/vtkObject.cxx, line 235
vtkStripper (0x827ff60): UnRegistered by NULL, ReferenceCount = 0

Debug: In /home/jurquhart/open_source/VTK/Common/vtkObject.cxx, line 131
vtkObject (0x827ff60): Destructing!

But wait... i thought i already gave it a VTK object? What on earth is going 
on? :s

Has anyone else encountered this problem?

Thanks,
-James




More information about the vtkusers mailing list