MEPP2 Project
DecompressionValencePlugin.h
Go to the documentation of this file.
1 // Copyright (c) 2012-2019 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 #include "FEVV/Filters/Generic/Manifold/Compression_Valence/decompression_valence.h" // A) include the header of the filter corresponding to your operation
32 
34 #ifdef FEVV_USE_CGAL
38 #endif // FEVV_USE_CGAL
39 #ifdef FEVV_USE_OPENMESH
41 #endif // FEVV_USE_OPENMESH
42 #ifdef FEVV_USE_AIF
44 #endif // FEVV_USE_AIF
45 #endif // Q_MOC_RUN
46 
47 
48 namespace FEVV {
49 
50 class DecompressionValencePlugin : 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 "DecompressionValencePlugin")
58 #endif
59 
60  /*public:
61  using BasePlugin::apply;*/
62 public:
65 
66 public:
67  void init() override { init("example.p3d", -1, true, false); }
68 
69  void init(const std::string &_p3dFilePath,
70  int _stop_level,
71  bool _write_info,
72  bool _write_intermediate_meshes)
73  {
74  p3dFilePath = _p3dFilePath;
75  stop_level = _stop_level;
76  write_info = _write_info;
77  write_intermediate_meshes = _write_intermediate_meshes;
79  intermediate_meshes_void = nullptr;
81  }
82 
83  void reset() override
84  {
85  init();
86 
87  emit resetSignal();
88  }
89 
90  void addParameters(BaseWindow *_window) override
91  {
92  window = _window;
93  if(window == nullptr || !window->isInit())
94  {
95  std::cerr << "BaseWindow is null or not initialized." << std::endl;
96  return;
97  }
98  }
99 
100  template< typename HalfedgeGraph >
101  void process(HalfedgeGraph *&_mesh, FEVV::PMapsContainer *&pmaps_bag)
102  {
103  std::cout << "Asking to apply DecompressionValence filter on file '"
104  << p3dFilePath << "'!" << std::endl;
105 
106 #if 0
107  //DBG
108  std::cout << "Decompression Valence Plugin DBG infos" << std::endl;
109  std::cout << " * p3dFilePath=" << p3dFilePath << std::endl;
110  std::cout << " * write_info=" << write_info << std::endl;
111  std::cout << " * write_intermediate_meshes=" << write_intermediate_meshes << std::endl;
112  std::cout << " * keep_intermediate_meshes=" << keep_intermediate_meshes << std::endl;
113 #endif
114 
115  // retrieve geometry property map
116  auto pm = get(boost::vertex_point, *_mesh);
117 
118  // create vertex color property map
119  using VertexColorMap =
121  HalfedgeGraph >::pmap_type;
122  VertexColorMap v_cm;
123 
124  // create intermediate meshes storage
125  std::vector< HalfedgeGraph * > *intermediate_meshes = nullptr;
126  std::vector< VertexColorMap * > *intermediate_vertexColorMaps = nullptr;
128  {
129  intermediate_meshes = new std::vector< HalfedgeGraph * >;
130  intermediate_vertexColorMaps = new std::vector< VertexColorMap * >;
131  }
132 
133  // apply Decompression Valence filter
134  std::string result;
135  try
136  {
137  result =
139  &pm,
140  &v_cm,
141  p3dFilePath,
142  has_color,
143  write_info,
144  intermediate_meshes,
145  intermediate_vertexColorMaps,
146  stop_level,
148 
149  // existing property maps are no more valid due to topological changes
150  // purge the property maps bag
151  FEVV::PMapsContainer new_pmaps_bag;
152  *pmaps_bag = new_pmaps_bag;
153 
154  // keep vertex color map if compressed mesh really has colors
155  if(has_color)
156  FEVV::put_property_map(FEVV::vertex_color, *_mesh, *pmaps_bag, v_cm);
157  }
158  catch(std::runtime_error &e)
159  {
160  std::cout << e.what() << std::endl;
161  }
162 
163  intermediate_meshes_void = static_cast< void * >(intermediate_meshes);
165  static_cast< void * >(intermediate_vertexColorMaps);
166 
167  std::string message("Decompression completed.\n\n");
168  message.append(result);
169  QMessageBox::information(0, "", QString::fromStdString(message));
170  }
171 
172 
173  template< typename HalfedgeGraph >
174  void applyHG(BaseAdapterVisu *_adapter)
175  {
176  // get filter parameters from dialog window
179  stop_level,
180  write_info,
183  if(dial1.exec() == QDialog::Accepted)
185  stop_level,
186  write_info,
189  else
190  return; // abort applying filter
191 
192  // create a new mesh and its property-maps bag for the filter
193  auto mesh = new HalfedgeGraph;
194  auto pmaps_bag = new FEVV::PMapsContainer;
195 
196  // apply filter
197  process(mesh, pmaps_bag);
198 
199  // draw mesh(es)
200  SimpleViewer *viewer =
201  dynamic_cast< SimpleViewer * >(_adapter->getViewer());
202  if(viewer)
203  {
204  using VertexColorMap =
206  HalfedgeGraph >::pmap_type;
207 
208  // draw the uncompressed mesh
209  viewer->draw_or_redraw_mesh(mesh, pmaps_bag, false, false, "uncompressed");
210 
211  // space_time mode ON
212  viewer->m_space_time = true;
213 
214  // draw all intermediate meshes
215  auto intermediate_meshes =
216  static_cast< std::vector< HalfedgeGraph * > * >(
218  auto intermediate_vertexColorMaps =
219  static_cast< std::vector< VertexColorMap * > * >(
221 
223  {
224  // loop over intermediate meshes
225  for(int i = intermediate_meshes->size() - 1; i >=0; i--)
226  {
227  HalfedgeGraph *mesh_i = (*intermediate_meshes)[i];
228  VertexColorMap *v_cm_i = (*intermediate_vertexColorMaps)[i];
229 
230  FEVV::PMapsContainer *pmaps_bag_i = new FEVV::PMapsContainer;
231  if(has_color)
232  {
234  FEVV::vertex_color, *mesh_i, *pmaps_bag_i, *v_cm_i);
235  }
236 
237  // draw intermediate mesh
238  viewer->draw_or_redraw_mesh(mesh_i,
239  pmaps_bag_i,
240  false,
241  false,
242  std::string("level") + std::to_string(i));
243  }
244  }
245 
246  delete(intermediate_meshes);
247  intermediate_meshes_void = nullptr;
248  delete(intermediate_vertexColorMaps);
250  }
251 
252  // comment next line to keep parameters value between calls
253  //reset();
254 
255  viewer->activate_time_mode();
256 
257 #if(FEVV_USE_QT5)
258  // empty
259 #else
260  viewer->frame(); // necessary or not ?
261 #endif
262  }
263 
264 
265 #ifdef FEVV_USE_CGAL
266  void apply(BaseAdapterVisu *_adapter,
267  MeshLCC * /*_mesh*/,
268  FEVV::PMapsContainer * /*pmaps_bag*/) override
269  {
270  apply(_adapter, static_cast< void * >(nullptr), nullptr);
271  }
272 
273  void apply(BaseAdapterVisu *_adapter,
274  MeshSurface * /*_mesh*/,
275  FEVV::PMapsContainer * /*pmaps_bag*/) override
276  {
277  apply(_adapter, static_cast< void * >(nullptr), nullptr);
278  }
279 
280  void apply(BaseAdapterVisu *_adapter,
281  MeshPolyhedron * /*_mesh*/,
282  FEVV::PMapsContainer * /*pmaps_bag*/) override
283  {
284  apply(_adapter, static_cast< void * >(nullptr), nullptr);
285  }
286 #endif
287 
288 
289 #ifdef FEVV_USE_OPENMESH
290  void apply(BaseAdapterVisu *_adapter,
291  MeshOpenMesh * /*_mesh*/,
292  FEVV::PMapsContainer * /*pmaps_bag*/) override
293  {
294  apply(_adapter, static_cast< void * >(nullptr), nullptr);
295  }
296 #endif
297 
298 
299 #ifdef FEVV_USE_AIF
300  void apply(BaseAdapterVisu *_adapter,
301  MeshAIF * /*_mesh*/,
302  FEVV::PMapsContainer * /*pmaps_bag*/) override
303  {
304  apply(_adapter, static_cast< void * >(nullptr), nullptr);
305  }
306 #endif
307 
308 
309  // case where the plugin is applied when no mesh is opened
310  void apply(BaseAdapterVisu *_adapter,
311  void * /*_mesh*/,
312  FEVV::PMapsContainer * /*pmaps_bag*/) override
313  {
314  // ask the user for the datastructure
315  std::string mesh_type = chooseDatastructureMsgBox();
316  if(mesh_type == "NONE")
317  return; // cancel pressed, aborting
318 
319  // apply plugin
320 #ifdef FEVV_USE_CGAL
321  if(mesh_type == "POLYHEDRON")
322  {
323  applyHG< MeshPolyhedron >(_adapter);
324  }
325  else if(mesh_type == "SURFACEMESH")
326  {
327  applyHG< MeshSurface >(_adapter);
328  }
329  else if(mesh_type == "LCC")
330  {
331  applyHG< MeshLCC >(_adapter);
332  }
333  else if(mesh_type == "CGALPOINTSET")
334  {
335  QMessageBox::information(
336  0,
337  "",
338  QObject::tr(
339  "Decompression Valence filter is not yet compatible with CGALPointSet!"));
340  }
341 #endif
342 
343 #ifdef FEVV_USE_OPENMESH
344  if(mesh_type == "OPENMESH")
345  {
346  applyHG< MeshOpenMesh >(_adapter);
347  }
348 #endif
349 
350 #ifdef FEVV_USE_AIF
351  if(mesh_type == "AIF")
352  {
353  QMessageBox::information(
354  0,
355  "",
356  QObject::tr(
357  "Decompression Valence filter is not yet compatible with AIF!"));
358  }
359 #endif
360 
361 #ifdef FEVV_USE_PCL
362  if(mesh_type == "PCLPOINTCLOUD")
363  {
364  QMessageBox::information(
365  0,
366  "",
367  QObject::tr(
368  "Decompression Valence filter is not yet compatible with PCLPointCloud!"));
369  }
370 #endif
371  }
372 
373 
374  QStringList Generic_plugins() const override
375  {
376  return QStringList() << "DecompressionValencePlugin";
377  }
378 
379  bool Generic_plugin(const QString &/*plugin*/) override
380  {
381  SimpleWindow *sw = static_cast< SimpleWindow * >(window);
382  // dynamic_cast fails under OS X
383  sw->onModificationParam("decompressionvalence_qt_p", this);
384  sw->onApplyButton();
385 
386  return true;
387  }
388 
389 signals:
390  void resetSignal();
391 
392 protected:
393  // filter parameters
394  std::string p3dFilePath;
397  bool keep_intermediate_meshes; // keep into RAM
398  bool write_intermediate_meshes; // write to files
401  bool has_color;
402 };
403 
404 } // namespace FEVV
405 
FEVV::BaseWindow::isInit
virtual bool isInit() const
Definition: BaseWindow.h:103
FEVV::SimpleViewer::activate_time_mode
void activate_time_mode()
Definition: SimpleViewer.inl:3456
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::DecompressionValencePlugin::has_color
bool has_color
Definition: DecompressionValencePlugin.h:401
FEVV::DecompressionValencePlugin::write_intermediate_meshes
bool write_intermediate_meshes
Definition: DecompressionValencePlugin.h:398
FEVV::DecompressionValencePlugin::intermediate_vertexColorMaps_void
void * intermediate_vertexColorMaps_void
Definition: DecompressionValencePlugin.h:400
FEVV::DecompressionValencePlugin::~DecompressionValencePlugin
~DecompressionValencePlugin()=default
FEVV::DialogDecompressionValence1::setDecompressionValenceParams
void setDecompressionValenceParams(const std::string &p3dFilePath, int stop_level, bool write_info, bool write_intermediate_meshes, bool display_intermediate_meshes)
Definition: DialogDecompressionValence1.cpp:35
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
FEVV::DecompressionValencePlugin::reset
void reset() override
Definition: DecompressionValencePlugin.h:83
FEVV::DecompressionValencePlugin::init
void init(const std::string &_p3dFilePath, int _stop_level, bool _write_info, bool _write_intermediate_meshes)
Definition: DecompressionValencePlugin.h:69
tr
double tr(double &n)
Truncate a number to 1/1000 (only if BOOLEAN_OPERATIONS_DEBUG is enable)
Definition: boolops_definitions.hpp:127
FEVV::DecompressionValencePlugin::write_info
bool write_info
Definition: DecompressionValencePlugin.h:396
FEVV::DecompressionValencePlugin::applyHG
void applyHG(BaseAdapterVisu *_adapter)
Definition: DecompressionValencePlugin.h:174
FEVV::DecompressionValencePlugin::Generic_plugin
bool Generic_plugin(const QString &) override
Definition: DecompressionValencePlugin.h:379
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
FEVV::DecompressionValencePlugin::apply
void apply(BaseAdapterVisu *_adapter, void *, FEVV::PMapsContainer *) override
Definition: DecompressionValencePlugin.h:310
properties_linear_cell_complex.h
FEVV::MeshSurface
CGAL::Surface_mesh< CGALPoint > MeshSurface
Definition: DataStructures_cgal_surface_mesh.h:23
FEVV::BaseViewer::m_space_time
bool m_space_time
Definition: BaseViewer.h:207
FEVV::DecompressionValencePlugin::DecompressionValencePlugin
DecompressionValencePlugin()=default
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::DialogDecompressionValence1::getDecompressionValenceParams
void getDecompressionValenceParams(std::string &p3dFilePath, int &stop_level, bool &write_info, bool &write_intermediate_meshes, bool &display_intermediate_meshes)
Definition: DialogDecompressionValence1.cpp:60
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::vertex_color_t
vertex_color_t
Definition: properties.h:47
FEVV::DecompressionValencePlugin::addParameters
void addParameters(BaseWindow *_window) override
Definition: DecompressionValencePlugin.h:90
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::DecompressionValencePlugin::process
void process(HalfedgeGraph *&_mesh, FEVV::PMapsContainer *&pmaps_bag)
Definition: DecompressionValencePlugin.h:101
properties_surface_mesh.h
FEVV::Filters::decompression_valence
std::string decompression_valence(HalfedgeGraph &g, PointMap *pm, VertexColorMap *v_cm, const std::string &input_filename, bool &has_color, bool do_write_info, std::vector< HalfedgeGraph * > *intermediate_meshes, std::vector< VertexColorMap * > *intermediate_vertex_color_maps, int stop_level, bool do_write_intermediate_meshes, const GeometryTraits &)
Uncompress a mesh compressed with Compression Valence algorithm.
Definition: decompression_valence.h:59
decompression_valence.h
FEVV::DecompressionValencePlugin::p3dFilePath
std::string p3dFilePath
Definition: DecompressionValencePlugin.h:394
FEVV::vertex_color
@ vertex_color
Definition: properties.h:47
SimpleViewer.h
FEVV::DecompressionValencePlugin::resetSignal
void resetSignal()
FEVV::DecompressionValencePlugin::Generic_plugins
QStringList Generic_plugins() const override
Definition: DecompressionValencePlugin.h:374
BasePluginQt.h
properties_openmesh.h
FEVV::DecompressionValencePlugin
Definition: DecompressionValencePlugin.h:53
FEVV::MeshOpenMesh
OpenMesh::PolyMesh_ArrayKernelT< MyTraits > MeshOpenMesh
Definition: DataStructures_openmesh.h:51
DialogDecompressionValence1.h
FEVV::Generic_PluginInterface
Definition: PluginInterface.h:37
FEVV::DialogDecompressionValence1
Definition: DialogDecompressionValence1.h:23
FEVV::DecompressionValencePlugin::keep_intermediate_meshes
bool keep_intermediate_meshes
Definition: DecompressionValencePlugin.h:397
FEVV::DecompressionValencePlugin::intermediate_meshes_void
void * intermediate_meshes_void
Definition: DecompressionValencePlugin.h:399
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::DecompressionValencePlugin::stop_level
int stop_level
Definition: DecompressionValencePlugin.h:395
FEVV::MeshPolyhedron
CGAL::Polyhedron_3< CGALKernel, CGAL::Polyhedron_items_with_id_3 > MeshPolyhedron
Definition: DataStructures_cgal_polyhedron_3.h:33
FEVV::MeshAIF
FEVV::DataStructures::AIF::AIFMesh MeshAIF
Definition: DataStructures_aif.h:19
FEVV::chooseDatastructureMsgBox
std::string chooseDatastructureMsgBox(void)
Definition: ChooseDatastructureMsgBox.hpp:28
FEVV::DecompressionValencePlugin::init
void init() override
Definition: DecompressionValencePlugin.h:67