bioformats  5.1.1
OMETIFFReader.h
1 /*
2  * #%L
3  * OME-BIOFORMATS 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_BIOFORMATS_IN_OMETIFFREADER_H
39 #define OME_BIOFORMATS_IN_OMETIFFREADER_H
40 
41 #include <ome/bioformats/in/MinimalTIFFReader.h>
42 #include <ome/bioformats/tiff/ImageJMetadata.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 bioformats
60  {
61  namespace in
62  {
63 
68  {
70 
71  protected:
74 
76  typedef std::map<std::string, boost::filesystem::path> uuid_file_map;
77 
79  typedef std::map<boost::filesystem::path, boost::filesystem::path> invalid_file_map;
80 
82  typedef std::map<boost::filesystem::path, ome::compat::shared_ptr<ome::bioformats::tiff::TIFF> > tiff_map;
83 
85  uuid_file_map files;
86 
88  invalid_file_map invalidFiles;
89 
90  // Mutable to allow opening TIFFs when const.
92  mutable tiff_map tiffs;
93 
95  boost::filesystem::path metadataFile;
96 
98  std::vector<boost::filesystem::path> usedFiles;
99 
101  bool hasSPW;
102 
103  public:
105  OMETIFFReader();
106 
108  virtual
109  ~OMETIFFReader();
110 
111  // Documented in superclass.
112  bool
113  isSingleFile(const boost::filesystem::path& id) const;
114 
115  // Documented in superclass.
116  bool
117  isThisType(const boost::filesystem::path& name,
118  bool open) const;
119 
120  protected:
121  // Documented in superclass.
122  bool
123  isFilenameThisTypeImpl(const boost::filesystem::path& name) const;
124 
125  // Documented in superclass.
126  void
128  VariantPixelBuffer& buf) const;
129 
130  // Documented in superclass.
131  void
133  VariantPixelBuffer& buf,
137  dimension_size_type h) const;
138 
146  const ome::compat::shared_ptr<const tiff::IFD>
147  ifdAtIndex(dimension_size_type plane) const;
148 
154  void
155  addTIFF(const boost::filesystem::path& tiff);
156 
168  const ome::compat::shared_ptr<const ome::bioformats::tiff::TIFF>
169  getTIFF(const boost::filesystem::path& tiff) const;
170 
178  void
179  closeTIFF(const boost::filesystem::path& tiff);
180 
181  public:
182  // Documented in superclass.
183  void
184  close(bool fileOnly = false);
185 
186  const std::vector<std::string>&
187  getDomains() const;
188 
189  // Documented in superclass.
190  const std::vector<boost::filesystem::path>
191  getSeriesUsedFiles(bool noPixels) const;
192 
193  // Documented in superclass.
195  fileGroupOption(const std::string& id);
196 
197  // Documented in superclass.
200 
201  // Documented in superclass.
204 
205  // Documented in superclass.
206  void
207  initFile(const boost::filesystem::path& id);
208 
209  private:
220  void
222  const boost::filesystem::path& currentId,
223  const boost::filesystem::path& currentDir,
224  const boost::optional<std::string>& currentUUID);
225 
235  void
237  std::vector<boost::optional<ome::xml::model::primitives::Timestamp> >& timestamps);
238 
246  void
248 
259 
272  void
275  boost::optional<ome::xml::model::primitives::NonNegativeInteger>& zIndexStart,
276  boost::optional<ome::xml::model::primitives::NonNegativeInteger>& tIndexStart,
277  boost::optional<ome::xml::model::primitives::NonNegativeInteger>& cIndexStart);
278 
292  bool
296  boost::optional<ome::xml::model::primitives::NonNegativeInteger>& tdIFD,
301 
312  void
315 
327  void
329 
330  public:
341  ome::compat::shared_ptr< ome::xml::meta::MetadataStore>
343 
353  ome::compat::shared_ptr< ome::xml::meta::MetadataStore>
355  };
356 
357 
358  }
359  }
360 }
361 
362 #endif // OME_BIOFORMATS_IN_OMETIFFREADER_H
363 
364 /*
365  * Local Variables:
366  * mode:C++
367  * End:
368  */
Interface for all biological file format readers (default behaviour).
Definition: FormatReader.h:109
bool hasSPW
Has screen-plate-well metadata.
Definition: OMETIFFReader.h:101
logging::sources::severity_logger_mt< logging::trivial::severity_level > Logger
Message logger.
Definition: log.h:98
void getAcquisitionDates(const ome::xml::meta::OMEXMLMetadata &meta, std::vector< boost::optional< ome::xml::model::primitives::Timestamp > > &timestamps)
Get acquisition dates for each image.
Definition: OMETIFFReader.cpp:1070
FormatReader::FileGroupOption fileGroupOption(const std::string &id)
Returns an enum indicating that we cannot, must, or might group the files in this dataset...
Definition: OMETIFFReader.cpp:388
void addTIFF(const boost::filesystem::path &tiff)
Add a TIFF file to the internal TIFF map.
Definition: OMETIFFReader.cpp:1326
void fixOMEROMetadata(ome::xml::meta::OMEXMLMetadata &meta, ome::xml::meta::BaseMetadata::index_type series)
Fix invalid OMERO OME-TIFF metadata.
Definition: OMETIFFReader.cpp:1218
ome::common::Logger logger
Message logger.
Definition: OMETIFFReader.h:73
ome::compat::shared_ptr< ome::xml::meta::MetadataStore > getMetadataStoreForDisplay()
Get a MetadataStore suitable for display.
Definition: OMETIFFReader.cpp:1379
invalid_file_map invalidFiles
Invalid filename to valid filename mapping.
Definition: OMETIFFReader.h:88
const std::vector< boost::filesystem::path > getSeriesUsedFiles(bool noPixels) const
Get the files used by the active series.
Definition: OMETIFFReader.cpp:362
bool isFilenameThisTypeImpl(const boost::filesystem::path &name) const
isThisType file implementation for readers.
Definition: OMETIFFReader.cpp:289
TIFF reader with support for ImageJ extensions.
Definition: OMETIFFReader.h:67
bool isThisType(const boost::filesystem::path &name, bool open=true) const
Check if the given file is a valid instance of this file format.
Definition: FormatReader.cpp:419
void fixDimensions(ome::xml::meta::BaseMetadata::index_type series)
Attempt to correct logically inconsistent dimensions.
Definition: OMETIFFReader.cpp:1253
std::map< boost::filesystem::path, boost::filesystem::path > invalid_file_map
Map filename to another file.
Definition: OMETIFFReader.h:79
uuid_file_map files
UUID to filename mapping.
Definition: OMETIFFReader.h:85
const ome::compat::shared_ptr< const ome::bioformats::tiff::TIFF > getTIFF(const boost::filesystem::path &tiff) const
Get a an open TIFF file from the internal TIFF map.
Definition: OMETIFFReader.cpp:1332
void openBytesImpl(dimension_size_type plane, VariantPixelBuffer &buf, dimension_size_type x, dimension_size_type y, dimension_size_type w, dimension_size_type h) const
Obtain a sub-image of an image plane.
Definition: OMETIFFReader.cpp:1311
tiff_map tiffs
Open TIFF files.
Definition: OMETIFFReader.h:92
void close(bool fileOnly=false)
Close the currently open file.
Definition: OMETIFFReader.cpp:222
bool isSingleFile(const boost::filesystem::path &id) const
Is this a single-file format?
Definition: OMETIFFReader.cpp:240
void findUsedFiles(const ome::xml::meta::OMEXMLMetadata &meta, const boost::filesystem::path &currentId, const boost::filesystem::path &currentDir, const boost::optional< std::string > &currentUUID)
Get UUID to file associations and used files.
Definition: OMETIFFReader.cpp:992
virtual ~OMETIFFReader()
Destructor.
Definition: OMETIFFReader.cpp:217
void closeTIFF(const boost::filesystem::path &tiff)
Close an open TIFF file from the internal TIFF map.
Definition: OMETIFFReader.cpp:1349
Open Microscopy Environment C++ implementation.
Definition: CoreMetadata.cpp:40
bool isThisType(const boost::filesystem::path &name, bool open) const
Check if the given file is a valid instance of this file format.
Definition: OMETIFFReader.cpp:279
void seriesIndexStart(const ome::xml::meta::OMEXMLMetadata &meta, ome::xml::meta::BaseMetadata::index_type series, boost::optional< ome::xml::model::primitives::NonNegativeInteger > &zIndexStart, boost::optional< ome::xml::model::primitives::NonNegativeInteger > &tIndexStart, boost::optional< ome::xml::model::primitives::NonNegativeInteger > &cIndexStart)
Get starting index for each dimension.
Definition: OMETIFFReader.cpp:1100
std::vector< boost::filesystem::path > usedFiles
Used files.
Definition: OMETIFFReader.h:98
void getLookupTable(dimension_size_type plane, VariantPixelBuffer &buf) const
Get the color lookup table associated with an image plane.
Definition: OMETIFFReader.cpp:1291
A metadata store implementation for constructing and manipulating OME-XML DOMs for the current versio...
Definition: OMEXMLMetadata.h:67
dimension_size_type seriesFileSamplesPerPixel(const ome::xml::meta::OMEXMLMetadata &meta, ome::xml::meta::BaseMetadata::index_type series)
Get the samples per pixel from the first IFD for a series.
void cleanMetadata(ome::xml::meta::OMEXMLMetadata &meta)
Clean up OME-XML metadata.
Definition: OMETIFFReader.cpp:1089
bool getTiffDataValues(const ome::xml::meta::OMEXMLMetadata &meta, ome::xml::meta::BaseMetadata::index_type series, ome::xml::meta::BaseMetadata::index_type tiffData, boost::optional< ome::xml::model::primitives::NonNegativeInteger > &tdIFD, ome::xml::model::primitives::NonNegativeInteger &numPlanes, ome::xml::model::primitives::NonNegativeInteger &firstZ, ome::xml::model::primitives::NonNegativeInteger &firstT, ome::xml::model::primitives::NonNegativeInteger &firstC)
Get values from a TiffData element.
Definition: OMETIFFReader.cpp:1152
ome::compat::shared_ptr< ome::xml::meta::MetadataStore > getMetadataStoreForConversion()
Get a MetadataStore suitable for writing.
Definition: OMETIFFReader.cpp:1360
dimension_size_type getOptimalTileHeight() const
Get the optimal sub-image height.
Definition: FormatReader.cpp:1146
const std::vector< std::string > & getDomains() const
Get the domains represented by the current file.
Definition: OMETIFFReader.cpp:355
boost::optional< boost::filesystem::path > currentId
The identifier (path) of the currently open file.
Definition: FormatReader.h:120
FileGroupOption
File grouping options.
Definition: FormatReader.h:77
std::map< boost::filesystem::path, ome::compat::shared_ptr< ome::bioformats::tiff::TIFF > > tiff_map
Map filename to open TIFF handle.
Definition: OMETIFFReader.h:82
OMETIFFReader()
Constructor.
Definition: OMETIFFReader.cpp:200
dimension_size_type series
The number of the current series (non-flattened).
Definition: FormatReader.h:142
std::map< std::string, boost::filesystem::path > uuid_file_map
Map UUID to filename.
Definition: OMETIFFReader.h:76
dimension_size_type getOptimalTileWidth() const
Get the optimal sub-image width.
Definition: FormatReader.cpp:1133
Buffer for all pixel types.
Definition: VariantPixelBuffer.h:72
boost::filesystem::path metadataFile
Metadata file.
Definition: OMETIFFReader.h:95
const ome::compat::shared_ptr< const tiff::IFD > ifdAtIndex(dimension_size_type plane) const
Get the IFD index for a plane in the current series.
Definition: OMETIFFReader.cpp:330
Boost.Log compatibility.
std::size_t dimension_size_type
Size type for image dimensions.
Definition: Types.h:59
std::size_t index_type
Index into an array.
Definition: BaseMetadata.h:64
A numeric type constrained to a subrange (or subranges) of its range limits.
Definition: ConstrainedNumeric.h:119
void initFile(const boost::filesystem::path &id)
Initialize the given file.
Definition: OMETIFFReader.cpp:425
Xerces-C modern C++ wrapper.
Definition: Base.h:53