comparison dmply.h @ 70:03aa729a9e90

Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 16 Dec 2019 07:51:05 +0200
parents
children 9ee0edff3940
comparison
equal deleted inserted replaced
69:267b3fd2c98c 70:03aa729a9e90
1 //
2 // GLDragon - OpenGL PLY model viewer / simple benchmark
3 // -- PLY file parsing
4 // Programmed and designed by Matti 'ccr' Hämäläinen <ccr@tnsp.org>
5 // (C) Copyright 2019 Tecnic Software productions (TNSP)
6 //
7 // See file "COPYING" for license information.
8 //
9 #ifndef DMPLY_H
10 #define DMPLY_H 1
11
12 #include "dmscene.h"
13 #include <unordered_map>
14
15
16 /* Constants
17 */
18 #define PLY_PROP_VERTEX_INDICES "vertex_indices"
19 #define PLY_ELEM_FACE "face"
20 #define PLY_ELEM_VERTEX "vertex"
21
22
23 enum DMPLYFormat
24 {
25 PLY_FMT_UNKNOWN,
26 PLY_FMT_ASCII,
27 PLY_FMT_BIN_LE,
28 PLY_FMT_BIN_BE
29 };
30
31
32 enum DMPLYPropType
33 {
34 PLY_TYPE_NONE,
35 PLY_TYPE_LIST,
36
37 PLY_TYPE_UINT8,
38 PLY_TYPE_INT8,
39 PLY_TYPE_INT16,
40 PLY_TYPE_UINT16,
41 PLY_TYPE_INT32,
42 PLY_TYPE_UINT32,
43 PLY_TYPE_FLOAT,
44 PLY_TYPE_DOUBLE
45 };
46
47
48 /* Structures
49 */
50 union DMPLYPropValue
51 {
52 double v_double;
53 float v_float;
54 unsigned int v_uint;
55 int v_int;
56 };
57
58
59 struct DMPLYFileProperty
60 {
61 std::string name;
62 DMPLYPropType
63 type,
64 list_num_type,
65 list_values_type;
66
67 DMPLYPropValue value, list_num_value;
68 std::vector<DMPLYPropValue> list_values;
69 };
70
71
72 struct DMPLYFileElement
73 {
74 int value;
75 std::string name;
76
77 std::unordered_map<std::string, DMPLYFileProperty> prop_map;
78 std::vector<DMPLYFileProperty *> properties;
79
80 DMPLYFileProperty *checkProp(const std::string &prop)
81 {
82 if (prop_map.count(prop))
83 return &prop_map[prop];
84 else
85 return 0;
86 }
87 };
88
89
90 struct DMPLYFileInfo : DMTextFileInfo
91 {
92 DMPLYFormat format;
93
94 std::unordered_map<std::string, DMPLYFileElement> elem_map;
95 std::vector<DMPLYFileElement *> elements;
96 DMPLYFileElement *element;
97
98 DMPLYFileInfo()
99 {
100 element = 0;
101 format = PLY_FMT_UNKNOWN;
102 }
103
104 DMPLYFileElement *checkElem(const std::string &elem)
105 {
106 if (elem_map.count(elem))
107 return &elem_map[elem];
108 else
109 return 0;
110 }
111 };
112
113
114 /* Functions
115 */
116 bool dmLoadFromPLY(DMModel &model, const std::string &filename);
117 bool dmLoadFromPLY(DMModel &model, const std::string &filename, DMPLYFileInfo &info);
118
119
120 #endif