ome-files  0.3.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 
146  private:
148  FormatReader (const FormatReader&);
149 
151  FormatReader&
152  operator= (const FormatReader&);
153 
154  public:
156  virtual
158  {}
159 
160  // Documented in superclass.
161  virtual
162  bool
163  isThisType(const boost::filesystem::path& name,
164  bool open = true) const = 0;
165 
178  virtual
179  bool
180  isThisType(const uint8_t *begin,
181  const uint8_t *end) const = 0;
182 
195  virtual
196  bool
197  isThisType(const uint8_t *begin,
198  std::size_t length) const = 0;
199 
208  virtual
209  bool
210  isThisType(std::istream& stream) const = 0;
211 
217  virtual
219  getImageCount() const = 0;
220 
229  virtual
230  bool
231  isRGB(dimension_size_type channel) const = 0;
232 
238  virtual
240  getSizeX() const = 0;
241 
247  virtual
249  getSizeY() const = 0;
250 
256  virtual
258  getSizeZ() const = 0;
259 
265  virtual
267  getSizeT() const = 0;
268 
274  virtual
276  getSizeC() const = 0;
277 
283  virtual
285  getPixelType() const = 0;
286 
296  virtual
298  getBitsPerPixel() const = 0;
299 
311  virtual
313  getEffectiveSizeC() const = 0;
314 
326  virtual
328  getRGBChannelCount(dimension_size_type channel) const = 0;
329 
338  virtual
339  bool
340  isIndexed() const = 0;
341 
352  virtual
353  bool
354  isFalseColor() const = 0;
355 
372  virtual
373  void
375  VariantPixelBuffer& buf) const = 0;
376 
382  virtual
383  Modulo&
384  getModuloZ() = 0;
385 
391  virtual
392  const Modulo&
393  getModuloZ() const = 0;
394 
400  virtual
401  Modulo&
402  getModuloT() = 0;
403 
409  virtual
410  const Modulo&
411  getModuloT() const = 0;
412 
418  virtual
419  Modulo&
420  getModuloC() = 0;
421 
427  virtual
428  const Modulo&
429  getModuloC() const = 0;
430 
436  virtual
438  getThumbSizeX() const = 0;
439 
445  virtual
447  getThumbSizeY() const = 0;
448 
454  virtual
455  bool
456  isLittleEndian() const = 0;
457 
476  virtual
477  const std::string&
478  getDimensionOrder() const = 0;
479 
485  virtual
486  bool
487  isOrderCertain() const = 0;
488 
495  virtual
496  bool
497  isThumbnailSeries() const = 0;
498 
517  virtual
518  bool
519  isInterleaved() const = 0;
520 
534  virtual
535  bool
536  isInterleaved(dimension_size_type channel) const = 0;
537 
553  virtual
554  void
556  VariantPixelBuffer& buf) const = 0;
557 
577  virtual
578  void
580  VariantPixelBuffer& buf,
584  dimension_size_type h) const = 0;
585 
595  virtual
596  void
598  VariantPixelBuffer& buf) const = 0;
599 
608  virtual
610  getSeriesCount() const = 0;
611 
625  virtual
626  void
627  setSeries(dimension_size_type series) const = 0;
628 
634  virtual
636  getSeries() const = 0;
637 
646  virtual void
647  setPlane(dimension_size_type plane) const = 0;
648 
654  virtual dimension_size_type
655  getPlane() const = 0;
656 
663  virtual
664  void
665  setNormalized(bool normalize) = 0;
666 
674  virtual
675  bool
676  isNormalized() const = 0;
677 
682  virtual
683  void
684  setOriginalMetadataPopulated(bool populate) = 0;
685 
694  virtual
695  bool
696  isOriginalMetadataPopulated() const = 0;
697 
705  virtual
706  void
707  setGroupFiles(bool group) = 0;
708 
714  virtual
715  bool
716  isGroupFiles() const = 0;
717 
724  virtual
725  bool
726  isMetadataComplete() const = 0;
727 
735  virtual
737  fileGroupOption(const std::string& id) = 0;
738 
746  virtual
747  const std::vector<boost::filesystem::path>
748  getUsedFiles(bool noPixels = false) const = 0;
749 
757  virtual
758  const std::vector<boost::filesystem::path>
759  getSeriesUsedFiles(bool noPixels = false) const = 0;
760 
769  virtual
770  std::vector<FileInfo>
771  getAdvancedUsedFiles(bool noPixels = false) const = 0;
772 
781  virtual
782  std::vector<FileInfo>
783  getAdvancedSeriesUsedFiles(bool noPixels = false) const = 0;
784 
790  virtual
791  const boost::optional<boost::filesystem::path>&
792  getCurrentFile() const = 0;
793 
799  virtual
800  const std::vector<std::string>&
801  getDomains() const = 0;
802 
817  virtual
821  dimension_size_type t) const = 0;
822 
846  virtual
851  dimension_size_type moduloZ,
852  dimension_size_type moduloC,
853  dimension_size_type moduloT) const = 0;
854 
864  virtual
865  std::array<dimension_size_type, 3>
866  getZCTCoords(dimension_size_type index) const = 0;
867 
884  virtual
885  std::array<dimension_size_type, 6>
886  getZCTModuloCoords(dimension_size_type index) const = 0;
887 
899  virtual
901  getMetadataValue(const std::string& field) const = 0;
902 
914  virtual
916  getSeriesMetadataValue(const MetadataMap::key_type& field) const = 0;
917 
926  virtual
927  const MetadataMap&
928  getGlobalMetadata() const = 0;
929 
938  virtual
939  const MetadataMap&
940  getSeriesMetadata() const = 0;
941 
950  virtual
951  const std::vector<std::shared_ptr<CoreMetadata>>&
952  getCoreMetadataList() const = 0;
953 
964  virtual
965  void
966  setMetadataFiltered(bool filter) = 0;
967 
974  virtual
975  bool
976  isMetadataFiltered() const = 0;
977 
983  virtual
984  void
985  setMetadataStore(std::shared_ptr<::ome::xml::meta::MetadataStore>& store) = 0;
986 
992  virtual
993  const std::shared_ptr<::ome::xml::meta::MetadataStore>&
994  getMetadataStore() const = 0;
995 
1001  virtual
1002  std::shared_ptr<::ome::xml::meta::MetadataStore>&
1003  getMetadataStore() = 0;
1004 
1013  virtual
1014  std::vector<std::shared_ptr<FormatReader>>
1015  getUnderlyingReaders() const = 0;
1016 
1027  virtual
1028  bool
1029  isSingleFile(const boost::filesystem::path& id) const = 0;
1030 
1061  virtual
1062  uint32_t
1063  getRequiredDirectories(const std::vector<std::string>& files) const = 0;
1064 
1070  virtual
1071  const std::string&
1072  getDatasetStructureDescription() const = 0;
1073 
1084  virtual
1085  const std::vector<std::string>&
1086  getPossibleDomains(const std::string& id) const = 0;
1087 
1094  virtual
1095  bool
1096  hasCompanionFiles() const = 0;
1097 
1106  virtual
1108  getOptimalTileWidth(dimension_size_type channel) const = 0;
1109 
1118  virtual
1120  getOptimalTileHeight(dimension_size_type channel) const = 0;
1121 
1135  virtual
1137  getOptimalTileWidth() const = 0;
1138 
1152  virtual
1154  getOptimalTileHeight() const = 0;
1155 
1156  // Sub-resolution API methods
1157 
1164  virtual
1166  seriesToCoreIndex(dimension_size_type series) const = 0;
1167 
1174  virtual
1176  coreIndexToSeries(dimension_size_type index) const = 0;
1177 
1183  virtual
1185  getCoreIndex() const = 0;
1186 
1200  virtual
1201  void
1202  setCoreIndex(dimension_size_type index) const = 0;
1203 
1213  virtual
1215  getResolutionCount() const = 0;
1216 
1231  virtual
1232  void
1233  setResolution(dimension_size_type resolution) const = 0;
1234 
1242  virtual
1244  getResolution() const = 0;
1245 
1251  virtual
1252  bool
1253  hasFlattenedResolutions() const = 0;
1254 
1266  virtual
1267  void
1268  setFlattenedResolutions(bool flatten) = 0;
1269  };
1270 
1271  }
1272 }
1273 
1274 #endif // OME_FILES_FORMATREADER_H
1275 
1276 /*
1277  * Local Variables:
1278  * mode:C++
1279  * End:
1280  */
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.
FormatReader & operator=(const FormatReader &)
Assignment operator (deleted).
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:157
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:75
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.