[vtkusers] vtkScalars

Malcolm Drummond malcolm at geovision.co.za
Tue Apr 6 16:14:14 EDT 2004


Hi Reagan

You must now assign one of the concrete vtkDataArray to scalars. Here's a
python script using vtkUnsignedCharArray - see facecolors and sgrid. If you
search the site you should find something about deprecation of
vtkAttributeData and sub-classes (vtk 4.0 onwards).

HTH
Malcolm

#----------------------------------------------

from vtk import *

# Create the RenderWindow, Renderer and RenderWindowInteractor
ren1 = vtkRenderer()
renWin = vtkRenderWindow()
renWin.AddRenderer(ren1)
iren = vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

# create a 2*2 cell/3*3 pt structuredgrid
points = vtkPoints()
points.InsertNextPoint(-1,1,0)
points.InsertNextPoint(0,1,0)
points.InsertNextPoint(1,1,0)
points.InsertNextPoint(-1,0,0)
points.InsertNextPoint(0,0,0)
points.InsertNextPoint(1,0,0)
points.InsertNextPoint(-1,-1,0)
points.InsertNextPoint(0,-1,0)
points.InsertNextPoint(1,-1,0)

faceColors = vtkUnsignedCharArray()

faceColors.SetNumberOfComponents(4)
faceColors.SetNumberOfTuples(4)

faceColors.SetComponent(0,0,0)
faceColors.SetComponent(0,1,255)
faceColors.SetComponent(0,2,0)
faceColors.SetComponent(0,3,255)
faceColors.SetComponent(1,0,0)
faceColors.SetComponent(1,1,255)
faceColors.SetComponent(1,2,0)
faceColors.SetComponent(1,3,175)
faceColors.SetComponent(2,0,0)
faceColors.SetComponent(2,1,255)
faceColors.SetComponent(2,2,0)
faceColors.SetComponent(2,3,100)
faceColors.SetComponent(3,0,0)
faceColors.SetComponent(3,1,255)
faceColors.SetComponent(3,2,0)
faceColors.SetComponent(3,3,25)

sgrid = vtkStructuredGrid()
sgrid.SetDimensions(3,3,1)
sgrid.SetPoints(points)
sgrid.GetCellData().SetScalars(faceColors)
faceColors.Modified()

sggf = vtkStructuredGridGeometryFilter()
sggf.SetInput(sgrid)
spdm = vtkPolyDataMapper()
spdm.SetInput(sggf.GetOutput())

mapper = vtkDataSetMapper()
mapper.SetInput(sgrid)
#mapper.SetScalarModeToUseCellData()

actor = vtkActor()
actor.SetMapper(mapper)
#actor SetMapper mapper spdm
actor.GetProperty().SetOpacity(0.999)

cyl = vtkCylinderSource()
cyl.SetResolution(10)
pdm = vtkPolyDataMapper()
pdm.SetInput(cyl.GetOutput())
cylinder = vtkActor()
cylinder.SetMapper(pdm)
cylinder.GetProperty().SetColor(0,0,1)

# Add the actors to the renderer, set the background and size
ren1.AddActor(actor)
ren1.AddActor(cylinder)
ren1.SetBackground(1,1,1)
renWin.SetSize(512,512)

iren.Initialize()
renWin.Render()
iren.Start()

#------------------------------------------------

----- Original Message -----
From: "Reagan Penner" <rpenner at cs.usask.ca>
To: "vtkusers" <vtkusers at vtk.org>
Sent: Tuesday, April 06, 2004 6:47 PM
Subject: [vtkusers] vtkScalars


> Hello, I am new to vtk, I have been given some older code that uses a
> function to generate a model.
>
> So far from what I can see most if not all of the examples use either
> the data that ships with vtk or the built in objects such as
> "vtkConeSource".
>
> As I mentioned above my model is generated from a c++ function and is
> simply a lot of single data values stored in a list. This old source
> used vtkScalars to hold this data however, I noticed that vtkScalars no
> longer exists in 4.2. I am wondering if there are any good examples that
> deal with user generated (single value) data points. Any examples that
> build up there own models would be helpful.
>
> thanks for your time ................. Reagan Penner
>
> _______________________________________________
> 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
>




More information about the vtkusers mailing list