ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ccWaveform.cpp
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 #include <pybind11/pybind11.h>
9 #include <pybind11/stl.h>
10 #include <pybind11/stl_bind.h>
11 
12 #include <ecvWaveform.h>
13 
14 #include "../casters.h"
15 
16 namespace py = pybind11;
17 using namespace pybind11::literals;
18 
19 void define_ccWaveform(py::module &m)
20 {
21  py::class_<WaveformDescriptor>(m, "WaveformDescriptor")
22  .def(py::init<>())
23  .def(py::self == py::self)
24  .def(py::self != py::self)
25  .def_readwrite("numberOfSamples", &WaveformDescriptor::numberOfSamples)
26  .def_readwrite("samplingRate_ps", &WaveformDescriptor::samplingRate_ps)
27  .def_readwrite("digitizerGain", &WaveformDescriptor::digitizerGain)
28  .def_readwrite("digitizerOffset", &WaveformDescriptor::digitizerOffset)
29  .def_readwrite("bitsPerSample", &WaveformDescriptor::bitsPerSample);
30 
31  py::class_<ccWaveform>(m, "ccWaveform")
32  .def(py::init<uint8_t>(), "id"_a)
33  .def("descriptorID", &ccWaveform::descriptorID)
34  .def("setDescriptorID", &ccWaveform::setDescriptorID, "id"_a)
35  .def("setDataDescription", &ccWaveform::setDataDescription, "dataOffset"_a, "byteCount"_a)
36  .def("getRawSample", &ccWaveform::getRawSample, "i"_a, "descriptor"_a, "dataStorage"_a)
37  .def("getSample", &ccWaveform::getRawSample, "i"_a, "descriptor"_a, "dataStorage"_a)
38  .def(
39  "getRange",
40  [](const ccWaveform &self,
41  const WaveformDescriptor &descriptor,
42  const uint8_t *dataStorage)
43  {
44  double min, max;
45  self.getRange(min, max, descriptor, dataStorage);
46  return py::make_tuple(min, max);
47  },
48  "descriptor"_a,
49  "dataStorage"_a)
50  .def(
51  "decodeSamples",
52  [](ccWaveform &self, const WaveformDescriptor &descriptor, const uint8_t *dataStorage)
53  {
54  std::vector<double> values;
55  self.decodeSamples(values, descriptor, dataStorage);
56  return values;
57  },
58  "descriptor"_a,
59  "dataStorage"_a)
60  .def("toASCII", &ccWaveform::toASCII, "filename"_a, "descriptor"_a, "dataStorage"_a)
61  .def_static("ToASCII", &ccWaveform::ToASCII, "filename"_a, "values"_a, "samplingRate_ps"_a)
62  .def("getSamplePos", &ccWaveform::getSamplePos, "i"_a, "getSamplePos"_a, "descriptor"_a)
63  .def("byteCount", &ccWaveform::byteCount)
64  .def("dataOffset", &ccWaveform::dataOffset)
65  .def("setDataOffset", &ccWaveform::setDataOffset, "offset"_a)
66  // TODO data(storage), the interaction with python will be weird to sort out
67  .def("setBeamDir", &ccWaveform::setBeamDir, "dir"_a)
68  .def("beamDir", &ccWaveform::beamDir)
69  .def("setEchoTime_ps", &ccWaveform::setEchoTime_ps, "time_ps"_a)
70  .def("echoTime_ps", &ccWaveform::echoTime_ps)
71  .def("applyRigidTransformation", &ccWaveform::applyRigidTransformation, "trans"_a)
72  .def("returnIndex", &ccWaveform::returnIndex)
73  .def("setReturnIndex", &ccWaveform::setReturnIndex, "index"_a);
74 
75  py::class_<ccWaveformProxy>(m, "ccWaveformProxy")
76  .def(py::init<const ccWaveform &, const WaveformDescriptor &, const uint8_t *>(),
77  "w"_a,
78  "d"_a,
79  "storage"_a)
80  .def("isValid", &ccWaveformProxy::isValid)
81  .def("descriptorID", &ccWaveformProxy::descriptorID)
82  .def("getRawSample", &ccWaveformProxy::getRawSample, "i"_a)
83  .def("getSample", &ccWaveformProxy::getRawSample, "i"_a)
84  .def("getRange",
85  [](const ccWaveformProxy &self)
86  {
87  double min, max;
88  self.getRange(min, max);
89  return py::make_tuple(min, max);
90  })
91  .def("decodeSamples",
92  [](const ccWaveformProxy &self)
93  {
94  std::vector<double> values;
95  self.decodeSamples(values);
96  return values;
97  })
98  .def("toASCII", &ccWaveformProxy::toASCII, "filename"_a)
99  .def("getSamplePos", &ccWaveformProxy::getSamplePos, "i"_a, "getSamplePos"_a)
100  .def("byteCount", &ccWaveformProxy::byteCount)
101  .def("data", &ccWaveformProxy::data)
102  .def("beamDir", &ccWaveformProxy::beamDir)
103  .def("echoTime_ps", &ccWaveformProxy::echoTime_ps)
104  .def("descriptor", &ccWaveformProxy::descriptor)
105  .def("waveform", &ccWaveformProxy::waveform);
106 }
void define_ccWaveform(py::module &m)
Definition: ccWaveform.cpp:19
Waveform descriptor.
Definition: ecvWaveform.h:23
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
uint32_t numberOfSamples
Number of samples.
Definition: ecvWaveform.h:43
double digitizerOffset
Definition: ecvWaveform.h:47
Waveform proxy.
Definition: ecvWaveform.h:189
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
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
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
uint32_t getRawSample(uint32_t i, const WaveformDescriptor &descriptor, const uint8_t *dataStorage) const
Returns the (raw) value of a given sample.
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.
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
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
void applyRigidTransformation(const ccGLMatrix &trans)
Applies a rigid transformation (on the beam direction)
const CCVector3f & beamDir() const
Returns the beam direction.
Definition: ecvWaveform.h:129
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.
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
void setEchoTime_ps(float time_ps)
Set the echo time (in picoseconds)
Definition: ecvWaveform.h:132
int min(int a, int b)
Definition: cutil_math.h:53
int max(int a, int b)
Definition: cutil_math.h:48