<div dir="ltr">Hi paraview list<div><br></div><div>Based on this blog post: <a href="http://www.kitware.com/blog/home/post/534">http://www.kitware.com/blog/home/post/534</a>, I am trying to make a Python plugin (source) that reads a stack of unsigned short TIFFs (uint16) and outputs 3D unsigned short imagedata in Paraview.</div><div><br></div><div>Assigning the geometry to the imagedata works fine (see def RequestInformation). My problem is that the values of the voxels in the imagedata is not assigned correct (see def RequestData). According to Paraview information tab the data type is unsigned short, but when reading in a known TIFF (8x8 with uint16 values 1..64) the values of the imagedata are not correct.</div><div><br></div><div>I suspect the last line "array.SetValue(offset+v, vals.GetValue(v))" is the problem. Does the vals.GetValue(v) get casted into a Python type int before stored in the array?</div><div><br></div><div>When I print vals.GetValue(v) to a textfile, I can see that I read the correct values from the TIFF.</div><div><br></div><div>Can anybody see what the problem is?</div><div><br></div><div>Cheers, </div><div>Allan</div><div><br></div><div><br></div><div><div>def RequestData():</div><div>    import os</div><div>    from paraview import vtk</div><div>    from vtk import vtkTIFFReader # this reader does not exist in paraview??</div><div><br></div><div>    filepath = Filepath # path to file</div><div>    filestr = Filename  # string containing filename and %d</div><div>    first = First       # first image, e.g. 0 or 1</div><div>    last = Last         # last image</div><div>    N = last-first+1    # number of images</div><div><br></div><div>    # Get a vtkImageData object for the output</div><div>    pdo = self.GetOutput()</div><div><br></div><div>    print 'read'</div><div>    # set up reader</div><div>    reader = vtkTIFFReader()</div><div>    filename = filestr % first</div><div>    reader.SetFileName(os.path.join(filepath, filename))</div><div>    reader.Update()</div><div><br></div><div>    # get tiff info</div><div>    ext = reader.GetDataExtent()</div><div><br></div><div>    # set up output volume</div><div>    pdo.SetExtent(0, ext[1], 0, ext[3], 0, N-1)</div><div>    #pdo.SetDimensions(ext[1]+1,ext[3]+1,N)</div><div>    pdo.SetOrigin(0,0,0)</div><div>    pdo.SetSpacing(1,1,1)</div><div>    pdo.AllocateScalars(vtk.VTK_UNSIGNED_SHORT,1)</div><div><br></div><div>    # temporary array for voxel values</div><div>    array = vtk.vtkUnsignedShortArray()</div><div>    array.SetName('Voxels')</div><div>    array.SetNumberOfComponents(1)</div><div>    #array.SetNumberOfTuples(pdo.GetNumberOfPoints())</div><div>    array.SetNumberOfValues(pdo.GetNumberOfPoints())</div><div>    pdo.GetPointData().AddArray(array)</div><div><br></div><div>    # fill array with tiffs</div><div>    for i in range(N):</div><div>        filename = filestr % (first+i)</div><div>        print filename</div><div>        reader.SetFileName(os.path.join(filepath, filename))</div><div>        reader.Update()</div><div>        image = reader.GetOutput()</div><div>        vals = image.GetPointData().GetArray('Tiff Scalars')</div><div>        offset = i*N</div><div>        for v in range((ext[0]+1)*(ext[1]+1)):</div><div>            print vals.GetValue(v)</div><div>            array.SetValue(offset+v, vals.GetValue(v))</div></div><div><br></div><div><br></div><div><div>def RequestInformation():</div><div>    import os<br></div><div>    from paraview import vtk, util</div><div>    from vtk import vtkTIFFReader</div><div><br></div><div>    filepath = Filepath # path to file</div><div>    filestr = Filename  # string containing filename and %d</div><div>    first = First       # first image, e.g. 0 or 1</div><div>    last = Last         # last image</div><div><br></div><div>    # set up reader</div><div>    reader = vtkTIFFReader()</div><div>    filename = filestr % first</div><div>    reader.SetFileName(os.path.join(filepath, filename))</div><div>    reader.Update()</div><div><br></div><div>    # get tiff info</div><div>    ext = reader.GetDataExtent()</div><div><br></div><div>    # update extent information</div><div>    util.SetOutputWholeExtent(self, [0, ext[1], 0, ext[3], 0, last-first])</div></div></div>