15 #include <boost/graph/graph_traits.hpp>
17 #include <CGAL/boost/graph/helpers.h>
56 template<
typename HalfedgeGraph,
63 bool allow_duplicates =
false)
120 template<
typename HalfedgeGraph,
122 typename VertexColorMap,
123 typename EdgeColorMap,
129 VertexColorMap &v_cm,
131 const GeometryTraits >,
142 draco::EncoderBuffer &buffer,
143 const std::string &measure_path,
144 bool preprocess =
true,
145 bool dequantiz =
false,
148 bool save_preprocess =
false,
150 const std::string& output_file_path_save_preprocess =
"",
151 bool allow_duplicates=
false)
154 throw std::runtime_error(
"progressive_compression_filter cannot handle non-pure triangular mesh, exiting (nothing is done).");
196 bool measure =
false;
211 batch(g, pm, EM, predict, v_cm, e_cm, batch_condition);
215 for (
int i = 0; i < nb_max_batches; i++)
217 batch.collapse_batch();
223 bool skip = ((i % 5) != 0);
224 batch.compute_distortion_l2(g_metric, HH, length, skip);
228 if ((nb_vertices_current_last == nb_vertices_current) ||
229 (
static_cast<int>(nb_vertices_current) <= nb_min_vertices))
235 nb_vertices_current_last = nb_vertices_current;
244 auto refinements = batch.get_refinements();
247 Binary_batch_encoder<HalfedgeGraph, PointMap>
250 size_t header_size = 0;
265 std::cout <<
"size coarse mesh: " << size << std::endl;
272 auto dist_RMSE = batch.get_RMSE_distortion();
273 auto dist_hausdorff = batch.get_hausdorff_distortion();
274 int cumulative_bitmask = 0;
275 int cumulative_residuals = 0;
276 int cumulative_connectivity = 0;
277 int cumulative_otherinfo = 0;
279 for (
int i =
static_cast<int>(refinements.size() - 1); i >= 0;
284 if (refinements[i].get_bitmask().size() > 0 &&
285 refinements[i].get_connectivity().size() > 0 &&
286 refinements[i].get_error_prediction().size() > 0)
290 binaryencode.
encode_bitmask(refinements[i].get_bitmask(), buffer);
291 auto data_connectivity =
292 binaryencode.
encode_bitmask(refinements[i].get_connectivity(), buffer);
294 std::pair< int, double > data_other_info = std::make_pair(0, 0.0);
295 size_t size_other_info = 0;
297 if (KP->get_type() == FEVV::Filters::VKEPT_POSITION::HALFEDGE)
300 refinements[i].get_reverse_bool(), buffer);
301 size_other_info = refinements[i].get_reverse_bool().size();
307 cumulative_bitmask += (data_bitmask.first);
308 cumulative_residuals += (data_residuals.first);
309 cumulative_connectivity += (data_connectivity.first);
310 cumulative_otherinfo += (data_other_info.first);
323 refinements[i].get_bitmask().size(),
324 refinements[i].get_connectivity().size(),
334 std::cout <<
"nothing to encode" << std::endl;
380 template<
typename HalfedgeGraph,
382 typename VertexColorMap,
383 typename EdgeColorMap,
388 VertexColorMap &v_cm,
390 const GeometryTraits >,
395 const std::string &output_path,
396 std::string &binary_path,
398 bool preprocess =
true,
401 bool dequantiz =
false,
404 bool save_preprocess =
false,
406 const std::string& output_file_path_save_preprocess =
"")
409 auto time_point_before_comp = std::chrono::high_resolution_clock::now();
427 PointMap> *KP =
nullptr;
430 FEVV::Filters::VKEPT_POSITION::HALFEDGE)
434 std::cout <<
"HALFEDGE" << std::endl;
436 KP =
new FEVV::Filters::
437 Halfedge< HalfedgeGraph, PointMap >(
441 FEVV::Filters::VKEPT_POSITION::MIDPOINT)
445 std::cout <<
"MIDPOINT" << std::endl;
447 KP =
new FEVV::Filters::
448 Midpoint< HalfedgeGraph, PointMap >(
452 throw std::runtime_error(
"progressive_compression_filter cannot handle kept position type.");
456 Error_metric< HalfedgeGraph, PointMap >
459 if (params.
get_metric() == FEVV::Filters::METRIC_TYPE::EDGE_LENGTH)
462 PointMap >(g, pm, KP, dq);
464 std::cout <<
"EDGE_LENGTH" << std::endl;
478 std::cout <<
"VOLUME_PRESERVING" << std::endl;
490 std::cout <<
"QEM_3D" << std::endl;
496 throw std::runtime_error(
"progressive_compression_filter cannot handle metric type.");
501 PointMap > *predict =
nullptr;
505 predict =
new FEVV::Filters::
506 Butterfly< HalfedgeGraph, PointMap >(g, KP, pm);
508 std::cout <<
"BUTTERFLY" << std::endl;
511 else if (params.
get_prediction() == FEVV::Filters::PREDICTION_TYPE::DELTA)
514 PointMap >(g, KP, pm);
516 std::cout <<
"DELTA" << std::endl;
519 else if (params.
get_prediction() == FEVV::Filters::PREDICTION_TYPE::POSITION)
522 PointMap >(g, KP, pm);
524 std::cout <<
"POSITION" << std::endl;
531 throw std::runtime_error(
"progressive_compression_filter cannot handle geometric prediction type.");
534 std::string measure_path =
536 output_path + predict->get_as_string() +
541 if (binary_path ==
"")
543 binary_path = output_path + predict->get_as_string() +
548 draco::EncoderBuffer buffer;
568 output_file_path_save_preprocess,
572 std::ofstream binary_output_file;
574 binary_output_file.open(binary_path, std::fstream::binary | std::ofstream::out | std::ofstream::trunc);
575 binary_output_file.write(buffer.data(), buffer.size());
576 binary_output_file.close();
588 auto time_point_after_comp = std::chrono::high_resolution_clock::now();
589 auto duration_comp = std::chrono::duration_cast<std::chrono::milliseconds>(time_point_after_comp - time_point_before_comp);
590 std::cout <<
"Compression time: " << duration_comp.count() <<
" milliseconds" << std::endl;
633 template<
typename HalfedgeGraph,
635 typename VertexColorMap,
636 typename EdgeColorMap,
641 VertexColorMap &v_cm,
644 const std::string &output_path,
645 std::string &binary_path,
649 bool preprocess =
true,
650 bool dequantiz =
false,
651 bool save_preprocess =
false,
652 const std::string& output_file_path_save_preprocess =
"")
655 GeometryTraits gt(g);
670 output_file_path_save_preprocess);