Util.cpp
Go to the documentation of this file.
1 
28 #include <algorithm>
29 
30 #include "lvr2/util/Util.hpp"
31 
32 namespace lvr2
33 {
34 
35 int Util::getSpectralChannel(int wavelength, PointBufferPtr p, int fallback)
36 {
37  UCharChannelOptional spectral_channels = p->getUCharChannel("spectral_channels");
38  if (!spectral_channels)
39  {
40  return fallback;
41  }
42 
43  int minWavelength = *p->getIntAtomic("spectral_wavelength_min");
44 
45  int channel = (wavelength - minWavelength) / wavelengthPerChannel(p);
46 
47  if (channel < 0 || channel >= spectral_channels->width())
48  {
49  return fallback;
50  }
51 
52  return channel;
53 }
54 
55 int Util::getSpectralWavelength(int channel, PointBufferPtr p, int fallback)
56 {
57  UCharChannelOptional spectral_channels = p->getUCharChannel("spectral_channels");
58  if (!spectral_channels)
59  {
60  return fallback;
61  }
62 
63  int minWavelength = *p->getIntAtomic("spectral_wavelength_min");
64 
65  if (channel < 0 || channel >= spectral_channels->width())
66  {
67  return fallback;
68  }
69 
70  return channel * wavelengthPerChannel(p) + minWavelength;
71 }
72 
74 {
75  UCharChannelOptional spectral_channels = p->getUCharChannel("spectral_channels");
76  if (!spectral_channels)
77  {
78  return -1.0f;
79  }
80 
81  int minWavelength = *p->getIntAtomic("spectral_wavelength_min");
82  int maxWavelength = *p->getIntAtomic("spectral_wavelength_max");
83 
84  return (maxWavelength - minWavelength) / static_cast<float>(spectral_channels->width());
85 }
86 
87 } // namespace lvr2
lvr2::Util::getSpectralChannel
static int getSpectralChannel(int wavelength, PointBufferPtr p, int fallback=-1)
Returns the spectral channel index for a given wavelength.
Definition: Util.cpp:35
lvr2::UCharChannelOptional
UCharChannel::Optional UCharChannelOptional
Definition: Channel.hpp:96
lvr2::PointBufferPtr
std::shared_ptr< PointBuffer > PointBufferPtr
Definition: PointBuffer.hpp:130
p
SharedPointer p
Definition: ConvertShared.hpp:42
lvr2::Util::getSpectralWavelength
static int getSpectralWavelength(int channel, PointBufferPtr p, int fallback=-1)
For a given spectral channel it return the corresponding wavelength.
Definition: Util.cpp:55
Util.hpp
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::Util::wavelengthPerChannel
static float wavelengthPerChannel(PointBufferPtr p)
Calculates the wavelength distance between two spectral channels.
Definition: Util.cpp:73


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Wed Mar 2 2022 00:37:25