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 Interpolator(const Interpolator &other) noexcept = delete;
26 Interpolator &operator=(const Interpolator &other) noexcept = delete;
27 Interpolator(Interpolator &&other) noexcept = default;
28 Interpolator &operator=(Interpolator &&other) noexcept = default;
29 ~Interpolator() = default;
30
32
61 static std::unique_ptr<Interpolator> Create(const Cube &cube, StdObserver stdObserver,
62 StdIlluminant stdIlluminant, InterpolationMethod interpolationMethod)
63 {
64 return Internal::DoResCallObjectOut<Interpolator>([&](void *&obj) {
65 return CVB_CALL_CAPI(CVSCreateInterpolator(cube.Handle(), static_cast<CExports::CVSStdObserver>(stdObserver),
66 static_cast<CExports::CVSStdIlluminant>(stdIlluminant),
67 static_cast<CExports::CVSInterpolationMethod>(interpolationMethod),
68 obj));
69 });
70 }
71
73
79 {
80 auto cVal = Internal::DoResCallValueOut<CExports::CVSStdObserver>([&](CExports::CVSStdObserver val) {
81 return CVB_CALL_CAPI(CVSInterpolatorGetObserver(this->Handle(), val));
82 });
83 return static_cast<Spectral::StdObserver>(cVal);
84 }
85
87
94 {
95 auto cVal = Internal::DoResCallValueOut<CExports::CVSStdIlluminant>([&](CExports::CVSStdIlluminant val) {
96 return CVB_CALL_CAPI(CVSInterpolatorGetIlluminant(this->Handle(), val));
97 });
98 return static_cast<Spectral::StdIlluminant>(cVal);
99 }
100
102
108 {
109 size_t sz = 0;
110 CVB_CALL_CAPI_CHECKED(CVSInterpolatorGetWavelengths(this->Handle(), reinterpret_cast<double *>(NULL), sz));
111 std::vector<double> waves(sz);
112 CVB_CALL_CAPI_CHECKED(CVSInterpolatorGetWavelengths(this->Handle(), waves.data(), sz));
113 return waves;
114 }
115
117
121 void *Handle() const noexcept
122 {
123 return handle_.Handle();
124 }
125
127
135 static std::unique_ptr<Interpolator> FromHandle(HandleGuard<Interpolator> &&guard)
136 {
137 if (!guard.Handle())
138 throw std::runtime_error("handle must not be null");
139 return std::unique_ptr<Interpolator>(new Interpolator(std::move(guard)));
140 }
141
142 private:
143 explicit Interpolator(HandleGuard<Interpolator> &&guard) noexcept
144 : handle_(std::move(guard))
145 {
146 }
147
148 private:
149 HandleGuard<Interpolator> handle_;
150 };
151 } // namespace Spectral
152
154
155 CVB_END_INLINE_NS
156} // namespace Cvb
Spectral Cube object.
Definition cube.hpp:59
void * Handle() const noexcept
Returns C-API style handle to the Cube.
Definition cube.hpp:316
Spectral Interpolator object.
Definition interpolator.hpp:23
Spectral::StdObserver StdObserver() const
Retrieves the standard observer from the interpolator object.
Definition interpolator.hpp:78
static std::unique_ptr< Interpolator > Create(const Cube &cube, StdObserver stdObserver, StdIlluminant stdIlluminant, InterpolationMethod interpolationMethod)
Creates an Interpolator object.
Definition interpolator.hpp:61
static std::unique_ptr< Interpolator > FromHandle(HandleGuard< Interpolator > &&guard)
Creates Interpolator from a classic API Interpolator handle.
Definition interpolator.hpp:135
Spectral::StdIlluminant StdIlluminant() const
Retrieves the standard illuminant from the interpolator object.
Definition interpolator.hpp:93
std::vector< double > Wavelengths() const
Retrieves the wavelengths of the illuminant spectrum.
Definition interpolator.hpp:107
void * Handle() const noexcept
Returns C-API style handle to the Interpolator.
Definition interpolator.hpp:121
cvbbool_t ReleaseObject(OBJ &Object)
T move(T... args)
Namespace for the Spectral package.
Definition arithmetic.hpp:14
StdIlluminant
Defines Standard Illumination.
Definition spectral.hpp:252
InterpolationMethod
Defines the interpolation method.
Definition spectral.hpp:282
StdObserver
Defines Standard Observer.
Definition spectral.hpp:267
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17