CVR-Lib last update 20 Sep 2009

cvr::loadImageList Class Reference

This class allows convenient loading of a set of images. More...

#include <cvrLoadImageList.h>

Inheritance diagram for cvr::loadImageList:

Inheritance graph
[legend]
Collaboration diagram for cvr::loadImageList:

Collaboration graph
[legend]

List of all members.

Classes

class  parameters
 The parameters for the class loadImageList. More...

Public Member Functions

 loadImageList ()
 loadImageList (const parameters &par)
 loadImageList (const loadImageList &other)
virtual ~loadImageList ()
loadImageListcopy (const loadImageList &other)
loadImageListoperator= (const loadImageList &other)
virtual const std::string & name () const
virtual loadImageListclone () const
virtual loadImageListnewInstance () const
const parametersgetParameters () const
virtual bool updateParameters ()
Flow control.
int computeSize () const
void rewind ()
bool hasNext () const
void skip ()
Set the source for the filenames
bool useDirectory (const std::string &dirname)
bool useFileList (const std::string &filename)
template<typename InputIterator >
bool useRange (InputIterator first, InputIterator last)
Load single image
Get the next image/channel etc.

from the given list of filenames.

const std::string & getNextFilename () const
const std::string & getLastLoadedFilename () const
bool load (image &img)
bool load (matrix< ubyte > &chnl, palette &pal)
bool load (matrix< ubyte > &chnl)
bool load (matrix< float > &chnl)
bool load (matrix< int32 > &chnl, palette &pal)
bool load (matrix< int32 > &chnl)
Load all images/channels etc.
Load all images at once from the given list of filenames.

void getFilenames (std::vector< std::string > &filenames) const
bool load (std::vector< image * > &img)
bool load (std::vector< matrix< ubyte > * > &chnl, std::vector< palette * > &pal)
bool load (std::vector< matrix< ubyte > * > &chnl)
bool load (std::vector< matrix< float > * > &chnl)
bool load (std::vector< matrix< int32 > * > &chnl, std::vector< palette * > &pal)
bool load (std::vector< matrix< int32 > * > &chnl)

Protected Member Functions

bool hasValidFileExtension (const std::string &filename) const
Helper functions for loading
template<class T >
bool loadHelp (T &dest)
template<class T >
bool loadHelp (T &dest, palette &pal)
template<class T >
bool loadHelp (std::vector< T * > &dest)
template<class T >
bool loadHelp (std::vector< T * > &dest, std::vector< palette * > &pal)

Protected Attributes

ioImage loader_
std::list< std::string > filenames_
std::list< std::string >
::const_iterator 
it_
bool loadAllImageTypes_
std::string fileExt_


Detailed Description

This class allows convenient loading of a set of images.

It can be supplied with a directory, a text file containing image filenames, or forward iterators to strings. To be consistent over different operating systems the filenames are sorted alphabetically.

Using this class is somewhat similar to using an iterator. However, to make sure no copying is involved in loading the images the destination objects are arguments to the load() member functions instead of dereferencing an iterator. The following example shows how to use the class:

 loadImageList loader;
 loader.useDirectory("/home/foo/bar");
 viewer2D viewer;
 viewer2D::interaction action;
 image img;
 while (loader.hasNext()) {
   loader.load(img);
   viewer.show(img);
   viewer.waitKey(action);
 }

The example first finds all image files in the directory /home/foo/bar. Then it shows them consecutively, each image until a key is pressed.

There are also load() member functions that load pointers to all images at once into a std::vector. This can be useful e.g. if the lag of loading the images can't be tolerated in latter processing. NOTE that the user is responsible for deleting the allocated memory. Not using this way of memory managment can result in excessive copying of the images.

There are also member functions to retrieve the name of the next image before actually loading it and to retrieve all filenames.

You can confine the image filetype you want to load by setting parameters::fileType to something other than "ALL". Also you can configure via continueOnError that errors while loading a file should be ignored and the next valid image should be returned instead.

See also:
loadImageList::parameters.

Constructor & Destructor Documentation

cvr::loadImageList::loadImageList (  ) 

Default constructor.

cvr::loadImageList::loadImageList ( const parameters par  ) 

Construct using the given parameters.

cvr::loadImageList::loadImageList ( const loadImageList other  ) 

Copy constructor.

Parameters:
other the object to be copied

virtual cvr::loadImageList::~loadImageList (  )  [virtual]

Destructor.


Member Function Documentation

virtual loadImageList* cvr::loadImageList::clone (  )  const [virtual]

Returns a pointer to a clone of this functor.

Implements cvr::object.

int cvr::loadImageList::computeSize (  )  const

Compute the total size of images available since the last use().

Please note that the size is computed, and therefore it is somehow slow. Never use this method to check if all images have been loaded; use hasNext() instead.

loadImageList& cvr::loadImageList::copy ( const loadImageList other  ) 

Copy data of "other" functor.

Parameters:
other the functor to be copied
Returns:
a reference to this functor object

void cvr::loadImageList::getFilenames ( std::vector< std::string > &  filenames  )  const

Puts the filenames of all files into filenames in the same order that they are in the load() member functions for the complete set.

const std::string& cvr::loadImageList::getLastLoadedFilename (  )  const

Returns the name of the image file that was loaded by the last call to one of the single image load() member functions.

This member function is a bit slower than getNextFilename() but is recommended of parameters::continueOnError is true.

const std::string& cvr::loadImageList::getNextFilename (  )  const

Returns the filename for the image that will be loaded by the next call to load().

Note that if parameters::continueOnError is true the filename returned by this member function might actually not be loaded by the next load() call in case an error occurs. Consider using getLastLoadedFilename() instead.

const parameters& cvr::loadImageList::getParameters (  )  const

Returns used parameters.

Reimplemented from cvr::parametersManager.

bool cvr::loadImageList::hasNext (  )  const

Returns true if there are more images to be loaded on the list.

bool cvr::loadImageList::hasValidFileExtension ( const std::string &  filename  )  const [protected]

checks whether a filename has the extension specified in the parameters

bool cvr::loadImageList::load ( std::vector< matrix< int32 > * > &  chnl  ) 

Load the contents as a integer mask.

Default implementation discards the palette of the other matrix<int32> method.

Parameters:
chnl integer mask

bool cvr::loadImageList::load ( std::vector< matrix< int32 > * > &  chnl,
std::vector< palette * > &  pal 
)

Load the contents as a integer mask.

Default implementation returns the casting of the channel8 related method.

Parameters:
chnl integer index channel
pal corresponding palette

bool cvr::loadImageList::load ( std::vector< matrix< float > * > &  chnl  ) 

Load a floating point channel.

Not many file formats support floating point channels, so the default implementation just casts a channel8 into the float.

Parameters:
chnl floating point gray channel

bool cvr::loadImageList::load ( std::vector< matrix< ubyte > * > &  chnl  ) 

Load the contents as a gray channel.

Default implementation just discards the palette of load(matrix<ubyte>&, palette&)

Parameters:
chnl 8-bit gray channel8

bool cvr::loadImageList::load ( std::vector< matrix< ubyte > * > &  chnl,
std::vector< palette * > &  pal 
)

Load a channel8 as a label mask with its corresponding palette.

If the file containes a color image, then the functor has to quantize the colors and returnes the quantized table.

Parameters:
chnl index channel
pal corresponding palette

bool cvr::loadImageList::load ( std::vector< image * > &  img  ) 

Load all files as a color image.

Parameters:
img the RGB image

bool cvr::loadImageList::load ( matrix< int32 > &  chnl  ) 

Load the contents as a integer mask.

Default implementation discards the palette of the other matrix<int32> method.

Parameters:
chnl integer mask

bool cvr::loadImageList::load ( matrix< int32 > &  chnl,
palette pal 
)

Load the contents as a integer mask.

Default implementation returns the casting of the channel8 related method.

Parameters:
chnl integer index channel
pal corresponding palette

bool cvr::loadImageList::load ( matrix< float > &  chnl  ) 

Load a floating point channel.

Not many file formats support floating point channels, so the default implementation just casts a channel8 into the float.

Parameters:
chnl floating point gray channel

bool cvr::loadImageList::load ( matrix< ubyte > &  chnl  ) 

Load the contents as a gray channel.

Default implementation just discards the palette of load(matrix<ubyte>&, palette&)

Parameters:
chnl 8-bit gray channel8

bool cvr::loadImageList::load ( matrix< ubyte > &  chnl,
palette pal 
)

Load a channel8 as a label mask with its corresponding palette.

If the file containes a color image, then the functor has to quantize the colors and returns the quantized table.

Parameters:
chnl index channel
pal corresponding palette

bool cvr::loadImageList::load ( image img  ) 

Load file as a color image.

Parameters:
img the RGB image

template<class T >
bool cvr::loadImageList::loadHelp ( std::vector< T * > &  dest,
std::vector< palette * > &  pal 
) [inline, protected]

load all channels of type T and corresponding palettes

template<class T >
bool cvr::loadImageList::loadHelp ( std::vector< T * > &  dest  )  [inline, protected]

load all images of type T

template<class T >
bool cvr::loadImageList::loadHelp ( T &  dest,
palette pal 
) [inline, protected]

load a channel of type T and a corresponding palette

template<class T >
bool cvr::loadImageList::loadHelp ( T &  dest  )  [inline, protected]

load an image of type T

virtual const std::string& cvr::loadImageList::name (  )  const [virtual]

Returns the complete name of the functor class.

Implements cvr::object.

virtual loadImageList* cvr::loadImageList::newInstance (  )  const [virtual]

Returns a pointer to a new instance of this functor.

Implements cvr::object.

loadImageList& cvr::loadImageList::operator= ( const loadImageList other  ) 

Alias for copy member.

Parameters:
other the functor to be copied
Returns:
a reference to this functor object

void cvr::loadImageList::rewind (  ) 

After calling rewind the next image loaded by a single image load() function will be the first one in the list.

void cvr::loadImageList::skip (  ) 

Skips the current image filename on the list and without actually loading it.

For example if you call rewind() and then skip() then the next load() will load the second image file on the list.

Warning:
Note that analogous to load it is your responsibility to check whether the list hasNext().

virtual bool cvr::loadImageList::updateParameters (  )  [virtual]

Makes sure the given parameters esp.

fileType are valid.

Reimplemented from cvr::parametersManager.

bool cvr::loadImageList::useDirectory ( const std::string &  dirname  ) 

Use all image filenames as specified in the parameters that can be found in dirname.

bool cvr::loadImageList::useFileList ( const std::string &  filename  ) 

Use all image filenames as specified in the parameters that are present in filename.

Note that lines starting with a semi-colon are regarded as comment lines and that the image filenames contained in filename are NOT sorted alphabetically.

template<typename InputIterator >
bool cvr::loadImageList::useRange ( InputIterator  first,
InputIterator  last 
) [inline]

Use the valid image filenames contained in the range first to last: [first; last).

The iterators must be valid input iterators and dereference to std::string.

Note that the image filenames contained in the range are NOT sorted alphabetically.


Member Data Documentation

std::string cvr::loadImageList::fileExt_ [protected]

Correct file extension if only one type is to be considered.

std::list<std::string> cvr::loadImageList::filenames_ [protected]

This list stores all valid image filenames to be loaded.

std::list<std::string>::const_iterator cvr::loadImageList::it_ [protected]

Iterator pointing to the next filename to load.

If true all filetypes supported by cvr::IOImage should be considered.

IOImage object used for actually loading the images and for checking valid filetypes when "ALL" is selected.


The documentation for this class was generated from the following file:

Generated on Sun Sep 20 22:08:55 2009 for CVR-Lib by Doxygen 1.5.8