MEPP2 Project
ScalingPlugin.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/DialogScaling1.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/Generic/scaling.hpp" // A) include the header of the filter corresponding to your operation
32 
34 
35 #ifdef FEVV_USE_CGAL
39 #endif // FEVV_USE_CGAL
40 #ifdef FEVV_USE_OPENMESH
42 #endif // FEVV_USE_OPENMESH
43 #ifdef FEVV_USE_AIF
45 #endif // FEVV_USE_AIF
46 #endif
47 
48 namespace FEVV {
49 
50 class ScalingPlugin : public QObject,
52  public BasePluginQt
53 {
54  Q_OBJECT
55  Q_INTERFACES(FEVV::Generic_PluginInterface)
56 #if(FEVV_USE_QT5) // see at the end of .cpp for QT4
57  Q_PLUGIN_METADATA(IID "ScalingPlugin")
58 #endif
59 
60  /*public:
61  using BasePlugin::apply;*/
62 public:
63  ScalingPlugin() = default;
64  ~ScalingPlugin() = default;
65 
66 public:
67  void init() override { init(1.0, 1.0, 1.0); }
68 
69  void init(double _x, double _y, double _z)
70  {
71  *value_x = _x;
72  *value_y = _y;
73  *value_z = _z;
74  }
75 
76  void reset() override
77  {
78  init();
79 
80  emit resetSignal();
81  }
82 
83  void addParameters(BaseWindow *_window) override
84  {
85  window = _window;
86  if(window == nullptr || !window->isInit())
87  {
88  std::cerr << "BaseWindow is null or not initialized." << std::endl;
89  return;
90  }
91 
92  // window->setParam( "(Qt) Scale: X", value_x, "scaling_qt_p", this );
93  // window->setParam( "(Qt) Scale: Y", value_y, "scaling_qt_p", this );
94  // window->setParam( "(Qt) Scale: Z", value_z, "scaling_qt_p", this );
95  }
96 
97  template< typename HalfedgeGraph >
98  void scale(HalfedgeGraph *_mesh)
99  {
100  std::cout << "Asking to Scale mesh ! " << std::endl;
101 
102  auto pm = get(boost::vertex_point, *_mesh);
103 
104  Filters::calculate_scaling( // B) call the filter corresponding to your
105  // operation
106  *_mesh,
107  pm,
108  *value_x,
109  *value_y,
110  *value_z);
111 
112  std::cout << "Scale mesh of " << *value_x << ";" << *value_y << ";"
113  << *value_z << "." << std::endl;
114  }
115 
116  template< typename HalfedgeGraph >
117  void applyHG(BaseAdapterVisu *_adapter,
118  HalfedgeGraph *_mesh,
119  FEVV::PMapsContainer *pmaps_bag)
120  {
121  // get filter parameters from dialog window
122  DialogScaling1 dial1;
123  dial1.setScale(*value_x, *value_y, *value_z);
124  if(dial1.exec() == QDialog::Accepted)
125  dial1.getScale(*value_x, *value_y, *value_z);
126  else
127  return; // abort applying filter
128 
129  // apply filter
130  scale(_mesh);
131 
132  // redraw mesh
133  SimpleViewer *viewer =
134  dynamic_cast< SimpleViewer * >(_adapter->getViewer());
135  if(viewer)
136  viewer->draw_or_redraw_mesh(_mesh, pmaps_bag, true, false);
137 
138  reset();
139 
140 #if(FEVV_USE_QT5)
141  // empty
142 #else
143  viewer->frame(); // necessary or not ?
144 #endif
145  }
146 
147 #ifdef FEVV_USE_OPENMESH
148  void apply(BaseAdapterVisu *_adapter,
149  MeshOpenMesh *_mesh,
150  FEVV::PMapsContainer *pmaps_bag) override
151  {
152  applyHG< MeshOpenMesh >(_adapter, _mesh, pmaps_bag);
153  }
154 #endif
155 
156 #ifdef FEVV_USE_CGAL
157  void apply(BaseAdapterVisu *_adapter,
158  MeshLCC *_mesh,
159  FEVV::PMapsContainer *pmaps_bag) override
160  {
161  applyHG< MeshLCC >(_adapter, _mesh, pmaps_bag);
162  }
163 
164  void apply(BaseAdapterVisu *_adapter,
165  MeshSurface *_mesh,
166  FEVV::PMapsContainer *pmaps_bag) override
167  {
168  applyHG< MeshSurface >(_adapter, _mesh, pmaps_bag);
169  }
170 
171  void apply(BaseAdapterVisu *_adapter,
172  MeshPolyhedron *_mesh,
173  FEVV::PMapsContainer *pmaps_bag) override
174  {
175  applyHG< MeshPolyhedron >(_adapter, _mesh, pmaps_bag);
176  }
177 
178  void apply(BaseAdapterVisu *_adapter,
179  CGALPointSet *_mesh,
180  FEVV::PMapsContainer *pmaps_bag) override
181  {
182  applyHG< CGALPointSet >(_adapter, _mesh, pmaps_bag);
183  }
184 #endif
185 
186 #ifdef FEVV_USE_AIF
187  void apply(BaseAdapterVisu *_adapter,
188  MeshAIF *_mesh,
189  FEVV::PMapsContainer *pmaps_bag) override
190  {
191  applyHG< MeshAIF >(_adapter, _mesh, pmaps_bag);
192  }
193 #endif
194 
195 #ifdef FEVV_USE_PCL
196  void apply(BaseAdapterVisu *_adapter,
197  PCLPointCloud *_mesh,
198  FEVV::PMapsContainer *pmaps_bag) override
199  {
200  applyHG< PCLPointCloud >(_adapter, _mesh, pmaps_bag);
201  }
202 #endif
203 
204 
205  QStringList Generic_plugins() const override
206  {
207  return QStringList() << "ScalingPlugin";
208  }
209 
210  bool Generic_plugin(const QString &/*plugin*/) override
211  {
212  SimpleWindow *sw = static_cast< SimpleWindow * >(window);
213  // dynamic_cast fails under OS X
214  sw->onModificationParam("scaling_qt_p", this);
215  sw->onApplyButton();
216 
217  return true;
218  }
219 
220 signals:
221  void resetSignal();
222 
223 protected:
224  double *value_x = new double(0.0);
225  double *value_y = new double(0.0);
226  double *value_z = new double(0.0);
227 };
228 
229 } // namespace FEVV
230 
FEVV::BaseWindow::isInit
virtual bool isInit() const
Definition: BaseWindow.h:103
FEVV::ScalingPlugin::init
void init(double _x, double _y, double _z)
Definition: ScalingPlugin.h:69
FEVV::CGALPointSet
CGAL::Point_set_3< CGALPointSetPoint > CGALPointSet
Definition: DataStructures_cgal_point_set.h:71
FEVV::ScalingPlugin::value_y
double * value_y
Definition: ScalingPlugin.h:225
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::ScalingPlugin::resetSignal
void resetSignal()
FEVV::BasePluginQt
This class is intended to provide some standard message boxes to all plugins.
Definition: BasePluginQt.h:30
FEVV::ScalingPlugin::value_x
double * value_x
Definition: ScalingPlugin.h:224
FEVV::ScalingPlugin
Definition: ScalingPlugin.h:53
FEVV::DialogScaling1::setScale
void setScale(double x, double y, double z)
Definition: DialogScaling1.cpp: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
properties_linear_cell_complex.h
FEVV::ScalingPlugin::reset
void reset() override
Definition: ScalingPlugin.h:76
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::Filters::calculate_scaling
void calculate_scaling(Graph &g, PointMap &pm, typename GeometryTraits::Scalar scale_x, typename GeometryTraits::Scalar scale_y, typename GeometryTraits::Scalar scale_z, const GeometryTraits &gt)
Scale a mesh.
Definition: scaling.hpp:38
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::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
DialogScaling1.h
FEVV::ScalingPlugin::value_z
double * value_z
Definition: ScalingPlugin.h:226
FEVV::ScalingPlugin::init
void init() override
Definition: ScalingPlugin.h:67
SimpleViewer.h
scaling.hpp
FEVV::ScalingPlugin::Generic_plugins
QStringList Generic_plugins() const override
Definition: ScalingPlugin.h:205
BasePluginQt.h
properties_openmesh.h
FEVV::DialogScaling1
Definition: DialogScaling1.h:23
FEVV::MeshOpenMesh
OpenMesh::PolyMesh_ArrayKernelT< MyTraits > MeshOpenMesh
Definition: DataStructures_openmesh.h:51
FEVV::ScalingPlugin::Generic_plugin
bool Generic_plugin(const QString &) override
Definition: ScalingPlugin.h:210
FEVV::Generic_PluginInterface
Definition: PluginInterface.h:37
FEVV::BasePluginQt::apply
virtual void apply(BaseAdapterVisu *, void *, FEVV::PMapsContainer *) override
Definition: BasePluginQt.h:108
FEVV::ScalingPlugin::addParameters
void addParameters(BaseWindow *_window) override
Definition: ScalingPlugin.h:83
PluginInterface.h
FEVV::ScalingPlugin::ScalingPlugin
ScalingPlugin()=default
FEVV::ScalingPlugin::applyHG
void applyHG(BaseAdapterVisu *_adapter, HalfedgeGraph *_mesh, FEVV::PMapsContainer *pmaps_bag)
Definition: ScalingPlugin.h:117
FEVV::BasePlugin::window
BaseWindow * window
Definition: BasePlugin.h:138
FEVV::BaseWindow
Definition: BaseWindow.h:25
properties.h
FEVV::ScalingPlugin::scale
void scale(HalfedgeGraph *_mesh)
Definition: ScalingPlugin.h:98
FEVV::MeshPolyhedron
CGAL::Polyhedron_3< CGALKernel, CGAL::Polyhedron_items_with_id_3 > MeshPolyhedron
Definition: DataStructures_cgal_polyhedron_3.h:33
FEVV::ScalingPlugin::~ScalingPlugin
~ScalingPlugin()=default
FEVV::DialogScaling1::getScale
void getScale(double &x, double &y, double &z)
Definition: DialogScaling1.cpp:38
FEVV::MeshAIF
FEVV::DataStructures::AIF::AIFMesh MeshAIF
Definition: DataStructures_aif.h:19