contrib/mul/vil3d/file_formats/vil3d_slice_list.h
Go to the documentation of this file.
00001 #ifndef vil3d_slice_list_h_
00002 #define vil3d_slice_list_h_
00003 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00004 #pragma interface
00005 #endif
00006 //:
00007 // \file
00008 // \brief Interface/base for a volume made up of slices.
00009 // \author Ian Scott - Manchester
00010 
00011 #include <vcl_vector.h>
00012 #include <vil3d/vil3d_file_format.h>
00013 #include <vil3d/vil3d_image_resource.h>
00014 #include <vil/vil_image_resource.h>
00015 
00016 //: Format class for a volume made up of a list of images.
00017 // The filename format can be a list of ';' delimited filenames.
00018 // It can also be single filename where '#' represents a numeric character.
00019 // A set of image files with contiguous numbering will be loaded, starting
00020 // with the lowest number.
00021 //
00022 // The first 2D image to be loaded is the k=0 slice in the image, etc.
00023 class vil3d_slice_list_format : public vil3d_file_format
00024 {
00025  public:
00026   vil3d_slice_list_format();
00027   virtual ~vil3d_slice_list_format();
00028 
00029   virtual vil3d_image_resource_sptr make_input_image(const char *) const;
00030 
00031   //: Make a "generic_image" on which put_section may be applied.
00032   // The file may be opened immediately for writing so that a header can be written.
00033   virtual vil3d_image_resource_sptr make_output_image(const char* filename,
00034                                                       unsigned ni,
00035                                                       unsigned nj,
00036                                                       unsigned nk,
00037                                                       unsigned nplanes,
00038                                                       enum vil_pixel_format)const;
00039 
00040   //: default filename tag for this image.
00041   virtual const char * tag() const {return "slice_list";}
00042 };
00043 
00044 
00045 //: Create a volume from a list of matching 2D slices.
00046 // If the slices do not match (in size, type etc) a null ptr will
00047 // be returned.
00048 vil3d_image_resource_sptr
00049 vil3d_slice_list_to_volume(const vcl_vector<vil_image_resource_sptr> &);
00050 
00051 //: Format class for a volume made up of a list of images.
00052 // You can't create one of these yourself.
00053 // Use vil3d_slice_list_format or vil3d_slice_list_to_volume instead.
00054 class vil3d_slice_list_image: public vil3d_image_resource
00055 {
00056   //: All the 2d image slice resources that make up this volume
00057   vcl_vector<vil_image_resource_sptr> slices_;
00058 
00059   friend vil3d_image_resource_sptr
00060     vil3d_slice_list_to_volume(const vcl_vector<vil_image_resource_sptr> &);
00061   friend class vil3d_slice_list_format;
00062 
00063  protected:
00064   vil3d_slice_list_image(const vcl_vector<vil_image_resource_sptr>&);
00065 
00066  public:
00067   virtual ~vil3d_slice_list_image();
00068 
00069   //: Dimensions:  nplanes x ni x nj x nk.
00070   // This concept is treated as a synonym to components.
00071   virtual unsigned nplanes() const;
00072   //: Dimensions:  nplanes x ni x nj x nk.
00073   // The number of pixels in each row.
00074   virtual unsigned ni() const;
00075   //: Dimensions:  nplanes x ni x nj x nk.
00076   // The number of pixels in each column.
00077   virtual unsigned nj() const;
00078   //: Dimensions:  nplanes x ni x nj x nk.
00079   // The number of slices per image.
00080   virtual unsigned nk() const;
00081 
00082   //: Pixel Format.
00083   virtual enum vil_pixel_format pixel_format() const;
00084 
00085 
00086   //: Create a read/write view of a copy of this data.
00087   // This function will always return a
00088   // multi-plane scalar-pixel view of the data.
00089   // \return 0 if unable to get view of correct size, or if resource is write-only.
00090   virtual vil3d_image_view_base_sptr get_copy_view(unsigned i0, unsigned ni,
00091                                                    unsigned j0, unsigned nj,
00092                                                    unsigned k0, unsigned nk) const;
00093 
00094   //: Put the data in this view back into the image source.
00095   // The view must be of scalar components. Assign your
00096   // view to a scalar-component view if this is not the case.
00097   // \return false if failed, because e.g. resource is read-only,
00098   // format of view is not correct (if it is a compound pixel type, try
00099   // assigning it to a multi-plane scalar pixel view.)
00100   virtual bool put_view(const vil3d_image_view_base& im,
00101                         unsigned i0, unsigned j0, unsigned k0);
00102 
00103   //: Return a string describing the file format.
00104   // Only file images have a format, others return 0
00105   virtual char const* file_format() const { return "slice_list"; }
00106 
00107   //: Extra property information
00108   // This will just return the property of the first slice in the list.
00109   virtual bool get_property(char const* tag, void* property_value = 0) const;
00110 };
00111 
00112 #endif // vil3d_slice_list_h_