Openholo  v2.1
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 
92 class __declspec(dllexport) PLYparser {
93 public:
94  PLYparser();
95  ~PLYparser();
96 
97 private:
98  enum class Type {
99  INVALID,
100  INT8,
101  UINT8,
102  INT16,
103  UINT16,
104  INT32,
105  UINT32,
106  FLOAT32,
107  FLOAT64
108  };
109 
110  //pair<int : stride, string : str>
111  std::map<Type, std::pair<int, std::string> > PropertyTable;
112 
113  struct PlyProperty {
114  std::string name;
115  Type propertyType;
116  bool isList = false;
117  Type listType = Type::INVALID;
118  longlong listCount = 0;
119 
120  PlyProperty(std::istream &is);
121  PlyProperty(const Type type, const std::string &_name);
122  PlyProperty(const Type list_type, const Type prop_type, const std::string &_name, const ulonglong list_count);
123  };
124 
125  struct PlyElement {
126  std::string name;
127  longlong size;
128  std::vector<PLYparser::PlyProperty> properties;
129 
130  PlyElement(std::istream &is);
131  PlyElement(const std::string &_name, const ulonglong count);
132  };
133 
134  static Type propertyTypeFromString(const std::string &t);
135 
136  bool findIdxOfPropertiesAndElement(
137  const std::vector<PlyElement> &elements,
138  const std::string &elementKey,
139  const std::string &propertyKeys,
140  longlong &elementIdx,
141  int &propertyIdx);
142 
143 public:
144  bool loadPLY( // for Point Cloud Data
145  const std::string& fileName,
146  ulonglong &n_points,
147  int &color_channels, //1 or 3 (If it is 4, Alpha channel is not loaded.)
148  Real** vertexArray,
149  Real** colorArray,
150  Real** phaseArray, //If isPhaseParse is false, PhaseArray is nullptr
151  bool &isPhaseParse);
152 
153  bool savePLY(
154  const std::string& fileName,
155  const ulonglong n_points,
156  const int color_channels,
157  Real* vertexArray,
158  Real* colorArray,
159  Real* phaseArray);
160 
161  bool loadPLY( // for Triangle Mesh Data
162  const char* fileName,
163  ulonglong &n_vertices,
164  int &color_channels,
165  uint** face_idx,
166  Real** vertexArray,
167  Real** colorArray);
168 
169  bool savePLY(
170  const char* fileName,
171  const ulonglong n_vertices,
172  const int color_channels,
173  uint* face_idx,
174  Real* vertexArray,
175  Real* colorArray);
176 };
177 
178 
179 #endif
long long longlong
Definition: typedef.h:66
name
Definition: setup.py:14
unsigned long long ulonglong
Definition: typedef.h:67
float Real
Definition: typedef.h:55
unsigned int uint
Definition: typedef.h:62