vtkStringArray and vtkImageReader

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

vtkStringArray and vtkImageReader

David Gobbi-2
Hi All,

Over the years I've run into problems with vtkImageReader several times
because I have a set of files that aren't a nice, numbered sequence.

Now that VTK has a vtkStringArray, it would be nice if vtkImageReader
had a SetFileNameArray() method to allow a user to set an arbitrary list
of files to read.

Has anyone started working on something similar?

 - David


_______________________________________________
vtk-developers mailing list
[hidden email]
http://www.vtk.org/mailman/listinfo/vtk-developers
Reply | Threaded
Open this post in threaded view
|

RE: vtkStringArray and vtkImageReader

Lorensen, William E (GE, Research)
David,

This is an excellent idea. We do this in itk. The file name generation is actually separate from the series readers. We always pass in lists of strings. Then we have series filenames generators. Looks like you could do this an still maintain the current API.

In itk we have:
NumericSeriesFileNames
RegularExpressionFileNames
Dicom(GDCM)SeriesFileNames
and
ArchetypeSeriesFileNames

The latter is particularly cool. You give it one file name from a set of filenames and it generates the set of names.

Actually, the itk I/O mechanism itself is very different in itk. itk uses an IO Factory that discovers which file specific reader to use. Also, we separate series reading from image reading. The series reader invokes an image reader for each file. We do not have to decide which reader to use with which filename, the factory does that.

Bill



-----Original Message-----
From: vtk-developers-bounces+lorensen=[hidden email]
[mailto:vtk-developers-bounces+lorensen=[hidden email]]On Behalf Of
David Gobbi
Sent: Thursday, February 02, 2006 4:08 PM
To: VTK Developers
Subject: [vtk-developers] vtkStringArray and vtkImageReader


Hi All,

Over the years I've run into problems with vtkImageReader several times
because I have a set of files that aren't a nice, numbered sequence.

Now that VTK has a vtkStringArray, it would be nice if vtkImageReader
had a SetFileNameArray() method to allow a user to set an arbitrary list
of files to read.

Has anyone started working on something similar?

 - David


_______________________________________________
vtk-developers mailing list
[hidden email]
http://www.vtk.org/mailman/listinfo/vtk-developers
_______________________________________________
vtk-developers mailing list
[hidden email]
http://www.vtk.org/mailman/listinfo/vtk-developers
Reply | Threaded
Open this post in threaded view
|

Re: vtkStringArray and vtkImageReader

David Gobbi-2
I'll take a look at ITK IO.  Right now I use some python code to figure
out filenames and decide which reader to use, and it works well for
that.  I have an app that I need to write in pure C++, though, and need
the user to be able to highlight a group of files in a file browser and
load them as a volume.  Surprisingly, that is a very difficult thing to
accomplish in VTK.

Lorensen, William E (GE, Research) wrote:

>David,
>
>This is an excellent idea. We do this in itk. The file name generation is actually separate from the series readers. We always pass in lists of strings. Then we have series filenames generators. Looks like you could do this an still maintain the current API.
>
>In itk we have:
>NumericSeriesFileNames
>RegularExpressionFileNames
>Dicom(GDCM)SeriesFileNames
>and
>ArchetypeSeriesFileNames
>
>The latter is particularly cool. You give it one file name from a set of filenames and it generates the set of names.
>
>Actually, the itk I/O mechanism itself is very different in itk. itk uses an IO Factory that discovers which file specific reader to use. Also, we separate series reading from image reading. The series reader invokes an image reader for each file. We do not have to decide which reader to use with which filename, the factory does that.
>
>Bill
>
>
>
>-----Original Message-----
>From: vtk-developers-bounces+lorensen=[hidden email]
>[mailto:vtk-developers-bounces+lorensen=[hidden email]]On Behalf Of
>David Gobbi
>Sent: Thursday, February 02, 2006 4:08 PM
>To: VTK Developers
>Subject: [vtk-developers] vtkStringArray and vtkImageReader
>
>
>Hi All,
>
>Over the years I've run into problems with vtkImageReader several times
>because I have a set of files that aren't a nice, numbered sequence.
>
>Now that VTK has a vtkStringArray, it would be nice if vtkImageReader
>had a SetFileNameArray() method to allow a user to set an arbitrary list
>of files to read.
>
>Has anyone started working on something similar?
>
> - David
>
>
>_______________________________________________
>vtk-developers mailing list
>[hidden email]
>http://www.vtk.org/mailman/listinfo/vtk-developers
>
>  
>

_______________________________________________
vtk-developers mailing list
[hidden email]
http://www.vtk.org/mailman/listinfo/vtk-developers
Reply | Threaded
Open this post in threaded view
|

Re: vtkStringArray and vtkDirectory

David Gobbi-2
In reply to this post by David Gobbi-2
On a related note, I just added a "GetFiles()" method to vtkDirectory to
get a vtkStringArray containing all of the files in a directory.  The
vtkDirectory also needs enhancements to make it list files only of a
specific type (e.g. "*.vtk") and to separately list subdirectories vs.
files.  Does anyone out there have a customized vtkDirectory class that
already does either of these?

David Gobbi wrote:

> Hi All,
>
> Over the years I've run into problems with vtkImageReader several
> times because I have a set of files that aren't a nice, numbered
> sequence.
>
> Now that VTK has a vtkStringArray, it would be nice if vtkImageReader
> had a SetFileNameArray() method to allow a user to set an arbitrary
> list of files to read.
>
> Has anyone started working on something similar?
>
> - David
>
>
> _______________________________________________
> vtk-developers mailing list
> [hidden email]
> http://www.vtk.org/mailman/listinfo/vtk-developers
>

_______________________________________________
vtk-developers mailing list
[hidden email]
http://www.vtk.org/mailman/listinfo/vtk-developers
Reply | Threaded
Open this post in threaded view
|

Re: vtkStringArray and vtkImageReader

David Gobbi-2
In reply to this post by David Gobbi-2
I've finished adding the vtkImageReader2::SetFileNames(vtkStringArray *) and will be committing to
CVS unless there are objections.  The bugtracker entry is here:

http://public.kitware.com/Bug/bug.php?op=show&bugid=2834

The next thing to do is add some filename-list generators.  It would be very convenient to be able
to do this:

 reader->SetFilePattern("/data/dir/*.sli")

The SetFileNamePattern optionally generate filenames using wildcards instead of format strings, if
the string contained "*" instead of "%".  I'm hesitant to further complicate the vtkImageReader2
API, but it sure would be nice to have something like this...

The generic solution is to add a "vtkFileNameGenerator", similar to the way ITK does things.  For
VTK I would build the different kinds of file name generation (wildcard, numbered series,
archetype) into one single class rather than create a class hierarchy.  There would eventually be
a vtkDICOMFileNameGenerator specifically for handling DICOM series.

 - David


--- David Gobbi <[hidden email]> wrote:

> I'll take a look at ITK IO.  Right now I use some python code to figure
> out filenames and decide which reader to use, and it works well for
> that.  I have an app that I need to write in pure C++, though, and need
> the user to be able to highlight a group of files in a file browser and
> load them as a volume.  Surprisingly, that is a very difficult thing to
> accomplish in VTK.
>
> Lorensen, William E (GE, Research) wrote:
>
> >David,
> >
> >This is an excellent idea. We do this in itk. The file name generation is actually separate
> from the series readers. We always pass in lists of strings. Then we have series filenames
> generators. Looks like you could do this an still maintain the current API.
> >
> >In itk we have:
> >NumericSeriesFileNames
> >RegularExpressionFileNames
> >Dicom(GDCM)SeriesFileNames
> >and
> >ArchetypeSeriesFileNames
> >
> >The latter is particularly cool. You give it one file name from a set of filenames and it
> generates the set of names.
> >
> >Actually, the itk I/O mechanism itself is very different in itk. itk uses an IO Factory that
> discovers which file specific reader to use. Also, we separate series reading from image
> reading. The series reader invokes an image reader for each file. We do not have to decide which
> reader to use with which filename, the factory does that.
> >
> >Bill
> >
> >
> >
> >-----Original Message-----
> >From: vtk-developers-bounces+lorensen=[hidden email]
> >[mailto:vtk-developers-bounces+lorensen=[hidden email]]On Behalf Of
> >David Gobbi
> >Sent: Thursday, February 02, 2006 4:08 PM
> >To: VTK Developers
> >Subject: [vtk-developers] vtkStringArray and vtkImageReader
> >
> >
> >Hi All,
> >
> >Over the years I've run into problems with vtkImageReader several times
> >because I have a set of files that aren't a nice, numbered sequence.
> >
> >Now that VTK has a vtkStringArray, it would be nice if vtkImageReader
> >had a SetFileNameArray() method to allow a user to set an arbitrary list
> >of files to read.
> >
> >Has anyone started working on something similar?
> >
> > - David
> >
> >
> >_______________________________________________
> >vtk-developers mailing list
> >[hidden email]
> >http://www.vtk.org/mailman/listinfo/vtk-developers
> >
> >  
> >
>
> _______________________________________________
> vtk-developers mailing list
> [hidden email]
> http://www.vtk.org/mailman/listinfo/vtk-developers
>

_______________________________________________
vtk-developers mailing list
[hidden email]
http://www.vtk.org/mailman/listinfo/vtk-developers
Reply | Threaded
Open this post in threaded view
|

Re: vtkStringArray and vtkImageReader

Michael Halle
>
>
> The generic solution is to add a "vtkFileNameGenerator", similar to
> the way ITK does things.  For
> VTK I would build the different kinds of file name generation
> (wildcard, numbered series,
> archetype) into one single class rather than create a class hierarchy.
>  There would eventually be
> a vtkDICOMFileNameGenerator specifically for handling DICOM series.

Maybe not even a "vtkFileNameGenerator", but a "vtkNameGenerator".
The interface is generic enough to iterate over other
string-described resources.  Subclasses could look for actual
files and such.

Too general?

--Mike

_______________________________________________
vtk-developers mailing list
[hidden email]
http://www.vtk.org/mailman/listinfo/vtk-developers
Reply | Threaded
Open this post in threaded view
|

Re: vtkStringArray and vtkImageReader

David Gobbi-2
--- Michael Halle <[hidden email]> wrote:

> > The generic solution is to add a "vtkFileNameGenerator", similar to
> > the way ITK does things.  For
> > VTK I would build the different kinds of file name generation
> > (wildcard, numbered series,
> > archetype) into one single class rather than create a class hierarchy.
> >  There would eventually be
> > a vtkDICOMFileNameGenerator specifically for handling DICOM series.
>
> Maybe not even a "vtkFileNameGenerator", but a "vtkNameGenerator".
> The interface is generic enough to iterate over other
> string-described resources.  Subclasses could look for actual
> files and such.
>
> Too general?

A generic iterator would probably go into Utilities/kwsys/SystemTools.cxx instead of into its own
VTK class.

 - David
_______________________________________________
vtk-developers mailing list
[hidden email]
http://www.vtk.org/mailman/listinfo/vtk-developers
Reply | Threaded
Open this post in threaded view
|

Re: vtkStringArray and vtkImageReader

Mathieu Malaterre-2
In reply to this post by David Gobbi-2
David Gobbi wrote:

> I've finished adding the vtkImageReader2::SetFileNames(vtkStringArray *) and will be committing to
> CVS unless there are objections.  The bugtracker entry is here:
>
> http://public.kitware.com/Bug/bug.php?op=show&bugid=2834
>
> The next thing to do is add some filename-list generators.  It would be very convenient to be able
> to do this:
>
>  reader->SetFilePattern("/data/dir/*.sli")
>
> The SetFileNamePattern optionally generate filenames using wildcards instead of format strings, if
> the string contained "*" instead of "%".  I'm hesitant to further complicate the vtkImageReader2
> API, but it sure would be nice to have something like this...
>
> The generic solution is to add a "vtkFileNameGenerator", similar to the way ITK does things.  For
> VTK I would build the different kinds of file name generation (wildcard, numbered series,
> archetype) into one single class rather than create a class hierarchy.  There would eventually be
> a vtkDICOMFileNameGenerator specifically for handling DICOM series.

I would rather see an ITK like approach, it has proven to be very
customizable in particular for the DICOM case as you mention.

Thanks
Mathieu
_______________________________________________
vtk-developers mailing list
[hidden email]
http://www.vtk.org/mailman/listinfo/vtk-developers
Reply | Threaded
Open this post in threaded view
|

Re: vtkStringArray and vtkImageReader

David Gobbi-2
Mathieu Malaterre wrote:

> David Gobbi wrote:
>
>> The generic solution is to add a "vtkFileNameGenerator", similar to
>> the way ITK does things.  For
>> VTK I would build the different kinds of file name generation
>> (wildcard, numbered series,
>> archetype) into one single class rather than create a class
>> hierarchy.  There would eventually be
>> a vtkDICOMFileNameGenerator specifically for handling DICOM series.
>
>
> I would rather see an ITK like approach, it has proven to be very
> customizable in particular for the DICOM case as you mention.

When I looked at how ITK does things, I saw that ITK's set of
"SeriesFileNames" classes do not fit into a heirarchy.  The
GDCMSeriesFileNames, ArchetypeSeriesFileNames,
RegularExpressionSeriesFileNames, etc. are all derived directly from
itk::Object, it seems that there should be a base class.

None of the ITK classes seems to have to feature I want most: to be able
to generate a list of file names based on the "*?[][^]" set of
wildcards. Regular expressions are a bit too advanced for most of my users.

Maybe I'm trying to bite off more than I can chew.  Instead of writing a
set of file name generators, I could just add a method to vtkDirectory
so that it will filter the list of files according to a wildcard string,
something like vtkDirectory::SetWildcardString("*.png").

 - David
_______________________________________________
vtk-developers mailing list
[hidden email]
http://www.vtk.org/mailman/listinfo/vtk-developers
Reply | Threaded
Open this post in threaded view
|

Re: vtkStringArray and vtkImageReader

David Gobbi-2
David Gobbi wrote:

> Mathieu Malaterre wrote:
>
>> David Gobbi wrote:
>>
>>> The generic solution is to add a "vtkFileNameGenerator", similar to
>>> the way ITK does things.  For
>>> VTK I would build the different kinds of file name generation
>>> (wildcard, numbered series,
>>> archetype) into one single class rather than create a class
>>> hierarchy.  There would eventually be
>>> a vtkDICOMFileNameGenerator specifically for handling DICOM series.
>>
>>
>>
>> I would rather see an ITK like approach, it has proven to be very
>> customizable in particular for the DICOM case as you mention.
>
>
> When I looked at how ITK does things, I saw that ITK's set of
> "SeriesFileNames" classes do not fit into a heirarchy.  The
> GDCMSeriesFileNames, ArchetypeSeriesFileNames,
> RegularExpressionSeriesFileNames, etc. are all derived directly from
> itk::Object, it seems that there should be a base class.
>
> None of the ITK classes seems to have to feature I want most: to be
> able to generate a list of file names based on the "*?[][!]" set of
> wildcards. Regular expressions are a bit too advanced for most of my
> users.


I've decided on a solution, if people agree that it is a good way to go
then I will implement it and commit it.

First I'll state the problem that I want to solve.  My app accepts
filenames in two ways :
1) on the command line, e.g.  "myapp [options] filename*.png
2) through a file browser that allows multiple file selections
I have to take these file names and sort them into a series that either
the ImageReader can use, or that a collection of vtkDataSetReaders can use.

My solution is to write two classes and modify vtkImageReader to accept
a list of files:
1) write a vtkGlob class that handles wildcards and produces a
vtkStringArray of files, implemented with Utilities/kwsys/Glob.
2) write a vtkSortSeriesFileNames class that will sort a vtkStringArray
of file names taken from vtkGlob or from a file browser
3) add a SetFileNames() method to vtkImageReader2 so that it can take a
vtkStringArray containing file names

I've already done (1) and (3) and they are ready to commit.

I only have the vtkSortSeriesFileNames class left to write.   It can be
the first of VTK's series file name generators.

 - David







_______________________________________________
vtk-developers mailing list
[hidden email]
http://www.vtk.org/mailman/listinfo/vtk-developers
Reply | Threaded
Open this post in threaded view
|

Re: vtkStringArray and vtkImageReader

Dean Inglis
In reply to this post by David Gobbi-2
Hi David,

I run into file name schemes of the type (sorted here)

I0012345.M01
I0012345.M02
I0012345.M03
I0012346.M01
I0012346.M02

or in general:

*< numeric_1 >.*< numeric_2 >

wherein standard alphabetical sorting does not work,
and sorting is required on two passes:
first on numeric_1 and then on numeric_2.

With regard to item 2), would it be sensible to
implement the API for vtkSortSeriesFileNames using a
callback mechanism:  that is either vtkSortSeriesFileNames
(or vtkImageReader) could broadcast a vtkCommand::SortFileNames
event that users could add a callback to that would permit
custom sorting.  Use scenario:

vtkStringArray array

vtkSortSeriesFileNames sorter
sorter AddObserver vtkCommand::SortFileNames mysortcallback
sorter SetFileNameArray array
sorter Sort

vtkImageReader reader
reader SetFileNameArray sorter GetSortedFileNameArray

Just a thought, and thanks for working on this.  I for one
welcome the additions!  The other thing that would be useful is if
vtkImageReader could read a series of single files having variable
length headers.

Dean

>My solution is to write two classes and modify vtkImageReader to accept
>a list of files:
>1) write a vtkGlob class that handles wildcards and produces a
>vtkStringArray of files, implemented with Utilities/kwsys/Glob.
>2) write a vtkSortSeriesFileNames class that will sort a vtkStringArray
>of file names taken from vtkGlob or from a file browser
>3) add a SetFileNames() method to vtkImageReader2 so that it can take a
>vtkStringArray containing file names




_______________________________________________
vtk-developers mailing list
[hidden email]
http://www.vtk.org/mailman/listinfo/vtk-developers
Reply | Threaded
Open this post in threaded view
|

RE: Re: vtkStringArray and vtkImageReader

Lorensen, William E (GE, Research)
In reply to this post by David Gobbi-2
The itkArchetypeSeriesFilenames class discovers patterns like the ones you describe. It uses the itkRegularExpressionSeriesFilenames internally. All regular expression, file and directory handling is done in a system independent way using kwsys. Similar classes could be written for vtk.

Bill


-----Original Message-----
From: vtk-developers-bounces+lorensen=[hidden email]
[mailto:vtk-developers-bounces+lorensen=[hidden email]]On Behalf Of
[hidden email]
Sent: Thursday, February 09, 2006 8:24 AM
To: [hidden email]
Subject: [vtk-developers] Re: vtkStringArray and vtkImageReader


Hi David,

I run into file name schemes of the type (sorted here)

I0012345.M01
I0012345.M02
I0012345.M03
I0012346.M01
I0012346.M02

or in general:

*< numeric_1 >.*< numeric_2 >

wherein standard alphabetical sorting does not work,
and sorting is required on two passes:
first on numeric_1 and then on numeric_2.

With regard to item 2), would it be sensible to
implement the API for vtkSortSeriesFileNames using a
callback mechanism:  that is either vtkSortSeriesFileNames
(or vtkImageReader) could broadcast a vtkCommand::SortFileNames
event that users could add a callback to that would permit
custom sorting.  Use scenario:

vtkStringArray array

vtkSortSeriesFileNames sorter
sorter AddObserver vtkCommand::SortFileNames mysortcallback
sorter SetFileNameArray array
sorter Sort

vtkImageReader reader
reader SetFileNameArray sorter GetSortedFileNameArray

Just a thought, and thanks for working on this.  I for one
welcome the additions!  The other thing that would be useful is if
vtkImageReader could read a series of single files having variable
length headers.

Dean

>My solution is to write two classes and modify vtkImageReader to accept
>a list of files:
>1) write a vtkGlob class that handles wildcards and produces a
>vtkStringArray of files, implemented with Utilities/kwsys/Glob.
>2) write a vtkSortSeriesFileNames class that will sort a vtkStringArray
>of file names taken from vtkGlob or from a file browser
>3) add a SetFileNames() method to vtkImageReader2 so that it can take a
>vtkStringArray containing file names




_______________________________________________
vtk-developers mailing list
[hidden email]
http://www.vtk.org/mailman/listinfo/vtk-developers
_______________________________________________
vtk-developers mailing list
[hidden email]
http://www.vtk.org/mailman/listinfo/vtk-developers
Reply | Threaded
Open this post in threaded view
|

Re: Re: vtkStringArray and vtkImageReader

David Gobbi-2
I hope nobody minds if I jump back in here...

The ArchetypeSeriesFilenames class always the original list of filenames
from a directory.  I need to be able to take my original list of
filenames from anywhere: a file load dialog (via multiple selections), a
directory listing, a wildcard glob, a network query, a text file, etc.

I'm not criticizing the ITK file name generator classes... I'm just
saying that none of them satisfy my requirements.

I want to contribute a generator that will take an unsorted list of
files from anywhere, and produce one or more sorted lists.  It will have
a NumericSort option to do proper left-to-right numeric sorting.  It
will be very much in the spirit of the ITK generators, but not quite so
specific-purpose.  Hopefully others will build on it to provide
regular-expression and archetype  generators.

 - David

P.S. One crazy idea I had was to make a new vtkDataObject as a container
for the filenames.  Then the series file name generators would actually
be sources or filters, and the Readers would convert the filename data
objects into VTK data sets.


Lorensen, William E (GE, Research) wrote:

>The itkArchetypeSeriesFilenames class discovers patterns like the ones you describe. It uses the itkRegularExpressionSeriesFilenames internally. All regular expression, file and directory handling is done in a system independent way using kwsys. Similar classes could be written for vtk.
>
>Bill
>
>
>-----Original Message-----
>From: vtk-developers-bounces+lorensen=[hidden email]
>[mailto:vtk-developers-bounces+lorensen=[hidden email]]On Behalf Of
>[hidden email]
>Sent: Thursday, February 09, 2006 8:24 AM
>To: [hidden email]
>Subject: [vtk-developers] Re: vtkStringArray and vtkImageReader
>
>
>Hi David,
>
>I run into file name schemes of the type (sorted here)
>
>I0012345.M01
>I0012345.M02
>I0012345.M03
>I0012346.M01
>I0012346.M02
>
>or in general:
>
>*< numeric_1 >.*< numeric_2 >
>
>wherein standard alphabetical sorting does not work,
>and sorting is required on two passes:
>first on numeric_1 and then on numeric_2.
>
>With regard to item 2), would it be sensible to
>implement the API for vtkSortSeriesFileNames using a
>callback mechanism:  that is either vtkSortSeriesFileNames
>(or vtkImageReader) could broadcast a vtkCommand::SortFileNames
>event that users could add a callback to that would permit
>custom sorting.  Use scenario:
>
>vtkStringArray array
>
>vtkSortSeriesFileNames sorter
>sorter AddObserver vtkCommand::SortFileNames mysortcallback
>sorter SetFileNameArray array
>sorter Sort
>
>vtkImageReader reader
>reader SetFileNameArray sorter GetSortedFileNameArray
>
>Just a thought, and thanks for working on this.  I for one
>welcome the additions!  The other thing that would be useful is if
>vtkImageReader could read a series of single files having variable
>length headers.
>
>Dean
>
>  
>
>>My solution is to write two classes and modify vtkImageReader to accept
>>a list of files:
>>1) write a vtkGlob class that handles wildcards and produces a
>>vtkStringArray of files, implemented with Utilities/kwsys/Glob.
>>2) write a vtkSortSeriesFileNames class that will sort a vtkStringArray
>>of file names taken from vtkGlob or from a file browser
>>3) add a SetFileNames() method to vtkImageReader2 so that it can take a
>>vtkStringArray containing file names
>>    
>>
>
>
>
>
>_______________________________________________
>vtk-developers mailing list
>[hidden email]
>http://www.vtk.org/mailman/listinfo/vtk-developers
>_______________________________________________
>vtk-developers mailing list
>[hidden email]
>http://www.vtk.org/mailman/listinfo/vtk-developers
>
>  
>

_______________________________________________
vtk-developers mailing list
[hidden email]
http://www.vtk.org/mailman/listinfo/vtk-developers