MEPP2 Project
helloworld_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
33 
35 
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 HelloworldPlugin : 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 "HelloworldPlugin")
59 #endif
60 
61  /*public:
62  using BasePlugin::apply;*/
63 public:
64  HelloworldPlugin() = default;
65  ~HelloworldPlugin() = default;
66 
67 public:
68  void init() override { init(1.0, 1.0, 1.0); }
69 
70  void init(double _x, double _y, double _z)
71  {
72  value_x = _x;
73  value_y = _y;
74  value_z = _z;
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  template< typename HalfedgeGraph >
95  void process(HalfedgeGraph *_mesh, FEVV::PMapsContainer *pmaps_bag)
96  {
97  std::cout << "Asking to Helloworld mesh ! " << std::endl;
98 
99  // retrieve or create vertex-color property map
100  using VertexColorMap =
102  HalfedgeGraph >::pmap_type;
103  VertexColorMap v_cm;
104  if(has_map(*pmaps_bag, FEVV::vertex_color))
105  {
106  std::cout << "use existing vertex-color map" << std::endl;
107  v_cm = get_property_map(FEVV::vertex_color, *_mesh, *pmaps_bag);
108  }
109  else
110  {
111  std::cout << "create vertex-color map" << std::endl;
112  v_cm = make_property_map(FEVV::vertex_color, *_mesh);
113  // store property map in property maps bag
114  put_property_map(FEVV::vertex_color, *_mesh, *pmaps_bag, v_cm);
115  }
116 
117  // retrieve or create vertex-normal property map
118  using VertexNormalMap =
120  HalfedgeGraph >::pmap_type;
121  VertexNormalMap v_nm;
122  if(has_map(*pmaps_bag, FEVV::vertex_normal))
123  {
124  std::cout << "use existing vertex-normal map" << std::endl;
125  v_nm = get_property_map(FEVV::vertex_normal, *_mesh, *pmaps_bag);
126  }
127  else
128  {
129  std::cout << "create vertex-normal map" << std::endl;
130  v_nm = make_property_map(FEVV::vertex_normal, *_mesh);
131  // store property map in property maps bag
132  put_property_map(FEVV::vertex_normal, *_mesh, *pmaps_bag, v_nm);
133  }
134 
135  // retrieve point property map (aka geometry)
136  auto pm = get(boost::vertex_point, *_mesh);
137 
138  // apply filter
139  // B) call the filter corresponding to your operation
140  helloworld_filter(*_mesh, pm, v_cm, v_nm);
141 
142  std::cout << "Helloworld mesh of " << value_x << ";" << value_y << ";"
143  << value_z << "." << std::endl;
144  }
145 
146 
147  template< typename HalfedgeGraph >
148  void applyHG(BaseAdapterVisu *_adapter,
149  HalfedgeGraph *_mesh,
150  FEVV::PMapsContainer *pmaps_bag)
151  {
152  // get filter parameters from dialog window
153  HelloworldDialog dialog;
155  if(dialog.exec() == QDialog::Accepted)
157  else
158  return; // abort applying filter
159 
160  // apply filter
161  process(_mesh, pmaps_bag);
162 
163  // redraw mesh
164  SimpleViewer *viewer =
165  dynamic_cast< SimpleViewer * >(_adapter->getViewer());
166  if(viewer)
167  viewer->draw_or_redraw_mesh(_mesh, pmaps_bag, true, false);
168 
169  // comment next line to keep parameters values between calls
170  reset();
171 
172 #if(FEVV_USE_QT5)
173  // empty
174 #else
175  viewer->frame(); // necessary or not ?
176 #endif
177  }
178 
179 
180 #ifdef FEVV_USE_OPENMESH
181  void apply(BaseAdapterVisu *_adapter,
182  MeshOpenMesh *_mesh,
183  FEVV::PMapsContainer *pmaps_bag) override
184  {
185  applyHG< MeshOpenMesh >(_adapter, _mesh, pmaps_bag);
186  }
187 #endif
188 
189 #ifdef FEVV_USE_CGAL
190  void apply(BaseAdapterVisu *_adapter,
191  MeshLCC *_mesh,
192  FEVV::PMapsContainer *pmaps_bag) override
193  {
194  applyHG< MeshLCC >(_adapter, _mesh, pmaps_bag);
195  }
196 
197  void apply(BaseAdapterVisu *_adapter,
198  MeshSurface *_mesh,
199  FEVV::PMapsContainer *pmaps_bag) override
200  {
201  applyHG< MeshSurface >(_adapter, _mesh, pmaps_bag);
202  }
203 
204  void apply(BaseAdapterVisu *_adapter,
205  MeshPolyhedron *_mesh,
206  FEVV::PMapsContainer *pmaps_bag) override
207  {
208  applyHG< MeshPolyhedron >(_adapter, _mesh, pmaps_bag);
209  }
210 #endif
211 
212 #ifdef FEVV_USE_AIF
213  void apply(BaseAdapterVisu *_adapter,
214  MeshAIF *_mesh,
215  FEVV::PMapsContainer *pmaps_bag) override
216  {
217  applyHG< MeshAIF >(_adapter, _mesh, pmaps_bag);
218  }
219 #endif
220 
221 
222  QStringList Generic_plugins() const override
223  {
224  return QStringList() << "HelloworldPlugin";
225  }
226 
227 
228  bool Generic_plugin(const QString &/*plugin*/) override
229  {
230  SimpleWindow *sw = static_cast< SimpleWindow * >(window);
231  // dynamic_cast fails under OS X
232  sw->onModificationParam("helloworld_qt_p", this);
233  //TODO-elo-refactor-plugins
234  // 1) the name of the function onModificationParam()
235  // is unrelated to its content!!!
236  // 2) Generic_plugin() is called by SimpleWindow
237  // and calls back SimpleWindow functions here ;
238  // looks like a bad architecture
239  sw->onApplyButton();
240 
241  return true;
242  }
243 
244 signals:
245  void resetSignal();
246 
247 protected:
248  // filter parameters
249  double value_x = 0;
250  double value_y = 0;
251  double value_z = 0;
252 };
253 
254 } // namespace FEVV
255 
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::get_property_map
PMap_traits< PropertyT, MeshT >::pmap_type get_property_map(PropertyT p, const MeshT &, const PMapsContainer &pmaps)
Definition: properties.h:646
FEVV::HelloworldDialog::getParameters
void getParameters(double &x, double &y, double &z)
Definition: helloworld_dialog.cpp:38
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::HelloworldPlugin::value_x
double value_x
Definition: helloworld_plugin.h:249
FEVV::has_map
bool has_map(const PMapsContainer &pmaps, const std::string &map_name)
(refer to Property Maps API)
Definition: properties.h:103
FEVV::HelloworldDialog
Definition: helloworld_dialog.h:23
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
FEVV::HelloworldPlugin
Definition: helloworld_plugin.h:54
FEVV::MeshSurface
CGAL::Surface_mesh< CGALPoint > MeshSurface
Definition: DataStructures_cgal_surface_mesh.h:23
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::HelloworldPlugin::Generic_plugins
QStringList Generic_plugins() const override
Definition: helloworld_plugin.h:222
FEVV::vertex_normal_t
vertex_normal_t
Definition: properties.h:35
FEVV::HelloworldPlugin::resetSignal
void resetSignal()
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::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
helloworld_dialog.h
helloworld_filter
void helloworld_filter(const HalfedgeGraph &g, PointMap &pm, VertexColorMap &v_cm, VertexNormalMap &v_nm, const GeometryTraits &gt)
Refer here for a detailed presentation of that filter example, what it does and how to use it.
Definition: helloworld_filter.hpp:27
FEVV::HelloworldPlugin::addParameters
void addParameters(BaseWindow *_window) override
Definition: helloworld_plugin.h:84
properties_surface_mesh.h
FEVV::HelloworldPlugin::process
void process(HalfedgeGraph *_mesh, FEVV::PMapsContainer *pmaps_bag)
Definition: helloworld_plugin.h:95
FEVV::vertex_color
@ vertex_color
Definition: properties.h:47
SimpleViewer.h
FEVV::HelloworldPlugin::init
void init() override
Definition: helloworld_plugin.h:68
FEVV::HelloworldPlugin::value_y
double value_y
Definition: helloworld_plugin.h:250
FEVV::HelloworldPlugin::value_z
double value_z
Definition: helloworld_plugin.h:251
BasePluginQt.h
properties_openmesh.h
FEVV::HelloworldPlugin::init
void init(double _x, double _y, double _z)
Definition: helloworld_plugin.h:70
FEVV::MeshOpenMesh
OpenMesh::PolyMesh_ArrayKernelT< MyTraits > MeshOpenMesh
Definition: DataStructures_openmesh.h:51
FEVV::Generic_PluginInterface
Definition: PluginInterface.h:37
FEVV::HelloworldPlugin::reset
void reset() override
Definition: helloworld_plugin.h:77
FEVV::HelloworldPlugin::~HelloworldPlugin
~HelloworldPlugin()=default
FEVV::BasePluginQt::apply
virtual void apply(BaseAdapterVisu *, void *, FEVV::PMapsContainer *) override
Definition: BasePluginQt.h:108
FEVV::HelloworldPlugin::HelloworldPlugin
HelloworldPlugin()=default
FEVV::HelloworldPlugin::applyHG
void applyHG(BaseAdapterVisu *_adapter, HalfedgeGraph *_mesh, FEVV::PMapsContainer *pmaps_bag)
Definition: helloworld_plugin.h:148
FEVV::HelloworldPlugin::Generic_plugin
bool Generic_plugin(const QString &) override
Definition: helloworld_plugin.h:228
PluginInterface.h
helloworld_filter.hpp
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::vertex_normal
@ vertex_normal
Definition: properties.h:35
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::HelloworldDialog::setParameters
void setParameters(double x, double y, double z)
Definition: helloworld_dialog.cpp:30