MEPP2 Project
weightedPCA_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 // the header of the filter corresponding to the 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 #ifdef FEVV_USE_PCL
49 #endif // FEVV_USE_AIF
50 #endif // Q_MOC_RUN
51 
52 namespace FEVV {
53 
54 class WeightedPCAPlugin : public QObject,
56  public BasePluginQt
57 {
58  Q_OBJECT
59  Q_INTERFACES(FEVV::Generic_PluginInterface)
60 #if(FEVV_USE_QT5) // see at the end of .cpp for QT4
61  Q_PLUGIN_METADATA(IID "WeightedPCAPlugin")
62 #endif
63 
64  /*public:
65  using BasePlugin::apply;*/
66 public:
67  WeightedPCAPlugin() = default;
68  ~WeightedPCAPlugin() = default;
69 
70 public:
71  void init() override { init(100, 0.01, 10000000); }
72 
73  void init(double _x, double _y, double _z)
74  {
75  n_neight = _x;
76  noise = _y;
77  curvature = _z;
78  }
79 
80  void reset() override
81  {
82  init();
83 
84  emit resetSignal();
85  }
86 
87  void addParameters(BaseWindow *_window) override
88  {
89  window = _window;
90  if(window == nullptr || !window->isInit())
91  {
92  std::cerr << "BaseWindow is null or not initialized." << std::endl;
93  return;
94  }
95  }
96 
97  template< typename HalfedgeGraph >
98  void process(HalfedgeGraph *cloud, FEVV::PMapsContainer *pmaps_bag, int n_neight, float noise, float curvature)
99  {
100  std::cout << "Running filter WeihgtedPCA normal computation..." << std::endl;
101 
102  std::cout << "create vertex-normal map" << std::endl;
103  auto v_nm = make_property_map(FEVV::vertex_normal, *cloud);
104  // store property map in property maps bag
105  FEVV::put_property_map(FEVV::vertex_normal, *cloud, *pmaps_bag, v_nm);
106 
107  // retrieve point property map (aka geometry)
108  auto pm = get(boost::vertex_point, *cloud);
109 
110  // apply filter
111  noise = (float)noise/sqrt(3);
112  noise = std::max(noise, 0.000001f);
114 
115  std::cout << "Running filter WeihgtedPCA normal computation... done." << std::endl;
116  }
117 
118  template< typename HalfedgeGraph >
119  void applyHG(BaseAdapterVisu *_adapter,
120  HalfedgeGraph *_mesh,
121  FEVV::PMapsContainer *pmaps_bag)
122  {
123  // get filter parameters from dialog window
124  WeightedPCADialog dialog;
126  if(dialog.exec() == QDialog::Accepted)
128  else
129  return; // abort applying filter
130 
131  // apply filter
132  process(_mesh, pmaps_bag, n_neight, noise, curvature);
133 
134  SimpleViewer *viewer =
135  dynamic_cast< SimpleViewer * >(_adapter->getViewer());
136  if(viewer)
137  viewer->draw_or_redraw_mesh(_mesh, pmaps_bag, true, false);
138 
139  // comment next line to keep parameters values between calls
140  reset();
141 
142 #if(FEVV_USE_QT5)
143  // empty
144 #else
145  viewer->frame(); // necessary or not ?
146 #endif
147  }
148 
149 #ifdef FEVV_USE_CGAL
150  void apply(BaseAdapterVisu *_adapter,
151  FEVV::CGALPointSet *pc,
152  FEVV::PMapsContainer *pmaps_bag) override
153  {
154  applyHG< FEVV::CGALPointSet >(_adapter, pc, pmaps_bag);
155  }
156 #endif
157 
158 #ifdef FEVV_USE_PCL
159  void apply(BaseAdapterVisu *_adapter,
161  FEVV::PMapsContainer *pmaps_bag) override
162  {
163  applyHG< FEVV::PCLPointCloud >(_adapter, pc, pmaps_bag);
164  }
165 #endif
166 
167  QStringList Generic_plugins() const override
168  {
169  return QStringList() << "WeightedPCAPlugin";
170  }
171 
172  bool Generic_plugin(const QString &/*plugin*/) override
173  {
174  SimpleWindow *sw = static_cast< SimpleWindow * >(window);
175  // dynamic_cast fails under OS X
176  sw->onModificationParam("weightedPCA_qt_p", this);
177  //TODO-elo-refactor-plugins
178  // 1) the name of the function onModificationParam()
179  // is unrelated to its content!!!
180  // 2) Generic_plugin() is called by SimpleWindow
181  // and calls back SimpleWindow functions here ;
182  // looks like a bad architecture
183  sw->onApplyButton();
184 
185  return true;
186  }
187 
188 signals:
189  void resetSignal();
190 
191 protected:
192  // filter parameters
193  double n_neight = 0;
194  double noise = 0;
195  double curvature = 0;
196 };
197 
198 } // namespace FEVV
199 
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::CGALPointSet
CGAL::Point_set_3< CGALPointSetPoint > CGALPointSet
Definition: DataStructures_cgal_point_set.h:71
FEVV::WeightedPCAPlugin::init
void init() override
Definition: weightedPCA_plugin.h:71
point_cloud_normal_wpca.hpp
FEVV::SimpleWindow::onApplyButton
void onApplyButton()
Definition: SimpleWindow.inl:525
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::WeightedPCAPlugin::noise
double noise
Definition: weightedPCA_plugin.h:194
properties_linear_cell_complex.h
FEVV::BaseAdapterVisu
Definition: BaseAdapterVisu.h:27
FEVV::WeightedPCAPlugin::WeightedPCAPlugin
WeightedPCAPlugin()=default
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::compute_weighted_pca
void compute_weighted_pca(const PointCloud &pointCloud, const PointMap &pointMap, NormalMap &normalMap, int n_neight, float noise, float curvature, const GeometryTraits &gt)
Definition: point_cloud_normal_wpca.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::WeightedPCAPlugin::~WeightedPCAPlugin
~WeightedPCAPlugin()=default
FEVV::SimpleViewer
SimpleViewer is a specialization of osgViewer::CompositeViewer. This class is a widget where we are a...
Definition: SimpleViewer.h:180
FEVV::WeightedPCAPlugin::Generic_plugins
QStringList Generic_plugins() const override
Definition: weightedPCA_plugin.h:167
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::WeightedPCADialog::getParameters
void getParameters(double &x, double &y, double &z)
Definition: weightedPCA_dialog.cpp:38
FEVV::WeightedPCADialog
Definition: weightedPCA_dialog.h:23
weightedPCA_dialog.h
properties_surface_mesh.h
FEVV::WeightedPCAPlugin::n_neight
double n_neight
Definition: weightedPCA_plugin.h:193
FEVV::WeightedPCAPlugin::addParameters
void addParameters(BaseWindow *_window) override
Definition: weightedPCA_plugin.h:87
FEVV::WeightedPCAPlugin::curvature
double curvature
Definition: weightedPCA_plugin.h:195
SimpleViewer.h
properties_pcl_point_cloud.h
FEVV::WeightedPCAPlugin::init
void init(double _x, double _y, double _z)
Definition: weightedPCA_plugin.h:73
FEVV::WeightedPCADialog::setParameters
void setParameters(double x, double y, double z)
Definition: weightedPCA_dialog.cpp:30
BasePluginQt.h
properties_openmesh.h
FEVV::WeightedPCAPlugin::process
void process(HalfedgeGraph *cloud, FEVV::PMapsContainer *pmaps_bag, int n_neight, float noise, float curvature)
Definition: weightedPCA_plugin.h:98
FEVV::WeightedPCAPlugin::applyHG
void applyHG(BaseAdapterVisu *_adapter, HalfedgeGraph *_mesh, FEVV::PMapsContainer *pmaps_bag)
Definition: weightedPCA_plugin.h:119
FEVV::Generic_PluginInterface
Definition: PluginInterface.h:37
FEVV::WeightedPCAPlugin::Generic_plugin
bool Generic_plugin(const QString &) override
Definition: weightedPCA_plugin.h:172
FEVV::BasePluginQt::apply
virtual void apply(BaseAdapterVisu *, void *, FEVV::PMapsContainer *) override
Definition: BasePluginQt.h:108
PluginInterface.h
FEVV::BasePlugin::window
BaseWindow * window
Definition: BasePlugin.h:138
FEVV::BaseWindow
Definition: BaseWindow.h:25
properties.h
FEVV::WeightedPCAPlugin
Definition: weightedPCA_plugin.h:57
FEVV::WeightedPCAPlugin::reset
void reset() override
Definition: weightedPCA_plugin.h:80
FEVV::WeightedPCAPlugin::resetSignal
void resetSignal()
FEVV::vertex_normal
@ vertex_normal
Definition: properties.h:35
FEVV::make_property_map
PMap_traits< PropertyT, MeshT >::pmap_type make_property_map(PropertyT, const MeshT &m)
Definition: properties.h:630