ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvWaveform.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 // Local
11 #include "CV_db.h"
12 #include "ecvGLMatrix.h"
13 #include "ecvSerializableObject.h"
14 
15 // cloudViewer
16 #include <CVGeom.h>
17 
18 // system
19 #include <cstdint>
20 #include <cstdlib>
21 
24 public:
27 
29  bool operator!=(const WaveformDescriptor& d) const;
30 
32  bool operator==(const WaveformDescriptor& d) const { return !(*this != d); }
33 
34  // inherited from ccSerializableObject
35  bool isSerializable() const override { return true; }
36  bool toFile(QFile& out, short dataVersion) const override;
37  short minimumFileVersion() const override;
38  bool fromFile(QFile& in,
39  short dataVersion,
40  int flags,
41  LoadedIDMap& oldToNewIDMap) override;
42 
43  uint32_t numberOfSamples;
44  uint32_t samplingRate_ps;
45  double digitizerGain;
47  double digitizerOffset;
49  uint8_t bitsPerSample;
50 };
51 
53 
56 public:
58  ccWaveform(uint8_t descriptorID = 0);
59 
61  ~ccWaveform() override = default;
62 
64 
67  inline uint8_t descriptorID() const { return m_descriptorID; }
68 
70  inline void setDescriptorID(uint8_t id) { m_descriptorID = id; }
71 
73  void setDataDescription(uint64_t dataOffset, uint32_t byteCount);
74 
76  uint32_t getRawSample(uint32_t i,
77  const WaveformDescriptor& descriptor,
78  const uint8_t* dataStorage) const;
79 
81  double getSample(uint32_t i,
82  const WaveformDescriptor& descriptor,
83  const uint8_t* dataStorage) const;
84 
86  double getRange(double& minVal,
87  double& maxVal,
88  const WaveformDescriptor& descriptor,
89  const uint8_t* dataStorage) const;
90 
92  bool decodeSamples(std::vector<double>& values,
93  const WaveformDescriptor& descriptor,
94  const uint8_t* dataStorage) const;
95 
97  bool toASCII(const QString& filename,
98  const WaveformDescriptor& descriptor,
99  const uint8_t* dataStorage) const;
100 
102  static bool ToASCII(const QString& filename,
103  std::vector<double>& values,
104  uint32_t samplingRate_ps);
105 
108  const CCVector3& P0,
109  const WaveformDescriptor& descriptor) const;
110 
112  inline uint32_t byteCount() const { return m_byteCount; }
113 
115  inline uint64_t dataOffset() const { return m_dataOffset; }
116 
118  inline void setDataOffset(uint64_t offset) { m_dataOffset = offset; }
119 
121  inline const uint8_t* data(const uint8_t* dataStorage) const {
122  return dataStorage + m_dataOffset;
123  }
124 
126  inline void setBeamDir(const CCVector3f& dir) { m_beamDir = dir; }
127 
129  inline const CCVector3f& beamDir() const { return m_beamDir; }
130 
132  inline void setEchoTime_ps(float time_ps) { m_echoTime_ps = time_ps; }
133 
135  inline float echoTime_ps() const { return m_echoTime_ps; }
136 
139 
141  uint8_t returnIndex() const { return m_returnIndex; }
143  void setReturnIndex(uint8_t index) { m_returnIndex = index; }
144 
145  // inherited from ccSerializableObject
146  bool isSerializable() const override { return true; }
147  bool toFile(QFile& out, short dataVersion) const override;
148  short minimumFileVersion() const override;
149  bool fromFile(QFile& in,
150  short dataVersion,
151  int flags,
152  LoadedIDMap& oldToNewIDMap) override;
153 
154 protected: // members
156 
158  uint32_t m_byteCount;
159 
161  uint64_t m_dataOffset;
162 
164 
168 
170 
175 
177 
180  uint8_t m_descriptorID;
181 
183  uint8_t m_returnIndex;
184 };
185 
187 
190 public:
193  const WaveformDescriptor& d,
194  const uint8_t* storage)
195  : m_w(w), m_d(d), m_storage(storage) {}
196 
198  inline bool isValid() const {
199  return m_storage && m_w.descriptorID() != 0 && m_d.numberOfSamples != 0;
200  }
201 
203 
206  inline uint8_t descriptorID() const { return m_w.descriptorID(); }
207 
209  inline uint32_t getRawSample(uint32_t i) const {
210  return m_w.getRawSample(i, m_d, m_storage);
211  }
212 
214  inline double getSample(uint32_t i) const {
215  return m_w.getSample(i, m_d, m_storage);
216  }
217 
219  inline double getRange(double& minVal, double& maxVal) const {
220  return m_w.getRange(minVal, maxVal, m_d, m_storage);
221  }
222 
224  inline bool decodeSamples(std::vector<double>& values) const {
225  return m_w.decodeSamples(values, m_d, m_storage);
226  }
227 
229  inline bool toASCII(const QString& filename) const {
230  return m_w.toASCII(filename, m_d, m_storage);
231  }
232 
234  inline CCVector3 getSamplePos(float i, const CCVector3& P0) const {
235  return m_w.getSamplePos(i, P0, m_d);
236  }
237 
239  inline uint32_t byteCount() const { return m_w.byteCount(); }
240 
242  inline const uint8_t* data() const { return m_w.data(m_storage); }
243 
245  inline const CCVector3f& beamDir() const { return m_w.beamDir(); }
246 
248  inline float echoTime_ps() const { return m_w.echoTime_ps(); }
249 
251  inline uint32_t numberOfSamples() const { return m_d.numberOfSamples; }
252 
254  inline const WaveformDescriptor& descriptor() const { return m_d; }
256  inline const ccWaveform& waveform() const { return m_w; }
257 
258 protected: // members
260  const ccWaveform& m_w;
264  const uint8_t* m_storage;
265 };
std::string filename
#define CV_DB_LIB_API
Definition: CV_db.h:15
int offset
Waveform descriptor.
Definition: ecvWaveform.h:23
bool operator!=(const WaveformDescriptor &d) const
Difference operator.
uint32_t samplingRate_ps
Sampling rate in pico seconds.
Definition: ecvWaveform.h:44
uint8_t bitsPerSample
Number of bits per sample.
Definition: ecvWaveform.h:49
bool toFile(QFile &out, short dataVersion) const override
Saves data to binary stream.
WaveformDescriptor()
Default constructor.
bool fromFile(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap) override
Loads data from binary stream.
short minimumFileVersion() const override
Returns the minimum file version required to save this instance.
uint32_t numberOfSamples
Number of samples.
Definition: ecvWaveform.h:43
bool operator==(const WaveformDescriptor &d) const
Equivalence operator.
Definition: ecvWaveform.h:32
bool isSerializable() const override
Returns whether object is serializable of not.
Definition: ecvWaveform.h:35
double digitizerOffset
Definition: ecvWaveform.h:47
Float version of ccGLMatrixTpl.
Definition: ecvGLMatrix.h:19
Serializable object interface.
QMultiMap< unsigned, unsigned > LoadedIDMap
Map of loaded unique IDs (old ID --> new ID)
Waveform proxy.
Definition: ecvWaveform.h:189
const uint8_t * m_storage
Associated storage data.
Definition: ecvWaveform.h:264
const WaveformDescriptor & m_d
Associated descriptor.
Definition: ecvWaveform.h:262
bool isValid() const
Returns whether the waveform (proxy) is valid or not.
Definition: ecvWaveform.h:198
bool toASCII(const QString &filename) const
Exports (real) samples to an ASCII file.
Definition: ecvWaveform.h:229
uint32_t byteCount() const
Returns the number of allocated bytes.
Definition: ecvWaveform.h:239
uint32_t numberOfSamples() const
Returns the number of samples.
Definition: ecvWaveform.h:251
const uint8_t * data() const
Gives access to the internal data.
Definition: ecvWaveform.h:242
uint8_t descriptorID() const
Returns the associated descriptor (ID)
Definition: ecvWaveform.h:206
uint32_t getRawSample(uint32_t i) const
Returns the (raw) value of a given sample.
Definition: ecvWaveform.h:209
const WaveformDescriptor & descriptor() const
Returns the descriptor.
Definition: ecvWaveform.h:254
CCVector3 getSamplePos(float i, const CCVector3 &P0) const
Returns the sample position in 3D.
Definition: ecvWaveform.h:234
double getSample(uint32_t i) const
Returns the (real) value of a given sample (in volts)
Definition: ecvWaveform.h:214
bool decodeSamples(std::vector< double > &values) const
Decodes the samples and store them in a vector.
Definition: ecvWaveform.h:224
const ccWaveform & m_w
Associated ccWaveform instance.
Definition: ecvWaveform.h:260
ccWaveformProxy(const ccWaveform &w, const WaveformDescriptor &d, const uint8_t *storage)
Default constructor.
Definition: ecvWaveform.h:192
double getRange(double &minVal, double &maxVal) const
Returns the range of (real) samples.
Definition: ecvWaveform.h:219
const ccWaveform & waveform() const
Returns the waveform.
Definition: ecvWaveform.h:256
const CCVector3f & beamDir() const
Returns the beam direction.
Definition: ecvWaveform.h:245
float echoTime_ps() const
Returns the echo time (in picoseconds)
Definition: ecvWaveform.h:248
Waveform.
Definition: ecvWaveform.h:55
uint32_t byteCount() const
Returns the number of allocated bytes.
Definition: ecvWaveform.h:112
uint8_t m_returnIndex
Return index.
Definition: ecvWaveform.h:183
bool decodeSamples(std::vector< double > &values, const WaveformDescriptor &descriptor, const uint8_t *dataStorage) const
Decodes the samples and store them in a vector.
uint32_t getRawSample(uint32_t i, const WaveformDescriptor &descriptor, const uint8_t *dataStorage) const
Returns the (raw) value of a given sample.
uint32_t m_byteCount
Waveform packet size in bytes.
Definition: ecvWaveform.h:158
void setReturnIndex(uint8_t index)
Sets the return index.
Definition: ecvWaveform.h:143
void setDescriptorID(uint8_t id)
Sets the associated descriptor (ID)
Definition: ecvWaveform.h:70
bool toASCII(const QString &filename, const WaveformDescriptor &descriptor, const uint8_t *dataStorage) const
Exports (real) samples to an ASCII file.
float m_echoTime_ps
Return Point location (in picoseconds)
Definition: ecvWaveform.h:174
void setDataOffset(uint64_t offset)
Sets the byte offset to waveform data.
Definition: ecvWaveform.h:118
void setBeamDir(const CCVector3f &dir)
Sets the beam direction.
Definition: ecvWaveform.h:126
double getSample(uint32_t i, const WaveformDescriptor &descriptor, const uint8_t *dataStorage) const
Returns the (real) value of a given sample (in volts)
float echoTime_ps() const
Returns the echo time (in picoseconds)
Definition: ecvWaveform.h:135
uint8_t descriptorID() const
Returns the associated descriptor (ID)
Definition: ecvWaveform.h:67
uint8_t returnIndex() const
Returns the return index.
Definition: ecvWaveform.h:141
~ccWaveform() override=default
Destructor.
CCVector3f m_beamDir
Laser beam direction.
Definition: ecvWaveform.h:167
short minimumFileVersion() const override
Returns the minimum file version required to save this instance.
uint64_t m_dataOffset
Byte offset to waveform data.
Definition: ecvWaveform.h:161
bool fromFile(QFile &in, short dataVersion, int flags, LoadedIDMap &oldToNewIDMap) override
Loads data from binary stream.
void applyRigidTransformation(const ccGLMatrix &trans)
Applies a rigid transformation (on the beam direction)
const uint8_t * data(const uint8_t *dataStorage) const
Gives access to the internal data.
Definition: ecvWaveform.h:121
ccWaveform(uint8_t descriptorID=0)
Default constructor.
const CCVector3f & beamDir() const
Returns the beam direction.
Definition: ecvWaveform.h:129
uint8_t m_descriptorID
Wave Packet descriptor index.
Definition: ecvWaveform.h:180
bool toFile(QFile &out, short dataVersion) const override
Saves data to binary stream.
void setDataDescription(uint64_t dataOffset, uint32_t byteCount)
Describes the waveform data.
static bool ToASCII(const QString &filename, std::vector< double > &values, uint32_t samplingRate_ps)
Helper: exports a series of values as an ASCII file.
bool isSerializable() const override
Returns whether object is serializable of not.
Definition: ecvWaveform.h:146
CCVector3 getSamplePos(float i, const CCVector3 &P0, const WaveformDescriptor &descriptor) const
Returns the sample position in 3D.
uint64_t dataOffset() const
Returns the byte offset to waveform data.
Definition: ecvWaveform.h:115
double getRange(double &minVal, double &maxVal, const WaveformDescriptor &descriptor, const uint8_t *dataStorage) const
Returns the range of (real) samples.
void setEchoTime_ps(float time_ps)
Set the echo time (in picoseconds)
Definition: ecvWaveform.h:132