Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ImagePackage.hh
1 #ifndef __IMAGEPACKAGE_HH__
2 #define __IMAGEPACKAGE_HH__
3 
4 #include <bias_config.h>
5 
6 #include <Base/Image/Image.hh>
7 #include <Base/Image/ImageConvert.hh>
8 #include <Base/Image/ImageIO.hh>
9 #include <Image/Camera.hh>
10 #include <Utils/IOUtils.hh>
11 #include <Image/BackwardMapping.hh>
12 #include <Image/ProjectionMapping.hh>
13 
14 namespace BIAS {
15 
16  /**
17  * An Image Package is multiple .mip images in one file. This class has methods for reading and writing.
18  * @author fkellner, 2008
19  */
20  class BIASImage_EXPORT ImagePackage {
21  public:
22 
23  class BIASImage_EXPORT IPImageHeader {
24  public:
25  unsigned int len_filename;
26  unsigned int len_metadata;
27  unsigned int len_pixeldata;
28  friend BIASImage_EXPORT std::ostream& operator<<(std::ostream& os, const IPImageHeader &ipih) {
29  os.write(reinterpret_cast<const char*>(&(ipih.len_filename)), sizeof(unsigned int));
30  os.write(reinterpret_cast<const char*>(&(ipih.len_metadata)), sizeof(unsigned int));
31  os.write(reinterpret_cast<const char*>(&(ipih.len_pixeldata)), sizeof(unsigned int));
32  return os;
33  }
34  friend BIASImage_EXPORT std::istream& operator>>(std::istream& is, IPImageHeader& ipih) {
35  is.read((char*)&(ipih.len_filename), sizeof(unsigned int));
36  is.read((char*)&(ipih.len_metadata), sizeof(unsigned int));
37  is.read((char*)&(ipih.len_pixeldata), sizeof(unsigned int));
38  return is;
39  }
40  };
41 
42  struct IPFileInfo {
43  unsigned char fileNum;
44  unsigned long int offset;
45  std::string fileName;
46  };
47 
48  /**
49  * An Image Package is much like an uncompressed zip file of mip images. The Package files are split at 1GB, where
50  * the files are named Images0001.pack, Images0002.pack etc. Each image inside a package can have its own filename, so
51  * writing the files to disk is made easy. Images in a package can be of any mixed size, storage type, but will always
52  * be saved uncompressed.
53  */
54  ImagePackage();
55 
56  ~ImagePackage();
57 
58  /**
59  * Create image Package file
60  * @param num used for numbering of .pack files, only used internally.
61  */
62  int Create(const std::string filename, unsigned int num=1);
63 
64  /**
65  * Adding an image with empty filename will use default name
66  */
67  int AddImage(const ImageBase image, const std::string filename="");
68 
69  /** open a package
70  * @return 0 on success
71  */
72  int Open(const std::string filename);
73 
74  /** get image by given index number
75  * @return 0 on success
76  */
77  int GetImage(const int imageNum, ImageBase &image, std::string &filename);
78 
79  /** get next image, call subsequently to walk through package file
80  * @return 0 if image exists
81  */
82  int GetNextImage(ImageBase &image, std::string &filename);
83 
84  /** get previous image, call subsequently to walk through package file
85  * @return 0 if image exists
86  */
87  int GetPrevImage(ImageBase &image, std::string &filename);
88 
89  /**
90  * helper to write image with index imageNum, empty filename will use the one stored in package file
91  */
92  int WriteSingleImage(const unsigned int imageNum, const std::string filename="");
93 
94  /**
95  * write all Images from the package. filename can be used to overwrite the ones from the package file (numbers will be added)
96  */
97  int WriteAllImages(const std::string filename="");
98 
99  /**
100  * close package
101  */
102  int Close();
103 
104  bool IsOpen() {
105  return bOpen_;
106  }
107 
108  private:
109 
110  int currentImg_;
111  int currentFile_;
112  unsigned int numImages_;
113  unsigned int fileNum_;
114  std::string filename_;
115  bool bOpen_;
116  bool bReadMode_;
117 
118  std::vector<std::ifstream*> ifs_;
119  std::ofstream ofs_;
120 
121  std::vector<IPFileInfo> fileInfos_;
122 
123 
124  };
125 
126 } // namespace
127 
128 #endif // __IMAGEPACKAGE_H_
An Image Package is multiple .mip images in one file.
Definition: ImagePackage.hh:20
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
friend BIASImage_EXPORT std::istream & operator>>(std::istream &is, IPImageHeader &ipih)
Definition: ImagePackage.hh:34
friend BIASImage_EXPORT std::ostream & operator<<(std::ostream &os, const IPImageHeader &ipih)
Definition: ImagePackage.hh:28