ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ply.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <string>
11 #include <vector>
12 
13 #include "types.h"
14 
15 namespace colmap {
16 
17 struct PlyPoint {
18  float x = 0.0f;
19  float y = 0.0f;
20  float z = 0.0f;
21  float nx = 0.0f;
22  float ny = 0.0f;
23  float nz = 0.0f;
24  uint8_t r = 0;
25  uint8_t g = 0;
26  uint8_t b = 0;
27 };
28 
29 struct PlyMeshVertex {
30  PlyMeshVertex() : x(0), y(0), z(0) {}
31  PlyMeshVertex(const float x, const float y, const float z)
32  : x(x), y(y), z(z) {}
33 
34  float x = 0.0f;
35  float y = 0.0f;
36  float z = 0.0f;
37 };
38 
39 struct PlyMeshFace {
41  PlyMeshFace(const size_t vertex_idx1,
42  const size_t vertex_idx2,
43  const size_t vertex_idx3)
47 
48  size_t vertex_idx1 = 0;
49  size_t vertex_idx2 = 0;
50  size_t vertex_idx3 = 0;
51 };
52 
53 struct PlyMesh {
54  std::vector<PlyMeshVertex> vertices;
55  std::vector<PlyMeshFace> faces;
56 };
57 
58 // Read PLY point cloud from text or binary file.
59 std::vector<PlyPoint> ReadPly(const std::string& path);
60 
61 // Write PLY point cloud to text or binary file.
62 void WriteTextPlyPoints(const std::string& path,
63  const std::vector<PlyPoint>& points,
64  const bool write_normal = true,
65  const bool write_rgb = true);
66 void WriteBinaryPlyPoints(const std::string& path,
67  const std::vector<PlyPoint>& points,
68  const bool write_normal = true,
69  const bool write_rgb = true);
70 
71 // Write PLY mesh to text or binary file.
72 void WriteTextPlyMesh(const std::string& path, const PlyMesh& mesh);
73 void WriteBinaryPlyMesh(const std::string& path, const PlyMesh& mesh);
74 
75 } // namespace colmap
int points
static const std::string path
Definition: PointCloud.cpp:59
void WriteTextPlyMesh(const std::string &path, const PlyMesh &mesh)
Definition: ply.cc:423
void WriteBinaryPlyPoints(const std::string &path, const std::vector< PlyPoint > &points, const bool write_normal, const bool write_rgb)
Definition: ply.cc:369
void WriteTextPlyPoints(const std::string &path, const std::vector< PlyPoint > &points, const bool write_normal, const bool write_rgb)
Definition: ply.cc:323
void WriteBinaryPlyMesh(const std::string &path, const PlyMesh &mesh)
Definition: ply.cc:448
std::vector< PlyPoint > ReadPly(const std::string &path)
Definition: ply.cc:43
size_t vertex_idx3
Definition: ply.h:50
PlyMeshFace(const size_t vertex_idx1, const size_t vertex_idx2, const size_t vertex_idx3)
Definition: ply.h:41
size_t vertex_idx2
Definition: ply.h:49
size_t vertex_idx1
Definition: ply.h:48
PlyMeshVertex(const float x, const float y, const float z)
Definition: ply.h:31
std::vector< PlyMeshFace > faces
Definition: ply.h:55
std::vector< PlyMeshVertex > vertices
Definition: ply.h:54
float nz
Definition: ply.h:23
uint8_t b
Definition: ply.h:26
float nx
Definition: ply.h:21
float z
Definition: ply.h:20
uint8_t r
Definition: ply.h:24
uint8_t g
Definition: ply.h:25
float ny
Definition: ply.h:22
float x
Definition: ply.h:18
float y
Definition: ply.h:19