MEPP2 Project
progressivecompression_plugin.h
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 General Public License as published
6 // by the Free Software Foundation; either version 3 of the License,
7 // 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 #pragma once
12 
13 #if(_MSC_VER >= 1400)
14 #ifndef _SCL_SECURE_NO_WARNINGS
15 #define _SCL_SECURE_NO_WARNINGS
16 #endif
17 #endif
18 
20 
21 #include <QStringList>
23 
24 #ifndef Q_MOC_RUN // MT : very important to avoid the error : ' Parse error at
25  // "BOOST_JOIN" ' -> (qt4 pb with boost)
28 
30 
31 // A) include the header of the filter corresponding to your operation
34 
35 #ifdef FEVV_USE_CGAL
39 #endif // FEVV_USE_CGAL
40 #if FEVV_USE_OPENMESH
42 #endif // FEVV_USE_OPENMESH
43 #if FEVV_USE_AIF
45 #endif // FEVV_USE_AIF
46 #endif
47 
48 namespace FEVV {
49 
50  template< typename MeshT >
51 void
53  MeshT &m,
54  FEVV::PMapsContainer &pmaps_bag,
58 
60 
61 {
62  // Note: the property maps must be extracted from the
63  // property maps bag, and explicitely passed as
64  // parameters to the filter, in order to make
65  // clear what property is used by the filter
66 
67  // retrieve or create vertex-color property map
68  if(has_map(pmaps_bag, FEVV::vertex_color))
69  {
70  std::cout << "use existing vertex-color map" << std::endl;
71  v_cm = get_property_map(FEVV::vertex_color, m, pmaps_bag);
72  }
73  else
74  {
75  std::cout << "create vertex-color map" << std::endl;
77  // store property map in property maps bag
78  put_property_map(FEVV::vertex_color, m, pmaps_bag, v_cm);
79  }
80  if(has_map(pmaps_bag, FEVV::edge_color))
81  {
82  std::cout << "using edge color property map" << std::endl;
83  e_cm = get_property_map(FEVV::edge_color, m, pmaps_bag);
84  // e_cm_ptr = &e_cm;
85  }
86  else
87  {
88  std::cout << "create vertex-color map" << std::endl;
90  // store property map in property maps bag
91  put_property_map(FEVV::edge_color, m, pmaps_bag, e_cm);
92  }
93  // retrieve or create vertex-normal property map
94 
95  if(has_map(pmaps_bag, FEVV::vertex_normal))
96  {
97  std::cout << "use existing vertex-normal map" << std::endl;
98  v_nm = get_property_map(FEVV::vertex_normal, m, pmaps_bag);
99  }
100  else
101  {
102  std::cout << "create vertex-normal map" << std::endl;
104  // store property map in property maps bag
105  put_property_map(FEVV::vertex_normal, m, pmaps_bag, v_nm);
106  }
107 }
108 class ProgressiveCompressionPlugin : public QObject,
110  public BasePluginQt
111 {
112  Q_OBJECT
113  Q_INTERFACES(FEVV::Generic_PluginInterface)
114 #if(FEVV_USE_QT5) // see at the end of .cpp for QT4
115  Q_PLUGIN_METADATA(IID "ProgressiveCompressionPlugin")
116 #endif
117 
118  /*public:
119  using BasePlugin::apply;*/
120 public:
123 
124 public:
125  void init() override {}
126 
127  void reset() override
128  {
129  init();
130 
131  emit resetSignal();
132  }
133 
134  void addParameters(BaseWindow *_window) override
135  {
136  window = _window;
137  if(window == nullptr || !window->isInit())
138  {
139  std::cerr << "BaseWindow is null or not initialized." << std::endl;
140  return;
141  }
142  }
143 
144  template< typename HalfedgeGraph >
145  void process(HalfedgeGraph *_mesh, FEVV::PMapsContainer *pmaps_bag)
146  {
147  std::cout << "Asking to ProgressiveCompression mesh ! " << std::endl;
148 
149  // retrieve or create vertex-color property map
150  using VertexColorMap =
152  HalfedgeGraph >::pmap_type;
153  VertexColorMap v_cm;
154 
155  // retrieve or create vertex-normal property map
156  using VertexNormalMap =
158  HalfedgeGraph >::pmap_type;
159  VertexNormalMap v_nm;
160 
164  *pmaps_bag,
165 
166  v_cm,
167  e_cm,
168  f_nm,
169  v_nm);
170 
171 
172  typename FEVV::Geometry_traits< HalfedgeGraph > gt(*_mesh); // retrieve point property map (aka
173  // geometry)
174  auto pm = get(boost::vertex_point, *_mesh);
175 
176  // apply filter
177  // B) call the filter corresponding to your operation
179  std::string filepath = ""; // output_path
180 
181  std::string result;
182  try {
184  pm,
185  v_cm,
186  e_cm,
187  //v_nm,
188  gt,
189  params,
190  _nb_batches,
192  _batch_stop,
193  filepath,
194  _filepath,
195  true,
196  true,
197  false,
198  "progressive_compression_original_mesh_after_preprocess_plugin.off");
199  }
200  catch (std::exception& e) {
201  result = e.what();
202  }
203 
204  // existing property maps are no more valid due to topological changes
205  // purge the property maps bag
206  FEVV::PMapsContainer clean_pmaps_bag;
207  *pmaps_bag = clean_pmaps_bag;
208 
209  std::string message("Progressive compression completed.\n\n");
210  message.append(result);
211  QMessageBox::information(0, "", QString::fromStdString(message));
212  }
213 
214  template< typename HalfedgeGraph >
215  void applyHG(BaseAdapterVisu *_adapter,
216  HalfedgeGraph *_mesh,
217  FEVV::PMapsContainer *pmaps_bag)
218  {
219  // get filter parameters from dialog window
221  std::string pred = "";
222  std::string metr = "";
223  std::string vkept = "";
224  std::string filepath = "";
225  std::string batch_string = "";
226  if(dialog.exec() == QDialog::Accepted)
227  dialog.getParameters(_quantization, _nb_batches, _minimum_vertices, metr, vkept, pred, filepath, batch_string);
228  else
229  return; // abort applying filter
230 
231  _filepath = filepath;
233  _batch_stop = FEVV::Filters::BATCH_CONDITION::ALL_EDGES;
234 
235  if(pred.compare("Butterfly") == 0)
236  {
238  }
239  else if(pred.compare("Delta") == 0)
240  {
241  _predictor = FEVV::Filters::PREDICTION_TYPE::DELTA;
242  }
243  else if (pred.compare("Position") == 0)
244  {
245  _predictor = FEVV::Filters::PREDICTION_TYPE::POSITION;
246  }
247 
249  if(metr.compare("QEM") == 0)
250  {
252  }
253  else if(metr.compare("Volume Preserving") == 0)
254  {
256  }
257  else if(metr.compare("EdgeLength") == 0)
258  {
259  _metric = FEVV::Filters::METRIC_TYPE::EDGE_LENGTH;
260  }
261 
262  if(batch_string.compare("All Edges") == 0)
263  {
264  _batch_stop = FEVV::Filters::BATCH_CONDITION::ALL_EDGES;
265  }
266  else if(batch_string.compare("Reach Threshold") == 0)
267  {
269  }
270 
271  _operator = FEVV::Filters::VKEPT_POSITION::MIDPOINT;
272  if(vkept.compare("MidPoint") == 0)
273  {
274  _operator = FEVV::Filters::VKEPT_POSITION::MIDPOINT;
275  }
276  else if(vkept.compare("Halfedge") == 0)
277  {
278  _operator = FEVV::Filters::VKEPT_POSITION::HALFEDGE;
279  }
280  //else if (vkept.compare("Fulledge") == 0)
281  //{
282  // _operator = FEVV::Filters::VKEPT_POSITION::FULLEDGE;
283  //}
284 
285  // apply filter
286  process(_mesh, pmaps_bag);
287 
288  SimpleViewer *viewer =
289  dynamic_cast< SimpleViewer * >(_adapter->getViewer());
290  if(viewer)
291  viewer->draw_or_redraw_mesh(_mesh, pmaps_bag, true, false);
292 
293  // comment next line to keep parameters values between calls
294  reset();
295 
296 #if(FEVV_USE_QT5)
297  // empty
298 #else
299  viewer->frame(); // necessary or not ?
300 #endif
301  }
302 
303 #ifdef FEVV_USE_OPENMESH
304 #if 0 // Works with CGAL AABB, no solution available for OpenMesh yet
305  void apply(BaseAdapterVisu *_adapter,
306  MeshOpenMesh *_mesh,
307  FEVV::PMapsContainer *pmaps_bag) override
308  {
309  applyHG< MeshOpenMesh >(_adapter, _mesh, pmaps_bag);
310  }
311 #endif
312 #endif
313 
314 #ifdef FEVV_USE_CGAL
315 #if 1
316  void apply(BaseAdapterVisu *_adapter,
317  MeshLCC *_mesh,
318  FEVV::PMapsContainer *pmaps_bag) override
319  {
320  applyHG< MeshLCC >(_adapter, _mesh, pmaps_bag);
321  }
322 #endif
323  void apply(BaseAdapterVisu *_adapter,
324  MeshSurface *_mesh,
325  FEVV::PMapsContainer *pmaps_bag) override
326  {
327  applyHG< MeshSurface >(_adapter, _mesh, pmaps_bag);
328  }
329 
330  void apply(BaseAdapterVisu *_adapter,
331  MeshPolyhedron *_mesh,
332  FEVV::PMapsContainer *pmaps_bag) override
333  {
334  applyHG< MeshPolyhedron >(_adapter, _mesh, pmaps_bag);
335  }
336 #endif
337 
338 #ifdef FEVV_USE_AIF
339 #if 0 // halfedge iteration is not compatible with AIF yet (halfedge_iterator type cannot be exported)
340  // Works with CGAL AABB, no solution available for AIF yet
341  void apply(BaseAdapterVisu *_adapter,
342  MeshAIF *_mesh,
343  FEVV::PMapsContainer *pmaps_bag) override
344  {
345  applyHG< MeshAIF >(_adapter, _mesh, pmaps_bag);
346  }
347 #endif
348 #endif
349 
350  QStringList Generic_plugins() const override
351  {
352  return QStringList() << "ProgressiveCompressionPlugin";
353  }
354 
355  bool Generic_plugin(const QString &/*plugin*/) override
356  {
357  SimpleWindow *sw = static_cast< SimpleWindow * >(window);
358  // dynamic_cast fails under OS X
359  sw->onModificationParam("progressivecompression_qt_p", this);
360  //TODO-elo-refactor-plugins
361  // 1) the name of the function onModificationParam()
362  // is unrelated to its content!!!
363  // 2) Generic_plugin() is called by SimpleWindow
364  // and calls back SimpleWindow functions here ;
365  // looks like a bad architecture
366  sw->onApplyButton();
367 
368  return true;
369  }
370 
371 signals:
372  void resetSignal();
373 
374 protected:
375  // filter parameters
380  std::string _filepath;
384 };
385 
386 } // namespace FEVV
387 
FEVV::BaseWindow::isInit
virtual bool isInit() const
Definition: BaseWindow.h:103
FEVV::ProgressiveCompressionPlugin::_predictor
Filters::PREDICTION_TYPE _predictor
Definition: progressivecompression_plugin.h:376
FEVV::put_property_map
void put_property_map(PropertyT p, const MeshT &, PMapsContainer &pmaps, const typename PMap_traits< PropertyT, MeshT >::pmap_type &pmap)
Definition: properties.h:664
FEVV::ProgressiveCompressionPlugin::ProgressiveCompressionPlugin
ProgressiveCompressionPlugin()=default
FEVV::get_property_map
PMap_traits< PropertyT, MeshT >::pmap_type get_property_map(PropertyT p, const MeshT &, const PMapsContainer &pmaps)
Definition: properties.h:646
FEVV::ProgressiveCompressionPlugin::_filepath
std::string _filepath
Definition: progressivecompression_plugin.h:380
FEVV::SimpleWindow::onApplyButton
void onApplyButton()
Definition: SimpleWindow.inl:525
FEVV::ProgressiveCompressionPlugin::_metric
Filters::METRIC_TYPE _metric
Definition: progressivecompression_plugin.h:377
FEVV::MeshLCC
CGAL::Linear_cell_complex_for_combinatorial_map< 2, 3, CGALLCCTraits, CGALItem > MeshLCC
Definition: DataStructures_cgal_linear_cell_complex.h:43
FEVV::has_map
bool has_map(const PMapsContainer &pmaps, const std::string &map_name)
(refer to Property Maps API)
Definition: properties.h:103
FEVV::BasePluginQt
This class is intended to provide some standard message boxes to all plugins.
Definition: BasePluginQt.h:30
FEVV::Filters::PREDICTION_TYPE
PREDICTION_TYPE
Definition: Parameters.h:19
FEVV::ProgressiveCompressionPlugin::_batch_stop
Filters::BATCH_CONDITION _batch_stop
Definition: progressivecompression_plugin.h:379
SimpleWindow.h
FEVV::ProgressiveCompressionPlugin::_operator
Filters::VKEPT_POSITION _operator
Definition: progressivecompression_plugin.h:378
FEVV::Filters::METRIC_TYPE
METRIC_TYPE
Definition: Parameters.h:33
FEVV::BaseAdapterVisu::getViewer
virtual Viewer * getViewer()
Definition: BaseAdapterVisu.h:130
FEVV::ProgressiveCompressionPlugin::process
void process(HalfedgeGraph *_mesh, FEVV::PMapsContainer *pmaps_bag)
Definition: progressivecompression_plugin.h:145
properties_linear_cell_complex.h
FEVV::ProgressiveCompressionPlugin::reset
void reset() override
Definition: progressivecompression_plugin.h:127
FEVV::Geometry_traits< HalfedgeGraph >
FEVV::ProgressiveCompressionPlugin
Definition: progressivecompression_plugin.h:111
FEVV::MeshSurface
CGAL::Surface_mesh< CGALPoint > MeshSurface
Definition: DataStructures_cgal_surface_mesh.h:23
FEVV::BaseAdapterVisu
Definition: BaseAdapterVisu.h:27
properties_aif.h
FEVV::ProgressiveCompressionPlugin::resetSignal
void resetSignal()
FEVV::SimpleWindow
SimpleWindow is a specialization of QMainWindow. This class the Main Window.
Definition: SimpleWindow.h:80
FEVV::PMapsContainer
std::map< std::string, boost::any > PMapsContainer
Definition: properties.h:99
FEVV::SimpleViewer::draw_or_redraw_mesh
void draw_or_redraw_mesh(HalfedgeGraph *_g, PMapsContainer *_pmaps, bool _redraw=false, bool _recomputeNT_if_redraw=false, std::string _mesh_filename=std::string(""), bool _recreateOSGobj_if_redraw=true, float _step=0.)
Definition: SimpleViewer.inl:3415
FEVV::vertex_normal_t
vertex_normal_t
Definition: properties.h:35
progressivecompression_dialog.h
FEVV::get
FEVV::PCLPointCloudPointMap::value_type get(const FEVV::PCLPointCloudPointMap &pm, FEVV::PCLPointCloudPointMap::key_type key)
Specialization of get(point_map, key) for PCLPointCloud.
Definition: Graph_properties_pcl_point_cloud.h:117
FEVV::SimpleViewer
SimpleViewer is a specialization of osgViewer::CompositeViewer. This class is a widget where we are a...
Definition: SimpleViewer.h:180
properties_polyhedron_3.h
FEVV::ProgressiveCompressionPlugin::~ProgressiveCompressionPlugin
~ProgressiveCompressionPlugin()=default
FEVV::vertex_color_t
vertex_color_t
Definition: properties.h:47
FEVV::SimpleWindow::onModificationParam
void onModificationParam(std::string _pluginName, BasePlugin *_plugin)
Definition: SimpleWindow.inl:505
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
FEVV::ProgressiveCompressionPlugin::_quantization
int _quantization
Definition: progressivecompression_plugin.h:382
FEVV::ProgressiveCompressionDialog::getParameters
void getParameters(int &quantiz, int &nb_batches, int &min_vertices, std::string &metric, std::string &vkept, std::string &predictor, std::string &filepath, std::string &batchstop)
Definition: progressivecompression_dialog.cpp:27
FEVV::Filters::METRIC_TYPE::NO_METRIC
@ NO_METRIC
properties_surface_mesh.h
FEVV::edge_color
@ edge_color
Definition: properties.h:73
FEVV::Filters::BATCH_CONDITION::ALL_EDGES
@ ALL_EDGES
FEVV::vertex_color
@ vertex_color
Definition: properties.h:47
FEVV::set_mesh_and_properties
void set_mesh_and_properties(MeshT &m, FEVV::PMapsContainer &pmaps_bag, typename FEVV::PMap_traits< FEVV::vertex_color_t, MeshT >::pmap_type &v_cm, typename FEVV::PMap_traits< FEVV::edge_color_t, MeshT >::pmap_type &e_cm, typename FEVV::PMap_traits< FEVV::face_normal_t, MeshT >::pmap_type &, typename FEVV::PMap_traits< FEVV::vertex_normal_t, MeshT >::pmap_type &v_nm)
Definition: progressivecompression_plugin.h:52
FEVV::ProgressiveCompressionPlugin::init
void init() override
Definition: progressivecompression_plugin.h:125
FEVV::ProgressiveCompressionPlugin::applyHG
void applyHG(BaseAdapterVisu *_adapter, HalfedgeGraph *_mesh, FEVV::PMapsContainer *pmaps_bag)
Definition: progressivecompression_plugin.h:215
SimpleViewer.h
FEVV::Filters::VKEPT_POSITION
VKEPT_POSITION
Definition: Parameters.h:28
FEVV::ProgressiveCompressionPlugin::_minimum_vertices
int _minimum_vertices
Definition: progressivecompression_plugin.h:383
FEVV::ProgressiveCompressionDialog
Definition: progressivecompression_dialog.h:23
FEVV::ProgressiveCompressionPlugin::Generic_plugin
bool Generic_plugin(const QString &) override
Definition: progressivecompression_plugin.h:355
BasePluginQt.h
properties_openmesh.h
FEVV::MeshOpenMesh
OpenMesh::PolyMesh_ArrayKernelT< MyTraits > MeshOpenMesh
Definition: DataStructures_openmesh.h:51
FEVV::ProgressiveCompressionPlugin::_nb_batches
int _nb_batches
Definition: progressivecompression_plugin.h:381
FEVV::Filters::progressive_compression_filter
void progressive_compression_filter(HalfedgeGraph &g, PointMap &pm, FEVV::Filters::Uniform_quantization< HalfedgeGraph, PointMap > &pq, VertexColorMap &v_cm, EdgeColorMap &e_cm, const GeometryTraits &gt, FEVV::Filters::Error_metric< HalfedgeGraph, PointMap > *EM, const FEVV::Filters::Kept_position< HalfedgeGraph, PointMap > *KP, FEVV::Filters::Predictor< HalfedgeGraph, PointMap > *predict, int nb_q_bits, int nb_max_batches, int nb_min_vertices, FEVV::Filters::BATCH_CONDITION batch_condition, draco::EncoderBuffer &buffer, const std::string &measure_path, bool preprocess=true, bool dequantiz=false, bool save_preprocess=false, const std::string &output_file_path_save_preprocess="", bool allow_duplicates=false)
Takes a mesh g, applies batches of simplification until either the number of max batches or the minim...
Definition: progressive_compression_filter.hpp:126
FEVV::ProgressiveCompressionPlugin::Generic_plugins
QStringList Generic_plugins() const override
Definition: progressivecompression_plugin.h:350
FEVV::Generic_PluginInterface
Definition: PluginInterface.h:37
FEVV::DataStructures::AIF::AIFMesh
This class represents an AIF structure. AIF structure can deal with both manifold and non-manifold su...
Definition: AIFMesh.hpp:47
FEVV::BasePluginQt::apply
virtual void apply(BaseAdapterVisu *, void *, FEVV::PMapsContainer *) override
Definition: BasePluginQt.h:108
FEVV::ProgressiveCompressionPlugin::addParameters
void addParameters(BaseWindow *_window) override
Definition: progressivecompression_plugin.h:134
PluginInterface.h
FEVV::_PMap_traits
Definition: properties.h:376
FEVV::BasePlugin::window
BaseWindow * window
Definition: BasePlugin.h:138
FEVV::BaseWindow
Definition: BaseWindow.h:25
properties.h
FEVV::vertex_normal
@ vertex_normal
Definition: properties.h:35
FEVV::Filters::Parameters
Parameters contains the compression parameters except the stopping criteria.
Definition: Parameters.h:46
FEVV::MeshPolyhedron
CGAL::Polyhedron_3< CGALKernel, CGAL::Polyhedron_items_with_id_3 > MeshPolyhedron
Definition: DataStructures_cgal_polyhedron_3.h:33
FEVV::Filters::METRIC_TYPE::QEM_3D
@ QEM_3D
do not use a local metric (not implemented in this release)
FEVV::Filters::BATCH_CONDITION
BATCH_CONDITION
Definition: Batch_collapser.h:51
FEVV::Filters::PREDICTION_TYPE::POSITION
@ POSITION
FEVV::make_property_map
PMap_traits< PropertyT, MeshT >::pmap_type make_property_map(PropertyT, const MeshT &m)
Definition: properties.h:630
progressive_compression_filter.hpp
FEVV::MeshAIF
FEVV::DataStructures::AIF::AIFMesh MeshAIF
Definition: DataStructures_aif.h:19