Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
MetaData.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 #ifndef __METADATA_HH__
27 #define __METADATA_HH__
28 #include "bias_config.h"
29 
30 #include <Base/Common/BIASpragmaStart.hh>
31 #include <vector>
32 #include <iostream>
33 #include <string>
34 
35 namespace BIAS {
36 
37  /** @class AppData
38  @brief this is a chunk of metadata, also see MetaData
39 
40  AppData can hold the meta datum either in ascii format (in this case
41  AppData.tag is set to AppData::MD_USE_ASCII) or in binary format (in this
42  case AppData.tag is set to anything except AppData::MD_USE_ASCII or
43  AppData::MD_Invalid)
44 
45  Basic operators for reading, writing and assignig exist
46 
47  @author woelk 11/2003 */
48 
49  class BIASImageBase_EXPORT AppData
50  {
51  public:
52  /** @enum TAppData
53  @brief Type of AppData
54 
55  If set to MD_USE_ASCII, AppData.tag, AppData.length and AppData.data
56  are invalid. AppData.stag and AppData.sdata should be used.
57 
58  If set to anything else except MD_Invalid, AppData.tag, AppData.length
59  and AppData.data are valid. AppData.stag and AppData.sdata should not
60  be used in this case.
61 
62  The string tag AppData.stag can be generated from the enum id by
63  removing 'MD_', substituting underscores with blanks and bracketing
64  with '#[' and ']'.
65 
66  For example tag=MD_Inertial_Sensor evolves to
67  stag="#[Inertial Sensor]".
68 
69  !! MD_ASCII_DATA is deprecated and should no longer be used. !!
70  It is keept her for compatibility reasons.
71  */
72  enum TAppData {MD_PMatrix=0, MD_Orientation=1, MD_TimeStamp=2,
73  MD_PTU_Data=3, MD_Inertial_Sensor=4, MD_ASCII_DATA=5,
74  MD_RMatrix=6, MD_KMatrix=7, MD_CVector=8, MD_HomgPoint2D=9,
75  MD_Invalid=10, MD_UUID=11, MD_USE_ASCII=12,
76  MD_Focal_Length=14, MD_GPS_Data=15, MD_Projection = 16,
77  MD_RefUUID=17, MD_PMD_DataDesc=18};
78  public:
79  AppData();
80  ~AppData();
81 
82  AppData(const AppData& app);
83 
84  AppData& operator=(const AppData& app);
85 
86  /** @brief Resets all members. */
87  void Clear();
88 
89  /** checks if stag and sdata have the correct format */
90  int CheckFormat();
91 
92  /** @brief The tag defines the type of data, e.g. MD_PMatrix
93  is set to MD_USE_ASCII if ascii data is used. See TAppData. */
94  enum TAppData tag;
95  /// number of bytes used by the data block
96  int length;
97  /// pointer to block of data
98  char *data;
99  /// the tag as given in ascii meta data
100  std::string stag;
101  /// the data as given in ascii meta data
102  std::string sdata;
103  };
104 
105  /** @relates AppData */
106  std::ostream& operator<<(std::ostream& os, const AppData& ad);
107  /** @relates AppData */
108  std::istream& operator>>(std::istream& is, AppData& ta);
109 
110  /** @relates TAppData */
111  std::ostream& operator<<(std::ostream& os, const AppData::TAppData& ta);
112 
113 
114  /** @class MetaData
115  @brief this class collects all additional data chunks of type AppData
116  to be written into/read from an image file
117 
118  See ExampleMetaData for usage.
119 
120  @author woelk 11/2003 */
121  class BIASImageBase_EXPORT MetaData : public std::vector<AppData>
122  {
123  public:
124  MetaData();
125 
126  MetaData(const MetaData& M) {
127  (*this) = M;
128  }
129 
131  std::vector<AppData>::operator=(M);
132  return (*this);
133  }
134 
135  ~MetaData();
136 
137  /** @brief Add a new binary meta datum.
138 
139  Replace old binary meta datum if already present.
140  Does not check if corresponding ascii datum is present. */
141  void Add(enum AppData::TAppData ID, unsigned int length, char *data);
142  void Add(AppData& ad);
143  /** @brief Add a new ascii meta datum
144 
145  Replace old ascii meta datum if already present.
146  Does not check if corresponding binary datum is present. */
147  void Add(const std::string &tag, const std::string& data);
148 
149  /** @brief searches for tag in binary coded AppDatas.
150 
151  returns: - position in vector if tag is found
152 
153  - -2 if tag not found but ascii data present
154 
155  - -1 if tag not found and no ascii data present */
156  int Find(const enum AppData::TAppData tag, AppData &data) const;
157  /** @brief searches for tag in ascii coded AppDatas.
158 
159  returns: - position in vector if tag is found
160 
161  - -2 if tag not found but binary data present
162 
163  - -1 if tag not found and no binary data present */
164  int Find(const std::string &tag, AppData &data) const;
165  /** @brief cascades Find(enum AppData::TAppData tag, AppData &data) and
166  Find(std::string tag, AppData &data) */
167  int Find(const enum AppData::TAppData tag, const std::string &stag,
168  AppData &data) const;
169 
170  /** @brief Delete the meta datum identified by tag.
171  Does not search for the corresponding ascii meta datum. */
172  void Delete(enum AppData::TAppData tag);
173  /** @brief Delete the meta datum identified by tag.
174  Does not search for the corresponding binary meta datum. */
175  void Delete(const std::string &tag);
176 
177  /** @brief Writes only the meta datas where AppData::tag!=MD_USE_ASCII
178  to os. */
179  std::ostream &WriteBinary(std::ostream& os) const;
180  /** @brief Writes only the meta datas where AppData::tag==MD_USE_ASCII
181  to os. */
182  std::ostream &WriteAscii(std::ostream& os) const;
183 
184  /// @brief dumps this to cout, unfinished piece of code
185  void Dump(std::ostream& os=std::cout);
186  };
187 
188  /** @relates MetaData
189  @brief Reads from is. Decides whether to read ascii format or binary
190  format */
191  BIASImageBase_EXPORT std::istream& operator>>(std::istream& is, MetaData& md);
192  /** @relates MetaData
193  @brief Dumb write operator writes everything to os.
194  !!! binary and ascii data are written mixed, if both are present !!! */
195  BIASImageBase_EXPORT std::ostream& operator<<(std::ostream& is, const MetaData& md);
196 
197 } //namespace
198 
199 
200 #include <Base/Common/BIASpragmaEnd.hh>
201 
202 #endif
std::string stag
the tag as given in ascii meta data
Definition: MetaData.hh:100
int length
number of bytes used by the data block
Definition: MetaData.hh:96
std::string sdata
the data as given in ascii meta data
Definition: MetaData.hh:102
char * data
pointer to block of data
Definition: MetaData.hh:98
std::ostream & operator<<(std::ostream &os, const Array2D< T > &arg)
Definition: Array2D.hh:260
TAppData
Type of AppData.
Definition: MetaData.hh:72
this class collects all additional data chunks of type AppData to be written into/read from an image ...
Definition: MetaData.hh:121
MetaData(const MetaData &M)
Definition: MetaData.hh:126
MetaData & operator=(const MetaData &M)
Definition: MetaData.hh:130
BIASCommon_EXPORT std::istream & operator>>(std::istream &is, BIAS::TimeStamp &ts)
Standard input operator for TimeStamps.
Definition: TimeStamp.cpp:157
this is a chunk of metadata, also see MetaData
Definition: MetaData.hh:49