[vtkusers] Texturing a surface triangle - how to?
Tron Darvann
tdarvann at lab3d.odont.ku.dk
Mon May 2 04:59:04 EDT 2005
Dear VTK-users,
Does anybody know how to accomplish the following:
I have
1) a triangle defined as 3 points,
2) And I have a texture (a 2D image), and finally I have
3) the texture coordinates for 3 positions in the texture.
How do I paste my triangular patch of the image as a 2D texture
onto my triangle?
The simple example in TPlane_test.tcl pastes a texture onto a
vtkPlaneSource, but in that example the texture coordinates
are created by the vtkPlaneSource. In my case the texture
coordinates are read from file and inserted e.g. into a
vtkFloatArray (is that the way to do it?) [I am aware of the
possibillites for creating texture coordinates through
vtkTextureMapToPlane, vtkTextureMapToSphere and vtkTextureMapToCylinder
and manipulation through vtkTransformTextureCoords, BUT since I
already have my coordinates explicitly defined, I do not need
these classes...]
(Eventually, when I know how to paste texture on a
single triangle, I can go on to texture all the triangles
in a surface scan of an object.)
Thanks for any suggestions.
Tron Darvann
Here some code to get the idea of what I'm trying to do:
# This script (modified from CreateStrip.tcl)
# shows how to manually create a vtkPolyData with a
# triangle. Then we paste a texture onto it using
# three texture coordinates in an image...?
package require vtk
package require vtkinteraction
# First we'll create some points.
#
vtkPoints points
points InsertPoint 0 0.0 0.0 0.0
points InsertPoint 1 0.0 1.0 0.0
points InsertPoint 2 1.0 0.0 0.0
vtkCellArray strips
strips InsertNextCell 3;#number of points
strips InsertCellPoint 0
strips InsertCellPoint 1
strips InsertCellPoint 2
vtkPolyData profile
profile SetPoints points
profile SetStrips strips
vtkPolyDataMapper map
map SetInput profile
vtkBMPReader bmpReader
bmpReader SetFileName "C:/tron/projects/3dMD/export/050406092854.bmp"
vtkTexture atext
atext SetInput [bmpReader GetOutput]
atext InterpolateOn
vtkActor triangle
triangle SetMapper map
triangle SetTexture atext
# Explicitly specify texture coordinates: a triangular patch in the input texture.
vtkFloatArray texcoord
texcoord SetNumberOfComponents 2
texcoord SetNumberOfTuples 3
texcoord SetTuple2 0 0.2348 0.7891
texcoord SetTuple2 1 0.2454 0.7830
texcoord SetTuple2 2 0.2128 0.7790
###### HERE MISSING CODE: TO APPLY THE TEXTURE COORDINATES !!!####
# Create the usual rendering stuff.
vtkRenderer ren1
vtkRenderWindow renWin
renWin AddRenderer ren1
vtkRenderWindowInteractor iren
iren SetRenderWindow renWin
# Add the actors to the renderer, set the background and size
#
ren1 AddActor triangle
ren1 SetBackground 1 1 1
renWin SetSize 250 250
renWin Render
# render the image
#
iren AddObserver UserEvent {wm deiconify .vtkInteract}
# prevent the tk window from showing up then start the event loop
wm withdraw .
More information about the vtkusers
mailing list