31 #include <boost/units/io.hpp>
32 #include <boost/assert.hpp>
39 namespace display_schema_1 {
41 static const double DEFAULT_IPD_METERS = 0.063;
43 DisplayDescriptor::DisplayDescriptor() {
47 DisplayDescriptor::DisplayDescriptor(
48 const std::string &display_description) {
49 parse(display_description);
52 void DisplayDescriptor::parse(
const std::string &display_description) {
54 auto const &hmd = root[
"hmd"];
56 auto const &fov = hmd[
"field_of_view"];
59 fov[
"monocular_horizontal"].asDouble() * util::degrees);
61 fov[
"monocular_vertical"].asDouble() * util::degrees);
63 fov.get(
"overlap_percent", 100).asDouble() / 100.0;
64 m_pitchTilt =
util::Angle(fov.get(
"pitch_tilt", 0).asDouble() *
68 auto const &devprops = hmd[
"device"];
70 m_vendor = devprops[
"vendor"].asString();
71 m_model = devprops[
"model"].asString();
72 m_version = devprops[
"Version"].asString();
73 m_note = devprops[
"Note"].asString();
76 auto const &resolutions = hmd[
"resolutions"];
77 if (resolutions.isNull()) {
79 "DisplayDescriptor::parse(): ERROR: Couldn't "
80 "find resolutions array!");
81 throw DisplayDescriptorParseException(
82 "Couldn't find resolutions array.");
85 for (
auto const &resolution : resolutions) {
86 m_processResolution(resolution);
89 if (m_resolutions.empty()) {
92 "DisplayDescriptor::parse(): ERROR: Couldn't "
93 "find any appropriate resolutions.");
99 auto const &rendering = hmd[
"rendering"];
100 m_rightRoll = rendering.get(
"right_roll", 0).asDouble();
101 m_leftRoll = rendering.get(
"left_roll", 0).asDouble();
104 auto const &distortion = hmd[
"distortion"];
105 m_distort.k1_red = distortion.get(
"k1_red", 0).asDouble();
106 m_distort.k1_green = distortion.get(
"k1_green", 0).asDouble();
107 m_distort.k1_blue = distortion.get(
"k1_blue", 0).asDouble();
110 auto const &eyes = hmd[
"eyes"];
112 OSVR_DEV_VERBOSE(
"DisplayDescriptor::parse(): ERROR: "
113 "Couldn't find eyes array!");
114 throw DisplayDescriptorParseException(
115 "Couldn't find eyes array.");
117 for (
auto const &eye : eyes) {
119 e.m_CenterProjX = eye.get(
"center_proj_x", 0.5).asDouble();
120 e.m_CenterProjY = eye.get(
"center_proj_y", 0.5).asDouble();
121 if (eye.isMember(
"rotate_180")) {
122 auto const& rot = eye[
"rotate_180"];
124 e.m_rotate180 = rot.asBool();
126 e.m_rotate180 = (rot.asInt() != 0);
135 std::ostringstream os;
136 bool needSpace =
false;
137 if (!m_vendor.empty()) {
142 if (!m_model.empty()) {
150 if (!m_version.empty()) {
154 os <<
"(Version " << m_version <<
")";
158 if (!m_note.empty()) {
162 os <<
"[Display descriptor note: " << m_note <<
"]";
168 DisplayDescriptor::m_processResolution(Json::Value
const &resolution) {
173 res.video_inputs = resolution.get(
"video_inputs", 1).asInt();
176 res.width = resolution[
"width"].asInt();
177 res.height = resolution[
"height"].asInt();
183 (res.video_inputs > 1 ? FULL_SCREEN : HORIZONTAL_SIDE_BY_SIDE);
185 auto const &display_mode = resolution[
"display_mode"];
186 if (display_mode.isString()) {
187 const std::string display_mode_str = display_mode.asString();
188 if (
"horz_side_by_side" == display_mode_str) {
189 res.display_mode = HORIZONTAL_SIDE_BY_SIDE;
190 }
else if (
"vert_side_by_side" == display_mode_str) {
191 res.display_mode = VERTICAL_SIDE_BY_SIDE;
192 }
else if (
"full_screen" == display_mode_str) {
193 res.display_mode = FULL_SCREEN;
195 OSVR_DEV_VERBOSE(
"DisplayDescriptor::parse(): WARNING: "
196 "Unknown display mode string: "
197 << display_mode_str <<
" (using default)");
201 m_resolutions.push_back(res);
204 void DisplayDescriptor::print()
const {
205 std::cout <<
"Monocular horizontal FOV: "
206 << m_monocularHorizontalFOV << std::endl;
207 std::cout <<
"Monocular vertical FOV: " << m_monocularVerticalFOV
209 std::cout <<
"Overlap percent: " << m_overlapPercent <<
"%"
211 std::cout <<
"Pitch tilt: " << m_pitchTilt << std::endl;
212 std::cout <<
"Resolution: " << activeResolution().width <<
" x "
213 << activeResolution().height << std::endl;
214 std::cout <<
"Video inputs: " << activeResolution().video_inputs
216 std::cout <<
"Display mode: " << activeResolution().display_mode
218 std::cout <<
"Right roll: " << m_rightRoll << std::endl;
219 std::cout <<
"Left roll: " << m_leftRoll << std::endl;
220 std::cout <<
"Number of eyes: " << m_eyes.size() << std::endl;
221 for (std::vector<EyeInfo>::size_type i = 0; i < m_eyes.size();
223 std::cout <<
"Eye " << i <<
": " << std::endl;
230 std::string DisplayDescriptor::getModel()
const {
return m_model; }
232 std::string DisplayDescriptor::getVersion()
const {
return m_version; }
234 std::string DisplayDescriptor::getNote()
const {
return m_note; }
236 int DisplayDescriptor::getNumDisplays()
const {
237 if (m_eyes.size() < 2) {
241 if (activeResolution().display_mode == DisplayMode::FULL_SCREEN) {
242 BOOST_ASSERT(activeResolution().video_inputs == 2);
248 int DisplayDescriptor::getDisplayTop()
const {
return 0; }
250 int DisplayDescriptor::getDisplayLeft()
const {
return 0; }
252 int DisplayDescriptor::getDisplayWidth()
const {
253 return activeResolution().width;
256 int DisplayDescriptor::getDisplayHeight()
const {
257 return activeResolution().height;
260 DisplayDescriptor::DisplayMode
261 DisplayDescriptor::getDisplayMode()
const {
262 return activeResolution().display_mode;
265 util::Angle DisplayDescriptor::getVerticalFOV()
const {
266 return m_monocularVerticalFOV;
269 util::Angle DisplayDescriptor::getHorizontalFOV()
const {
270 return m_monocularHorizontalFOV;
273 double DisplayDescriptor::getOverlapPercent()
const {
274 return m_overlapPercent;
277 util::Angle DisplayDescriptor::getPitchTilt()
const {
281 double DisplayDescriptor::getIPDMeters()
const {
282 return DEFAULT_IPD_METERS;
285 std::vector<DisplayDescriptor::EyeInfo>
const &
286 DisplayDescriptor::getEyes()
const {
290 void DisplayDescriptor::EyeInfo::print()
const {
291 std::cout <<
"Center of projection (X): " << m_CenterProjX
293 std::cout <<
"Center of projection (Y): " << m_CenterProjY
295 std::cout <<
"Rotate by 180: " << std::boolalpha << m_rotate180
AngleRadiansd Angle
Default angle type.
std::string getVendor() const
Read the property information.
Header containing wrappers for some common jsoncpp operations.
Internal, configured header file for verbosity macros.
std::string getHumanReadableDescription() const
Returns a human-readable description of the device being used, assembled from properties.
Json::Value jsonParse(std::string const &str)
Parses a string as JSON, returning a null value if parsing fails.