ome-files  0.5.0
OMETIFFReader.h
1 /*
2  * #%L
3  * OME-FILES C++ library for image IO.
4  * Copyright © 2015 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_IN_OMETIFFREADER_H
39 #define OME_FILES_IN_OMETIFFREADER_H
40 
41 #include <ome/files/in/MinimalTIFFReader.h>
42 #include <ome/files/tiff/TIFF.h>
43 
44 #include <ome/common/log.h>
45 
46 #include <ome/xml/meta/BaseMetadata.h>
47 
48 namespace ome
49 {
50 
51  namespace xml
52  {
53  namespace meta
54  {
55  class OMEXMLMetadata;
56  }
57  }
58 
59  namespace files
60  {
61  namespace in
62  {
63 
68  {
69  using detail::FormatReader::isThisType;
70  using ::ome::files::FormatReader::getOptimalTileWidth;
71  using ::ome::files::FormatReader::getOptimalTileHeight;
72 
73  protected:
76 
78  typedef std::map<std::string, boost::filesystem::path> uuid_file_map;
79 
81  typedef std::map<boost::filesystem::path, boost::filesystem::path> invalid_file_map;
82 
84  typedef std::map<boost::filesystem::path, std::shared_ptr<ome::files::tiff::TIFF>> tiff_map;
85 
87  uuid_file_map files;
88 
90  invalid_file_map invalidFiles;
91 
92  // Mutable to allow opening TIFFs when const.
94  mutable tiff_map tiffs;
95 
97  boost::filesystem::path metadataFile;
98 
100  std::vector<boost::filesystem::path> usedFiles;
101 
103  bool hasSPW;
104 
106  mutable std::shared_ptr<::ome::xml::meta::OMEXMLMetadata> cachedMetadata;
107 
112  mutable boost::filesystem::path cachedMetadataFile;
113 
114  public:
116  OMETIFFReader();
117 
119  virtual
120  ~OMETIFFReader();
121 
122  // Documented in superclass.
123  bool
124  isSingleFile(const boost::filesystem::path& id) const;
125 
126  // Documented in superclass.
127  bool
128  isThisType(const boost::filesystem::path& name,
129  bool open) const;
130 
131  protected:
132  // Documented in superclass.
133  bool
134  isFilenameThisTypeImpl(const boost::filesystem::path& name) const;
135 
136  // Documented in superclass.
137  void
138  getLookupTable(dimension_size_type plane,
139  VariantPixelBuffer& buf) const;
140 
141  // Documented in superclass.
142  void
143  openBytesImpl(dimension_size_type plane,
144  VariantPixelBuffer& buf,
148  dimension_size_type h) const;
149 
157  const std::shared_ptr<const tiff::IFD>
158  ifdAtIndex(dimension_size_type plane) const;
159 
165  void
166  addTIFF(const boost::filesystem::path& tiff);
167 
179  const std::shared_ptr<const ome::files::tiff::TIFF>
180  getTIFF(const boost::filesystem::path& tiff) const;
181 
188  bool
189  validTIFF(const boost::filesystem::path& tiff) const;
190 
198  void
199  closeTIFF(const boost::filesystem::path& tiff);
200 
207  std::shared_ptr<::ome::xml::meta::OMEXMLMetadata>
208  readMetadata(const ome::files::tiff::TIFF& tiff);
209 
217  std::shared_ptr<::ome::xml::meta::OMEXMLMetadata>
218  readMetadata(const boost::filesystem::path& id);
219 
232  std::shared_ptr<::ome::xml::meta::OMEXMLMetadata>
233  cacheMetadata(const boost::filesystem::path& id) const;
234 
235  public:
236  // Documented in superclass.
237  void
238  close(bool fileOnly = false);
239 
240  const std::vector<std::string>&
241  getDomains() const;
242 
243  // Documented in superclass.
244  const std::vector<boost::filesystem::path>
245  getSeriesUsedFiles(bool noPixels) const;
246 
247  // Documented in superclass.
249  fileGroupOption(const std::string& id);
250 
251  // Documented in superclass.
253  getOptimalTileWidth(dimension_size_type channel) const;
254 
255  // Documented in superclass.
257  getOptimalTileHeight(dimension_size_type channel) const;
258 
259  // Documented in superclass.
260  void
261  initFile(const boost::filesystem::path& id);
262 
263  private:
274  void
275  findUsedFiles(const ome::xml::meta::OMEXMLMetadata& meta,
276  const boost::filesystem::path& currentId,
277  const boost::filesystem::path& currentDir,
278  const boost::optional<std::string>& currentUUID);
279 
289  void
290  getAcquisitionDates(const ome::xml::meta::OMEXMLMetadata& meta,
291  std::vector<boost::optional<ome::xml::model::primitives::Timestamp>>& timestamps);
292 
300  void
301  cleanMetadata(ome::xml::meta::OMEXMLMetadata& meta);
302 
311  seriesFileSamplesPerPixel(const ome::xml::meta::OMEXMLMetadata& meta,
313 
326  void
327  seriesIndexStart(const ome::xml::meta::OMEXMLMetadata& meta,
329  boost::optional<ome::xml::model::primitives::NonNegativeInteger>& zIndexStart,
330  boost::optional<ome::xml::model::primitives::NonNegativeInteger>& tIndexStart,
331  boost::optional<ome::xml::model::primitives::NonNegativeInteger>& cIndexStart);
332 
346  bool
347  getTiffDataValues(const ome::xml::meta::OMEXMLMetadata& meta,
350  boost::optional<ome::xml::model::primitives::NonNegativeInteger>& tdIFD,
355 
366  void
367  fixOMEROMetadata(ome::xml::meta::OMEXMLMetadata& meta,
369 
381  void
382  fixDimensions(ome::xml::meta::BaseMetadata::index_type series);
383 
384  public:
400  std::shared_ptr< ome::xml::meta::MetadataStore>
401  getMetadataStoreForConversion();
402 
420  std::shared_ptr< ome::xml::meta::MetadataStore>
421  getMetadataStoreForDisplay();
422  };
423 
424 
425  }
426  }
427 }
428 
429 #endif // OME_FILES_IN_OMETIFFREADER_H
430 
431 /*
432  * Local Variables:
433  * mode:C++
434  * End:
435  */
boost::filesystem::path cachedMetadataFile
Cached metadata file location (for re-using parsed metadata).
Definition: OMETIFFReader.h:112
logging::sources::severity_logger_mt< logging::trivial::severity_level > Logger
Tagged Image File Format (TIFF).
Definition: TIFF.h:156
std::size_t dimension_size_type
Size type for image dimensions.
Definition: Types.h:58
FileGroupOption
File grouping options.
Definition: FormatReader.h:79
bool hasSPW
Has screen-plate-well metadata.
Definition: OMETIFFReader.h:103
invalid_file_map invalidFiles
Invalid filename to valid filename mapping.
Definition: OMETIFFReader.h:90
uuid_file_map files
UUID to filename mapping.
Definition: OMETIFFReader.h:87
tiff_map tiffs
Open TIFF files.
Definition: OMETIFFReader.h:94
TIFF reader with support for OME-XML metadata.
Definition: OMETIFFReader.h:67
Open Microscopy Environment C++.
std::map< boost::filesystem::path, std::shared_ptr< ome::files::tiff::TIFF > > tiff_map
Map filename to open TIFF handle.
Definition: OMETIFFReader.h:84
std::shared_ptr<::ome::xml::meta::OMEXMLMetadata > cachedMetadata
Cached metadata (for re-using parsed metadata).
Definition: OMETIFFReader.h:106
Interface for all biological file format readers (default behaviour).
Definition: FormatReader.h:107
ome::common::Logger logger
Message logger.
Definition: OMETIFFReader.h:75
std::map< boost::filesystem::path, boost::filesystem::path > invalid_file_map
Map filename to another file.
Definition: OMETIFFReader.h:81
boost::filesystem::path metadataFile
Metadata file.
Definition: OMETIFFReader.h:97
std::map< std::string, boost::filesystem::path > uuid_file_map
Map UUID to filename.
Definition: OMETIFFReader.h:78
Buffer for all pixel types.
Definition: VariantPixelBuffer.h:78
std::vector< boost::filesystem::path > usedFiles
Used files.
Definition: OMETIFFReader.h:100