contrib/mul/vil3d/file_formats/vil3d_gipl_format.h
Go to the documentation of this file.
00001 // This is mul/vil3d/file_formats/vil3d_gipl_format.h
00002 #ifndef vil3d_gipl_format_h_
00003 #define vil3d_gipl_format_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Reader/Writer for GIPL format images.
00010 // \author Tim Cootes - Manchester
00011 
00012 #include <vil3d/vil3d_file_format.h>
00013 #include <vil/vil_stream.h>
00014 
00015 
00016 //: Reader/Writer for GIPL format images.
00017 class vil3d_gipl_format : public vil3d_file_format
00018 {
00019  public:
00020   vil3d_gipl_format();
00021   //: The destructor must be virtual so that the memory chunk is destroyed.
00022   virtual ~vil3d_gipl_format();
00023 
00024   virtual vil3d_image_resource_sptr make_input_image(const char *) const;
00025 
00026   //: Make a "generic_image" on which put_section may be applied.
00027   // The file may be opened immediately for writing so that a header can be written.
00028   virtual vil3d_image_resource_sptr make_output_image(const char* filename,
00029                                                       unsigned ni,
00030                                                       unsigned nj,
00031                                                       unsigned nk,
00032                                                       unsigned nplanes,
00033                                                       enum vil_pixel_format) const;
00034 
00035 
00036   //: default filename tag for this image.
00037   virtual const char * tag() const {return "gipl";}
00038 };
00039 
00040 // You can't create one of these yourself.
00041 // Use vil3d_gipl_format instead.
00042 class vil3d_gipl_image: public vil3d_image_resource
00043 {
00044   vil_smart_ptr<vil_stream> is_;
00045 
00046   //: output stream
00047   vil_smart_ptr<vil_stream> os_;
00048 
00049   //: image dimensions
00050   unsigned dim1_, dim2_, dim3_;
00051 
00052   //: number of planes
00053   unsigned nplanes_;
00054 
00055   //: Physical Voxel dimensions ( in mm )
00056   float vox_width1_, vox_width2_, vox_width3_;
00057 
00058   bool read_header(vil_stream *is);
00059   bool write_header(void);
00060 
00061   //: Expected pixel type.
00062   enum vil_pixel_format pixel_format_;
00063 
00064   //: Orientation of the image
00065   char orientation_flag_;
00066 
00067   //: Minimum and maximum voxel values in the image
00068   double min_val_, max_val_;
00069 
00070   //: X, Y, Z and T offset
00071   double origin1_, origin2_, origin3_;
00072 
00073   float interslice_gap_;
00074 
00075   vil_streampos start_of_data_;
00076 
00077  public:
00078   vil3d_gipl_image(vil_stream* os, unsigned);
00079   vil3d_gipl_image(vil_stream *);
00080 
00081 #if 0
00082   vil3d_gipl_image(vil_stream* os,
00083                    unsigned ni,
00084                    unsigned nj,
00085                    unsigned nk,
00086                    unsigned nplanes,
00087                    enum vil_pixel_format);
00088 #endif // 0
00089 
00090  vil3d_gipl_image(vil_stream* os,
00091     unsigned ni,
00092     unsigned nj,
00093     unsigned nk,
00094     unsigned nplanes,
00095     enum vil_pixel_format format,
00096     float vox_width1=1.0,
00097     float vox_width2=1.0,
00098     float vox_width3=1.0,
00099     char orientation_flag=0, //GIPL_UNDEFINED_ORIENTATION
00100     double min_val=0.0,
00101     double max_val=0.0,
00102     double origin1=0.0,
00103     double origin2=0.0,
00104     double origin3=0.0,
00105     float interslice_gap=0.0
00106     );
00107 
00108   virtual ~vil3d_gipl_image();
00109 
00110   //: Dimensions:  nplanes x ni x nj x nk.
00111   // This concept is treated as a synonym to components.
00112   virtual unsigned nplanes() const;
00113   //: Dimensions:  nplanes x ni x nj x nk.
00114   // The number of pixels in each row.
00115   virtual unsigned ni() const;
00116   //: Dimensions:  nplanes x ni x nj x nk.
00117   // The number of pixels in each column.
00118   virtual unsigned nj() const;
00119   //: Dimensions:  nplanes x ni x nj x nk.
00120   // The number of slices per image.
00121   virtual unsigned nk() const;
00122 
00123   //: Pixel Format.
00124   virtual enum vil_pixel_format pixel_format() const;
00125 
00126   //: Set the size of the each voxel in the i,j,k directions.
00127   // You can get the voxel sizes via get_properties().
00128   // \return false if underlying image doesn't store pixel sizes.
00129   virtual bool set_voxel_size(float/*i*/,float/*j*/,float/*k*/);
00130 
00131   //: Create a read/write view of a copy of this data.
00132   // This function will always return a
00133   // multi-plane scalar-pixel view of the data.
00134   // \return 0 if unable to get view of correct size, or if resource is write-only.
00135   virtual vil3d_image_view_base_sptr get_copy_view(unsigned i0, unsigned ni,
00136                                                    unsigned j0, unsigned nj,
00137                                                    unsigned k0, unsigned nk) const;
00138 
00139   //: Put the data in this view back into the image source.
00140   // The view must be of scalar components. Assign your
00141   // view to a scalar-component view if this is not the case.
00142   // \return false if failed, because e.g. resource is read-only,
00143   // format of view is not correct (if it is a compound pixel type, try
00144   // assigning it to a multi-plane scalar pixel view.)
00145   virtual bool put_view(const vil3d_image_view_base& im,
00146                         unsigned i0, unsigned j0, unsigned k0);
00147 
00148   //: Return a string describing the file format.
00149   // Only file images have a format, others return 0
00150   virtual char const* file_format() const { return "gipl"; }
00151 
00152   //: Extra property information
00153   // This will just return the property of the first slice in the list.
00154   virtual bool get_property(char const* label, void* property_value = 0) const;
00155 #if 0
00156   bool put_view(const vil3d_image_view_base& im,
00157                         unsigned i0=0, unsigned j0=0, unsigned k0=0);
00158 #endif // 0
00159 };
00160 
00161 #endif