[vtkusers] cutting a 4D set of points

Lorenzo Bernardi lorenzo.bernardi at lpn.cnrs.fr
Thu Jul 30 16:59:38 EDT 2009


Dear All,

   I have a 4D set of points (3 space coordinates x,y,z and a value k ) 
which are unstructured that is I just have the position and not the 
connectivity.  I would like to represent 2D cuts of this set. This 2D 
cut should be represented as 3d plot or maybe as a contour plot.

I managed to see something with ContourFilter and ProbeFilter but it 
looks that there is no interpolation between points. I mean the value 
seems to exist only a the defined points and is zero everywhere else.

Can someone explain me how to make a 3d plot of a cut with an 
interpolation between points or using vtkPolyData is not a good choice.

Or if someone has a piece of code for visualizing a 4D cloud of points 
I'll be interested in since I'm not sure cut is the best way to 
visualize the data. The value at each point  is the wavefunction.

Thanks in advance

L.

an example code greatly inspired by probecomp.py.

#!/usr/bin/python
# visualization of field described by a cloud of points

import vtk
import math

#creating the set of points (they are regular but I create it just as
# a set of points) and the value associated with

Vpoints=vtk.vtkPoints()
Vcell=vtk.vtkCellArray()

Vvalue=vtk.vtkDoubleArray()
Vvalue.SetName("values")

index=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            Vpoints.InsertPoint(index,i,j,k)
            Vvalue.InsertNextValue(math.cos(i)*math.cos(j)*math.cos(k))
            Vcell.InsertNextCell(1)
            Vcell.InsertCellPoint(index)
            index+=1
          
Vpolydata=vtk.vtkPolyData()
Vpolydata.SetPoints(Vpoints)
Vpolydata.SetVerts(Vcell)
Vpolydata.GetPointData().SetScalars(Vvalue)

print "Scalar Range: ",Vpolydata.GetScalarRange()
print "Bounds: ",Vpolydata.GetBounds()

# first visualisation of the points
Vmapper = vtk.vtkPolyDataMapper()
Vmapper.SetInput(Vpolydata)
Vmapper.SetScalarRange(-0.5, 1)

# Create an actor.
Vactor = vtk.vtkActor()
Vactor.SetMapper(Vmapper)


# creating the plane for the cut
plane = vtk.vtkPlaneSource()
plane.SetResolution(50, 50)

transP1 = vtk.vtkTransform()
transP1.Translate(5., 5.0, 5.0)
transP1.Scale(5, 5, 5)
transP1.RotateY(90)

tpd1 = vtk.vtkTransformPolyDataFilter()
tpd1.SetInputConnection(plane.GetOutputPort())
tpd1.SetTransform(transP1)

outTpd1 = vtk.vtkOutlineFilter()
outTpd1.SetInputConnection(tpd1.GetOutputPort())

mapTpd1 = vtk.vtkPolyDataMapper()
mapTpd1.SetInputConnection(outTpd1.GetOutputPort())

tpd1Actor = vtk.vtkActor()
tpd1Actor.SetMapper(mapTpd1)
tpd1Actor.GetProperty().SetColor(0, 0, 0)

probe = vtk.vtkProbeFilter()
probe.SetInputConnection(tpd1.GetOutputPort())
probe.SetSource(Vpolydata)

contour = vtk.vtkContourFilter()
contour.SetInputConnection(probe.GetOutputPort())
contour.GenerateValues(50, Vpolydata.GetScalarRange())

contourMapper = vtk.vtkPolyDataMapper()
contourMapper.SetInputConnection(contour.GetOutputPort())
contourMapper.SetScalarRange(Vpolydata.GetScalarRange())

planeActor = vtk.vtkActor()
planeActor.SetMapper(contourMapper)

# Create the rendering objects.
ren = vtk.vtkRenderer()
ren.AddActor(Vactor)
ren.AddActor(tpd1Actor)
ren.AddActor(planeActor)

ren.SetBackground(1, 1, 1)

renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)

iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

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




More information about the vtkusers mailing list