Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Isofill on pointdata struct grid #1119

Merged
merged 4 commits into from Mar 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 6 additions & 10 deletions Packages/vcs/Lib/VTKPlots.py
Expand Up @@ -405,7 +405,6 @@ def plot(self,data1,data2,template,gtype,gname,bg,*args,**kargs):
if ( gtype in ["3d_scalar", "3d_dual_scalar", "3d_vector"] ) and (self.renderer <> None):
ren = self.renderer
else:
#print "Calling 1"
#ren = self.createRenderer()
#if not (vcs.issecondaryobject(gm) and gm.priority==0):
# self.setLayer(ren,tpl.data.priority)
Expand Down Expand Up @@ -626,7 +625,7 @@ def plotVector(self,data1,data2,tmpl,gm,vtk_backend_grid=None,vtk_backend_geo=No
zaxis = None
data1 = self.trimData2D(data1) # Ok get3 only the last 2 dims
data2 = self.trimData2D(data2)
gridGenDict = vcs2vtk.genGridOnPoints(data1,data2,gm,deep=False,grid=vtk_backend_grid,geo=vtk_backend_geo)
gridGenDict = vcs2vtk.genGridOnPoints(data1,gm,deep=False,grid=vtk_backend_grid,geo=vtk_backend_geo)
for k in ['vtk_backend_grid','xm','xM','ym','yM','continents','wrap','geo']:
exec("%s = gridGenDict['%s']" % (k,k))
returned["vtk_backend_grid"]=vtk_backend_grid
Expand Down Expand Up @@ -725,7 +724,11 @@ def plot2D(self,data1,data2,tmpl,gm,vtk_backend_grid=None,vtk_backend_geo=None):
data1 = self.trimData2D(data1) # Ok get3 only the last 2 dims
if gm.g_name!="Gfm":
data2 = self.trimData2D(data2)
gridGenDict = vcs2vtk.genGrid(data1,data2,gm,deep=False,grid=vtk_backend_grid,geo=vtk_backend_geo)
if isinstance(gm,(vcs.isofill.Gfi,vcs.isoline.Gi)):
gridGenDict = vcs2vtk.genGridOnPoints(data1,gm,deep=False,grid=vtk_backend_grid,geo=vtk_backend_geo)
gridGenDict["cellData"]=False
else:
gridGenDict = vcs2vtk.genGrid(data1,data2,gm,deep=False,grid=vtk_backend_grid,geo=vtk_backend_geo)
for k in ['vtk_backend_grid','xm','xM','ym','yM','continents','wrap','geo','cellData']:
exec("%s = gridGenDict['%s']" % (k,k))
returned["vtk_backend_grid"]=vtk_backend_grid
Expand Down Expand Up @@ -775,23 +778,17 @@ def plot2D(self,data1,data2,tmpl,gm,vtk_backend_grid=None,vtk_backend_geo=None):
c2p = vtk.vtkCellDataToPointData()
c2p.SetInputData(vtk_backend_grid)
c2p.Update()
if self.debug:
vcs2vtk.dump2VTK(c2p)
#For contouring duplicate points seem to confuse it
if vtk_backend_grid.IsA("vtkUntructuredGrid"):
cln = vtk.vtkCleanUnstructuredGrid()
cln.SetInputConnection(c2p.GetOutputPort())
if self.debug:
vcs2vtk.dump2VTK(cln)
sFilter.SetInputConnection(cln.GetOutputPort())
else:
sFilter.SetInputConnection(c2p.GetOutputPort())
else:
sFilter.SetInputData(vtk_backend_grid)
sFilter.Update()
returned["vtk_backend_filter"]=sFilter
if self.debug:
vcs2vtk.dump2VTK(sFilter)
if isinstance(gm,isoline.Gi):
cot = vtk.vtkContourFilter()
if cellData:
Expand Down Expand Up @@ -1857,7 +1854,6 @@ def update_input(self,vtkobjects,array1,array2=None,update=True):
j=0
while actor:
j+=1
#print "renderer:",i,"actor",j
m = actor.GetMapper()
m.Update()
actor=actors.GetNextItem()
Expand Down
20 changes: 5 additions & 15 deletions Packages/vcs/Lib/vcs2vtk.py
Expand Up @@ -76,7 +76,7 @@ def putMaskOnVTKGrid(data,grid,actorColor=None,cellData=True,deep=True):
grid.SetCellVisibilityArray(msk)
return mapper

def genGridOnPoints(data1,data2,gm,deep=True,grid=None,geo=None):
def genGridOnPoints(data1,gm,deep=True,grid=None,geo=None):
continents = False
xm,xM,ym,yM = None, None, None, None
useStructuredGrid = True
Expand Down Expand Up @@ -126,11 +126,11 @@ def genGridOnPoints(data1,data2,gm,deep=True,grid=None,geo=None):
xm,xM,ym,yM = getRange(gm,xm,xM,ym,yM)
if geo is None:
geo, geopts = project(pts,projection,[xm,xM,ym,yM])
## Sets the vertics into the grid
## Sets the vertices into the grid
if grid is None:
if useStructuredGrid:
vg = vtk.vtkStructuredGrid()
vg.SetDimensions(y.shape[1],y.shape[0],1)
vg.SetDimensions(data1.shape[1],data1.shape[0],1)
else:
vg = vtk.vtkUnstructuredGrid()
vg.SetPoints(geopts)
Expand Down Expand Up @@ -191,7 +191,6 @@ def genGrid(data1,data2,gm,deep=True,grid=None,geo=None):
# here we add dummy levels, might want to reconsider converting "trimData" to "reOrderData" and use actual levels?
m3=numpy.concatenate((m2,numpy.zeros((m2.shape[0],1))),axis=1)
except Exception,err: # Ok no mesh on file, will do with lat/lon
#print "No mesh data found"
pass
if m3 is not None:
#Create unstructured grid points
Expand Down Expand Up @@ -440,8 +439,6 @@ def project(pts,projection,wc,geo=None):
if geo is None:
geo = vtk.vtkGeoTransform()
ps = vtk.vtkGeoProjection()
#for i in range(ps.GetNumberOfProjections()):
# print i, ps.GetProjectionName(i)
pd = vtk.vtkGeoProjection()
names = ["linear","utm","state","aea","lcc","merc","stere","poly","eqdc","tmerc","stere","lcca","azi","gnom","ortho","vertnearper","sinu","eqc","mill","vandg","omerc","robin","somerc","alsk","goode","moll","imoll","hammer","wag4","wag7","oea"]
proj_dic = {"polar stereographic":"stere",
Expand All @@ -452,12 +449,6 @@ def project(pts,projection,wc,geo=None):

pname = proj_dic.get(projection._type,projection.type)
projName = pname
#for i in range(0,184,2):
# pd.SetName(pd.GetProjectionName(i))
# print i,":",pd.GetProjectionName(i),"(",pd.GetNumberOfOptionalParameters(),") --"
# pd.SetName(pd.GetProjectionName(i+1))
# print i+1,":",pd.GetProjectionName(i+1),"(",pd.GetNumberOfOptionalParameters(),")"

pd.SetName(projName)
if projection.type == "polar (non gctp)":
if ym<yM:
Expand Down Expand Up @@ -635,10 +626,10 @@ def setProjectionParameters(pd,proj):
dumps={}
def dump2VTK(obj,fnm=None):
global dumps
if fnm[:-4].lower()!=".vtk":
fnm+=".vtk"
if fnm is None:
fnm="foo.vtk" % dumps
if fnm[:-4].lower()!=".vtk":
fnm+=".vtk"
if fnm in dumps:
dumps[fnm]+=1
fnm=fnm[:-4]+"%.3i.vtk" % dumps[fnm]
Expand Down Expand Up @@ -1305,7 +1296,6 @@ def world2Renderer(ren,x,y,vp=[0.,1.,0.,1.],wc=[0.,1.,0.,1.]):

def R2World(ren,x,y):
"""Converts renderer's x/y to WorldCoordinate for a given Renderer"""
#print "ok X and Y:",x,y
ren.SetDisplayPoint(x,y,0)
ren.DisplayToWorld()
return wp
Expand Down