contrib/mul/vil3d/vil3d_file_format.cxx

Go to the documentation of this file.
00001 // This is mul/vil3d/vil3d_file_format.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 // \file
00007 // \brief Base for objects capable of reading/writing different image formats.
00008 // \author Tim Cootes - Manchester
00009 
00010 #include "vil3d_file_format.h"
00011 #include <vcl_vector.h>
00012 #include <vil/vil_open.h>
00013 #include <vil3d/file_formats/vil3d_analyze_format.h>
00014 #include <vil3d/file_formats/vil3d_gipl_format.h>
00015 #include <vil3d/file_formats/vil3d_slice_list.h>
00016 
00017 #if 0 // commented out
00018 
00019 #include <vil3d/vil3d_header_data.h>
00020 
00021 //: Read header and image from named file if possible
00022 bool vil3d_file_format::read_file(vil3d_header_data_sptr& header,
00023                                   vil3d_image_view_base_sptr& image,
00024                                   const vcl_string& filename)
00025 {
00026   vil_stream *is = vil_open(filename.c_str(), "r");
00027   if (is) return read_stream(header,image,is);
00028 
00029   vcl_cerr << __FILE__ ": Failed to load [" << filename << "]\n";
00030   return false;
00031 }
00032 
00033     //: Write header and image to named file if possible
00034 bool vil3d_file_format::write_file(vil3d_header_data_sptr& header,
00035                                    vil3d_image_view_base_sptr& image,
00036                                    const vcl_string& filename)
00037 {
00038   vil_stream* os = vil_open(filename.c_str(), "w");
00039   if (!os->ok()) {
00040     vcl_cerr << __FILE__ ": Invalid stream for \"" << filename << "\"\n";
00041     return false;
00042   }
00043 
00044   return write_stream(header,image,os);
00045 }
00046 
00047 #endif // 0
00048 
00049 //: Store list of file_formats in this class to ensure tidy deletion.
00050 class vil3d_file_formats
00051 {
00052  public:
00053   vcl_vector<vil3d_file_format *> v;
00054   vil3d_file_formats()
00055   {
00056     v.push_back(new vil3d_analyze_format);
00057     v.push_back(new vil3d_gipl_format);
00058     v.push_back(new vil3d_slice_list_format);
00059   }
00060   ~vil3d_file_formats()
00061   {
00062     for (unsigned i=0; i<v.size(); ++i)
00063       delete v[i];
00064 
00065     v.clear();
00066   }
00067 };
00068 
00069 static vil3d_file_formats formats_available;
00070 
00071 //: Add a format reader to current list of those available
00072 void vil3d_file_format::add_format(vil3d_file_format* new_format)
00073 {
00074   formats_available.v.push_back(new_format);
00075 }
00076 
00077 //: Number of formats available (number added by add_format()
00078 unsigned vil3d_file_format::n_formats()
00079 {
00080   return formats_available.v.size();
00081 }
00082 
00083 //: Access to available format readers supplied by add_format
00084 const vil3d_file_format& vil3d_file_format::format(unsigned i)
00085 {
00086   return *formats_available.v[i];
00087 }
00088 

Generated on Mon Nov 23 05:15:07 2009 for contrib/mul/vil3d by  doxygen 1.5.1