MEPP2 Project
CompressionValencePlugin.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/compression_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 CompressionValencePlugin : 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 "CompressionValencePlugin")
58 #endif
59 
60  /*public:
61  using BasePlugin::apply;*/
62 public:
65 
66 public:
67  void init() override { init("compressed_mesh.p3d", false, 10, 100); }
68 
69  void init(const std::string &_p3dFilePath,
70  bool _with_adaptative_quantization,
71  int _quantization_bits,
72  int _max_vertices)
73  {
74  p3dFilePath = _p3dFilePath;
75  with_adaptative_quantization = _with_adaptative_quantization;
76  quantization_bits = _quantization_bits;
77  max_vertices = _max_vertices;
78  }
79 
80  void reset() override
81  {
82  init();
83 
84  emit resetSignal();
85  }
86 
87  void addParameters(BaseWindow *_window) override
88  {
89  window = _window;
90  if(window == nullptr || !window->isInit())
91  {
92  std::cerr << "BaseWindow is null or not initialized." << std::endl;
93  return;
94  }
95  }
96 
97  template< typename HalfedgeGraph >
98  void process(HalfedgeGraph *_mesh, FEVV::PMapsContainer *pmaps_bag)
99  {
100  std::cout << "Asking to apply CompressionValence filter ! " << std::endl;
101 
102  // do not compress if p3d file name has not been set
103  bool with_compression = !p3dFilePath.empty();
104 
105 #if 0
106  //TODO-elo DBG
107  std::cout << "Compression Valence Plugin DBG infos" << std::endl;
108  std::cout << " * p3dFilePath=" << p3dFilePath << std::endl;
109  std::cout << " * with_compression=" << with_compression << std::endl;
110  std::cout << " * with_adaptative_quantization=" << with_adaptative_quantization << std::endl;
111  std::cout << " * quantization_bits=" << quantization_bits << std::endl;
112  std::cout << " * max_vertices=" << max_vertices << std::endl;
113 #endif
114 
115  // retrieve geometry property map
116  auto pm = get(boost::vertex_point, *_mesh);
117 
118  // retrieve vertex color property map
119  using VertexColorMap =
121  HalfedgeGraph >::pmap_type;
122  VertexColorMap v_cm;
123  VertexColorMap *v_cm_ptr = nullptr;
124 
125  if(pmaps_bag && has_map(*pmaps_bag, FEVV::vertex_color))
126  {
127  std::cout << "Compression Valence filter: using vertex color property map"
128  << std::endl;
129  v_cm = FEVV::get_property_map(FEVV::vertex_color, *_mesh, *pmaps_bag);
130  v_cm_ptr = &v_cm;
131  }
132  else
133  std::cout << "Compression Valence filter: no vertex color property map "
134  "found, ignoring color"
135  << std::endl;
136 
137  // copy the original mesh and its vertex-color property map (if any)
138  // to be able to display the original mesh and the compressed
139  // mesh at the same time in space mode
140 
141  // create new empty mesh
142  HalfedgeGraph *mesh_copy = new HalfedgeGraph;
143  mesh_copy_void = static_cast< void * >(mesh_copy);
144 
145  // create new vertex-color map if needed
146  VertexColorMap *v_cm_copy_ptr = nullptr;
147  if(v_cm_ptr != nullptr)
148  {
149  v_cm_copy_ptr = new VertexColorMap;
150  }
151 
152  // put vertex-color map into a property maps bag
154  if(v_cm_copy_ptr != nullptr)
155  {
157  FEVV::vertex_color, *mesh_copy, *pmaps_bag_copy, *v_cm_copy_ptr);
158  }
159 
160  // copy mesh and vertex-color
161  using PointMap =
162  typename boost::property_map< HalfedgeGraph,
163  boost::vertex_point_t >::type;
165  copy_mesh(*_mesh, v_cm_ptr, *mesh_copy, v_cm_copy_ptr);
166 
167  // apply Compression Valence filter on original mesh
168  std::string result;
169  result = FEVV::Filters::compression_valence(*_mesh,
170  &pm,
171  v_cm_ptr,
172  "",
173  p3dFilePath,
174  with_compression,
176  max_vertices,
178 
179  // existing property maps are no more valid due to topological changes
180  // purge the property maps bag except the vertex color map
181  FEVV::PMapsContainer clean_pmaps_bag;
182  if(v_cm_ptr != nullptr)
183  {
184  // put vertex color property map into property maps bag
185  FEVV::put_property_map(FEVV::vertex_color, *_mesh, clean_pmaps_bag, v_cm);
186  }
187  *pmaps_bag = clean_pmaps_bag;
188 
189  std::string message("Compression completed.\n\n");
190  message.append(result);
191  QMessageBox::information(0, "", QString::fromStdString(message));
192  }
193 
194  template< typename HalfedgeGraph >
195  void applyHG(BaseAdapterVisu *_adapter,
196  HalfedgeGraph *_mesh,
197  FEVV::PMapsContainer *pmaps_bag)
198  {
199  // get filter parameters from dialog window
204  max_vertices);
205  if(dial1.exec() == QDialog::Accepted)
206  {
210  max_vertices);
211 
212  // if the P3D file name doesn't end with the right extension, fix it
213  if(p3dFilePath.size() < 4 ||
214  p3dFilePath.substr(p3dFilePath.size() - 4) != ".p3d")
215  p3dFilePath.append(".p3d");
216  }
217  else
218  return; // abort applying filter
219 
220  // apply filter
221  process(_mesh, pmaps_bag);
222 
223  // redraw/draw meshes
224  SimpleViewer *viewer =
225  dynamic_cast< SimpleViewer * >(_adapter->getViewer());
226  if(viewer)
227  {
228  // redraw main mesh -> which is NOW compressed
229  viewer->draw_or_redraw_mesh(_mesh, pmaps_bag, true, true, "compressed");
230  viewer->centerMesh(_mesh);
231  viewer->updateSWModelList();
232 
233  // space_time mode ON
234  viewer->m_space_time = true;
235 
236  // draw old original mesh
237  viewer->draw_or_redraw_mesh(
238  static_cast< HalfedgeGraph * >(mesh_copy_void),
240  false,
241  false,
242  "original_mesh_copied");
243  }
244 
245  reset();
246 
247  viewer->activate_time_mode();
248 
249 #if(FEVV_USE_QT5)
250  // empty
251 #else
252  viewer->frame(); // necessary or not ?
253 #endif
254  }
255 
256 #ifdef FEVV_USE_OPENMESH
257  void apply(BaseAdapterVisu *_adapter,
258  MeshOpenMesh *_mesh,
259  FEVV::PMapsContainer *pmaps_bag) override
260  {
261  applyHG< MeshOpenMesh >(_adapter, _mesh, pmaps_bag);
262  }
263 #endif
264 
265 #ifdef FEVV_USE_CGAL
266  void apply(BaseAdapterVisu *_adapter,
267  MeshLCC *_mesh,
268  FEVV::PMapsContainer *pmaps_bag) override
269  {
270  applyHG< MeshLCC >(_adapter, _mesh, pmaps_bag);
271  }
272 
273  void apply(BaseAdapterVisu *_adapter,
274  MeshSurface *_mesh,
275  FEVV::PMapsContainer *pmaps_bag) override
276  {
277  applyHG< MeshSurface >(_adapter, _mesh, pmaps_bag);
278  }
279 
280  void apply(BaseAdapterVisu *_adapter,
281  MeshPolyhedron *_mesh,
282  FEVV::PMapsContainer *pmaps_bag) override
283  {
284  applyHG< MeshPolyhedron >(_adapter, _mesh, pmaps_bag);
285  }
286 #endif
287 
288 #ifdef FEVV_USE_AIF
289 #if 0 //TODO-elo restore when Compression Valence compiles with AIF
290  void apply(BaseAdapterVisu *_adapter,
291  MeshAIF *_mesh,
292  FEVV::PMapsContainer *pmaps_bag) override
293  {
294 
295  applyHG<MeshAIF>(_adapter, _mesh, pmaps_bag);
296  }
297 #endif
298 #endif
299 
300 
301  QStringList Generic_plugins() const override
302  {
303  return QStringList() << "CompressionValencePlugin";
304  }
305 
306  bool Generic_plugin(const QString &/*plugin*/) override
307  {
308  SimpleWindow *sw = static_cast< SimpleWindow * >(window);
309  // dynamic_cast fails under OS X
310  sw->onModificationParam("compressionvalence_qt_p", this);
311  sw->onApplyButton();
312 
313  return true;
314  }
315 
316 signals:
317  void resetSignal();
318 
319 protected:
320  // filter parameters
321  std::string p3dFilePath;
325 
328 };
329 
330 } // namespace FEVV
331 
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::Filters::compression_valence
std::string compression_valence(HalfedgeGraph &g, PointMap *pm, VertexColorMap *v_cm, const std::string &input_filename, const std::string &output_filename, bool with_compression, bool with_adaptative_quantization, int max_vertices, int quantiz_bits, const GeometryTraits &)
Compress the input mesh using the Compression Valence algorithm.
Definition: compression_valence.h:54
FEVV::DialogCompressionValence1::getCompressionValenceParams
void getCompressionValenceParams(std::string &p3dFilePath, bool &with_adaptative_quantization, int &quantization_bits, int &max_vertices)
Definition: DialogCompressionValence1.cpp:52
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::DialogCompressionValence1
Definition: DialogCompressionValence1.h:23
FEVV::CompressionValencePlugin::mesh_copy_void
void * mesh_copy_void
Definition: CompressionValencePlugin.h:326
FEVV::SimpleWindow::onApplyButton
void onApplyButton()
Definition: SimpleWindow.inl:525
FEVV::CompressionValencePlugin::applyHG
void applyHG(BaseAdapterVisu *_adapter, HalfedgeGraph *_mesh, FEVV::PMapsContainer *pmaps_bag)
Definition: CompressionValencePlugin.h:195
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::CompressionValencePlugin::~CompressionValencePlugin
~CompressionValencePlugin()=default
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::CompressionValencePlugin::resetSignal
void resetSignal()
properties_linear_cell_complex.h
FEVV::DialogCompressionValence1::setCompressionValenceParams
void setCompressionValenceParams(const std::string &p3dFilePath, bool with_adaptative_quantization, int quantization_bits, int max_verticesdouble)
Definition: DialogCompressionValence1.cpp:35
FEVV::CompressionValencePlugin::quantization_bits
int quantization_bits
Definition: CompressionValencePlugin.h:323
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::CompressionValencePlugin::reset
void reset() override
Definition: CompressionValencePlugin.h:80
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::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::updateSWModelList
void updateSWModelList()
Definition: SimpleViewer.inl:3480
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::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
properties_surface_mesh.h
FEVV::CompressionValencePlugin::p3dFilePath
std::string p3dFilePath
Definition: CompressionValencePlugin.h:321
FEVV::vertex_color
@ vertex_color
Definition: properties.h:47
SimpleViewer.h
DialogCompressionValence1.h
FEVV::CompressionValencePlugin::Generic_plugin
bool Generic_plugin(const QString &) override
Definition: CompressionValencePlugin.h:306
FEVV::CompressionValencePlugin::init
void init() override
Definition: CompressionValencePlugin.h:67
FEVV::CompressionValencePlugin::CompressionValencePlugin
CompressionValencePlugin()=default
BasePluginQt.h
properties_openmesh.h
FEVV::CompressionValencePlugin::process
void process(HalfedgeGraph *_mesh, FEVV::PMapsContainer *pmaps_bag)
Definition: CompressionValencePlugin.h:98
FEVV::CompressionValencePlugin::pmaps_bag_copy
FEVV::PMapsContainer * pmaps_bag_copy
Definition: CompressionValencePlugin.h:327
FEVV::MeshOpenMesh
OpenMesh::PolyMesh_ArrayKernelT< MyTraits > MeshOpenMesh
Definition: DataStructures_openmesh.h:51
FEVV::Generic_PluginInterface
Definition: PluginInterface.h:37
FEVV::CompressionValencePlugin::max_vertices
int max_vertices
Definition: CompressionValencePlugin.h:324
FEVV::BasePluginQt::apply
virtual void apply(BaseAdapterVisu *, void *, FEVV::PMapsContainer *) override
Definition: BasePluginQt.h:108
FEVV::CompressionValencePlugin::Generic_plugins
QStringList Generic_plugins() const override
Definition: CompressionValencePlugin.h:301
PluginInterface.h
FEVV::_PMap_traits
Definition: properties.h:376
FEVV::BasePlugin::window
BaseWindow * window
Definition: BasePlugin.h:138
FEVV::CompressionValencePlugin::init
void init(const std::string &_p3dFilePath, bool _with_adaptative_quantization, int _quantization_bits, int _max_vertices)
Definition: CompressionValencePlugin.h:69
FEVV::BaseWindow
Definition: BaseWindow.h:25
properties.h
compression_valence.h
FEVV::SimpleViewer::centerMesh
void centerMesh(HalfedgeGraph *_g)
Definition: SimpleViewer.inl:3245
FEVV::CompressionValencePlugin::addParameters
void addParameters(BaseWindow *_window) override
Definition: CompressionValencePlugin.h:87
Compression_Valence_Component::copy_mesh
static void copy_mesh(const HalfedgeGraph &_pMesh, const VertexColorMap *_v_cm, HalfedgeGraph &mesh_copy, VertexColorMap *v_cm_copy)
Copy the current mesh and vertex-color map to a new mesh and vertex-color map. If v_cm_copy == nullpt...
Definition: Compression_Valence_Component.inl:6521
FEVV::MeshPolyhedron
CGAL::Polyhedron_3< CGALKernel, CGAL::Polyhedron_items_with_id_3 > MeshPolyhedron
Definition: DataStructures_cgal_polyhedron_3.h:33
FEVV::CompressionValencePlugin
Definition: CompressionValencePlugin.h:53
FEVV::MeshAIF
FEVV::DataStructures::AIF::AIFMesh MeshAIF
Definition: DataStructures_aif.h:19
FEVV::CompressionValencePlugin::with_adaptative_quantization
bool with_adaptative_quantization
Definition: CompressionValencePlugin.h:322