MEPP2 Project
MSDM2Plugin.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>
22 #include "Dialogs/DialogMSDM21.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 #include "FEVV/Filters/CGAL/Surface_mesh/msdm2.h" // A) include the header of the filter corresponding to your operation
34 
36 #ifdef FEVV_USE_CGAL
40 #endif // FEVV_USE_CGAL
41 #ifdef FEVV_USE_OPENMESH
43 #endif // FEVV_USE_OPENMESH
44 #ifdef FEVV_USE_AIF
46 #endif // FEVV_USE_AIF
47 #endif
48 
49 namespace FEVV {
50 
51 class MSDM2Plugin : public QObject,
53  public BasePluginQt
54 {
55  Q_OBJECT
56  Q_INTERFACES(FEVV::Generic_PluginInterface)
57 #if(FEVV_USE_QT5) // see at the end of .cpp for QT4
58  Q_PLUGIN_METADATA(IID "MSDM2Plugin")
59 #endif
60 
61  /*public:
62  using BasePlugin::apply;*/
63 public:
64  MSDM2Plugin() = default;
65  ~MSDM2Plugin() = default;
66 
67 public:
68  void init() override
69  {
70  one_two = false;
71  two_one = false;
72  scales = 3;
73  color = true;
75  }
76 
77  void reset() override
78  {
79  init();
80 
81  emit resetSignal();
82  }
83 
84  void addParameters(BaseWindow *_window) override
85  {
86  window = _window;
87  if(window == nullptr || !window->isInit())
88  {
89  std::cerr << "BaseWindow is null or not initialized." << std::endl;
90  return;
91  }
92  }
93 
94  void process(MeshSurface &m_degraded,
95  FEVV::PMapsContainer &pmaps_bag_degraded,
96  MeshSurface &m_original,
97  FEVV::PMapsContainer &pmaps_bag_original,
98  double &MSDM2)
99  {
100  auto pm_degrad = get(boost::vertex_point, m_degraded);
101  auto pm_original = get(boost::vertex_point, m_original);
102 
103  using FaceNormalMap = typename FEVV::PMap_traits< FEVV::face_normal_t,
104  MeshSurface >::pmap_type;
105  FaceNormalMap fnm_degrad;
106  if(has_map(pmaps_bag_degraded, FEVV::face_normal))
107  {
108  std::cout << "use existing face-normal map for degraded mesh"
109  << std::endl;
110  fnm_degrad =
111  get_property_map(FEVV::face_normal, m_degraded, pmaps_bag_degraded);
112  }
113  else
114  {
115  std::cout << "create face-normal map for degraded mesh" << std::endl;
116  fnm_degrad = make_property_map(FEVV::face_normal, m_degraded);
117  // store property map in property maps bag
119  FEVV::face_normal, m_degraded, pmaps_bag_degraded, fnm_degrad);
120  FEVV::Filters::calculate_face_normals(m_degraded, pm_degrad, fnm_degrad);
121  }
122 
123  FaceNormalMap fnm_original;
124  if(has_map(pmaps_bag_original, FEVV::face_normal))
125  {
126  std::cout << "use existing face-normal map for original mesh"
127  << std::endl;
128  fnm_original =
129  get_property_map(FEVV::face_normal, m_original, pmaps_bag_original);
130  }
131  else
132  {
133  std::cout << "create face-normal map for original mesh" << std::endl;
134  fnm_original = make_property_map(FEVV::face_normal, m_original);
135  // store property map in property maps bag
137  FEVV::face_normal, m_original, pmaps_bag_original, fnm_original);
139  m_original, pm_original, fnm_original);
140  }
141 
142 
143  typedef typename FEVV::Vertex_pmap< MeshSurface, double > vertex_msdm2_map;
144  vertex_msdm2_map msdm2_pmap;
145 
146  if(has_map(pmaps_bag_degraded, std::string("v:msdm2")))
147  {
148  msdm2_pmap =
149  boost::any_cast< vertex_msdm2_map >(pmaps_bag_degraded.at("v:msdm2"));
150  }
151  else
152  {
153  msdm2_pmap =
154  FEVV::make_vertex_property_map< MeshSurface, double >(m_degraded);
155  pmaps_bag_degraded["v:msdm2"] = msdm2_pmap;
156  }
157 
159  pm_degrad,
160  fnm_degrad,
161  pmaps_bag_degraded,
162  m_original,
163  pm_original,
164  fnm_original,
165  pmaps_bag_original,
166  scales,
167  msdm2_pmap,
168  MSDM2);
169 
170  using VertexColorMap = typename FEVV::PMap_traits< FEVV::vertex_color_t,
171  MeshSurface >::pmap_type;
172  VertexColorMap v_cm;
173  if(has_map(pmaps_bag_degraded, FEVV::vertex_color))
174  {
175  std::cout << "use existing vertex-color map" << std::endl;
176  v_cm =
177  get_property_map(FEVV::vertex_color, m_degraded, pmaps_bag_degraded);
178  }
179  else
180  {
181  std::cout << "create vertex-color map" << std::endl;
182  v_cm = make_property_map(FEVV::vertex_color, m_degraded);
183  // store property map in property maps bag
185  FEVV::vertex_color, m_degraded, pmaps_bag_degraded, v_cm);
186  }
187 
188  double maxMSDM2, minMSDM2;
189  if(color)
190  {
192  m_degraded, msdm2_pmap, minMSDM2, maxMSDM2);
193 
195  m_degraded, msdm2_pmap, v_cm, minMSDM2, maxMSDM2, LUT_CourbureClust);
196  }
197  }
198 
199  template< typename HalfedgeGraph >
200  void process(HalfedgeGraph &/*m_degraded*/,
201  FEVV::PMapsContainer &/*pmaps_bag_degraded*/,
202  HalfedgeGraph &/*m_original*/,
203  FEVV::PMapsContainer &/*pmaps_bag_original*/,
204  double &/*MSDM2*/)
205  {
206  QMessageBox::information(0,
207  "",
208  QObject::tr("MSMD2 filter only works with Surface_mesh "
209  "data structure"));
210  }
211 
212  template< typename HalfedgeGraph >
213  void applyHG(BaseAdapterVisu *_adapter,
214  HalfedgeGraph * /*_mesh*/,
215  FEVV::PMapsContainer * /*pmaps_bag*/)
216  {
217  // retrieve the two input meshes in current viewer window,
218  // then apply the filter
219 
220  SimpleViewer *viewer =
221  dynamic_cast< SimpleViewer * >(_adapter->getViewer());
222 
223  if(! viewer)
224  {
225  // something goes wrong
226  QMessageBox::information(0,
227  "",
228  QObject::tr("An error occur during MSDM2 filter processing."));
229  return;
230  }
231 
232  MixedMeshesVector mixed_meshes = viewer->getMeshes();
233  std::vector< FEVV::PMapsContainer * > properties_maps =
234  viewer->get_properties_maps();
235 
236  if(mixed_meshes.size() == 2)
237  {
238  // check that the two input meshes have the same type
239  if( mixed_meshes[0].second == mixed_meshes[1].second )
240  {
241  // get filter parameters from dialog window
242  DialogMSDM21 dial1;
243  if(dial1.exec() == QDialog::Accepted)
245  else
246  return; // abort applying filter
247 
248  auto m1 = static_cast< HalfedgeGraph * >(mixed_meshes[0].first);
249  auto pm1 = properties_maps[0];
250  auto m2 = static_cast< HalfedgeGraph * >(mixed_meshes[1].first);
251  auto pm2 = properties_maps[1];
252 
253  double MSDM2 = 0, MSDM2_1_2 = 0, MSDM2_2_1 = 0;
254  if(one_two)
255  {
256  process(*m2, *pm2, *m1, *pm1, MSDM2_1_2);
257  MSDM2 = MSDM2_1_2;
258  }
259  if(two_one)
260  {
261  process(*m1, *pm1, *m2, *pm2, MSDM2_2_1);
262  MSDM2 = MSDM2_2_1;
263  }
264  if(one_two && two_one)
265  {
266  MSDM2 = (MSDM2_1_2 + MSDM2_2_1) / 2.;
267  }
268  std::cout << "MSDM2 :" << MSDM2 << std::endl;
269 
270  // redraw meshes
271  viewer->draw_or_redraw_mesh(m1, pm1, true, false);
272  viewer->draw_or_redraw_mesh(m2, pm2, true, false);
273  }
274  else
275  {
276  QMessageBox::information(0,
277  "",
278  QObject::tr("MSDM2 filter can not be applied on meshes "
279  "with different data structures."));
280  }
281  }
282  else
283  {
284  QMessageBox::information(0,
285  "",
286  QObject::tr("MSDM2 filter needs two meshes opened "
287  "with the Surface_mesh data structure."));
288  }
289 
290  // comment next line to keep parameters between calls
291  reset();
292 
293 #if(FEVV_USE_QT5)
294  // empty
295 #else
296  viewer->frame(); // necessary or not ?
297 #endif
298  }
299 
300 #ifdef FEVV_USE_OPENMESH
301  void apply(BaseAdapterVisu *_adapter,
302  MeshOpenMesh *_mesh,
303  FEVV::PMapsContainer *pmaps_bag) override
304  {
305  applyHG< MeshOpenMesh >(_adapter, _mesh, pmaps_bag);
306  }
307 #endif
308 
309 #ifdef FEVV_USE_CGAL
310  void apply(BaseAdapterVisu *_adapter,
311  MeshLCC *_mesh,
312  FEVV::PMapsContainer *pmaps_bag) override
313  {
314  applyHG< MeshLCC >(_adapter, _mesh, pmaps_bag);
315  }
316 
317  void apply(BaseAdapterVisu *_adapter,
318  MeshSurface *_mesh,
319  FEVV::PMapsContainer *pmaps_bag) override
320  {
321  applyHG< MeshSurface >(_adapter, _mesh, pmaps_bag);
322  }
323 
324  void apply(BaseAdapterVisu *_adapter,
325  MeshPolyhedron *_mesh,
326  FEVV::PMapsContainer *pmaps_bag) override
327  {
328  applyHG< MeshPolyhedron >(_adapter, _mesh, pmaps_bag);
329  }
330 #endif
331 
332 #ifdef FEVV_USE_AIF
333  void apply(BaseAdapterVisu *_adapter,
334  MeshAIF *_mesh,
335  FEVV::PMapsContainer *pmaps_bag) override
336  {
337  applyHG< MeshAIF >(_adapter, _mesh, pmaps_bag);
338  }
339 #endif
340 
341 
342  QStringList Generic_plugins() const override
343  {
344  return QStringList() << "MSDM2Plugin";
345  }
346 
347  bool Generic_plugin(const QString &/*plugin*/) override
348  {
349  SimpleWindow *sw = static_cast< SimpleWindow * >(window);
350  // dynamic_cast fails under OS X
351  sw->onModificationParam("msdm2_qt_p", this);
352  sw->onApplyButton();
353 
354  return true;
355  }
356 
357 signals:
358  void resetSignal();
359 
360 protected:
361  bool one_two;
362  bool two_one;
363  int scales;
364  bool color;
366 };
367 
368 } // namespace FEVV
369 
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
FEVV::MSDM2Plugin::resetSignal
void resetSignal()
FEVV::MSDM2Plugin::color
bool color
Definition: MSDM2Plugin.h:364
minmax_map.h
FEVV::SimpleWindow::onApplyButton
void onApplyButton()
Definition: SimpleWindow.inl:525
FEVV::MSDM2Plugin::init
void init() override
Definition: MSDM2Plugin.h:68
FEVV::MeshLCC
CGAL::Linear_cell_complex_for_combinatorial_map< 2, 3, CGALLCCTraits, CGALItem > MeshLCC
Definition: DataStructures_cgal_linear_cell_complex.h:43
FEVV::DialogMSDM21
Definition: DialogMSDM21.h:23
tr
double tr(double &n)
Truncate a number to 1/1000 (only if BOOLEAN_OPERATIONS_DEBUG is enable)
Definition: boolops_definitions.hpp:127
FEVV::MSDM2Plugin::~MSDM2Plugin
~MSDM2Plugin()=default
FEVV::MSDM2Plugin::two_one
bool two_one
Definition: MSDM2Plugin.h:362
FEVV::has_map
bool has_map(const PMapsContainer &pmaps, const std::string &map_name)
(refer to Property Maps API)
Definition: properties.h:103
FEVV::MSDM2Plugin::addParameters
void addParameters(BaseWindow *_window) override
Definition: MSDM2Plugin.h:84
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
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::MSDM2Plugin::MSDM2Plugin
MSDM2Plugin()=default
FEVV::MeshSurface
CGAL::Surface_mesh< CGALPoint > MeshSurface
Definition: DataStructures_cgal_surface_mesh.h:23
FEVV::MSDM2Plugin::applyHG
void applyHG(BaseAdapterVisu *_adapter, HalfedgeGraph *, FEVV::PMapsContainer *)
Definition: MSDM2Plugin.h:213
FEVV::MSDM2Plugin::Generic_plugin
bool Generic_plugin(const QString &) override
Definition: MSDM2Plugin.h:347
FEVV::BaseAdapterVisu
Definition: BaseAdapterVisu.h:27
DialogMSDM21.h
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::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::MSDM2Plugin::LUT_CourbureClust
FEVV::Filters::ColorMeshLUT LUT_CourbureClust
Definition: MSDM2Plugin.h:365
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::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
FEVV::MSDM2Plugin::process
void process(MeshSurface &m_degraded, FEVV::PMapsContainer &pmaps_bag_degraded, MeshSurface &m_original, FEVV::PMapsContainer &pmaps_bag_original, double &MSDM2)
Definition: MSDM2Plugin.h:94
msdm2.h
properties_surface_mesh.h
FEVV::MSDM2Plugin::reset
void reset() override
Definition: MSDM2Plugin.h:77
FEVV::Filters::ColorMeshLUT
std::vector< float > ColorMeshLUT
Definition: color_mesh.h:25
FEVV::MSDM2Plugin::Generic_plugins
QStringList Generic_plugins() const override
Definition: MSDM2Plugin.h:342
FEVV::vertex_color
@ vertex_color
Definition: properties.h:47
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::MSDM2Plugin::one_two
bool one_two
Definition: MSDM2Plugin.h:361
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::MSDM2Plugin::process
void process(HalfedgeGraph &, FEVV::PMapsContainer &, HalfedgeGraph &, FEVV::PMapsContainer &, double &)
Definition: MSDM2Plugin.h:200
FEVV::Filters::process_msdm2_multires
double process_msdm2_multires(const HalfedgeGraph &m_poly_degrad, const PointMap &pm_degrad, const FaceNormalMap &fnm_degrad, FEVV::PMapsContainer &pmaps_degrad, const GeometryTraits &gt_degrad, const HalfedgeGraph &m_poly_original, const PointMap &pm_original, const FaceNormalMap &fnm_original, FEVV::PMapsContainer &, const GeometryTraits &, const int nb_level, VertexMSDM2Map &msdm2_pmap, const double maxdim, double &msdm2_value)
Definition: msdm2.h:274
BasePluginQt.h
properties_openmesh.h
FEVV::MeshOpenMesh
OpenMesh::PolyMesh_ArrayKernelT< MyTraits > MeshOpenMesh
Definition: DataStructures_openmesh.h:51
FEVV::Generic_PluginInterface
Definition: PluginInterface.h:37
FEVV::MSDM2Plugin
Definition: MSDM2Plugin.h:54
FEVV::DialogMSDM21::getProcess
void getProcess(bool &one_two, bool &two_one, int &scales, bool &colors)
Definition: DialogMSDM21.cpp:30
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::MSDM2Plugin::scales
int scales
Definition: MSDM2Plugin.h:363
FEVV::BasePlugin::window
BaseWindow * window
Definition: BasePlugin.h:138
FEVV::BaseWindow
Definition: BaseWindow.h:25
properties.h
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::MeshAIF
FEVV::DataStructures::AIF::AIFMesh MeshAIF
Definition: DataStructures_aif.h:19
FEVV::face_normal
@ face_normal
Definition: properties.h:77