[vtkusers] vtkFollower and SetScale Problem...

Andrea Gavana andrea.gavana at polymtl.ca
Mon Jul 12 05:21:44 EDT 2004


Hello NG,

      I'm having a problem using vtkVectorText + vtkFollower. I have a 3D grid 
(representing an oil reservoir) and I can display it together with a 3D cell 
mesh (wireframe of surface) and a polydata lines (representing the wells in the 
oil reservoir). What I would like to do, is to place a text above each well, in 
order to show the name of this well... so, I've tried vtkVectorText + 
vtkFollower, but I'm having some problem:

1) The grid coordinates have different order of magnitude (0<=x<=20000, 
0<=y<=20000, 0<=z<=300), so I have to scale the grid by using SetScale. For the 
same reason, I have to scale the Polydata that represents the wells in the 
reservoir;

2) Once I try to visualize the well names (using vtkVectorText + vtkFollower), 
the text is always too far away from the well, even if I give to the text the 
same position of the first point of the line that represent the well. It seems 
to me that no matter which z-coordinate I give to vtkFollower, the position is 
always the same.

3) If I remove the SetScale on the 3D grid+Wireframe+Polydata, the text 
position is almost correct (eve if the text is too big...). Unfortunately, I 
need to change the scale in order to understand something from the figure.

I post the relevant part of the code... does anyone have a suggestion? Thank 
you a lot.

Andrea.

# CODE BEGIN
# HERE the variable "nanna" represents my matrix of 3D coordinates for the grid 
# HERE the variable "zcentout" is only to assing a color to the points

vtk_xyz = vtkpython.vtkFloatArray()
vtk_xyz.SetNumberOfTuples(8*nx*ny*nz)
vtk_xyz.SetNumberOfComponents(3)
vtk_xyz.SetVoidArray(Numeric.ravel(nanna),24*nx*ny*nz,1)

vtk_pts = vtkpython.vtkPoints()
vtk_pts.SetNumberOfPoints(8*nx*ny*nz)
vtk_pts.SetDataTypeToFloat()
vtk_pts.SetData(vtk_xyz)

# create vtk data
a = vtkpython.vtkStructuredGrid()
a.SetDimensions(2*nx, 2*ny, 2*nz)
a.SetPoints(vtk_pts)

# create scalars

vtk_scal = vtkpython.vtkFloatArray()
vtk_scal.SetNumberOfTuples(8*nx*ny*nz)
vtk_scal.SetNumberOfComponents(1)
vtk_scal.SetVoidArray(Numeric.ravel(zcentout),8*nx*ny*nz,1)

a.GetPointData().SetScalars(vtk_scal)

# create tubes to represent the wells

profileTubes = vtkpython.vtkTubeFilter()
profileTubes.SetRadius(70.0)

# read VTK file with well position/coordinates

reader = vtkpython.vtkPolyDataReader()
reader.SetFileName("mywells.vtk")

mapsurface = vtkpython.vtkDataSetMapper()
mapedge = vtkpython.vtkDataSetMapper()

meshGeom = vtkpython.vtkExtractGrid()
meshGeom.SetInput(a)

mapsurface.SetInput(meshGeom.GetOutput())
mapedge.SetInput(meshGeom.GetOutput())

profileTubes.SetNumberOfSides(10)
profileTubes.SetInput(reader.GetOutput())

profileMapper = vtkpython.vtkPolyDataMapper()
profileMapper.SetInput(profileTubes.GetOutput())

# This is the 3D grid
actsurface = vtkpython.vtkActor()
actsurface.SetMapper(mapsurface)

# This is the 3D wireframe
actedge = vtkpython.vtkActor()
actedge.SetMapper(mapedge)

# This are the wells
profileactor = vtkpython.vtkActor()
profileactor.SetMapper(profileMapper)

data_range = a.GetScalarRange()
mapsurface.SetScalarRange(data_range)
mapsurface.ScalarVisibilityOn()
mapedge.SetScalarRange(data_range)
mapedge.ScalarVisibilityOff()

actsurface.GetProperty().SetRepresentationToSurface()
actsurface.SetScale(1.0,1.0,6.0)
actsurface.SetOrientation(135.0,0.0,0.0)

actedge.GetProperty().SetRepresentationToWireframe()
actedge.GetProperty().SetLineWidth(1.5)
actedge.SetScale(1.0,1.0,6.0)
actedge.SetOrientation(135.0,0.0,0.0)
actedge.GetProperty().SetColor(1,1,1)
actedge.GetProperty().SetAmbient(1.0);
actedge.GetProperty().SetDiffuse(0.0);
actedge.GetProperty().SetSpecular(0.0);

# TRY TO POSITION THE TEXT   <---- HELP HELP HELP
atext = vtkpython.vtkVectorText()
atext.SetText("MY WELL")
textMapper = vtkpython.vtkPolyDataMapper()
textMapper.SetInput(atext.GetOutput())
textActor = vtkpython.vtkFollower()
textActor.SetMapper(textMapper)
    
xmin, xmax, ymin, ymax, zmin, zmax = actsurface.GetBounds()
xmin1, xmax1, ymin1, ymax1, zmin1, zmax1 = profileactor.GetBounds()
xmin = min(xmin,xmin1)
ymin = min(ymin,ymin1)
zmin = min(zmin,zmin1)
xmax = max(xmax,xmax1)
ymax = max(ymax,ymax1)
zmax = max(zmax,zmax1)

scale = max((xmax-xmin),(ymax-ymin),(zmax-zmin))/40.0

textActor.SetOrigin(0,0,0)		
# self.wellt represent the well coordinates
textActor.SetPosition(self.wellt[0,0],self.wellt[0,1],self.wellt[0,2])
textActor.SetScale(scale, scale, scale)
textActor.GetProperty().SetColor(1, 1, 1)
textActor.PickableOff()	

# TRY TO POSITION THE TEXT   <---- HELP HELP HELP END


profileactor.GetProperty().SetColor(dim_grey)
profileactor.GetProperty().SetInterpolationToGouraud()
profileactor.GetProperty().SetBackfaceCulling(0)
profileactor.GetProperty().SetSpecular(.5)
profileactor.GetProperty().SetSpecularPower(100.0)
profileactor.GetProperty().SetAmbient(1.0)
profileactor.SetScale(1.0,1.0,6.0)
profileactor.SetOrientation(135.0,0.0,0.0)

self.window = wxFrame(None, -1, "VTK Reservoir Surface", wxPoint(100,10), wxSize
(1000,900),
            
style=wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER|wxNO_FULL_REPAINT_ON_RESIZE)

hiwin = wxVTKRenderWindow(self.window,-1,1)

hirenWin = hiwin.GetRenderWindow()

hiren = vtkpython.vtkRenderer()
hiren.SetRenderWindow(hirenWin)

hiren.AddActor(actsurface)
hiren.AddActor(actedge)
hiren.AddActor(textActor)
hiren.AddActor(profileactor)

hirenWin.AddRenderer(hiren)
hiren.GetActiveCamera().Zoom(1.5)
textActor.SetCamera(hiren.GetActiveCamera())

self.window.Show(TRUE)

iren = wxVTKRenderWindowInteractor(self.window, -1,1)
iren.SetRenderWindow(hirenWin)

dlg.Destroy()

self.renwin = hirenWin	
iren.Initialize()
iren.Start()





More information about the vtkusers mailing list