1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26
27 #include "AlignmentSession.h"
28
29 #include <json/json.h>
30
31 namespace three {
32
ConvertToJsonValue(Json::Value & value) const33 bool AlignmentSession::ConvertToJsonValue(Json::Value &value) const
34 {
35 value["class_name"] = "AlignmentSession";
36 value["version_major"] = 1;
37 value["version_minor"] = 0;
38 Json::Value source_array;
39 for (const auto &si : source_indices_) {
40 source_array.append((int)si);
41 }
42 value["source_indices"] = source_array;
43 Json::Value target_array;
44 for (const auto &ti : target_indices_) {
45 target_array.append((int)ti);
46 }
47 value["target_indices"] = target_array;
48 if (EigenMatrix4dToJsonArray(transformation_, value["transformation"]) ==
49 false) {
50 return false;
51 }
52 value["voxel_size"] = voxel_size_;
53 value["max_correspondence_distance"] = max_correspondence_distance_;
54 value["with_scaling"] = with_scaling_;
55 return true;
56 }
57
ConvertFromJsonValue(const Json::Value & value)58 bool AlignmentSession::ConvertFromJsonValue(const Json::Value &value)
59 {
60 if (value.isObject() == false) {
61 PrintWarning("AlignmentSession read JSON failed: unsupported json format.\n");
62 return false;
63 }
64 if (value.get("class_name", "").asString() != "AlignmentSession" ||
65 value.get("version_major", 1).asInt() != 1 ||
66 value.get("version_minor", 0).asInt() != 0) {
67 PrintWarning("AlignmentSession read JSON failed: unsupported json format.\n");
68 return false;
69 }
70 const auto &source_array = value["source_indices"];
71 source_indices_.resize(source_array.size());
72 for (int i = 0; i < (int)source_array.size(); i++) {
73 source_indices_[i] = (size_t)source_array[i].asInt();
74 }
75 const auto &target_array = value["target_indices"];
76 target_indices_.resize(target_array.size());
77 for (int i = 0; i < (int)target_array.size(); i++) {
78 target_indices_[i] = (size_t)target_array[i].asInt();
79 }
80 if (EigenMatrix4dFromJsonArray(transformation_, value["transformation"]) ==
81 false) {
82 return false;
83 }
84 voxel_size_ = value["voxel_size"].asDouble();
85 max_correspondence_distance_ =
86 value["max_correspondence_distance"].asDouble();
87 with_scaling_ = value["with_scaling"].asBool();
88 return true;
89 }
90
91 } // namespace three
92