1+ // ----------------------------------------------------------------------------
2+ // - Open3D: www.open3d.org -
3+ // ----------------------------------------------------------------------------
4+ // Copyright (c) 2018-2024 www.open3d.org
5+ // SPDX-License-Identifier: MIT
6+ // ----------------------------------------------------------------------------
7+
8+ #include " open3d/io/FileFormatIO.h"
9+
10+ #include < fstream>
11+
12+ #include " open3d/utility/FileSystem.h"
13+ #include " tests/Tests.h"
14+
15+ namespace open3d {
16+ namespace tests {
17+ namespace {
18+
19+ bool HasGeometry (io::FileGeometry geometry, io::FileGeometry flag) {
20+ return (int (geometry) & int (flag)) != 0 ;
21+ }
22+
23+ const char kPointPly [] = R"( ply
24+ format ascii 1.0
25+ element vertex 1
26+ property float x
27+ property float y
28+ property float z
29+ end_header
30+ 0 0 0
31+ )" ;
32+
33+ const char kGaussianSplatPly [] = R"( ply
34+ format ascii 1.0
35+ element vertex 1
36+ property float x
37+ property float y
38+ property float z
39+ property float opacity
40+ property float scale_0
41+ property float scale_1
42+ property float scale_2
43+ property float rot_0
44+ property float rot_1
45+ property float rot_2
46+ property float rot_3
47+ property float f_dc_0
48+ property float f_dc_1
49+ property float f_dc_2
50+ end_header
51+ 0 0 0 1 1 1 1 1 0 0 0 0.1 0.2 0.3
52+ )" ;
53+
54+ const char kMissingOpacityGaussianSplatPly [] = R"( ply
55+ format ascii 1.0
56+ element vertex 1
57+ property float x
58+ property float y
59+ property float z
60+ property float scale_0
61+ property float scale_1
62+ property float scale_2
63+ property float rot_0
64+ property float rot_1
65+ property float rot_2
66+ property float rot_3
67+ property float f_dc_0
68+ property float f_dc_1
69+ property float f_dc_2
70+ end_header
71+ 0 0 0 1 1 1 1 0 0 0 0.1 0.2 0.3
72+ )" ;
73+
74+ } // namespace
75+
76+ TEST (FileFormatIO, ReadFileGeometryTypePLYPointCloud) {
77+ const std::string path = utility::filesystem::GetTempDirectoryPath () +
78+ " /file_type_points.ply" ;
79+ std::ofstream output (path, std::ios::binary);
80+ ASSERT_TRUE (output.is_open ());
81+ output << kPointPly ;
82+ output.close ();
83+
84+ const auto geometry = io::ReadFileGeometryType (path);
85+ EXPECT_TRUE (HasGeometry (geometry, io::CONTAINS_POINTS));
86+ EXPECT_FALSE (HasGeometry (geometry, io::CONTAINS_GAUSSIAN_SPLATS));
87+ }
88+
89+ TEST (FileFormatIO, ReadFileGeometryTypePLYGaussianSplat) {
90+ const std::string path = utility::filesystem::GetTempDirectoryPath () +
91+ " /file_type_gaussian_splat.ply" ;
92+ std::ofstream output (path, std::ios::binary);
93+ ASSERT_TRUE (output.is_open ());
94+ output << kGaussianSplatPly ;
95+ output.close ();
96+
97+ const auto geometry = io::ReadFileGeometryType (path);
98+ EXPECT_TRUE (HasGeometry (geometry, io::CONTAINS_POINTS));
99+ EXPECT_TRUE (HasGeometry (geometry, io::CONTAINS_GAUSSIAN_SPLATS));
100+ }
101+
102+ TEST (FileFormatIO, ReadFileGeometryTypePLYRequiresFullGaussianSplatCore) {
103+ const std::string path = utility::filesystem::GetTempDirectoryPath () +
104+ " /file_type_incomplete_gaussian_splat.ply" ;
105+ std::ofstream output (path, std::ios::binary);
106+ ASSERT_TRUE (output.is_open ());
107+ output << kMissingOpacityGaussianSplatPly ;
108+ output.close ();
109+
110+ const auto geometry = io::ReadFileGeometryType (path);
111+ EXPECT_TRUE (HasGeometry (geometry, io::CONTAINS_POINTS));
112+ EXPECT_FALSE (HasGeometry (geometry, io::CONTAINS_GAUSSIAN_SPLATS));
113+ }
114+
115+ TEST (FileFormatIO, ReadFileGeometryTypeSPLAT) {
116+ const std::string path =
117+ utility::filesystem::GetTempDirectoryPath () + " /file_type.splat" ;
118+ std::ofstream output (path, std::ios::binary);
119+ ASSERT_TRUE (output.is_open ());
120+ output.write (" " , 0 );
121+ output.close ();
122+
123+ const auto geometry = io::ReadFileGeometryType (path);
124+ EXPECT_TRUE (HasGeometry (geometry, io::CONTAINS_POINTS));
125+ EXPECT_TRUE (HasGeometry (geometry, io::CONTAINS_GAUSSIAN_SPLATS));
126+ }
127+
128+ } // namespace tests
129+ } // namespace open3d
0 commit comments