Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
PlyFile.h
Go to the documentation of this file.
1#pragma once
2
13#include "Math/constant.h"
14
15#include <Common/primitive_type.h>
16
17#include <vector>
18#include <cstddef>
19#include <string>
20#include <string_view>
21#include <climits>
22
23namespace ph { class IInputStream; }
24
25namespace ph
26{
27
29{
30 ASCII = 0,
33
34 NUM
35};
36
37enum class EPlyDataType
38{
39 Unspecified = 0,
40
42 Int8,
43
45 UInt8,
46
48 Int16,
49
51 UInt16,
52
54 Int32,
55
57 UInt32,
58
60 Float32,
61
63 Float64,
64
65 NUM
66};
67
68struct PlyIOConfig final
69{
71 bool bIgnoreComments = true;
72
74 bool bPreloadIntoMemory = true;
75
78
81};
82
85
88struct PlyProperty final
89{
90 std::string name;
93 std::size_t strideOffset;
94 std::size_t fixedListSize;
95
99 std::vector<std::byte> rawListBuffer;
100
104 std::vector<std::size_t> listSizesPrefixSum;
105
106 PlyProperty();
107
108 bool isList() const;
109 bool isFixedSizeList() const;
110};
111
114struct PlyElement final
115{
116 std::string name;
117 std::size_t numElements;
118 std::vector<PlyProperty> properties;
119 std::size_t strideSize;
120
129 std::vector<std::byte> rawBuffer;
130
131 PlyElement();
132
133 bool isLoaded() const;
134 bool containsList() const;
135 PlyProperty* findProperty(std::string_view name);
138};
139
143{
144 friend PlyElement;
145
146public:
147 float64 get(std::size_t index) const;
148 void set(std::size_t index, float64 value);
149 std::size_t size() const;
150 operator bool () const;
151
152private:
154
156 std::byte* rawBuffer,
157 std::size_t strideSize,
158 std::size_t numElements,
159 EPlyDataType valueType);
160
161 std::size_t getBufferOffset(std::size_t index) const;
162
163 std::byte* m_rawBuffer;
164 std::size_t m_strideSize;
165 std::size_t m_numElements;
166 EPlyDataType m_valueType;
167};
168
172{
173 friend PlyElement;
174
175public:
176 float64 get(std::size_t listIndex, std::size_t listElementIndex) const;
177 void set(std::size_t listIndex, std::size_t listElementIndex, float64 value);
178
181 std::size_t size() const;
182
185 std::size_t listSize(std::size_t listIndex) const;
186
187 bool isFixedSizeList() const;
188 std::size_t fixedListSize() const;
189 operator bool () const;
190
191private:
193
195 std::byte* rawBuffer,
196 std::size_t* listSizesPrefixSum,
197 std::size_t numLists,
198 std::size_t fixedListSize,
199 EPlyDataType valueType);
200
201 std::size_t getBufferOffset(std::size_t listIndex, std::size_t listElementIndex) const;
202
203 std::byte* m_rawBuffer;
204 std::size_t* m_listSizesPrefixSum;
205 std::size_t m_numLists;
206 std::size_t m_fixedListSize;
207 EPlyDataType m_valueType;
208};
209
210class PlyFile final
211{
212 static_assert(sizeof(std::byte) * CHAR_BIT == 8,
213 "The file explicitly depends on the fact that std::byte contains 8 bits.");
214
215public:
216 PlyFile();
217
220 explicit PlyFile(const Path& plyFilePath);
221
225 PlyFile(const Path& plyFilePath, const PlyIOConfig& config);
226
227 PlyElement* findElement(std::string_view name);
228 std::size_t numElements() const;
229
231 void setInputFormat(EPlyDataFormat format);
233 void setOutputFormat(EPlyDataFormat format);
234
239 std::size_t numComments() const;
240 std::string_view getComment(std::size_t commentIndex) const;
242
245 void loadFile(const Path& plyFilePath, const PlyIOConfig& config);
246
249 void clearBuffer();
250
252
253private:
255 void parseHeader(IInputStream& stream, const PlyIOConfig& config);
256
260 void loadBuffer(IInputStream& stream, const PlyIOConfig& config);
261
263 void loadAsciiElementBuffer(
264 IInputStream& stream,
265 PlyElement& element,
266 const PlyIOConfig& config);
267
269 void loadBinaryElementBuffer(
270 IInputStream& stream,
271 PlyElement& element,
272 const PlyIOConfig& config);
273
275 void loadNonListBinaryElementBuffer(
276 IInputStream& stream,
277 PlyElement& element,
278 const PlyIOConfig& config);
279
280 void loadSingleBinaryPlyDataToBuffer(
281 IInputStream& stream,
282 EPlyDataType dataType,
283 std::byte* out_buffer);
284
286 void compactBuffer();
287
289 void reserveBuffer();
290
291private:
292 EPlyDataFormat m_inputFormat;
293 EPlyDataFormat m_outputFormat;
294 EPlyDataFormat m_nativeFormat;
295 SemanticVersion m_version;
296 std::vector<std::string> m_comments;
297 std::vector<PlyElement> m_elements;
298};
299
300}// end namespace ph
Definition IInputStream.h:13
General path representation. Does not check whether the target actually exists (e....
Definition Path.h:21
Definition PlyFile.h:211
std::size_t numComments() const
Access to comments in the file. There will be no comments if PlyIOConfig::bIgnoreComments is set.
Definition PlyFile.cpp:723
void setOutputFormat(EPlyDataFormat format)
Definition PlyFile.cpp:757
std::string_view getComment(std::size_t commentIndex) const
Definition PlyFile.cpp:728
EPlyDataFormat getOutputFormat() const
Definition PlyFile.cpp:752
void setInputFormat(EPlyDataFormat format)
Definition PlyFile.cpp:747
void loadFile(const Path &plyFilePath, const PlyIOConfig &config)
Load and append file content to existing data.
Definition PlyFile.cpp:831
PlyFile()
Definition PlyFile.cpp:659
std::size_t numElements() const
Definition PlyFile.cpp:718
PlyElement * findElement(std::string_view name)
Definition PlyFile.cpp:706
EPlyDataFormat getInputFormat() const
Definition PlyFile.cpp:742
SemanticVersion getVersion() const
Definition PlyFile.cpp:826
void clearBuffer()
Clear all data storages for the elements.
Definition PlyFile.cpp:762
A convenient PLY list property accessor.
Definition PlyFile.h:172
std::size_t listSize(std::size_t listIndex) const
Size of the list on index listIndex.
Definition PlyFile.cpp:632
float64 get(std::size_t listIndex, std::size_t listElementIndex) const
Definition PlyFile.cpp:610
void set(std::size_t listIndex, std::size_t listElementIndex, float64 value)
Definition PlyFile.cpp:618
bool isFixedSizeList() const
Definition PlyFile.cpp:643
std::size_t fixedListSize() const
Definition PlyFile.cpp:648
std::size_t size() const
Number of lists in this property.
Definition PlyFile.cpp:627
A convenient PLY property accessor.
Definition PlyFile.h:143
void set(std::size_t index, float64 value)
Definition PlyFile.cpp:550
std::size_t size() const
Definition PlyFile.cpp:559
float64 get(std::size_t index) const
Definition PlyFile.cpp:542
Convenient software version handling routines. See https://semver.org/ for a detailed explaination of...
Definition SemanticVersion.h:16
constexpr std::size_t MiB
Definition constant.h:80
constexpr std::size_t GiB
Definition constant.h:81
The root for all renderer implementations.
Definition EEngineProject.h:6
EPlyDataType
Definition PlyFile.h:38
EPlyDataFormat
Definition PlyFile.h:29
PLY element storage.
Definition PlyFile.h:115
PlyPropertyListValues listPropertyValues(PlyProperty *prop)
Definition PlyFile.cpp:492
std::vector< std::byte > rawBuffer
Definition PlyFile.h:129
std::string name
Definition PlyFile.h:116
PlyPropertyValues propertyValues(PlyProperty *prop)
Definition PlyFile.cpp:471
bool isLoaded() const
Definition PlyFile.cpp:424
PlyElement()
Definition PlyFile.cpp:416
std::vector< PlyProperty > properties
Definition PlyFile.h:118
bool containsList() const
Definition PlyFile.cpp:446
std::size_t strideSize
Definition PlyFile.h:119
PlyProperty * findProperty(std::string_view name)
Definition PlyFile.cpp:459
std::size_t numElements
Definition PlyFile.h:117
Definition PlyFile.h:69
bool bPreloadIntoMemory
Definition PlyFile.h:74
std::size_t preloadMemoryThreshold
Definition PlyFile.h:77
bool bIgnoreComments
Definition PlyFile.h:71
std::size_t reduceStorageMemoryThreshold
Definition PlyFile.h:80
PLY property storage.
Definition PlyFile.h:89
std::vector< std::byte > rawListBuffer
Definition PlyFile.h:99
std::size_t fixedListSize
Definition PlyFile.h:94
bool isList() const
Definition PlyFile.cpp:406
EPlyDataType dataType
Definition PlyFile.h:91
PlyProperty()
Definition PlyFile.cpp:396
std::size_t strideOffset
Definition PlyFile.h:93
EPlyDataType listSizeType
Definition PlyFile.h:92
bool isFixedSizeList() const
Definition PlyFile.cpp:411
std::vector< std::size_t > listSizesPrefixSum
Definition PlyFile.h:104
std::string name
Definition PlyFile.h:90