MEPP2 Project
point_cloud_curvature_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 
36 
37 #ifdef FEVV_USE_CGAL
42 #endif // FEVV_USE_CGAL
43 #ifdef FEVV_USE_OPENMESH
45 #endif // FEVV_USE_OPENMESH
46 #ifdef FEVV_USE_AIF
48 #endif // FEVV_USE_AIF
49 #ifdef FEVV_USE_PCL
51 #endif // FEVV_USE_AIF
52 #endif // Q_MOC_RUN
53 
54 namespace FEVV {
55 
56 class PointCloudCurvaturePlugin : 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 "PointCloudCurvaturePlugin")
64 #endif
65 
66  /*public:
67  using BasePlugin::apply;*/
68 public:
71 
72 public:
73  void init() override
74  {
75  m_k = 15;
76  m_radius = 0.001;
77  m_knn_search = true;
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 *pc, FEVV::PMapsContainer *pmaps_bag)
99  {
100  std::cout << "Running filter PointCloudCurvature..." << std::endl;
101 
102  // retrieve geometry property map
103  auto pm = get(boost::vertex_point, *pc);
104 
105  // create a vertex curvature property map
106  auto v_curvm =
107  FEVV::make_vertex_property_map< HalfedgeGraph, double >(*pc);
108 
109  // create a vertex color property map
111  FEVV::put_property_map(FEVV::vertex_color, *pc, *pmaps_bag, v_cm);
112 
113  // apply Point Cloud Curvature filter
114  if(m_knn_search)
115  {
116  // use a kNN-search
117  FEVV::Filters::point_cloud_curvature(*pc, pm, m_k, 0.0, v_curvm, v_cm);
118  }
119  else
120  {
121  // use a radius-search
122  double max_bb_size = Filters::get_max_bb_size(*pc, pm);
123  double radius = m_radius * max_bb_size;
124  FEVV::Filters::point_cloud_curvature(*pc, pm, 0, radius, v_curvm, v_cm);
125  }
126 
127  std::cout << "Running filter PointCloudCurvature... done." << std::endl;
128  }
129 
130 
131  template< typename HalfedgeGraph >
132  void applyHG(BaseAdapterVisu *_adapter,
133  HalfedgeGraph *_mesh,
134  FEVV::PMapsContainer *pmaps_bag)
135  {
136  // get filter parameters from dialog window
139  if(dialog.exec() == QDialog::Accepted)
141  else
142  return; // abort applying filter
143 
144  // apply filter
145  process(_mesh, pmaps_bag);
146 
147  // redraw mesh
148  SimpleViewer *viewer =
149  dynamic_cast< SimpleViewer * >(_adapter->getViewer());
150  if(viewer)
151  viewer->draw_or_redraw_mesh(_mesh, pmaps_bag, true, false);
152 
153  // comment next line to keep parameters values between calls
154  //reset();
155 
156 #if(FEVV_USE_QT5)
157  // empty
158 #else
159  viewer->frame(); // necessary or not ?
160 #endif
161  }
162 
163 #if 0 // Point cloud only
164 #ifdef FEVV_USE_OPENMESH
165  void apply(BaseAdapterVisu *_adapter,
166  MeshOpenMesh *_mesh,
167  FEVV::PMapsContainer *pmaps_bag) override
168  {
169  applyHG< MeshOpenMesh >(_adapter, _mesh, pmaps_bag);
170  }
171 #endif
172 
173 #ifdef FEVV_USE_CGAL
174  void apply(BaseAdapterVisu *_adapter,
175  MeshLCC *_mesh,
176  FEVV::PMapsContainer *pmaps_bag) override
177  {
178  applyHG< MeshLCC >(_adapter, _mesh, pmaps_bag);
179  }
180 
181  void apply(BaseAdapterVisu *_adapter,
182  MeshSurface *_mesh,
183  FEVV::PMapsContainer *pmaps_bag) override
184  {
185  applyHG< MeshSurface >(_adapter, _mesh, pmaps_bag);
186  }
187 
188  void apply(BaseAdapterVisu *_adapter,
189  MeshPolyhedron *_mesh,
190  FEVV::PMapsContainer *pmaps_bag) override
191  {
192  applyHG< MeshPolyhedron >(_adapter, _mesh, pmaps_bag);
193  }
194 #endif
195 
196 #ifdef FEVV_USE_AIF
197  void apply(BaseAdapterVisu *_adapter,
198  MeshAIF *_mesh,
199  FEVV::PMapsContainer *pmaps_bag) override
200  {
201  applyHG< MeshAIF >(_adapter, _mesh, pmaps_bag);
202  }
203 #endif
204 #endif // Point cloud only
205 
206 #ifdef FEVV_USE_CGAL
207  void apply(BaseAdapterVisu *_adapter,
208  FEVV::CGALPointSet *pc,
209  FEVV::PMapsContainer *pmaps_bag) override
210  {
211  applyHG< FEVV::CGALPointSet >(_adapter, pc, pmaps_bag);
212  }
213 #endif
214 
215 #ifdef FEVV_USE_PCL
216  void apply(BaseAdapterVisu *_adapter,
218  FEVV::PMapsContainer *pmaps_bag) override
219  {
220  applyHG< FEVV::PCLPointCloud >(_adapter, pc, pmaps_bag);
221  }
222 #endif
223 
224  QStringList Generic_plugins() const override
225  {
226  return QStringList() << "PointCloudCurvaturePlugin";
227  }
228 
229 
230  bool Generic_plugin(const QString &/*plugin*/) override
231  {
232  SimpleWindow *sw = static_cast< SimpleWindow * >(window);
233  // dynamic_cast fails under OS X
234  sw->onModificationParam("point_cloud_curvature_qt_p", this);
235  //TODO-elo-refactor-plugins
236  // 1) the name of the function onModificationParam()
237  // is unrelated to its content!!!
238  // 2) Generic_plugin() is called by SimpleWindow
239  // and calls back SimpleWindow functions here ;
240  // looks like a bad architecture
241  sw->onApplyButton();
242 
243  return true;
244  }
245 
246 signals:
247  void resetSignal();
248 
249 protected:
250  // filter parameters
251  unsigned int m_k;
252  double m_radius;
254 };
255 
256 } // namespace FEVV
257 
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
point_cloud_curvature.hpp
FEVV::PointCloudCurvaturePlugin::m_k
unsigned int m_k
Definition: point_cloud_curvature_plugin.h:251
FEVV::PointCloudCurvaturePlugin
Definition: point_cloud_curvature_plugin.h:59
FEVV::CGALPointSet
CGAL::Point_set_3< CGALPointSetPoint > CGALPointSet
Definition: DataStructures_cgal_point_set.h:71
FEVV::SimpleWindow::onApplyButton
void onApplyButton()
Definition: SimpleWindow.inl:525
FEVV::PointCloudCurvaturePlugin::PointCloudCurvaturePlugin
PointCloudCurvaturePlugin()=default
FEVV::MeshLCC
CGAL::Linear_cell_complex_for_combinatorial_map< 2, 3, CGALLCCTraits, CGALItem > MeshLCC
Definition: DataStructures_cgal_linear_cell_complex.h:43
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
properties_linear_cell_complex.h
FEVV::PointCloudCurvaturePlugin::resetSignal
void resetSignal()
FEVV::MeshSurface
CGAL::Surface_mesh< CGALPoint > MeshSurface
Definition: DataStructures_cgal_surface_mesh.h:23
FEVV::BaseAdapterVisu
Definition: BaseAdapterVisu.h:27
FEVV::Filters::point_cloud_curvature
void point_cloud_curvature(const PointCloud &pc, const PointMap &pm, unsigned int k, double radius, VertexCurvatureMap &v_curvm, VertexColorMap &v_cm, const GeometryTraits &gt)
Compute the curvature for each point of the point cloud using the nearest neighbors.
Definition: point_cloud_curvature.hpp:212
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::PointCloudCurvaturePlugin::addParameters
void addParameters(BaseWindow *_window) override
Definition: point_cloud_curvature_plugin.h:87
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::PointCloudCurvaturePlugin::reset
void reset() override
Definition: point_cloud_curvature_plugin.h:80
FEVV::PointCloudCurvaturePlugin::init
void init() override
Definition: point_cloud_curvature_plugin.h:73
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
FEVV::Filters::get_max_bb_size
double get_max_bb_size(const HalfedgeGraph &g, PointMap &pm, GeometryTraits &gt)
Gets the maximum size of the object bounding box.
Definition: get_max_bb_size.hpp:36
FEVV::PointCloudCurvaturePlugin::m_radius
double m_radius
Definition: point_cloud_curvature_plugin.h:252
FEVV::vertex_color
@ vertex_color
Definition: properties.h:47
SimpleViewer.h
properties_pcl_point_cloud.h
point_cloud_curvature_dialog.h
BasePluginQt.h
FEVV::PointCloudCurvatureDialog::setParameters
void setParameters(unsigned int k, double radius, bool knn_search)
Definition: point_cloud_curvature_dialog.cpp:30
properties_openmesh.h
FEVV::PointCloudCurvaturePlugin::Generic_plugins
QStringList Generic_plugins() const override
Definition: point_cloud_curvature_plugin.h:224
FEVV::PointCloudCurvaturePlugin::process
void process(HalfedgeGraph *pc, FEVV::PMapsContainer *pmaps_bag)
Definition: point_cloud_curvature_plugin.h:98
FEVV::MeshOpenMesh
OpenMesh::PolyMesh_ArrayKernelT< MyTraits > MeshOpenMesh
Definition: DataStructures_openmesh.h:51
FEVV::PointCloudCurvaturePlugin::~PointCloudCurvaturePlugin
~PointCloudCurvaturePlugin()=default
FEVV::Generic_PluginInterface
Definition: PluginInterface.h:37
FEVV::PointCloudCurvatureDialog
Definition: point_cloud_curvature_dialog.h:23
FEVV::BasePluginQt::apply
virtual void apply(BaseAdapterVisu *, void *, FEVV::PMapsContainer *) override
Definition: BasePluginQt.h:108
get_max_bb_size.hpp
FEVV::PointCloudCurvatureDialog::getParameters
void getParameters(unsigned int &k, double &radius, bool &knn_search)
Definition: point_cloud_curvature_dialog.cpp:41
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::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::PointCloudCurvaturePlugin::applyHG
void applyHG(BaseAdapterVisu *_adapter, HalfedgeGraph *_mesh, FEVV::PMapsContainer *pmaps_bag)
Definition: point_cloud_curvature_plugin.h:132
FEVV::MeshAIF
FEVV::DataStructures::AIF::AIFMesh MeshAIF
Definition: DataStructures_aif.h:19
FEVV::PointCloudCurvaturePlugin::Generic_plugin
bool Generic_plugin(const QString &) override
Definition: point_cloud_curvature_plugin.h:230
FEVV::PointCloudCurvaturePlugin::m_knn_search
bool m_knn_search
Definition: point_cloud_curvature_plugin.h:253