Coverage Report

Created: 2025-06-09 07:07

/src/gdal/frmts/safe/safedataset.h
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *
3
 * Project:  Sentinel SAFE products
4
 * Purpose:  Sentinel Products (manifest.safe) driver
5
 * Author:   Delfim Rego, delfimrego@gmail.com
6
 *
7
 ******************************************************************************
8
 * Copyright (c) 2015, Delfim Rego <delfimrego@gmail.com>
9
 *
10
 * SPDX-License-Identifier: MIT
11
 ****************************************************************************/
12
13
#ifndef SAFEDATASET_H_INCLUDED
14
#define SAFEDATASET_H_INCLUDED
15
16
#include "cpl_minixml.h"
17
#include "cpl_string.h"
18
#include "gdal_frmts.h"
19
#include "gdal_pam.h"
20
#include "ogr_spatialref.h"
21
#include <set>
22
#include <map>
23
#include <chrono>
24
#include <ctime>
25
#include <iostream>
26
#include <thread>
27
#include <vector>
28
29
/************************************************************************/
30
/* ==================================================================== */
31
/*                               SAFEDataset                            */
32
/* ==================================================================== */
33
/************************************************************************/
34
35
class SAFEDataset final : public GDALPamDataset
36
{
37
    CPLXMLTreeCloser psManifest{nullptr};
38
39
    int nGCPCount = 0;
40
    GDAL_GCP *pasGCPList = nullptr;
41
    OGRSpatialReference m_oGCPSRS{};
42
    char **papszSubDatasets = nullptr;
43
    double adfGeoTransform[6] = {0.0, 1.0, 0.0, 0.0, 0.0, 1.0};
44
    bool bHaveGeoTransform = false;
45
    char **papszExtraFiles = nullptr;
46
    int m_nSubDSNum = 0;
47
48
  protected:
49
    virtual int CloseDependentDatasets() override;
50
51
    static const CPLXMLNode *GetMetaDataObject(const CPLXMLNode *,
52
                                               const char *);
53
54
    static const CPLXMLNode *GetDataObject(const CPLXMLNode *, const char *);
55
    static const CPLXMLNode *GetDataObject(const CPLXMLNode *,
56
                                           const CPLXMLNode *, const char *);
57
58
    void AddSubDataset(const CPLString &osName, const CPLString &osDesc);
59
60
  public:
61
    SAFEDataset();
62
    virtual ~SAFEDataset();
63
64
    virtual int GetGCPCount() override;
65
    const OGRSpatialReference *GetGCPSpatialRef() const override;
66
    virtual const GDAL_GCP *GetGCPs() override;
67
68
    virtual CPLErr GetGeoTransform(double *) override;
69
70
    virtual char **GetMetadataDomainList() override;
71
    virtual char **GetMetadata(const char *pszDomain = "") override;
72
73
    virtual char **GetFileList(void) override;
74
75
    static GDALDataset *Open(GDALOpenInfo *);
76
    static int Identify(GDALOpenInfo *);
77
78
    const CPLXMLNode *GetManifest()
79
0
    {
80
0
        return psManifest.get();
81
0
    }
82
};
83
84
/************************************************************************/
85
/* ==================================================================== */
86
/*                    SAFERasterBand                                    */
87
/* ==================================================================== */
88
/************************************************************************/
89
90
class SAFERasterBand final : public GDALPamRasterBand
91
{
92
    std::unique_ptr<GDALDataset> poBandFile{};
93
94
  public:
95
    SAFERasterBand(SAFEDataset *poDSIn, GDALDataType eDataTypeIn,
96
                   const CPLString &osSwath, const CPLString &osPol,
97
                   std::unique_ptr<GDALDataset> &&poBandFileIn);
98
99
    virtual CPLErr IReadBlock(int, int, void *) override;
100
101
    static GDALDataset *Open(GDALOpenInfo *);
102
};
103
104
/************************************************************************/
105
/* ==================================================================== */
106
/*                    SAFESLCRasterBand                                 */
107
/* ==================================================================== */
108
/************************************************************************/
109
110
class SAFESLCRasterBand : public GDALPamRasterBand
111
{
112
  public:
113
    typedef enum BandType
114
    {
115
        COMPLEX = 0,
116
        INTENSITY
117
    } BandType;
118
119
    SAFESLCRasterBand(SAFEDataset *poDSIn, GDALDataType eDataTypeIn,
120
                      const CPLString &osSwath, const CPLString &osPol,
121
                      std::unique_ptr<GDALDataset> &&poBandFileIn,
122
                      BandType eBandType);
123
124
    virtual CPLErr IReadBlock(int, int, void *) override;
125
    static GDALDataset *Open(GDALOpenInfo *);
126
127
  private:
128
    std::unique_ptr<GDALDataset> poBandFile{};
129
    BandType m_eBandType = COMPLEX;
130
    GDALDataType m_eInputDataType = GDT_Unknown;
131
};
132
133
/************************************************************************/
134
/* ==================================================================== */
135
/*                   SAFECalibratedRasterBand                           */
136
/* ==================================================================== */
137
/************************************************************************/
138
139
class SAFECalibratedRasterBand : public GDALPamRasterBand
140
{
141
  public:
142
    typedef enum CalibrationType
143
    {
144
        SIGMA_NOUGHT = 0,
145
        BETA_NOUGHT,
146
        GAMMA
147
    } CalibrationType;
148
149
    SAFECalibratedRasterBand(SAFEDataset *poDSIn, GDALDataType eDataTypeIn,
150
                             const CPLString &osSwath,
151
                             const CPLString &osPolarization,
152
                             std::unique_ptr<GDALDataset> &&poBandDatasetIn,
153
                             const char *pszCalibrationFilename,
154
                             CalibrationType eCalibrationType);
155
156
    virtual CPLErr IReadBlock(int, int, void *) override;
157
158
    bool ReadLUT();
159
160
    static GDALDataset *Open(GDALOpenInfo *);
161
162
  private:
163
    typedef std::chrono::system_clock::time_point TimePoint;
164
165
    std::unique_ptr<GDALDataset> poBandDataset{};
166
    GDALDataType m_eInputDataType = GDT_Unknown;
167
    std::vector<float> m_afTable;
168
    CPLString m_osCalibrationFilename;
169
    std::vector<int> m_anLineLUT;
170
    std::vector<int> m_anPixelLUT;
171
    TimePoint m_oStartTimePoint;
172
    TimePoint m_oStopTimePoint;
173
    int m_nNumPixels = 0;
174
    CPLStringList m_oAzimuthList;
175
    CalibrationType m_eCalibrationType = SIGMA_NOUGHT;
176
177
    static TimePoint getTimePoint(const char *pszTime);
178
    static double getTimeDiff(TimePoint oT1, TimePoint oT2);
179
    static TimePoint getazTime(TimePoint oStart, TimePoint oStop,
180
                               long nNumOfLines, int nOffset);
181
182
    int getCalibrationVectorIndex(int nLineNo);
183
    int getPixelIndex(int nPixelNo);
184
};
185
186
#endif