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_DETAIL_FORMATREADER_H
39 #define OME_FILES_DETAIL_FORMATREADER_H
40 
41 #include <string>
42 #include <vector>
43 #include <map>
44 
45 #include <ome/files/FormatReader.h>
46 #include <ome/files/FormatHandler.h>
47 
48 namespace ome
49 {
50  namespace files
51  {
58  namespace detail
59  {
60 
65  {
67  std::string name;
69  std::string description;
71  std::vector<boost::filesystem::path> suffixes;
73  std::vector<boost::filesystem::path> compression_suffixes;
75  std::set<MetadataOptions::MetadataLevel> metadata_levels;
76 
83  ReaderProperties(const std::string& name,
84  const std::string& description):
85  name(name),
86  description(description),
87  suffixes(),
88  compression_suffixes(),
89  metadata_levels()
90  {
91  compression_suffixes.push_back(boost::filesystem::path(""));
92  }
93  };
94 
108  virtual public ::ome::files::FormatHandler
109  {
110  protected:
112  typedef std::vector<std::shared_ptr<::ome::files::CoreMetadata>> coremetadata_list_type;
113 
116 
118  boost::optional<boost::filesystem::path> currentId;
119 
121  std::shared_ptr<std::istream> in;
122 
125 
133 
141 
149 
151  coremetadata_list_type core;
152 
160 
163 
170 
176 
179 
181  std::string datasetDescription;
182 
185 
188 
191 
194 
196  bool group;
197 
199  std::vector<std::string> domains;
200 
205  std::shared_ptr<::ome::xml::meta::MetadataStore> metadataStore;
206 
209 
212 
214  FormatReader (const FormatReader&) = delete;
215 
216  FormatReader&
217  operator= (const FormatReader&) = delete;
219 
220  public:
222  virtual
223  ~FormatReader();
224 
225  protected:
240  virtual
241  void
242  initFile(const boost::filesystem::path& id);
243 
250  virtual
251  bool
252  isUsedFile(const boost::filesystem::path& file);
253 
268  virtual
269  void
270  readPlane(std::istream& source,
271  VariantPixelBuffer& dest,
276  dimension_size_type samples);
277 
293  virtual
294  void
295  readPlane(std::istream& source,
296  VariantPixelBuffer& dest,
301  dimension_size_type scanlinePad,
302  dimension_size_type samples);
303 
312  virtual
313  std::shared_ptr<::ome::xml::meta::MetadataStore>
314  makeFilterMetadata();
315 
324  const CoreMetadata&
326  {
327  coremetadata_list_type::value_type cm(core.at(index));
328  if (!cm)
329  throw std::logic_error("CoreMetadata null");
330  return *cm;
331  }
332 
341  CoreMetadata&
343  {
344  coremetadata_list_type::value_type cm(core.at(index));
345  if (!cm)
346  throw std::logic_error("CoreMetadata null");
347  return *cm;
348  }
349 
350  public:
351  // Documented in superclass.
352  const std::set<MetadataOptions::MetadataLevel>&
353  getSupportedMetadataLevels();
354 
355  // Documented in superclass.
356  void
357  setMetadataOptions(const MetadataOptions& options);
358 
359  // Documented in superclass.
360  const MetadataOptions&
361  getMetadataOptions() const;
362 
364  getMetadataOptions();
365 
366  // Documented in superclass.
367  const MetadataMap&
368  getGlobalMetadata() const;
369 
370  // Documented in superclass.
372  getMetadataValue(const std::string& field) const;
373 
374  // Documented in superclass.
375  const MetadataMap&
376  getSeriesMetadata() const;
377 
378  // Documented in superclass.
380  getSeriesMetadataValue(const MetadataMap::key_type& field) const;
381 
382  // Documented in superclass.
383  bool
384  isThisType(const boost::filesystem::path& name,
385  bool open = true) const;
386 
387  // Documented in superclass.
388  bool
389  isThisType(const uint8_t *begin,
390  std::size_t length) const;
391 
392  // Documented in superclass.
393  bool
394  isThisType(const uint8_t *begin,
395  const uint8_t *end) const;
396 
397  // Documented in superclass.
398  bool
399  isThisType(std::istream& stream) const;
400 
401  protected:
414  virtual
415  bool
416  isFilenameThisTypeImpl(const boost::filesystem::path& name) const;
417 
430  virtual
431  bool
432  isStreamThisTypeImpl(std::istream& stream) const;
433 
434  public:
435  // Documented in superclass.
437  getImageCount() const;
438 
439  // Documented in superclass.
440  bool
441  isRGB(dimension_size_type channel) const;
442 
443  // Documented in superclass.
445  getSizeX() const;
446 
447  // Documented in superclass.
449  getSizeY() const;
450 
451  // Documented in superclass.
453  getSizeZ() const;
454 
455  // Documented in superclass.
457  getSizeT() const;
458 
459  // Documented in superclass.
461  getSizeC() const;
462 
463  // Documented in superclass.
465  getPixelType() const;
466 
467  // Documented in superclass.
469  getBitsPerPixel() const;
470 
471  // Documented in superclass.
473  getEffectiveSizeC() const;
474 
475  // Documented in superclass.
477  getRGBChannelCount(dimension_size_type channel) const;
478 
479  // Documented in superclass.
480  bool
481  isIndexed() const;
482 
483  // Documented in superclass.
484  bool
485  isFalseColor() const;
486 
487  // Documented in superclass.
488  void
489  getLookupTable(dimension_size_type plane,
490  VariantPixelBuffer& buf) const;
491 
492  // Documented in superclass.
493  Modulo&
494  getModuloZ();
495 
496  // Documented in superclass.
497  const Modulo&
498  getModuloZ() const;
499 
500  // Documented in superclass.
501  Modulo&
502  getModuloT();
503 
504  // Documented in superclass.
505  const Modulo&
506  getModuloT() const;
507 
508  // Documented in superclass.
509  Modulo&
510  getModuloC();
511 
512  // Documented in superclass.
513  const Modulo&
514  getModuloC() const;
515 
516  protected:
523  std::array<dimension_size_type, 2>
524  getThumbSize() const;
525 
526  public:
527  // Documented in superclass.
529  getThumbSizeX() const;
530 
531  // Documented in superclass.
533  getThumbSizeY() const;
534 
535  // Documented in superclass.
536  bool
537  isLittleEndian() const;
538 
539  // Documented in superclass.
540  const std::string&
541  getDimensionOrder() const;
542 
543  // Documented in superclass.
544  bool
545  isOrderCertain() const;
546 
547  // Documented in superclass.
548  bool
549  isThumbnailSeries() const;
550 
551  // Documented in superclass.
552  bool
553  isInterleaved() const;
554 
555  // Documented in superclass.
556  bool
557  isInterleaved(dimension_size_type subC) const;
558 
559  // Documented in superclass.
560  void
561  openBytes(dimension_size_type plane,
562  VariantPixelBuffer& buf) const;
563 
564  // Documented in superclass.
565  void
566  openBytes(dimension_size_type plane,
567  VariantPixelBuffer& buf,
571  dimension_size_type h) const;
572 
573  protected:
577  virtual
578  void
579  openBytesImpl(dimension_size_type plane,
580  VariantPixelBuffer& buf,
584  dimension_size_type h) const = 0;
585 
586  public:
587  // Documented in superclass.
588  void
589  openThumbBytes(dimension_size_type plane,
590  VariantPixelBuffer& buf) const;
591 
592  // Documented in superclass.
593  void
594  close(bool fileOnly = false);
595 
596  // Documented in superclass.
598  getSeriesCount() const;
599 
600  // Documented in superclass.
601  void
602  setSeries(dimension_size_type series) const;
603 
604  // Documented in superclass.
606  getSeries() const;
607 
608  // Documented in superclass.
609  void
610  setPlane(dimension_size_type plane) const;
611 
612  // Documented in superclass.
614  getPlane() const;
615 
616  // Documented in superclass.
617  void
618  setGroupFiles(bool group);
619 
620  // Documented in superclass.
621  bool
622  isGroupFiles() const;
623 
624  // Documented in superclass.
626  fileGroupOption(const std::string& id);
627 
628  // Documented in superclass.
629  bool
630  isMetadataComplete() const;
631 
632  // Documented in superclass.
633  void
634  setNormalized(bool normalize);
635 
636  // Documented in superclass.
637  bool
638  isNormalized() const;
639 
640  // Documented in superclass.
641  void
642  setOriginalMetadataPopulated(bool populate);
643 
644  // Documented in superclass.
645  bool
646  isOriginalMetadataPopulated() const;
647 
648  // Documented in superclass.
649  const std::vector<boost::filesystem::path>
650  getUsedFiles(bool noPixels = false) const;
651 
652  // Documented in superclass.
653  const std::vector<boost::filesystem::path>
654  getSeriesUsedFiles(bool noPixels = false) const;
655 
656  // Documented in superclass.
657  std::vector<FileInfo>
658  getAdvancedUsedFiles(bool noPixels = false) const;
659 
660  // Documented in superclass.
661  std::vector<FileInfo>
662  getAdvancedSeriesUsedFiles(bool noPixels = false) const;
663 
664  // Documented in superclass.
665  const boost::optional<boost::filesystem::path>&
666  getCurrentFile() const;
667 
668  // Documented in superclass.
672  dimension_size_type t) const;
673 
674  // Documented in superclass.
679  dimension_size_type moduloZ,
680  dimension_size_type moduloC,
681  dimension_size_type moduloT) const;
682 
683  // Documented in superclass.
684  std::array<dimension_size_type, 3>
685  getZCTCoords(dimension_size_type index) const;
686 
687  // Documented in superclass.
688  std::array<dimension_size_type, 6>
689  getZCTModuloCoords(dimension_size_type index) const;
690 
691  // Documented in superclass.
692  const std::vector<std::shared_ptr<::ome::files::CoreMetadata>>&
693  getCoreMetadataList() const;
694 
695  // Documented in superclass.
696  void
697  setMetadataFiltered(bool filter);
698 
699  // Documented in superclass.
700  bool
701  isMetadataFiltered() const;
702 
703  // Documented in superclass.
704  void
705  setMetadataStore(std::shared_ptr<::ome::xml::meta::MetadataStore>& store);
706 
707  // Documented in superclass.
708  const std::shared_ptr<::ome::xml::meta::MetadataStore>&
709  getMetadataStore() const;
710 
711  // Documented in superclass.
712  std::shared_ptr<::ome::xml::meta::MetadataStore>&
713  getMetadataStore();
714 
715  // Documented in superclass.
716  std::vector<std::shared_ptr<::ome::files::FormatReader>>
717  getUnderlyingReaders() const;
718 
719  // Documented in superclass.
720  bool
721  isSingleFile(const boost::filesystem::path& id) const;
722 
723  // Documented in superclass.
724  uint32_t
725  getRequiredDirectories(const std::vector<std::string>& files) const;
726 
727  // Documented in superclass.
728  const std::string&
729  getDatasetStructureDescription() const;
730 
731  // Documented in superclass.
732  const std::vector<std::string>&
733  getPossibleDomains(const std::string& id) const;
734 
735  // Documented in superclass.
736  bool
737  hasCompanionFiles() const;
738 
739  // Documented in superclass.
740  const std::vector<std::string>&
741  getDomains() const;
742 
743  // Documented in superclass.
745  getOptimalTileWidth(dimension_size_type channel) const;
746 
747  // Documented in superclass.
749  getOptimalTileHeight(dimension_size_type channel) const;
750 
751  // Documented in superclass.
753  getOptimalTileWidth() const;
754 
755  // Documented in superclass.
757  getOptimalTileHeight() const;
758 
759  // Documented in superclass.
761  seriesToCoreIndex(dimension_size_type series) const;
762 
763  // Documented in superclass.
765  coreIndexToSeries(dimension_size_type index) const;
766 
767  // Documented in superclass.
769  getCoreIndex() const;
770 
771  // Documented in superclass.
772  void
773  setCoreIndex(dimension_size_type index) const;
774 
775  // Documented in superclass.
777  getResolutionCount() const;
778 
779  // Documented in superclass.
780  void
781  setResolution(dimension_size_type resolution) const;
782 
783  // Documented in superclass.
785  getResolution() const;
786 
787  // Documented in superclass.
788  bool
789  hasFlattenedResolutions() const;
790 
791  // Documented in superclass.
792  void
793  setFlattenedResolutions(bool flatten);
794 
795  // Documented in superclass.
796  void
797  setId(const boost::filesystem::path& id);
798 
799  // Documented in superclass.
800  const std::string&
801  getFormat() const;
802 
803  // Documented in superclass.
804  const std::string&
805  getFormatDescription() const;
806 
807  // Documented in superclass.
808  const std::vector<boost::filesystem::path>&
809  getSuffixes() const;
810 
811  // Documented in superclass.
812  const std::vector<boost::filesystem::path>&
813  getCompressionSuffixes() const;
814  };
815 
816  }
817  }
818 }
819 
820 #endif // OME_FILES_DETAIL_FORMATREADER_H
821 
822 /*
823  * Local Variables:
824  * mode:C++
825  * End:
826  */
bool indexedAsRGB
Whether or not MetadataStore sets C = 3 for indexed color images.
Definition: FormatReader.h:193
dimension_size_type resolution
The number of the current resolution.
Definition: FormatReader.h:159
Properties specific to a particular reader.
Definition: FormatReader.h:64
const ReaderProperties & readerProperties
Reader properties specific to the derived file format.
Definition: FormatReader.h:115
uint32_t pixel_size_type
Size type for pixel bit depths.
Definition: Types.h:61
const CoreMetadata & getCoreMetadata(dimension_size_type index) const
Get CoreMetadata by core index.
Definition: FormatReader.h:325
std::size_t dimension_size_type
Size type for image dimensions.
Definition: Types.h:58
std::set< MetadataOptions::MetadataLevel > metadata_levels
Supported metadata levels. A typical default is {METADATA_MINIMUM,METADATA_NO_OVERLAYS,METADATA_ALL}.
Definition: FormatReader.h:75
std::vector< std::string > domains
List of domains in which this format is used.
Definition: FormatReader.h:199
std::shared_ptr<::ome::xml::meta::MetadataStore > metadataStore
Current metadata store.
Definition: FormatReader.h:205
boost::make_variant_over< discriminated_types >::type value_type
Value type, allowing assignment of all storable types.
Definition: MetadataMap.h:147
FileGroupOption
File grouping options.
Definition: FormatReader.h:79
dimension_size_type getIndex(const std::string &order, dimension_size_type zSize, dimension_size_type cSize, dimension_size_type tSize, dimension_size_type num, dimension_size_type z, dimension_size_type c, dimension_size_type t)
Get the rasterized index corresponding to the given Z, C and T coordinates (real sizes).
Definition: FormatTools.cpp:365
Metadata key-value map using a restricted set of value types.
Definition: MetadataMap.h:79
dimension_size_type series
The number of the current series (non-flattened).
Definition: FormatReader.h:140
bool suffixNecessary
Whether the file extension matching one of the reader&#39;s suffixes is necessary to identify the file as...
Definition: FormatReader.h:169
::ome::files::MetadataMap metadata
Mapping of metadata key/value pairs.
Definition: FormatReader.h:124
bool filterMetadata
Whether or not to filter out invalid metadata.
Definition: FormatReader.h:187
dimension_size_type plane
The number of the current plane in the current series.
Definition: FormatReader.h:148
std::vector< boost::filesystem::path > suffixes
Filename suffixes this format can handle.
Definition: FormatReader.h:71
bool companionFiles
Whether this format supports multi-file datasets.
Definition: FormatReader.h:178
std::string name
Format name.
Definition: FormatReader.h:67
Open Microscopy Environment C++.
bool flattenedResolutions
Whether or not resolutions are flattened.
Definition: FormatReader.h:162
bool group
Whether or not to group multi-file formats.
Definition: FormatReader.h:196
bool saveOriginalMetadata
Whether or not to save proprietary metadata in the MetadataStore.
Definition: FormatReader.h:190
std::vector< std::shared_ptr<::ome::files::CoreMetadata > > coremetadata_list_type
List type for storing CoreMetadata.
Definition: FormatReader.h:112
bool normalizeData
Whether or not to normalize float data.
Definition: FormatReader.h:184
CoreMetadata & getCoreMetadata(dimension_size_type index)
Get CoreMetadata by core index.
Definition: FormatReader.h:342
std::string key_type
Key type.
Definition: MetadataMap.h:144
Core metadata values.
Definition: CoreMetadata.h:77
coremetadata_list_type core
Core metadata values.
Definition: FormatReader.h:151
bool suffixSufficient
Whether the file extension matching one of the reader&#39;s suffixes is sufficient to identify the file a...
Definition: FormatReader.h:175
MetadataOptions metadataOptions
Metadata parsing options.
Definition: FormatReader.h:208
Interface for all biological file format readers (default behaviour).
Definition: FormatReader.h:107
std::string description
Format description.
Definition: FormatReader.h:69
std::array< dimension_size_type, 3 > getZCTCoords(const std::string &order, dimension_size_type zSize, dimension_size_type cSize, dimension_size_type tSize, dimension_size_type num, dimension_size_type index)
Get the Z, C and T coordinates (real sizes) corresponding to the given rasterized index value...
Definition: FormatTools.cpp:422
std::vector< boost::filesystem::path > compression_suffixes
Filename compression suffixes this format can handle.
Definition: FormatReader.h:73
boost::optional< boost::filesystem::path > currentId
The identifier (path) of the currently open file.
Definition: FormatReader.h:118
std::string datasetDescription
Short description of the structure of the dataset.
Definition: FormatReader.h:181
Interface for all biological file format readers.
Definition: FormatReader.h:72
std::shared_ptr< std::istream > in
Current input.
Definition: FormatReader.h:121
A subdimension of Z, C, or T.
Definition: Modulo.h:56
ReaderProperties(const std::string &name, const std::string &description)
Constructor.
Definition: FormatReader.h:83
Buffer for all pixel types.
Definition: VariantPixelBuffer.h:78
dimension_size_type coreIndex
The number of the current series (flattened).
Definition: FormatReader.h:132
Interface for all biological file format readers and writers.
Definition: FormatHandler.h:63
Metadata options.
Definition: MetadataOptions.h:54