ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
AlignmentSession.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include "AlignmentSession.h"
9 
10 #include <json/json.h>
11 
12 namespace cloudViewer {
13 
14 bool AlignmentSession::ConvertToJsonValue(Json::Value &value) const {
15  value["class_name"] = "AlignmentSession";
16  value["version_major"] = 1;
17  value["version_minor"] = 0;
18  Json::Value source_array;
19  for (const auto &si : source_indices_) {
20  source_array.append((int)si);
21  }
22  value["source_indices"] = source_array;
23  Json::Value target_array;
24  for (const auto &ti : target_indices_) {
25  target_array.append((int)ti);
26  }
27  value["target_indices"] = target_array;
28  if (!EigenMatrix4dToJsonArray(transformation_, value["transformation"])) {
29  return false;
30  }
31  value["voxel_size"] = voxel_size_;
32  value["max_correspondence_distance"] = max_correspondence_distance_;
33  value["with_scaling"] = with_scaling_;
34  return true;
35 }
36 
37 bool AlignmentSession::ConvertFromJsonValue(const Json::Value &value) {
38  if (!value.isObject()) {
40  "AlignmentSession read JSON failed: unsupported json "
41  "format.");
42  return false;
43  }
44  if (value.get("class_name", "").asString() != "AlignmentSession" ||
45  value.get("version_major", 1).asInt() != 1 ||
46  value.get("version_minor", 0).asInt() != 0) {
48  "AlignmentSession read JSON failed: unsupported json "
49  "format.");
50  return false;
51  }
52  const auto &source_array = value["source_indices"];
53  source_indices_.resize(source_array.size());
54  for (int i = 0; i < (int)source_array.size(); i++) {
55  source_indices_[i] = (size_t)source_array[i].asInt();
56  }
57  const auto &target_array = value["target_indices"];
58  target_indices_.resize(target_array.size());
59  for (int i = 0; i < (int)target_array.size(); i++) {
60  target_indices_[i] = (size_t)target_array[i].asInt();
61  }
62  if (!EigenMatrix4dFromJsonArray(transformation_, value["transformation"])) {
63  return false;
64  }
65  voxel_size_ = value["voxel_size"].asDouble();
67  value["max_correspondence_distance"].asDouble();
68  with_scaling_ = value["with_scaling"].asBool();
69  return true;
70 }
71 
72 } // namespace cloudViewer
std::vector< size_t > source_indices_
Eigen::Matrix4d_u transformation_
bool ConvertFromJsonValue(const Json::Value &value) override
std::vector< size_t > target_indices_
bool ConvertToJsonValue(Json::Value &value) const override
static bool EigenMatrix4dFromJsonArray(Eigen::Matrix4d &mat, const Json::Value &value)
static bool EigenMatrix4dToJsonArray(const Eigen::Matrix4d &mat, Json::Value &value)
#define LogWarning(...)
Definition: Logging.h:72
Generic file read and write utility for python interface.