-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathRGBPoints.cpp
106 lines (91 loc) · 3.7 KB
/
RGBPoints.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/** @file
@brief Implementation
@date 2016
@author
Sensics, Inc.
<http://sensics.com/osvr>
*/
// Copyright 2016 Razer Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Internal Includes
#include "RGBPoints.h"
#include "PointHelpers.h"
// Library/third-party includes
#include <json/value.h>
#include <json/writer.h>
// Standard includes
// - none
namespace osvr {
namespace vive {
static const std::array<std::string, 3> COLOR_NAMES = {
"red_point_samples", "green_point_samples", "blue_point_samples"};
struct RGBPoints::Impl {
Impl()
: root(Json::objectValue),
distortion_(&(root["display"]["hmd"]["distortion"] =
Json::Value(Json::objectValue))) {
// So inside the distortion object, there are named arrays for each
// color. they each contain an array for each eye, and in each eye
// array goes each [ [inu, inv], [outu, outv] ] pair.
for (auto colorIdx : {Red, Green, Blue}) {
/// Create the array for this color
colors_[colorIdx] = &(distortion()[COLOR_NAMES[colorIdx]] =
Json::Value(Json::arrayValue));
/// create its first (left) eye array
colors_[colorIdx]->append(Json::Value(Json::arrayValue));
/// create its second (right) eye array
colors_[colorIdx]->append(Json::Value(Json::arrayValue));
}
}
Json::Value root;
Json::Value &distortion() { return *distortion_; }
Json::Value &getColorAndEye(Eye eye, size_t color) {
return (*colors_[color])[static_cast<int>(eye)];
}
void addSample(Eye eye, size_t color, Json::Value const &inputUV,
Point2 const &outUV) {
getColorAndEye(eye, color)
.append(pointhelpers::makeSample(inputUV, outUV));
}
void addSample(Eye eye, size_t color, Point2 const &inputUV,
Point2 const &outUV) {
getColorAndEye(eye, color)
.append(pointhelpers::makeSample(inputUV, outUV));
}
void addSample(Eye eye, Point2 const &inputUV, Point2 const &outR,
Point2 const &outG, Point2 const &outB) {
auto inUV = pointhelpers::arrayToJson(inputUV);
addSample(eye, Red, inUV, outR);
addSample(eye, Green, inUV, outG);
addSample(eye, Blue, inUV, outB);
}
Json::Value *distortion_ = nullptr;
std::array<Json::Value *, 3> colors_;
};
RGBPoints::RGBPoints() : impl_(new Impl) {}
RGBPoints::~RGBPoints() {}
void RGBPoints::addSample(Eye eye, Point2 const &inputUV,
Point2 const &outR, Point2 const &outG,
Point2 const &outB) {
impl_->addSample(eye, inputUV, outR, outG, outB);
}
std::string RGBPoints::getSeparateFile() const {
Json::FastWriter writer;
return writer.write(impl_->root);
}
std::string RGBPoints::getSeparateFileStyled() const {
return impl_->root.toStyledString();
}
} // namespace vive
} // namespace osvr