ome-files  0.1.1
OMETIFFWriter.h
1 /*
2  * #%L
3  * OME-FILES C++ library for image IO.
4  * Copyright © 2006 - 2014 Open Microscopy Environment:
5  * - Massachusetts Institute of Technology
6  * - National Institutes of Health
7  * - University of Dundee
8  * - Board of Regents of the University of Wisconsin-Madison
9  * - Glencoe Software, Inc.
10  * %%
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions are met:
13  *
14  * 1. Redistributions of source code must retain the above copyright notice,
15  * this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright notice,
17  * this list of conditions and the following disclaimer in the documentation
18  * and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  * The views and conclusions contained in the software and documentation are
33  * those of the authors and should not be interpreted as representing official
34  * policies, either expressed or implied, of any organization.
35  * #L%
36  */
37 
38 #ifndef OME_FILES_OUT_OMETIFFWRITER_H
39 #define OME_FILES_OUT_OMETIFFWRITER_H
40 
41 #include <ome/files/detail/FormatWriter.h>
42 #include <ome/files/detail/OMETIFF.h>
43 
44 #include <ome/common/filesystem.h>
45 #include <ome/common/log.h>
46 
47 #include <ome/xml/meta/OMEXMLMetadata.h>
48 
49 namespace ome
50 {
51  namespace files
52  {
53  namespace tiff
54  {
55 
56  class TIFF;
57  class IFD;
58 
59  }
60 
61  namespace out
62  {
63 
68  {
69  protected:
72 
74  typedef std::map<boost::filesystem::path, std::string> file_uuid_map;
75 
76  // In the Java reader, this is uuids + ifdCounts
78  struct TIFFState
79  {
81  std::string uuid;
83  ome::compat::shared_ptr<ome::files::tiff::TIFF> tiff;
86 
92  TIFFState(ome::compat::shared_ptr<ome::files::tiff::TIFF>& tiff);
93 
95  ~TIFFState();
96  };
97 
99  typedef std::map<boost::filesystem::path, TIFFState> tiff_map;
100 
101  // In the Java reader, this is imageLocations.
103  struct SeriesState
104  {
106  std::vector<detail::OMETIFFPlane> planes;
107  };
108 
110  typedef std::vector<SeriesState> series_list;
111 
113  boost::filesystem::path baseDir;
114 
116  file_uuid_map files;
117 
118  // Mutable to allow opening TIFFs when const.
120  mutable tiff_map tiffs;
121 
123  tiff_map::iterator currentTIFF;
124 
126  std::string flags;
127 
129  series_list seriesState;
130 
140  ome::compat::shared_ptr< ::ome::xml::meta::MetadataRetrieve> originalMetadataRetrieve;
141 
143  ome::compat::shared_ptr<ome::xml::meta::OMEXMLMetadata> omeMeta;
144 
145  private:
147  boost::optional<bool> bigTIFF;
148 
149  public:
151  OMETIFFWriter();
152 
154  virtual
155  ~OMETIFFWriter();
156 
157  // Documented in superclass.
158  void
159  setId(const boost::filesystem::path& id);
160 
161  // Documented in superclass.
162  void
163  close(bool fileOnly = false);
164 
166 
167  // Documented in superclass.
168  void
169  setSeries(dimension_size_type series) const;
170 
171  // Documented in superclass.
172  void
173  setPlane(dimension_size_type plane) const;
174 
175  protected:
177  void
178  nextIFD() const;
179 
181  void
182  setupIFD() const;
183 
184  public:
185  // Documented in superclass.
186  void
187  saveBytes(dimension_size_type plane,
188  VariantPixelBuffer& buf,
193 
194  private:
200  void
201  fillMetadata();
202 
209  std::string
210  getOMEXML(const boost::filesystem::path& id);
211 
218  void
219  saveComment(const boost::filesystem::path& id,
220  const std::string& xml);
221 
222  // Java getUUID unimplemented; see uuid member of TIFFState.
223 
224  // Java planeCount() unimplemented; use getImageCount()
225  // instead. Note the java implementation special-cases
226  // certain behaviour such as interleaving for certain pixel
227  // types; here the caller can specify exactly what they want.
228 
229  public:
233  void
234  setBigTIFF(boost::optional<bool> big = true);
235 
239  boost::optional<bool>
240  getBigTIFF() const;
241  };
242 
243  }
244  }
245 }
246 
247 #endif // OME_FILES_OUT_OMETIFFWRITER_H
248 
249 /*
250  * Local Variables:
251  * mode:C++
252  * End:
253  */
boost::filesystem::path baseDir
Base path for computing relative paths in the OME-XML.
Definition: OMETIFFWriter.h:113
logging::sources::severity_logger_mt< logging::trivial::severity_level > Logger
dimension_size_type ifdCount
Number of IFDs written.
Definition: OMETIFFWriter.h:85
series_list seriesState
State of each series.
Definition: OMETIFFWriter.h:129
ome::compat::shared_ptr< ome::xml::meta::OMEXMLMetadata > omeMeta
OME-XML metadata for embedding in the TIFF.
Definition: OMETIFFWriter.h:143
std::size_t dimension_size_type
Size type for image dimensions.
Definition: Types.h:59
ome::compat::shared_ptr< ome::files::tiff::TIFF > tiff
TIFF file handle.
Definition: OMETIFFWriter.h:83
std::string getOMEXML(::ome::xml::meta::OMEXMLMetadata &omexml, bool validate)
Get OME-XML document from OME-XML metadata.
Definition: MetadataTools.cpp:378
std::map< boost::filesystem::path, TIFFState > tiff_map
Map filename to TIFF state.
Definition: OMETIFFWriter.h:99
ome::common::Logger logger
Message logger.
Definition: OMETIFFWriter.h:71
virtual void saveBytes(dimension_size_type plane, VariantPixelBuffer &buf)=0
Save an image plane.
std::map< boost::filesystem::path, std::string > file_uuid_map
Map filename to UUID.
Definition: OMETIFFWriter.h:74
tiff_map tiffs
Open TIFF files.
Definition: OMETIFFWriter.h:120
std::string flags
TIFF flags.
Definition: OMETIFFWriter.h:126
Interface for all biological file format writers (default behaviour).
Definition: FormatWriter.h:108
ome::compat::shared_ptr< ::ome::xml::meta::MetadataRetrieve > originalMetadataRetrieve
Original MetadataRetrieve.
Definition: OMETIFFWriter.h:140
file_uuid_map files
UUID to filename mapping.
Definition: OMETIFFWriter.h:116
Current state of an image series.
Definition: OMETIFFWriter.h:103
TIFF writer with support for OME-XML metadata.
Definition: OMETIFFWriter.h:67
std::string uuid
UUID of file.
Definition: OMETIFFWriter.h:81
State of TIFF file.
Definition: OMETIFFWriter.h:78
std::vector< detail::OMETIFFPlane > planes
Current state of each plane in an image series.
Definition: OMETIFFWriter.h:106
void fillMetadata(::ome::xml::meta::MetadataStore &store, const FormatReader &reader, bool doPlane, bool doImageName)
Fill OME-XML metadata store from reader core metadata.
Definition: MetadataTools.cpp:517
Buffer for all pixel types.
Definition: VariantPixelBuffer.h:75
tiff_map::iterator currentTIFF
Current TIFF file.
Definition: OMETIFFWriter.h:123
std::vector< SeriesState > series_list
Vector of SeriesState objects.
Definition: OMETIFFWriter.h:110
boost::optional< bool > bigTIFF
Write a Big TIFF.
Definition: OMETIFFWriter.h:147