ome-files 0.1.0

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

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/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 files
60 {
61 namespace in
62 {
63
67 class OMETIFFReader : public ::ome::files::detail::FormatReader
68 {
69 using detail::FormatReader::isThisType;
70 using ::ome::files::FormatReader::getOptimalTileWidth;
71 using ::ome::files::FormatReader::getOptimalTileHeight;
72
73 protected:
75 ome::common::Logger logger;
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, ome::compat::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
105 public:
107 OMETIFFReader();
108
110 virtual
111 ~OMETIFFReader();
112
113 // Documented in superclass.
114 bool
115 isSingleFile(const boost::filesystem::path& id) const;
116
117 // Documented in superclass.
118 bool
119 isThisType(const boost::filesystem::path& name,
120 bool open) const;
121
122 protected:
123 // Documented in superclass.
124 bool
125 isFilenameThisTypeImpl(const boost::filesystem::path& name) const;
126
127 // Documented in superclass.
128 void
129 getLookupTable(dimension_size_type plane,
130 VariantPixelBuffer& buf) const;
131
132 // Documented in superclass.
133 void
134 openBytesImpl(dimension_size_type plane,
135 VariantPixelBuffer& buf,
136 dimension_size_type x,
137 dimension_size_type y,
138 dimension_size_type w,
139 dimension_size_type h) const;
140
148 const ome::compat::shared_ptr<const tiff::IFD>
149 ifdAtIndex(dimension_size_type plane) const;
150
156 void
157 addTIFF(const boost::filesystem::path& tiff);
158
170 const ome::compat::shared_ptr<const ome::files::tiff::TIFF>
171 getTIFF(const boost::filesystem::path& tiff) const;
172
180 void
181 closeTIFF(const boost::filesystem::path& tiff);
182
183 public:
184 // Documented in superclass.
185 void
186 close(bool fileOnly = false);
187
188 const std::vector<std::string>&
189 getDomains() const;
190
191 // Documented in superclass.
192 const std::vector<boost::filesystem::path>
193 getSeriesUsedFiles(bool noPixels) const;
194
195 // Documented in superclass.
196 FormatReader::FileGroupOption
197 fileGroupOption(const std::string& id);
198
199 // Documented in superclass.
200 dimension_size_type
201 getOptimalTileWidth(dimension_size_type channel) const;
202
203 // Documented in superclass.
204 dimension_size_type
205 getOptimalTileHeight(dimension_size_type channel) const;
206
207 // Documented in superclass.
208 void
209 initFile(const boost::filesystem::path& id);
210
211 private:
222 void
223 findUsedFiles(const ome::xml::meta::OMEXMLMetadata& meta,
224 const boost::filesystem::path& currentId,
225 const boost::filesystem::path& currentDir,
226 const boost::optional<std::string>& currentUUID);
227
237 void
238 getAcquisitionDates(const ome::xml::meta::OMEXMLMetadata& meta,
239 std::vector<boost::optional<ome::xml::model::primitives::Timestamp> >& timestamps);
240
248 void
249 cleanMetadata(ome::xml::meta::OMEXMLMetadata& meta);
250
258 dimension_size_type
259 seriesFileSamplesPerPixel(const ome::xml::meta::OMEXMLMetadata& meta,
260 ome::xml::meta::BaseMetadata::index_type series);
261
274 void
275 seriesIndexStart(const ome::xml::meta::OMEXMLMetadata& meta,
276 ome::xml::meta::BaseMetadata::index_type series,
277 boost::optional<ome::xml::model::primitives::NonNegativeInteger>& zIndexStart,
278 boost::optional<ome::xml::model::primitives::NonNegativeInteger>& tIndexStart,
279 boost::optional<ome::xml::model::primitives::NonNegativeInteger>& cIndexStart);
280
294 bool
295 getTiffDataValues(const ome::xml::meta::OMEXMLMetadata& meta,
296 ome::xml::meta::BaseMetadata::index_type series,
297 ome::xml::meta::BaseMetadata::index_type tiffData,
298 boost::optional<ome::xml::model::primitives::NonNegativeInteger>& tdIFD,
299 ome::xml::model::primitives::NonNegativeInteger& numPlanes,
300 ome::xml::model::primitives::NonNegativeInteger& firstZ,
301 ome::xml::model::primitives::NonNegativeInteger& firstT,
302 ome::xml::model::primitives::NonNegativeInteger& firstC);
303
314 void
315 fixOMEROMetadata(ome::xml::meta::OMEXMLMetadata& meta,
316 ome::xml::meta::BaseMetadata::index_type series);
317
329 void
330 fixDimensions(ome::xml::meta::BaseMetadata::index_type series);
331
332 public:
343 ome::compat::shared_ptr< ome::xml::meta::MetadataStore>
344 getMetadataStoreForConversion();
345
355 ome::compat::shared_ptr< ome::xml::meta::MetadataStore>
356 getMetadataStoreForDisplay();
357 };
358
359
360 }
361 }
362 }
363
364 #endif // OME_FILES_IN_OMETIFFREADER_H
365
366 /*
367 * Local Variables:
368 * mode:C++
369 * End:
370 */
ome::files::in::OMETIFFReader::getTIFF
const ome::compat::shared_ptr< const ome::files::tiff::TIFF > getTIFF(const boost::filesystem::path &tiff) const
Get a an open TIFF file from the internal TIFF map.
Definition: OMETIFFReader.cpp:1319
ome::files::in::OMETIFFReader::getDomains
const std::vector< std::string > & getDomains() const
Get the domains represented by the current file.
Definition: OMETIFFReader.cpp:329
ome::common::Logger
logging::sources::severity_logger_mt< logging::trivial::severity_level > Logger
ome::files::in::OMETIFFReader::fixOMEROMetadata
void fixOMEROMetadata(ome::xml::meta::OMEXMLMetadata &meta, ome::xml::meta::BaseMetadata::index_type series)
Fix invalid OMERO OME-TIFF metadata.
Definition: OMETIFFReader.cpp:1203
ome::files::in::OMETIFFReader::getSeriesUsedFiles
const std::vector< boost::filesystem::path > getSeriesUsedFiles(bool noPixels) const
Get the files used by the active series.
Definition: OMETIFFReader.cpp:336
ome::files::dimension_size_type
std::size_t dimension_size_type
Size type for image dimensions.
Definition: Types.h:59
ome::files::in::OMETIFFReader::seriesFileSamplesPerPixel
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.
ome::files::in::OMETIFFReader::tiff_map
std::map< boost::filesystem::path, ome::compat::shared_ptr< ome::files::tiff::TIFF > > tiff_map
Map filename to open TIFF handle.
Definition: OMETIFFReader.h:84
ome::files::in::OMETIFFReader::isSingleFile
bool isSingleFile(const boost::filesystem::path &id) const
Is this a single-file format?
Definition: OMETIFFReader.cpp:214
ome::files::in::OMETIFFReader::getLookupTable
void getLookupTable(dimension_size_type plane, VariantPixelBuffer &buf) const
Get the color lookup table associated with an image plane.
Definition: OMETIFFReader.cpp:1276
ome::files::FormatReader::FileGroupOption
FileGroupOption
File grouping options.
Definition: FormatReader.h:77
ome::files::in::OMETIFFReader::hasSPW
bool hasSPW
Has screen-plate-well metadata.
Definition: OMETIFFReader.h:103
ome::files::in::OMETIFFReader::invalidFiles
invalid_file_map invalidFiles
Invalid filename to valid filename mapping.
Definition: OMETIFFReader.h:90
ome::files::in::OMETIFFReader::fileGroupOption
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:362
ome::files::in::OMETIFFReader::cleanMetadata
void cleanMetadata(ome::xml::meta::OMEXMLMetadata &meta)
Clean up OME-XML metadata.
Definition: OMETIFFReader.cpp:1074
ome::files::in::OMETIFFReader::files
uuid_file_map files
UUID to filename mapping.
Definition: OMETIFFReader.h:87
ome::files::detail::FormatReader::series
dimension_size_type series
The number of the current series (non-flattened).
Definition: FormatReader.h:140
ome::files::in::OMETIFFReader::getMetadataStoreForConversion
ome::compat::shared_ptr< ome::xml::meta::MetadataStore > getMetadataStoreForConversion()
Get a MetadataStore suitable for writing.
Definition: OMETIFFReader.cpp:1347
ome::files::in::OMETIFFReader::isThisType
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:253
ome::files::detail::FormatReader::getOptimalTileWidth
dimension_size_type getOptimalTileWidth() const
Get the optimal sub-image width.
Definition: FormatReader.cpp:1159
ome::files::in::OMETIFFReader::tiffs
tiff_map tiffs
Open TIFF files.
Definition: OMETIFFReader.h:94
ome::files::detail::FormatReader::plane
dimension_size_type plane
The number of the current plane in the current series.
Definition: FormatReader.h:148
ome::files::detail::FormatReader::isThisType
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:420
ome::files::in::OMETIFFReader::OMETIFFReader
OMETIFFReader()
Constructor.
Definition: OMETIFFReader.cpp:167
ome::files::in::OMETIFFReader::isFilenameThisTypeImpl
bool isFilenameThisTypeImpl(const boost::filesystem::path &name) const
isThisType file implementation for readers.
Definition: OMETIFFReader.cpp:263
ome::files::in::OMETIFFReader
TIFF reader with support for OME-XML metadata.
Definition: OMETIFFReader.h:67
ome
ome::files::in::OMETIFFReader::getMetadataStoreForDisplay
ome::compat::shared_ptr< ome::xml::meta::MetadataStore > getMetadataStoreForDisplay()
Get a MetadataStore suitable for display.
Definition: OMETIFFReader.cpp:1366
ome::files::in::OMETIFFReader::close
void close(bool fileOnly=false)
Close the currently open file.
Definition: OMETIFFReader.cpp:196
ome::files::in::OMETIFFReader::fixDimensions
void fixDimensions(ome::xml::meta::BaseMetadata::index_type series)
Attempt to correct logically inconsistent dimensions.
Definition: OMETIFFReader.cpp:1238
ome::files::in::OMETIFFReader::seriesIndexStart
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:1085
ome::files::in::OMETIFFReader::initFile
void initFile(const boost::filesystem::path &id)
Initialize the given file.
Definition: OMETIFFReader.cpp:399
ome::xml::meta::OMEXMLMetadata
ome::files::detail::FormatReader
Interface for all biological file format readers (default behaviour).
Definition: FormatReader.h:107
ome::files::in::OMETIFFReader::logger
ome::common::Logger logger
Message logger.
Definition: OMETIFFReader.h:75
ome::files::in::OMETIFFReader::invalid_file_map
std::map< boost::filesystem::path, boost::filesystem::path > invalid_file_map
Map filename to another file.
Definition: OMETIFFReader.h:81
ome::files::in::OMETIFFReader::~OMETIFFReader
virtual ~OMETIFFReader()
Destructor.
Definition: OMETIFFReader.cpp:184
ome::files::detail::FormatReader::currentId
boost::optional< boost::filesystem::path > currentId
The identifier (path) of the currently open file.
Definition: FormatReader.h:118
ome::files::in::OMETIFFReader::metadataFile
boost::filesystem::path metadataFile
Metadata file.
Definition: OMETIFFReader.h:97
ome::files::in::OMETIFFReader::getAcquisitionDates
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:1055
ome::files::in::OMETIFFReader::ifdAtIndex
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:304
ome::files::in::OMETIFFReader::getTiffDataValues
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:1137
ome::files::in::OMETIFFReader::uuid_file_map
std::map< std::string, boost::filesystem::path > uuid_file_map
Map UUID to filename.
Definition: OMETIFFReader.h:78
log.h
ome::files::in::OMETIFFReader::closeTIFF
void closeTIFF(const boost::filesystem::path &tiff)
Close an open TIFF file from the internal TIFF map.
Definition: OMETIFFReader.cpp:1336
ome::files::detail::FormatReader::getOptimalTileHeight
dimension_size_type getOptimalTileHeight() const
Get the optimal sub-image height.
Definition: FormatReader.cpp:1172
ome::files::in::OMETIFFReader::findUsedFiles
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:966
ome::files::VariantPixelBuffer
Buffer for all pixel types.
Definition: VariantPixelBuffer.h:75
ome::files::in::OMETIFFReader::openBytesImpl
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:1298
ome::xml::meta::BaseMetadata::index_type
std::size_t index_type
ome::xml::model::primitives::ConstrainedNumeric
ome::files::in::OMETIFFReader::usedFiles
std::vector< boost::filesystem::path > usedFiles
Used files.
Definition: OMETIFFReader.h:100
ome::common::xml
ome::files::in::OMETIFFReader::addTIFF
void addTIFF(const boost::filesystem::path &tiff)
Add a TIFF file to the internal TIFF map.
Definition: OMETIFFReader.cpp:1313