Go to the documentation of this file.00001
00002 #ifndef vil3d_meta_image_format_h_
00003 #define vil3d_meta_image_format_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007
00008
00009
00010
00011
00012 #include <vil3d/vil3d_file_format.h>
00013 #include <vil/vil_pixel_format.h>
00014 #include <vcl_iosfwd.h>
00015 #include <vcl_string.h>
00016
00017 class vil3d_meta_image_header
00018 {
00019 public:
00020
00021 vil3d_meta_image_header(void);
00022 ~vil3d_meta_image_header(void);
00023
00024
00025 void set_byte_order_msb(const bool is_msb);
00026 bool byte_order_is_msb(void) const;
00027
00028 void set_offset(const double off_i, const double off_j, const double off_k);
00029 double offset_i(void) const;
00030 double offset_j(void) const;
00031 double offset_k(void) const;
00032
00033 void set_vox_size(const double vox_i, const double vox_j, const double vox_k);
00034 double vox_size_i(void) const;
00035 double vox_size_j(void) const;
00036 double vox_size_k(void) const;
00037
00038 void set_dim_size(const unsigned int ni, const unsigned int nj, const unsigned int nk, const unsigned int np);
00039 unsigned int ni(void) const;
00040 unsigned int nj(void) const;
00041 unsigned int nk(void) const;
00042 unsigned int nplanes(void) const;
00043
00044 void set_element_type(const vcl_string &elem_type);
00045 const vcl_string &element_type(void) const;
00046
00047 void set_image_fname(const vcl_string &image_fname);
00048 const vcl_string &image_fname(void) const;
00049
00050 void set_pixel_format(const vil_pixel_format format);
00051 vil_pixel_format pixel_format(void) const;
00052
00053 void clear(void);
00054
00055
00056 bool read_header(const vcl_string &header_fname);
00057 bool write_header(const vcl_string &header_fname) const;
00058
00059
00060 void print_header(vcl_ostream &os) const;
00061
00062
00063 void check_need_swap(void);
00064 bool need_swap(void) const;
00065
00066 private:
00067
00068
00069 bool check_next_header_line(const vcl_string &nxt_line);
00070 vcl_string get_header_value(const vcl_string &nxt_line);
00071 bool set_header_offset(const vcl_string &offs);
00072 bool set_header_dim_size(const vcl_string &dims);
00073 bool set_header_voxel_size(const vcl_string &vsize);
00074
00075
00076 bool header_valid_;
00077
00078
00079 bool byte_order_msb_;
00080 double offset_i_, offset_j_, offset_k_;
00081 double vox_size_i_, vox_size_j_, vox_size_k_;
00082 unsigned int dim_size_i_, dim_size_j_, dim_size_k_;
00083 unsigned int nplanes_;
00084 vcl_string elem_type_;
00085 vcl_string im_file_;
00086
00087
00088
00089 vil_pixel_format pformat_;
00090
00091
00092 bool need_swap_;
00093 };
00094
00095
00096 vcl_ostream& operator<<(vcl_ostream &os, const vil3d_meta_image_header &header);
00097
00098
00099 class vil3d_meta_image_format : public vil3d_file_format
00100 {
00101 public:
00102 vil3d_meta_image_format();
00103
00104 virtual ~vil3d_meta_image_format();
00105
00106 virtual vil3d_image_resource_sptr make_input_image(const char *) const;
00107
00108
00109
00110 virtual vil3d_image_resource_sptr make_output_image(const char* filename,
00111 unsigned ni,
00112 unsigned nj,
00113 unsigned nk,
00114 unsigned nplanes,
00115 vil_pixel_format format) const;
00116
00117
00118 virtual const char * tag() const {return "mhd";}
00119 };
00120
00121
00122
00123 class vil3d_meta_image: public vil3d_image_resource
00124 {
00125 private:
00126 vil3d_meta_image_header header_;
00127 vcl_string fpath_;
00128
00129
00130 bool write_image();
00131
00132 public:
00133 vil3d_meta_image(const vil3d_meta_image_header &header,
00134 const vcl_string &fname);
00135
00136 virtual ~vil3d_meta_image();
00137
00138
00139
00140 virtual unsigned nplanes() const;
00141
00142
00143 virtual unsigned ni() const;
00144
00145
00146 virtual unsigned nj() const;
00147
00148
00149 virtual unsigned nk() const;
00150
00151
00152 const vil3d_meta_image_header &header(void) const;
00153
00154
00155 virtual enum vil_pixel_format pixel_format() const;
00156
00157
00158
00159
00160 virtual bool set_voxel_size(float,float,float);
00161
00162
00163
00164 void set_offset(const double i, const double j, const double k,
00165 const double vx_i, const double vx_j, const double vx_k);
00166
00167
00168
00169
00170
00171 virtual vil3d_image_view_base_sptr get_copy_view(unsigned i0, unsigned ni,
00172 unsigned j0, unsigned nj,
00173 unsigned k0, unsigned nk) const;
00174
00175
00176
00177
00178
00179
00180
00181 virtual bool put_view(const vil3d_image_view_base& im,
00182 unsigned i0, unsigned j0, unsigned k0);
00183
00184
00185
00186 virtual char const* file_format() const { return "meta_image"; }
00187
00188
00189
00190 virtual bool get_property(char const* label, void* property_value = 0) const;
00191 };
00192
00193 #endif