oln::io::internal Namespace Reference


Classes

struct  stream_wrapper< StreamFile >
struct  stream_wrapper< StreamGz >
class  image_reader
 Read an image of type reader_id. More...
struct  image_writer
 Write an image of type writer_id. More...
struct  try_readers
 Image's reader. More...
struct  try_readers< ReadNone, T >
 Reader for image of type None. More...
struct  readers_trier
 Readers trier functor, helper for stream_wrappers. More...
struct  try_writers
 Image's writer. More...
struct  try_writers< WriteNone, T >
 Reader for image of type None. More...
struct  writers_trier
 Writers trier functor, helper for stream_wrappers. More...
struct  pnm2d_info
struct  get_it
class  get_pnm_type
class  pnm_reader
struct  image_reader< ReadPnmPlain, I >
struct  image_reader< ReadPnmRaw, I >
struct  pnm_reader< R, 2, PnmBinary, I >
struct  pnm_reader< R, 2, PnmInteger, I >
struct  pnm_reader< R, 2, PnmVectorial, I >
 class pnm_reader<R, 2, PnmVectorial, I> More...
struct  pnm_reader< ReadPnmRaw, 3, P, I >
class  pnm_read_data
struct  pnm_read_data< PnmBinary, ReadPnmPlain >
struct  pnm_read_data< PnmBinary, ReadPnmRaw >
struct  pnm_read_data< PnmInteger, ReadPnmPlain >
struct  pnm_read_data< PnmInteger, ReadPnmRaw >
struct  pnm_read_data< PnmVectorial, ReadPnmPlain >
struct  pnm_read_data< PnmVectorial, ReadPnmRaw >
class  pnm_writer
struct  image_writer< WritePnmPlain, I >
struct  image_writer< WritePnmRaw, I >
struct  pnm_writer< W, 2, PnmBinary, I >
struct  pnm_writer< W, 2, PnmInteger, I >
struct  pnm_writer< W, 2, PnmVectorial, I >
struct  pnm_writer< WritePnmRaw, 3, P, I >
class  pnm_write_data
struct  pnm_write_data< PnmBinary, WritePnmPlain >
struct  pnm_write_data< PnmBinary, WritePnmRaw >
struct  pnm_write_data< PnmInteger, WritePnmPlain >
struct  pnm_write_data< PnmInteger, WritePnmRaw >
struct  pnm_write_data< PnmVectorial, WritePnmPlain >
struct  pnm_write_data< PnmVectorial, WritePnmRaw >
class  anything
 Anything. More...
class  stream_wrapper
struct  stream_wrappers_find_files
 Find files compatible with the given root, extension free filename. More...
struct  stream_wrappers_find_files< StreamNone >
 Do nothing because of the type of stream. More...
struct  try_stream_wrappers_in
 Read a stream. More...
struct  try_stream_wrappers_in< StreamNone, T, Reader >
 Read a stream of type None. More...
struct  try_stream_wrappers_out
 Write a stream. More...
struct  try_stream_wrappers_out< StreamNone, T, Reader >
 Write a stream of type None. More...
struct  utils
 Utils for io (get extension of a file). More...

Enumerations

enum  reader_id { ReadNone = 0, ReadPnmPlain = 1, ReadPnmRaw = 2, ReadAny = 2 }
 Reader identifiers. More...
enum  writer_id { WriteNone = 0, WritePnmPlain = 1, WritePnmRaw = 2, WriteAny = 2 }
 Writer identifiers. More...
enum  pnm_type { PnmInvalid = 0, PnmBinary = 1, PnmInteger = 2, PnmVectorial = 3 }
enum  stream_id { StreamNone = 0, StreamFile = 1, StreamGz = 2, StreamAny = 2 }
 Stream identifiers. More...

Functions

template<typename T>
bool read_any (T &output, const std::string &name)
 Read from a file.
template<typename T>
bool write_any (const T &input, const std::string &name)
 Write anything to a file.
template<unsigned N, class E>
bool read (abstract::image_with_dim< N, E > &output, const std::string &name)
 Read an image (2 dimensions) from a file.
template<class E>
bool read (abstract::image_with_dim< 1, E > &output, const std::string &name)
 Read an image (1 dimension) from a file.
template<class E, unsigned N>
bool write (const abstract::image_with_dim< N, E > &input, const std::string &name)
 Write an image (2 dimensions) to a file.
template<class E>
bool write (const abstract::image_with_dim< 1, E > &input, const std::string &name)
 Write an image (1 dimension) to a file.
static bool pnm_read_header2d (std::istream &s, char type, pnm2d_info &info)
 Return true if the headers from s are valid, false otherwise.
static bool pnm_write_header2d (std::ostream &s, char type, const pnm2d_info &info)
 Write headers in s output file, then return true.
bool read (window1d &output, const std::string &name)
 Read a window (1 dimension) from a file.
bool read (window2d &output, const std::string &name)
 Read a window (2 dimensions) from a file.
bool read (window3d &output, const std::string &name)
 Read a window (3 dimensions) from a file.
bool write (const window1d &input, const std::string &name)
 Write a window (1 dimension) to a file.
bool write (const window2d &input, const std::string &name)
 Write a window (2 dimensions) to a file.
bool write (const window3d &input, const std::string &name)
 Write a window (3 dimensions) to a file.
bool read (neighborhood1d &output, const std::string &name)
bool read (neighborhood2d &output, const std::string &name)
 Read a neighborhood from a file.
bool read (neighborhood3d &output, const std::string &name)
bool write (const neighborhood1d &input, const std::string &name)
bool write (const neighborhood2d &input, const std::string &name)
 Write a neighborhood to a file.
bool write (const neighborhood3d &input, const std::string &name)


Enumeration Type Documentation

enum oln::io::internal::reader_id

Reader identifiers.

They are used recursively: each time a ReadId fails, then try with ReadId - 1.

Definition at line 48 of file image_base.hh.

00048                      { ReadNone     = 0,
00049                        ReadPnmPlain = 1,
00050                        ReadPnmRaw   = 2,
00051                        ReadAny      = 2 };

enum oln::io::internal::stream_id

Stream identifiers.

They are used recursively: each time a StreamId fails, then try with StreamId - 1.

Definition at line 50 of file stream_wrapper.hh.

00050                      { StreamNone = 0,
00051                        StreamFile = 1,
00052                        StreamGz   = 2,
00053                        StreamAny  = 2 };

enum oln::io::internal::writer_id

Writer identifiers.

They are used recursively: each time a WriteId fails, then try with WriteId - 1.

Definition at line 95 of file image_base.hh.

00095                      { WriteNone     = 0,
00096                        WritePnmPlain = 1,
00097                        WritePnmRaw   = 2,
00098                        WriteAny      = 2 };


Function Documentation

static bool oln::io::internal::pnm_read_header2d ( std::istream &  s,
char  type,
pnm2d_info &  info 
) [static]

Return true if the headers from s are valid, false otherwise.

Todo:
FIXME: should be in a .cc file ?

Definition at line 54 of file pnm_read_2d.hh.

References oln::io::internal::pnm2d_info::cols, oln::io::internal::pnm2d_info::max_val, and oln::io::internal::pnm2d_info::rows.

Referenced by oln::io::internal::pnm_reader< R, 2, PnmVectorial, I >::read(), oln::io::internal::pnm_reader< R, 2, PnmInteger, I >::read(), and oln::io::internal::pnm_reader< R, 2, PnmBinary, I >::read().

00055       {
00056         // check magic
00057         if (s.get() != 'P' ) return false;
00058         if (s.get() != type) return false;
00059         if (s.get() != '\n') return false;
00060 
00061         // skip comments
00062         while (s.peek() == '#')
00063           {
00064             std::string line;
00065             std::getline(s,line);
00066           }
00067 
00068         // read size
00069         s >> info.cols >> info.rows;
00070         if (info.cols <= 0 || info.rows <= 0) return false;
00071 
00072         // FIXME: it can be either '\n', 'whitespace', ..., not only '\n'!
00073 
00074         // extract or skip maxvalue
00075         if (s.get() != '\n') return false;
00076         if (type != '1' && type != '4')
00077           {
00078             s >> info.max_val;
00079             if (info.max_val > 65535 || s.get() != '\n')
00080               return false;
00081           }
00082         return true;
00083       }

static bool oln::io::internal::pnm_write_header2d ( std::ostream &  s,
char  type,
const pnm2d_info &  info 
) [static]

Write headers in s output file, then return true.

Todo:
FIXME: should be in a .cc file ?

Definition at line 57 of file pnm_write_2d.hh.

References oln::io::internal::pnm2d_info::cols, oln::io::internal::pnm2d_info::max_val, and oln::io::internal::pnm2d_info::rows.

Referenced by oln::io::internal::pnm_writer< W, 2, PnmVectorial, I >::write(), oln::io::internal::pnm_writer< W, 2, PnmInteger, I >::write(), and oln::io::internal::pnm_writer< W, 2, PnmBinary, I >::write().

00058       {
00059         s.put('P'); s.put(type); s.put('\n');
00060         s << "# Creator: OLENA / Epita-LRDE" << std::endl
00061           << info.cols << ' ' << info.rows << std::endl;
00062 
00063         if (info.max_val >= 0)
00064           s << info.max_val << std::endl;
00065         return true;
00066       }

bool oln::io::internal::read ( neighborhood2d &  output,
const std::string &  name 
) [inline]

Read a neighborhood from a file.

Definition at line 49 of file se_neighborhood.hh.

References oln::neighborhood2d::add(), oln::abstract::dpoint< Exact >::is_centered(), and read().

00050       {
00051         image2d<ntg::bin> im;
00052         if (!read(im, name))
00053           return false;
00054 
00055         if (!(im.ncols() % 2) || !(im.nrows() % 2))
00056           {
00057             // std::clog << "[both image dimensions have to be odd for "
00058             //      << "a neighborhood2d]" << std::flush;
00059             return false;
00060           }
00061         image2d<ntg::bin>::fwd_iter_type it(im);
00062         neighborhood2d w;
00063         dpoint2d dcenter = dpoint2d(im.nrows()/2, im.ncols()/2);
00064         for_all (it)
00065           {
00066             if (it.row() == im.nrows()/2 && it.col() == im.ncols()/2+1)
00067               break;
00068             if (im[it])
00069               {
00070                 dpoint2d dp = dpoint2d(it) - dcenter;
00071                 if (dp.is_centered()) return false;
00072                 w.add(dp);
00073               }
00074           }
00075         for_all_remaining (it)
00076           {
00077             point2d p = it - dcenter;
00078             point2d inv_p = -p + dcenter;
00079             if (im[it] != im[inv_p])
00080               {
00081                 // std::clog << "[a neighborhood2d must be symmetric]"
00082                 //  << std::flush;
00083                 return false;
00084               }
00085           }
00086         output = w;
00087         return true;
00088       }

bool oln::io::internal::read ( neighborhood1d &  output,
const std::string &  name 
) [inline]

Functions from oln/io/se_neighborhood.hh.

bool oln::io::internal::read ( window3d &  output,
const std::string &  name 
) [inline]

Read a window (3 dimensions) from a file.

Definition at line 109 of file se_window.hh.

References oln::window3d::add(), and read().

00110       {
00111         image3d<ntg::bin> im;
00112         if (!read(im, name))
00113           return false;
00114         if (!(im.ncols() % 2) || !(im.nrows() % 2) || !(im.nslices() % 2))
00115           return false;
00116         image3d<ntg::bin>::iter_type it(im);
00117         window3d w;
00118         for_all (it)
00119           if (!im[it])
00120             w.add(dpoint3d(it) - dpoint3d(im.nrows()/2,
00121                                           im.ncols()/2,
00122                                           im.nslices()/2));
00123         output = w;
00124         return true;
00125       }

bool oln::io::internal::read ( window2d &  output,
const std::string &  name 
) [inline]

Read a window (2 dimensions) from a file.

Definition at line 81 of file se_window.hh.

References oln::window2d::add(), and read().

00082       {
00083         image2d<ntg::bin> im;
00084         if (!read(im, name))
00085           return false;
00086         if (!(im.ncols() % 2) || !(im.nrows() % 2))
00087           {
00088             // std::clog << "[both image dimensions have to be odd for a"
00089             //        << "window2d]"
00090             //        << std::flush;
00091             return false;
00092           }
00093         image2d<ntg::bin>::fwd_iter_type it(im);
00094         window2d w;
00095         for_all (it)
00096           if (!im[it])
00097             w.add(dpoint2d(it) - dpoint2d(im.nrows()/2, im.ncols()/2));
00098         output = w;
00099         return true;
00100       }

bool oln::io::internal::read ( window1d &  output,
const std::string &  name 
) [inline]

Read a window (1 dimension) from a file.

Functions from oln/io/se_window.hh.

Definition at line 58 of file se_window.hh.

References oln::window1d::add(), and read().

00059       {
00060         image1d<ntg::bin> im;
00061         if (!read(im, name))
00062           return false;
00063         if (!(im.ncols() % 2))
00064           return false;
00065         image1d<ntg::bin>::iter_type it(im);
00066         window1d w;
00067         for_all (it)
00068           if (!im[it])
00069             w.add(dpoint1d(it) - dpoint1d(im.ncols()/2));
00070         output = w;
00071         return true;
00072       }

template<class E>
bool oln::io::internal::read ( abstract::image_with_dim< 1, E > &  output,
const std::string &  name 
) [inline]

Read an image (1 dimension) from a file.

Definition at line 219 of file image_read.hh.

References read().

00220       {
00221         image2d<oln_value_type(E)> tmp;
00222         if (!read(tmp, name))
00223           return false;
00224         if (tmp.nrows() != 1)
00225           return false;
00226         typename image2d<oln_value_type(E)>::iter_type it(tmp);
00227         output.exact() = E(tmp.ncols());
00228         for_all(it)
00229           output(it.col()) = tmp[it];
00230         return true;
00231       }

template<unsigned N, class E>
bool oln::io::internal::read ( abstract::image_with_dim< N, E > &  output,
const std::string &  name 
) [inline]

Read an image (2 dimensions) from a file.

<

Todo:
FIXME: E or abstract::image_with_dim<N,E> ? E is convenient.

Definition at line 160 of file image_read.hh.

References oln::io::internal::utils::extension().

Referenced by oln::io::internal::pnm_read_data< PnmVectorial, ReadPnmRaw >::read(), oln::io::internal::pnm_read_data< PnmVectorial, ReadPnmPlain >::read(), read(), and read_any().

00161       {
00162         mlc::is_true<N == 2 || N == 3>::ensure();
00163 
00165         typedef try_stream_wrappers_in<StreamAny, E, readers_trier>
00166           stream_trier;
00167 
00168         std::string ext = internal::utils::extension(name);
00169 
00170         if (stream_trier::by_extension(output.exact(), name, ext))
00171           return true;
00172         if (stream_trier::by_data(output.exact(), name))
00173           return true;
00174 
00175         // No valid file found using name directly. Let's try other
00176         // possible filenames based on name.
00177 
00178         std::list<std::string> names;
00179         stream_wrappers_find_files<StreamAny>::doit(names, name);
00180 
00181         for (std::list<std::string>::iterator it = names.begin();
00182              it !=  names.end();
00183              ++it)
00184           {
00185             std::string ext = utils::extension(*it);
00186             if (stream_trier::by_extension(output.exact(), *it, ext))
00187               {
00188                 // std::clog << "[" << name << " found as " << *it << "] "
00189                 //           << std::flush;
00190                 return true;
00191               }
00192           }
00193         for (std::list<std::string>::iterator it = names.begin();
00194              it !=  names.end();
00195              ++it)
00196           if (stream_trier::by_data(output.exact(), *it))
00197             {
00198               // std::clog << "['" << name << "' found as '" << *it << "'] "
00199               //        << std::flush;
00200               return true;
00201             }
00202         // std::clog << "[unable to read '" << name << "'] " << std::endl;
00203         return false;
00204       }

template<typename T>
bool oln::io::internal::read_any ( T &  output,
const std::string &  name 
)

Read from a file.

The specialized read function is called by template specialization.

Definition at line 56 of file base.hh.

References read().

Referenced by oln::io::internal::anything::assign(), and oln::io::load().

00057       {
00058         return read(output, name);
00059       }

bool oln::io::internal::write ( const neighborhood2d &  input,
const std::string &  name 
) [inline]

Write a neighborhood to a file.

Definition at line 97 of file se_neighborhood.hh.

References write().

00098       {
00099         image2d<ntg::bin> im(input.delta()*2+1, input.delta()*2+1);
00100         image2d<ntg::bin>::fwd_iter_type it(im);
00101         for_all (it) im[it] = false;
00102         for (unsigned i = 0; i < input.card(); ++i)
00103           im[point2d(input.delta(),input.delta()) + input.dp(i)] = true;
00104         if (!write(im, name))
00105           return false;
00106         return true;
00107       }

bool oln::io::internal::write ( const window3d &  input,
const std::string &  name 
) [inline]

Write a window (3 dimensions) to a file.

Definition at line 172 of file se_window.hh.

References write().

00173       {
00174         image3d<ntg::bin> im(input.delta()*2+1,
00175                              input.delta()*2+1,
00176                              input.delta()*2+1);
00177         image3d<ntg::bin>::iter_type it(im);
00178         for_all (it) im[it] = true;
00179         for (unsigned i = 0; i < input.card(); ++i)
00180           im[point3d(input.delta(), input.delta(), input.delta())
00181              + input.dp(i)] = false;
00182         if (!write(im, name))
00183           return false;
00184         return true;
00185       }

bool oln::io::internal::write ( const window2d &  input,
const std::string &  name 
) [inline]

Write a window (2 dimensions) to a file.

Definition at line 153 of file se_window.hh.

References write().

00154       {
00155         image2d<ntg::bin> im(input.delta()*2+1, input.delta()*2+1);
00156         image2d<ntg::bin>::fwd_iter_type it(im);
00157         for_all (it) im[it] = true;
00158         for (unsigned i = 0; i < input.card(); ++i)
00159           im[point2d(input.delta(), input.delta()) + input.dp(i)] = false;
00160         if (!write(im, name))
00161           return false;
00162         return true;
00163       }

bool oln::io::internal::write ( const window1d &  input,
const std::string &  name 
) [inline]

Write a window (1 dimension) to a file.

Definition at line 134 of file se_window.hh.

References write().

00135       {
00136         image1d<ntg::bin> im(input.delta()*2+1);
00137         image1d<ntg::bin>::iter_type it(im);
00138         for_all (it) im[it] = true;
00139         for (unsigned i = 0; i < input.card(); ++i)
00140           im[point1d(input.delta()) + input.dp(i)] = false;
00141         if (!write(im, name))
00142           return false;
00143         return true;
00144       }

template<class E>
bool oln::io::internal::write ( const abstract::image_with_dim< 1, E > &  input,
const std::string &  name 
) [inline]

Write an image (1 dimension) to a file.

Definition at line 190 of file image_write.hh.

References write().

00192       {
00193         image2d<oln_value_type(E)> tmp(1, input.ncols());
00194         oln_iter_type(image1d<oln_value_type(E) > ) it(input);
00195         for_all(it)
00196           tmp(0, it.col()) = input[it];
00197         if (!write(tmp, name))
00198           return false;
00199         return true;
00200       }

template<class E, unsigned N>
bool oln::io::internal::write ( const abstract::image_with_dim< N, E > &  input,
const std::string &  name 
) [inline]

Write an image (2 dimensions) to a file.

Definition at line 161 of file image_write.hh.

References oln::io::internal::utils::extension().

Referenced by oln::io::internal::pnm_write_data< PnmVectorial, WritePnmRaw >::write(), oln::io::internal::pnm_write_data< PnmVectorial, WritePnmPlain >::write(), oln::io::internal::pnm_write_data< PnmInteger, WritePnmRaw >::write(), oln::io::internal::pnm_write_data< PnmInteger, WritePnmPlain >::write(), write(), and write_any().

00163       {
00164         mlc::is_true<N == 2 || N == 3>::ensure();
00165 
00166         typedef try_stream_wrappers_out<StreamAny, E, writers_trier>
00167           stream_trier;
00168 
00169         std::string ext = utils::extension(name);
00170 
00171         if (stream_trier::by_extension(input.exact(), name, ext))
00172           return true;
00173         // std::clog << "[unable to write '" << name << "'] " << std::endl;
00174         return false;
00175       }

template<typename T>
bool oln::io::internal::write_any ( const T &  input,
const std::string &  name 
)

Write anything to a file.

The specialized write function is called by template specialization.

Definition at line 68 of file base.hh.

References write().

Referenced by oln::io::save().

00069       {
00070         return write(input, name);
00071       }


Generated on Tue Feb 20 20:27:19 2007 for Olena by  doxygen 1.5.1