bioformats  5.1.2
FormatReader.h
1 /*
2  * #%L
3  * OME-BIOFORMATS C++ library for image IO.
4  * Copyright © 2006 - 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_FORMATREADER_H
39 #define OME_BIOFORMATS_FORMATREADER_H
40 
41 #include <string>
42 #include <vector>
43 #include <map>
44 
45 #include <boost/optional.hpp>
46 
47 #include <ome/bioformats/CoreMetadata.h>
48 #include <ome/bioformats/FileInfo.h>
49 #include <ome/bioformats/FormatHandler.h>
50 #include <ome/bioformats/MetadataConfigurable.h>
51 #include <ome/bioformats/MetadataMap.h>
52 #include <ome/bioformats/Types.h>
53 
54 #include <ome/compat/array.h>
55 
56 #include <ome/xml/meta/MetadataStore.h>
57 
58 namespace ome
59 {
60  namespace bioformats
61  {
62 
63  class VariantPixelBuffer;
64 
70  class FormatReader : virtual public FormatHandler,
71  virtual public MetadataConfigurable
72  {
73  public:
75 
78  {
82  };
83 
84  protected:
97  class SaveSeries
98  {
99  private:
104 
105  public:
111  SaveSeries(const FormatReader& reader):
112  reader(reader),
113  coreIndex(reader.getCoreIndex())
114  {}
115 
122  {
123  try
124  {
125  if (coreIndex != reader.getCoreIndex())
126  reader.setCoreIndex(coreIndex);
127  }
128  catch (...)
129  {
130  // We can't throw in a destructor.
131  }
132  }
133  };
134 
137  {}
138 
139  private:
141  FormatReader (const FormatReader&);
142 
144  FormatReader&
145  operator= (const FormatReader&);
146 
147  public:
149  virtual
151  {}
152 
153  // Documented in superclass.
154  virtual
155  bool
156  isThisType(const boost::filesystem::path& name,
157  bool open = true) const = 0;
158 
171  virtual
172  bool
173  isThisType(const uint8_t *begin,
174  const uint8_t *end) const = 0;
175 
188  virtual
189  bool
190  isThisType(const uint8_t *begin,
191  std::size_t length) const = 0;
192 
201  virtual
202  bool
203  isThisType(std::istream& stream) const = 0;
204 
210  virtual
212  getImageCount() const = 0;
213 
222  virtual
223  bool
224  isRGB(dimension_size_type channel) const = 0;
225 
231  virtual
233  getSizeX() const = 0;
234 
240  virtual
242  getSizeY() const = 0;
243 
249  virtual
251  getSizeZ() const = 0;
252 
258  virtual
260  getSizeT() const = 0;
261 
267  virtual
269  getSizeC() const = 0;
270 
276  virtual
278  getPixelType() const = 0;
279 
289  virtual
291  getBitsPerPixel() const = 0;
292 
304  virtual
306  getEffectiveSizeC() const = 0;
307 
319  virtual
321  getRGBChannelCount(dimension_size_type channel) const = 0;
322 
331  virtual
332  bool
333  isIndexed() const = 0;
334 
345  virtual
346  bool
347  isFalseColor() const = 0;
348 
365  virtual
366  void
368  VariantPixelBuffer& buf) const = 0;
369 
375  virtual
376  Modulo&
377  getModuloZ() = 0;
378 
384  virtual
385  const Modulo&
386  getModuloZ() const = 0;
387 
393  virtual
394  Modulo&
395  getModuloT() = 0;
396 
402  virtual
403  const Modulo&
404  getModuloT() const = 0;
405 
411  virtual
412  Modulo&
413  getModuloC() = 0;
414 
420  virtual
421  const Modulo&
422  getModuloC() const = 0;
423 
429  virtual
431  getThumbSizeX() const = 0;
432 
438  virtual
440  getThumbSizeY() const = 0;
441 
447  virtual
448  bool
449  isLittleEndian() const = 0;
450 
469  virtual
470  const std::string&
471  getDimensionOrder() const = 0;
472 
478  virtual
479  bool
480  isOrderCertain() const = 0;
481 
488  virtual
489  bool
490  isThumbnailSeries() const = 0;
491 
510  virtual
511  bool
512  isInterleaved() const = 0;
513 
527  virtual
528  bool
529  isInterleaved(dimension_size_type channel) const = 0;
530 
546  virtual
547  void
549  VariantPixelBuffer& buf) const = 0;
550 
570  virtual
571  void
573  VariantPixelBuffer& buf,
577  dimension_size_type h) const = 0;
578 
588  virtual
589  void
591  VariantPixelBuffer& buf) const = 0;
592 
601  virtual
603  getSeriesCount() const = 0;
604 
617  virtual
618  void
619  setSeries(dimension_size_type series) const = 0;
620 
626  virtual
628  getSeries() const = 0;
629 
636  virtual
637  void
638  setNormalized(bool normalize) = 0;
639 
647  virtual
648  bool
649  isNormalized() const = 0;
650 
655  virtual
656  void
657  setOriginalMetadataPopulated(bool populate) = 0;
658 
667  virtual
668  bool
669  isOriginalMetadataPopulated() const = 0;
670 
678  virtual
679  void
680  setGroupFiles(bool group) = 0;
681 
687  virtual
688  bool
689  isGroupFiles() const = 0;
690 
697  virtual
698  bool
699  isMetadataComplete() const = 0;
700 
708  virtual
710  fileGroupOption(const std::string& id) = 0;
711 
719  virtual
720  const std::vector<boost::filesystem::path>
721  getUsedFiles(bool noPixels = false) const = 0;
722 
730  virtual
731  const std::vector<boost::filesystem::path>
732  getSeriesUsedFiles(bool noPixels = false) const = 0;
733 
742  virtual
743  std::vector<FileInfo>
744  getAdvancedUsedFiles(bool noPixels = false) const = 0;
745 
754  virtual
755  std::vector<FileInfo>
756  getAdvancedSeriesUsedFiles(bool noPixels = false) const = 0;
757 
763  virtual
764  const boost::optional<boost::filesystem::path>&
765  getCurrentFile() const = 0;
766 
772  virtual
773  const std::vector<std::string>&
774  getDomains() const = 0;
775 
790  virtual
794  dimension_size_type t) const = 0;
795 
819  virtual
824  dimension_size_type moduloZ,
825  dimension_size_type moduloC,
826  dimension_size_type moduloT) const = 0;
827 
837  virtual
838  ome::compat::array<dimension_size_type, 3>
839  getZCTCoords(dimension_size_type index) const = 0;
840 
857  virtual
858  ome::compat::array<dimension_size_type, 6>
859  getZCTModuloCoords(dimension_size_type index) const = 0;
860 
872  virtual
874  getMetadataValue(const std::string& field) const = 0;
875 
887  virtual
889  getSeriesMetadataValue(const MetadataMap::key_type& field) const = 0;
890 
899  virtual
900  const MetadataMap&
901  getGlobalMetadata() const = 0;
902 
911  virtual
912  const MetadataMap&
913  getSeriesMetadata() const = 0;
914 
923  virtual
924  const std::vector<ome::compat::shared_ptr<CoreMetadata> >&
925  getCoreMetadataList() const = 0;
926 
937  virtual
938  void
939  setMetadataFiltered(bool filter) = 0;
940 
947  virtual
948  bool
949  isMetadataFiltered() const = 0;
950 
956  virtual
957  void
958  setMetadataStore(ome::compat::shared_ptr< ::ome::xml::meta::MetadataStore>& store) = 0;
959 
965  virtual
966  const ome::compat::shared_ptr< ::ome::xml::meta::MetadataStore>&
967  getMetadataStore() const = 0;
968 
974  virtual
975  ome::compat::shared_ptr< ::ome::xml::meta::MetadataStore>&
976  getMetadataStore() = 0;
977 
986  virtual
987  std::vector<ome::compat::shared_ptr<FormatReader> >
988  getUnderlyingReaders() const = 0;
989 
1000  virtual
1001  bool
1002  isSingleFile(const boost::filesystem::path& id) const = 0;
1003 
1034  virtual
1035  uint32_t
1036  getRequiredDirectories(const std::vector<std::string>& files) const = 0;
1037 
1043  virtual
1044  const std::string&
1045  getDatasetStructureDescription() const = 0;
1046 
1057  virtual
1058  const std::vector<std::string>&
1059  getPossibleDomains(const std::string& id) const = 0;
1060 
1067  virtual
1068  bool
1069  hasCompanionFiles() const = 0;
1070 
1079  virtual
1081  getOptimalTileWidth(dimension_size_type channel) const = 0;
1082 
1091  virtual
1093  getOptimalTileHeight(dimension_size_type channel) const = 0;
1094 
1108  virtual
1110  getOptimalTileWidth() const = 0;
1111 
1125  virtual
1127  getOptimalTileHeight() const = 0;
1128 
1129  // Sub-resolution API methods
1130 
1137  virtual
1139  seriesToCoreIndex(dimension_size_type series) const = 0;
1140 
1147  virtual
1149  coreIndexToSeries(dimension_size_type index) const = 0;
1150 
1156  virtual
1158  getCoreIndex() const = 0;
1159 
1173  virtual
1174  void
1175  setCoreIndex(dimension_size_type index) const = 0;
1176 
1186  virtual
1188  getResolutionCount() const = 0;
1189 
1202  virtual
1203  void
1204  setResolution(dimension_size_type resolution) const = 0;
1205 
1213  virtual
1215  getResolution() const = 0;
1216 
1222  virtual
1223  bool
1224  hasFlattenedResolutions() const = 0;
1225 
1237  virtual
1238  void
1239  setFlattenedResolutions(bool flatten) = 0;
1240  };
1241 
1242  }
1243 }
1244 
1245 #endif // OME_BIOFORMATS_FORMATREADER_H
1246 
1247 /*
1248  * Local Variables:
1249  * mode:C++
1250  * End:
1251  */
Files must be grouped.
Definition: FormatReader.h:79
virtual FileGroupOption fileGroupOption(const std::string &id)=0
Returns an enum indicating that we cannot, must, or might group the files in this dataset...
virtual Modulo & getModuloT()=0
Get the Modulo subdivision of the T dimension.
virtual std::vector< ome::compat::shared_ptr< FormatReader > > getUnderlyingReaders() const =0
Get all underlying readers.
virtual uint32_t getRequiredDirectories(const std::vector< std::string > &files) const =0
Get required parent directories.
virtual void setFlattenedResolutions(bool flatten)=0
Set resolution flattening.
virtual void openBytes(dimension_size_type plane, VariantPixelBuffer &buf) const =0
Obtain an image plane.
virtual const MetadataMap & getGlobalMetadata() const =0
Get global metadata map.
virtual bool isOrderCertain() const =0
Get whether the dimension order and sizes are known, or merely guesses.
virtual void getLookupTable(dimension_size_type plane, VariantPixelBuffer &buf) const =0
Get the color lookup table associated with an image plane.
virtual bool isThumbnailSeries() const =0
Get whether the current series is a lower resolution copy of a different series.
A subdimension of Z, C, or T.
Definition: Modulo.h:57
Metadata key-value map using a restricted set of value types.
Definition: MetadataMap.h:79
uint32_t pixel_size_type
Size type for pixel bit depths.
Definition: Types.h:62
Interface for all biological file format readers and writers.
Definition: FormatHandler.h:64
virtual bool hasCompanionFiles() const =0
Does this format support multi-file datasets?
virtual void setNormalized(bool normalize)=0
Set float normalization.
virtual bool isIndexed() const =0
Get whether the image planes are indexed color.
virtual pixel_size_type getBitsPerPixel() const =0
Get the number of valid bits per pixel.
virtual const std::vector< boost::filesystem::path > getSeriesUsedFiles(bool noPixels=false) const =0
Get the files used by the active series.
Interface for all biological file format readers.
Definition: FormatReader.h:70
virtual bool isOriginalMetadataPopulated() const =0
Get proprietary metadata storage.
const FormatReader & reader
Reader for which the state will be saved and restored.
Definition: FormatReader.h:101
virtual std::vector< FileInfo > getAdvancedSeriesUsedFiles(bool noPixels=false) const =0
Get the files used by the active series.
virtual dimension_size_type getCoreIndex() const =0
Get the CoreMetadata index of the current resolution/series.
virtual dimension_size_type getSeries() const =0
Get the active series.
virtual dimension_size_type getEffectiveSizeC() const =0
Get the effective size of the C dimension.
virtual void setMetadataStore(ome::compat::shared_ptr< ::ome::xml::meta::MetadataStore > &store)=0
Set the default metadata store for this reader.
virtual dimension_size_type getThumbSizeX() const =0
Get the thumbnail size of the X dimension.
virtual dimension_size_type getSizeC() const =0
Get the size of the C dimension.
virtual dimension_size_type getIndex(dimension_size_type z, dimension_size_type c, dimension_size_type t) const =0
Get the linear index of a Z, C and T coordinate.
virtual bool isThisType(const boost::filesystem::path &name, bool open=true) const =0
Check if the given file is a valid instance of this file format.
virtual bool isMetadataFiltered() const =0
Get metadata filtering.
virtual dimension_size_type coreIndexToSeries(dimension_size_type index) const =0
Get the series corresponding to the specified core index.
virtual ~FormatReader()
Destructor.
Definition: FormatReader.h:150
virtual bool isSingleFile(const boost::filesystem::path &id) const =0
Is this a single-file format?
virtual dimension_size_type getSizeZ() const =0
Get the size of the Z dimension.
virtual Modulo & getModuloZ()=0
Get the Modulo subdivision of the Z dimension.
Array type substitution.
FormatReader()
Constructor.
Definition: FormatReader.h:136
Files may be grouped.
Definition: FormatReader.h:80
virtual void setResolution(dimension_size_type resolution) const =0
Set the active resolution level.
virtual dimension_size_type getOptimalTileWidth() const =0
Get the optimal sub-image width.
virtual const std::vector< std::string > & getPossibleDomains(const std::string &id) const =0
Get the possible domains represented in which this format is used.
virtual bool isRGB(dimension_size_type channel) const =0
Check if the image planes for a channel have more than one sub-channel per openBytes() call...
boost::make_variant_over< discriminated_types >::type value_type
Value type, allowing assignment of all storable types.
Definition: MetadataMap.h:150
SaveSeries(const FormatReader &reader)
Constructor.
Definition: FormatReader.h:111
virtual void setMetadataFiltered(bool filter)=0
Set metadata filtering.
virtual ome::xml::model::enums::PixelType getPixelType() const =0
Get the pixel type.
virtual const MetadataMap::value_type & getSeriesMetadataValue(const MetadataMap::key_type &field) const =0
Get a series metadata value.
Open Microscopy Environment C++ implementation.
Definition: CoreMetadata.cpp:40
std::string key_type
Key type.
Definition: MetadataMap.h:147
virtual ome::compat::array< dimension_size_type, 6 > getZCTModuloCoords(dimension_size_type index) const =0
Get the Z, C, T, ModuloZ, ModuloC and ModuloT coordinate of a linear index.
virtual dimension_size_type getSizeX() const =0
Get the size of the X dimension.
virtual bool isNormalized() const =0
Get float normalization.
virtual dimension_size_type getSizeT() const =0
Get the size of the T dimension.
virtual dimension_size_type seriesToCoreIndex(dimension_size_type series) const =0
Get the first core index corresponding to the specified series.
virtual dimension_size_type getResolutionCount() const =0
Get the number of resolutions for the current series.
virtual bool hasFlattenedResolutions() const =0
Get resolution flattening.
virtual void setCoreIndex(dimension_size_type index) const =0
Set the current resolution/series (ignoring sub-resolutions).
virtual dimension_size_type getSizeY() const =0
Get the size of the Y dimension.
Files can not be grouped.
Definition: FormatReader.h:81
virtual Modulo & getModuloC()=0
Get the Modulo subdivision of the C dimension.
Sentry for saving and restoring reader series state.
Definition: FormatReader.h:97
virtual const MetadataMap::value_type & getMetadataValue(const std::string &field) const =0
Get a global metadata value.
virtual bool isFalseColor() const =0
Get whether the image planes are false color.
Metadata configuration interface.
Definition: MetadataConfigurable.h:53
virtual ome::compat::array< dimension_size_type, 3 > getZCTCoords(dimension_size_type index) const =0
Get the Z, C and T coordinate of a linear index.
virtual void setGroupFiles(bool group)=0
Set file grouping.
virtual std::vector< FileInfo > getAdvancedUsedFiles(bool noPixels=false) const =0
Get the files used by this dataset.
virtual const std::vector< std::string > & getDomains() const =0
Get the domains represented by the current file.
virtual const MetadataMap & getSeriesMetadata() const =0
Get series metadata map.
virtual bool isInterleaved() const =0
Get whether or not the channels are interleaved.
virtual const std::vector< boost::filesystem::path > getUsedFiles(bool noPixels=false) const =0
Get the files used by this dataset.
virtual bool isMetadataComplete() const =0
Get status of metadata parsing.
virtual const boost::optional< boost::filesystem::path > & getCurrentFile() const =0
Get the currently open file.
FormatReader & operator=(const FormatReader &)
Assignment operator (deleted).
PixelType enumeration.
Definition: PixelType.h:70
FileGroupOption
File grouping options.
Definition: FormatReader.h:77
virtual dimension_size_type getThumbSizeY() const =0
Get the thumbnail size of the Y dimension.
~SaveSeries()
Destructor.
Definition: FormatReader.h:121
virtual dimension_size_type getImageCount() const =0
Determine the number of image planes in the current series.
dimension_size_type coreIndex
Saved state.
Definition: FormatReader.h:103
virtual const ome::compat::shared_ptr< ::ome::xml::meta::MetadataStore > & getMetadataStore() const =0
Get the current metadata store for this reader.
virtual dimension_size_type getSeriesCount() const =0
Get the number of image series in this file.
virtual const std::string & getDatasetStructureDescription() const =0
Get a short description of the dataset structure.
Buffer for all pixel types.
Definition: VariantPixelBuffer.h:72
virtual bool isGroupFiles() const =0
Get file grouping.
virtual bool isLittleEndian() const =0
Get whether the data is in little-endian format.
virtual const std::string & getDimensionOrder() const =0
Get the dimension order.
virtual void setSeries(dimension_size_type series) const =0
Set the active series.
virtual const std::vector< ome::compat::shared_ptr< CoreMetadata > > & getCoreMetadataList() const =0
Get the core metadata.
virtual void setOriginalMetadataPopulated(bool populate)=0
Specifies whether or not to save proprietary metadata in the MetadataStore.
virtual void openThumbBytes(dimension_size_type plane, VariantPixelBuffer &buf) const =0
Obtain a thumbnail of an image plane.
virtual dimension_size_type getRGBChannelCount(dimension_size_type channel) const =0
Get the number of channels returned for a call to openBytes().
virtual dimension_size_type getOptimalTileHeight() const =0
Get the optimal sub-image height.
std::size_t dimension_size_type
Size type for image dimensions.
Definition: Types.h:59
virtual dimension_size_type getResolution() const =0
Get the active resolution level.
virtual bool isThisType(const boost::filesystem::path &name, bool open=true) const =0
Check if the given file is a valid instance of this file format.