MEPP2 Project
progressivedecompression_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 #ifdef FEVV_USE_OPENMESH
42 #endif // FEVV_USE_OPENMESH
43 #ifdef FEVV_USE_AIF
45 #endif // FEVV_USE_AIF
46 #endif
47 
48 namespace FEVV {
49 
50 class ProgressiveDecompressionPlugin : public QObject,
52  public BasePluginQt
53 {
54  Q_OBJECT
55  Q_INTERFACES(FEVV::Generic_PluginInterface)
56 #if(FEVV_USE_QT5) // see at the end of .cpp for QT4
57  Q_PLUGIN_METADATA(IID "ProgressiveDecompressionPlugin")
58 #endif
59 
60  /*public:
61  using BasePlugin::apply;*/
62 public:
65 
66 public:
67  void init() override {}
68 
69  void reset() override
70  {
71  init();
72 
73  emit resetSignal();
74  }
75 
76  void addParameters(BaseWindow *_window) override
77  {
78  window = _window;
79  if(window == nullptr || !window->isInit())
80  {
81  std::cerr << "BaseWindow is null or not initialized." << std::endl;
82  return;
83  }
84  }
85 
86  template< typename HalfedgeGraph >
87  void process(HalfedgeGraph& _mesh, FEVV::PMapsContainer& pmaps_bag)
88  {
89  std::cout << "Asking to ProgressiveDecompression mesh ! " << std::endl;
90 
91  // retrieve or create vertex-color property map
92  using VertexColorMap =
94  HalfedgeGraph >::pmap_type;
95  VertexColorMap v_cm;
96  if(has_map(pmaps_bag, FEVV::vertex_color))
97  {
98  std::cout << "use existing vertex-color map" << std::endl;
99  v_cm = get_property_map(FEVV::vertex_color, _mesh, pmaps_bag);
100  }
101  else
102  {
103  std::cout << "create vertex-color map" << std::endl;
104  v_cm = make_property_map(FEVV::vertex_color, _mesh);
105  // store property map in property maps bag
106  put_property_map(FEVV::vertex_color, _mesh, pmaps_bag, v_cm);
107  }
108 
109  // retrieve or create vertex-normal property map
110  using VertexNormalMap =
112  HalfedgeGraph >::pmap_type;
113  VertexNormalMap v_nm;
114  if(has_map(pmaps_bag, FEVV::vertex_normal))
115  {
116  std::cout << "use existing vertex-normal map" << std::endl;
117  v_nm = get_property_map(FEVV::vertex_normal, _mesh, pmaps_bag);
118  }
119  else
120  {
121  std::cout << "create vertex-normal map" << std::endl;
122  v_nm = make_property_map(FEVV::vertex_normal, _mesh);
123  // store property map in property maps bag
124  put_property_map(FEVV::vertex_normal, _mesh, pmaps_bag, v_nm);
125  }
126 
127 
129  if(has_map(pmaps_bag, FEVV::edge_color))
130  {
131  std::cout << "using edge color property map" << std::endl;
132  e_cm = get_property_map(FEVV::edge_color, _mesh, pmaps_bag);
133  // e_cm_ptr = &e_cm;
134  }
135  else
136  {
137  std::cout << "create vertex-color map" << std::endl;
138  e_cm = make_property_map(FEVV::edge_color, _mesh);
139  // store property map in property maps bag
140  put_property_map(FEVV::edge_color, _mesh, pmaps_bag, e_cm);
141  }
142 
143  // retrieve point property map (aka geometry)
144  auto pm = get(boost::vertex_point, _mesh);
145 
146  // apply filter
147  // B) call the filter corresponding to your operation
148  std::string result;
149  try {
151  pm,
152  v_cm,
154  true);
155  }
156  catch (std::exception& e) {
157  result = e.what();
158  }
159 
160  // existing property maps are no more valid due to topological changes
161  // purge the property maps bag
162  FEVV::PMapsContainer clean_pmaps_bag;
163  pmaps_bag = clean_pmaps_bag;
164 
165  std::string message("Progressive decompression completed.\n\n");
166  message.append(result);
167  QMessageBox::information(0, "", QString::fromStdString(message));
168  }
169 
170  template< typename HalfedgeGraph >
171  void applyHG(BaseAdapterVisu *_adapter)
172  {
173  // get filter parameters from dialog window
175  //dialog.setParameters(value_x, value_y, value_z);
176  if(dialog.exec() == QDialog::Accepted)
178  else
179  return; // abort applying filter
180 
181 
182  // create a new mesh and its property-maps bag for the filter
183  HalfedgeGraph* mesh = new HalfedgeGraph();
184  FEVV::PMapsContainer* pmaps_bag = new FEVV::PMapsContainer();
185 
186  // apply filter
187  process(*mesh, *pmaps_bag);
188 
189  SimpleViewer *viewer =
190  dynamic_cast< SimpleViewer * >(_adapter->getViewer());
191  if(viewer)
192  viewer->draw_or_redraw_mesh(mesh, pmaps_bag, false, false, "uncompressed");
193 
194  // comment next line to keep parameters values between calls
195  reset();
196 
197 #if(FEVV_USE_QT5)
198  // empty
199 #else
200  viewer->frame(); // necessary or not ?
201 #endif
202  }
203 
204 #if FEVV_USE_OPENMESH
205  void apply(BaseAdapterVisu* _adapter, MeshOpenMesh* /*_mesh*/, FEVV::PMapsContainer * /*pmaps_bag*/) override
206  {
207  apply(_adapter, static_cast<void *>(nullptr), nullptr);
208  }
209 #endif
210 
211 #ifdef FEVV_USE_CGAL
212 #if 1
213  void apply(BaseAdapterVisu* _adapter, MeshLCC* /*_mesh*/, FEVV::PMapsContainer * /*pmaps_bag*/) override
214  {
215  apply(_adapter, static_cast<void *>(nullptr), nullptr);
216  }
217 #endif
218  void apply(BaseAdapterVisu* _adapter, MeshSurface* /*_mesh*/, FEVV::PMapsContainer * /*pmaps_bag*/) override
219  {
220  apply(_adapter, static_cast<void *>(nullptr), nullptr);
221  }
222 
223  void apply(BaseAdapterVisu* _adapter, MeshPolyhedron* /*_mesh*/, FEVV::PMapsContainer * /*pmaps_bag*/) override
224  {
225  apply(_adapter, static_cast<void *>(nullptr), nullptr);
226  }
227 #endif
228 
229 #if FEVV_USE_AIF
230 #if 0 // halfedge iteration is not compatible with AIF yet (halfedge_iterator type cannot be exported)
231  void apply(BaseAdapterVisu* _adapter, MeshAIF* /*_mesh*/, FEVV::PMapsContainer * /*pmaps_bag*/) override
232  {
233  apply(_adapter, static_cast<void *>(nullptr), nullptr);
234  }
235 #endif
236 #endif
237 
238  // case where the plugin is applied when no mesh is opened
239  void apply(BaseAdapterVisu *_adapter,
240  void * /*_mesh*/,
241  FEVV::PMapsContainer * /*pmaps_bag*/) override
242  {
243  // ask the user for the datastructure
244  std::string mesh_type = chooseDatastructureMsgBox();
245  if (mesh_type == "NONE")
246  return; // cancel pressed, aborting
247 
248  // apply plugin
249 #ifdef FEVV_USE_CGAL
250  if (mesh_type == "POLYHEDRON")
251  {
252  applyHG< MeshPolyhedron >(_adapter);
253  }
254  else if (mesh_type == "SURFACEMESH")
255  {
256  applyHG< MeshSurface >(_adapter);
257  }
258  else if (mesh_type == "LCC")
259  {
260  applyHG< MeshLCC >(_adapter);
261  }
262 #endif
263 
264 #ifdef FEVV_USE_OPENMESH
265  if (mesh_type == "OPENMESH")
266  {
267  applyHG< MeshOpenMesh >(_adapter);
268  }
269 #endif
270 
271 #ifdef FEVV_USE_AIF
272  if (mesh_type == "AIF")
273  {
274  QMessageBox::information(
275  0,
276  "",
277  QObject::tr(
278  "Progressive Decompression filter is not yet compatible with AIF!"));
279  }
280 #endif
281  }
282 
283  QStringList Generic_plugins() const override
284  {
285  return QStringList() << "ProgressiveDecompressionPlugin";
286  }
287 
288  bool Generic_plugin(const QString &/*plugin*/) override
289  {
290  SimpleWindow *sw = static_cast< SimpleWindow * >(window);
291  // dynamic_cast fails under OS X
292  sw->onModificationParam("progressivedecompression_qt_p", this);
293  //TODO-elo-refactor-plugins
294  // 1) the name of the function onModificationParam()
295  // is unrelated to its content!!!
296  // 2) Generic_plugin() is called by SimpleWindow
297  // and calls back SimpleWindow functions here ;
298  // looks like a bad architecture
299  sw->onApplyButton();
300 
301  return true;
302  }
303 
304 signals:
305  void resetSignal();
306 
307 protected:
308  // filter parameters
309  std::string mesh_binary_path ="";
310 };
311 
312 } // namespace FEVV
313 
FEVV::BaseWindow::isInit
virtual bool isInit() const
Definition: BaseWindow.h:103
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::get_property_map
PMap_traits< PropertyT, MeshT >::pmap_type get_property_map(PropertyT p, const MeshT &, const PMapsContainer &pmaps)
Definition: properties.h:646
progressive_decompression_filter.hpp
FEVV::ProgressiveDecompressionPlugin::apply
void apply(BaseAdapterVisu *_adapter, void *, FEVV::PMapsContainer *) override
Definition: progressivedecompression_plugin.h:239
FEVV::SimpleWindow::onApplyButton
void onApplyButton()
Definition: SimpleWindow.inl:525
FEVV::MeshLCC
CGAL::Linear_cell_complex_for_combinatorial_map< 2, 3, CGALLCCTraits, CGALItem > MeshLCC
Definition: DataStructures_cgal_linear_cell_complex.h:43
tr
double tr(double &n)
Truncate a number to 1/1000 (only if BOOLEAN_OPERATIONS_DEBUG is enable)
Definition: boolops_definitions.hpp:127
FEVV::ProgressiveDecompressionPlugin
Definition: progressivedecompression_plugin.h:53
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
SimpleWindow.h
FEVV::BaseAdapterVisu::getViewer
virtual Viewer * getViewer()
Definition: BaseAdapterVisu.h:130
properties_linear_cell_complex.h
FEVV::ProgressiveDecompressionPlugin::~ProgressiveDecompressionPlugin
~ProgressiveDecompressionPlugin()=default
FEVV::ProgressiveDecompressionPlugin::resetSignal
void resetSignal()
FEVV::ProgressiveDecompressionDialog::getParameters
void getParameters(std::string &filepath)
Definition: progressivedecompression_dialog.cpp:23
FEVV::ProgressiveDecompressionPlugin::addParameters
void addParameters(BaseWindow *_window) override
Definition: progressivedecompression_plugin.h:76
FEVV::MeshSurface
CGAL::Surface_mesh< CGALPoint > MeshSurface
Definition: DataStructures_cgal_surface_mesh.h:23
FEVV::ProgressiveDecompressionPlugin::mesh_binary_path
std::string mesh_binary_path
Definition: progressivedecompression_plugin.h:309
FEVV::BaseAdapterVisu
Definition: BaseAdapterVisu.h:27
properties_aif.h
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
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
FEVV::ProgressiveDecompressionPlugin::applyHG
void applyHG(BaseAdapterVisu *_adapter)
Definition: progressivedecompression_plugin.h:171
properties_polyhedron_3.h
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
progressivedecompression_dialog.h
properties_surface_mesh.h
FEVV::ProgressiveDecompressionPlugin::Generic_plugins
QStringList Generic_plugins() const override
Definition: progressivedecompression_plugin.h:283
FEVV::ProgressiveDecompressionPlugin::ProgressiveDecompressionPlugin
ProgressiveDecompressionPlugin()=default
FEVV::edge_color
@ edge_color
Definition: properties.h:73
FEVV::vertex_color
@ vertex_color
Definition: properties.h:47
FEVV::ProgressiveDecompressionDialog
Definition: progressivedecompression_dialog.h:23
SimpleViewer.h
FEVV::ProgressiveDecompressionPlugin::Generic_plugin
bool Generic_plugin(const QString &) override
Definition: progressivedecompression_plugin.h:288
FEVV::ProgressiveDecompressionPlugin::reset
void reset() override
Definition: progressivedecompression_plugin.h:69
BasePluginQt.h
properties_openmesh.h
FEVV::ProgressiveDecompressionPlugin::process
void process(HalfedgeGraph &_mesh, FEVV::PMapsContainer &pmaps_bag)
Definition: progressivedecompression_plugin.h:87
FEVV::MeshOpenMesh
OpenMesh::PolyMesh_ArrayKernelT< MyTraits > MeshOpenMesh
Definition: DataStructures_openmesh.h:51
FEVV::Generic_PluginInterface
Definition: PluginInterface.h:37
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
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::MeshPolyhedron
CGAL::Polyhedron_3< CGALKernel, CGAL::Polyhedron_items_with_id_3 > MeshPolyhedron
Definition: DataStructures_cgal_polyhedron_3.h:33
FEVV::make_property_map
PMap_traits< PropertyT, MeshT >::pmap_type make_property_map(PropertyT, const MeshT &m)
Definition: properties.h:630
FEVV::ProgressiveDecompressionPlugin::init
void init() override
Definition: progressivedecompression_plugin.h:67
FEVV::MeshAIF
FEVV::DataStructures::AIF::AIFMesh MeshAIF
Definition: DataStructures_aif.h:19
FEVV::chooseDatastructureMsgBox
std::string chooseDatastructureMsgBox(void)
Definition: ChooseDatastructureMsgBox.hpp:28