CVB++ 15.0
interpolator.hpp
1#pragma once
2
3#include "../_cexports/c_spectral.h"
4#include "spectral.hpp"
5#include "cube.hpp"
6
7namespace Cvb
8{
9 CVB_BEGIN_INLINE_NS
10
11 template <>
12 inline HandleGuard<Spectral::Interpolator>::HandleGuard(void * handle) noexcept
13 : HandleGuard<Spectral::Interpolator>(handle, [](void* handle) { CVB_CALL_CAPI(ReleaseObject(handle)); })
14 {
15 }
16
17 namespace Spectral
18 {
20
22 class Interpolator final
23 {
24 public:
25
26 Interpolator(const Interpolator& other) noexcept = delete;
27 Interpolator& operator=(const Interpolator& other) noexcept = delete;
28 Interpolator(Interpolator&& other) noexcept = default;
29 Interpolator& operator=(Interpolator&& other) noexcept = default;
30 ~Interpolator() = default;
31
33
58 , StdObserver stdObserver
59 , StdIlluminant stdIlluminant
60 , InterpolationMethod interpolationMethod)
61 {
62 return Internal::DoResCallObjectOut<Interpolator>([&](void* & obj)
63 {
64 return CVB_CALL_CAPI(CVSCreateInterpolator(cube.Handle()
65 , static_cast<CExports::CVSStdObserver>(stdObserver)
66 , static_cast<CExports::CVSStdIlluminant>(stdIlluminant)
67 , static_cast<CExports::CVSInterpolationMethod>(interpolationMethod)
68 , obj));
69 });
70 }
71
72
74
80 {
81 auto cVal = Internal::DoResCallValueOut<CExports::CVSStdObserver>([&](CExports::CVSStdObserver val)
82 {
83 return CVB_CALL_CAPI(CVSInterpolatorGetObserver(this->Handle(), val));
84 });
85 return static_cast<Spectral::StdObserver>(cVal);
86 }
87
88
90
96 {
97 auto cVal = Internal::DoResCallValueOut<CExports::CVSStdIlluminant>([&](CExports::CVSStdIlluminant val)
98 {
99 return CVB_CALL_CAPI(CVSInterpolatorGetIlluminant(this->Handle(), val));
100 });
101 return static_cast<Spectral::StdIlluminant>(cVal);
102 }
103
104
106
112 {
113 size_t sz = 0;
114 CVB_CALL_CAPI_CHECKED(CVSInterpolatorGetWavelengths(this->Handle()
115 , reinterpret_cast<double*>(NULL), sz));
116 std::vector<double> waves(sz);
117 CVB_CALL_CAPI_CHECKED(CVSInterpolatorGetWavelengths(this->Handle()
118 , waves.data(), sz));
119 return waves;
120 }
121
122
124
128 void* Handle() const noexcept
129 {
130 return handle_.Handle();
131 }
132
133
135
143 static std::unique_ptr<Interpolator> FromHandle(HandleGuard<Interpolator>&& guard)
144 {
145 if (!guard.Handle())
146 throw std::runtime_error("handle must not be null");
147 return std::unique_ptr<Interpolator>(new Interpolator(std::move(guard)));
148 }
149
150
151 private:
152 explicit Interpolator(HandleGuard<Interpolator>&& guard) noexcept
153 : handle_(std::move(guard))
154 {
155 }
156
157
158 private:
159
160 HandleGuard<Interpolator> handle_;
161 };
162 }
163
164 using Spectral::Interpolator;
165
166 CVB_END_INLINE_NS
167}
Spectral Cube object.
Definition: cube.hpp:51
void * Handle() const noexcept
Returns C-API style handle to the Cube.
Definition: cube.hpp:344
Spectral Interpolator object.
Definition: interpolator.hpp:23
Spectral::StdObserver StdObserver() const
Retrieves the standard observer from the interpolator object.
Definition: interpolator.hpp:79
static std::unique_ptr< Interpolator > Create(const Cube &cube, StdObserver stdObserver, StdIlluminant stdIlluminant, InterpolationMethod interpolationMethod)
Creates an Interpolator object.
Definition: interpolator.hpp:57
static std::unique_ptr< Interpolator > FromHandle(HandleGuard< Interpolator > &&guard)
Creates Interpolator from a classic API Interpolator handle.
Definition: interpolator.hpp:143
Spectral::StdIlluminant StdIlluminant() const
Retrieves the standard illuminant from the interpolator object.
Definition: interpolator.hpp:95
std::vector< double > Wavelengths() const
Retrieves the wavelengths of the illuminant spectrum.
Definition: interpolator.hpp:111
void * Handle() const noexcept
Returns C-API style handle to the Interpolator.
Definition: interpolator.hpp:128
StdIlluminant
Defines Standard Illumination.
Definition: spectral.hpp:246
InterpolationMethod
Defines the interpolation method.
Definition: spectral.hpp:276
StdObserver
Defines Standard Observer.
Definition: spectral.hpp:261
Root namespace for the Image Manager interface.
Definition: c_barcode.h:15