ome-files  0.1.1
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<ome::compat::shared_ptr< ::ome::files::CoreMetadata> > coremetadata_list_type;
113 
116 
118  boost::optional<boost::filesystem::path> currentId;
119 
121  ome::compat::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  ome::compat::shared_ptr< ::ome::xml::meta::MetadataStore> metadataStore;
206 
209 
212 
213  public:
215  virtual
216  ~FormatReader();
217 
218  private:
220  FormatReader (const FormatReader&);
221 
223  FormatReader&
224  operator= (const FormatReader&);
225 
226  protected:
241  virtual
242  void
243  initFile(const boost::filesystem::path& id);
244 
251  virtual
252  bool
253  isUsedFile(const boost::filesystem::path& file);
254 
269  virtual
270  void
271  readPlane(std::istream& source,
272  VariantPixelBuffer& dest,
277  dimension_size_type samples);
278 
294  virtual
295  void
296  readPlane(std::istream& source,
297  VariantPixelBuffer& dest,
302  dimension_size_type scanlinePad,
303  dimension_size_type samples);
304 
313  virtual
314  ome::compat::shared_ptr< ::ome::xml::meta::MetadataStore>
315  makeFilterMetadata();
316 
325  const CoreMetadata&
327  {
328  coremetadata_list_type::value_type cm(core.at(index));
329  if (!cm)
330  throw std::logic_error("CoreMetadata null");
331  return *cm;
332  }
333 
342  CoreMetadata&
344  {
345  coremetadata_list_type::value_type cm(core.at(index));
346  if (!cm)
347  throw std::logic_error("CoreMetadata null");
348  return *cm;
349  }
350 
351  public:
352  // Documented in superclass.
353  const std::set<MetadataOptions::MetadataLevel>&
354  getSupportedMetadataLevels();
355 
356  // Documented in superclass.
357  void
358  setMetadataOptions(const MetadataOptions& options);
359 
360  // Documented in superclass.
361  const MetadataOptions&
362  getMetadataOptions() const;
363 
365  getMetadataOptions();
366 
367  // Documented in superclass.
368  const MetadataMap&
369  getGlobalMetadata() const;
370 
371  // Documented in superclass.
373  getMetadataValue(const std::string& field) const;
374 
375  // Documented in superclass.
376  const MetadataMap&
377  getSeriesMetadata() const;
378 
379  // Documented in superclass.
381  getSeriesMetadataValue(const MetadataMap::key_type& field) const;
382 
383  // Documented in superclass.
384  bool
385  isThisType(const boost::filesystem::path& name,
386  bool open = true) const;
387 
388  // Documented in superclass.
389  bool
390  isThisType(const uint8_t *begin,
391  std::size_t length) const;
392 
393  // Documented in superclass.
394  bool
395  isThisType(const uint8_t *begin,
396  const uint8_t *end) const;
397 
398  // Documented in superclass.
399  bool
400  isThisType(std::istream& stream) const;
401 
402  protected:
415  virtual
416  bool
417  isFilenameThisTypeImpl(const boost::filesystem::path& name) const;
418 
431  virtual
432  bool
433  isStreamThisTypeImpl(std::istream& stream) const;
434 
435  public:
436  // Documented in superclass.
438  getImageCount() const;
439 
440  // Documented in superclass.
441  bool
442  isRGB(dimension_size_type channel) const;
443 
444  // Documented in superclass.
446  getSizeX() const;
447 
448  // Documented in superclass.
450  getSizeY() const;
451 
452  // Documented in superclass.
454  getSizeZ() const;
455 
456  // Documented in superclass.
458  getSizeT() const;
459 
460  // Documented in superclass.
462  getSizeC() const;
463 
464  // Documented in superclass.
466  getPixelType() const;
467 
468  // Documented in superclass.
470  getBitsPerPixel() const;
471 
472  // Documented in superclass.
474  getEffectiveSizeC() const;
475 
476  // Documented in superclass.
478  getRGBChannelCount(dimension_size_type channel) const;
479 
480  // Documented in superclass.
481  bool
482  isIndexed() const;
483 
484  // Documented in superclass.
485  bool
486  isFalseColor() const;
487 
488  // Documented in superclass.
489  void
490  getLookupTable(dimension_size_type plane,
491  VariantPixelBuffer& buf) const;
492 
493  // Documented in superclass.
494  Modulo&
495  getModuloZ();
496 
497  // Documented in superclass.
498  const Modulo&
499  getModuloZ() const;
500 
501  // Documented in superclass.
502  Modulo&
503  getModuloT();
504 
505  // Documented in superclass.
506  const Modulo&
507  getModuloT() const;
508 
509  // Documented in superclass.
510  Modulo&
511  getModuloC();
512 
513  // Documented in superclass.
514  const Modulo&
515  getModuloC() const;
516 
517  protected:
524  ome::compat::array<dimension_size_type, 2>
525  getThumbSize() const;
526 
527  public:
528  // Documented in superclass.
530  getThumbSizeX() const;
531 
532  // Documented in superclass.
534  getThumbSizeY() const;
535 
536  // Documented in superclass.
537  bool
538  isLittleEndian() const;
539 
540  // Documented in superclass.
541  const std::string&
542  getDimensionOrder() const;
543 
544  // Documented in superclass.
545  bool
546  isOrderCertain() const;
547 
548  // Documented in superclass.
549  bool
550  isThumbnailSeries() const;
551 
552  // Documented in superclass.
553  bool
554  isInterleaved() const;
555 
556  // Documented in superclass.
557  bool
558  isInterleaved(dimension_size_type subC) const;
559 
560  // Documented in superclass.
561  void
562  openBytes(dimension_size_type plane,
563  VariantPixelBuffer& buf) const;
564 
565  // Documented in superclass.
566  void
567  openBytes(dimension_size_type plane,
568  VariantPixelBuffer& buf,
572  dimension_size_type h) const;
573 
574  protected:
578  virtual
579  void
580  openBytesImpl(dimension_size_type plane,
581  VariantPixelBuffer& buf,
585  dimension_size_type h) const = 0;
586 
587  public:
588  // Documented in superclass.
589  void
590  openThumbBytes(dimension_size_type plane,
591  VariantPixelBuffer& buf) const;
592 
593  // Documented in superclass.
594  void
595  close(bool fileOnly = false);
596 
597  // Documented in superclass.
599  getSeriesCount() const;
600 
601  // Documented in superclass.
602  void
603  setSeries(dimension_size_type series) const;
604 
605  // Documented in superclass.
607  getSeries() const;
608 
609  // Documented in superclass.
610  void
611  setPlane(dimension_size_type plane) const;
612 
613  // Documented in superclass.
615  getPlane() const;
616 
617  // Documented in superclass.
618  void
619  setGroupFiles(bool group);
620 
621  // Documented in superclass.
622  bool
623  isGroupFiles() const;
624 
625  // Documented in superclass.
627  fileGroupOption(const std::string& id);
628 
629  // Documented in superclass.
630  bool
631  isMetadataComplete() const;
632 
633  // Documented in superclass.
634  void
635  setNormalized(bool normalize);
636 
637  // Documented in superclass.
638  bool
639  isNormalized() const;
640 
641  // Documented in superclass.
642  void
643  setOriginalMetadataPopulated(bool populate);
644 
645  // Documented in superclass.
646  bool
647  isOriginalMetadataPopulated() const;
648 
649  // Documented in superclass.
650  const std::vector<boost::filesystem::path>
651  getUsedFiles(bool noPixels = false) const;
652 
653  // Documented in superclass.
654  const std::vector<boost::filesystem::path>
655  getSeriesUsedFiles(bool noPixels = false) const;
656 
657  // Documented in superclass.
658  std::vector<FileInfo>
659  getAdvancedUsedFiles(bool noPixels = false) const;
660 
661  // Documented in superclass.
662  std::vector<FileInfo>
663  getAdvancedSeriesUsedFiles(bool noPixels = false) const;
664 
665  // Documented in superclass.
666  const boost::optional<boost::filesystem::path>&
667  getCurrentFile() const;
668 
669  // Documented in superclass.
673  dimension_size_type t) const;
674 
675  // Documented in superclass.
680  dimension_size_type moduloZ,
681  dimension_size_type moduloC,
682  dimension_size_type moduloT) const;
683 
684  // Documented in superclass.
685  ome::compat::array<dimension_size_type, 3>
686  getZCTCoords(dimension_size_type index) const;
687 
688  // Documented in superclass.
689  ome::compat::array<dimension_size_type, 6>
690  getZCTModuloCoords(dimension_size_type index) const;
691 
692  // Documented in superclass.
693  const std::vector<ome::compat::shared_ptr< ::ome::files::CoreMetadata> >&
694  getCoreMetadataList() const;
695 
696  // Documented in superclass.
697  void
698  setMetadataFiltered(bool filter);
699 
700  // Documented in superclass.
701  bool
702  isMetadataFiltered() const;
703 
704  // Documented in superclass.
705  void
706  setMetadataStore(ome::compat::shared_ptr< ::ome::xml::meta::MetadataStore>& store);
707 
708  // Documented in superclass.
709  const ome::compat::shared_ptr< ::ome::xml::meta::MetadataStore>&
710  getMetadataStore() const;
711 
712  // Documented in superclass.
713  ome::compat::shared_ptr< ::ome::xml::meta::MetadataStore>&
714  getMetadataStore();
715 
716  // Documented in superclass.
717  std::vector<ome::compat::shared_ptr< ::ome::files::FormatReader> >
718  getUnderlyingReaders() const;
719 
720  // Documented in superclass.
721  bool
722  isSingleFile(const boost::filesystem::path& id) const;
723 
724  // Documented in superclass.
725  uint32_t
726  getRequiredDirectories(const std::vector<std::string>& files) const;
727 
728  // Documented in superclass.
729  const std::string&
730  getDatasetStructureDescription() const;
731 
732  // Documented in superclass.
733  const std::vector<std::string>&
734  getPossibleDomains(const std::string& id) const;
735 
736  // Documented in superclass.
737  bool
738  hasCompanionFiles() const;
739 
740  // Documented in superclass.
741  const std::vector<std::string>&
742  getDomains() const;
743 
744  // Documented in superclass.
746  getOptimalTileWidth(dimension_size_type channel) const;
747 
748  // Documented in superclass.
750  getOptimalTileHeight(dimension_size_type channel) const;
751 
752  // Documented in superclass.
754  getOptimalTileWidth() const;
755 
756  // Documented in superclass.
758  getOptimalTileHeight() const;
759 
760  // Documented in superclass.
762  seriesToCoreIndex(dimension_size_type series) const;
763 
764  // Documented in superclass.
766  coreIndexToSeries(dimension_size_type index) const;
767 
768  // Documented in superclass.
770  getCoreIndex() const;
771 
772  // Documented in superclass.
773  void
774  setCoreIndex(dimension_size_type index) const;
775 
776  // Documented in superclass.
778  getResolutionCount() const;
779 
780  // Documented in superclass.
781  void
782  setResolution(dimension_size_type resolution) const;
783 
784  // Documented in superclass.
786  getResolution() const;
787 
788  // Documented in superclass.
789  bool
790  hasFlattenedResolutions() const;
791 
792  // Documented in superclass.
793  void
794  setFlattenedResolutions(bool flatten);
795 
796  // Documented in superclass.
797  void
798  setId(const boost::filesystem::path& id);
799 
800  // Documented in superclass.
801  const std::string&
802  getFormat() const;
803 
804  // Documented in superclass.
805  const std::string&
806  getFormatDescription() const;
807 
808  // Documented in superclass.
809  const std::vector<boost::filesystem::path>&
810  getSuffixes() const;
811 
812  // Documented in superclass.
813  const std::vector<boost::filesystem::path>&
814  getCompressionSuffixes() const;
815  };
816 
817  }
818  }
819 }
820 
821 #endif // OME_FILES_DETAIL_FORMATREADER_H
822 
823 /*
824  * Local Variables:
825  * mode:C++
826  * End:
827  */
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:62
ome::compat::shared_ptr< std::istream > in
Current input.
Definition: FormatReader.h:121
std::size_t dimension_size_type
Size type for image dimensions.
Definition: Types.h:59
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
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:77
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
ome::compat::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
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
const CoreMetadata & getCoreMetadata(dimension_size_type index) const
Get CoreMetadata by core index.
Definition: FormatReader.h:326
std::vector< ome::compat::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:343
std::string key_type
Key type.
Definition: MetadataMap.h:144
Core metadata values.
Definition: CoreMetadata.h:78
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::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:70
A subdimension of Z, C, or T.
Definition: Modulo.h:57
ReaderProperties(const std::string &name, const std::string &description)
Constructor.
Definition: FormatReader.h:83
Buffer for all pixel types.
Definition: VariantPixelBuffer.h:75
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:64
Metadata options.
Definition: MetadataOptions.h:55
ome::compat::shared_ptr< ::ome::xml::meta::MetadataStore > metadataStore
Current metadata store.
Definition: FormatReader.h:205