|
|
@@ -1,6 +1,7 @@
|
|
|
#include "image_saver_impl.h"
|
|
|
#include "core/image_utility.hpp"
|
|
|
#include "core/imgui_utility.hpp"
|
|
|
+#include "core/pc_utility.h"
|
|
|
|
|
|
#include <opencv2/imgcodecs.hpp>
|
|
|
#include <opencv2/imgproc.hpp>
|
|
|
@@ -13,6 +14,36 @@
|
|
|
|
|
|
using boost::asio::post;
|
|
|
|
|
|
+void image_saver::impl::item_store_type::save_ply() {
|
|
|
+ auto file_name = fmt::format("{}_{}.ply", ui_name, par->save_cnt);
|
|
|
+ auto pc = OBJ_QUERY(pc_ptr, img_name);
|
|
|
+ assert(pc->format() == PC_XYZ_RGB);
|
|
|
+
|
|
|
+ auto size = pc->size();
|
|
|
+ FILE *fp = fopen(file_name.c_str(), "wb+"); // TODO: move save function to pc_utility
|
|
|
+ fprintf(fp, "ply\n");
|
|
|
+ fprintf(fp, "format ascii 1.0\n");
|
|
|
+ fprintf(fp, "element vertex %ld\n", size);
|
|
|
+ fprintf(fp, "property float x\n");
|
|
|
+ fprintf(fp, "property float y\n");
|
|
|
+ fprintf(fp, "property float z\n");
|
|
|
+ fprintf(fp, "property uchar red\n");
|
|
|
+ fprintf(fp, "property uchar green\n");
|
|
|
+ fprintf(fp, "property uchar blue\n");
|
|
|
+ fprintf(fp, "end_header\n");
|
|
|
+
|
|
|
+ auto pc_mem = pc->memory(MEM_HOST, &par->stream);
|
|
|
+ auto ptr = (pc_xyz_rgb_type *) pc_mem.start_ptr();
|
|
|
+ for (int i = 0; i < size; i++) {
|
|
|
+ fprintf(fp, "%.3f %.3f %.3f %d %d %d\n",
|
|
|
+ ptr->x, ptr->y, ptr->z, ptr->r, ptr->g, ptr->b);
|
|
|
+ ptr++;
|
|
|
+ }
|
|
|
+
|
|
|
+ fflush(fp);
|
|
|
+ fclose(fp);
|
|
|
+}
|
|
|
+
|
|
|
void image_saver::impl::item_store_type::save_png() {
|
|
|
auto file_name = fmt::format("{}_{}.png", ui_name, par->save_cnt);
|
|
|
auto img_mat = image_as_mat(img_name, &par->stream);
|
|
|
@@ -33,6 +64,7 @@ void image_saver::impl::item_store_type::process() { // TODO: move save work to
|
|
|
case SAVE_PNG: { save_png(); break; }
|
|
|
// case SAVE_JPG: { save_jpg(); break; }
|
|
|
// case SAVE_RAW: { save_raw(); break; }
|
|
|
+ case SAVE_PLY: { save_ply(); break; }
|
|
|
// @formatter:on
|
|
|
}
|
|
|
}
|
|
|
@@ -42,9 +74,13 @@ image_saver::impl::impl(const create_config &conf) {
|
|
|
std::ranges::transform(
|
|
|
conf.img_list, std::back_inserter(item_list),
|
|
|
[par = this](auto item) {
|
|
|
+ auto is_point_cloud =
|
|
|
+ OBJ_TYPE(item.img_name) == typeid(pc_ptr);
|
|
|
return item_store_type{
|
|
|
.ui_name = item.name,
|
|
|
.img_name = item.img_name,
|
|
|
+ .data_type = is_point_cloud ? DATA_PC : DATA_IMG,
|
|
|
+ .save_type = is_point_cloud ? SAVE_PLY : SAVE_PNG,
|
|
|
.par = par};
|
|
|
});
|
|
|
}
|
|
|
@@ -77,13 +113,18 @@ void image_saver::impl::show() {
|
|
|
|
|
|
// save type
|
|
|
ImGui::SameLine();
|
|
|
- ImGui::RadioButton("PNG", &item.save_type, SAVE_PNG);
|
|
|
|
|
|
- auto guard = imgui_disable_guard(); // not implemented
|
|
|
- ImGui::SameLine();
|
|
|
- ImGui::RadioButton("JPG", &item.save_type, SAVE_JPG);
|
|
|
- ImGui::SameLine();
|
|
|
- ImGui::RadioButton("RAW", &item.save_type, SAVE_RAW);
|
|
|
+ if (item.data_type == DATA_IMG) {
|
|
|
+ ImGui::RadioButton("PNG", &item.save_type, SAVE_PNG);
|
|
|
+ auto guard = imgui_disable_guard(); // not implemented
|
|
|
+ ImGui::SameLine();
|
|
|
+ ImGui::RadioButton("JPG", &item.save_type, SAVE_JPG);
|
|
|
+ ImGui::SameLine();
|
|
|
+ ImGui::RadioButton("RAW", &item.save_type, SAVE_RAW);
|
|
|
+ } else {
|
|
|
+ assert(item.data_type == DATA_PC);
|
|
|
+ ImGui::RadioButton("PLY", &item.save_type, SAVE_PLY);
|
|
|
+ }
|
|
|
|
|
|
ImGui::TreePop();
|
|
|
}
|