COGS
Computer Graphics Structures library
DataBlockExporter.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_EXPORTER_H
7 #define COGS_DATA_BLOCK_EXPORTER_H
8 #include <vector>
9 #include <memory>
10 #include <COGS/io/DataBlockManager.h>
11 
12 
13 
14 namespace cogs // forward declarations
15 {
16  class PointCloud;
17  class Scan;
18  struct Mesh;
19 }
20 
21 
22 
23 namespace cogs
24 {
25  namespace io
26  {
40  class COGS_API DataBlockExporter
41  {
42  public:
43 
45  static uint8_t VERSION;
46 
48  explicit DataBlockExporter();
49 
51  DataBlockExporter(const std::shared_ptr<DataBlockManager> &datablock_manager);
52 
53  virtual ~DataBlockExporter();
54  DataBlockExporter(const DataBlockExporter &) = delete;
55  DataBlockExporter &operator=(const DataBlockExporter &) = delete;
56  DataBlockExporter(const DataBlockExporter &&) = delete;
57  DataBlockExporter &operator=(const DataBlockExporter &&) = delete;
58 
65  [[nodiscard]] bool OpenFile(const std::string &filename, bool overwrite_existing = false);
66 
68  void CloseFile();
69 
75  [[nodiscard]] DataBlockIndex WritePointCloud(const cogs::PointCloud &cloud);
76 
82  [[nodiscard]] DataBlockIndex WriteScan(const cogs::Scan &scan);
83 
89  [[nodiscard]] DataBlockIndex WriteMesh(const cogs::Mesh &mesh);
90 
91  private:
92 
93  struct DataBlockInfo
94  {
96  DataBlockType type;
98  uint8_t version;
100  uint64_t position;
101  };
102 
103  std::ofstream file_;
104  std::streampos nav_reference_position_;
105  std::vector<DataBlockInfo> navigation_;
106  std::shared_ptr<DataBlockManager> datablock_manager_;
107  std::unordered_map<DataBlockType, DataBlockIndex> index_counter_;
108 
114  [[nodiscard]] std::unique_ptr<cogs::io::DataBlock> WriteCustom(const DataBlockType &type);
115 
121  template <typename T>
122  std::unique_ptr<T> WriteCustom(const DataBlockType &type)
123  {
124  auto dtb_ptr = WriteCustom(type);
125  return std::unique_ptr<T> { static_cast<T *>(dtb_ptr.release()) };
126  }
127 
129  void ExportHeader();
130 
132  void ExportNavigation();
133 
135  [[nodiscard]] bool ExportDatablock(DataBlock &dtb);
136  };
137 
138  }
139 }
140 
141 #endif /* !COGS_DATA_BLOCK_EXPORTER_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
size_t DataBlockIndex
Defines position index of the data block in a file.
Definition: DataBlock.h:13
Enables writing or cogs structures into files.
Definition: DataBlockExporter.h:40
Management class for a set of data points in a 3D space.
Definition: PointCloud.h:32
Definition of required interface for derived data blocks.
Definition: DataBlock.h:25
static uint8_t VERSION
Current exporter version.
Definition: DataBlockExporter.h:45
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