FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
OpenSplat/ply.cpp at OpenSplatLibrary · NewChromantics/OpenSplat · GitHub
NewChromantics
/
OpenSplat
Public
forked from
WebODM/OpenSplat
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
OpenSplat
/
ply.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
92 lines (72 loc) · 2.34 KB
Breadcrumbs
OpenSplat
/
ply.cpp
Copy path
File metadata and controls
92 lines (72 loc) · 2.34 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#
include
"
ply.hpp
"
#
include
<
fstream
>
void
Ply::Write
(std::ostream& Output,WriteParams Params,std::function<SplatElement(
int
)> GetSplatByIndex)
{
//
if input is a file, check it's open
{
auto
* OutputFile =
dynamic_cast
<std::ofstream*>(&Output);
if
( OutputFile )
{
if
( !OutputFile->
is_open
() )
throw
std::runtime_error
(
"
Ply::Write with stream that's not open
"
);
}
}
auto
& o = Output;
//
grab first element to get dc/rest feature count
SplatElement FirstElement = Params.
PointCount
>
0
?
GetSplatByIndex
(
0
) : SplatElement{};
//
todo: sanitise Comment to remove line feeds
o <<
"
ply
"
<< std::endl;
o <<
"
format binary_little_endian 1.0
"
<< std::endl;
o <<
"
comment
"
<< Params.
Comment
<< std::endl;
o <<
"
element vertex
"
<< Params.
PointCount
<< std::endl;
o <<
"
property float x
"
<< std::endl;
o <<
"
property float y
"
<< std::endl;
o <<
"
property float z
"
<< std::endl;
if
( Params.
WriteNormals
)
{
o <<
"
property float nx
"
<< std::endl;
o <<
"
property float ny
"
<< std::endl;
o <<
"
property float nz
"
<< std::endl;
}
for
(
int
i=
0
; i<FirstElement.
FeatureDcs
().
size
(); i++)
{
o <<
"
property float f_dc_
"
<< i << std::endl;
}
//
Match Inria's version
for
(
int
i =
0
; i <FirstElement.
FeatureRests
.
size
(); i++)
{
o <<
"
property float f_rest_
"
<< i << std::endl;
}
o <<
"
property float opacity
"
<< std::endl;
o <<
"
property float scale_0
"
<< std::endl;
o <<
"
property float scale_1
"
<< std::endl;
o <<
"
property float scale_2
"
<< std::endl;
o <<
"
property float rot_0
"
<< std::endl;
o <<
"
property float rot_1
"
<< std::endl;
o <<
"
property float rot_2
"
<< std::endl;
o <<
"
property float rot_3
"
<< std::endl;
o <<
"
end_header
"
<< std::endl;
auto
Write = [&o](std::span<
float
> Values)
{
auto
* Bytes =
reinterpret_cast
<
const
char
*>(Values.
data
());
o.
write
( Bytes, Values.
size_bytes
() );
};
for
(
int
p=
0
; p<Params.
PointCount
; p++ )
{
auto
Element =
GetSplatByIndex
(p);
//
remember to strictly match header order!
Write
( Element.
Position3
() );
if
( Params.
WriteNormals
)
{
Write
( Element.
Normal3
() );
}
Write
( Element.
FeatureDcs
() );
Write
( Element.
FeatureRests
);
Write
( Element.
Opacity
() );
Write
( Element.
Scale3
() );
//
note this order is supposed to be WXYZ not XYZW in splat viewers
Write
( Element.
QuaternionWXYZ
() );
}
//
leave this to caller
//
o.close();
}
Back
|
FazBrowse Home
|
New Git URL