[vtkusers] Texture problems
Roger Blum
roger_blum at swissonline.ch
Tue May 2 03:34:29 EDT 2006
Hi everybody,
I try to put JPG images as a texture on some polygones (vtkPolyData). To
achieve this is have the following pipeline:
vtkPoints ------
> vtkPolyData ------> vtkPolyDataMapper -------
vtkCellArray ---
> vtkActor
vtkJPEGReader ------> vtkTexture ----------------------------------
I have created a Tcl test script to experiment with different PolyData.
- If I create the polydata with vtkCubeSource the texture is displayed
correctly on 2 (of 6) sides of the cube.
- If I create the polygons with point/cells, the color of the whole polygon
is the same (depending on the colors of the image).
I insert my test script for illustration purposes. To change the polydata
source just comment/uncomment the appropriate line following the
vtkPolyDataMapper instantiation (PDM SetInput ...)
Note: I have done this with vtk 5.0 on Windows.
Any hint to slove the problem is very much appreciated.
Regards,
Roger
# ----------------------------------
# File: testCubeTexture.tcl
# Created by vtkgui v 1.0
# ----------------------------------
vtkCommand DeleteAllObjects
# ------------------------------------------------------------
# Call the VTK Tcl packages to make available all VTK commands
# ------------------------------------------------------------
package require vtk
package require vtkinteraction
package require vtktesting
# --------------------------------------------------------------
# Create a Renderer, a RenderWindow and a RenderWindowInteractor
# --------------------------------------------------------------
vtkRenderer R
R SetBackground 0.1 0.1 0.1
R SetLightFollowCamera 1
vtkRenderWindow RW
RW AddRenderer R
RW AddRenderer R
RW SetSize 981 482
vtkRenderWindowInteractor RWI
RWI SetRenderWindow RW
RWI SetLightFollowCamera 1
# -----------------------
# Create the VTK pipeline
# -----------------------
vtkCubeSource CS
CS SetCenter 0 0 0
CS SetXLength 1
CS SetYLength 1
CS SetZLength 1
# ---------------------------------------------------------------------------
# Define polygons
vtkPoints P
P InsertPoint 0 771000 266000 1
P InsertPoint 1 776000 266000 1
P InsertPoint 2 776000 260000 1
P InsertPoint 3 771000 260000 1
P InsertPoint 4 765000 270000 1
P InsertPoint 5 771000 275000 1
P InsertPoint 6 776000 275000 1
P InsertPoint 7 782000 270000 1
P InsertPoint 8 765000 290000 1
P InsertPoint 9 776000 290000 1
P InsertPoint 10 776000 280000 1
P InsertPoint 11 771000 280000 1
vtkPolygon PG1
[PG1 GetPointIds] SetNumberOfIds 4
[PG1 GetPointIds] SetId 0 3
[PG1 GetPointIds] SetId 1 2
[PG1 GetPointIds] SetId 2 1
[PG1 GetPointIds] SetId 3 0
vtkPolygon PG2
[PG2 GetPointIds] SetNumberOfIds 6
[PG2 GetPointIds] SetId 0 0
[PG2 GetPointIds] SetId 1 1
[PG2 GetPointIds] SetId 2 7
[PG2 GetPointIds] SetId 3 6
[PG2 GetPointIds] SetId 3 5
[PG2 GetPointIds] SetId 3 4
vtkPolygon PG3
[PG3 GetPointIds] SetNumberOfIds 4
[PG3 GetPointIds] SetId 0 11
[PG3 GetPointIds] SetId 1 10
[PG3 GetPointIds] SetId 2 9
[PG3 GetPointIds] SetId 3 8
vtkCellArray CA
CA InsertNextCell PG1
CA InsertNextCell PG2
CA InsertNextCell PG3
vtkPolyData PD
PD SetPoints P
PD SetPolys CA
vtkLinearExtrusionFilter LEF
LEF SetInput PD
LEF SetExtrusionTypeToVectorExtrusion
LEF SetVector 0 1 1
LEF SetScaleFactor 3000
LEF CappingOn
vtkCleanPolyData CPD
CPD SetInput PD
vtkPoints P2
P2 InsertPoint 0 1 1 1
P2 InsertPoint 1 1 2 1
P2 InsertPoint 2 2 2 1
P2 InsertPoint 3 2 1 1
vtkCellArray CA2
CA2 InsertNextCell 4
CA2 InsertCellPoint 0
CA2 InsertCellPoint 1
CA2 InsertCellPoint 2
CA2 InsertCellPoint 3
vtkPolyData PD2
PD2 SetPoints P2
PD2 SetPolys CA2
vtkPlaneSource PS
vtkPolyDataMapper PDM
# PDM SetInput [PS GetOutput]
# PDM SetInput [LEF GetOutput]
# PDM SetInput PD
# PDM SetInput [CS GetOutput]
# PDM SetInput [CPD GetOutput]
PDM SetInput PD2
PDM SetNumberOfPieces 1
PDM SetScalarRange 0 1
PDM SetColorMode 0
PDM SetResolveCoincidentTopology 0
PDM SetScalarMode 0
PDM SetImmediateModeRendering 0
PDM SetScalarVisibility 1
PDM SetUseLookupTableScalarRange 0
vtkJPEGReader JPEGR
JPEGR SetOutput [JPEGR GetOutput]
JPEGR SetFileName C:/temp/mytexture.jpg
JPEGR SetFilePattern %s.%d
JPEGR SetDataByteOrder 1
JPEGR SetDataScalarType 3
vtkTexture T
T SetInput [JPEGR GetOutput]
T SetQuality 0
T SetInterpolate 1
T SetMapColorScalarsThroughLookupTable 0
T RepeatOff
vtkActor A
A SetMapper PDM
A SetTexture T
A SetOrigin 0 0 0
A SetPosition 0 0 0
A SetScale 1 1 1
A SetPickable 1
A SetVisibility 1
# -----------------------------------
# Insert all actors into the renderer
# -----------------------------------
R AddActor A
# -------------------------------------
# Reset the camera and show the console
# -------------------------------------
R ResetCamera
R ResetCameraClippingRange
RW Render
#RWI Start
;# To enable a console, uncomment next line
#console show
wm withdraw .
update
More information about the vtkusers
mailing list