Line data Source code
1 : /******************************************************************************
2 : *
3 : * Name: gdalmultidim_array_unscaled.h
4 : * Project: GDAL Core
5 : * Purpose: Declaration of GDALMDArrayUnscaled
6 : * Author: Even Rouault <even.rouault at spatialys.com>
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2019, Even Rouault <even.rouault at spatialys.com>
10 : *
11 : * SPDX-License-Identifier: MIT
12 : ****************************************************************************/
13 :
14 : #ifndef GDALMULTIDIM_ARRAY_UNSCALED_H
15 : #define GDALMULTIDIM_ARRAY_UNSCALED_H
16 :
17 : #include "gdal_multidim.h"
18 : #include "gdal_pam_multidim.h"
19 :
20 : //! @cond Doxygen_Suppress
21 :
22 : /************************************************************************/
23 : /* GDALMDArrayUnscaled */
24 : /************************************************************************/
25 :
26 : class GDALMDArrayUnscaled final : public GDALPamMDArray
27 : {
28 : private:
29 : std::shared_ptr<GDALMDArray> m_poParent{};
30 : const GDALExtendedDataType m_dt;
31 : bool m_bHasNoData;
32 : const double m_dfScale;
33 : const double m_dfOffset;
34 : std::vector<GByte> m_abyRawNoData{};
35 :
36 : protected:
37 13 : explicit GDALMDArrayUnscaled(const std::shared_ptr<GDALMDArray> &poParent,
38 : double dfScale, double dfOffset,
39 : double dfOverriddenDstNodata, GDALDataType eDT)
40 26 : : GDALAbstractMDArray(std::string(),
41 26 : "Unscaled view of " + poParent->GetFullName()),
42 : GDALPamMDArray(
43 26 : std::string(), "Unscaled view of " + poParent->GetFullName(),
44 26 : GDALPamMultiDim::GetPAM(poParent), poParent->GetContext()),
45 13 : m_poParent(std::move(poParent)),
46 : m_dt(GDALExtendedDataType::Create(eDT)),
47 13 : m_bHasNoData(m_poParent->GetRawNoDataValue() != nullptr),
48 78 : m_dfScale(dfScale), m_dfOffset(dfOffset)
49 : {
50 13 : m_abyRawNoData.resize(m_dt.GetSize());
51 : const auto eNonComplexDT =
52 13 : GDALGetNonComplexDataType(m_dt.GetNumericDataType());
53 26 : GDALCopyWords64(
54 13 : &dfOverriddenDstNodata, GDT_Float64, 0, m_abyRawNoData.data(),
55 : eNonComplexDT, GDALGetDataTypeSizeBytes(eNonComplexDT),
56 13 : GDALDataTypeIsComplex(m_dt.GetNumericDataType()) ? 2 : 1);
57 13 : }
58 :
59 : bool IRead(const GUInt64 *arrayStartIdx, const size_t *count,
60 : const GInt64 *arrayStep, const GPtrDiff_t *bufferStride,
61 : const GDALExtendedDataType &bufferDataType,
62 : void *pDstBuffer) const override;
63 :
64 : bool IWrite(const GUInt64 *arrayStartIdx, const size_t *count,
65 : const GInt64 *arrayStep, const GPtrDiff_t *bufferStride,
66 : const GDALExtendedDataType &bufferDataType,
67 : const void *pSrcBuffer) override;
68 :
69 0 : bool IAdviseRead(const GUInt64 *arrayStartIdx, const size_t *count,
70 : CSLConstList papszOptions) const override
71 : {
72 0 : return m_poParent->AdviseRead(arrayStartIdx, count, papszOptions);
73 : }
74 :
75 : public:
76 : static std::shared_ptr<GDALMDArrayUnscaled>
77 13 : Create(const std::shared_ptr<GDALMDArray> &poParent, double dfScale,
78 : double dfOffset, double dfDstNodata, GDALDataType eDT)
79 : {
80 : auto newAr(std::shared_ptr<GDALMDArrayUnscaled>(new GDALMDArrayUnscaled(
81 13 : poParent, dfScale, dfOffset, dfDstNodata, eDT)));
82 13 : newAr->SetSelf(newAr);
83 13 : return newAr;
84 : }
85 :
86 1 : bool IsWritable() const override
87 : {
88 1 : return m_poParent->IsWritable();
89 : }
90 :
91 14 : const std::string &GetFilename() const override
92 : {
93 14 : return m_poParent->GetFilename();
94 : }
95 :
96 : const std::vector<std::shared_ptr<GDALDimension>> &
97 221 : GetDimensions() const override
98 : {
99 221 : return m_poParent->GetDimensions();
100 : }
101 :
102 103 : const GDALExtendedDataType &GetDataType() const override
103 : {
104 103 : return m_dt;
105 : }
106 :
107 1 : const std::string &GetUnit() const override
108 : {
109 1 : return m_poParent->GetUnit();
110 : }
111 :
112 1 : std::shared_ptr<OGRSpatialReference> GetSpatialRef() const override
113 : {
114 1 : return m_poParent->GetSpatialRef();
115 : }
116 :
117 6 : const void *GetRawNoDataValue() const override
118 : {
119 6 : return m_bHasNoData ? m_abyRawNoData.data() : nullptr;
120 : }
121 :
122 1 : bool SetRawNoDataValue(const void *pRawNoData) override
123 : {
124 1 : m_bHasNoData = true;
125 1 : memcpy(m_abyRawNoData.data(), pRawNoData, m_dt.GetSize());
126 1 : return true;
127 : }
128 :
129 4 : std::vector<GUInt64> GetBlockSize() const override
130 : {
131 4 : return m_poParent->GetBlockSize();
132 : }
133 :
134 : std::shared_ptr<GDALAttribute>
135 0 : GetAttribute(const std::string &osName) const override
136 : {
137 0 : return m_poParent->GetAttribute(osName);
138 : }
139 :
140 : std::vector<std::shared_ptr<GDALAttribute>>
141 1 : GetAttributes(CSLConstList papszOptions = nullptr) const override
142 : {
143 1 : return m_poParent->GetAttributes(papszOptions);
144 : }
145 :
146 0 : bool SetUnit(const std::string &osUnit) override
147 : {
148 0 : return m_poParent->SetUnit(osUnit);
149 : }
150 :
151 0 : bool SetSpatialRef(const OGRSpatialReference *poSRS) override
152 : {
153 0 : return m_poParent->SetSpatialRef(poSRS);
154 : }
155 :
156 : std::shared_ptr<GDALAttribute>
157 1 : CreateAttribute(const std::string &osName,
158 : const std::vector<GUInt64> &anDimensions,
159 : const GDALExtendedDataType &oDataType,
160 : CSLConstList papszOptions = nullptr) override
161 : {
162 1 : return m_poParent->CreateAttribute(osName, anDimensions, oDataType,
163 1 : papszOptions);
164 : }
165 : };
166 :
167 : //! @endcond
168 :
169 : #endif // GDALMULTIDIM_ARRAY_UNSCALED_H
|