MEPP2 Project
copy_graph_plugin.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 // A) include the header of the filter corresponding to your operation
34 
35 #ifdef FEVV_USE_CGAL
41 #endif // FEVV_USE_CGAL
42 #ifdef FEVV_USE_OPENMESH
44 #endif // FEVV_USE_OPENMESH
45 #ifdef FEVV_USE_AIF
47 #endif // FEVV_USE_AIF
48 #ifdef FEVV_USE_PCL
51 #endif // FEVV_USE_PCL
52 #endif
53 
54 namespace FEVV {
55 
56 class CopyGraphPlugin : public QObject,
58  public BasePluginQt
59 {
60  Q_OBJECT
61  Q_INTERFACES(FEVV::Generic_PluginInterface)
62 #if(FEVV_USE_QT5) // see at the end of .cpp for QT4
63  Q_PLUGIN_METADATA(IID "CopyGraphPlugin")
64 #endif
65 
66  /*public:
67  using BasePlugin::apply;*/
68 public:
69  CopyGraphPlugin() = default;
70  ~CopyGraphPlugin() = default;
71 
72 public:
73  void init() override
74  {
75  m_output_mesh_void = nullptr;
76  m_output_pmaps_bag = nullptr;
77  }
78 
79  void reset() override
80  {
81  init();
82 
83  emit resetSignal();
84  }
85 
86  void addParameters(BaseWindow *_window) override
87  {
88  window = _window;
89  if(window == nullptr || !window->isInit())
90  {
91  std::cerr << "BaseWindow is null or not initialized." << std::endl;
92  return;
93  }
94  }
95 
96  template< typename HalfedgeGraphS,
97  typename HalfedgeGraphT >
98  void process(const HalfedgeGraphS *_mesh,
99  const FEVV::PMapsContainer *pmaps_bag)
100  {
101  std::cout << "Asking to CopyGraph mesh ! " << std::endl;
102 
103  // create output mesh and pmaps bag
104  HalfedgeGraphT *output_mesh = new HalfedgeGraphT;
106 
107  // store output mesh for later display
108  m_output_mesh_void = static_cast< void * >(output_mesh);
109 
110  // apply filter
112  *_mesh, *pmaps_bag, *output_mesh, *m_output_pmaps_bag);
113  }
114 
115 
116  template< typename HalfedgeGraphS,
117  typename HalfedgeGraphT >
118  void applyHG(BaseAdapterVisu *_adapter,
119  HalfedgeGraphS *_mesh,
120  FEVV::PMapsContainer *pmaps_bag)
121  {
122  // note: disable dialog box because no need for now
124  //CopyGraphDialog dialog;
125  //dialog.setParameters(value_x, value_y, value_z);
126  //if(dialog.exec() == QDialog::Accepted)
127  // dialog.getParameters(value_x, value_y, value_z);
128  //else
129  // return; // abort applying filter
130 
131  // apply filter
132  process< HalfedgeGraphS, HalfedgeGraphT >(_mesh, pmaps_bag);
133 
134  // redraw mesh
135  SimpleViewer *viewer =
136  dynamic_cast< SimpleViewer * >(_adapter->getViewer());
137  if(viewer)
138  {
139  // draw output mesh
140  auto output_mesh = static_cast< HalfedgeGraphT * >(m_output_mesh_void);
141  if(output_mesh)
142  {
143  viewer->draw_or_redraw_mesh(output_mesh,
145  false,
146  false,
147  "COPY");
148  }
149  }
150 
151  // comment next line to keep parameters values between calls
152  reset();
153 
154 #if(FEVV_USE_QT5)
155  // empty
156 #else
157  viewer->frame(); // necessary or not ?
158 #endif
159  }
160 
161 
162 #ifdef FEVV_USE_OPENMESH
163  void apply(BaseAdapterVisu *_adapter,
164  MeshOpenMesh *_mesh,
165  FEVV::PMapsContainer *pmaps_bag) override
166  {
167  apply_choose_output< MeshOpenMesh >(_adapter, _mesh, pmaps_bag);
168  }
169 #endif
170 
171 #ifdef FEVV_USE_CGAL
172  void apply(BaseAdapterVisu *_adapter,
173  MeshLCC *_mesh,
174  FEVV::PMapsContainer *pmaps_bag) override
175  {
176  apply_choose_output< MeshLCC >(_adapter, _mesh, pmaps_bag);
177  }
178 
179  void apply(BaseAdapterVisu *_adapter,
180  MeshSurface *_mesh,
181  FEVV::PMapsContainer *pmaps_bag) override
182  {
183  apply_choose_output< MeshSurface >(_adapter, _mesh, pmaps_bag);
184  }
185 
186  void apply(BaseAdapterVisu *_adapter,
187  MeshPolyhedron *_mesh,
188  FEVV::PMapsContainer *pmaps_bag) override
189  {
190  apply_choose_output< MeshPolyhedron >(_adapter, _mesh, pmaps_bag);
191  }
192 
193  void apply(BaseAdapterVisu *_adapter,
194  CGALPointSet *_mesh,
195  FEVV::PMapsContainer *pmaps_bag) override
196  {
197  apply_choose_output< CGALPointSet >(_adapter, _mesh, pmaps_bag);
198  }
199 #endif
200 
201 #ifdef FEVV_USE_AIF
202  void apply(BaseAdapterVisu *_adapter,
203  MeshAIF *_mesh,
204  FEVV::PMapsContainer *pmaps_bag) override
205  {
206  apply_choose_output< MeshAIF >(_adapter, _mesh, pmaps_bag);
207  }
208 #endif
209 
210 #ifdef FEVV_USE_PCL
211  void apply(BaseAdapterVisu *_adapter,
212  PCLPointCloud *_mesh,
213  FEVV::PMapsContainer *pmaps_bag) override
214  {
215  apply_choose_output< PCLPointCloud >(_adapter, _mesh, pmaps_bag);
216  }
217 #endif
218 
219 
220  template< typename MeshT >
222  MeshT *_mesh,
223  FEVV::PMapsContainer *pmaps_bag)
224  {
225  // ask the user for the datastructure
226  std::string mesh_type = chooseDatastructureMsgBox();
227  if(mesh_type == "NONE")
228  return; // cancel pressed, aborting
229 
230  // apply plugin
231  if(false)
232  {
233  // dummy case to be able to write all other cases as 'else if'
234  }
235 #ifdef FEVV_USE_CGAL
236  else if(mesh_type == "POLYHEDRON")
237  {
238  applyHG< MeshT, MeshPolyhedron >(_adapter, _mesh, pmaps_bag);
239  }
240  else if(mesh_type == "SURFACEMESH")
241  {
242  applyHG< MeshT, MeshSurface >(_adapter, _mesh, pmaps_bag);
243  }
244  else if(mesh_type == "LCC")
245  {
246  applyHG< MeshT, MeshLCC >(_adapter, _mesh, pmaps_bag);
247  }
248  else if(mesh_type == "CGALPOINTSET")
249  {
250  applyHG< MeshT, CGALPointSet >(_adapter, _mesh, pmaps_bag);
251  }
252 #endif
253 #ifdef FEVV_USE_OPENMESH
254  else if(mesh_type == "OPENMESH")
255  {
256  applyHG< MeshT, MeshOpenMesh >(_adapter, _mesh, pmaps_bag);
257  }
258 #endif
259 #ifdef FEVV_USE_AIF
260  else if(mesh_type == "AIF")
261  {
262  applyHG< MeshT, MeshAIF >(_adapter, _mesh, pmaps_bag);
263  }
264 #endif
265 #ifdef FEVV_USE_PCL
266  else if(mesh_type == "PCLPOINTCLOUD")
267  {
268  applyHG< MeshT, PCLPointCloud >(_adapter, _mesh, pmaps_bag);
269  }
270 #endif
271  else
272  {
273  QMessageBox::information(0,
274  "",
275  QObject::tr("Copy Graph is not yet compatible "
276  "with the datastructure you have "
277  "chosen!"));
278  }
279  }
280 
281 
282  QStringList Generic_plugins() const override
283  {
284  return QStringList() << "CopyGraphPlugin";
285  }
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("copy_graph_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 output
311 };
312 
313 } // namespace FEVV
314 
FEVV::BaseWindow::isInit
virtual bool isInit() const
Definition: BaseWindow.h:103
FEVV::Filters::copy_graph
void copy_graph(const FEVV::CGALPointSet &pc_s, const FEVV::PMapsContainer &pmaps_s, PointCloudT &pc_t, FEVV::PMapsContainer &pmaps_t, const Parameters &params, const GeometryTraitsS &gt_s, const GeometryTraitsT &gt_t)
Overloading of copy_graph() for CGAL Point Set copy from.
Definition: copy_graph_cgal_point_set.hpp:43
FEVV::CGALPointSet
CGAL::Point_set_3< CGALPointSetPoint > CGALPointSet
Definition: DataStructures_cgal_point_set.h:71
FEVV::CopyGraphPlugin::process
void process(const HalfedgeGraphS *_mesh, const FEVV::PMapsContainer *pmaps_bag)
Definition: copy_graph_plugin.h:98
FEVV::CopyGraphPlugin
Definition: copy_graph_plugin.h:59
copy_graph_pcl.hpp
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::CopyGraphPlugin::m_output_mesh_void
void * m_output_mesh_void
Definition: copy_graph_plugin.h:309
FEVV::CopyGraphPlugin::Generic_plugin
bool Generic_plugin(const QString &) override
Definition: copy_graph_plugin.h:288
FEVV::BasePluginQt
This class is intended to provide some standard message boxes to all plugins.
Definition: BasePluginQt.h:30
SimpleWindow.h
FEVV::PCLPointCloud
pcl::PointCloud< PCLEnrichedPoint > PCLPointCloud
Definition: DataStructures_pcl_point_cloud.h:28
FEVV::BaseAdapterVisu::getViewer
virtual Viewer * getViewer()
Definition: BaseAdapterVisu.h:130
FEVV::CopyGraphPlugin::~CopyGraphPlugin
~CopyGraphPlugin()=default
copy_graph.hpp
properties_linear_cell_complex.h
FEVV::MeshSurface
CGAL::Surface_mesh< CGALPoint > MeshSurface
Definition: DataStructures_cgal_surface_mesh.h:23
FEVV::BaseAdapterVisu
Definition: BaseAdapterVisu.h:27
properties_aif.h
FEVV::CopyGraphPlugin::applyHG
void applyHG(BaseAdapterVisu *_adapter, HalfedgeGraphS *_mesh, FEVV::PMapsContainer *pmaps_bag)
Definition: copy_graph_plugin.h:118
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::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::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::CopyGraphPlugin::addParameters
void addParameters(BaseWindow *_window) override
Definition: copy_graph_plugin.h:86
properties_surface_mesh.h
FEVV::CopyGraphPlugin::apply_choose_output
void apply_choose_output(BaseAdapterVisu *_adapter, MeshT *_mesh, FEVV::PMapsContainer *pmaps_bag)
Definition: copy_graph_plugin.h:221
copy_graph_dialog.h
FEVV::CopyGraphPlugin::resetSignal
void resetSignal()
SimpleViewer.h
properties_pcl_point_cloud.h
BasePluginQt.h
properties_openmesh.h
FEVV::CopyGraphPlugin::init
void init() override
Definition: copy_graph_plugin.h:73
FEVV::MeshOpenMesh
OpenMesh::PolyMesh_ArrayKernelT< MyTraits > MeshOpenMesh
Definition: DataStructures_openmesh.h:51
FEVV::Generic_PluginInterface
Definition: PluginInterface.h:37
FEVV::DataStructures::AIF::AIFMesh
This class represents an AIF structure. AIF structure can deal with both manifold and non-manifold su...
Definition: AIFMesh.hpp:47
FEVV::CopyGraphPlugin::Generic_plugins
QStringList Generic_plugins() const override
Definition: copy_graph_plugin.h:282
FEVV::BasePluginQt::apply
virtual void apply(BaseAdapterVisu *, void *, FEVV::PMapsContainer *) override
Definition: BasePluginQt.h:108
FEVV::CopyGraphPlugin::CopyGraphPlugin
CopyGraphPlugin()=default
copy_graph_cgal_point_set.hpp
FEVV::CopyGraphPlugin::reset
void reset() override
Definition: copy_graph_plugin.h:79
PluginInterface.h
FEVV::BasePlugin::window
BaseWindow * window
Definition: BasePlugin.h:138
FEVV::BaseWindow
Definition: BaseWindow.h:25
properties.h
properties_cgal_point_set.h
FEVV::CopyGraphPlugin::m_output_pmaps_bag
FEVV::PMapsContainer * m_output_pmaps_bag
Definition: copy_graph_plugin.h:310
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