ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvScalarField.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 // cloudViewer
11 #include <ScalarField.h>
12 
13 // CV_DB_LIB
14 #include "ecvColorScale.h"
15 
17 
20  public ccSerializableObject {
21 public:
23 
25  explicit ccScalarField(const char* name = nullptr);
26 
28 
31  ccScalarField(const ccScalarField& sf);
32 
33  /*** Scalar values display handling ***/
34 
37  public:
39  Range() : m_min(0), m_start(0), m_stop(0), m_max(0), m_range(1) {}
40 
41  // getters
42  inline ScalarType min() const { return m_min; }
43  inline ScalarType start() const { return m_start; }
44  inline ScalarType stop() const { return m_stop; }
45  inline ScalarType max() const { return m_max; }
46  inline ScalarType range() const { return m_range; }
47  inline ScalarType maxRange() const { return m_max - m_min; }
48 
49  // setters
50  void setBounds(ScalarType minVal,
51  ScalarType maxVal,
52  bool resetStartStop = true) {
53  assert(minVal <= maxVal);
54  m_min = minVal;
55  m_max = maxVal;
56  if (resetStartStop) {
57  m_start = m_min;
58  m_stop = m_max;
59  } else {
60  m_start = inbound(m_start);
61  m_stop = inbound(m_stop);
62  }
63  updateRange();
64  }
65 
66  inline void setStart(ScalarType value) {
67  m_start = inbound(value);
68  if (m_stop < m_start) m_stop = m_start;
69  updateRange();
70  }
71  inline void setStop(ScalarType value) {
72  m_stop = inbound(value);
73  if (m_stop < m_start) m_start = m_stop;
74  updateRange();
75  }
76 
78  inline ScalarType inbound(ScalarType val) const {
79  return (val < m_min ? m_min : (val > m_max ? m_max : val));
80  }
82  inline bool isInbound(ScalarType val) const {
83  return (val >= m_min && val <= m_max);
84  }
86  inline bool isInRange(ScalarType val) const {
87  return (val >= m_start && val <= m_stop);
88  }
89 
90  protected:
92  inline void updateRange() {
93  m_range = std::max(m_stop - m_start, ZERO_TOLERANCE_SCALAR);
94  }
95 
96  ScalarType m_min;
97  ScalarType m_start;
98  ScalarType m_stop;
99  ScalarType m_max;
100  ScalarType
102  };
103 
105 
108  inline const Range& displayRange() const { return m_displayRange; }
109 
111 
114  inline const Range& saturationRange() const {
115  return m_logScale ? m_logSaturationRange : m_saturationRange;
116  }
117 
119 
122  inline const Range& logSaturationRange() const {
123  return m_logSaturationRange;
124  }
125 
127  void setMinDisplayed(ScalarType val);
129  void setMaxDisplayed(ScalarType val);
131  void setSaturationStart(ScalarType val);
133  void setSaturationStop(ScalarType val);
134 
137 
139  inline const ecvColor::Rgb* getColor(ScalarType value) const {
140  assert(m_colorScale);
141  return m_colorScale->getColorByRelativePos(
142  normalize(value), m_colorRampSteps,
143  m_showNaNValuesInGrey ? &ecvColor::lightGrey : nullptr);
144  }
145 
147  inline const ecvColor::Rgb* getValueColor(unsigned index) const {
148  return getColor(getValue(index));
149  }
150 
153  void showNaNValuesInGrey(bool state);
154 
156  inline bool areNaNValuesShownInGrey() const {
157  return m_showNaNValuesInGrey;
158  }
159 
161  void alwaysShowZero(bool state);
162 
164  inline bool isZeroAlwaysShown() const { return m_alwaysShowZero; }
165 
167 
169  void setSymmetricalScale(bool state);
170 
172 
174  inline bool symmetricalScale() const { return m_symmetricalScale; }
175 
177  void setLogScale(bool state);
178 
180  inline bool logScale() const { return m_logScale; }
181 
182  // inherited
183  void computeMinAndMax() override;
184 
186  inline const ccColorScale::Shared& getColorScale() const {
187  return m_colorScale;
188  }
189 
191  void setColorScale(ccColorScale::Shared scale);
192 
194  inline unsigned getColorRampSteps() const { return m_colorRampSteps; }
195 
197  void setColorRampSteps(unsigned steps);
198 
200  struct Histogram : std::vector<unsigned> {
202  unsigned maxValue = 0;
203  };
204 
206  inline const Histogram& getHistogram() const { return m_histogram; }
207 
210 
214  bool mayHaveHiddenValues() const;
215 
217  inline void setModificationFlag(bool state) { m_modified = state; }
219  inline bool getModificationFlag() const { return m_modified; }
220 
222  void importParametersFrom(const ccScalarField* sf);
223 
224  // inherited from ccSerializableObject
225  inline bool isSerializable() const override { return true; }
226  bool toFile(QFile& out, short dataVersion) const override;
227  short minimumFileVersion() const override;
228  bool fromFile(QFile& in,
229  short dataVersion,
230  int flags,
231  LoadedIDMap& oldToNewIDMap) override;
232 
234  inline double getGlobalShift() const { return m_globalShift; }
236  inline void setGlobalShift(double shift) { m_globalShift = shift; }
237 
238 protected: // methods
240 
242  ~ccScalarField() override = default;
243 
245  void updateSaturationBounds();
246 
248 
252  ScalarType normalize(ScalarType val) const;
253 
254 protected: // members
257 
259 
262 
264 
267 
270 
272 
275 
278 
281 
284 
287 
290 
292 
296 
299 };
constexpr ScalarType ZERO_TOLERANCE_SCALAR
Definition: CVConst.h:57
#define CV_DB_LIB_API
Definition: CV_db.h:15
std::string name
QSharedPointer< ccColorScale > Shared
Shared pointer type.
Definition: ecvColorScale.h:74
Scalar field range structure.
Range()
Default constructor.
void setStop(ScalarType value)
ScalarType stop() const
bool isInbound(ScalarType val) const
Returns whether a value is inbound or not.
ScalarType min() const
ScalarType maxRange() const
void updateRange()
Updates actual range.
ScalarType inbound(ScalarType val) const
Returns the nearest inbound value.
bool isInRange(ScalarType val) const
Returns whether a value is inside range or not.
ScalarType max() const
void setBounds(ScalarType minVal, ScalarType maxVal, bool resetStartStop=true)
void setStart(ScalarType value)
ScalarType range() const
ScalarType start() const
A scalar field associated to display-related parameters.
const ccColorScale::Shared & getColorScale() const
Returns associated color scale.
Range m_logSaturationRange
saturation values range (log scale mode)
double m_globalShift
Global shift.
bool getModificationFlag() const
Returns modification flag state.
bool isSerializable() const override
Returns whether object is serializable of not.
bool m_showNaNValuesInGrey
Whether NaN values are shown in grey or are hidden.
bool logScale() const
Returns whether scalar field is logarithmic or not.
void setGlobalShift(double shift)
Sets the global shift.
unsigned getColorRampSteps() const
Returns number of color ramp steps.
Range m_displayRange
Displayed values range.
double getGlobalShift() const
Returns the global shift (if any)
Histogram m_histogram
Associated histogram values (for display)
unsigned m_colorRampSteps
Number of color ramps steps (for display)
bool m_alwaysShowZero
Whether 0 should always appear in associated color ramp.
const Range & saturationRange() const
Access to the range of saturation values.
const Histogram & getHistogram() const
Returns associated histogram values (for display)
bool m_symmetricalScale
Whether color scale is symmetrical or not.
~ccScalarField() override=default
Default destructor.
const Range & displayRange() const
Access to the range of displayed values.
const ecvColor::Rgb * getColor(ScalarType value) const
bool m_logScale
Whether scale is logarithmic or not.
void setModificationFlag(bool state)
Sets modification flag state.
bool symmetricalScale() const
Returns whether the color scale s symmetrical or not.
const Range & logSaturationRange() const
Access to the range of log scale saturation values.
bool m_modified
Modification flag.
const ecvColor::Rgb * getValueColor(unsigned index) const
Shortcut to getColor.
Range m_saturationRange
Saturation values range.
bool areNaNValuesShownInGrey() const
Returns whether NaN values are displayed in gray or hidden.
bool isZeroAlwaysShown() const
Returns whether 0 should always appear in associated color ramp or not.
ccColorScale::Shared m_colorScale
Active color ramp (for display)
Serializable object interface.
virtual short minimumFileVersion() const =0
Returns the minimum file version required to save this instance.
virtual bool toFile(QFile &out, short dataVersion) const
Saves data to binary stream.
virtual bool fromFile(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap)
Loads data from binary stream.
A simple scalar field (to be associated to a point cloud)
Definition: ScalarField.h:25
virtual void computeMinAndMax()
Determines the min and max values.
Definition: ScalarField.h:123
ScalarType & getValue(std::size_t index)
Definition: ScalarField.h:92
RGB color structure.
Definition: ecvColorTypes.h:49
constexpr Rgb lightGrey(static_cast< ColorCompType >(MAX *0.8), static_cast< ColorCompType >(MAX *0.8), static_cast< ColorCompType >(MAX *0.8))
Simple histogram structure.