MEPP2 Project
cmdm_plugin.h
Go to the documentation of this file.
1 // Copyright (c) 2012-2020 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>
22 #include "Dialogs/cmdm_dialog.h"
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
35 
37 
38 #ifdef FEVV_USE_CGAL
42 #endif // FEVV_USE_CGAL
43 #ifdef FEVV_USE_OPENMESH
45 #endif // FEVV_USE_OPENMESH
46 #ifdef FEVV_USE_AIF
48 #endif // FEVV_USE_AIF
49 #endif
50 
51 namespace FEVV {
52 
53 class CMDMPlugin : public QObject,
55  public BasePluginQt
56 {
57  Q_OBJECT
58  Q_INTERFACES(FEVV::Generic_PluginInterface)
59 #if(FEVV_USE_QT5) // see at the end of .cpp for QT4
60  Q_PLUGIN_METADATA(IID "CMDMPlugin")
61 #endif
62 
63  /*public:
64  using BasePlugin::apply;*/
65 public:
66  CMDMPlugin() = default;
67  ~CMDMPlugin() = default;
68 
69 public:
71 
74  FEVV::MeshSurface >::pmap_type;
75  void init() override
76  {
77  one_two = false;
78  two_one = false;
79  scales = 3;
80  color = false;
82  }
83 
84  void reset() override
85  {
86  init();
87 
88  emit resetSignal();
89  }
90 
91  void addParameters(BaseWindow *_window) override
92  {
93  window = _window;
94  if(window == nullptr || !window->isInit())
95  {
96  std::cerr << "BaseWindow is null or not initialized." << std::endl;
97  return;
98  }
99  }
100 
101  void process(MeshSurface &m_degraded,
102  FEVV::PMapsContainer &pmaps_bag_degraded,
103  MeshSurface &m_original,
104  FEVV::PMapsContainer &pmaps_bag_original,
105  double &CMDM,
106  vertex_cmdm_map &cmdm_pmap,
107  VertexColorMap &v_cm)
108  {
109  auto pm_degrad = get(boost::vertex_point, m_degraded);
110  auto pm_original = get(boost::vertex_point, m_original);
111 
112  using FaceNormalMap = typename FEVV::PMap_traits< FEVV::face_normal_t,
113  MeshSurface >::pmap_type;
114  FaceNormalMap fnm_degrad;
115  if(has_map(pmaps_bag_degraded, FEVV::face_normal))
116  {
117  std::cout << "use existing face-normal map for degraded mesh"
118  << std::endl;
119  fnm_degrad =
120  get_property_map(FEVV::face_normal, m_degraded, pmaps_bag_degraded);
121  }
122  else
123  {
124  std::cout << "create face-normal map for degraded mesh" << std::endl;
125  fnm_degrad = make_property_map(FEVV::face_normal, m_degraded);
126  // store property map in property maps bag
128  FEVV::face_normal, m_degraded, pmaps_bag_degraded, fnm_degrad);
129  FEVV::Filters::calculate_face_normals(m_degraded, pm_degrad, fnm_degrad);
130  }
131 
132  FaceNormalMap fnm_original;
133  if(has_map(pmaps_bag_original, FEVV::face_normal))
134  {
135  std::cout << "use existing face-normal map for original mesh"
136  << std::endl;
137  fnm_original =
138  get_property_map(FEVV::face_normal, m_original, pmaps_bag_original);
139  }
140  else
141  {
142  std::cout << "create face-normal map for original mesh" << std::endl;
143  fnm_original = make_property_map(FEVV::face_normal, m_original);
144  // store property map in property maps bag
146  FEVV::face_normal, m_original, pmaps_bag_original, fnm_original);
148  m_original, pm_original, fnm_original);
149  }
150 
151  // Using a vertex property map to store the local distortions and visualize
152  // them later (color map).
153  // vertex_cmdm_map cmdm_pmap;
154  if(has_map(pmaps_bag_degraded, std::string("v:cmdm")))
155  {
156  cmdm_pmap =
157  boost::any_cast< vertex_cmdm_map >(pmaps_bag_degraded.at("v:cmdm"));
158  }
159  else
160  {
161  cmdm_pmap =
162  FEVV::make_vertex_property_map< MeshSurface, double >(m_degraded);
163  pmaps_bag_degraded["v:cmdm"] = cmdm_pmap;
164  }
165 
166  // B) call the filter corresponding to your operation
168  pm_degrad,
169  fnm_degrad,
170  pmaps_bag_degraded,
171  m_original,
172  pm_original,
173  fnm_original,
174  pmaps_bag_original,
175  scales,
176  cmdm_pmap,
177  CMDM);
178  // To Visualise CMDM as color map later
179  v_cm = get_property_map(FEVV::vertex_color, m_degraded, pmaps_bag_degraded);
180  }
181 
182  template< typename HalfedgeGraph >
183  void process(HalfedgeGraph &/*m_degraded*/,
184  FEVV::PMapsContainer &/*pmaps_bag_degraded*/,
185  HalfedgeGraph &/*m_original*/,
186  FEVV::PMapsContainer &/*pmaps_bag_original*/,
187  double &/*CMDM*/,
188  vertex_cmdm_map &/*cmdm_pmap*/,
189  VertexColorMap &/*v_cm*/)
190  {
191  QMessageBox::information(
192  0, "", QObject::tr("CMDM only works with surface_mesh"));
193  // return EXIT_FAILURE;
194  }
195 
196 
197  template< typename HalfedgeGraph >
198  void applyHG(BaseAdapterVisu *_adapter,
199  HalfedgeGraph * /*_mesh*/,
200  FEVV::PMapsContainer * /*pmaps_bag*/)
201  {
202  // retrieve the two input meshes in current viewer window
203  SimpleViewer *viewer =
204  dynamic_cast< SimpleViewer * >(_adapter->getViewer());
205 
206  if(!viewer)
207  {
208  // something goes wrong
209  QMessageBox::information(
210  0, "", QObject::tr("An error occur during CMDM filter processing."));
211  return;
212  }
213 
214  MixedMeshesVector mixed_meshes = viewer->getMeshes();
215  std::vector< FEVV::PMapsContainer * > properties_maps =
216  viewer->get_properties_maps();
217 
218  if(mixed_meshes.size() == 2)
219  {
220  // check that the two input meshes have the same type
221  if(mixed_meshes[0].second == mixed_meshes[1].second)
222  {
223  // get filter parameters from dialog window
224  CMDMDialog dialog;
225  if(dialog.exec() == QDialog::Accepted)
227  else
228  return; // abort applying filter
229 
230  // retieve meshes and property bags
231  auto m1 = static_cast< HalfedgeGraph * >(mixed_meshes[0].first);
232  auto pmaps_bag1 = properties_maps[0];
233  auto m2 = static_cast< HalfedgeGraph * >(mixed_meshes[1].first);
234  auto pmaps_bag2 = properties_maps[1];
235 
236  // ensure both meshes have diffuse color maps
237  if(has_map(*pmaps_bag1, FEVV::vertex_color) &&
238  has_map(*pmaps_bag2, FEVV::vertex_color))
239  {
240  // apply filter
241  double CMDM = 0, CMDM_1_2 = 0, CMDM_2_1 = 0;
242  vertex_cmdm_map cmdm_pmap_deg, cmdm_pmap_orig;
243  VertexColorMap v_cm_deg, v_cm_orig;
244  if(one_two)
245  {
246  process(*m2, *pmaps_bag2, *m1, *pmaps_bag1, CMDM_1_2, cmdm_pmap_deg,
247  v_cm_deg);
248  CMDM = CMDM_1_2;
249  }
250  if(two_one)
251  {
252  process(*m1, *pmaps_bag1, *m2, *pmaps_bag2, CMDM_2_1, cmdm_pmap_orig,
253  v_cm_orig);
254  CMDM = CMDM_2_1;
255  }
256  if(one_two && two_one)
257  {
258  CMDM = (CMDM_1_2 + CMDM_2_1) / 2.;
259  }
260  std::cout << "CMDM = " << CMDM << std::endl;
261 
262  // Visalize local distortions (LD)
263  if(color)
264  {
265  double max_cmdm_1_2, min_cmdm_1_2, max_cmdm_2_1, min_cmdm_2_1;
266  // 1- LD of the degraded mesh in relation to the original mesh(color
267  // map of cmdm_1_2)
269  cmdm_pmap_deg,
270  min_cmdm_1_2,
271  max_cmdm_1_2);
272 
274  cmdm_pmap_deg,
275  v_cm_deg,
276  min_cmdm_1_2,
277  max_cmdm_1_2,
279 
280  // 2- LD of the original mesh in relation to the degraded mesh(color
281  // map of cmdm_1_2)
283  cmdm_pmap_orig,
284  min_cmdm_2_1,
285  max_cmdm_2_1);
286 
288  cmdm_pmap_orig,
289  v_cm_orig,
290  min_cmdm_2_1,
291  max_cmdm_2_1,
293  }
294 
295  // redraw meshes
296  viewer->draw_or_redraw_mesh(m1, pmaps_bag1, true, false);
297  viewer->draw_or_redraw_mesh(m2, pmaps_bag2, true, false);
298  }
299  else
300  {
301  QMessageBox::information(
302  0,
303  "",
304  QObject::tr(
305  "CMDM needs 2 meshes with diffuse colors.\nUse MSDM2 Plugin"
306  "for meshes having geometry characteristics only."));
307  }
308  }
309  else
310  {
311  QMessageBox::information(
312  0,
313  "",
314  QObject::tr("CMDM filter can not be applied on meshes "
315  "with different datastructures."));
316  }
317  }
318  else
319  {
320  QMessageBox::information(0,
321  "",
322  QObject::tr("CMDM needs 2 meshes opened "
323  "with the same datastructure."));
324  }
325 
326  reset();
327 
328 #if(FEVV_USE_QT5)
329  // empty
330 #else
331  viewer->frame(); // necessary or not ?
332 #endif
333  }
334 
335 
336 #ifdef FEVV_USE_OPENMESH
337  void apply(BaseAdapterVisu *_adapter,
338  MeshOpenMesh *_mesh,
339  FEVV::PMapsContainer *pmaps_bag) override
340  {
341  applyHG< MeshOpenMesh >(_adapter, _mesh, pmaps_bag);
342  }
343 #endif
344 
345 #ifdef FEVV_USE_CGAL
346  void apply(BaseAdapterVisu *_adapter,
347  MeshLCC *_mesh,
348  FEVV::PMapsContainer *pmaps_bag) override
349  {
350  applyHG< MeshLCC >(_adapter, _mesh, pmaps_bag);
351  }
352 
353  void apply(BaseAdapterVisu *_adapter,
354  MeshSurface *_mesh,
355  FEVV::PMapsContainer *pmaps_bag) override
356  {
357  applyHG< MeshSurface >(_adapter, _mesh, pmaps_bag);
358  }
359 
360  void apply(BaseAdapterVisu *_adapter,
361  MeshPolyhedron *_mesh,
362  FEVV::PMapsContainer *pmaps_bag) override
363  {
364  applyHG< MeshPolyhedron >(_adapter, _mesh, pmaps_bag);
365  }
366 #endif
367 
368 #ifdef FEVV_USE_AIF
369  void apply(BaseAdapterVisu *_adapter,
370  MeshAIF *_mesh,
371  FEVV::PMapsContainer *pmaps_bag) override
372  {
373  applyHG< MeshAIF >(_adapter, _mesh, pmaps_bag);
374  }
375 #endif
376 
377 
378  QStringList Generic_plugins() const override
379  {
380  return QStringList() << "CMDMPlugin";
381  }
382 
383 
384  bool Generic_plugin(const QString &/*plugin*/) override
385  {
386  SimpleWindow *sw = static_cast< SimpleWindow * >(window);
387  // dynamic_cast fails under OS X
388  sw->onModificationParam("cmdm_qt_p", this);
389 
390  sw->onApplyButton();
391 
392  return true;
393  }
394 
395 signals:
396  void resetSignal();
397 
398 protected:
399  bool one_two;
400  bool two_one;
401  int scales;
402  bool color;
404 };
405 
406 } // namespace FEVV
FEVV::CMDMPlugin::Generic_plugins
QStringList Generic_plugins() const override
Definition: cmdm_plugin.h:378
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::face_normal_t
face_normal_t
Definition: properties.h:77
FEVV::Filters::compute_min_max_vertices
void compute_min_max_vertices(const HalfedgeGraph &g, const PropertyMap &prop_map, MapType &min_metric, MapType &max_metric)
Compute min and max value of a numerical property map for the vertices of a mesh.
Definition: minmax_map.h:92
FEVV::get_property_map
PMap_traits< PropertyT, MeshT >::pmap_type get_property_map(PropertyT p, const MeshT &, const PMapsContainer &pmaps)
Definition: properties.h:646
minmax_map.h
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::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::CMDMPlugin::scales
int scales
Definition: cmdm_plugin.h:401
FEVV::CMDMPlugin::applyHG
void applyHG(BaseAdapterVisu *_adapter, HalfedgeGraph *, FEVV::PMapsContainer *)
Definition: cmdm_plugin.h:198
FEVV::BaseAdapterVisu::getViewer
virtual Viewer * getViewer()
Definition: BaseAdapterVisu.h:130
properties_linear_cell_complex.h
color_mesh.h
FEVV::MixedMeshesVector
Functions to retrieve the name of the datastructure according to the mesh type.
Definition: SimpleViewer.h:138
FEVV::MixedMeshesVector::size
std::size_t size(void)
Definition: SimpleViewer.h:158
FEVV::CMDMPlugin::CMDMPlugin
CMDMPlugin()=default
FEVV::MeshSurface
CGAL::Surface_mesh< CGALPoint > MeshSurface
Definition: DataStructures_cgal_surface_mesh.h:23
FEVV::BaseAdapterVisu
Definition: BaseAdapterVisu.h:27
FEVV::CMDMPlugin::process
void process(MeshSurface &m_degraded, FEVV::PMapsContainer &pmaps_bag_degraded, MeshSurface &m_original, FEVV::PMapsContainer &pmaps_bag_original, double &CMDM, vertex_cmdm_map &cmdm_pmap, VertexColorMap &v_cm)
Definition: cmdm_plugin.h:101
FEVV::CMDMPlugin::VertexColorMap
typename FEVV::PMap_traits< FEVV::vertex_color_t, FEVV::MeshSurface >::pmap_type VertexColorMap
Definition: cmdm_plugin.h:74
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::Filters::color_vertices_from_map
void color_vertices_from_map(const HalfedgeGraph &g, const PropertyMap &prop_map, ColorMap &color_pmap, const MapType min_metric, const MapType max_metric, const ColorMeshLUT &colors=make_LUT())
Fill the color map for the vertices of a mesh using a numerical property map.
Definition: color_mesh.h:211
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::CMDMPlugin::color
bool color
Definition: cmdm_plugin.h:402
cmdm.h
FEVV::Filters::make_LUT
ColorMeshLUT make_LUT(bool color_in_0_255=true, unsigned int colors_nbr=256, float h1=240, float h2=0)
Create a RGB LUT based on an HSV range. Default range creates a blue-cyan-green-yellow-red gradient.
Definition: color_mesh.h:41
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::CMDMPlugin
Definition: cmdm_plugin.h:56
FEVV::SimpleViewer::getMeshes
MixedMeshesVector getMeshes()
Definition: SimpleViewer.inl:421
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::Filters::ColorMeshLUT
std::vector< float > ColorMeshLUT
Definition: color_mesh.h:25
FEVV::CMDMPlugin::reset
void reset() override
Definition: cmdm_plugin.h:84
FEVV::CMDMDialog::getProcess
void getProcess(bool &one_two, bool &two_one, int &scales, bool &colors)
Definition: cmdm_dialog.cpp:30
FEVV::vertex_color
@ vertex_color
Definition: properties.h:47
cmdm_dialog.h
SimpleViewer.h
FEVV::Filters::calculate_face_normals
void calculate_face_normals(const HalfedgeGraph &g, const PointMap &pm, FaceNormalMap fnm, const GeometryTraits &gt)
Calculate "some" normal of all the faces of the considered mesh and populate the argument provided Fa...
Definition: calculate_face_normals.hpp:40
FEVV::SimpleViewer::get_properties_maps
std::vector< PMapsContainer * > get_properties_maps()
Definition: SimpleViewer.inl:475
FEVV::Vertex_pmap
typename Vertex_pmap_traits< MeshT, ValueT >::pmap_type Vertex_pmap
Definition: properties.h:607
FEVV::CMDMPlugin::init
void init() override
Definition: cmdm_plugin.h:75
BasePluginQt.h
properties_openmesh.h
FEVV::CMDMPlugin::resetSignal
void resetSignal()
FEVV::CMDMPlugin::LUT_CourbureClust
FEVV::Filters::ColorMeshLUT LUT_CourbureClust
Definition: cmdm_plugin.h:403
FEVV::CMDMPlugin::~CMDMPlugin
~CMDMPlugin()=default
FEVV::MeshOpenMesh
OpenMesh::PolyMesh_ArrayKernelT< MyTraits > MeshOpenMesh
Definition: DataStructures_openmesh.h:51
FEVV::CMDMPlugin::two_one
bool two_one
Definition: cmdm_plugin.h:400
FEVV::Generic_PluginInterface
Definition: PluginInterface.h:37
FEVV::CMDMPlugin::addParameters
void addParameters(BaseWindow *_window) override
Definition: cmdm_plugin.h:91
FEVV::BasePluginQt::apply
virtual void apply(BaseAdapterVisu *, void *, FEVV::PMapsContainer *) override
Definition: BasePluginQt.h:108
PluginInterface.h
FEVV::_PMap_traits
Definition: properties.h:376
FEVV::Filters::process_CMDM_multires
double process_CMDM_multires(const HalfedgeGraph &m_poly_degrad, const PointMap &pm_degrad, const FaceNormalMap &fnm_degrad, FEVV::PMapsContainer &pmaps_degrad, const HalfedgeGraph &m_poly_original, const PointMap &pm_original, const FaceNormalMap &fnm_original, FEVV::PMapsContainer &pmaps_original, const int nb_level, VertexCMDMMap &cmdm_pmap, const double maxdim, double &CMDM_value)
Definition: cmdm.h:484
FEVV::BasePlugin::window
BaseWindow * window
Definition: BasePlugin.h:138
FEVV::BaseWindow
Definition: BaseWindow.h:25
properties.h
FEVV::CMDMPlugin::process
void process(HalfedgeGraph &, FEVV::PMapsContainer &, HalfedgeGraph &, FEVV::PMapsContainer &, double &, vertex_cmdm_map &, VertexColorMap &)
Definition: cmdm_plugin.h:183
FEVV::CMDMPlugin::one_two
bool one_two
Definition: cmdm_plugin.h:399
FEVV::CMDMPlugin::Generic_plugin
bool Generic_plugin(const QString &) override
Definition: cmdm_plugin.h:384
FEVV::MeshPolyhedron
CGAL::Polyhedron_3< CGALKernel, CGAL::Polyhedron_items_with_id_3 > MeshPolyhedron
Definition: DataStructures_cgal_polyhedron_3.h:33
FEVV::CMDMDialog
Definition: cmdm_dialog.h:23
FEVV::CMDMPlugin::vertex_cmdm_map
FEVV::Vertex_pmap< MeshSurface, double > vertex_cmdm_map
Definition: cmdm_plugin.h:70
FEVV::make_property_map
PMap_traits< PropertyT, MeshT >::pmap_type make_property_map(PropertyT, const MeshT &m)
Definition: properties.h:630
FEVV::MeshAIF
FEVV::DataStructures::AIF::AIFMesh MeshAIF
Definition: DataStructures_aif.h:19
FEVV::face_normal
@ face_normal
Definition: properties.h:77