[Fwd: Re: [vtkusers] SetTCoords() broken?]

Terry J. Ligocki tjligocki at lbl.gov
Fri Feb 27 19:45:56 EST 2004


I wanted to forward the solution to a texture coordinates problem Ted 
Sternberg and I were having with VTK 4.4.  The problem and solution are 
enclosed below.  Our thanks to Berk Geveci (of Kitware) for clearing 
things up!

The executive summary is that Ted was moving some Python code from VTK 
3.2 to VTK 4.4 and the texture coordinate portion of the code failed to 
work.  Ted then determined that a Python example from VTK 3.2 also 
didn't work under VTK 4.4 (after correcting obvious API changes).

It turns out that VTK 3.2 only supported 2D textures maps.  If you 
specified a 2D texture map and 3D texture coordinates then it ignored 
the third component to get 2D texture coordinates.  VTK 4.4 also does 
not support 3D textures maps BUT if you specify a 2D texture map and 3D 
texture coordinates you get no texture (see below).  If you change to 2D 
texture coordinates everything is fine!

Our thanks to Berk for his help!

      Terry J. (Ligocki, tjligocki at lbl.gov)
      Applied Numerical Algorithms Group
      Lawrence Berkeley National Laboratory

/-- Every hour wounds, the last one kills/ - old saying

-------- Original Message --------
Subject: 	Re: [vtkusers] SetTCoords() broken?
Date: 	Mon, 16 Feb 2004 10:40:01 -0500
From: 	Berk Geveci <berklist at nycap.rr.com>
To: 	Theodore D. Sternberg <TDSternberg at lbl.gov>, TJLigocki at lbl.gov
References: 	<Pine.LNX.4.44.0402051241250.9655-100000 at hepburn.lbl.gov>



Hi Ted,

There is nothing broken in VTK. You are using 3D texture coordinates
with a 2D texture. Try this:

tCoords = vtkFloatArray()
tCoords.SetNumberOfComponents(2)
insert_func = tCoords.InsertTuple2

and get rid of the 3rd component where you are setting the coordinates.
I also had to change the top part of the script to:

from libvtkCommonPython import *
from libvtkImagingPython import *
from libvtkRenderingPython import *

-Berk

On Thu, 2004-02-05 at 15:45, Theodore D. Sternberg wrote:
> 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 =======================
> 
> _______________________________________________
> This is the private VTK discussion list. 
> Please keep messages on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
-- 
Berk Geveci <berklist at nycap.rr.com>/
/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040227/6d2178f4/attachment.htm>


More information about the vtkusers mailing list