Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

vnl_matlab_read.h

Go to the documentation of this file.
00001 #ifndef vnl_matlab_read_h_
00002 #define vnl_matlab_read_h_
00003 // This is vxl/vnl/vnl_matlab_read.h
00004 
00005 //: \file
00006 // \brief Read from MATLAB files 
00007 // \author fsm@robots.ox.ac.uk
00008 
00009 // Modifications
00010 // LSB (Manchester) 23/3/01 documentation tidied
00011 
00012 #include <vcl_iosfwd.h>
00013 #include <vcl_complex_fwd.h>
00014 #include <vnl/vnl_matlab_header.h>
00015 
00016 // ------------------------------ easy ------------------------------
00017 
00018 template <class T> class vnl_vector;
00019 template <class T> class vnl_matrix;
00020 
00021 //: Attempt to read vector or matrix. If the MATLAB header cannot be
00022 // read, return false. Else, if a name is given, and it doesn't 
00023 // match what's in the file, abort(). If the data in the file cannot 
00024 // reasonably be read into the destination, abort().
00025 //
00026 // The vector/matrix will be resized if necessary.
00027 template <class T> bool vnl_matlab_read_or_die(vcl_istream &, vnl_vector<T> &, char const *name =0);
00028 template <class T> bool vnl_matlab_read_or_die(vcl_istream &, vnl_matrix<T> &, char const *name =0);
00029 
00030 // ------------------------------ less easy ------------------------------
00031 
00032 //: MATLAB stores its data as a real block followed by an imaginary block.
00033 // This function will read both blocks and interleave them into the area
00034 // pointed to by ptr. For real T, it is equivalent to s.read(ptr, sizeof(T)*n);
00035 template <class T> void vnl_matlab_read_data(vcl_istream &s, T *ptr, unsigned n);
00036 
00037 class vnl_matlab_readhdr {
00038 public:
00039   vnl_matlab_readhdr(vcl_istream &);
00040   ~vnl_matlab_readhdr();
00041 
00042   operator bool () const;
00043   void read_next(); // skip to next header in file
00044   
00045   bool is_single() const;
00046   bool is_rowwise() const;
00047   bool is_bigendian() const; // don't use this
00048   long rows() const { return hdr.rows; }
00049   long cols() const { return hdr.cols; }
00050   bool is_complex() const { return hdr.imag != 0; }
00051   char const *name() const { return varname; }
00052 
00053   // bah! no member templates
00054   //template <class T> bool read_data(T &); // scalar
00055   //template <class T> bool read_data(T *); // vector
00056   //template <class T> bool read_data(T * const *); // 2D array
00057 #define fsm_declare_methods(T) \
00058 private: \
00059   bool type_chck(T &); \
00060 public: \
00061   bool read_data(T &); \
00062   bool read_data(T *); \
00063   bool read_data(T * const *) // no ; here, please. SunPro 5.0 barfs.
00064 fsm_declare_methods(float);
00065 fsm_declare_methods(double);
00066 fsm_declare_methods(vcl_complex<float>);
00067 fsm_declare_methods(vcl_complex<double>);
00068 #undef fsm_declare_methods
00069   
00070 private:
00071   vcl_istream &s;
00072   vnl_matlab_header hdr;
00073   char *varname;
00074   bool data_read;
00075 
00076   void read_hdr(); // internal work routine
00077 };
00078 
00079 #endif // vnl_matlab_read_h_

Generated at Wed Mar 12 01:13:15 2003 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000