Skip to content

Commit b22345a

Browse files
takeruProjitB
authored andcommitted
Implement CLI tools for PLY to SPZ conversion and vice versa, along with SPZ file information retrieval.
1 parent bbefb49 commit b22345a

File tree

4 files changed

+112
-0
lines changed

4 files changed

+112
-0
lines changed

CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,20 @@ install(EXPORT spzTargets
7676
NAMESPACE spz::
7777
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/spz"
7878
)
79+
80+
# CLI Tools
81+
add_executable(ply_to_spz cli_tools/src/ply_to_spz.cpp)
82+
target_link_libraries(ply_to_spz PRIVATE spz)
83+
target_include_directories(ply_to_spz PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
84+
85+
add_executable(spz_to_ply cli_tools/src/spz_to_ply.cpp)
86+
target_link_libraries(spz_to_ply PRIVATE spz)
87+
target_include_directories(spz_to_ply PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
88+
89+
add_executable(spz_info cli_tools/src/spz_info.cpp)
90+
target_link_libraries(spz_info PRIVATE spz)
91+
target_include_directories(spz_info PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
92+
93+
install(TARGETS ply_to_spz spz_to_ply spz_info
94+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
95+
)

cli_tools/src/ply_to_spz.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <iostream>
2+
#include "cc/load-spz.h"
3+
4+
int main(int argc, char *argv[]) {
5+
if (argc < 3) {
6+
std::cerr << "Usage: ply_to_spz <input.ply> <output.spz>" << std::endl;
7+
return 1;
8+
}
9+
10+
try {
11+
// Load PLY File
12+
spz::UnpackOptions unpack_options;
13+
spz::GaussianCloud splat = spz::loadSplatFromPly(argv[1], unpack_options);
14+
15+
// Save SPZ File
16+
spz::PackOptions pack_options;
17+
spz::saveSpz(splat, pack_options, argv[2]);
18+
19+
return 0;
20+
} catch (const std::exception& e) {
21+
std::cerr << "Error: " << e.what() << std::endl;
22+
return 1;
23+
}
24+
}

cli_tools/src/spz_info.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <iostream>
2+
#include "cc/load-spz.h"
3+
4+
void printCloudInfo(const spz::GaussianCloud& cloud) {
5+
std::cout << "Number of points: " << cloud.positions.size() / 3 << std::endl;
6+
7+
if (!cloud.positions.empty()) {
8+
float min_x = cloud.positions[0];
9+
float max_x = cloud.positions[0];
10+
float min_y = cloud.positions[1];
11+
float max_y = cloud.positions[1];
12+
float min_z = cloud.positions[2];
13+
float max_z = cloud.positions[2];
14+
15+
for (size_t i = 0; i < cloud.positions.size(); i += 3) {
16+
min_x = std::min(min_x, cloud.positions[i]);
17+
max_x = std::max(max_x, cloud.positions[i]);
18+
min_y = std::min(min_y, cloud.positions[i + 1]);
19+
max_y = std::max(max_y, cloud.positions[i + 1]);
20+
min_z = std::min(min_z, cloud.positions[i + 2]);
21+
max_z = std::max(max_z, cloud.positions[i + 2]);
22+
}
23+
24+
std::cout << "Bounding box:" << std::endl;
25+
std::cout << " X: " << min_x << " to " << max_x << std::endl;
26+
std::cout << " Y: " << min_y << " to " << max_y << std::endl;
27+
std::cout << " Z: " << min_z << " to " << max_z << std::endl;
28+
}
29+
}
30+
31+
int main(int argc, char *argv[]) {
32+
if (argc < 2) {
33+
std::cerr << "Usage: spz_info <input.spz>" << std::endl;
34+
return 1;
35+
}
36+
37+
try {
38+
// Load SPZ File
39+
spz::UnpackOptions unpack_options;
40+
spz::GaussianCloud cloud = spz::loadSpz(argv[1], unpack_options);
41+
printCloudInfo(cloud);
42+
return 0;
43+
} catch (const std::exception& e) {
44+
std::cerr << "Error: " << e.what() << std::endl;
45+
return 1;
46+
}
47+
}

cli_tools/src/spz_to_ply.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <iostream>
2+
#include "cc/load-spz.h"
3+
4+
int main(int argc, char *argv[]) {
5+
if (argc < 3) {
6+
std::cerr << "Usage: spz_to_ply <input.spz> <output.ply>" << std::endl;
7+
return 1;
8+
}
9+
10+
try {
11+
// Load SPZ File
12+
spz::UnpackOptions unpack_options;
13+
spz::GaussianCloud splat = spz::loadSpz(argv[1], unpack_options);
14+
15+
// Save PLY File
16+
spz::PackOptions pack_options;
17+
spz::saveSplatToPly(splat, pack_options, argv[2]);
18+
19+
return 0;
20+
} catch (const std::exception& e) {
21+
std::cerr << "Error: " << e.what() << std::endl;
22+
return 1;
23+
}
24+
}

0 commit comments

Comments
 (0)