vtk 3.1, vtkImageAppend, and vtkImageClip

Jody Winston jody at sccsi.com
Wed Mar 22 09:27:41 EST 2000


I'm trying to cut out regions from a TIFF file and then append the
regions into a single image, but I'm getting the following errors:

    #
    # ERROR: In vtkImageData.cxx, line 1221
    # vtkImageData (0x100a55e0): GetScalarPointer: Pixel (384, 1772, 0) not in memory.
    # Current extent= (91, 302, 0, 3543, 0, 0)
    #

Enclosed is a sample program (but without the tiff data) that fails.

#!/usr/bin/env python

from VTK import *

import getopt

VTK_IMAGE_X_AXIS = 0
VTK_IMAGE_Y_AXIS = 1

def help(name):
    import sys
    print "%s:\t-h|--help" % (name)
    print "\t -i|--input name"
    print "\t -o|--output name"
    print "\t -v|--verbose name"
    sys.exit()
    
def main(argv):

    opts = getopt.getopt(argv[1:], 
			 "hvi:o:", 
			 ['help', 'input=', 'verbose', 'output='])

    #
    # extents of this tiff are (0, 1527, 0, 1771, 0, 0)
    #
    filename = "/hosts/radsgi002/radraid/tegwyn/core_in.tif"
    output = "foo.tiff"
    verbose = 0
    
    options = opts[0]

    for i in xrange(len(options)):
	if '-h' == options[i][0] or '--help' == options[i][0]:
	    help(argv[0])
	if '-c' == options[i][0] or '--curve' == options[i][0]:
	    curve = options[i][1]
	if '-v' == options[i][0] or '--verbose' == options[i][0]:
	    verbose = 1
	if '-i' == options[i][0] or '--input' == options[i][0]:
	    filename = options[i][1]
	if '-o' == options[i][0] or '--output' == options[i][0]:
	    output = options[i][1]

    # Image pipeline
    reader = vtkTIFFReader()
    reader.ReleaseDataFlagOff()
    reader.SetFileName(filename)
    reader.SetDebug(verbose)
    reader.Update()
    extents = reader.GetDataExtent()
    print "Reader extents =", extents
    
    #
    # Bug in vtk?
    # If using more than one clip, we have problems with extents
    #
    
    xvCoords = [
        [(91, 660), (302, 1718)],
        [(384, 72), (582, 1557)],
        ]
    
    append = vtkImageAppend()
    append.SetAppendAxis(VTK_IMAGE_Y_AXIS)

    for coords in xvCoords:
        print "Clipping out region", coords[0], coords[1]
        clip = vtkImageClip()
        clip.SetInput(reader.GetOutput())
        clip.SetDebug(verbose)
        clip.SetOutputWholeExtent(coords[0][0], coords[1][0],
                                  extents[2], extents[3],
                                  0, 0)

        #
        # If Update is missing we get bogus message
        # 
        # ERROR: In vtkImageData.cxx, line 1585
        # vtkImageData (0x100acce0): Bad Extent, retaining previous values
        #

        clip.Update()
        append.AddInput(clip.GetOutput())

    #
    # ERROR: In vtkImageData.cxx, line 1221
    # vtkImageData (0x100a55e0): GetScalarPointer: Pixel (384, 1772, 0) not in memory.
    # Current extent= (91, 302, 0, 3543, 0, 0)
    #

    append.Update()
    
    writer = vtkTIFFWriter()
    writer.SetDebug(verbose)
    writer.SetInput(append.GetOutput())
    writer.SetFileName(output)
    writer.Write()

    return

if __name__ == "__main__":
    import sys
    sys.exit(main(sys.argv) or 0)


--------------------------------------------------------------------
This is the private VTK discussion list. Please keep messages on-topic.
Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at public.kitware.com>. For help, send message body containing
"info vtkusers" to the same address.
--------------------------------------------------------------------



More information about the vtkusers mailing list