I've been given a .mat
file (three dimensions, single precision floating point), which I'd like to read using VXL
. VNL
has a few classes/functions for doing this, but I've not found any examples demonstrating their use. I've pieced the following together from the header file, but no data seems to be read in, and when I ask for the dimensions, I get what appears to be uninitialized junk (though some data from the header is read).
#include <vcl_cstdlib.h>
#include <vcl_iostream.h>
#include <vcl_fstream.h>
#include <vnl/vnl_matlab_read.h>
#include <vnl/vnl_vector.h>
int main(int argc, char ** argv)
{
if (2 != argc)
{
std::cerr << "Provide a file." << std::endl;
return EXIT_FAILURE;
}
const char * fileName = argv[1];
vcl_filebuf fileBuffer;
if (!fileBuffer.open(fileName,vcl_ios::in))
{
std::cerr << "There was a problem opening the file." << std::endl;
return EXIT_FAILURE;
}
vcl_istream stream(&fileBuffer);
vnl_matlab_readhdr read(stream);
vcl_cout << read.name() << vcl_endl; // Platform: PCWIN64, Created on: (date and time)
vcl_cout << read.rows() << vcl_endl; // 1094852661
vcl_cout << read.cols() << vcl_endl; // 774905933
vnl_vector<float> data;
vnl_matlab_read_or_die(stream, data, fileName);
std::cout << data.size() << std::endl; // 0
return EXIT_SUCCESS;
}
I can't tell if I'm using the class incorrectly, or if perhaps VNL
can't deal with multidimensional arrays?