contrib/mul/vil3d/file_formats/vil3d_gen_synthetic.h
Go to the documentation of this file.
00001 // This is mul/vil3d/file_formats/vil3d_gen_synthetic.h
00002 #ifndef vil3d_gen_synthetic_h_
00003 #define vil3d_gen_synthetic_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Reader for simple synthetic images generated on the fly.
00010 // \author Ian Scott - Manchester
00011 
00012 #include <vil3d/vil3d_file_format.h>
00013 
00014 //: Reader for generated synthetic images.
00015 // To get a 10x10x20 vxl_byte image set to 128, you would specify a filename
00016 // of "gen:10x10x20:vxl_byte:128"
00017 // \note This format is not used by vil3d automatically. If
00018 // you want to use it in your application,
00019 // call \code{vil3d_file_format::add_format(new vil3d_gen_synthetic_format)};
00020 
00021 class vil3d_gen_synthetic_format : public vil3d_file_format
00022 {
00023  public:
00024   vil3d_gen_synthetic_format() {}
00025   //: The destructor must be virtual so that the memory chunk is destroyed.
00026   virtual ~vil3d_gen_synthetic_format() {}
00027 
00028   virtual vil3d_image_resource_sptr make_input_image(const char *) const;
00029 
00030   //: Make a "generic_image" on which put_section may be applied.
00031   // The file may be opened immediately for writing so that a header can be written.
00032   virtual vil3d_image_resource_sptr make_output_image(const char* filename,
00033                                                       unsigned ni,
00034                                                       unsigned nj,
00035                                                       unsigned nk,
00036                                                       unsigned nplanes,
00037                                                       enum vil_pixel_format) const;
00038 
00039 
00040   //: default filename tag for this image.
00041   virtual const char * tag() const {return "gen";}
00042 };
00043 
00044 //: Implementation class - not for public use.
00045 union vil3d_gen_synthetic_pixel_value
00046 {
00047   vxl_uint_32 uint_32_value;
00048   vxl_int_32 int_32_value;
00049   vxl_uint_16 uint_16_value;
00050   vxl_int_16 int_16_value;
00051   vxl_byte byte_value;
00052   vxl_sbyte sbyte_value;
00053   float float_value;
00054   double double_value;
00055   bool bool_value;
00056 };
00057 
00058 // You can't create one of these yourself.
00059 // Use vil3d_gen_synthetic_format instead.
00060 class vil3d_gen_synthetic_image: public vil3d_image_resource
00061 {
00062   //: image dimensions
00063   unsigned ni_, nj_, nk_;
00064 
00065   //: Pixel type.
00066   enum vil_pixel_format format_;
00067 
00068   //: Pixel value.
00069   vil3d_gen_synthetic_pixel_value value_;
00070 
00071  public:
00072   vil3d_gen_synthetic_image(
00073     unsigned ni,
00074     unsigned nj,
00075     unsigned nk,
00076     enum vil_pixel_format format,
00077     vil3d_gen_synthetic_pixel_value pv);
00078 
00079   virtual ~vil3d_gen_synthetic_image() {}
00080 
00081   //: Dimensions:  nplanes x ni x nj x nk.
00082   // This concept is treated as a synonym to components.
00083   virtual unsigned nplanes() const;
00084   //: Dimensions:  nplanes x ni x nj x nk.
00085   // The number of pixels in each row.
00086   virtual unsigned ni() const;
00087   //: Dimensions:  nplanes x ni x nj x nk.
00088   // The number of pixels in each column.
00089   virtual unsigned nj() const;
00090   //: Dimensions:  nplanes x ni x nj x nk.
00091   // The number of slices per image.
00092   virtual unsigned nk() const;
00093 
00094   //: Pixel Format.
00095   virtual enum vil_pixel_format pixel_format() const;
00096 
00097 
00098   //: Create a read/write view of a copy of this data.
00099   // This function will always return a
00100   // multi-plane scalar-pixel view of the data.
00101   // \return 0 if unable to get view of correct size, or if resource is write-only.
00102   virtual vil3d_image_view_base_sptr get_copy_view(unsigned i0, unsigned ni,
00103                                                    unsigned j0, unsigned nj,
00104                                                    unsigned k0, unsigned nk) const;
00105 
00106   //: Put the data in this view back into the image source.
00107   // The view must be of scalar components. Assign your
00108   // view to a scalar-component view if this is not the case.
00109   // \return false if failed, because e.g. resource is read-only,
00110   // format of view is not correct (if it is a compound pixel type, try
00111   // assigning it to a multi-plane scalar pixel view.)
00112   virtual bool put_view(const vil3d_image_view_base& im,
00113                         unsigned i0, unsigned j0, unsigned k0);
00114 
00115   //: Return a string describing the file format.
00116   // Only file images have a format, others return 0
00117   virtual char const* file_format() const { return "gen"; }
00118 
00119   //: Extra property information
00120   // This will just return the property of the first slice in the list.
00121   virtual bool get_property(char const* label, void* property_value = 0) const;
00122 };
00123 
00124 #endif