Skip to content

Commit 266121b

Browse files
danlipsadoutriaux1
authored andcommitted
Projected isofill bounds (#411)
* Compute BB of a projected dataset from all points. The border in Cartesian space may no corespond to the border in the projected space. * Add isofill orthographic test.
1 parent 3f352fe commit 266121b

File tree

2 files changed

+36
-27
lines changed

2 files changed

+36
-27
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import basevcstest
2+
import vcs
3+
4+
5+
class TestVCSIsofill(basevcstest.VCSBaseTest):
6+
def isofillOrthographic(self, centerlatitude):
7+
8+
a = self.clt("clt")
9+
10+
p = self.x.getprojection('orthographic')
11+
p.centerlatitude = centerlatitude
12+
b = self.x.createisofill()
13+
b.projection = p
14+
self.x.plot(a(latitude=(90, -90)), b, bg=self.bg)
15+
fnm = "test_vcs_isofill_orthographic_%i.png" % centerlatitude
16+
self.checkImage(fnm)
17+
18+
def testIsofill(self):
19+
for lat in [45, 90]:
20+
self.isofillOrthographic(lat)

vcs/vcs2vtk.py

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
def debugWriteGrid(grid, name):
2323
if DEBUG_MODE:
2424
writer = vtk.vtkXMLDataSetWriter()
25+
if (grid.GetClassName() == "vtkPoints"):
26+
poly = vtk.vtkPolyData()
27+
poly.SetPoints(grid)
28+
grid = poly
2529
gridType = grid.GetDataObjectType()
2630
if (gridType == vtk.VTK_STRUCTURED_GRID):
2731
ext = ".vts"
@@ -344,7 +348,7 @@ def getBoundsList(axis, hasCellData, dualGrid):
344348
return None
345349

346350

347-
def setInfToValid(geoPoints, ghost):
351+
def setInfToValid(geoPoints, ghost=None):
348352
'''
349353
Set infinity points to a point that already exists in the list.
350354
We also hide infinity points in the ghost array.
@@ -368,7 +372,8 @@ def setInfToValid(geoPoints, ghost):
368372
if (math.isinf(point[1])):
369373
newPoint[1] = validPoint[1]
370374
geoPoints.SetPoint(i, newPoint)
371-
ghost.SetValue(i, vtk.vtkDataSetAttributes.HIDDENPOINT)
375+
if (ghost):
376+
ghost.SetValue(i, vtk.vtkDataSetAttributes.HIDDENPOINT)
372377
return anyInfinity
373378

374379

@@ -2029,35 +2034,19 @@ def getProjectedBoundsForWorldCoords(wc, proj, subdiv=50):
20292034
if vcs.elements['projection'][proj].type == 'linear':
20302035
return wc
20312036

2032-
xs = numpy.linspace(wc[0], wc[1], subdiv).tolist()
2033-
xs += [wc[1], ] * subdiv
2034-
xs += numpy.linspace(wc[1], wc[0], subdiv).tolist()
2035-
xs += [wc[0], ] * subdiv
2036-
2037-
ys = [wc[2], ] * subdiv
2038-
ys += numpy.linspace(wc[2], wc[3], subdiv).tolist()
2039-
ys += [wc[3], ] * subdiv
2040-
ys += numpy.linspace(wc[3], wc[2], subdiv).tolist()
2037+
# the border in Cartesian space may not corespond to the border
2038+
# in the projected space.
2039+
x = numpy.linspace(wc[0], wc[1], subdiv)
2040+
y = numpy.linspace(wc[2], wc[3], subdiv)
2041+
xy = numpy.transpose([numpy.tile(x, len(y)), numpy.repeat(y, len(x))])
20412042

20422043
pts = vtk.vtkPoints()
2043-
2044-
for idx in range(len(xs)):
2045-
pts.InsertNextPoint(xs[idx], ys[idx], 0.0)
2044+
for idx in range(len(xy)):
2045+
pts.InsertNextPoint(xy[idx][0], xy[idx][1], 0.0)
20462046

20472047
geoTransform, xformPts = project(pts, proj, wc)
2048-
2049-
# def printPoints(vtkPoints):
2050-
# ptStr = ''
2051-
# for ptIdx in range(vtkPoints.GetNumberOfPoints()):
2052-
# point = vtkPoints.GetPoint(ptIdx)
2053-
# ptStr = '{0}, {1}'.format(point, ptStr)
2054-
# print(ptStr)
2055-
2056-
# print('Subdivided points')
2057-
# printPoints(pts)
2058-
# print('Transformed subdivided points')
2059-
# printPoints(xformPts)
2060-
2048+
setInfToValid(xformPts)
2049+
debugWriteGrid(xformPts, "points")
20612050
return xformPts.GetBounds()
20622051

20632052

0 commit comments

Comments
 (0)