PCL
IntegrationMetadata.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.7.0
6 // ----------------------------------------------------------------------------
7 // pcl/IntegrationMetadata.h - Released 2024-06-18T15:48:54Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2024 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (https://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_IntegrationMetadata_h
53 #define __PCL_IntegrationMetadata_h
54 
56 
57 #include <pcl/Console.h>
58 #include <pcl/FITSHeaderKeyword.h>
59 #include <pcl/Property.h>
60 #include <pcl/TimePoint.h>
61 
62 namespace pcl
63 {
64 
65 // ----------------------------------------------------------------------------
66 
87 template <class T>
88 class PCL_CLASS ConsistentlyDefined
89 {
90 public:
91 
99  : m_value() // N.B: this initialization prevents warnings such as
100  { // 'ConsistentlyDefined<>::m_value may be used uninitialized...'
101  }
102 
111 
112  /*
113  * Move constructor.
114  */
116 
121  ConsistentlyDefined( const T& value )
122  : m_value( value )
123  , m_defined( true )
124  {
125  }
126 
132  T& operator =( const T& value )
133  {
134  m_value = value;
135  m_defined = m_consistent = true;
136  return m_value;
137  }
138 
157  ConsistentlyDefined& operator =( const ConsistentlyDefined& other )
158  {
159  if ( m_consistent )
160  if ( other.m_defined )
161  {
162  if ( m_defined )
163  {
164  if ( m_value != other.m_value )
165  m_consistent = false;
166  }
167  else
168  {
169  m_value = other.m_value;
170  m_defined = true;
171  }
172  }
173  else
174  {
175  if ( m_defined )
176  m_consistent = false;
177  }
178 
179  return *this;
180  }
181 
201  ConsistentlyDefined& operator +=( const ConsistentlyDefined& other )
202  {
203  if ( m_consistent )
204  if ( other.m_defined )
205  {
206  if ( m_defined )
207  m_value += other.m_value;
208  else
209  {
210  m_value = other.m_value;
211  m_defined = true;
212  }
213  }
214  else
215  {
216  if ( m_defined )
217  m_consistent = false;
218  }
219 
220  return *this;
221  }
222 
237  ConsistentlyDefined& operator +=( const T& otherValue )
238  {
239  if ( m_consistent )
240  if ( m_defined )
241  m_value += otherValue;
242  else
243  {
244  m_value = otherValue;
245  m_defined = true;
246  }
247 
248  return *this;
249  }
250 
257  const T& operator ()() const
258  {
259  return m_value;
260  }
261 
265  bool IsDefined() const
266  {
267  return m_defined;
268  }
269 
274  bool IsConsistent() const
275  {
276  return m_consistent;
277  }
278 
290  bool IsConsistentlyDefined( const String& what = String() ) const
291  {
292  if ( m_defined )
293  {
294  if ( m_consistent )
295  return true;
296  if ( !what.IsEmpty() )
297  Console().WarningLn( "<end><cbr>** Warning: Inconsistent " + what + " value(s) - metadata not generated." );
298  }
299  return false;
300  }
301 
305  void Undefine()
306  {
307  m_defined = false;
308  }
309 
314  {
315  m_consistent = false;
316  }
317 
322  void ForceValue( const T& value )
323  {
324  m_value = value;
325  }
326 
332  String ToString() const
333  {
334  return m_defined ? String( m_value ) : String();
335  }
336 
337 private:
338 
339  T m_value;
340  bool m_defined = false;
341  bool m_consistent = true;
342 };
343 
344 // ----------------------------------------------------------------------------
345 
346 #define __PCL_INTEGRATION_METADATA_VERSION "1.2"
347 
348 /*
349  * Optional, consistently defined metadata of an integrable image.
350  *
351  * ### N.B. Internal use - Not a public interface.
352  */
353 class IntegrationMetadata
354 {
355 public:
356 
357  String version = __PCL_INTEGRATION_METADATA_VERSION;
358  ConsistentlyDefined<String> author;
359  ConsistentlyDefined<String> observer;
360  ConsistentlyDefined<String> instrumentName;
361  ConsistentlyDefined<String> frameType;
362  ConsistentlyDefined<String> filterName;
363  ConsistentlyDefined<IsoString> cfaPatternName;
364  ConsistentlyDefined<IsoString> cfaPattern;
365  ConsistentlyDefined<int> cfaXOffset; // px
366  ConsistentlyDefined<int> cfaYOffset; // px
367  ConsistentlyDefined<double> pedestal; // DN
368  ConsistentlyDefined<double> expTime; // s
369  ConsistentlyDefined<double> sensorTemp; // C
370  ConsistentlyDefined<double> xPixSize; // um
371  ConsistentlyDefined<double> yPixSize; // um
372  ConsistentlyDefined<double> cameraGain;
373  ConsistentlyDefined<unsigned> cameraISO;
374  ConsistentlyDefined<unsigned> xBinning;
375  ConsistentlyDefined<unsigned> yBinning;
376  ConsistentlyDefined<unsigned> xOrigin; // px
377  ConsistentlyDefined<unsigned> yOrigin; // px
378  ConsistentlyDefined<String> telescopeName;
379  ConsistentlyDefined<double> focalLength; // mm
380  ConsistentlyDefined<double> aperture; // mm
381  ConsistentlyDefined<double> apertureArea; // mm^2
382  ConsistentlyDefined<String> objectName;
383  ConsistentlyDefined<TimePoint> startTime; // UTC
384  ConsistentlyDefined<TimePoint> endTime; // UTC
385  ConsistentlyDefined<double> ra; // deg (-180,+180]
386  ConsistentlyDefined<double> dec; // deg [-90,+90]
387  ConsistentlyDefined<IsoString> celCrdSys; // ICRS, FK5
388  ConsistentlyDefined<double> equinox; // yr
389  ConsistentlyDefined<double> longObs; // deg (-180,+180]
390  ConsistentlyDefined<double> latObs; // deg [-90,+90]
391  ConsistentlyDefined<double> altObs; // m
392 
393  IntegrationMetadata() = default;
394  IntegrationMetadata( const IntegrationMetadata& ) = default;
395 
396  IntegrationMetadata( const PropertyArray&, const FITSKeywordArray& );
397  IntegrationMetadata( const String& serialization );
398 
399  String Serialize() const;
400 
401  bool IsValid() const
402  {
403  return m_valid;
404  }
405 
406  void UpdatePropertiesAndKeywords( PropertyArray&, FITSKeywordArray& ) const;
407 
408  static IntegrationMetadata Summary( const Array<IntegrationMetadata>& );
409 
410 private:
411 
412  bool m_valid = false;
413 
414  // Block separators for text metadata serialization (UTF-16).
415  constexpr static char16_type ItemSeparator = char16_type( 0x2028 ); // Unicode Line Separator
416  constexpr static char16_type TokenSeparator = char16_type( 0x2029 ); // Unicode Paragraph Separator
417 };
418 
419 // ----------------------------------------------------------------------------
420 
421 } // pcl
422 
423 #endif // __PCL_IntegrationMetadata_h
424 
425 // ----------------------------------------------------------------------------
426 // EOF pcl/IntegrationMetadata.h - Released 2024-06-18T15:48:54Z
An object that can be in consistently defined or undefined/inconsistent states.
ConsistentlyDefined(const T &value)
ConsistentlyDefined(const ConsistentlyDefined &)=default
void ForceValue(const T &value)
bool IsConsistentlyDefined(const String &what=String()) const
A high-level interface to a PixInsight processing console.
Definition: Console.h:359
void WarningLn(const String &s)
Definition: Console.h:471
Dynamic array of FITS header keywords.
Dynamic array of Property objects.
Unicode (UTF-16) string.
Definition: String.h:8113
uint16 char16_type
Definition: Defs.h:1141
PCL root namespace.
Definition: AbstractImage.h:77