<!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.&nbsp; The problem and solution are
enclosed below.&nbsp; 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.&nbsp; 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.&nbsp; If you
specified a 2D texture map and 3D texture coordinates then it ignored
the third component to get 2D texture coordinates.&nbsp; 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).&nbsp; If you change to
2D texture coordinates everything is fine!<br>
<br>
Our thanks to Berk for his help!<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Terry J. (Ligocki, <a class="moz-txt-link-abbreviated"
 href="mailto:tjligocki@lbl.gov">tjligocki@lbl.gov</a>)
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Applied Numerical Algorithms Group
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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">&lt;berklist@nycap.rr.com&gt;</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">&lt;TDSternberg@lbl.gov&gt;</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">&lt;Pine.LNX.4.44.0402051241250.9655-100000@hepburn.lbl.gov&gt;</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:
&gt; SetTCoords() seems to have no effect.  I'm working with VTK checked out
&gt; from your CVS repository -- tag release-4-4.
&gt; 
&gt; Consider the program included below.  This is your triangularTexture.py
&gt; from the VTK3.2 distribution, modified by me to run under VTK4 as well
&gt; (vtkTCoords becomes vtkFloatArray, etc).
&gt; 
&gt; Run this against VTK3.2 ("python triangularTexture.py") and you get
&gt; something that looks like a diamond with some decorative cutouts (which
&gt; are the texture).  Run it against VTK4.4 ("vtkpython
&gt; triangularTexture.py") and you don't see the cutouts.  Run it against
&gt; VTK3.2 again -- this time commenting out the two places where SetTCoords()
&gt; gets invoked -- and it looks like it does under VTK4.4, i.e. no texture.
&gt; 
&gt; Ted Sternberg
&gt; Lawrence Berkeley National Laboratory
&gt; 
&gt; #======================== program begins here =======================
&gt; 
&gt; use_tcoords = 1
&gt; 
&gt; import os
&gt; 
&gt; from libVTKCommonPython import *
&gt; from libVTKGraphicsPython import *
&gt; 
&gt; try:
&gt;     foo = vtkTCoords()
&gt;     vtk_version = 3
&gt; except:
&gt;     vtk_version = 4
&gt; 
&gt; 
&gt; #
&gt; # create a triangular texture and save it as a ppm
&gt; #
&gt; ren = vtkRenderer()
&gt; renWin = vtkRenderWindow()
&gt; renWin.AddRenderer(ren)
&gt; renWin.SetSize(400,400)
&gt; iren = vtkRenderWindowInteractor()
&gt; iren.SetRenderWindow(renWin)
&gt; 
&gt; 
&gt; aTriangularTexture = vtkTriangularTexture()
&gt; aTriangularTexture.SetTexturePattern(1)
&gt; aTriangularTexture.SetXSize(32)
&gt; aTriangularTexture.SetYSize(32)
&gt;   
&gt; 
&gt; points = vtkPoints()
&gt; points.InsertPoint(0,0.0,0.0,0.0)
&gt; points.InsertPoint(1,1.0,0.0,0.0)
&gt; points.InsertPoint(2,.5,1.0,0.0)
&gt; points.InsertPoint(3,1.0,0.0,0.0)
&gt; points.InsertPoint(4,0.0,0.0,0.0)
&gt; points.InsertPoint(5,.5,-1.0,.5)
&gt; 
&gt; if   vtk_version == 3:
&gt;     tCoords = vtkTCoords()
&gt;     insert_func = tCoords.InsertTCoord
&gt; elif vtk_version == 4:
&gt;     tCoords = vtkFloatArray()
&gt;     tCoords.SetNumberOfComponents(3)
&gt;     insert_func = tCoords.InsertTuple3
&gt; apply(insert_func, (0,0.0,0.0,0.0))
&gt; apply(insert_func, (1,1.0,0.0,0.0))
&gt; apply(insert_func, (2,.5,.86602540378443864676,0.0))
&gt; apply(insert_func, (3,0.0,0.0,0.0))
&gt; apply(insert_func, (4,1.0,0.0,0.0))
&gt; apply(insert_func, (5,.5,.86602540378443864676,0.0))
&gt; 
&gt; pointData = vtkPointData()
&gt; if use_tcoords:
&gt;     pointData.SetTCoords(tCoords)
&gt; 
&gt; triangles = vtkCellArray()
&gt; triangles.InsertNextCell(3)
&gt; triangles.InsertCellPoint(0)
&gt; triangles.InsertCellPoint(1)
&gt; triangles.InsertCellPoint(2)
&gt; triangles.InsertNextCell(3)
&gt; triangles.InsertCellPoint(3)
&gt; triangles.InsertCellPoint(4)
&gt; triangles.InsertCellPoint(5)
&gt; 
&gt; triangle = vtkPolyData()
&gt; triangle.SetPolys(triangles)
&gt; triangle.SetPoints(points)
&gt; if use_tcoords:
&gt;     triangle.GetPointData().SetTCoords(tCoords)
&gt; 
&gt; triangleMapper = vtkPolyDataMapper()
&gt; triangleMapper.SetInput(triangle)
&gt; 
&gt; aTexture = vtkTexture()
&gt; aTexture.SetInput(aTriangularTexture.GetOutput())
&gt; 
&gt; triangleActor = vtkActor()
&gt; triangleActor.SetMapper(triangleMapper)
&gt; triangleActor.SetTexture(aTexture)
&gt; 
&gt; ren.SetBackground(.3,.7,.2)
&gt; ren.AddActor(triangleActor)
&gt; ren.GetActiveCamera().Zoom(1.5)
&gt; 
&gt; # render the image
&gt; #
&gt; iren.Initialize()
&gt; 
&gt; iren.Start()
&gt; #======================== program ends here =======================
&gt; 
&gt; _______________________________________________
&gt; This is the private VTK discussion list. 
&gt; Please keep messages on-topic. Check the FAQ at: <a class="moz-txt-link-rfc2396E" href="http://public.kitware.com/cgi-bin/vtkfaq">&lt;http://public.kitware.com/cgi-bin/vtkfaq&gt;</a>
&gt; Follow this link to subscribe/unsubscribe:
&gt; <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">&lt;berklist@nycap.rr.com&gt;</a><i>
</i>
</pre>
</body>
</html>