ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
OctreeIO.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 "OctreeIO.h"
9 
10 #include <FileSystem.h>
11 #include <Logging.h>
12 
13 #include <unordered_map>
14 
15 #include "IJsonConvertibleIO.h"
16 
17 namespace cloudViewer {
18 namespace io {
19 static const std::unordered_map<
20  std::string,
21  std::function<bool(const std::string &, geometry::Octree &)>>
23  {"json", ReadOctreeFromJson},
24  };
25 
26 static const std::unordered_map<
27  std::string,
28  std::function<bool(const std::string &, const geometry::Octree &)>>
30  {"json", WriteOctreeToJson},
31  };
32 
33 std::shared_ptr<geometry::Octree> CreateOctreeFromFile(
34  const std::string &filename, const std::string &format) {
35  auto octree = std::make_shared<geometry::Octree>();
37  return octree;
38 }
39 
40 bool ReadOctree(const std::string &filename,
42  const std::string &format) {
43  std::string filename_ext;
44  if (format == "auto") {
45  filename_ext =
47  } else {
48  filename_ext = format;
49  }
50  if (filename_ext.empty()) {
52  "Read geometry::Octree failed: unknown file extension.");
53  return false;
54  }
55  auto map_itr = file_extension_to_octree_read_function.find(filename_ext);
56  if (map_itr == file_extension_to_octree_read_function.end()) {
58  "Read geometry::Octree failed: unknown file extension.");
59  return false;
60  }
61  bool success = map_itr->second(filename, octree);
62  utility::LogDebug("Read geometry::Octree.");
63  return success;
64 }
65 
66 bool WriteOctree(const std::string &filename, const geometry::Octree &octree) {
67  std::string filename_ext =
69  if (filename_ext.empty()) {
71  "Write geometry::Octree failed: unknown file extension.");
72  return false;
73  }
74  auto map_itr = file_extension_to_octree_write_function.find(filename_ext);
75  if (map_itr == file_extension_to_octree_write_function.end()) {
77  "Write geometry::Octree failed: unknown file extension.");
78  return false;
79  }
80  bool success = map_itr->second(filename, octree);
81  utility::LogDebug("Write geometry::Octree.");
82  return success;
83 }
84 
85 bool ReadOctreeFromJson(const std::string &filename, geometry::Octree &octree) {
87 }
88 
89 bool WriteOctreeToJson(const std::string &filename,
90  const geometry::Octree &octree) {
92 }
93 } // namespace io
94 } // namespace cloudViewer
std::string filename
filament::Texture::InternalFormat format
Octree datastructure.
Definition: Octree.h:250
#define LogWarning(...)
Definition: Logging.h:72
#define LogDebug(...)
Definition: Logging.h:90
bool WriteOctree(const std::string &filename, const geometry::Octree &octree)
Definition: OctreeIO.cpp:66
static const std::unordered_map< std::string, std::function< bool(const std::string &, geometry::Octree &)> > file_extension_to_octree_read_function
Definition: OctreeIO.cpp:22
bool ReadOctreeFromJson(const std::string &filename, geometry::Octree &octree)
Definition: OctreeIO.cpp:85
bool WriteIJsonConvertibleToJSON(const std::string &filename, const cloudViewer::utility::IJsonConvertible &object)
static const std::unordered_map< std::string, std::function< bool(const std::string &, const geometry::Octree &)> > file_extension_to_octree_write_function
Definition: OctreeIO.cpp:29
bool WriteOctreeToJson(const std::string &filename, const geometry::Octree &octree)
Definition: OctreeIO.cpp:89
bool ReadIJsonConvertible(const std::string &filename, cloudViewer::utility::IJsonConvertible &object)
std::shared_ptr< geometry::Octree > CreateOctreeFromFile(const std::string &filename, const std::string &format="auto")
Definition: OctreeIO.cpp:33
bool ReadOctree(const std::string &filename, geometry::Octree &octree, const std::string &format="auto")
Definition: OctreeIO.cpp:40
std::string GetFileExtensionInLowerCase(const std::string &filename)
Definition: FileSystem.cpp:281
Generic file read and write utility for python interface.
cloudViewer::DgmOctree * octree