bioformats  5.1.0
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 
221  virtual
222  bool
223  isRGB() const = 0;
224 
230  virtual
232  getSizeX() const = 0;
233 
239  virtual
241  getSizeY() const = 0;
242 
248  virtual
250  getSizeZ() const = 0;
251 
257  virtual
259  getSizeT() const = 0;
260 
266  virtual
268  getSizeC() const = 0;
269 
275  virtual
277  getPixelType() const = 0;
278 
288  virtual
290  getBitsPerPixel() const = 0;
291 
303  virtual
305  getEffectiveSizeC() const = 0;
306 
317  virtual
319  getRGBChannelCount() const = 0;
320 
329  virtual
330  bool
331  isIndexed() const = 0;
332 
343  virtual
344  bool
345  isFalseColor() const = 0;
346 
363  virtual
364  void
366  dimension_size_type no = 0U) const = 0;
367 
373  virtual
374  Modulo&
375  getModuloZ() = 0;
376 
382  virtual
383  const Modulo&
384  getModuloZ() const = 0;
385 
391  virtual
392  Modulo&
393  getModuloT() = 0;
394 
400  virtual
401  const Modulo&
402  getModuloT() const = 0;
403 
409  virtual
410  Modulo&
411  getModuloC() = 0;
412 
418  virtual
419  const Modulo&
420  getModuloC() const = 0;
421 
427  virtual
429  getThumbSizeX() const = 0;
430 
436  virtual
438  getThumbSizeY() const = 0;
439 
445  virtual
446  bool
447  isLittleEndian() const = 0;
448 
467  virtual
468  const std::string&
469  getDimensionOrder() const = 0;
470 
476  virtual
477  bool
478  isOrderCertain() const = 0;
479 
486  virtual
487  bool
488  isThumbnailSeries() const = 0;
489 
508  virtual
509  bool
510  isInterleaved() const = 0;
511 
525  virtual
526  bool
527  isInterleaved(dimension_size_type subC) const = 0;
528 
544  virtual
545  void
547  VariantPixelBuffer& buf) const = 0;
548 
568  virtual
569  void
571  VariantPixelBuffer& buf,
575  dimension_size_type h) const = 0;
576 
586  virtual
587  void
589  VariantPixelBuffer& buf) const = 0;
590 
599  virtual
601  getSeriesCount() const = 0;
602 
615  virtual
616  void
617  setSeries(dimension_size_type no) const = 0;
618 
624  virtual
626  getSeries() const = 0;
627 
634  virtual
635  void
636  setNormalized(bool normalize) = 0;
637 
645  virtual
646  bool
647  isNormalized() const = 0;
648 
653  virtual
654  void
655  setOriginalMetadataPopulated(bool populate) = 0;
656 
665  virtual
666  bool
667  isOriginalMetadataPopulated() const = 0;
668 
676  virtual
677  void
678  setGroupFiles(bool group) = 0;
679 
685  virtual
686  bool
687  isGroupFiles() const = 0;
688 
695  virtual
696  bool
697  isMetadataComplete() const = 0;
698 
706  virtual
708  fileGroupOption(const std::string& id) = 0;
709 
717  virtual
718  const std::vector<boost::filesystem::path>
719  getUsedFiles(bool noPixels = false) const = 0;
720 
728  virtual
729  const std::vector<boost::filesystem::path>
730  getSeriesUsedFiles(bool noPixels = false) const = 0;
731 
740  virtual
741  std::vector<FileInfo>
742  getAdvancedUsedFiles(bool noPixels = false) const = 0;
743 
752  virtual
753  std::vector<FileInfo>
754  getAdvancedSeriesUsedFiles(bool noPixels = false) const = 0;
755 
761  virtual
762  const boost::optional<boost::filesystem::path>&
763  getCurrentFile() const = 0;
764 
770  virtual
771  const std::vector<std::string>&
772  getDomains() const = 0;
773 
788  virtual
792  dimension_size_type t) const = 0;
793 
817  virtual
822  dimension_size_type moduloZ,
823  dimension_size_type moduloC,
824  dimension_size_type moduloT) const = 0;
825 
835  virtual
836  ome::compat::array<dimension_size_type, 3>
837  getZCTCoords(dimension_size_type index) const = 0;
838 
855  virtual
856  ome::compat::array<dimension_size_type, 6>
857  getZCTModuloCoords(dimension_size_type index) const = 0;
858 
870  virtual
872  getMetadataValue(const std::string& field) const = 0;
873 
885  virtual
887  getSeriesMetadataValue(const MetadataMap::key_type& field) const = 0;
888 
897  virtual
898  const MetadataMap&
899  getGlobalMetadata() const = 0;
900 
909  virtual
910  const MetadataMap&
911  getSeriesMetadata() const = 0;
912 
921  virtual
922  const std::vector<ome::compat::shared_ptr<CoreMetadata> >&
923  getCoreMetadataList() const = 0;
924 
935  virtual
936  void
937  setMetadataFiltered(bool filter) = 0;
938 
945  virtual
946  bool
947  isMetadataFiltered() const = 0;
948 
954  virtual
955  void
956  setMetadataStore(ome::compat::shared_ptr< ::ome::xml::meta::MetadataStore>& store) = 0;
957 
963  virtual
964  const ome::compat::shared_ptr< ::ome::xml::meta::MetadataStore>&
965  getMetadataStore() const = 0;
966 
972  virtual
973  ome::compat::shared_ptr< ::ome::xml::meta::MetadataStore>&
974  getMetadataStore() = 0;
975 
984  virtual
985  std::vector<ome::compat::shared_ptr<FormatReader> >
986  getUnderlyingReaders() const = 0;
987 
998  virtual
999  bool
1000  isSingleFile(const boost::filesystem::path& id) const = 0;
1001 
1032  virtual
1033  uint32_t
1034  getRequiredDirectories(const std::vector<std::string>& files) const = 0;
1035 
1041  virtual
1042  const std::string&
1043  getDatasetStructureDescription() const = 0;
1044 
1055  virtual
1056  const std::vector<std::string>&
1057  getPossibleDomains(const std::string& id) const = 0;
1058 
1065  virtual
1066  bool
1067  hasCompanionFiles() const = 0;
1068 
1075  virtual
1077  getOptimalTileWidth() const = 0;
1078 
1085  virtual
1087  getOptimalTileHeight() const = 0;
1088 
1089  // Sub-resolution API methods
1090 
1097  virtual
1099  seriesToCoreIndex(dimension_size_type series) const = 0;
1100 
1107  virtual
1109  coreIndexToSeries(dimension_size_type index) const = 0;
1110 
1116  virtual
1118  getCoreIndex() const = 0;
1119 
1133  virtual
1134  void
1135  setCoreIndex(dimension_size_type index) const = 0;
1136 
1146  virtual
1148  getResolutionCount() const = 0;
1149 
1162  virtual
1163  void
1164  setResolution(dimension_size_type resolution) const = 0;
1165 
1173  virtual
1175  getResolution() const = 0;
1176 
1182  virtual
1183  bool
1184  hasFlattenedResolutions() const = 0;
1185 
1197  virtual
1198  void
1199  setFlattenedResolutions(bool flatten) = 0;
1200  };
1201 
1202  }
1203 }
1204 
1205 #endif // OME_BIOFORMATS_FORMATREADER_H
1206 
1207 /*
1208  * Local Variables:
1209  * mode:C++
1210  * End:
1211  */
Files must be grouped.
Definition: FormatReader.h:79
virtual bool isRGB() const =0
Check if the image planes in the file have more than one channel per openBytes() call.
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 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 bool isThumbnailSeries() const =0
Get whether the current series is a lower resolution copy of a different series.
virtual void openThumbBytes(dimension_size_type no, VariantPixelBuffer &buf) const =0
Obtain a thumbnail of an image plane.
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 void setSeries(dimension_size_type no) const =0
Set the active series.
virtual const std::vector< std::string > & getPossibleDomains(const std::string &id) const =0
Get the possible domains represented in which this format is used.
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 void getLookupTable(VariantPixelBuffer &buf, dimension_size_type no=0U) const =0
Get the color lookup table associated with an image plane.
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 subresolutions).
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 file.
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 void openBytes(dimension_size_type no, VariantPixelBuffer &buf) const =0
Obtain an image plane.
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 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 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.
virtual dimension_size_type getRGBChannelCount() const =0
Get the number of channels returned with each call to openBytes().