CVB++ 14.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
28
53 , StdObserver stdObserver
54 , StdIlluminant stdIlluminant
55 , InterpolationMethod interpolationMethod)
56 {
57 return Internal::DoResCallObjectOut<Interpolator>([&](void* & obj)
58 {
59 return CVB_CALL_CAPI(CVSCreateInterpolator(cube.Handle()
60 , static_cast<CExports::CVSStdObserver>(stdObserver)
61 , static_cast<CExports::CVSStdIlluminant>(stdIlluminant)
62 , static_cast<CExports::CVSInterpolationMethod>(interpolationMethod)
63 , obj));
64 });
65 }
66
67
69
75 {
76 auto cVal = Internal::DoResCallValueOut<CExports::CVSStdObserver>([&](CExports::CVSStdObserver val)
77 {
78 return CVB_CALL_CAPI(CVSInterpolatorGetObserver(this->Handle(), val));
79 });
80 return static_cast<Spectral::StdObserver>(cVal);
81 }
82
83
85
91 {
92 auto cVal = Internal::DoResCallValueOut<CExports::CVSStdIlluminant>([&](CExports::CVSStdIlluminant val)
93 {
94 return CVB_CALL_CAPI(CVSInterpolatorGetIlluminant(this->Handle(), val));
95 });
96 return static_cast<Spectral::StdIlluminant>(cVal);
97 }
98
99
101
107 {
108 size_t sz = 0;
109 CVB_CALL_CAPI_CHECKED(CVSInterpolatorGetWavelengths(this->Handle()
110 , reinterpret_cast<double*>(NULL), sz));
111 std::vector<double> waves(sz);
112 CVB_CALL_CAPI_CHECKED(CVSInterpolatorGetWavelengths(this->Handle()
113 , waves.data(), sz));
114 return waves;
115 }
116
117
119
123 void* Handle() const noexcept
124 {
125 return handle_.Handle();
126 }
127
128
130
138 static std::unique_ptr<Interpolator> FromHandle(HandleGuard<Interpolator>&& guard)
139 {
140 if (!guard.Handle())
141 throw std::runtime_error("handle must not be null");
142 return std::unique_ptr<Interpolator>(new Interpolator(std::move(guard)));
143 }
144
145
146 private:
147 Interpolator(HandleGuard<Interpolator>&& guard) noexcept
148 : handle_(std::move(guard))
149 {
150 }
151
152 Interpolator(Interpolator && other) noexcept
153 : handle_(std::move(other.handle_))
154 {
155 }
156
157 Interpolator & operator=(Interpolator && other) = default;
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:366
Spectral Interpolator object.
Definition: interpolator.hpp:23
Spectral::StdObserver StdObserver() const
Retrieves the standard observer from the interpolator object.
Definition: interpolator.hpp:74
static std::unique_ptr< Interpolator > Create(const Cube &cube, StdObserver stdObserver, StdIlluminant stdIlluminant, InterpolationMethod interpolationMethod)
Creates an Interpolator object.
Definition: interpolator.hpp:52
static std::unique_ptr< Interpolator > FromHandle(HandleGuard< Interpolator > &&guard)
Creates Interpolator from a classic API Interpolator handle.
Definition: interpolator.hpp:138
Spectral::StdIlluminant StdIlluminant() const
Retrieves the standard illuminant from the interpolator object.
Definition: interpolator.hpp:90
std::vector< double > Wavelengths() const
Retrieves the wavelengths of the illuminant spectrum.
Definition: interpolator.hpp:106
void * Handle() const noexcept
Returns C-API style handle to the Interpolator.
Definition: interpolator.hpp:123
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:24