last update 20 Sep 2009 |
#include <cvrLoadImageList.h>
Classes | |
class | parameters |
The parameters for the class loadImageList. More... | |
Public Member Functions | |
loadImageList () | |
loadImageList (const parameters &par) | |
loadImageList (const loadImageList &other) | |
virtual | ~loadImageList () |
loadImageList & | copy (const loadImageList &other) |
loadImageList & | operator= (const loadImageList &other) |
virtual const std::string & | name () const |
virtual loadImageList * | clone () const |
virtual loadImageList * | newInstance () const |
const parameters & | getParameters () 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. | |
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_ |
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.
cvr::loadImageList::loadImageList | ( | ) |
Default constructor.
cvr::loadImageList::loadImageList | ( | const parameters & | par | ) |
Construct using the given parameters.
cvr::loadImageList::loadImageList | ( | const loadImageList & | other | ) |
virtual cvr::loadImageList::~loadImageList | ( | ) | [virtual] |
Destructor.
virtual loadImageList* cvr::loadImageList::clone | ( | ) | const [virtual] |
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 | ) |
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 |
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
Load the contents as a integer mask.
Default implementation discards the palette of the other matrix<int32> method.
chnl | integer mask |
bool cvr::loadImageList::load | ( | std::vector< matrix< float > * > & | chnl | ) |
Load the contents as a gray channel.
Default implementation just discards the palette of load(matrix<ubyte>&, palette&)
chnl | 8-bit gray channel8 |
bool cvr::loadImageList::load | ( | std::vector< image * > & | img | ) |
Load the contents as a integer mask.
Default implementation discards the palette of the other matrix<int32> method.
chnl | integer mask |
bool cvr::loadImageList::load | ( | matrix< float > & | chnl | ) |
Load the contents as a gray channel.
Default implementation just discards the palette of load(matrix<ubyte>&, palette&)
chnl | 8-bit gray channel8 |
bool cvr::loadImageList::load | ( | image & | img | ) |
bool cvr::loadImageList::loadHelp | ( | std::vector< T * > & | dest, | |
std::vector< palette * > & | pal | |||
) | [inline, protected] |
load all channels of type T and corresponding palettes
bool cvr::loadImageList::loadHelp | ( | std::vector< T * > & | dest | ) | [inline, protected] |
load all images of type T
bool cvr::loadImageList::loadHelp | ( | T & | dest, | |
palette & | pal | |||
) | [inline, protected] |
load a channel of type T and a corresponding palette
bool cvr::loadImageList::loadHelp | ( | T & | dest | ) | [inline, protected] |
load an image of type T
virtual const std::string& cvr::loadImageList::name | ( | ) | const [virtual] |
virtual loadImageList* cvr::loadImageList::newInstance | ( | ) | const [virtual] |
loadImageList& cvr::loadImageList::operator= | ( | const loadImageList & | other | ) |
void cvr::loadImageList::rewind | ( | ) |
void cvr::loadImageList::skip | ( | ) |
virtual bool cvr::loadImageList::updateParameters | ( | ) | [virtual] |
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.
bool cvr::loadImageList::useRange | ( | InputIterator | first, | |
InputIterator | last | |||
) | [inline] |
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] |
std::list<std::string>::const_iterator cvr::loadImageList::it_ [protected] |
Iterator pointing to the next filename to load.
bool cvr::loadImageList::loadAllImageTypes_ [protected] |
If true all filetypes supported by cvr::IOImage should be considered.
ioImage cvr::loadImageList::loader_ [protected] |
IOImage object used for actually loading the images and for checking valid filetypes when "ALL" is selected.