ome-files  0.3.2
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 <boost/filesystem/path.hpp>
42 
43 #include <ome/files/detail/FormatWriter.h>
44 #include <ome/files/detail/OMETIFF.h>
45 
46 #include <ome/common/log.h>
47 
48 #include <ome/xml/meta/OMEXMLMetadata.h>
49 
50 namespace ome
51 {
52  namespace files
53  {
54  namespace tiff
55  {
56 
57  class TIFF;
58  class IFD;
59 
60  }
61 
62  namespace out
63  {
64 
69  {
70  protected:
73 
75  typedef std::map<boost::filesystem::path, std::string> file_uuid_map;
76 
77  // In the Java reader, this is uuids + ifdCounts
79  struct TIFFState
80  {
82  std::string uuid;
84  std::shared_ptr<ome::files::tiff::TIFF> tiff;
87 
93  TIFFState(std::shared_ptr<ome::files::tiff::TIFF>& tiff);
94 
96  ~TIFFState();
97  };
98 
100  typedef std::map<boost::filesystem::path, TIFFState> tiff_map;
101 
102  // In the Java reader, this is imageLocations.
104  struct SeriesState
105  {
107  std::vector<detail::OMETIFFPlane> planes;
108  };
109 
111  typedef std::vector<SeriesState> series_list;
112 
114  boost::filesystem::path baseDir;
115 
117  file_uuid_map files;
118 
119  // Mutable to allow opening TIFFs when const.
121  mutable tiff_map tiffs;
122 
124  tiff_map::iterator currentTIFF;
125 
127  std::string flags;
128 
130  series_list seriesState;
131 
141  std::shared_ptr<::ome::xml::meta::MetadataRetrieve> originalMetadataRetrieve;
142 
144  std::shared_ptr<ome::xml::meta::OMEXMLMetadata> omeMeta;
145 
146  private:
148  boost::optional<bool> bigTIFF;
149 
150  public:
152  OMETIFFWriter();
153 
155  virtual
156  ~OMETIFFWriter();
157 
158  // Documented in superclass.
159  void
160  setId(const boost::filesystem::path& id);
161 
162  // Documented in superclass.
163  void
164  close(bool fileOnly = false);
165 
167 
168  // Documented in superclass.
169  void
170  setSeries(dimension_size_type series) const;
171 
172  // Documented in superclass.
173  void
174  setPlane(dimension_size_type plane) const;
175 
176  protected:
178  void
179  nextIFD() const;
180 
182  void
183  setupIFD() const;
184 
185  public:
186  // Documented in superclass.
187  void
188  saveBytes(dimension_size_type plane,
189  VariantPixelBuffer& buf,
194 
195  private:
201  void
202  fillMetadata();
203 
210  std::string
211  getOMEXML(const boost::filesystem::path& id);
212 
219  void
220  saveComment(const boost::filesystem::path& id,
221  const std::string& xml);
222 
223  // Java getUUID unimplemented; see uuid member of TIFFState.
224 
225  // Java planeCount() unimplemented; use getImageCount()
226  // instead. Note the java implementation special-cases
227  // certain behaviour such as interleaving for certain pixel
228  // types; here the caller can specify exactly what they want.
229 
230  public:
234  void
235  setBigTIFF(boost::optional<bool> big = true);
236 
240  boost::optional<bool>
241  getBigTIFF() const;
242  };
243 
244  }
245  }
246 }
247 
248 #endif // OME_FILES_OUT_OMETIFFWRITER_H
249 
250 /*
251  * Local Variables:
252  * mode:C++
253  * End:
254  */
boost::filesystem::path baseDir
Base path for computing relative paths in the OME-XML.
Definition: OMETIFFWriter.h:114
std::shared_ptr< ome::xml::meta::OMEXMLMetadata > omeMeta
OME-XML metadata for embedding in the TIFF.
Definition: OMETIFFWriter.h:144
logging::sources::severity_logger_mt< logging::trivial::severity_level > Logger
dimension_size_type ifdCount
Number of IFDs written.
Definition: OMETIFFWriter.h:86
series_list seriesState
State of each series.
Definition: OMETIFFWriter.h:130
std::size_t dimension_size_type
Size type for image dimensions.
Definition: Types.h:58
std::string getOMEXML(::ome::xml::meta::OMEXMLMetadata &omexml, bool validate)
Get OME-XML document from OME-XML metadata.
Definition: MetadataTools.cpp:379
std::map< boost::filesystem::path, TIFFState > tiff_map
Map filename to TIFF state.
Definition: OMETIFFWriter.h:100
ome::common::Logger logger
Message logger.
Definition: OMETIFFWriter.h:72
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:75
std::shared_ptr< ome::files::tiff::TIFF > tiff
TIFF file handle.
Definition: OMETIFFWriter.h:84
tiff_map tiffs
Open TIFF files.
Definition: OMETIFFWriter.h:121
std::string flags
TIFF flags.
Definition: OMETIFFWriter.h:127
Interface for all biological file format writers (default behaviour).
Definition: FormatWriter.h:108
Open Microscopy Environment C++.
file_uuid_map files
UUID to filename mapping.
Definition: OMETIFFWriter.h:117
std::shared_ptr<::ome::xml::meta::MetadataRetrieve > originalMetadataRetrieve
Original MetadataRetrieve.
Definition: OMETIFFWriter.h:141
Current state of an image series.
Definition: OMETIFFWriter.h:104
TIFF writer with support for OME-XML metadata.
Definition: OMETIFFWriter.h:68
std::string uuid
UUID of file.
Definition: OMETIFFWriter.h:82
State of TIFF file.
Definition: OMETIFFWriter.h:79
std::vector< detail::OMETIFFPlane > planes
Current state of each plane in an image series.
Definition: OMETIFFWriter.h:107
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:516
Buffer for all pixel types.
Definition: VariantPixelBuffer.h:75
tiff_map::iterator currentTIFF
Current TIFF file.
Definition: OMETIFFWriter.h:124
std::vector< SeriesState > series_list
Vector of SeriesState objects.
Definition: OMETIFFWriter.h:111
boost::optional< bool > bigTIFF
Write a Big TIFF.
Definition: OMETIFFWriter.h:148