libCZI
Reading and Writing CZI documents made easy
libCZI_Metadata.h
1 // SPDX-FileCopyrightText: 2017-2022 Carl Zeiss Microscopy GmbH
2 //
3 // SPDX-License-Identifier: LGPL-3.0-or-later
4 
5 #pragma once
6 
7 #include "ImportExport.h"
8 #include "libCZI_DimCoordinate.h"
9 #include "libCZI_Pixels.h"
10 #include <limits>
11 #include <string>
12 #include <vector>
13 #include <map>
14 #include <functional>
15 #include <memory>
16 #include <cmath>
17 #include <sstream>
18 #include <stdexcept>
19 
20 namespace libCZI
21 {
22  struct SubBlockStatistics;
23 
25  struct LIBCZI_API XmlDateTime
26  {
27  int sec;
28  int min;
29  int hour;
30  int mday;
31  int mon;
32  int year;
33 
34  bool isUTC;
35 
38 
41 
43  void Clear()
44  {
45  this->sec = this->min = this->hour = this->mday = this->mon = this->year = 0;
46  this->isUTC = false;
47  this->offsetHours = (std::numeric_limits<int>::min)();
48  this->offsetMinutes = (std::numeric_limits<int>::min)();
49  }
50 
54  bool HasTimeZoneOffset() const
55  {
56  if (this->isUTC)
57  {
58  return false;
59  }
60 
61  if (this->offsetHours <= -24 || this->offsetHours >= 24 || this->offsetMinutes >= 60 || this->offsetMinutes < 0)
62  {
63  return false;
64  }
65 
66  return true;
67  }
68 
72  std::string ToXmlString() const;
73 
77  std::wstring ToXmlWstring() const;
78 
81  bool IsValid() const;
82 
88  static bool TryParse(const char* sz, XmlDateTime* ptrDateTime);
89 
95  static bool TryParse(const wchar_t* szw, XmlDateTime* ptrDateTime);
96  };
97 
100  {
102  LIBCZI_API GeneralDocumentInfo() : name_valid(false), title_valid(false), userName_valid(false), description_valid(false), comment_valid(false), keywords_valid(false), rating_valid(false), rating(0), creationDateTime_valid(false) {}
103  bool name_valid;
104  std::wstring name;
105  bool title_valid;
106  std::wstring title;
108  std::wstring userName;
110  std::wstring description;
112  std::wstring comment;
114  std::wstring keywords;
116  int rating;
118  std::wstring creationDateTime;
119 
123  LIBCZI_API void SetName(const wchar_t* sz) { this->SetMember(&GeneralDocumentInfo::name, &GeneralDocumentInfo::name_valid, sz); }
124 
128  LIBCZI_API void SetName(const std::wstring& str) { this->SetName(str.c_str()); }
129 
133  LIBCZI_API void SetTitle(const wchar_t* sz) { this->SetMember(&GeneralDocumentInfo::title, &GeneralDocumentInfo::title_valid, sz); }
134 
138  LIBCZI_API void SetTitle(const std::wstring& str) { this->SetTitle(str.c_str()); }
139 
143  LIBCZI_API void SetUserName(const wchar_t* sz) { this->SetMember(&GeneralDocumentInfo::userName, &GeneralDocumentInfo::userName_valid, sz); }
144 
148  LIBCZI_API void SetUserName(const std::wstring& str) { this->SetUserName(str.c_str()); }
149 
153  LIBCZI_API void SetDescription(const wchar_t* sz) { this->SetMember(&GeneralDocumentInfo::description, &GeneralDocumentInfo::description_valid, sz); }
154 
158  LIBCZI_API void SetDescription(const std::wstring& str) { this->SetDescription(str.c_str()); }
159 
163  LIBCZI_API void SetComment(const wchar_t* sz) { this->SetMember(&GeneralDocumentInfo::comment, &GeneralDocumentInfo::comment_valid, sz); }
164 
168  LIBCZI_API void SetComment(const std::wstring& str) { this->SetComment(str.c_str()); }
169 
173  LIBCZI_API void SetKeywords(const wchar_t* sz) { this->SetMember(&GeneralDocumentInfo::keywords, &GeneralDocumentInfo::keywords_valid, sz); }
174 
178  LIBCZI_API void SetKeywords(const std::wstring& str) { this->SetKeywords(str.c_str()); }
179 
182  LIBCZI_API void SetRating(int rating) { this->rating = rating; this->rating_valid = rating >= 0 ? true : false; }
183 
187  LIBCZI_API void SetCreationDate(const wchar_t* sz) { this->SetMember(&GeneralDocumentInfo::creationDateTime, &GeneralDocumentInfo::creationDateTime_valid, sz); }
188 
192  LIBCZI_API void SetCreationDate(const std::wstring& str) { this->SetCreationDate(str.c_str()); }
193 
197  LIBCZI_API void SetCreationDate(const XmlDateTime* dateTime) { if (dateTime != nullptr && dateTime->IsValid()) { this->SetCreationDate(dateTime->ToXmlWstring()); } else { this->SetCreationDate(static_cast<const wchar_t*>(nullptr)); } }
198 
200  LIBCZI_API void Clear()
201  {
202  this->name_valid = this->title_valid = this->userName_valid = this->description_valid =
203  this->comment_valid = this->keywords_valid = this->rating_valid = this->creationDateTime_valid = false;
204  }
205  private:
206  void SetMember(std::wstring(GeneralDocumentInfo::* strMember), bool(GeneralDocumentInfo::* validMember), const wchar_t* str)
207  {
208  if (str == nullptr || *str == L'\0')
209  {
210  (this->*strMember).clear();
211  this->*validMember = false;
212  }
213  else
214  {
215  this->*strMember = str;
216  this->*validMember = true;
217  }
218  }
219  };
220 
222  struct LIBCZI_API ScalingInfo
223  {
225  ScalingInfo() : scaleX(std::numeric_limits<double>::quiet_NaN()), scaleY(std::numeric_limits<double>::quiet_NaN()), scaleZ(std::numeric_limits<double>::quiet_NaN()) {}
226  double scaleX;
227  double scaleY;
228  double scaleZ;
229 
233  bool IsScaleXValid() const { return !std::isnan(this->scaleX) && !std::isinf(this->scaleX); }
234 
238  bool IsScaleYValid() const { return !std::isnan(this->scaleY) && !std::isinf(this->scaleY); }
239 
243  bool IsScaleZValid() const { return !std::isnan(this->scaleZ) && !std::isinf(this->scaleZ); }
244 
252  bool IsScaleValid(char d) const
253  {
254  switch (d)
255  {
256  case 'x':case'X': return this->IsScaleXValid();
257  case 'y':case'Y': return this->IsScaleYValid();
258  case 'z':case'Z': return this->IsScaleZValid();
259  default: throw std::invalid_argument("invalid dimension");
260  }
261  }
262 
270  double GetScale(char d) const
271  {
272  switch (d)
273  {
274  case 'x':case'X': return this->scaleX;
275  case 'y':case'Y': return this->scaleY;
276  case 'z':case'Z': return this->scaleZ;
277  default: throw std::invalid_argument("invalid dimension");
278  }
279  }
280  };
281 
285  {
286  std::wstring defaultUnitFormatX;
287  std::wstring defaultUnitFormatY;
288  std::wstring defaultUnitFormatZ;
289 
297  LIBCZI_API std::wstring GetDefaultUnitFormat(char d) const
298  {
299  switch (d)
300  {
301  case 'x':case'X': return this->defaultUnitFormatX;
302  case 'y':case'Y': return this->defaultUnitFormatY;
303  case 'z':case'Z': return this->defaultUnitFormatZ;
304  default: throw std::invalid_argument("invalid dimension");
305  }
306  }
307  };
308 
310  class LIBCZI_API IDimensionInfo
311  {
312  public:
313 
316  virtual DimensionIndex GetDimension() const = 0;
317 
321  virtual void GetInterval(int* start, int* end) const = 0;
322 
327  virtual void GetIntervalIsExplicitlyStated(bool* startExplicitlyStated, bool* endExplicitlyStated) const = 0;
328 
329  virtual ~IDimensionInfo() = default;
330  };
331 
333  class LIBCZI_API IDimensionZInfo
334  {
335  public:
343  enum class XyzHandedness : std::uint8_t
344  {
345  LeftHanded,
346  RightHanded,
347  Undefined
348  };
349 
359  enum class ZaxisDirection : std::uint8_t
360  {
361  FromSpecimenToObjective,
362  FromObjectiveToSpecimen,
363  Undefined
364  };
365 
370  enum class ZDriveMode : std::uint8_t
371  {
372  Continuous,
373  Step
374  };
375 
379  virtual bool TryGetReferencePosition(double* d) = 0;
380 
385  virtual bool TryGetIntervalDefinition(double* offset, double* increment) = 0;
386 
390  virtual bool TryGetPositionList(std::vector<double>* positions) = 0;
391 
395  virtual bool TryGetXyzHandedness(XyzHandedness* xyzHandedness) = 0;
396 
400  virtual bool TryGetZAxisDirection(ZaxisDirection* zAxisDirection) = 0;
401 
405  virtual bool TryGetZDriveMode(ZDriveMode* zdrivemode) = 0;
406 
410  virtual bool TryZDriveSpeed(double* zdrivespeed) = 0;
411 
412  virtual ~IDimensionZInfo() = default;
413  };
414 
416  class LIBCZI_API IDimensionTInfo
417  {
418  public:
423  virtual bool TryGetStartTime(XmlDateTime* dateTime) = 0;
424 
429  virtual bool TryGetIntervalDefinition(double* offset, double* increment) = 0;
430 
434  virtual bool TryGetOffsetsList(std::vector<double>* offsets) = 0;
435 
436  virtual ~IDimensionTInfo() = default;
437  };
438 
440  struct DisplaySettingsPOD;
442 
444  class LIBCZI_API IDisplaySettings
445  {
446  public:
449  {
450  double x;
451  double y;
452 
456  SplineControlPoint(double x, double y) : x(x), y(y) {}
457 
461  bool operator==(const SplineControlPoint& rhs) const { return this->x == rhs.x && this->y == rhs.y; }
462 
466  bool operator!=(const SplineControlPoint& rhs) const { return !this->operator==(rhs); }
467  };
468 
470  enum class GradationCurveMode : std::uint8_t
471  {
472  Linear,
473  Gamma,
474  Spline
475  };
476 
477 
482  enum class TintingMode : std::uint8_t
483  {
484  None = 0,
485  Color = 1,
486  LookUpTableExplicit = 2,
487  LookUpTableWellKnown = 3
488  };
489 
492  {
493  double a;
494  double b;
495  double c;
496  double d;
497 
503  double Get(int index) const
504  {
505  switch (index)
506  {
507  case 0: return this->a;
508  case 1: return this->b;
509  case 2: return this->c;
510  case 3: return this->d;
511  default: return std::numeric_limits<double>::quiet_NaN();
512  }
513  }
514  };
515 
517  struct SplineData
518  {
520  double xPos;
521 
524  };
525 
530  virtual void EnumChannels(std::function<bool(int chIndex)> func) const = 0;
531 
538  virtual std::shared_ptr<libCZI::IChannelDisplaySetting> GetChannelDisplaySettings(int chIndex) const = 0;
539 
540  virtual ~IDisplaySettings() = default;
541 
545  static void Clone(const IDisplaySettings* disp, DisplaySettingsPOD& pod);
546  };
547 
549  class LIBCZI_API IChannelDisplaySetting
550  {
551  public:
555  virtual bool GetIsEnabled() const = 0;
556 
560  virtual float GetWeight() const = 0;
561 
568  virtual bool TryGetTintingColorRgb8(libCZI::Rgb8Color* pColor) const = 0;
569 
574  virtual void GetBlackWhitePoint(float* pBlack, float* pWhite) const = 0;
575 
580 
586  virtual bool TryGetGamma(float* gamma) const = 0;
587 
599  virtual bool TryGetSplineControlPoints(std::vector<libCZI::IDisplaySettings::SplineControlPoint>* ctrlPts) const = 0;
600 
606  virtual bool TryGetSplineData(std::vector<libCZI::IDisplaySettings::SplineData>* data) const = 0;
607 
608  virtual ~IChannelDisplaySetting() = default;
609 
614  };
615 
619  {
621  bool isEnabled;
622 
624  float weight;
625 
628 
631 
633  float blackPoint;
634 
636  float whitePoint;
637 
640 
642  float gamma;
643 
645  std::vector<libCZI::IDisplaySettings::SplineControlPoint> splineCtrlPoints;
646 
651 
656  LIBCZI_API static std::shared_ptr<IChannelDisplaySetting> CreateIChannelDisplaySettingSp(const ChannelDisplaySettingsPOD& pod);
657 
660  LIBCZI_API void Clear()
661  {
662  this->isEnabled = false;
663  this->tintingMode = IDisplaySettings::TintingMode::None;
664  this->blackPoint = 0;
665  this->whitePoint = 1;
666  this->gradationCurveMode = IDisplaySettings::GradationCurveMode::Linear;
667  this->weight = 1;
668  this->gamma = 1;
669  }
670  };
671 
675  {
677  std::map<int, ChannelDisplaySettingsPOD > channelDisplaySettings;
678 
683 
688  LIBCZI_API static std::shared_ptr<libCZI::IDisplaySettings> CreateIDisplaySettingSp(const DisplaySettingsPOD& pod);
689  };
690 
692 
695  {
696  public:
700 
704 
707  virtual libCZI::ScalingInfo GetScalingInfo() const = 0;
708 
715  virtual void EnumDimensions(const std::function<bool(DimensionIndex)>& enumDimensions) = 0;
716 
723  virtual std::shared_ptr<IDimensionInfo> GetDimensionInfo(DimensionIndex dim) = 0;
724 
728  virtual std::shared_ptr<IDimensionZInfo> GetDimensionZInfo() = 0;
729 
733  virtual std::shared_ptr<IDimensionTInfo> GetDimensionTInfo() = 0;
734 
738  virtual std::shared_ptr<IDimensionsChannelsInfo> GetDimensionChannelsInfo() = 0;
739 
744  virtual std::shared_ptr<IDisplaySettings> GetDisplaySettings() const = 0;
745 
746  virtual ~ICziMultiDimensionDocumentInfo() = default;
747 
750  std::vector<DimensionIndex> GetDimensions()
751  {
752  std::vector<DimensionIndex> vec;
753  this->EnumDimensions([&](DimensionIndex i)->bool {vec.push_back(i); return true; });
754  return vec;
755  }
756  };
757 
759  class LIBCZI_API IXmlNodeRead
760  {
761  public:
764  virtual std::wstring Name() const = 0;
765 
773  virtual bool TryGetAttribute(const wchar_t* attributeName, std::wstring* attribValue) const = 0;
774 
778  virtual void EnumAttributes(const std::function<bool(const std::wstring& attribName, const std::wstring& attribValue)>& enumFunc) const = 0;
779 
785  virtual bool TryGetValue(std::wstring* value) const = 0;
786 
825  virtual std::shared_ptr<IXmlNodeRead> GetChildNodeReadonly(const char* path) = 0;
826 
830  virtual void EnumChildren(const std::function<bool(std::shared_ptr<IXmlNodeRead>)>& enumChildren) = 0;
831 
835  bool TryGetValueAsDouble(double* p);
836 
840  bool TryGetValueAsFloat(float* p);
841 
845  bool TryGetValueAsInt32(std::int32_t* p);
846 
850  bool TryGetValueAsUInt32(std::uint32_t* p);
851 
855  bool TryGetValueAsInt64(std::int64_t* p);
856 
860  bool TryGetValueAsUInt64(std::uint64_t* p);
861 
866  bool TryGetValueAsBool(bool* p);
867 
868  virtual ~IXmlNodeRead() = default;
869  };
870 
872  class LIBCZI_API ICziMetadata : public IXmlNodeRead
873  {
874  public:
880  virtual bool IsXmlValid() const = 0;
881 
885  virtual std::string GetXml() = 0;
886 
890  virtual std::shared_ptr<libCZI::ICziMultiDimensionDocumentInfo> GetDocumentInfo() = 0;
891 
892  virtual ~ICziMetadata() = default;
893  };
894 
895  class IXmlNodeRw;
896 
898  class LIBCZI_API IXmlNodeWrite
899  {
900  public:
922  virtual std::shared_ptr<IXmlNodeRw> GetOrCreateChildNode(const char* path) = 0;
923 
960  virtual std::shared_ptr<IXmlNodeRw> GetChildNode(const char* path) = 0;
961 
967  virtual std::shared_ptr<IXmlNodeRw> AppendChildNode(const char* name) = 0;
968 
973  virtual void SetAttribute(const char* name, const char* value) = 0;
974 
979  virtual void SetAttribute(const wchar_t* name, const wchar_t* value) = 0;
980 
984  virtual void SetValue(const char* str) = 0;
985 
989  virtual void SetValue(const wchar_t* str) = 0;
990 
994  virtual void SetValueI32(int value) = 0;
995 
999  virtual void SetValueUI32(unsigned int value) = 0;
1000 
1004  virtual void SetValueDbl(double value) = 0;
1005 
1009  virtual void SetValueFlt(float value) = 0;
1010 
1014  virtual void SetValueBool(bool value) = 0;
1015 
1019  virtual void SetValueI64(long long value) = 0;
1020 
1024  virtual void SetValueUI64(unsigned long long value) = 0;
1025 
1027  virtual void RemoveChildren() = 0;
1028 
1030  virtual void RemoveAttributes() = 0;
1031 
1036  virtual bool RemoveChild(const char* name) = 0;
1037 
1042  virtual bool RemoveAttribute(const char* name) = 0;
1043 
1044  virtual ~IXmlNodeWrite() = default;
1045 
1049  void SetValue(const std::string& str) { this->SetValue(str.c_str()); }
1050 
1054  void SetValue(const std::wstring& str) { this->SetValue(str.c_str()); }
1055 
1077  std::shared_ptr<IXmlNodeRw> GetOrCreateChildNode(const std::string& path) { return this->GetOrCreateChildNode(path.c_str()); }
1078 
1082  std::shared_ptr<IXmlNodeRw> GetChildNode(const std::string& path) { return this->GetChildNode(path.c_str()); }
1083  };
1084 
1086  class IXmlNodeRw : public IXmlNodeRead, public IXmlNodeWrite
1087  {
1088  };
1089 
1092  {
1093  public:
1097  virtual std::shared_ptr<IXmlNodeRw> GetRootNode() = 0;
1098 
1102  virtual std::string GetXml(bool withIndent = false) = 0;
1103 
1104  virtual ~ICziMetadataBuilder() = default;
1105  };
1106 
1108  struct LIBCZI_API CustomValueVariant
1109  {
1110  public:
1112  enum class Type
1113  {
1114  Invalid,
1115  Int32,
1116  Float,
1117  Double,
1118  Boolean,
1119  String
1120  };
1121 
1124  {
1125  }
1126 
1130  explicit CustomValueVariant(std::int32_t v)
1131  {
1132  this->SetInt32(v);
1133  }
1134 
1138  explicit CustomValueVariant(double v)
1139  {
1140  this->SetDouble(v);
1141  }
1142 
1146  explicit CustomValueVariant(float v)
1147  {
1148  this->SetFloat(v);
1149  }
1150 
1154  explicit CustomValueVariant(bool v)
1155  {
1156  this->SetBool(v);
1157  }
1158 
1162  explicit CustomValueVariant(const std::string& v)
1163  {
1164  this->SetString(v);
1165  }
1166 
1170  explicit CustomValueVariant(const char* string)
1171  {
1172  this->SetString(string);
1173  }
1174 
1178  void SetInt32(std::int32_t v)
1179  {
1180  this->type = Type::Int32;
1181  this->int32Value = v;
1182  }
1183 
1187  void SetDouble(double v)
1188  {
1189  this->type = Type::Double;
1190  this->doubleValue = v;
1191  }
1192 
1196  void SetFloat(float v)
1197  {
1198  this->type = Type::Float;
1199  this->floatValue = v;
1200  }
1201 
1205  void SetBool(bool v)
1206  {
1207  this->type = Type::Boolean;
1208  this->boolValue = v;
1209  }
1210 
1214  void SetString(const std::string& v)
1215  {
1216  this->type = Type::String;
1217  this->stringValue = v;
1218  }
1219 
1221  std::int32_t GetAsInt32OrThrow() const
1222  {
1223  this->ThrowIfTypeIsUnequalTo(Type::Int32);
1224  return this->int32Value;
1225  }
1226 
1228  double GetAsDoubleOrThrow() const
1229  {
1230  this->ThrowIfTypeIsUnequalTo(Type::Double);
1231  return this->doubleValue;
1232  }
1233 
1235  float GetAsFloatOrThrow() const
1236  {
1237  this->ThrowIfTypeIsUnequalTo(Type::Float);
1238  return this->floatValue;
1239  }
1240 
1242  bool GetAsBoolOrThrow() const
1243  {
1244  this->ThrowIfTypeIsUnequalTo(Type::Boolean);
1245  return this->boolValue;
1246  }
1247 
1249  std::string GetAsStringOrThrow() const
1250  {
1251  this->ThrowIfTypeIsUnequalTo(Type::String);
1252  return this->stringValue;
1253  }
1254 
1256  Type GetType() const
1257  {
1258  return this->type;
1259  }
1260 
1261  private:
1262  Type type;
1263 
1264  union
1265  {
1266  std::int32_t int32Value;
1267  float floatValue;
1268  double doubleValue;
1269  bool boolValue;
1270  };
1271 
1272  std::string stringValue;
1273 
1274  void ThrowIfTypeIsUnequalTo(Type typeToCheck) const
1275  {
1276  if (this->type != typeToCheck)
1277  {
1278  throw std::runtime_error("Unexpected type encountered.");
1279  }
1280  }
1281  };
1282 
1284  class LIBCZI_API MetadataUtils
1285  {
1286  public:
1289  {
1290  bool writePixelType{ false };
1292  bool writeIdAttribute{ false };
1293  std::wstring idAttribute;
1294  bool writeNameAttribute{ false };
1295  std::wstring nameAttribute;
1296  };
1297 
1303  static void WriteImageSizeInformation(libCZI::ICziMetadataBuilder* builder, int width, int height);
1304 
1310 
1317 
1323 
1334  static void WriteDimInfoT_Interval(libCZI::ICziMetadataBuilder* builder, const libCZI::XmlDateTime* startTime, double startOffSet, double increment);
1335 
1344  static void WriteDimInfoT_List(libCZI::ICziMetadataBuilder* builder, const libCZI::XmlDateTime* startTime, const std::function<double(int)>& funcGetOffsets);
1345 
1352  static void WriteDimInfoZ_Interval(libCZI::ICziMetadataBuilder* builder, double startPos, double startOffSet, double increment);
1353 
1360  static void WriteDimInfoZ_List(libCZI::ICziMetadataBuilder* builder, double startPos, const std::function<double(int)>& funcGetOffsets);
1361 
1367 
1372  static void WriteScalingInfo(libCZI::ICziMetadataBuilder* builder, const libCZI::ScalingInfo& scalingInfo);
1373 
1378  static void WriteScalingInfoEx(libCZI::ICziMetadataBuilder* builder, const libCZI::ScalingInfoEx& scalingInfo);
1379 
1387  static void SetOrAddCustomKeyValuePair(libCZI::ICziMetadataBuilder* builder, const std::string& key, const libCZI::CustomValueVariant& value);
1388 
1398  static void WriteDisplaySettings(libCZI::ICziMetadataBuilder* builder, const libCZI::IDisplaySettings* display_settings, const std::map<int, PixelType>* channel_pixel_type = nullptr);
1399 
1410  static void WriteDisplaySettings(libCZI::ICziMetadataBuilder* builder, const libCZI::IDisplaySettings* display_settings, int channel_count, const std::map<int, PixelType>* channel_pixel_type = nullptr);
1411 
1422  static void WriteDisplaySettings(libCZI::ICziMetadataBuilder* builder, const libCZI::IDisplaySettings* display_settings, int channel_count, const std::function<void(int, CoerceAdditionalInfoForChannelDisplaySettings&)>& coerce_additional_info_functor);
1423  };
1424 }
1425 
The display-settings for a channel.
Definition: libCZI_Metadata.h:550
virtual void GetBlackWhitePoint(float *pBlack, float *pWhite) const =0
virtual bool TryGetGamma(float *gamma) const =0
virtual bool TryGetTintingColorRgb8(libCZI::Rgb8Color *pColor) const =0
virtual bool GetIsEnabled() const =0
virtual IDisplaySettings::GradationCurveMode GetGradationCurveMode() const =0
static void Clone(const IChannelDisplaySetting *disp, ChannelDisplaySettingsPOD &pod)
virtual float GetWeight() const =0
virtual bool TryGetSplineData(std::vector< libCZI::IDisplaySettings::SplineData > *data) const =0
virtual bool TryGetSplineControlPoints(std::vector< libCZI::IDisplaySettings::SplineControlPoint > *ctrlPts) const =0
A utility class intended for constructing CZI-metadata.
Definition: libCZI_Metadata.h:1092
virtual std::string GetXml(bool withIndent=false)=0
virtual std::shared_ptr< IXmlNodeRw > GetRootNode()=0
Representation of the CZI-metadata.
Definition: libCZI_Metadata.h:873
virtual bool IsXmlValid() const =0
virtual std::shared_ptr< libCZI::ICziMultiDimensionDocumentInfo > GetDocumentInfo()=0
virtual std::string GetXml()=0
The top-level interface for the CZI-metadata object.
Definition: libCZI_Metadata.h:695
virtual std::shared_ptr< IDimensionInfo > GetDimensionInfo(DimensionIndex dim)=0
virtual std::shared_ptr< IDimensionZInfo > GetDimensionZInfo()=0
virtual std::shared_ptr< IDimensionTInfo > GetDimensionTInfo()=0
virtual libCZI::ScalingInfoEx GetScalingInfoEx() const =0
virtual std::shared_ptr< IDimensionsChannelsInfo > GetDimensionChannelsInfo()=0
virtual std::shared_ptr< IDisplaySettings > GetDisplaySettings() const =0
virtual void EnumDimensions(const std::function< bool(DimensionIndex)> &enumDimensions)=0
virtual libCZI::ScalingInfo GetScalingInfo() const =0
std::vector< DimensionIndex > GetDimensions()
Definition: libCZI_Metadata.h:750
virtual GeneralDocumentInfo GetGeneralDocumentInfo() const =0
Base class for information about the dimension.
Definition: libCZI_Metadata.h:311
virtual void GetInterval(int *start, int *end) const =0
virtual DimensionIndex GetDimension() const =0
virtual void GetIntervalIsExplicitlyStated(bool *startExplicitlyStated, bool *endExplicitlyStated) const =0
This structure defines the information for the "T-dimension". It resembles the ZEN-metadata-structure...
Definition: libCZI_Metadata.h:417
virtual bool TryGetOffsetsList(std::vector< double > *offsets)=0
virtual bool TryGetIntervalDefinition(double *offset, double *increment)=0
virtual bool TryGetStartTime(XmlDateTime *dateTime)=0
This structure defines the information for the "Z-dimension". It resembles the ZEN-metadata-structure...
Definition: libCZI_Metadata.h:334
ZaxisDirection
Definition: libCZI_Metadata.h:360
virtual bool TryGetPositionList(std::vector< double > *positions)=0
virtual bool TryGetZAxisDirection(ZaxisDirection *zAxisDirection)=0
virtual bool TryGetXyzHandedness(XyzHandedness *xyzHandedness)=0
virtual bool TryGetIntervalDefinition(double *offset, double *increment)=0
virtual bool TryZDriveSpeed(double *zdrivespeed)=0
virtual bool TryGetZDriveMode(ZDriveMode *zdrivemode)=0
ZDriveMode
Definition: libCZI_Metadata.h:371
XyzHandedness
Definition: libCZI_Metadata.h:344
virtual bool TryGetReferencePosition(double *d)=0
Information about the set of channels.
Definition: libCZI_Metadata2.h:354
The display settings.
Definition: libCZI_Metadata.h:445
static void Clone(const IDisplaySettings *disp, DisplaySettingsPOD &pod)
TintingMode
Definition: libCZI_Metadata.h:483
@ None
None - which gives the "original color", i.e. in case of RGB the RGB-value is directly used,...
virtual std::shared_ptr< libCZI::IChannelDisplaySetting > GetChannelDisplaySettings(int chIndex) const =0
GradationCurveMode
Values that represent the gradation curve modes.
Definition: libCZI_Metadata.h:471
@ Linear
The gradation curve is a straight line (from white point to black point).
virtual void EnumChannels(std::function< bool(int chIndex)> func) const =0
This interface provides read-only access to an XML-node.
Definition: libCZI_Metadata.h:760
bool TryGetValueAsUInt32(std::uint32_t *p)
bool TryGetValueAsBool(bool *p)
bool TryGetValueAsDouble(double *p)
virtual std::shared_ptr< IXmlNodeRead > GetChildNodeReadonly(const char *path)=0
bool TryGetValueAsUInt64(std::uint64_t *p)
virtual std::wstring Name() const =0
virtual bool TryGetAttribute(const wchar_t *attributeName, std::wstring *attribValue) const =0
virtual bool TryGetValue(std::wstring *value) const =0
virtual void EnumChildren(const std::function< bool(std::shared_ptr< IXmlNodeRead >)> &enumChildren)=0
bool TryGetValueAsInt32(std::int32_t *p)
bool TryGetValueAsInt64(std::int64_t *p)
bool TryGetValueAsFloat(float *p)
virtual void EnumAttributes(const std::function< bool(const std::wstring &attribName, const std::wstring &attribValue)> &enumFunc) const =0
This interface combines read- and write-access for an XML-node.
Definition: libCZI_Metadata.h:1087
This interface provides write access to an XML-node.
Definition: libCZI_Metadata.h:899
std::shared_ptr< IXmlNodeRw > GetChildNode(const std::string &path)
Definition: libCZI_Metadata.h:1082
virtual void SetValueI32(int value)=0
virtual std::shared_ptr< IXmlNodeRw > GetOrCreateChildNode(const char *path)=0
virtual bool RemoveChild(const char *name)=0
virtual void SetValueBool(bool value)=0
virtual void SetValueUI64(unsigned long long value)=0
virtual void SetAttribute(const wchar_t *name, const wchar_t *value)=0
virtual std::shared_ptr< IXmlNodeRw > GetChildNode(const char *path)=0
void SetValue(const std::wstring &str)
Definition: libCZI_Metadata.h:1054
virtual void SetValue(const wchar_t *str)=0
std::shared_ptr< IXmlNodeRw > GetOrCreateChildNode(const std::string &path)
Definition: libCZI_Metadata.h:1077
virtual void RemoveChildren()=0
Removes all children of this node.
virtual void SetValueDbl(double value)=0
virtual void SetValueFlt(float value)=0
virtual void SetValueUI32(unsigned int value)=0
virtual void SetValueI64(long long value)=0
virtual bool RemoveAttribute(const char *name)=0
virtual void SetValue(const char *str)=0
virtual void RemoveAttributes()=0
Removes all attributes of this node.
void SetValue(const std::string &str)
Definition: libCZI_Metadata.h:1049
virtual void SetAttribute(const char *name, const char *value)=0
virtual std::shared_ptr< IXmlNodeRw > AppendChildNode(const char *name)=0
Helper functions useful for constructing CZI-metadata.
Definition: libCZI_Metadata.h:1285
static void WriteDimensionSize(libCZI::ICziMetadataBuilder *builder, libCZI::DimensionIndex dim, int size)
static void WriteFillWithSubBlockStatistics(libCZI::ICziMetadataBuilder *builder, const libCZI::SubBlockStatistics &statistics)
static void WriteDimInfoT_List(libCZI::ICziMetadataBuilder *builder, const libCZI::XmlDateTime *startTime, const std::function< double(int)> &funcGetOffsets)
static void WriteScalingInfoEx(libCZI::ICziMetadataBuilder *builder, const libCZI::ScalingInfoEx &scalingInfo)
static void WriteDimInfoZ_Interval(libCZI::ICziMetadataBuilder *builder, double startPos, double startOffSet, double increment)
static void WriteMIndexSizeInformation(libCZI::ICziMetadataBuilder *builder, int mSize)
static void WriteDimInfoT_Interval(libCZI::ICziMetadataBuilder *builder, const libCZI::XmlDateTime *startTime, double startOffSet, double increment)
static void WriteDisplaySettings(libCZI::ICziMetadataBuilder *builder, const libCZI::IDisplaySettings *display_settings, int channel_count, const std::function< void(int, CoerceAdditionalInfoForChannelDisplaySettings &)> &coerce_additional_info_functor)
static void WriteDisplaySettings(libCZI::ICziMetadataBuilder *builder, const libCZI::IDisplaySettings *display_settings, int channel_count, const std::map< int, PixelType > *channel_pixel_type=nullptr)
static void WriteDimInfoZ_List(libCZI::ICziMetadataBuilder *builder, double startPos, const std::function< double(int)> &funcGetOffsets)
static void WriteGeneralDocumentInfo(libCZI::ICziMetadataBuilder *builder, const libCZI::GeneralDocumentInfo &info)
static void WriteDisplaySettings(libCZI::ICziMetadataBuilder *builder, const libCZI::IDisplaySettings *display_settings, const std::map< int, PixelType > *channel_pixel_type=nullptr)
static void SetOrAddCustomKeyValuePair(libCZI::ICziMetadataBuilder *builder, const std::string &key, const libCZI::CustomValueVariant &value)
static void WriteImageSizeInformation(libCZI::ICziMetadataBuilder *builder, int width, int height)
static void WriteScalingInfo(libCZI::ICziMetadataBuilder *builder, const libCZI::ScalingInfo &scalingInfo)
External interfaces, classes, functions and structs are found in the namespace "libCZI".
Definition: libCZI.h:31
DimensionIndex
Values that represent dimension indexes.
Definition: libCZI_DimCoordinate.h:17
@ None
No camera processing was used.
PixelType
An enum representing a pixel-type.
Definition: libCZI_Pixels.h:114
@ Invalid
Invalid pixel type.
Definition: libCZI_Metadata.h:619
bool isEnabled
A boolean indicating whether the corresponding channel is 'active' in the multi-channel-composition.
Definition: libCZI_Metadata.h:621
static LIBCZI_API IChannelDisplaySetting * CreateIChannelDisplaySetting(const ChannelDisplaySettingsPOD &pod)
IDisplaySettings::TintingMode tintingMode
The tinting mode.
Definition: libCZI_Metadata.h:627
IDisplaySettings::GradationCurveMode gradationCurveMode
The gradation curve mode.
Definition: libCZI_Metadata.h:639
LIBCZI_API void Clear()
Definition: libCZI_Metadata.h:660
static LIBCZI_API std::shared_ptr< IChannelDisplaySetting > CreateIChannelDisplaySettingSp(const ChannelDisplaySettingsPOD &pod)
float blackPoint
The (normalized) black point value.
Definition: libCZI_Metadata.h:633
float whitePoint
The (normalized) white point value.
Definition: libCZI_Metadata.h:636
float gamma
The value for gamma (only valid if gradation curve mode == Gamma).
Definition: libCZI_Metadata.h:642
libCZI::Rgb8Color tintingColor
The tinting color (only valid if tinting mode == Color).
Definition: libCZI_Metadata.h:630
float weight
The weight of the channel (for multi-channel-composition).
Definition: libCZI_Metadata.h:624
std::vector< libCZI::IDisplaySettings::SplineControlPoint > splineCtrlPoints
The spline control points (only valid if gradation curve mode == Spline).
Definition: libCZI_Metadata.h:645
Variant for CustomValue.
Definition: libCZI_Metadata.h:1109
CustomValueVariant()
Default constructor - setting the variant to 'invalid'.
Definition: libCZI_Metadata.h:1123
std::int32_t GetAsInt32OrThrow() const
Returns integer value if ValueType is int, otherwise throws a RuntimeError.
Definition: libCZI_Metadata.h:1221
Type GetType() const
Returns ValueType.
Definition: libCZI_Metadata.h:1256
CustomValueVariant(std::int32_t v)
Definition: libCZI_Metadata.h:1130
CustomValueVariant(bool v)
Definition: libCZI_Metadata.h:1154
void SetFloat(float v)
Definition: libCZI_Metadata.h:1196
void SetBool(bool v)
Definition: libCZI_Metadata.h:1205
float GetAsFloatOrThrow() const
Returns float value if ValueType is 'Float', otherwise throws a RuntimeError.
Definition: libCZI_Metadata.h:1235
std::string GetAsStringOrThrow() const
Returns string value if ValueType is string, otherwise throws a RuntimeError.
Definition: libCZI_Metadata.h:1249
double GetAsDoubleOrThrow() const
Returns double value if ValueType is double, otherwise throws a RuntimeError.
Definition: libCZI_Metadata.h:1228
bool GetAsBoolOrThrow() const
Returns boolean value if ValueType is boolean, otherwise throws a RuntimeError.
Definition: libCZI_Metadata.h:1242
void SetString(const std::string &v)
Definition: libCZI_Metadata.h:1214
void SetInt32(std::int32_t v)
Definition: libCZI_Metadata.h:1178
CustomValueVariant(double v)
Definition: libCZI_Metadata.h:1138
void SetDouble(double v)
Definition: libCZI_Metadata.h:1187
Type
Values that represent the type represented by this variant.
Definition: libCZI_Metadata.h:1113
CustomValueVariant(const std::string &v)
Definition: libCZI_Metadata.h:1162
CustomValueVariant(float v)
Definition: libCZI_Metadata.h:1146
CustomValueVariant(const char *string)
Definition: libCZI_Metadata.h:1170
Definition: libCZI_Metadata.h:675
std::map< int, ChannelDisplaySettingsPOD > channelDisplaySettings
The channel display settings. Key is the channel index, and value is the POD-channel-display-data str...
Definition: libCZI_Metadata.h:677
static LIBCZI_API libCZI::IDisplaySettings * CreateIDisplaySetting(const DisplaySettingsPOD &pod)
static LIBCZI_API std::shared_ptr< libCZI::IDisplaySettings > CreateIDisplaySettingSp(const DisplaySettingsPOD &pod)
General document information - corresponding to Information/Document.
Definition: libCZI_Metadata.h:100
LIBCZI_API void SetKeywords(const wchar_t *sz)
Definition: libCZI_Metadata.h:173
LIBCZI_API void SetTitle(const wchar_t *sz)
Definition: libCZI_Metadata.h:133
LIBCZI_API void SetUserName(const std::wstring &str)
Definition: libCZI_Metadata.h:148
int rating
An integer specifying a "five-star-rating" (should be between 0 and 5).
Definition: libCZI_Metadata.h:116
std::wstring userName
Name of the user who created the document.
Definition: libCZI_Metadata.h:108
LIBCZI_API void SetCreationDate(const std::wstring &str)
Definition: libCZI_Metadata.h:192
bool comment_valid
Whether the field comment is valid.
Definition: libCZI_Metadata.h:111
LIBCZI_API GeneralDocumentInfo()
Default constructor - all fields are intially marked "invalid".
Definition: libCZI_Metadata.h:102
LIBCZI_API void SetUserName(const wchar_t *sz)
Definition: libCZI_Metadata.h:143
bool rating_valid
Whether the field rating is valid.
Definition: libCZI_Metadata.h:115
std::wstring comment
A text with comments on the document.
Definition: libCZI_Metadata.h:112
LIBCZI_API void SetCreationDate(const wchar_t *sz)
Definition: libCZI_Metadata.h:187
bool userName_valid
Whether the field userName is valid.
Definition: libCZI_Metadata.h:107
std::wstring creationDateTime
The creation date of the document (formatted as xml-datatype "dateTime").
Definition: libCZI_Metadata.h:118
LIBCZI_API void SetTitle(const std::wstring &str)
Definition: libCZI_Metadata.h:138
LIBCZI_API void SetRating(int rating)
Definition: libCZI_Metadata.h:182
LIBCZI_API void SetName(const std::wstring &str)
Definition: libCZI_Metadata.h:128
bool creationDateTime_valid
Whether the field creationDateTime is valid.
Definition: libCZI_Metadata.h:117
LIBCZI_API void Clear()
Sets all fields to "invalid".
Definition: libCZI_Metadata.h:200
LIBCZI_API void SetCreationDate(const XmlDateTime *dateTime)
Definition: libCZI_Metadata.h:197
std::wstring title
Title of the document.
Definition: libCZI_Metadata.h:106
LIBCZI_API void SetComment(const wchar_t *sz)
Definition: libCZI_Metadata.h:163
LIBCZI_API void SetDescription(const std::wstring &str)
Definition: libCZI_Metadata.h:158
LIBCZI_API void SetKeywords(const std::wstring &str)
Definition: libCZI_Metadata.h:178
std::wstring description
A text describing the document.
Definition: libCZI_Metadata.h:110
bool name_valid
Whether the field name is valid.
Definition: libCZI_Metadata.h:103
bool keywords_valid
Whether the field keywords is valid.
Definition: libCZI_Metadata.h:113
LIBCZI_API void SetDescription(const wchar_t *sz)
Definition: libCZI_Metadata.h:153
std::wstring keywords
List of keywords (should be separated by semicolons)
Definition: libCZI_Metadata.h:114
LIBCZI_API void SetComment(const std::wstring &str)
Definition: libCZI_Metadata.h:168
LIBCZI_API void SetName(const wchar_t *sz)
Definition: libCZI_Metadata.h:123
bool title_valid
Whether the field title is valid.
Definition: libCZI_Metadata.h:105
bool description_valid
Whether the field description is valid.
Definition: libCZI_Metadata.h:109
std::wstring name
Name of the document.
Definition: libCZI_Metadata.h:104
The coefficients of a cubic spline defined by .
Definition: libCZI_Metadata.h:492
double d
The constant.
Definition: libCZI_Metadata.h:496
double c
The coefficient of the linear term.
Definition: libCZI_Metadata.h:495
double a
The coefficient of the cube.
Definition: libCZI_Metadata.h:493
double b
The coefficient of the square.
Definition: libCZI_Metadata.h:494
double Get(int index) const
Definition: libCZI_Metadata.h:503
The (normalized) control points of a spline.
Definition: libCZI_Metadata.h:449
SplineControlPoint(double x, double y)
Definition: libCZI_Metadata.h:456
double x
The normalized x-coordinate of a spline control point.
Definition: libCZI_Metadata.h:450
bool operator!=(const SplineControlPoint &rhs) const
Definition: libCZI_Metadata.h:466
double y
The normalized y-coordinate of a spline control point.
Definition: libCZI_Metadata.h:451
bool operator==(const SplineControlPoint &rhs) const
Definition: libCZI_Metadata.h:461
The definition of the (piecewise) spline. The spline starts at xPos which is the normalized position ...
Definition: libCZI_Metadata.h:518
CubicSplineCoefficients coefficients
The spline coefficients for this piece.
Definition: libCZI_Metadata.h:523
double xPos
The (normalized) position for which this spline definition is valid.
Definition: libCZI_Metadata.h:520
This struct is used for controlling the operation of adding display-settings.
Definition: libCZI_Metadata.h:1289
std::wstring nameAttribute
The value of the attribute "Name" (if "writeNameAttribute" is true).
Definition: libCZI_Metadata.h:1295
std::wstring idAttribute
The value of the attribute "Id" (if "writeIdAttribute" is true).
Definition: libCZI_Metadata.h:1293
libCZI::PixelType pixelType
The pixel-type to write to the element "PixelType" (if "writePixelType" is true).
Definition: libCZI_Metadata.h:1291
A structure representing an R-G-B-color triple (as bytes).
Definition: libCZI_Pixels.h:98
Definition: libCZI_Metadata.h:285
std::wstring defaultUnitFormatY
The default unit-format for Y.
Definition: libCZI_Metadata.h:287
LIBCZI_API std::wstring GetDefaultUnitFormat(char d) const
Definition: libCZI_Metadata.h:297
std::wstring defaultUnitFormatX
The default unit-format for X.
Definition: libCZI_Metadata.h:286
std::wstring defaultUnitFormatZ
The default unit-format for Z.
Definition: libCZI_Metadata.h:288
Scaling information - gives the size of a pixel.
Definition: libCZI_Metadata.h:223
double scaleY
The length of a pixel in y-direction in the unit meters. If unknown/invalid, this value is numeric_li...
Definition: libCZI_Metadata.h:227
double scaleZ
The length of a pixel in y-direction in the unit meters. If unknown/invalid, this value is numeric_li...
Definition: libCZI_Metadata.h:228
ScalingInfo()
Default constructor - sets all members to invalid.
Definition: libCZI_Metadata.h:225
bool IsScaleZValid() const
Definition: libCZI_Metadata.h:243
bool IsScaleValid(char d) const
Definition: libCZI_Metadata.h:252
bool IsScaleXValid() const
Definition: libCZI_Metadata.h:233
double scaleX
The length of a pixel in x-direction in the unit meters. If unknown/invalid, this value is numeric_li...
Definition: libCZI_Metadata.h:226
double GetScale(char d) const
Definition: libCZI_Metadata.h:270
bool IsScaleYValid() const
Definition: libCZI_Metadata.h:238
Statistics about all sub-blocks found in a CZI-document.
Definition: libCZI.h:439
This structure specifies the information in an XSD-DateTime field (cf. https://www....
Definition: libCZI_Metadata.h:26
std::string ToXmlString() const
bool isUTC
True if this object is specifying the time-date in UTC.
Definition: libCZI_Metadata.h:34
int year
year [-9999 - 9999]
Definition: libCZI_Metadata.h:32
int hour
hours since midnight - [0, 23]
Definition: libCZI_Metadata.h:29
int offsetMinutes
The minutes of the timezone-offset. If greater than 60 or negative, it indicates an invalid timezone-...
Definition: libCZI_Metadata.h:40
bool IsValid() const
void Clear()
Clears this object to its blank/initial state.
Definition: libCZI_Metadata.h:43
std::wstring ToXmlWstring() const
int offsetHours
The hours of the timezone-offset. If greater than 24 or less than -24, it indicates an invalid timezo...
Definition: libCZI_Metadata.h:37
int mon
months since January - [0, 11]
Definition: libCZI_Metadata.h:31
bool HasTimeZoneOffset() const
Definition: libCZI_Metadata.h:54
int min
minutes after the hour - [0, 59]
Definition: libCZI_Metadata.h:28
static bool TryParse(const char *sz, XmlDateTime *ptrDateTime)
int sec
Seconds after the minute - [0, 60] including leap second.
Definition: libCZI_Metadata.h:27
int mday
day of the month - [1, 31]
Definition: libCZI_Metadata.h:30
static bool TryParse(const wchar_t *szw, XmlDateTime *ptrDateTime)