ome-files  0.5.0
FormatReader.h
1 /*
2  * #%L
3  * OME-FILES 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_FILES_FORMATREADER_H
39 #define OME_FILES_FORMATREADER_H
40 
41 #include <array>
42 #include <memory>
43 #include <string>
44 #include <vector>
45 #include <map>
46 
47 #include <boost/optional.hpp>
48 
49 #include <ome/compat/memory.h>
50 
51 #include <ome/files/CoreMetadata.h>
52 #include <ome/files/FileInfo.h>
53 #include <ome/files/FormatHandler.h>
54 #include <ome/files/MetadataConfigurable.h>
55 #include <ome/files/MetadataMap.h>
56 #include <ome/files/Types.h>
57 
58 #include <ome/xml/meta/MetadataStore.h>
59 
60 namespace ome
61 {
62  namespace files
63  {
64 
65  class VariantPixelBuffer;
66 
72  class FormatReader : virtual public FormatHandler,
73  virtual public MetadataConfigurable
74  {
75  public:
77 
80  {
84  };
85 
86  protected:
99  class SaveSeries
100  {
101  private:
108 
109  public:
115  SaveSeries(const FormatReader& reader):
116  reader(reader),
117  coreIndex(reader.getCoreIndex()),
118  plane(reader.getPlane())
119  {}
120 
127  {
128  try
129  {
130  if (coreIndex != reader.getCoreIndex())
131  reader.setCoreIndex(coreIndex);
132  if (plane != reader.getPlane())
133  reader.setPlane(plane);
134  }
135  catch (...)
136  {
137  // We can't throw in a destructor.
138  }
139  }
140  };
141 
144  {}
145 
147  FormatReader (const FormatReader&) = delete;
148 
149  FormatReader&
150  operator= (const FormatReader&) = delete;
152 
153  public:
155  virtual
157  {}
158 
159  // Documented in superclass.
160  virtual
161  bool
162  isThisType(const boost::filesystem::path& name,
163  bool open = true) const = 0;
164 
177  virtual
178  bool
179  isThisType(const uint8_t *begin,
180  const uint8_t *end) const = 0;
181 
194  virtual
195  bool
196  isThisType(const uint8_t *begin,
197  std::size_t length) const = 0;
198 
207  virtual
208  bool
209  isThisType(std::istream& stream) const = 0;
210 
216  virtual
218  getImageCount() const = 0;
219 
228  virtual
229  bool
230  isRGB(dimension_size_type channel) const = 0;
231 
237  virtual
239  getSizeX() const = 0;
240 
246  virtual
248  getSizeY() const = 0;
249 
255  virtual
257  getSizeZ() const = 0;
258 
264  virtual
266  getSizeT() const = 0;
267 
273  virtual
275  getSizeC() const = 0;
276 
282  virtual
284  getPixelType() const = 0;
285 
295  virtual
297  getBitsPerPixel() const = 0;
298 
310  virtual
312  getEffectiveSizeC() const = 0;
313 
325  virtual
327  getRGBChannelCount(dimension_size_type channel) const = 0;
328 
337  virtual
338  bool
339  isIndexed() const = 0;
340 
351  virtual
352  bool
353  isFalseColor() const = 0;
354 
371  virtual
372  void
374  VariantPixelBuffer& buf) const = 0;
375 
381  virtual
382  Modulo&
383  getModuloZ() = 0;
384 
390  virtual
391  const Modulo&
392  getModuloZ() const = 0;
393 
399  virtual
400  Modulo&
401  getModuloT() = 0;
402 
408  virtual
409  const Modulo&
410  getModuloT() const = 0;
411 
417  virtual
418  Modulo&
419  getModuloC() = 0;
420 
426  virtual
427  const Modulo&
428  getModuloC() const = 0;
429 
435  virtual
437  getThumbSizeX() const = 0;
438 
444  virtual
446  getThumbSizeY() const = 0;
447 
453  virtual
454  bool
455  isLittleEndian() const = 0;
456 
475  virtual
476  const std::string&
477  getDimensionOrder() const = 0;
478 
484  virtual
485  bool
486  isOrderCertain() const = 0;
487 
494  virtual
495  bool
496  isThumbnailSeries() const = 0;
497 
516  virtual
517  bool
518  isInterleaved() const = 0;
519 
533  virtual
534  bool
535  isInterleaved(dimension_size_type channel) const = 0;
536 
552  virtual
553  void
555  VariantPixelBuffer& buf) const = 0;
556 
576  virtual
577  void
579  VariantPixelBuffer& buf,
583  dimension_size_type h) const = 0;
584 
594  virtual
595  void
597  VariantPixelBuffer& buf) const = 0;
598 
607  virtual
609  getSeriesCount() const = 0;
610 
624  virtual
625  void
626  setSeries(dimension_size_type series) const = 0;
627 
633  virtual
635  getSeries() const = 0;
636 
645  virtual void
646  setPlane(dimension_size_type plane) const = 0;
647 
653  virtual dimension_size_type
654  getPlane() const = 0;
655 
662  virtual
663  void
664  setNormalized(bool normalize) = 0;
665 
673  virtual
674  bool
675  isNormalized() const = 0;
676 
683  virtual
684  void
685  setOriginalMetadataPopulated(bool populate) = 0;
686 
695  virtual
696  bool
697  isOriginalMetadataPopulated() const = 0;
698 
706  virtual
707  void
708  setGroupFiles(bool group) = 0;
709 
715  virtual
716  bool
717  isGroupFiles() const = 0;
718 
725  virtual
726  bool
727  isMetadataComplete() const = 0;
728 
736  virtual
738  fileGroupOption(const std::string& id) = 0;
739 
747  virtual
748  const std::vector<boost::filesystem::path>
749  getUsedFiles(bool noPixels = false) const = 0;
750 
758  virtual
759  const std::vector<boost::filesystem::path>
760  getSeriesUsedFiles(bool noPixels = false) const = 0;
761 
770  virtual
771  std::vector<FileInfo>
772  getAdvancedUsedFiles(bool noPixels = false) const = 0;
773 
782  virtual
783  std::vector<FileInfo>
784  getAdvancedSeriesUsedFiles(bool noPixels = false) const = 0;
785 
791  virtual
792  const boost::optional<boost::filesystem::path>&
793  getCurrentFile() const = 0;
794 
800  virtual
801  const std::vector<std::string>&
802  getDomains() const = 0;
803 
818  virtual
822  dimension_size_type t) const = 0;
823 
847  virtual
852  dimension_size_type moduloZ,
853  dimension_size_type moduloC,
854  dimension_size_type moduloT) const = 0;
855 
865  virtual
866  std::array<dimension_size_type, 3>
867  getZCTCoords(dimension_size_type index) const = 0;
868 
885  virtual
886  std::array<dimension_size_type, 6>
887  getZCTModuloCoords(dimension_size_type index) const = 0;
888 
900  virtual
902  getMetadataValue(const std::string& field) const = 0;
903 
915  virtual
917  getSeriesMetadataValue(const MetadataMap::key_type& field) const = 0;
918 
927  virtual
928  const MetadataMap&
929  getGlobalMetadata() const = 0;
930 
939  virtual
940  const MetadataMap&
941  getSeriesMetadata() const = 0;
942 
951  virtual
952  const std::vector<std::shared_ptr<CoreMetadata>>&
953  getCoreMetadataList() const = 0;
954 
965  virtual
966  void
967  setMetadataFiltered(bool filter) = 0;
968 
975  virtual
976  bool
977  isMetadataFiltered() const = 0;
978 
984  virtual
985  void
986  setMetadataStore(std::shared_ptr<::ome::xml::meta::MetadataStore>& store) = 0;
987 
993  virtual
994  const std::shared_ptr<::ome::xml::meta::MetadataStore>&
995  getMetadataStore() const = 0;
996 
1002  virtual
1003  std::shared_ptr<::ome::xml::meta::MetadataStore>&
1004  getMetadataStore() = 0;
1005 
1014  virtual
1015  std::vector<std::shared_ptr<FormatReader>>
1016  getUnderlyingReaders() const = 0;
1017 
1028  virtual
1029  bool
1030  isSingleFile(const boost::filesystem::path& id) const = 0;
1031 
1062  virtual
1063  uint32_t
1064  getRequiredDirectories(const std::vector<std::string>& files) const = 0;
1065 
1071  virtual
1072  const std::string&
1073  getDatasetStructureDescription() const = 0;
1074 
1085  virtual
1086  const std::vector<std::string>&
1087  getPossibleDomains(const std::string& id) const = 0;
1088 
1095  virtual
1096  bool
1097  hasCompanionFiles() const = 0;
1098 
1107  virtual
1109  getOptimalTileWidth(dimension_size_type channel) const = 0;
1110 
1119  virtual
1121  getOptimalTileHeight(dimension_size_type channel) const = 0;
1122 
1136  virtual
1138  getOptimalTileWidth() const = 0;
1139 
1153  virtual
1155  getOptimalTileHeight() const = 0;
1156 
1157  // Sub-resolution API methods
1158 
1165  virtual
1167  seriesToCoreIndex(dimension_size_type series) const = 0;
1168 
1175  virtual
1177  coreIndexToSeries(dimension_size_type index) const = 0;
1178 
1184  virtual
1186  getCoreIndex() const = 0;
1187 
1201  virtual
1202  void
1203  setCoreIndex(dimension_size_type index) const = 0;
1204 
1214  virtual
1216  getResolutionCount() const = 0;
1217 
1232  virtual
1233  void
1234  setResolution(dimension_size_type resolution) const = 0;
1235 
1243  virtual
1245  getResolution() const = 0;
1246 
1252  virtual
1253  bool
1254  hasFlattenedResolutions() const = 0;
1255 
1267  virtual
1268  void
1269  setFlattenedResolutions(bool flatten) = 0;
1270  };
1271 
1272  }
1273 }
1274 
1275 #endif // OME_FILES_FORMATREADER_H
1276 
1277 /*
1278  * Local Variables:
1279  * mode:C++
1280  * End:
1281  */
virtual Modulo & getModuloT()=0
Get the Modulo subdivision of the T dimension.
virtual const MetadataMap::value_type & getMetadataValue(const std::string &field) const =0
Get a global metadata value.
virtual const std::string & getDimensionOrder() const =0
Get the dimension order.
virtual const std::vector< std::string > & getDomains() const =0
Get the domains represented by the current file.
virtual bool isNormalized() const =0
Get float normalization.
virtual const std::vector< std::shared_ptr< CoreMetadata > > & getCoreMetadataList() const =0
Get the core metadata.
virtual dimension_size_type getPlane() const =0
Get the active plane.
virtual dimension_size_type coreIndexToSeries(dimension_size_type index) const =0
Get the series corresponding to the specified core index.
virtual dimension_size_type getImageCount() const =0
Determine the number of image planes in the current series.
virtual const MetadataMap & getSeriesMetadata() const =0
Get series metadata map.
virtual pixel_size_type getBitsPerPixel() const =0
Get the number of valid bits per pixel.
virtual bool isLittleEndian() const =0
Get whether the data is in little-endian format.
virtual void setCoreIndex(dimension_size_type index) const =0
Set the current resolution/series (ignoring sub-resolutions).
Files may be grouped.
Definition: FormatReader.h:82
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.
uint32_t pixel_size_type
Size type for pixel bit depths.
Definition: Types.h:61
virtual dimension_size_type getSizeX() const =0
Get the size of the X dimension.
virtual dimension_size_type getResolutionCount() const =0
Get the number of resolutions for the current series.
virtual bool isOrderCertain() const =0
Get whether the dimension order and sizes are known, or merely guesses.
virtual bool isOriginalMetadataPopulated() const =0
Get proprietary metadata storage.
std::size_t dimension_size_type
Size type for image dimensions.
Definition: Types.h:58
virtual void setFlattenedResolutions(bool flatten)=0
Set resolution flattening.
virtual std::vector< std::shared_ptr< FormatReader > > getUnderlyingReaders() const =0
Get all underlying readers.
~SaveSeries()
Destructor.
Definition: FormatReader.h:126
virtual Modulo & getModuloC()=0
Get the Modulo subdivision of the C dimension.
virtual std::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 std::array< dimension_size_type, 3 > getZCTCoords(dimension_size_type index) const =0
Get the Z, C and T coordinate of a linear index.
boost::make_variant_over< discriminated_types >::type value_type
Value type, allowing assignment of all storable types.
Definition: MetadataMap.h:147
Sentry for saving and restoring reader series state.
Definition: FormatReader.h:99
FileGroupOption
File grouping options.
Definition: FormatReader.h:79
virtual void setResolution(dimension_size_type resolution) const =0
Set the active resolution level.
Metadata key-value map using a restricted set of value types.
Definition: MetadataMap.h:79
virtual dimension_size_type getSeriesCount() const =0
Get the number of image series in this file.
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.
virtual const std::vector< boost::filesystem::path > getUsedFiles(bool noPixels=false) const =0
Get the files used by this dataset.
virtual bool hasFlattenedResolutions() const =0
Get resolution flattening.
virtual dimension_size_type getSizeZ() const =0
Get the size of the Z dimension.
virtual dimension_size_type getThumbSizeX() const =0
Get the thumbnail size of the X dimension.
virtual const boost::optional< boost::filesystem::path > & getCurrentFile() const =0
Get the currently open file.
virtual const MetadataMap & getGlobalMetadata() const =0
Get global metadata map.
dimension_size_type coreIndex
Saved core index.
Definition: FormatReader.h:105
virtual bool isIndexed() const =0
Get whether the image planes are indexed color.
const FormatReader & reader
Reader for which the state will be saved and restored.
Definition: FormatReader.h:103
virtual dimension_size_type seriesToCoreIndex(dimension_size_type series) const =0
Get the first core index corresponding to the specified series.
virtual void setGroupFiles(bool group)=0
Set file grouping.
Open Microscopy Environment C++.
virtual bool isMetadataComplete() const =0
Get status of metadata parsing.
virtual const std::vector< boost::filesystem::path > getSeriesUsedFiles(bool noPixels=false) const =0
Get the files used by the active series.
virtual void setOriginalMetadataPopulated(bool populate)=0
Specifies whether or not to save proprietary metadata in the MetadataStore.
virtual void getLookupTable(dimension_size_type plane, VariantPixelBuffer &buf) const =0
Get the color lookup table associated with an image plane.
virtual dimension_size_type getSizeC() const =0
Get the size of the C dimension.
virtual dimension_size_type getEffectiveSizeC() const =0
Get the effective size of the C dimension.
virtual bool isSingleFile(const boost::filesystem::path &id) const =0
Is this a single-file format?
virtual void openBytes(dimension_size_type plane, VariantPixelBuffer &buf) const =0
Obtain an image plane.
std::string key_type
Key type.
Definition: MetadataMap.h:144
virtual dimension_size_type getThumbSizeY() const =0
Get the thumbnail size of the Y dimension.
virtual bool isMetadataFiltered() const =0
Get metadata filtering.
virtual dimension_size_type getResolution() const =0
Get the active resolution level.
Files can not be grouped.
Definition: FormatReader.h:83
virtual dimension_size_type getSizeT() const =0
Get the size of the T dimension.
virtual bool hasCompanionFiles() const =0
Does this format support multi-file datasets?
virtual ~FormatReader()
Destructor.
Definition: FormatReader.h:156
virtual std::vector< FileInfo > getAdvancedSeriesUsedFiles(bool noPixels=false) const =0
Get the files used by the active series.
Metadata configuration interface.
Definition: MetadataConfigurable.h:53
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 FileGroupOption fileGroupOption(const std::string &id)=0
Returns an enum indicating that we cannot, must, or might group the files in this dataset...
Files must be grouped.
Definition: FormatReader.h:81
virtual void setMetadataStore(std::shared_ptr<::ome::xml::meta::MetadataStore > &store)=0
Set the default metadata store for this reader.
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 uint32_t getRequiredDirectories(const std::vector< std::string > &files) const =0
Get required parent directories.
virtual bool isInterleaved() const =0
Get whether or not the channels are interleaved.
virtual void setPlane(dimension_size_type plane) const =0
Set the active plane.
virtual ome::xml::model::enums::PixelType getPixelType() const =0
Get the pixel type.
virtual void openThumbBytes(dimension_size_type plane, VariantPixelBuffer &buf) const =0
Obtain a thumbnail of an image plane.
virtual dimension_size_type getSizeY() const =0
Get the size of the Y dimension.
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...
virtual bool isFalseColor() const =0
Get whether the image planes are false color.
dimension_size_type plane
Saved plane index.
Definition: FormatReader.h:107
virtual bool isGroupFiles() const =0
Get file grouping.
virtual void setSeries(dimension_size_type series) const =0
Set the active series.
virtual void setNormalized(bool normalize)=0
Set float normalization.
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 std::vector< FileInfo > getAdvancedUsedFiles(bool noPixels=false) const =0
Get the files used by this dataset.
Interface for all biological file format readers.
Definition: FormatReader.h:72
virtual void setMetadataFiltered(bool filter)=0
Set metadata filtering.
A subdimension of Z, C, or T.
Definition: Modulo.h:56
virtual bool isThumbnailSeries() const =0
Get whether the current series is a lower resolution copy of a different series.
virtual const std::shared_ptr<::ome::xml::meta::MetadataStore > & getMetadataStore() const =0
Get the current metadata store for this reader.
virtual const MetadataMap::value_type & getSeriesMetadataValue(const MetadataMap::key_type &field) const =0
Get a series metadata value.
virtual dimension_size_type getOptimalTileWidth() const =0
Get the optimal sub-image width.
Buffer for all pixel types.
Definition: VariantPixelBuffer.h:78
virtual Modulo & getModuloZ()=0
Get the Modulo subdivision of the Z dimension.
virtual dimension_size_type getSeries() const =0
Get the active series.
Interface for all biological file format readers and writers.
Definition: FormatHandler.h:63
FormatReader()
Constructor.
Definition: FormatReader.h:143
virtual const std::string & getDatasetStructureDescription() const =0
Get a short description of the dataset structure.
SaveSeries(const FormatReader &reader)
Constructor.
Definition: FormatReader.h:115
virtual dimension_size_type getCoreIndex() const =0
Get the CoreMetadata index of the current resolution/series.