[vtkusers] VTK CVS + wxPython...

Andrea Gavana andrea.gavana at polymtl.ca
Wed Jul 21 05:59:10 EDT 2004


Hello NG,

      thank you Charl for your prompt answer... I was able to run the following
Python code without problems:

#!/usr/bin/env python

import vtkpython
from wxPython.wx import *
from wxVTKRenderWindow import *
from wxVTKRenderWindowInteractor import *

cone = vtkpython.vtkConeSource()
coneMapper = vtkpython.vtkPolyDataMapper()
coneMapper.SetInput(cone.GetOutput())
coneActor = vtkpython.vtkActor()
coneActor.SetMapper(coneMapper)
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)

app = wxPySimpleApp()

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(window,-1,1)
hirenWin = hiwin.GetRenderWindow()

ren = vtkpython.vtkRenderer()
ren.AddActor(coneActor)
renWin = hirenWin
renWin.SetSize(600, 600)
renWin.AddRenderer(ren)

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

widget = vtkpython.vtkOrientationMarkerWidget()
widget.SetViewport(0, 0, 0.25, 0.25)
widget.SetOrientationMarker(assembly)
widget.SetInteractor(iren)
widget.On()
widget.InteractiveOff()
iren.Initialize()
renWin.Render()
iren.Start()

Unfortunately, my code still does not work... I don't know how to reproduce the
behavior of the wxVTK_things... probably is due to the call I make on the class
that defines this wxVTK calls... I'm still an unexperienced user of Python, and
probably I've done some error in calling the class. For example, for me this
code should work without problem:

#!/usr/bin/env python
import vtkpython
from wxPython.wx import *
from wxVTKRenderWindow import *
from wxVTKRenderWindowInteractor import *

class MiaApp(wxApp):
    def OnInit(self):

        cone = vtkpython.vtkConeSource()
        coneMapper = vtkpython.vtkPolyDataMapper()
        coneMapper.SetInput(cone.GetOutput())
        coneActor = vtkpython.vtkActor()
        coneActor.SetMapper(coneMapper)
        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)

        app = wxPySimpleApp()

        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(window,-1,1)
        hirenWin = hiwin.GetRenderWindow()

        ren = vtkpython.vtkRenderer()
        ren.AddActor(coneActor)
        renWin = hirenWin
        renWin.SetSize(600, 600)
        renWin.AddRenderer(ren)

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

        widget = vtkpython.vtkOrientationMarkerWidget()
        widget.SetViewport(0, 0, 0.25, 0.25)
        widget.SetOrientationMarker(assembly)
        widget.SetInteractor(iren)
        widget.On()
        widget.InteractiveOff()
        iren.Initialize()
        renWin.Render()
        iren.Start()

        return 1

app = MiaApp()
app.MainLoop()

But it does not work... the window is frozen, no interaction nor resizing...
what is wrong??? In my program the call is similar, and I don't know where the
error could be. I attach here my code, with the Main() module with the call to
the class that draw the 3D grid.
Thank to you all for every suggestion/pointer.

Andrea.

# My Python Code


from wxPython.wx import *
import os
import sys
import string
import vtkpython
import Numeric
import readugrid
import readfgrid
import readegrid
import grdecl
import adjustme
import zcentr
import coordinates
import time
from pyvtk import *
from wxVTKRenderWindow import *
from wxVTKRenderWindowInteractor import *
from scipy import *
from vtk.util.colors import *

class ReadEclipseData(wxApp):

	def OnInit(self):

		self.dimens = []
		self.failed = 0
		self.datapath = ''
		self.startdate = []
		self.eclipsedata = ''

		return true

	def ReadDataFile(self):
		wildcard = "ECLIPSE DATA Files (*.DATA)|*.DATA;"

		if self.datapath == '' :
			datapath = os.getcwd()
		else:
			datapath = self.datapath

		dlg = wxFileDialog(None, "Please Select An ECLIPSE DATA File",datapath, "",
						   wildcard,
						   wxOPEN
						   | wxCHANGE_DIR)
		if dlg.ShowModal() == wxID_OK:
			self.eclipsedata = dlg.GetFilename()
			self.datapath = dlg.GetPath()
		else:
			self.eclipsedata = ''
			self.datapath = ''
			return self

		dlg.Destroy()

		dlg = wxProgressDialog("VTKPROVA Action: Scanning ECLIPSE DATA File",
							   "Reading "+self.eclipsedata+30*chr(32),
							   2,
							   None,
							   wxPD_APP_MODAL |wxPD_AUTO_HIDE | wxPD_ELAPSED_TIME)
		wxUsleep(200)

		self.datapath = string.replace(self.datapath,self.eclipsedata,'')
		os.chdir(self.datapath)

		fid = open(self.eclipsedata, "rb")
		coco = 0

		keepGoing = dlg.Update(0)

		while 1:
			tline = fid.readline()
			if coco == 1:
				break
			if not tline:
				break
			if string.find(tline[0:1],'=') >= 0:
				keepGoing = dlg.Update(2)
				dlg.Destroy()
				txt1 = "ECLIPSE DATA File Is A Pre-95 Version. VTKPROVA Can Not Read This
Kind Of DATA File"
				txt2 = "VTKPROVA Action: ERROR"
				ret = mymsgerror(txt1,txt2)
				self.failed = 1
				fid.close()
				return self

			if string.find(tline[0:2],'--') < 0 and string.find(tline[0:5],'START') >= 0:
				tline = fid.readline()
				while tline[0:2] == '--'  or len(string.strip(tline)) < 2 :
					tline = fid.readline()
				strdate = string.replace(tline,"'",'')
				strdate = string.split(strdate)
				strdate = strdate[0:3]

			if string.find(tline[0:2],'--') < 0 and string.find(tline[0:6],'DIMENS') >=
0:
				tline = fid.readline()
				while tline[0:2] == '--'  or len(string.strip(tline)) < 2 :
					tline = fid.readline()
				dimens = string.split(tline)
				dimens = dimens[0:3]

			coco = 0
			cocosched = 0
			cocoerr = 1
			if string.find(tline[0:2],'--') < 0 and string.find(tline[0:8],'SCHEDULE') >=
0:
				while 1:
					if coco == 1:
						break
					tline = fid.readline()
					if not tline:
						break
					while tline[0:2] == '--'  or len(string.strip(tline)) < 2 :
						tline = fid.readline()
					if string.find(tline[0:8],'WELSPECS') >= 0 and string.find(tline[0:2],'--')
< 0 :
						cocosched = 0
						coco = 1
						break
					if string.find(tline[0:7],'INCLUDE') >= 0:
						tline = fid.readline()
						while tline[0:2] == '--'  or len(string.strip(tline)) < 2 :
							tline = fid.readline()
						iostar = string.rfind(tline,'/')
						filesched = tline[0:iostar-1]
						filesched = string.replace(filesched,"'",'')

						if string.find(filesched,'/dbstudi') >= 0 :
							for i in range(97,123):
								charset = string.upper(chr(i))
								filesched2 =
string.replace(filesched,'/nm/celerra2/dbstudi/',charset+":/")
								filesched2 = string.replace(filesched2,'/dbstudi/',charset+":/")
								filesched2 = string.strip(filesched2)
								try:
									fid2 = open(filesched2,'rb')
									cocoerr = 0
									break
								except IOError:
									pass
							if i == 122 and cocoerr == 1 :
								keepGoing = dlg.Update(2)
								dlg.Destroy()
								txt1 = "Unable To Open ECLIPSE INCLUDE File:\n\n" + filesched +
"\n\nPlease Check The Correctness Of Your DATA File"
								txt2 = "VTKPROVA Action: ERROR"
								ret = mymsgerror(txt1,txt2)
								fid.close()
								self.failed = 1
								return self

						else:
							try:
								fid2 = open(filesched,'rb')
								filesched2 = filesched
							except IOError:
								keepGoing = dlg.Update(2)
								dlg.Destroy()
								txt1 = "Unable To Open ECLIPSE INCLUDE File:\n\n" + filesched +
"\n\nPlease Check The Correctness Of Your DATA File"
								txt2 = "VTKPROVA Action: ERROR"
								ret = mymsgerror(txt1,txt2)
								fid.close()
								self.failed = 1
								return self

						schedlines = fid2.read()
						fid2.close()

						if string.find(schedlines,'COMPDAT') and
string.find(schedlines,'WELSPECS') :
							coco = 1
							cocosched = 1
							break

					if coco == 1:
						break

		fid.close()

		wellnames = range(0,400)
		wellgroup = range(0,400)
		xcoord = range(0,400)
		ycoord = range(0,400)
		datumdepth = range(0,400)

		welspecsfound = 0
		compdatfound = 0
		wcount = 0

		cw = 0
		if cocosched == 0:
			keepGoing = dlg.Update(1,"Reading SCHEDULE Section In The ECLIPSE DATA File")
			wxUsleep(200)
			fid = open(self.eclipsedata,'rb')
		else:
			keepGoing = dlg.Update(1,"Reading SCHEDULE Section From External File")
			wxUsleep(200)
			fid = open(filesched2,'rb')
		while 1:
			tline = fid.readline()
			if not tline:
				break
			if string.find(tline[0:2],'--') < 0 and string.find(tline[0:8],'WELSPECS') >=
0:
				while string.find(tline[0:1],'/') < 0 :
					tline = fid.readline()
					if not tline:
						break
					if string.find(tline[0:2],'--') < 0 and len(string.strip(tline)) > 0 :
						if string.find(tline[0:1],'/') >= 0:
							break
						newline = string.split(tline)
						ciccia = 1
						if cw == 0:
							wellnames[cw] = string.replace(string.strip(newline[0]),"'","")
							wellgroup[cw] = string.replace(string.strip(newline[1]),"'","")
							xcoord[cw] = int(newline[2])
							ycoord[cw] = int(newline[3])
							if string.find(newline[4],'*') >= 0:
								datumdepth[cw] = -1.0
							else:
								datumdepth[cw] = float(newline[4])
							cw = cw + 1
							welspecsfound = 1
						else:
							try:
								wellnames.index(string.replace(string.strip(newline[0]),"'",""))
								ciccia = 0
							except:
								ciccia = 1
								pass
							if ciccia == 1:
								wellnames[cw] = string.replace(string.strip(newline[0]),"'","")
								wellgroup[cw] = string.replace(string.strip(newline[1]),"'","")
								xcoord[cw] = int(newline[2])
								ycoord[cw] = int(newline[3])
								if string.find(newline[4],'*') >= 0:
									datumdepth[cw] = -1.0
								else:
									datumdepth[cw] = float(newline[4])
								cw = cw + 1

				welcount = Numeric.zeros(cw)
				xwell = Numeric.zeros((cw,5000))
				ywell = Numeric.zeros((cw,5000))
				zwell = Numeric.zeros((cw,5000))
				welcount = welcount.tolist()

			if string.find(tline[0:2],'--') < 0 and string.find(tline[0:7],'COMPDAT') >=
0:

				while string.find(tline[0:1],'/') < 0 :
					tline = fid.readline()

					if not tline:
						break
					if string.find(tline[0:2],'--') < 0 and len(string.strip(tline)) > 0 :
						if string.find(tline[0:1],'/') >= 0:
							break
						newline = string.split(tline)
						ciccia = 1
						try:
							wellpos =
wellnames.index(string.replace(string.strip(newline[0]),"'",""))
						except:
							keepGoing = dlg.Update(2)
							dlg.Destroy()
							txt1 = "Incompatible WELSPECS/COMPDAT Sections. Well:\n\n" +
string.strip(newline[0]) + "\n\nDoes Not Exist In The COMPDAT Section. Please
Check Your ECLIPSE DATA File"
							txt2 = "VTKPROVA Action: ERROR"
							ret = mymsgerror(txt1,txt2)
							fid.close()
							self.failed = 1
							return self

						wcount = wcount + 1
						if string.find(newline[1],'2*') >= 0 :
							xca = xcoord[wellpos]
							yca = ycoord[wellpos]
						else:
							if string.find(newline[1],'1*') >= 0 :
								xca = xcoord[wellpos]
							else:
								xca = int(newline[1])
							if string.find(newline[2],'1*') >= 0 :
								yca = ycoord[wellpos]
							else:
								yca = int(newline[2])

						zca1 = int(newline[3])
						zca2 = int(newline[4])

						myinterval = range(zca1,zca2+1)
						for i in myinterval:
							if wcount > 1:
								if any(zwell[wellpos,0:] == i) == 0 :
									xwell[wellpos,welcount[wellpos]] = xca
									ywell[wellpos,welcount[wellpos]] = yca
									zwell[wellpos,welcount[wellpos]] = i
									welcount[wellpos] = welcount[wellpos] + 1

							else:
								xwell[wellpos,welcount[wellpos]] = xca
								ywell[wellpos,welcount[wellpos]] = yca
								zwell[wellpos,welcount[wellpos]] = i
								welcount[wellpos] = welcount[wellpos] + 1


		fid.close()

		keepGoing = dlg.Update(2)

		del(wellnames[cw:])
		del(wellgroup[cw:])
		del(xcoord)
		del(ycoord)
		del(datumdepth[cw:])

		xm = max(welcount)

		xwell = xwell[0:,0:xm]
		ywell = ywell[0:,0:xm]
		zwell = zwell[0:,0:xm]

		self.wellnames = wellnames
		self.wellgroup = wellgroup
		self.xwell = xwell
		self.ywell = ywell
		self.zwell = zwell
		self.datumdepth = datumdepth

		dlg.Destroy()

		os.chdir("C:/Python23/myproject")

		return self


class MiaApp(wxApp):

	def OnInit(self):

		self.data_type = ''
		self.gridfilename = ''
		self.originaldir = "C:\Python23\myproject"

		return true

	def GetGridfilename(self):

		wildcard = "ECLIPSE GRID Files
(*.GRID,*.FGRID,*.EGRID,*.FEGRID,*.GRDECL)|*.GRID;*.FGRID;*.EGRID;*.FEGRID;*.GRD*;*.GRDECL"

		dlg = wxFileDialog(None, "Please Select An ECLIPSE GRID File",os.getcwd(), "",
						   wildcard,
						   wxOPEN
						   | wxCHANGE_DIR)
		if dlg.ShowModal() == wxID_OK:

			gridfilename = dlg.GetFilename()
			self.gridfilename = gridfilename

		else:
			self.gridfilename = ''

		dlg.Destroy()

		return self

	def ReadGridFile(self):

		maxx = 3
		z = string.rfind(self.gridfilename,'\\')
		extens = string.rfind(self.gridfilename,'.')
		if self.gridfilename[extens+1:] == 'GRID' :
			gridext = 1
		elif self.gridfilename[extens+1:] == 'FGRID' :
			gridext = 2
		elif self.gridfilename[extens+1:] == 'EGRID' :
			gridext = 3
		elif self.gridfilename[extens+1:] == 'FEGRID' :
			gridext = 4
		else:
			gridext = 5

		dlg = wxProgressDialog("Python Action: Scanning ECLIPSE GRID File",
							   "Reading "+self.gridfilename[z+1:]+30*chr(32),
							   maxx,
							   None,
							   wxPD_APP_MODAL |wxPD_AUTO_HIDE | wxPD_ELAPSED_TIME)

		keepGoing = dlg.Update(0,'Reading GRID Dimension')
		wxUsleep(200)
		if gridext == 1:
			nx, ny, nz = readugrid.readdimens(self.gridfilename)
		elif gridext == 2:
			nx, ny, nz = readfgrid.readdimens(self.gridfilename)
		elif gridext == 3:
			nx, ny, nz = readegrid.readdimens(self.gridfilename)
		elif gridext == 4:
			nx, ny, nz = readfegrid.readdimens(self.gridfilename)

		keepGoing = dlg.Update(1,"Reading "+self.gridfilename[z+1:])
		wxUsleep(200)

		if gridext == 1:
			matrix = readugrid.readgrid(self.gridfilename,nx,ny,nz)
		elif gridext == 2:
			matrix = readfgrid.readgrid(self.gridfilename,nx,ny,nz)
		elif gridext == 3:
			coord, zcorn = readegrid.readgrid(self.gridfilename,nx,ny,nz)
		elif gridext == 4:
			coord, zcorn = readfegrid.readgrid(self.gridfilename,nx,ny,nz)

		keepGoing = dlg.Update(2,"Reading "+self.gridfilename[z+1:])

		if gridext == 3 or gridext == 4:
			keepGoing = dlg.Update(3,"Backcalculating Original Coordinates")
			x, y, z = grdecl.grdecl(coord,zcorn,nx,ny,nz)

			matrix = adjustme.adjustme(x,y,z,nx,ny,nz)
		else:
			keepGoing = dlg.Update(3,"Reading "+self.gridfilename[z+1:])

		self.dimens = [nx, ny, nz]
		self.matrix = matrix

		os.chdir(self.originaldir)

		dlg.Destroy()

		return self

	def readandplot(self):

		ss = self.GetGridfilename()
		if not ss.gridfilename == '' :
			ss = self.ReadGridFile()
		else:
			text1 = "No ECLIPSE GRID File Selected. Please Select An Eclipse Grid File"
			text2 = "VTKPROVA Action: ERROR"
			ret = mymsgerror(text1,text2)

		dlg = wxProgressDialog("VTK Builder",
								"Building VTK-Python Inputs..."+30*chr(32),
								2,
								None,
								wxPD_APP_MODAL |wxPD_AUTO_HIDE | wxPD_ELAPSED_TIME)

		nx = ss.dimens[0]
		ny = ss.dimens[1]
		nz = ss.dimens[2]

		keepGoing = dlg.Update(0)

		x = Numeric.reshape(ss.matrix[0:24:3,:],(8,nx*ny*nz))
		y = Numeric.reshape(ss.matrix[1:24:3,:],(8,nx*ny*nz))
		z = Numeric.reshape(ss.matrix[2:24:3,:],(8,nx*ny*nz))

		keepGoing = dlg.Update(1,"Calculating Cell Centroids...")

		self = buildcentroids(self)
		zcent = self.zcent

		self = buildwells(self)

		nanna, zcentout = coordinates.coordinates(x,y,z,nx,ny,nz,zcent)
		nanna = Numeric.transpose(nanna)

		keepGoing = dlg.Update(2,"Building VTK Grid And Rendering...")

		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)

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

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

		transform = vtkpython.vtkTransform()
		transform.Identity()
		# CHANGE SCALE HERE:
		transform.Scale(1.0,1.0,6.0)

		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)

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

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

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


		camAxes = vtkpython.vtkCamera()
		camAxes.ParallelProjectionOn()

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

##		window.Show(1)
		hiwin = wxVTKRenderWindow(window,-1,1)
		hirenWin = hiwin.GetRenderWindow()

		hiren = vtkpython.vtkRenderer()

		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)
		hirenWin.SetSize(1000,900)

		hirenWin.AddRenderer(hiren)

		iren = wxVTKRenderWindowInteractor(window, -1,1)
	##	iren = vtkpython.vtkRenderWindowInteractor()
		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()

		dlg.Destroy()
	##	self.renwin = hirenWin

		iren.Initialize()
		hiren.Render()
		iren.Start()

		return self


def mymsgerror(text1,text2):

	dlg = wxMessageDialog(None,text1,text2,
						  wxOK | wxSTAY_ON_TOP | wxICON_ERROR)
	try:
		result = dlg.ShowModal()
	finally:
		dlg.Destroy()


def buildcentroids(self):

	matrix = self.matrix

	xcent = zcentr.zcentroids(matrix[0:24:3,0:])
	ycent = zcentr.zcentroids(matrix[1:24:3,0:])
	zcent = zcentr.zcentroids(matrix[2:24:3,0:])

	self.xcent = xcent
	self.ycent = ycent
	self.zcent = zcent

	return self

def buildwells(self):

	iwell = self.xwell
	jwell = self.ywell
	kwell = self.zwell

	xwell = self.xcent
	ywell = self.ycent
	zwell = self.zcent

	ccount = 0
	nx = self.dimens[0]
	ny = self.dimens[1]
	nz = self.dimens[2]
	num = Numeric.shape(iwell)
	wellp = Numeric.zeros((2000,3),Numeric.Float)
	wellc = Numeric.zeros(len(self.wellnames),Numeric.Int)
	wellt = Numeric.zeros((len(self.wellnames),3),Numeric.Float)

	outofrange = Numeric.zeros(len(self.wellnames),Numeric.Float)
	ccc = 0
	for i in range(0,len(self.wellnames)):
		partialc = 0
		for j in range(0,num[1]):
			if iwell[i,j] > 0:
				lenind = iwell[i,j] + nx*(jwell[i,j] - 1) + nx*ny*(kwell[i,j] - 1) - 1
				if partialc == 0:
					outofrange[ccc] = zwell[lenind] - zwell[lenind]/10.0
					ccc = ccc + 1
					partialc = partialc + 1

	minz = min(outofrange)
	ccc = 0

	for i in range(0,len(self.wellnames)):
		partialcount = 0
		for j in range(0,num[1]):
			if iwell[i,j] > 0:
				lenindex = iwell[i,j] + nx*(jwell[i,j] - 1) + nx*ny*(kwell[i,j] - 1) - 1
				if partialcount == 0:
					wellp[ccount,0] = xwell[lenindex]
					wellp[ccount,1] = ywell[lenindex]
					wellp[ccount,2] = minz
					wellt[ccc,0] = xwell[lenindex]
					wellt[ccc,1] = ywell[lenindex]
					wellt[ccc,2] = minz #- minz/100.0
					ccount = ccount + 1
					ccc = ccc + 1

				wellp[ccount,0] = xwell[lenindex]
				wellp[ccount,1] = ywell[lenindex]
				wellp[ccount,2] = zwell[lenindex]
				ccount = ccount + 1
				partialcount = partialcount + 1

		wellc[i] = partialcount + 1

	wellpoints = wellp[0:ccount,:]
	wellpoints = wellpoints.tolist()
	self.wellpoints = wellpoints
	self.wellt = wellt

	w = list()
	ccount = 0
	oldcount = 0

	for i in range(0,len(self.wellnames)):
		myarray = range(oldcount,oldcount+wellc[i])
		oldcount = oldcount + wellc[i]
		w.append(myarray)

	structure = PolyData(points=wellpoints, lines=w)
	vtk = VtkData(structure)
	vtk.tofile('mywells','ascii')

	return self


def Main():
	self2 = ReadEclipseData(1)
	self2 = self2.ReadDataFile()

	if self2.eclipsedata == '' or self2.failed == 1:
		return 0

	app = MiaApp()
	app.MainLoop()

	app.xwell = self2.xwell
	app.ywell = self2.ywell
	app.zwell = self2.zwell
	app.wellnames = self2.wellnames
	app.wellgroup = self2.wellgroup
	app.eclipsedata = self2.eclipsedata
	app.datapath = self2.datapath
	app.datumdepth = self2.datumdepth
	app.startdate = self2.startdate

	app = app.readandplot()
	app.MainLoop()


if __name__ == '__main__':
	Main()





More information about the vtkusers mailing list