[vtk-developers] vtkSortFileNames, series file name generators

David Gobbi dgobbi at atamai.com
Wed Jun 28 11:54:31 EDT 2006


Hi All,

This is a note about the VTK "series filename generator"
classes that I started working on in Feb, and which were
finally committed to CVS over the weekend.

My goal was to provide classes that would make it easy
for a user to select files either in a file browser or on the
command line, and then have the application sort those
files for use by a vtkImageReader.

The first class is vtkGlobFileNames, which finds all
files that match a wildcard pattern.  The main purpose
of this class is to take a set of wildcards provided on
the command line and expand them to generate a
list of files contained in a vtkStringArray:

vtkGlobFileNames *glob = vtkGlobFileNames::New();
glob->AddFileNames("data/file*.png")
glob->AddFileNames("data2/file*.jpg")

vtkStringArray *files = glob->GetFilenames();


The second class is vtkSortFileNames, which can be used
to sort a list of files, or even to group them according
to similarity of the filenames:

vtkSortFileNames *sortFiles = vtkSortFileNames::New();
sortFiles->SetInputFiles(files);
sortFiles->NumericSortOn();
sortFiles->GroupingOn();

int n = sortFiles->GetNumberOfGroups();
vtkStringArray *group1 = sortFiles->GetFileNames(0);
vtkStringArray *group2 = sortFiles->GetFileNames(1);


Finally, I have added a method to vtkImageReader2 so
that it can accept a list of file names contained in a
vtkStringArray.  Since all the image readers are derived
from vtkImageReader2, they have all inherited this
method.

vtkPNGReader *reader = vtkPNGReader::New();
reader->SetFileNames(group1);


These changes add a great deal of flexibility to the
ways that VTK can handle file names. 

One big question that I have, however, is what
people think about the use of vtkStringArray as
the input to the ImageReader.  It seems to me that
it would be nicer if the string array could be
contained in a vtkDataObject, so that the sequence

"file browser" -> "vtkSortFileNames" -> "vtkImageReader"

could be viewed as a pipeline for a data object
containing a vtkStringArray.  Of course string
processing is not what VTK was designed for,
but it still seems that it might be nice to have a
distinct data object for a list of strings.

Any thoughts?

 - David






More information about the vtk-developers mailing list