ome-files 0.2.2

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
64 struct ReaderProperties
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
107 class FormatReader : public ::ome::files::FormatReader,
108 virtual public ::ome::files::FormatHandler
109 {
110 protected:
112 typedef std::vector<ome::compat::shared_ptr< ::ome::files::CoreMetadata> > coremetadata_list_type;
113
115 const ReaderProperties& readerProperties;
116
118 boost::optional<boost::filesystem::path> currentId;
119
121 ome::compat::shared_ptr<std::istream> in;
122
124 ::ome::files::MetadataMap metadata;
125
132 mutable dimension_size_type coreIndex;
133
140 mutable dimension_size_type series;
141
148 mutable dimension_size_type plane;
149
151 coremetadata_list_type core;
152
159 mutable dimension_size_type resolution;
160
162 bool flattenedResolutions;
163
169 bool suffixNecessary;
170
175 bool suffixSufficient;
176
178 bool companionFiles;
179
181 std::string datasetDescription;
182
184 bool normalizeData;
185
187 bool filterMetadata;
188
190 bool saveOriginalMetadata;
191
193 bool indexedAsRGB;
194
196 bool group;
197
199 std::vector<std::string> domains;
200
205 ome::compat::shared_ptr< ::ome::xml::meta::MetadataStore> metadataStore;
206
208 MetadataOptions metadataOptions;
209
211 FormatReader(const ReaderProperties&);
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,
273 dimension_size_type x,
274 dimension_size_type y,
275 dimension_size_type w,
276 dimension_size_type h,
277 dimension_size_type samples);
278
294 virtual
295 void
296 readPlane(std::istream& source,
297 VariantPixelBuffer& dest,
298 dimension_size_type x,
299 dimension_size_type y,
300 dimension_size_type w,
301 dimension_size_type h,
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&
326 getCoreMetadata(dimension_size_type index) const
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&
343 getCoreMetadata(dimension_size_type index)
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
364 MetadataOptions&
365 getMetadataOptions();
366
367 // Documented in superclass.
368 const MetadataMap&
369 getGlobalMetadata() const;
370
371 // Documented in superclass.
372 const MetadataMap::value_type&
373 getMetadataValue(const std::string& field) const;
374
375 // Documented in superclass.
376 const MetadataMap&
377 getSeriesMetadata() const;
378
379 // Documented in superclass.
380 const MetadataMap::value_type&
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.
437 dimension_size_type
438 getImageCount() const;
439
440 // Documented in superclass.
441 bool
442 isRGB(dimension_size_type channel) const;
443
444 // Documented in superclass.
445 dimension_size_type
446 getSizeX() const;
447
448 // Documented in superclass.
449 dimension_size_type
450 getSizeY() const;
451
452 // Documented in superclass.
453 dimension_size_type
454 getSizeZ() const;
455
456 // Documented in superclass.
457 dimension_size_type
458 getSizeT() const;
459
460 // Documented in superclass.
461 dimension_size_type
462 getSizeC() const;
463
464 // Documented in superclass.
465 ome::xml::model::enums::PixelType
466 getPixelType() const;
467
468 // Documented in superclass.
469 pixel_size_type
470 getBitsPerPixel() const;
471
472 // Documented in superclass.
473 dimension_size_type
474 getEffectiveSizeC() const;
475
476 // Documented in superclass.
477 dimension_size_type
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.
529 dimension_size_type
530 getThumbSizeX() const;
531
532 // Documented in superclass.
533 dimension_size_type
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,
569 dimension_size_type x,
570 dimension_size_type y,
571 dimension_size_type w,
572 dimension_size_type h) const;
573
574 protected:
578 virtual
579 void
580 openBytesImpl(dimension_size_type plane,
581 VariantPixelBuffer& buf,
582 dimension_size_type x,
583 dimension_size_type y,
584 dimension_size_type w,
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.
598 dimension_size_type
599 getSeriesCount() const;
600
601 // Documented in superclass.
602 void
603 setSeries(dimension_size_type series) const;
604
605 // Documented in superclass.
606 dimension_size_type
607 getSeries() const;
608
609 // Documented in superclass.
610 void
611 setPlane(dimension_size_type plane) const;
612
613 // Documented in superclass.
614 dimension_size_type
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.
626 FileGroupOption
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.
670 dimension_size_type
671 getIndex(dimension_size_type z,
672 dimension_size_type c,
673 dimension_size_type t) const;
674
675 // Documented in superclass.
676 dimension_size_type
677 getIndex(dimension_size_type z,
678 dimension_size_type c,
679 dimension_size_type t,
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.
745 dimension_size_type
746 getOptimalTileWidth(dimension_size_type channel) const;
747
748 // Documented in superclass.
749 dimension_size_type
750 getOptimalTileHeight(dimension_size_type channel) const;
751
752 // Documented in superclass.
753 dimension_size_type
754 getOptimalTileWidth() const;
755
756 // Documented in superclass.
757 dimension_size_type
758 getOptimalTileHeight() const;
759
760 // Documented in superclass.
761 dimension_size_type
762 seriesToCoreIndex(dimension_size_type series) const;
763
764 // Documented in superclass.
765 dimension_size_type
766 coreIndexToSeries(dimension_size_type index) const;
767
768 // Documented in superclass.
769 dimension_size_type
770 getCoreIndex() const;
771
772 // Documented in superclass.
773 void
774 setCoreIndex(dimension_size_type index) const;
775
776 // Documented in superclass.
777 dimension_size_type
778 getResolutionCount() const;
779
780 // Documented in superclass.
781 void
782 setResolution(dimension_size_type resolution) const;
783
784 // Documented in superclass.
785 dimension_size_type
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 */
ome::files::detail::FormatReader::indexedAsRGB
bool indexedAsRGB
Whether or not MetadataStore sets C = 3 for indexed color images.
Definition: FormatReader.h:193
ome::files::detail::FormatReader::resolution
dimension_size_type resolution
The number of the current resolution.
Definition: FormatReader.h:159
ome::files::detail::ReaderProperties
Properties specific to a particular reader.
Definition: FormatReader.h:64
ome::files::detail::FormatReader::readerProperties
const ReaderProperties & readerProperties
Reader properties specific to the derived file format.
Definition: FormatReader.h:115
ome::files::pixel_size_type
uint32_t pixel_size_type
Size type for pixel bit depths.
Definition: Types.h:62
ome::files::detail::FormatReader::getCoreMetadata
const CoreMetadata & getCoreMetadata(dimension_size_type index) const
Get CoreMetadata by core index.
Definition: FormatReader.h:326
ome::files::detail::FormatReader::in
ome::compat::shared_ptr< std::istream > in
Current input.
Definition: FormatReader.h:121
ome::files::dimension_size_type
std::size_t dimension_size_type
Size type for image dimensions.
Definition: Types.h:59
ome::files::detail::ReaderProperties::metadata_levels
std::set< MetadataOptions::MetadataLevel > metadata_levels
Supported metadata levels. A typical default is {METADATA_MINIMUM,METADATA_NO_OVERLAYS,METADATA_ALL}.
Definition: FormatReader.h:75
ome::files::detail::FormatReader::domains
std::vector< std::string > domains
List of domains in which this format is used.
Definition: FormatReader.h:199
ome::files::MetadataMap::value_type
boost::make_variant_over< discriminated_types >::type value_type
Value type, allowing assignment of all storable types.
Definition: MetadataMap.h:147
ome::files::FormatReader::FileGroupOption
FileGroupOption
File grouping options.
Definition: FormatReader.h:77
ome::files::getIndex
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
ome::files::MetadataMap
Metadata key-value map using a restricted set of value types.
Definition: MetadataMap.h:79
ome::files::detail::FormatReader::series
dimension_size_type series
The number of the current series (non-flattened).
Definition: FormatReader.h:140
ome::files::detail::FormatReader::suffixNecessary
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::detail::FormatReader::metadata
::ome::files::MetadataMap metadata
Mapping of metadata key/value pairs.
Definition: FormatReader.h:124
ome::files::detail::FormatReader::filterMetadata
bool filterMetadata
Whether or not to filter out invalid metadata.
Definition: FormatReader.h:187
ome::files::detail::FormatReader::plane
dimension_size_type plane
The number of the current plane in the current series.
Definition: FormatReader.h:148
ome::files::detail::ReaderProperties::suffixes
std::vector< boost::filesystem::path > suffixes
Filename suffixes this format can handle.
Definition: FormatReader.h:71
ome::files::detail::FormatReader::companionFiles
bool companionFiles
Whether this format supports multi-file datasets.
Definition: FormatReader.h:178
ome::files::detail::ReaderProperties::name
std::string name
Format name.
Definition: FormatReader.h:67
ome::files::getZCTCoords
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
ome
Open Microscopy Environment C++.
ome::files::detail::FormatReader::flattenedResolutions
bool flattenedResolutions
Whether or not resolutions are flattened.
Definition: FormatReader.h:162
ome::files::detail::FormatReader::group
bool group
Whether or not to group multi-file formats.
Definition: FormatReader.h:196
ome::files::detail::FormatReader::saveOriginalMetadata
bool saveOriginalMetadata
Whether or not to save proprietary metadata in the MetadataStore.
Definition: FormatReader.h:190
ome::files::detail::FormatReader::coremetadata_list_type
std::vector< ome::compat::shared_ptr< ::ome::files::CoreMetadata > > coremetadata_list_type
List type for storing CoreMetadata.
Definition: FormatReader.h:112
ome::files::detail::FormatReader::normalizeData
bool normalizeData
Whether or not to normalize float data.
Definition: FormatReader.h:184
ome::files::detail::FormatReader::getCoreMetadata
CoreMetadata & getCoreMetadata(dimension_size_type index)
Get CoreMetadata by core index.
Definition: FormatReader.h:343
ome::files::MetadataMap::key_type
std::string key_type
Key type.
Definition: MetadataMap.h:144
ome::files::CoreMetadata
Core metadata values.
Definition: CoreMetadata.h:78
ome::files::detail::FormatReader::core
coremetadata_list_type core
Core metadata values.
Definition: FormatReader.h:151
ome::files::detail::FormatReader::suffixSufficient
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
ome::files::detail::FormatReader::metadataOptions
MetadataOptions metadataOptions
Metadata parsing options.
Definition: FormatReader.h:208
ome::files::detail::FormatReader
Interface for all biological file format readers (default behaviour).
Definition: FormatReader.h:107
ome::files::detail::ReaderProperties::description
std::string description
Format description.
Definition: FormatReader.h:69
ome::xml::model::enums::PixelType
ome::files::detail::ReaderProperties::compression_suffixes
std::vector< boost::filesystem::path > compression_suffixes
Filename compression suffixes this format can handle.
Definition: FormatReader.h:73
ome::files::detail::FormatReader::currentId
boost::optional< boost::filesystem::path > currentId
The identifier (path) of the currently open file.
Definition: FormatReader.h:118
ome::files::detail::FormatReader::datasetDescription
std::string datasetDescription
Short description of the structure of the dataset.
Definition: FormatReader.h:181
ome::files::FormatReader
Interface for all biological file format readers.
Definition: FormatReader.h:70
ome::files::Modulo
A subdimension of Z, C, or T.
Definition: Modulo.h:57
ome::files::detail::ReaderProperties::ReaderProperties
ReaderProperties(const std::string &name, const std::string &description)
Constructor.
Definition: FormatReader.h:83
ome::files::VariantPixelBuffer
Buffer for all pixel types.
Definition: VariantPixelBuffer.h:75
ome::files::detail::FormatReader::coreIndex
dimension_size_type coreIndex
The number of the current series (flattened).
Definition: FormatReader.h:132
ome::files::FormatHandler
Interface for all biological file format readers and writers.
Definition: FormatHandler.h:63
ome::files::MetadataOptions
Metadata options.
Definition: MetadataOptions.h:55
ome::files::detail::FormatReader::metadataStore
ome::compat::shared_ptr< ::ome::xml::meta::MetadataStore > metadataStore
Current metadata store.
Definition: FormatReader.h:205