<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
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!<br>
<br>
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).<br>
<br>
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!<br>
<br>
Our thanks to Berk for his help!<br>
<br>
Terry J. (Ligocki, <a class="moz-txt-link-abbreviated"
href="mailto:tjligocki@lbl.gov">tjligocki@lbl.gov</a>)
<br>
Applied Numerical Algorithms Group
<br>
Lawrence Berkeley National Laboratory
<br>
<br>
<i>-- Every hour wounds, the last one kills</i> - old saying<br>
<br>
-------- Original Message --------
<table cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr>
<th valign="baseline" align="right" nowrap="nowrap">Subject: </th>
<td>Re: [vtkusers] SetTCoords() broken?</td>
</tr>
<tr>
<th valign="baseline" align="right" nowrap="nowrap">Date: </th>
<td>Mon, 16 Feb 2004 10:40:01 -0500</td>
</tr>
<tr>
<th valign="baseline" align="right" nowrap="nowrap">From: </th>
<td>Berk Geveci <a class="moz-txt-link-rfc2396E" href="mailto:berklist@nycap.rr.com"><berklist@nycap.rr.com></a></td>
</tr>
<tr>
<th valign="baseline" align="right" nowrap="nowrap">To: </th>
<td>Theodore D. Sternberg <a class="moz-txt-link-rfc2396E" href="mailto:TDSternberg@lbl.gov"><TDSternberg@lbl.gov></a>,
<a class="moz-txt-link-abbreviated" href="mailto:TJLigocki@lbl.gov">TJLigocki@lbl.gov</a></td>
</tr>
<tr>
<th valign="baseline" align="right" nowrap="nowrap">References: </th>
<td><a class="moz-txt-link-rfc2396E" href="mailto:Pine.LNX.4.44.0402051241250.9655-100000@hepburn.lbl.gov"><Pine.LNX.4.44.0402051241250.9655-100000@hepburn.lbl.gov></a></td>
</tr>
</tbody>
</table>
<br>
<br>
<pre>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: <a class="moz-txt-link-rfc2396E" href="http://public.kitware.com/cgi-bin/vtkfaq"><http://public.kitware.com/cgi-bin/vtkfaq></a>
> Follow this link to subscribe/unsubscribe:
> <a class="moz-txt-link-freetext" href="http://www.vtk.org/mailman/listinfo/vtkusers">http://www.vtk.org/mailman/listinfo/vtkusers</a>
--
Berk Geveci <a class="moz-txt-link-rfc2396E" href="mailto:berklist@nycap.rr.com"><berklist@nycap.rr.com></a><i>
</i>
</pre>
</body>
</html>