Go to the documentation of this file.00001 
00002 #ifndef vil3d_analyze_format_h_
00003 #define vil3d_analyze_format_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 
00008 
00009 
00010 
00011 
00012 
00013 #include <vcl_iosfwd.h>
00014 #include <vil3d/vil3d_file_format.h>
00015 
00016 
00017 class vil3d_analyze_header
00018 {
00019  public :
00020   
00021   class Key
00022   {
00023    public :
00024     int sizeof_hdr;
00025     char data_type[10];
00026     char db_name[18];
00027     int extents;
00028     short int session_error;
00029     char regular;
00030     char hkey_un0;
00031 
00032     Key() { reset(); }
00033     ~Key() {}
00034 
00035     void reset();
00036   };
00037 
00038   
00039   class Dimensions
00040   {
00041    public :
00042     short int dim[8];
00043     short int unused8;
00044     short int unused9;
00045     short int unused10;
00046     short int unused11;
00047     short int unused12;
00048     short int unused13;
00049     short int unused14;
00050     short int datatype;
00051     short int bitpix;
00052     short int dim_un0;
00053     float pixdim[8];
00054     float funused8;
00055     float funused9;
00056     float funused10;
00057     float funused11;
00058     float funused12;
00059     float funused13;
00060     float compressed;
00061     float verified;
00062     int glmax;
00063     int glmin;
00064 
00065     Dimensions() { reset(); }
00066     ~Dimensions() {}
00067 
00068     void reset();
00069   };
00070 
00071   
00072   class History
00073   {
00074    public :
00075     char descrip[80];
00076     char aux_file[24];
00077     char orient;
00078     char originator[10];
00079     char generated[10];
00080     char scannum[10];
00081     char patient_id[10];
00082     char exp_date[10];
00083     char exp_time[10];
00084     char hist_un0[3];
00085     int views;
00086     int vols_added;
00087     int start_field;
00088     int field_skip;
00089     int omax;
00090     int omin;
00091     int smax;
00092     int smin;
00093 
00094     History() { reset(); }
00095     ~History() {}
00096 
00097     void reset();
00098   };
00099 
00100   Key        key;
00101   Dimensions dim;
00102   History    history;
00103 
00104  private:
00105   bool swap_bytes_; 
00106 
00107  public:
00108   vil3d_analyze_header() : swap_bytes_(false) {}
00109   ~vil3d_analyze_header() {}
00110 
00111   void reset();
00112 
00113   
00114   enum vil_pixel_format pixel_format() const;
00115 
00116   
00117   void set_pixel_format(enum vil_pixel_format format);
00118 
00119   
00120   void set_image_size(unsigned ni, unsigned nj, unsigned nk, unsigned np=1);
00121 
00122   short int ni() const { return dim.dim[1]; }
00123   short int nj() const { return dim.dim[2]; }
00124   short int nk() const { return dim.dim[3]; }
00125 
00126   
00127   short int nplanes() const { return dim.dim[4]; }
00128 
00129   float voxel_width_i() const { return dim.pixdim[1]; }
00130   float voxel_width_j() const { return dim.pixdim[2]; }
00131   float voxel_width_k() const { return dim.pixdim[3]; }
00132 
00133   
00134   void set_voxel_size(float si, float sj, float sk);
00135 
00136   
00137   bool read_file(const vcl_string& path);
00138 
00139   
00140   bool write_file(const vcl_string& path) const;
00141 
00142   void swapBytes(char *data, int size);
00143   bool needSwap() const { return swap_bytes_; }
00144 
00145   
00146   void print_summary(vcl_ostream& os) const;
00147 };
00148 
00149 
00150 vcl_ostream& operator<<(vcl_ostream& os, const vil3d_analyze_header&);
00151 
00152 
00153 class vil3d_analyze_format : public vil3d_file_format
00154 {
00155  public:
00156   vil3d_analyze_format();
00157   
00158   virtual ~vil3d_analyze_format();
00159 
00160   virtual vil3d_image_resource_sptr make_input_image(const char *) const;
00161 
00162   
00163   
00164   virtual vil3d_image_resource_sptr make_output_image(const char* filename,
00165                                                       unsigned ni,
00166                                                       unsigned nj,
00167                                                       unsigned nk,
00168                                                       unsigned nplanes,
00169                                                       enum vil_pixel_format) const;
00170 
00171 
00172   
00173   virtual const char * tag() const {return "hdr";}
00174 };
00175 
00176 
00177 
00178 
00179 class vil3d_analyze_image: public vil3d_image_resource
00180 {
00181   
00182   vcl_string base_path_;
00183 
00184   
00185   vil3d_analyze_header header_;
00186 
00187   
00188   unsigned nplanes_;
00189 
00190   
00191   float vox_width1_, vox_width2_, vox_width3_;
00192 
00193  public:
00194   
00195   
00196   
00197   vil3d_analyze_image(const vil3d_analyze_header& header,
00198                       const vcl_string& base_path);
00199 
00200   virtual ~vil3d_analyze_image();
00201 
00202   
00203   
00204   virtual unsigned nplanes() const;
00205   
00206   
00207   virtual unsigned ni() const;
00208   
00209   
00210   virtual unsigned nj() const;
00211   
00212   
00213   virtual unsigned nk() const;
00214 
00215   
00216   const vcl_string& base_path() const { return base_path_; }
00217 
00218   
00219   const vil3d_analyze_header& header() { return header_; }
00220 
00221   
00222   virtual enum vil_pixel_format pixel_format() const;
00223 
00224 
00225   
00226   
00227   
00228   
00229   virtual vil3d_image_view_base_sptr get_copy_view(unsigned i0, unsigned ni,
00230                                                    unsigned j0, unsigned nj,
00231                                                    unsigned k0, unsigned nk) const;
00232 
00233   
00234   
00235   
00236   
00237   
00238   
00239   virtual bool put_view(const vil3d_image_view_base& im,
00240                         unsigned i0, unsigned j0, unsigned k0);
00241 
00242   
00243   
00244   
00245   virtual bool set_voxel_size(float,float,float);
00246 
00247   
00248   
00249   virtual char const* file_format() const { return "analyze"; }
00250 
00251   
00252   
00253   virtual bool get_property(char const* label, void* property_value = 0) const;
00254 };
00255 
00256 #endif