MEPP2 Project
texture_image_demo_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 TextureImageDemoPlugin : 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 "TextureImageDemoPlugin")
59 #endif
60 
61  /*public:
62  using BasePlugin::apply;*/
63 public:
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  /*
73  value_x = _x;
74  value_y = _y;
75  value_z = _z;
76  */
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 HalfedgeGraph >
97  void process(HalfedgeGraph *_mesh, FEVV::PMapsContainer *pmaps_bag)
98  {
99  std::cout << "Asking to TextureImageDemo mesh ! " << std::endl;
100 
101  // retrieve the materials property map
102 
103  if(! has_map(*pmaps_bag, FEVV::mesh_materials))
104  {
105  std::cout << "The mesh has no materials. Aborting." << std::endl;
106  return;
107  }
108 
109  std::cout << "retrieve existing mesh_materials property map" << std::endl;
110  auto mtl_pm = get_property_map(FEVV::mesh_materials, *_mesh, *pmaps_bag);
111 
112  // apply filter
113  // B) call the filter corresponding to your operation
114  texture_image_demo_filter(*_mesh, mtl_pm);
115 
116  std::cout << "TextureImageDemo successfully applied." << std::endl;
117  }
118 
119 
120  template< typename HalfedgeGraph >
121  void applyHG(BaseAdapterVisu *_adapter,
122  HalfedgeGraph *_mesh,
123  FEVV::PMapsContainer *pmaps_bag)
124  {
125  // get filter parameters from dialog window
126  TextureImageDemoDialog dialog;
127  dialog.setParameters(/*value_x, value_y, value_z*/);
128  if(dialog.exec() == QDialog::Accepted)
129  dialog.getParameters(/*value_x, value_y, value_z*/);
130  else
131  return; // abort applying filter
132 
133  // apply filter
134  process(_mesh, pmaps_bag);
135 
136  // redraw mesh
137  SimpleViewer *viewer =
138  dynamic_cast< SimpleViewer * >(_adapter->getViewer());
139  if(viewer)
140  viewer->draw_or_redraw_mesh(_mesh, pmaps_bag, true, false);
141 
142  // comment next line to keep parameters values between calls
143  reset();
144 
145 #if(FEVV_USE_QT5)
146  // empty
147 #else
148  viewer->frame(); // necessary or not ?
149 #endif
150  }
151 
152 
153 #ifdef FEVV_USE_OPENMESH
154  void apply(BaseAdapterVisu *_adapter,
155  MeshOpenMesh *_mesh,
156  FEVV::PMapsContainer *pmaps_bag) override
157  {
158  applyHG< MeshOpenMesh >(_adapter, _mesh, pmaps_bag);
159  }
160 #endif
161 
162 #ifdef FEVV_USE_CGAL
163  void apply(BaseAdapterVisu *_adapter,
164  MeshLCC *_mesh,
165  FEVV::PMapsContainer *pmaps_bag) override
166  {
167  applyHG< MeshLCC >(_adapter, _mesh, pmaps_bag);
168  }
169 
170  void apply(BaseAdapterVisu *_adapter,
171  MeshSurface *_mesh,
172  FEVV::PMapsContainer *pmaps_bag) override
173  {
174  applyHG< MeshSurface >(_adapter, _mesh, pmaps_bag);
175  }
176 
177  void apply(BaseAdapterVisu *_adapter,
178  MeshPolyhedron *_mesh,
179  FEVV::PMapsContainer *pmaps_bag) override
180  {
181  applyHG< MeshPolyhedron >(_adapter, _mesh, pmaps_bag);
182  }
183 #endif
184 
185 #ifdef FEVV_USE_AIF
186  void apply(BaseAdapterVisu *_adapter,
187  MeshAIF *_mesh,
188  FEVV::PMapsContainer *pmaps_bag) override
189  {
190  applyHG< MeshAIF >(_adapter, _mesh, pmaps_bag);
191  }
192 #endif
193 
194 
195  QStringList Generic_plugins() const override
196  {
197  return QStringList() << "TextureImageDemoPlugin";
198  }
199 
200 
201  bool Generic_plugin(const QString &/*plugin*/) override
202  {
203  SimpleWindow *sw = static_cast< SimpleWindow * >(window);
204  // dynamic_cast fails under OS X
205  sw->onModificationParam("texture_image_demo_qt_p", this);
206  //TODO-elo-refactor-plugins
207  // 1) the name of the function onModificationParam()
208  // is unrelated to its content!!!
209  // 2) Generic_plugin() is called by SimpleWindow
210  // and calls back SimpleWindow functions here ;
211  // looks like a bad architecture
212  sw->onApplyButton();
213 
214  return true;
215  }
216 
217 signals:
218  void resetSignal();
219 
220 protected:
221  // filter parameters
222  /*
223  double value_x = 0;
224  double value_y = 0;
225  double value_z = 0;
226  */
227 };
228 
229 } // namespace FEVV
230 
FEVV::BaseWindow::isInit
virtual bool isInit() const
Definition: BaseWindow.h:103
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::TextureImageDemoPlugin::process
void process(HalfedgeGraph *_mesh, FEVV::PMapsContainer *pmaps_bag)
Definition: texture_image_demo_plugin.h:97
FEVV::SimpleWindow::onApplyButton
void onApplyButton()
Definition: SimpleWindow.inl:525
FEVV::TextureImageDemoPlugin::Generic_plugin
bool Generic_plugin(const QString &) override
Definition: texture_image_demo_plugin.h:201
FEVV::mesh_materials
@ mesh_materials
Definition: properties.h:89
FEVV::TextureImageDemoPlugin::TextureImageDemoPlugin
TextureImageDemoPlugin()=default
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::TextureImageDemoPlugin::resetSignal
void resetSignal()
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::TextureImageDemoPlugin::init
void init(double, double, double)
Definition: texture_image_demo_plugin.h:70
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::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::TextureImageDemoPlugin::reset
void reset() override
Definition: texture_image_demo_plugin.h:79
properties_surface_mesh.h
SimpleViewer.h
FEVV::TextureImageDemoPlugin::addParameters
void addParameters(BaseWindow *_window) override
Definition: texture_image_demo_plugin.h:86
texture_image_demo_filter.hpp
FEVV::TextureImageDemoPlugin::~TextureImageDemoPlugin
~TextureImageDemoPlugin()=default
FEVV::TextureImageDemoDialog
Definition: texture_image_demo_dialog.h:23
FEVV::TextureImageDemoPlugin
Definition: texture_image_demo_plugin.h:54
FEVV::TextureImageDemoDialog::getParameters
void getParameters()
Definition: texture_image_demo_dialog.cpp:40
FEVV::TextureImageDemoPlugin::Generic_plugins
QStringList Generic_plugins() const override
Definition: texture_image_demo_plugin.h:195
BasePluginQt.h
properties_openmesh.h
FEVV::TextureImageDemoPlugin::applyHG
void applyHG(BaseAdapterVisu *_adapter, HalfedgeGraph *_mesh, FEVV::PMapsContainer *pmaps_bag)
Definition: texture_image_demo_plugin.h:121
FEVV::MeshOpenMesh
OpenMesh::PolyMesh_ArrayKernelT< MyTraits > MeshOpenMesh
Definition: DataStructures_openmesh.h:51
FEVV::Generic_PluginInterface
Definition: PluginInterface.h:37
texture_image_demo_filter
void texture_image_demo_filter(const HalfedgeGraph &, MaterialMap &mtl_pm, const GeometryTraits &)
Definition: texture_image_demo_filter.hpp:24
FEVV::BasePluginQt::apply
virtual void apply(BaseAdapterVisu *, void *, FEVV::PMapsContainer *) override
Definition: BasePluginQt.h:108
FEVV::TextureImageDemoPlugin::init
void init() override
Definition: texture_image_demo_plugin.h:68
PluginInterface.h
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::TextureImageDemoDialog::setParameters
void setParameters()
Definition: texture_image_demo_dialog.cpp:30
FEVV::MeshAIF
FEVV::DataStructures::AIF::AIFMesh MeshAIF
Definition: DataStructures_aif.h:19
texture_image_demo_dialog.h