Spaces:
Build error
Build error
File size: 3,517 Bytes
28451f7 |
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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*
* 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.
*/
/** @file json_binding.h
* @author Thomas Müller, NVIDIA
* @brief Conversion between some ngp types and nlohmann::json.
*/
#pragma once
#include <neural-graphics-primitives/bounding_box.cuh>
#include <neural-graphics-primitives/common.h>
#include <tiny-cuda-nn/vec_json.h>
#include <json/json.hpp>
namespace ngp {
inline void to_json(nlohmann::json& j, const BoundingBox& box) {
j["min"] = box.min;
j["max"] = box.max;
}
inline void from_json(const nlohmann::json& j, BoundingBox& box) {
box.min = j.at("min");
box.max = j.at("max");
}
inline void to_json(nlohmann::json& j, const Lens& lens) {
if (lens.mode == ELensMode::OpenCV) {
j["is_fisheye"] = false;
j["k1"] = lens.params[0];
j["k2"] = lens.params[1];
j["p1"] = lens.params[2];
j["p2"] = lens.params[3];
} else if (lens.mode == ELensMode::OpenCVFisheye) {
j["is_fisheye"] = true;
j["k1"] = lens.params[0];
j["k2"] = lens.params[1];
j["k3"] = lens.params[2];
j["k4"] = lens.params[3];
} else if (lens.mode == ELensMode::FTheta) {
j["ftheta_p0"] = lens.params[0];
j["ftheta_p1"] = lens.params[1];
j["ftheta_p2"] = lens.params[2];
j["ftheta_p3"] = lens.params[3];
j["ftheta_p4"] = lens.params[4];
j["w"] = lens.params[5];
j["h"] = lens.params[6];
} else if (lens.mode == ELensMode::LatLong) {
j["latlong"] = true;
} else if (lens.mode == ELensMode::Equirectangular) {
j["equirectangular"] = true;
} else if (lens.mode == ELensMode::Orthographic) {
j["orthographic"] = true;
}
}
inline void from_json(const nlohmann::json& j, Lens& lens) {
if (j.contains("k1")) {
if (j.value("is_fisheye", false)) {
lens.mode = ELensMode::OpenCVFisheye;
lens.params[0] = j.at("k1");
lens.params[1] = j.at("k2");
lens.params[2] = j.at("k3");
lens.params[3] = j.at("k4");
} else {
lens.mode = ELensMode::OpenCV;
lens.params[0] = j.at("k1");
lens.params[1] = j.at("k2");
lens.params[2] = j.at("p1");
lens.params[3] = j.at("p2");
}
} else if (j.contains("ftheta_p0")) {
lens.mode = ELensMode::FTheta;
lens.params[0] = j.at("ftheta_p0");
lens.params[1] = j.at("ftheta_p1");
lens.params[2] = j.at("ftheta_p2");
lens.params[3] = j.at("ftheta_p3");
lens.params[4] = j.at("ftheta_p4");
lens.params[5] = j.at("w");
lens.params[6] = j.at("h");
} else if (j.contains("latlong")) {
lens.mode = ELensMode::LatLong;
} else if (j.contains("equirectangular")) {
lens.mode = ELensMode::Equirectangular;
} else if (j.contains("orthographic")) {
lens.mode = ELensMode::Orthographic;
} else {
lens.mode = ELensMode::Perspective;
}
}
inline void from_json(const nlohmann::json& j, TrainingXForm& x) {
x.start = j.at("start");
x.end = j.at("end");
}
inline void to_json(nlohmann::json& j, const TrainingXForm& x) {
j["start"] = x.start;
j["end"] = x.end;
}
}
|