[vtkusers] SetTCoords() broken?

Theodore D. Sternberg tdsternberg at lbl.gov
Thu Feb 5 15:45:09 EST 2004


SetTCoords() seems to have no effect.  I'm working with VTK checked out
from your CVS repository -- tag release-4-4.

Consider the program included below.  This is your triangularTexture.py
from the VTK3.2 distribution, modified by me to run under VTK4 as well
(vtkTCoords becomes vtkFloatArray, etc).

Run this against VTK3.2 ("python triangularTexture.py") and you get
something that looks like a diamond with some decorative cutouts (which
are the texture).  Run it against VTK4.4 ("vtkpython
triangularTexture.py") and you don't see the cutouts.  Run it against
VTK3.2 again -- this time commenting out the two places where SetTCoords()
gets invoked -- and it looks like it does under VTK4.4, i.e. no texture.

Ted Sternberg
Lawrence Berkeley National Laboratory

#======================== program begins here =======================

use_tcoords = 1

import os

from libVTKCommonPython import *
from libVTKGraphicsPython import *

try:
    foo = vtkTCoords()
    vtk_version = 3
except:
    vtk_version = 4


#
# create a triangular texture and save it as a ppm
#
ren = vtkRenderer()
renWin = vtkRenderWindow()
renWin.AddRenderer(ren)
renWin.SetSize(400,400)
iren = vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)


aTriangularTexture = vtkTriangularTexture()
aTriangularTexture.SetTexturePattern(1)
aTriangularTexture.SetXSize(32)
aTriangularTexture.SetYSize(32)
  

points = vtkPoints()
points.InsertPoint(0,0.0,0.0,0.0)
points.InsertPoint(1,1.0,0.0,0.0)
points.InsertPoint(2,.5,1.0,0.0)
points.InsertPoint(3,1.0,0.0,0.0)
points.InsertPoint(4,0.0,0.0,0.0)
points.InsertPoint(5,.5,-1.0,.5)

if   vtk_version == 3:
    tCoords = vtkTCoords()
    insert_func = tCoords.InsertTCoord
elif vtk_version == 4:
    tCoords = vtkFloatArray()
    tCoords.SetNumberOfComponents(3)
    insert_func = tCoords.InsertTuple3
apply(insert_func, (0,0.0,0.0,0.0))
apply(insert_func, (1,1.0,0.0,0.0))
apply(insert_func, (2,.5,.86602540378443864676,0.0))
apply(insert_func, (3,0.0,0.0,0.0))
apply(insert_func, (4,1.0,0.0,0.0))
apply(insert_func, (5,.5,.86602540378443864676,0.0))

pointData = vtkPointData()
if use_tcoords:
    pointData.SetTCoords(tCoords)

triangles = vtkCellArray()
triangles.InsertNextCell(3)
triangles.InsertCellPoint(0)
triangles.InsertCellPoint(1)
triangles.InsertCellPoint(2)
triangles.InsertNextCell(3)
triangles.InsertCellPoint(3)
triangles.InsertCellPoint(4)
triangles.InsertCellPoint(5)

triangle = vtkPolyData()
triangle.SetPolys(triangles)
triangle.SetPoints(points)
if use_tcoords:
    triangle.GetPointData().SetTCoords(tCoords)

triangleMapper = vtkPolyDataMapper()
triangleMapper.SetInput(triangle)

aTexture = vtkTexture()
aTexture.SetInput(aTriangularTexture.GetOutput())

triangleActor = vtkActor()
triangleActor.SetMapper(triangleMapper)
triangleActor.SetTexture(aTexture)

ren.SetBackground(.3,.7,.2)
ren.AddActor(triangleActor)
ren.GetActiveCamera().Zoom(1.5)

# render the image
#
iren.Initialize()

iren.Start()
#======================== program ends here =======================




More information about the vtkusers mailing list