[vtkusers] VTK CVS + wxPython...

Andrea Gavana andrea.gavana at polymtl.ca
Wed Jul 21 04:22:42 EDT 2004


Hello NG,

      thank you for the suggestions about downloading the CVS source of VTK, I
corrected the cvsgrab script in order to get the files from CVSView and now I
have all the source code for VTK-CVS. For those who may be interested, I've
corrected the file cvsgrab.bat in this way:

Replace the line:

java -classpath %CVSGRAB_HOME%\lib\cvsgrab.jar %LOG_ARGS% %HOME_ARG%
%ANT_CMD_LINE_ARGS%

With the line:

java -jar %CVSGRAB_HOME%\lib\cvsgrab.jar %LOG_ARGS% %HOME_ARG%
%ANT_CMD_LINE_ARGS%

I don't know why, but now it works. Anyway, I've compiled the VTK source code
using CMake and Visual Studio 6 (VTK Release configuration). I have all the
*.dll file correctly created with no warnings or errors.
My problem concerns the use of VTK within a wxPython window; with the older
version of VTK (4.2) I had no problem, but now when I run my application the
wxFrame in which I create the VTK surface is frozen: I can not interact with it
(rotate, pan, zoom) and I can not even resize the window... if I click on close
button, the Windows Task Manager appears telling me that the program is not
responding and I have to kill it.
My script is at the end of the mail... basically, it creates a 3D grid (from a
matrix called "nanna"), together with an outline, 3 external axes and some
PolyData in order to show the oil wells+the well names.
Currently I'm using VTK from CVS and wxPython 2.4.2.4, with Python 2.3 (Python
and wxPython have been obtained using the Enthought Python installer). Does
anyone know if there are incompatibilities between wxPython 2.4.2.4 and VTK
CVS? Do I have to upgrade wxPython? Or are just my programming errors?
Please not that if I substitute all the instances of wxVTKRenderWindow and
wxVTKRenderWindowInteractor with vtkRenderWindow and vtkRenderWindowInteractor
everything works fine... but I need wxPython because I would like to create a
GUI and not only a VTK window.

Thank you a lot for every suggestion.

Andrea.

# BEGIN PYTHON CODE


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 the tubes to represent the wells
profileTubes = vtkpython.vtkTubeFilter()
profileTubes.SetRadius(70.0)

# read the well position from the file mywells.vtk
reader = vtkpython.vtkPolyDataReader()
reader.SetFileName("mywells.vtk")

# scale the well names wrt the z coordinate
transform = vtkpython.vtkTransform()
transform.Identity()
# CHANGE SCALE HERE:
transform.Scale(1.0,1.0,6.0)

# create the surface 3D grid and the wireframe together
# mapsurface-actsurface = VTK objects for the 3D grid surface
# mapedge-actedge = VTK objects for the 3D wireframe
# profileTubes-profileMapper = VTK objects for the wells

mapsurface = vtkpython.vtkDataSetMapper()
mapedge = vtkpython.vtkDataSetMapper()
meshGeom = vtkpython.vtkExtractGrid()
meshGeom.SetInput(a)
mapsurface.SetInput(meshGeom.GetOutput())
mapedge.SetInput(meshGeom.GetOutput())

profileTubes.SetNumberOfSides(80)
profileTubes.SetInput(reader.GetOutput())
profileMapper = vtkpython.vtkPolyDataMapper()
profileMapper.SetInput(profileTubes.GetOutput())

actsurface = vtkpython.vtkActor()
actsurface.SetMapper(mapsurface)
actedge = vtkpython.vtkActor()
actedge.SetMapper(mapedge)

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)

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

profileactor.GetProperty().SetColor(dim_grey)
profileactor.GetProperty().SetInterpolationToGouraud()
profileactor.GetProperty().SetBackfaceCulling(0)
profileactor.GetProperty().SetSpecular(.9)
profileactor.GetProperty().SetSpecularPower(10.0)
profileactor.GetProperty().SetAmbient(1.0)
profileactor.SetScale(1.0,1.0,6.0)

# create the well names and put them as text actors
# self.wellt represent the well names position

textActor = range(0,len(self.wellnames))

for i in range(0,len(self.wellnames)):
    textActor[i] = vtkpython.vtkCaptionActor2D()
    textActor[i].SetCaption(self.wellnames[i])
    textActor[i].SetAttachmentPoint(transform.TransformPoint(self.wellt[i,0],
self.wellt[i,1],self.wellt[i,2]))
    textActor[i].GetPositionCoordinate().SetCoordinateSystemToWorld()
    textActor[i].GetPositionCoordinate().SetValue(0,0,0)
   
textActor[i].GetPositionCoordinate().SetCoordinateSystemToNormalizedDisplay()
    lenwell = len(self.wellnames[i])
    textActor[i].SetWidth(0.013*lenwell)
    textActor[i].SetHeight(0.022)
    textActor[i].GetCaptionTextProperty().SetFontFamilyToTimes()
    textActor[i].GetCaptionTextProperty().SetGlobalAntiAliasingToAll()
    textActor[i].GetCaptionTextProperty().ShadowOn()
    textActor[i].GetCaptionTextProperty().BoldOn()
    textActor[i].GetCaptionTextProperty().SetJustificationToLeft()
    textActor[i].GetCaptionTextProperty().SetVerticalJustificationToBottom()
    textActor[i].GetCaptionTextProperty().SetFontSize(12)
    textActor[i].GetCaptionTextProperty().SetColor(mint_cream)
    textActor[i].BorderOff()

# create the wxWindow using wxFrame

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()

# create the outline for the 3D grid
outline = vtkpython.vtkOutlineFilter()
outline.SetInput(meshGeom.GetOutput())
mapOutline = vtkpython.vtkPolyDataMapper()
mapOutline.SetInput(outline.GetOutput())
outlineActor = vtkpython.vtkActor()
outlineActor.SetMapper(mapOutline)
outlineActor.GetProperty().SetColor(1,1,1)
outlineActor.SetScale(1.0,1.0,6.0)

bounds = actsurface.GetBounds()

# create the axes for the 3D grid
axes = vtkpython.vtkAxes()
axes.SetOrigin(bounds[0], bounds[2], bounds[4])
axes.SetScaleFactor(actsurface.GetLength()/10.0)
axesTubes = vtkpython.vtkTubeFilter()
axesTubes.SetInput(axes.GetOutput())
axesTubes.SetRadius(axes.GetScaleFactor()/25.0)
axesTubes.SetNumberOfSides(8)
axesMapper = vtkpython.vtkPolyDataMapper()
axesMapper.SetInput(axesTubes.GetOutput())
axesActor = vtkpython.vtkActor()
axesActor.SetMapper(axesMapper)
axesActor.GetProperty().SetLineWidth(3.0)
axesActor.GetProperty().SetOpacity(0.7)

axisLength = actsurface.GetLength()/10.0
xcone = vtkpython.vtkConeSource()
xcone.SetHeight(axisLength/5.0)
xcone.SetRadius(axes.GetScaleFactor()/10.0)
xcone.SetResolution(80)
xcone.SetDirection(1,0,0)
xconeMapper = vtkpython.vtkPolyDataMapper()
xconeMapper.SetInput(xcone.GetOutput())
xconeActor = vtkpython.vtkActor()
xconeActor.SetMapper(xconeMapper)
xconeActor.GetProperty().SetColor(1,0,0)
xconeActor.SetPosition((11.0/10.0)*axisLength+bounds[0], bounds[2], bounds[4])
xconeActor.GetProperty().SetOpacity(0.7)
xconeActor.GetProperty().SetInterpolationToPhong()

ycone = vtkpython.vtkConeSource()
ycone.SetHeight(axisLength/5.0)
ycone.SetRadius(axes.GetScaleFactor()/10.0)
ycone.SetResolution(80)
ycone.SetDirection(0,1,0)
yconeMapper = vtkpython.vtkPolyDataMapper()
yconeMapper.SetInput(ycone.GetOutput())
yconeActor = vtkpython.vtkActor()
yconeActor.SetMapper(yconeMapper)
yconeActor.GetProperty().SetColor(1,1,0)
yconeActor.SetPosition(bounds[0], bounds[2]+(11.0/10.0)*axisLength, bounds[4])
yconeActor.GetProperty().SetOpacity(0.7)
yconeActor.GetProperty().SetInterpolationToPhong()

zcone = vtkpython.vtkConeSource()
zcone.SetHeight(axisLength/5.0)
zcone.SetRadius(axes.GetScaleFactor()/10.0)
zcone.SetResolution(80)
zcone.SetDirection(0,0,1)
zconeMapper = vtkpython.vtkPolyDataMapper()
zconeMapper.SetInput(zcone.GetOutput())
zconeActor = vtkpython.vtkActor()
zconeActor.SetMapper(zconeMapper)
zconeActor.GetProperty().SetColor(0,1,0)
zconeActor.SetPosition(bounds[0], bounds[2],(11.0/10.0)*axisLength+bounds[4])
zconeActor.GetProperty().SetOpacity(0.7)
zconeActor.GetProperty().SetInterpolationToPhong()

# create the camera
camAxes = vtkpython.vtkCamera()
camAxes.ParallelProjectionOn()

hiren.AddActor(actsurface)
hiren.AddActor(actedge)

for i in range(0,len(self.wellnames)):
    hiren.AddActor(textActor[i])

hiren.AddActor(profileactor)
hiren.AddActor(outlineActor)
hiren.AddActor(axesActor)
hiren.AddActor(xconeActor)
hiren.AddActor(yconeActor)
hiren.AddActor(zconeActor)

hiren.GetActiveCamera().Zoom(1.5)
hiren.GetActiveCamera().Elevation(135.0)
hiren.GetActiveCamera().Roll(180.0)

self.window.Show(TRUE)
hirenWin.AddRenderer(hiren)

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

##	style = vtkpython.vtkInteractorStyleTrackballCamera()
##	iren.SetInteractorStyle(style)
##	iren.SetRenderWindow(hirenWin)
##	axes = vtkpython.vtkAxesActor()
##	cube = vtkpython.vtkAnnotatedCubeActor()
##
##	cube.GetCubeProperty().SetRepresentationToWireframe()
##	cube.GetCubeProperty().SetAmbient(1)
##	cube.GetCubeProperty().SetDiffuse(0)
##	cube.TextEdgesOff()
##
##	assembly = vtkpython.vtkPropAssembly()
##	assembly.AddPart(axes)
##	assembly.AddPart(cube)
##
##	widget = vtkpython.vtkOrientationMarkerWidget()
##	widget.SetViewport(0, 0, 0.25, 0.25)
##	widget.SetOrientationMarker(assembly)
##	widget.SetInteractor(iren)
##	widget.On()
##	widget.InteractiveOff()

self.renwin = hirenWin

iren.Initialize()
iren.Start()

return self





More information about the vtkusers mailing list