OpenZGY/C++ API and Internals (ALPHA)
Access seismic data stored in ZGY format.
genlod.h
Go to the documentation of this file.
1 // Copyright 2017-2020, Schlumberger
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include "enum.h"
18 #include "lodalgo.h"
19 #include "histogramdata.h"
20 #include "histogrambuilder.h"
21 #include "statisticdata.h"
22 #include "databuffer.h"
23 #include "../exception.h"
24 
25 #include <memory>
26 #include <cstdint>
27 #include <array>
28 #include <vector>
29 #include <functional>
30 #include <iostream>
31 
37 namespace InternalZGY {
38 #if 0
39 }
40 #endif
41 
42 class ZgyInternalMeta;
43 class ZgyInternalBulk;
44 
52 {
53 protected:
54  std::int32_t _nlods;
55  std::int64_t _total;
56  std::int64_t _done;
57  index3_t _surveysize;
58  index3_t _bricksize;
59  RawDataType _dtype;
60  std::array<double,2> _histogram_range;
61  std::vector<LodAlgorithm> _decimation;
62  std::shared_ptr<HistogramData> _wa_histogram;
63  double _wa_defaultstorage;
64  std::function<bool(std::int64_t,std::int64_t)> _progress;
65  bool _verbose;
66 
67 public:
68  GenLodBase(const index3_t& size,
69  const index3_t& bricksize,
70  RawDataType dtype,
71  const std::array<double,2>& histogram_range,
72  std::int32_t nlods_in,
73  const std::vector<LodAlgorithm>& decimation,
74  const std::shared_ptr<HistogramData>& histogram,
75  double defaultvalue,
76  const std::function<bool(std::int64_t,std::int64_t)>& progress,
77  bool verbose);
78 protected:
79  virtual std::shared_ptr<DataBuffer> _read(
80  std::int32_t lod, const index3_t& pos, const index3_t& size);
81  virtual void _write(
82  std::int32_t lod, const index3_t& pos,
83  const std::shared_ptr<const DataBuffer>& data);
84  virtual void _savestats();
85  void _report(const DataBuffer* data);
86  std::string _prefix(std::int32_t lod);
87  static std::string _format_result(const std::shared_ptr<DataBuffer>& data);
88 };
89 
94 class GenLodImpl: public GenLodBase
95 {
96  std::shared_ptr<StatisticData> _stats;
97  std::shared_ptr<HistogramData> _histo;
98 
99 public:
100  GenLodImpl(const index3_t& size,
101  const index3_t& bricksize,
102  RawDataType dtype,
103  const std::array<double,2>& histogram_range,
104  std::int32_t nlods_in,
105  const std::vector<LodAlgorithm>& decimation,
106  const std::shared_ptr<HistogramData>& histogram,
107  double defaultvalue,
108  const std::function<bool(std::int64_t,std::int64_t)>& progress,
109  bool verbose);
110  std::tuple<std::shared_ptr<StatisticData>, std::shared_ptr<HistogramData>>
111  call();
112 protected:
113  template <typename T>
114  void _accumulateT(const std::shared_ptr<const DataBuffer>& data_in);
115  void _accumulate(const std::shared_ptr<const DataBuffer>& data);
116  std::shared_ptr<DataBuffer>
117  _calculate(const index3_t& readpos_in, std::int32_t readlod);
118  std::shared_ptr<DataBuffer>
119  _decimate(const std::shared_ptr<const DataBuffer>& data, std::int64_t lod);
120  std::shared_ptr<DataBuffer>
121  _paste1(const std::shared_ptr<DataBuffer>& result,
122  const std::shared_ptr<const DataBuffer>& more,
123  std::int64_t ioff, std::int64_t joff);
124  std::shared_ptr<const DataBuffer>
125  _paste4(const std::shared_ptr<const DataBuffer>& d00,
126  const std::shared_ptr<const DataBuffer>& d01,
127  const std::shared_ptr<const DataBuffer>& d10,
128  const std::shared_ptr<const DataBuffer>& d11);
129  static std::array<double,2>
130  suggestHistogramRange(
131  const std::array<double,2>& writtenrange,
132  RawDataType dtype);
133 };
134 
135 class GenLodC : public GenLodImpl
136 {
137  std::shared_ptr<ZgyInternalBulk> _accessor;
138  compressor_t _lodcompressor;
139 public:
140  GenLodC(const std::shared_ptr<ZgyInternalBulk>& accessor,
141  const std::shared_ptr<ZgyInternalMeta>& meta,
142  const compressor_t& lodcompressor,
143  const std::vector<LodAlgorithm>& decimation,
144  const std::function<bool(std::int64_t,std::int64_t)>& progress,
145  bool verbose);
146 protected:
147  std::shared_ptr<DataBuffer> _read(
148  std::int32_t lod, const index3_t& pos, const index3_t& size) override;
149  void _write(
150  std::int32_t lod, const index3_t& pos,
151  const std::shared_ptr<const DataBuffer>& data) override;
152  void _savestats() override;
153 };
154 
155 } // namespace
databuffer.h
Each DataBuffer instance represents some in memory data.
InternalZGY::GenLodBase
Definition: genlod.h:51
enum.h
enums and type aliases not visible to the public API.
statisticdata.h
provides class InternalZGY::StatisticData.
InternalZGY::GenLodC
Definition: genlod.h:135
InternalZGY::RawDataType
RawDataType
Definition: enum.h:95
lodalgo.h
Decimation algorithms to output low resolution bricks.
InternalZGY::compressor_t
std::function< rawdata_t(const rawdata_t &, const index3_t &)> compressor_t
Function for compressing a brick.
Definition: enum.h:84
histogramdata.h
provides class InternalZGY::HistogramData.
InternalZGY
Implementation not visible to clients.
InternalZGY::DataBuffer
Each DataBuffer instance represents some in memory data.
Definition: databuffer.h:185
InternalZGY::GenLodImpl
Definition: genlod.h:94
InternalZGY::index3_t
std::array< std::int64_t, 3 > index3_t
type equivalent to std::int64_t[3]
Definition: enum.h:60
histogrambuilder.h
Collect statistics and histogram for bulk data.