COGS
Computer Graphics Structures library
DataBlockImporter.h
1 /*
2  Copyright (C) Skeletex Research, s.r.o. - All Rights Reserved
3  Unauthorized copying of this file, via any medium is strictly prohibited
4  Proprietary and confidential
5 */
6 #ifndef COGS_DATA_BLOCK_IMPORTER_H
7 #define COGS_DATA_BLOCK_IMPORTER_H
8 #include <unordered_map>
9 #include <vector>
10 #include <memory>
11 
12 #include <COGS/io/DataBlockManager.h>
13 
14 
15 
16 namespace cogs // forward declarations
17 {
18  class PointCloud;
19  class Scan;
20  struct Mesh;
21 }
22 
23 
24 
25 namespace cogs
26 {
27  namespace io
28  {
42  class COGS_API DataBlockImporter
43  {
44  public:
45 
47  explicit DataBlockImporter();
48 
50  DataBlockImporter(const std::shared_ptr<DataBlockManager> &datablock_manager);
51 
52  DataBlockImporter(const DataBlockImporter &) = delete;
53  DataBlockImporter &operator=(const DataBlockImporter &) = delete;
54  DataBlockImporter(const DataBlockImporter &&) = delete;
55  DataBlockImporter &operator=(const DataBlockImporter &&) = delete;
56 
58  bool OpenFile(const std::string &filename);
59 
61  void CloseFile();
62 
64  [[nodiscard]] bool IsFileOpen() const;
65 
67  [[nodiscard]] size_t GetPointCloudCount() const;
68 
70  bool ReadPointCloud(cogs::PointCloud &out_cloud, DataBlockIndex id = 0);
71 
73  [[nodiscard]] size_t GetScanCount() const;
74 
76  bool ReadScan(cogs::Scan &out_scan, DataBlockIndex id = 0);
77 
79  [[nodiscard]] size_t GetMeshCount() const;
80 
82  bool ReadMesh(cogs::Mesh &out_mesh, DataBlockIndex id = 0);
83 
84  private:
85 
86  struct DataBlockInfo
87  {
89  uint8_t version;
91  std::streampos position;
93  std::shared_ptr<DataBlock> block;
95  template <typename T>
96  std::shared_ptr<T> CastBlock() const
97  {
98  return std::static_pointer_cast<T>(block);
99  }
100  };
101 
102  std::shared_ptr<DataBlockManager> datablock_manager_;
103  std::ifstream file_;
104  uint8_t file_version_;
105  std::unordered_map<DataBlockType, std::vector<DataBlockInfo>> navigation_;
106 
108  [[nodiscard]] size_t GetDatablockCount(const DataBlockType &type) const;
109 
111  std::optional<DataBlockInfo> GoToDatablock(const DataBlockType &type, DataBlockIndex id = 0);
112 
114  bool ImportHeader(std::istream &in_s);
115 
117  bool ImportNavigation(std::istream &in_s);
118  };
119 
120  }
121 }
122 
123 #endif /* !COGS_DATA_BLOCK_IMPORTER_H */
A Mesh is structure containing a point-cloud a triangulation and a material. Not all of these are req...
Definition: Mesh.h:21
Namespace of "Computer Graphic Structures" library, which implement many core classes and structures...
Definition: AabbHierarchy.h:8
Enables reading of cogs structures into files.
Definition: DataBlockImporter.h:42
size_t DataBlockIndex
Defines position index of the data block in a file.
Definition: DataBlock.h:13
Management class for a set of data points in a 3D space.
Definition: PointCloud.h:32
Set of 3D data points which are additionally organized over 2D grid.
Definition: Scan.h:22
std::string DataBlockType
Identifies data block instances. Each class derived from cogs::io::DataBlockType should have unique t...
Definition: DataBlock.h:22