• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

load.hh

00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
00002 //
00003 // This file is part of Olena.
00004 //
00005 // Olena is free software: you can redistribute it and/or modify it under
00006 // the terms of the GNU General Public License as published by the Free
00007 // Software Foundation, version 2 of the License.
00008 //
00009 // Olena is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Olena.  If not, see <http://www.gnu.org/licenses/>.
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software project without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to produce
00021 // an executable, this file does not by itself cause the resulting
00022 // executable to be covered by the GNU General Public License.  This
00023 // exception does not however invalidate any other reasons why the
00024 // executable file might be covered by the GNU General Public License.
00025 
00026 #ifndef MLN_IO_FITS_LOAD_HH
00027 # define MLN_IO_FITS_LOAD_HH
00028 
00033 
00034 # include <iostream>
00035 # include <fstream>
00036 # include <string>
00037 
00038 # include <mln/core/image/image2d.hh>
00039 # include <mln/value/int_u8.hh>
00040 
00041 # include <fitsio.h>
00042 
00043 
00044 namespace mln
00045 {
00046 
00047   namespace io
00048   {
00049 
00050 
00051     namespace fits
00052     {
00053 
00060       void load(image2d<float>& ima,
00061                 const std::string& filename);
00062 
00069       image2d<float> load(const std::string& filename);
00070 
00071 # ifndef MLN_INCLUDE_ONLY
00072 
00073       inline
00074       void fits_exit(int status)
00075       {
00076         if (status)
00077         {
00078           fits_report_error(stderr, status);
00079           exit(status);
00080         }
00081         return;
00082       }
00083 
00084       inline
00085       image2d<float> load(const std::string& filename)
00086       {
00087         trace::entering("mln::io::fits::load");
00088 
00089         fitsfile *fptr;
00090         int status,  nfound, anynull;
00091         long naxes[2];
00092         float nullval;
00093 
00094         status = 0;
00095         if (fits_open_file(&fptr, filename.c_str(), READONLY, &status))
00096           fits_exit(status);
00097 
00098         char NAXIS[] = "NAXIS";
00099         if (fits_read_keys_lng(fptr, NAXIS, 1, 2, naxes, &nfound, &status))
00100           fits_exit(status);
00101 
00102         const int ncols = naxes[0], nrows = naxes[1];
00103 
00104         image2d<float> output(nrows, ncols);
00105 
00106         nullval  = 0; // don't check null values
00107 
00108         point2d p(point2d(0, 0));
00109 
00110         for (p.row() = 0; p.row() < nrows; ++p.row())
00111         {
00112           if (fits_read_img(fptr,
00113                             TFLOAT,
00114                             1 + p.row() * ncols,
00115                             ncols,
00116                             &nullval,
00117                             &(output(p)),
00118                             &anynull,
00119                             &status))
00120             fits_exit(status);
00121         }
00122 
00123         if (fits_close_file(fptr, &status))
00124           fits_exit(status);
00125 
00126         trace::exiting("mln::io::fits::load");
00127 
00128         return output;
00129       }
00130 
00131       inline
00132       void load(image2d<float>& ima,
00133                 const std::string& filename)
00134       {
00135         ima = load(filename);
00136       }
00137 
00138 # endif // ! MLN_INCLUDE_ONLY
00139 
00140     } // end of namespace mln::io::fits
00141 
00142   } // end of namespace mln::io
00143 
00144 } // end of namespace mln
00145 
00146 
00147 #endif // ! MLN_IO_FITS_LOAD_HH

Generated on Tue Oct 4 2011 15:24:02 for Milena (Olena) by  doxygen 1.7.1