2222def 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