<div dir="ltr">Hi all,<div><br></div><div>I have written a python function to setup a curvilinear structured grid and returns the grid object at the end. In the returned grid object, I don&#39;t have the points as assigned rather very small values (order of e-50 to e-300) that is effectively 0.</div>
<div><br></div><div>The code is as follows: </div><div><div><div>    import vtk, numpy as np</div><div>    # The test function</div><div>    def testGrid():</div><div>        &#39;&#39;&#39; Small test setting up a cuivilinear grid vts&#39;&#39;&#39;</div>
<div>        x = np.arange(-1,0.6,0.5)</div><div>        y = np.arange(-2,0.1,1.0)</div><div>        z = np.arange(2,-1.1,-0.5)</div><div>        gx,gy,gz = np.meshgrid(x,y,z)</div><div>        nodC = np.hstack((gx.T.reshape((np.prod(gx.shape),1)),gy.T.reshape((np.prod(gy.shape),1)),gz.T.reshape((np.prod(gz.shape),1))))</div>
<div>        nodCvtk = npsup.numpy_to_vtk(nodC)</div><div>        points = vtk.vtkPoints()</div><div>        points.SetData(nodCvtk)</div><div><br></div><div>        color = np.arange(np.prod(gx.shape-np.array([1,1,1])))</div>
<div>        cellColors = npsup.numpy_to_vtk(colorReSh)</div><div>        cellColors.SetName(&#39;Colors&#39;)</div><div>        sgrid = vtk.vtkStructuredGrid()</div><div>        sgrid.SetDimensions(gx.shape)</div><div>        sgrid.SetPoints(points)</div>
<div>        sgrid.GetCellData().AddArray(cellColors)</div><div>        def writeVTSFile(fileName,vtsObj):</div><div>            vtsWriter = vtk.vtkXMLStructuredGridWriter()</div><div>            vtsWriter.SetFileName(fileName)</div>
<div>            vtsWriter.SetInput(vtsObj)</div><div>            vtsWriter.Update()</div><div>        writeVTSFile(&#39;vts3DFile.vts&#39;,sgrid)</div><div>        return sgrid</div><div><br></div><div>    # Read the file</div>
<div>    vtsReader = vtk.vtkXMLStructuredGridReader()</div><div>    vtsReader.SetFileName(&#39;vts3DFile.vts&#39;)</div><div>    vtsReader.Update()</div><div>    sgridReader = vtsReader.GetOutput()</div><div>    # Excute the function</div>
<div>    sgridFunc = testGrid()</div><div>    </div><div>    # Print out the first point</div><div>    print sgridFunc.GetPoint(0)</div><div>    print sgridReader.GetPoint(0)</div></div></div><div><br></div><div><br></div>
<div>The results from the print function are:</div><div><div>(-1.6934276617628493e-54, 3.4178058e-316, -1.1548972446486807e-82)</div><div>(-1.0, -2.0, 2.0)</div></div><div><br></div><div>However, if I write the object to a file and read it everything is working order. Are there some special tricks to return a grid object from a python function?</div>
<div><br></div><div>I am running on a Linux 64-bit Fedora 17, with self-compiled version of vtk 5.10.1 and python 2.7.</div><div><br></div><div>Thanks,</div><div>Gudni</div></div>