Openholo  v5.0
Open Source Digital Holographic Library
PLYparser.h
Go to the documentation of this file.
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install, copy or use the software.
7 //
8 //
9 // License Agreement
10 // For Open Source Digital Holographic Library
11 //
12 // Openholo library is free software;
13 // you can redistribute it and/or modify it under the terms of the BSD 2-Clause license.
14 //
15 // Copyright (C) 2017-2024, Korea Electronics Technology Institute. All rights reserved.
16 // E-mail : contact.openholo@gmail.com
17 // Web : http://www.openholo.org
18 //
19 // Redistribution and use in source and binary forms, with or without modification,
20 // are permitted provided that the following conditions are met:
21 //
22 // 1. Redistribution's of source code must retain the above copyright notice,
23 // this list of conditions and the following disclaimer.
24 //
25 // 2. Redistribution's in binary form must reproduce the above copyright notice,
26 // this list of conditions and the following disclaimer in the documentation
27 // and/or other materials provided with the distribution.
28 //
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the copyright holder or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
39 //
40 // This software contains opensource software released under GNU Generic Public License,
41 // NVDIA Software License Agreement, or CUDA supplement to Software License Agreement.
42 // Check whether software you use contains licensed software.
43 //
44 //M*/
45 
46 #ifndef __PLY_PARSER_H__
47 #define __PLY_PARSER_H__
48 
49 #include <iostream>
50 #include <sstream>
51 #include <fstream>
52 #include <map>
53 #include <typeinfo>
54 #include "include.h"
55 
56 
57 /* PLY File Header for Openholo Point Cloud Format
58 ply
59 format ascii 1.0
60 comment Openholo Point Cloud Format
61 element color 1
62 property int channel
63 element vertex n_vertices
64 property Real x
65 property Real y
66 property Real z
67 property uchar red #diffuse_red
68 property uchar green #diffuse_green
69 property uchar blue #diffuse_blue
70 property Real phase
71 end_header
72 */
73 
74 /* PLY File Header for Openholo Triangle Mesh Format
75 ply
76 format ascii 1.0
77 comment Openholo Triangle Mesh Format
78 element color 1
79 property int channel
80 element vertex n_vertices
81 property uint face_idx
82 property Real x
83 property Real y
84 property Real z
85 property uchar red #diffuse_red
86 property uchar green #diffuse_green
87 property uchar blue #diffuse_blue
88 end_header
89 */
90 
91 //#ifdef _WIN32
92 //#define OPH_DLL __declspec(dllexport)
93 //#else
94 //#define OPH_DLL __attribute__((visibility("default")))
95 //#endif
96 
97 
98 
100 public:
101  PLYparser();
102  ~PLYparser();
103 
104 private:
105  enum class Type {
106  INVALID,
107  INT8,
108  UINT8,
109  INT16,
110  UINT16,
111  INT32,
112  UINT32,
113  FLOAT32,
114  FLOAT64
115  };
116 
117  //pair<int : stride, string : str>
118  std::map<Type, std::pair<int, std::string> > PropertyTable;
119 
120  struct PlyProperty {
121  std::string name;
122  Type propertyType;
123  bool isList = false;
124  Type listType = Type::INVALID;
125  longlong listCount = 0;
126 
127  PlyProperty(std::istream &is);
128  PlyProperty(const Type type, const std::string &_name);
129  PlyProperty(const Type list_type, const Type prop_type, const std::string &_name, const ulonglong list_count);
130  };
131 
132  struct PlyElement {
133  std::string name;
134  longlong size;
135  std::vector<PLYparser::PlyProperty> properties;
136 
137  PlyElement(std::istream &is);
138  PlyElement(const std::string &_name, const ulonglong count);
139  };
140 
141  static Type propertyTypeFromString(const std::string &t);
142 
143  bool findIdxOfPropertiesAndElement(
144  const std::vector<PlyElement> &elements,
145  const std::string &elementKey,
146  const std::string &propertyKeys,
147  longlong &elementIdx,
148  int &propertyIdx);
149 
150 public:
151  bool loadPLY(
152  const std::string& fileName,
153  ulonglong& n_points,
154  Vertex** vertices
155  );
156 
157  bool savePLY(
158  const std::string& fileName,
159  const ulonglong n_points,
160  Vertex* vertices,
161  bool isBinary
162  );
163 
164  bool loadPLY(
165  const std::string& fileName,
166  ulonglong& n_Vertices,
167  Face** faces
168  );
169 
170  bool savePLY(
171  const std::string& fileName,
172  const ulonglong n_vertices,
173  Face* faces,
174  bool isBinary
175  );
176 };
177 
178 
179 #endif
long long longlong
Definition: typedef.h:66
unsigned long long ulonglong
Definition: typedef.h:67
#define OPH_DLL
Definition: Base.h:59
Definition: struct.h:102
Definition: struct.h:115