MEPP2 Project
progressive_decompression_filter.hpp
Go to the documentation of this file.
1 // Copyright (c) 2012-2022 University of Lyon and CNRS (France).
2 // All rights reserved.
3 //
4 // This file is part of MEPP2; you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as
6 // published by the Free Software Foundation; either version 3 of
7 // the License, or (at your option) any later version.
8 //
9 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
10 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11 
12 #pragma once
13 
15 #include <boost/graph/graph_traits.hpp>
17 
27 
31 
32 //#define TIMING
33 #ifdef TIMING
34 #include <chrono>
35 #endif
36 
37 namespace FEVV {
38 namespace Filters {
39 
62 template< typename HalfedgeGraph,
63  typename PointMap,
64  typename VertexColorMap,
65  typename GeometryTraits >
66 void
68  PointMap& pm,
69  VertexColorMap& v_cm,
70  const GeometryTraits&/*gt*/,
71  draco::DecoderBuffer& buffer,
72  bool dequantize = true,
73  unsigned int nb_max_batches = 10000)
74 {
76  // DECODE FILE HEADER //
78  // Retrieve decompression info (predictor, kept position, quantization
79  // settings)
81  HH.decode_binary_header(buffer);
82 
83  // Retrieve the base mesh
85  HalfedgeGraph, PointMap >
86  coarse(g, pm);
87  coarse.decode_coarse_mesh(buffer);
88 
89  // Create predictor and kept position objects according to header info
93  HalfedgeGraph,
94  PointMap>* KP = nullptr;
96  HalfedgeGraph,
97  PointMap>* predictor = nullptr;
98 
99 
100  if(_vkept == FEVV::Filters::VKEPT_POSITION::HALFEDGE)
101  {
102  KP = new FEVV::Filters::Halfedge<
103  HalfedgeGraph,
104  PointMap >(g, pm);
105  }
106  else if(_vkept == FEVV::Filters::VKEPT_POSITION::MIDPOINT)
107  {
108  KP = new FEVV::Filters::Midpoint<
109  HalfedgeGraph,
110  PointMap >(g, pm);
111  }
112  else
113  throw std::runtime_error("progressive_decompression_filter cannot handle kept position type.");
114 
115 
117  {
118  std::cout << "butterfly" << std::endl;
119  predictor = new FEVV::Filters::Butterfly<
120  HalfedgeGraph,
121  PointMap>(g, KP, pm);
122  }
123  else if(_pred == FEVV::Filters::PREDICTION_TYPE::DELTA)
124  {
125  std::cout << "delta" << std::endl;
126  predictor = new FEVV::Filters::Delta_predictor<
127  HalfedgeGraph,
128  PointMap>(g, KP, pm);
129  }
130  else if(_pred == FEVV::Filters::PREDICTION_TYPE::POSITION)
131  {
132  std::cout << "position" << std::endl;
133  predictor = new FEVV::Filters::Raw_positions< HalfedgeGraph,
134  PointMap >(g, KP, pm);
135  }
136  else
137  {
138  delete KP;
139  throw std::runtime_error("progressive_decompression_filter cannot handle geometric prediction type.");
140  }
141 
143  // DECODE REFINEMENT BATCHES //
145  // Create a batch decompressor object to decode the refinement information
146  // of the following LoDs and update consequently the halfedge graph g and
147  // its point map pm.
149  HalfedgeGraph,
150  PointMap,
151  VertexColorMap>
152  _batch(g,
153  pm,
154  predictor,
155  KP,
156  HH,
157  v_cm);
158 
159  // Refine mesh until the buffer is fully decoded
160  // Implements the while loop of Algorithm 2.
161  unsigned int nb = 0;
162  while((buffer.remaining_size() != 0) && (nb < nb_max_batches))
163  {
164  _batch.decompress_binary_batch(buffer);
165  ++nb;
166  }
167  if(dequantize) // if we want, dequantize attributes (it is useful to not
168  { // dequantize for tests)
169  // These lines implement line 21 of Algorithm 2.
171  g, pm, HH.get_quantization(), HH.get_dimension(), HH.get_init_coord());
173  }
174  }
175 
197 template< typename HalfedgeGraph,
198  typename PointMap,
199  typename VertexColorMap,
200  typename GeometryTraits >
201 void
203  PointMap &pm,
204  VertexColorMap &v_cm,
205  const GeometryTraits & gt,
206  const std::string &input_file_path,
207  bool dequantize = true,
208  unsigned int nb_max_batches = 10000)
209 {
210 #ifdef TIMING
211  auto time_point_before_decomp = std::chrono::high_resolution_clock::now();
212 #endif
213  std::fstream filebin;
214  filebin.open(input_file_path, std::fstream::in | std::fstream::binary);
215  draco::DecoderBuffer buffer;
216  buffer.set_bitstream_version(DRACO_BITSTREAM_VERSION(2, 2));
217 
218  std::vector< char > data;
219  char b;
220  // Open file, load binary data.
221  while(filebin.get(b))
222  {
223  data.push_back(b);
224  }
225  filebin.close();
226 
227  // Init draco buffer with the content of the binary file.
228  buffer.Init(data.data(), data.size());
229 
230  progressive_decompression_filter(g, pm, v_cm, gt, buffer, dequantize, nb_max_batches);
231 
232 #ifdef TIMING
233  auto time_point_after_decomp = std::chrono::high_resolution_clock::now();
234  auto duration_decomp = std::chrono::duration_cast<std::chrono::milliseconds>(time_point_after_decomp - time_point_before_decomp);
235  std::cout << "Decompression time: " << duration_decomp.count() << " milliseconds" << std::endl;
236 #endif
237 }
238 
258 template< typename HalfedgeGraph,
259  typename PointMap,
260  typename VertexColorMap,
261  typename GeometryTraits = FEVV::Geometry_traits< HalfedgeGraph > >
262 void
264  PointMap &pm,
265  VertexColorMap &v_cm,
266  const std::string &input_file_path,
267  bool dequantize = true,
268  unsigned int nb_max_batches = 10000)
269 
270 {
271  GeometryTraits gt(g);
272  progressive_decompression_filter< HalfedgeGraph,
273  PointMap,
274  VertexColorMap,
275  GeometryTraits>(
276  g, pm, v_cm, gt, input_file_path, dequantize, nb_max_batches);
277 }
278 
279 } // namespace Filters
280 } // namespace FEVV
FEVV::Header_handler::get_pred
FEVV::Filters::PREDICTION_TYPE get_pred() const
Definition: Header_handler.h:158
FEVV::Header_handler::get_init_coord
const std::vector< double > & get_init_coord() const
Definition: Header_handler.h:161
Delta_predictor.h
Uniform_quantization.h
Parameters.h
Volume_preserving.h
FEVV::Filters::Butterfly
Definition: Butterfly.h:28
FEVV::Header_handler::get_quantization
int get_quantization() const
Definition: Header_handler.h:159
FEVV::Filters::Raw_positions
Definition: Raw_positions.h:25
FEVV::Filters::PREDICTION_TYPE
PREDICTION_TYPE
Definition: Parameters.h:19
FEVV::Header_handler::get_dimension
const std::vector< double > & get_dimension() const
Definition: Header_handler.h:160
FEVV::Geometry_traits< HalfedgeGraph >
Uniform_dequantization.h
Binary_batch_decoder.h
FEVV::Filters::Uniform_dequantization::point_dequantization
void point_dequantization()
Dequantizes all vertex positions stored in the point map.
Definition: Uniform_dequantization.h:111
FEVV::Filters::Predictor
Abstract class used to predict position.
Definition: Predictor.h:35
FEVV::Filters::Halfedge
Concrete class to represent the target position type of the resulting vertex of an edge collapse.
Definition: Halfedge.h:28
FEVV::Header_handler::get_vkept
FEVV::Filters::VKEPT_POSITION get_vkept() const
Definition: Header_handler.h:157
FEVV::Filters::Kept_position
Abstract class to represent the position type of the resulting vertex of an edge collapse.
Definition: Kept_position.h:31
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
Butterfly.h
Geometry_traits.h
FEVV::Filters::VKEPT_POSITION
VKEPT_POSITION
Definition: Parameters.h:28
FEVV::Header_handler::decode_binary_header
void decode_binary_header(draco::DecoderBuffer &buffer)
Definition: Header_handler.h:133
Edge_length_metric.h
FEVV::Filters::Delta_predictor
Definition: Delta_predictor.h:27
FEVV::Filters::Coarse_mesh_decoder
Definition: Coarse_mesh_decoder.h:44
FEVV::Filters::Uniform_dequantization< HalfedgeGraph, PointMap >
FEVV::Filters::Batch_decompressor
Batch_decompressor: Given a draco buffer, will decompress a non-textured (or not) mesh.
Definition: Batch_decompressor.h:78
FEVV::Filters::Midpoint
Concrete class to represent the midpoint position type of the resulting vertex of an edge collapse.
Definition: Midpoint.h:28
QEM_3D.h
FEVV::Header_handler
Definition: Header_handler.h:35
Batch_decompressor.h
FEVV::Filters::progressive_decompression_filter
void progressive_decompression_filter(HalfedgeGraph &g, PointMap &pm, VertexColorMap &v_cm, const GeometryTraits &, draco::DecoderBuffer &buffer, bool dequantize=true, unsigned int nb_max_batches=10000)
Takes a buffer as an input, will decode the compression settings, the coarse mesh and refine the mesh...
Definition: progressive_decompression_filter.hpp:67
properties.h
Raw_positions.h
Header_handler.h
FEVV::Filters::PREDICTION_TYPE::POSITION
@ POSITION