OpenZGY/C++ API and Internals (ALPHA)
Access seismic data stored in ZGY format.
histogramdata.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 //Adapted from: Zgy/UtilityLib/HistogramData
16 #pragma once
17 
18 #include "../declspec.h"
19 #include "roundandclip.h"
20 
21 #include <memory>
22 #include <math.h>
23 #include <cmath>
24 
25 namespace InternalZGY {
26 #if 0
27 }
28 #endif
29 
75 class OPENZGY_TEST_API HistogramData
76 {
77 public:
78  typedef std::int32_t size_type;
79  typedef std::int64_t count_type;
80 
81  HistogramData(size_type _nbins, double _min, double _max);
82  HistogramData(const count_type* bins, int nbins, double min, double max);
83  HistogramData(const HistogramData& other);
84  HistogramData& operator=(const HistogramData& other);
85  HistogramData& operator+=(const HistogramData& other);
86  HistogramData& operator-=(const HistogramData& other);
87  HistogramData& operator*=(count_type factor);
88  bool operator==(const HistogramData& other) const;
89  bool operator!=(const HistogramData& other) const;
90 
91  // Queries
92  size_type getsize() const { return nbins_; }
93  const count_type* getbins() const { return bins_.get(); }
94  double getmin() const { return min_; }
95  double getmax() const { return max_; }
96  double getsmallestbinwidth() const { return 0.125; }
97  count_type get(double value) const;
98  count_type getcount() const;
100  // Operations
101  void scale(double oldmin, double oldmax, double newmin, double newmax);
102 
103  // Internal, to be called from HistogramBuilder only.
104 public:
105  void clear();
106  static void getLinearTransform(double *offset, double *scale, double oldmin, double oldmax, double newmin, double newmax);
107  void calculateConversionFactors(double* A, double* B) const; // Called from get(), AddBins(), TryAdd().
108  void addToBinNumberUNSAFE(size_type binno) { bins_[binno] += 1; }
110 private:
111  void addBins(const count_type* bins, int nbins, double min, double max, bool add); // Called from +=, -=.
112  inline void addOne(double value, count_type factor, double A, double B); // Called from AddBins() only.
113  bool compare(const HistogramData& other) const; // Called from operator== and operator!=.
114 
115 private:
116  double min_;
117  double max_;
118  size_type nbins_;
119  std::unique_ptr<count_type[]> bins_;
120 };
121 
131 inline void HistogramData::addOne(double value, count_type factor, double A, double B)
132 {
133  if (std::isfinite(value)) {
134 
135  // calculate bin index.
136  // This is based on number of bins and the min/max range,
137  // but the caller has precalculated the linear conversion
138  // implied by those numbers.
139  int n(RoundD2I(A + B*value));
140 
141  // if (n>=0 && n<nbins_) performance tweak. We know nbins_ is positive.
142  if (static_cast<unsigned int>(n) < static_cast<unsigned int>(nbins_))
143  bins_[n] += factor;
144  }
145 }
146 
147 } // end namespace
InternalZGY::HistogramData
A histogram for a data set.
Definition: histogramdata.h:75
roundandclip.h
Conversion between scalar types.
InternalZGY
Implementation not visible to clients.