OpenZGY/C++ API and Internals (ALPHA)
Access seismic data stored in ZGY format.
lookuptable.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 
19 //#include <sstream>
20 //#include <algorithm>
21 
22 #include <cstdint>
23 #include <vector>
24 #include <array>
25 #include <string>
26 
27 namespace InternalZGY {
28 #if 0
29 }
30 #endif
31 
65 {
66 private:
67 #if 0
68  // Actual lookup tables as read from file (alup, blup)
69  // or computed (aend, bend for all current file versions)
70  std::vector<std::uint64_t> _alup;
71  std::vector<std::uint64_t> _aend;
72  std::vector<std::uint64_t> _blup;
73  std::vector<std::uint64_t> _bend;
74 
75  // Information derived from size, bricksize, and datatype.
76  // This will never change so it is safe to cache.
77  std::vector<std::array<std::int64_t,3>> _lodsizes;
78  std::vector<std::int64_t> _alphaoffsets;
79  std::vector<std::int64_t> _brickoffsets;
80  std::int64_t _bytesperalpha;
81  std::int64_t _bytesperbrick;
82 
83  // Scenario 4: If replacing the ILookupTableAccess
84  // then some additional boilerplate code is needed.
85  virtual void dump(std::ostream& out, const std::string& prefix = "");
86  virtual void read(const std::shared_ptr<FileADT>& file, std::int64_t offset, std::int64_t size);
87  virtual void byteswap();
88 #endif
89 
90 public:
92  struct LutInfo
93  {
94  BrickStatus status;
95  std::int64_t offset_in_file;
96  std::int64_t size_in_file;
97  std::uint32_t raw_constant; // Value stored in least significant bits.
99  LutInfo(BrickStatus status_in, std::int64_t offset, std::int64_t size, std::uint32_t constant)
100  : status(status_in)
101  , offset_in_file(offset)
102  , size_in_file(size)
103  , raw_constant(constant)
104  {
105  }
106  };
107 
108 public:
109  static std::vector<std::uint64_t> calcLookupSize(
110  const std::vector<std::uint64_t>& lookup,
111  std::int64_t eof, std::int64_t maxsize);
112 
113  static LutInfo getAlphaFilePosition(
114  std::int64_t i, std::int64_t j, std::int64_t lod,
115  const std::vector<std::array<std::int64_t,3>>& lodsizes,
116  const std::vector<std::int64_t>& alphaoffsets,
117  const std::vector<std::uint64_t>& alup,
118  std::int64_t bytesperalpha);
119 
120  static LutInfo getBrickFilePosition(
121  std::int64_t i, std::int64_t j, std::int64_t k, std::int64_t lod,
122  const std::vector<std::array<std::int64_t,3>>& lodsizes,
123  const std::vector<std::int64_t>& brickoffsets,
124  const std::vector<std::uint64_t>& blup,
125  const std::vector<std::uint64_t>& bend,
126  std::int64_t bytesperbrick);
127 
128  static void setBrickFilePosition(
129  std::int64_t i, std::int64_t j, std::int64_t k, std::int64_t lod,
130  const LutInfo& info,
131  const std::vector<std::array<std::int64_t,3>>& lodsizes,
132  const std::vector<std::int64_t>& brickoffsets,
133  std::vector<std::uint64_t>* blup,
134  std::vector<std::uint64_t>* bend);
135 
136 private:
137 
138  static std::string _formatPosition(
139  std::int64_t i, std::int64_t j, std::int64_t k, std::int64_t lod);
140 
141  static void _validatePosition(
142  std::int64_t i, std::int64_t j, std::int64_t k, std::int64_t lod,
143  const std::vector<std::array<std::int64_t,3>>& lodsizes);
144 
145  static std::int64_t _getLookupIndex(
146  std::int64_t i, std::int64_t j, std::int64_t k, std::int64_t lod,
147  const std::vector<std::array<std::int64_t,3>>& lodsizes,
148  const std::vector<std::int64_t>& offsets);
149 
150  static std::int64_t _getAlphaLookupIndex(
151  std::int64_t i, std::int64_t j, std::int64_t lod,
152  const std::vector<std::array<std::int64_t,3>>& lodsizes,
153  const std::vector<std::int64_t>& alphaoffsets);
154 
155  static std::int64_t _getBrickLookupIndex(
156  std::int64_t i, std::int64_t j, std::int64_t k, std::int64_t lod,
157  const std::vector<std::array<std::int64_t,3>>& lodsizes,
158  const std::vector<std::int64_t>& brickoffsets);
159 
160  static std::pair<std::int64_t, std::int64_t> _getBegAndSize(
161  std::int64_t ix,
162  const std::vector<std::uint64_t>& lup,
163  const std::vector<std::uint64_t>& end,
164  std::int64_t maxsize);
165 };
166 } // namespace
InternalZGY::LookupTable
Static methods to assist working with lookup tables.
Definition: lookuptable.h:64
enum.h
enums and type aliases not visible to the public API.
InternalZGY::LookupTable::LutInfo::LutInfo
LutInfo(BrickStatus status_in, std::int64_t offset, std::int64_t size, std::uint32_t constant)
Create an instance will all data fields filled in.
Definition: lookuptable.h:99
InternalZGY::LookupTable::LutInfo
Decoded contents of the lookup table for one brick or tile.
Definition: lookuptable.h:92
InternalZGY
Implementation not visible to clients.
InternalZGY::BrickStatus
BrickStatus
Definition: enum.h:167