MEPP2 Project
mepp-gui.cpp
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 #if(_MSC_VER >= 1400)
12 #ifndef _SCL_SECURE_NO_WARNINGS
13 #define _SCL_SECURE_NO_WARNINGS
14 #endif
15 #endif
16 
17 #include "mepp-gui.h"
18 
20 
21 #include <fstream>
22 #include <functional>
23 
26 //#include "Visualization/SimpleAdapterVisu.h" // REMOVE ?
28 
29 #include "Base/Color.hpp"
30 #include "Base/Block.h"
31 
32 // OSG mesh loader
34 
35 // IO tools
37 
38 enum OpenWith {
48 };
49 
50 
51 int
52 main(int argc, char **argv)
53 {
54  bool test = false;
55  OpenWith mesh_open_with = OPEN_WITH_ALL;
56 #ifdef __GNUC__
57 #pragma GCC diagnostic push
58 #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
59 #endif
60  OpenWith cloud_open_with = OPEN_WITH_ALL;
61 #ifdef __GNUC__
62 #pragma GCC diagnostic pop
63 #endif
64  std::vector< std::string > mesh_filenames;
65  std::vector< std::string > cloud_filenames;
66  std::vector< std::string > mesh_extensions = { ".off", ".obj" };
67  std::vector< std::string > cloud_extensions = { ".xyz", ".ply", ".pcd" };
68 
69  if((argc == 1) || (argv[1] && (strncmp("-psn", argv[1], 4) == 0)))
70  // very specific ".app/GUI" stuff from Apple...
71  // https://discussions.apple.com/thread/1571921?tstart=0
72  {
73  std::cout << "Usage: " << std::endl
74  << " " << argv[0]
75  << " [mesh_filename] [cloud_filename]"
76  " [-test] [-emptytest] [-all|-polyhedron|-surfacemesh|-lcc|-openmesh|-aif|-cgalps|-pclpc]"
77  << std::endl
78  << "Examples:" << std::endl
79  << argv[0] << " casting.off" << std::endl
80  << argv[0] << " casting.off casting.xyz" << std::endl
81  << argv[0] << " casting.off -test" << std::endl
82  << argv[0] << " casting.off -polyhedron casting.xyz" << std::endl
83  << argv[0] << " casting.off -polyhedron casting.xyz -pclpc -test" << std::endl;
84  // exit(EXIT_FAILURE);
85  }
86  else if(argc >= 2)
87  {
88  // parse arguments
89  for(int i = 1; i < argc; i++)
90  {
91  std::string argvi(argv[i]);
92 
93  if(argvi == "-test")
94  {
95  test = true;
96  }
97  else if(argvi == "-emptytest")
98  {
99  test = true;
100  mesh_open_with = OPEN_WITH_NONE;
101  cloud_open_with = OPEN_WITH_NONE;
102  }
103  else if(argvi == "-polyhedron")
104  {
105  mesh_open_with = OPEN_WITH_POLYHEDRON;
106  }
107  else if(argvi == "-surfacemesh")
108  {
109  mesh_open_with = OPEN_WITH_SURFACEMESH;
110  }
111  else if(argvi == "-lcc")
112  {
113  mesh_open_with = OPEN_WITH_LCC;
114  }
115  else if(argvi == "-openmesh")
116  {
117  mesh_open_with = OPEN_WITH_OPENMESH;
118  }
119  else if(argvi == "-aif")
120  {
121  mesh_open_with = OPEN_WITH_AIF;
122  }
123  else if(argvi == "-cgalps")
124  {
125  cloud_open_with = OPEN_WITH_CGALPOINTSET;
126  }
127  else if(argvi == "-pclpc")
128  {
129  cloud_open_with = OPEN_WITH_PCLPOINTCLOUD;
130  }
131  else if(argvi == "-all")
132  {
133  mesh_open_with = OPEN_WITH_ALL;
134  cloud_open_with = OPEN_WITH_ALL;
135  }
136  else
137  {
138  // this is a file name
139  if(FEVV::FileUtils::has_extension(argvi, mesh_extensions))
140  mesh_filenames.push_back(argvi);
141  else if(FEVV::FileUtils::has_extension(argvi, cloud_extensions))
142  cloud_filenames.push_back(argvi);
143  }
144  }
145  }
146 
147 // init GUI
148 
149 #ifdef Q_WS_X11
150 #if QT_VERSION >= 0x040800
151  // Required for multithreaded QGLWidget on Linux/X11,
152  // see http://blog.qt.io/blog/2011/06/03/threaded-opengl-in-4-8/
153  QApplication::setAttribute(
154  Qt::AA_X11InitThreads); // must be called before QApplication app( argc,
155  // argv );
156 #endif
157 #endif
158 
159  FEVV::Block::begin("init", "Init Visualization.");
160  FEVV::SimpleApplication app(argc, argv);
161  FEVV::SimpleWindow gui;
162 
163 #ifndef FEVV_USE_PCL
164  #define PCL_VERSION_PRETTY "(no PCL)"
165 #endif
166 
167  gui.setWindowTitle(
168  QObject::tr("%1 - %2 - %3 - %4 - Qt (compiled) %5 - Qt (run-time) %6 - "
169  "OSG %7 - CGAL %8 (%9.%10.%11) - PCL %12")
170  .arg(MAINWINDOW_TITLE)
171  .arg(MEPP_VERSION)
172  .arg(ARCHITECTURE)
173  .arg(BUILD_TYPE)
174  .arg(QT_VERSION_STR)
175  .arg(qVersion())
176  .arg(osgGetVersion())
177  .arg(CGAL_VERSION_STR)
178  .arg(CGAL_VERSION_MAJOR)
179  .arg(CGAL_VERSION_MINOR)
180  .arg(CGAL_VERSION_PATCH)
181  .arg(PCL_VERSION_PRETTY));
182 
183  gui.init(test);
184 
185  gui.loadQtPlugins();
186 
187  FEVV::Block::end("init");
188 
189 #ifdef DEBUG_VISU2
190  std::cout << "*** file " << __FILE__ << " line " << __LINE__ << std::endl;
191 #endif
192 
193  // open mesh file(s) provided on command line
194 
195 #ifdef DEBUG_VISU2
196  std::cout << "*** file " << __FILE__ << " line " << __LINE__ << std::endl;
197 #endif
198 
199  if(! mesh_filenames.empty())
200  {
201 #ifdef FEVV_USE_CGAL
202  if(mesh_open_with == OPEN_WITH_POLYHEDRON || mesh_open_with == OPEN_WITH_ALL)
204  {
205  FEVV::Block::begin("loading-polyhedron", "Loading Polyhedron mesh.");
206  {
207  gui.open_SPACE_TIME< FEVV::MeshPolyhedron >(nullptr, mesh_filenames);
208  }
209  FEVV::Block::end("loading-polyhedron");
210  }
211 
213  if(mesh_open_with == OPEN_WITH_SURFACEMESH || mesh_open_with == OPEN_WITH_ALL)
214  {
215  FEVV::Block::begin("loading-surface", "Loading SurfaceMesh mesh.");
216  {
217  gui.open_SPACE_TIME< FEVV::MeshSurface >(nullptr, mesh_filenames);
218  }
219  FEVV::Block::end("loading-surface");
221  }
222 
224  if(mesh_open_with == OPEN_WITH_LCC || mesh_open_with == OPEN_WITH_ALL)
225  {
226  FEVV::Block::begin("loading-lcc", "Loading LCC mesh.");
227  {
228  gui.open_SPACE_TIME< FEVV::MeshLCC >(nullptr, mesh_filenames);
229  }
230  FEVV::Block::end("loading-lcc");
231  }
232 #endif // FEVV_USE_CGAL
233 
234 #ifdef DEBUG_VISU2
235  std::cout << "*** file " << __FILE__ << " line " << __LINE__ << std::endl;
236 #endif
237 
238 #ifdef FEVV_USE_OPENMESH
239  if(mesh_open_with == OPEN_WITH_OPENMESH || mesh_open_with == OPEN_WITH_ALL)
241  {
242  FEVV::Block::begin("loading-openmesh", "Loading OpenMesh mesh.");
243  {
244  gui.open_SPACE_TIME< FEVV::MeshOpenMesh >(nullptr, mesh_filenames);
245  }
246  FEVV::Block::end("loading-openmesh");
247  }
248 #endif // FEVV_USE_OPENMESH
249 
250 #ifdef DEBUG_VISU2
251  std::cout << "*** file " << __FILE__ << " line " << __LINE__ << std::endl;
252 #endif
253 
254 #ifdef FEVV_USE_AIF
255  if(mesh_open_with == OPEN_WITH_AIF || mesh_open_with == OPEN_WITH_ALL)
257  {
258  FEVV::Block::begin("loading-aif", "Loading AIF mesh.");
259  {
260  gui.open_SPACE_TIME< FEVV::MeshAIF >(nullptr, mesh_filenames);
261  }
262  FEVV::Block::end("loading-aif");
263  }
264 #endif // FEVV_USE_AIF
265  }
266 
267  // open point cloud file(s) provided on command line
268 
269  if(! cloud_filenames.empty())
270  {
271 #ifdef FEVV_USE_CGAL
272  // CGALPointSet
273  if(cloud_open_with == OPEN_WITH_CGALPOINTSET || cloud_open_with == OPEN_WITH_ALL)
274  {
275  FEVV::Block::begin("loading-CGALPointSet", "Loading CGALPointSet point cloud.");
276  {
277  gui.open_SPACE_TIME< FEVV::CGALPointSet >(nullptr, cloud_filenames);
278  }
279  FEVV::Block::end("loading-CGALPointSet");
280  }
281 #endif // FEVV_USE_CGAL
282 
283 #ifdef FEVV_USE_PCL
284  // PCLPointCloud
285  if(cloud_open_with == OPEN_WITH_PCLPOINTCLOUD || cloud_open_with == OPEN_WITH_ALL)
286  {
287  FEVV::Block::begin("loading-PCLPointCloud", "Loading PCLPointCloud point cloud.");
288  {
289  gui.open_SPACE_TIME< FEVV::PCLPointCloud >(nullptr, cloud_filenames);
290  }
291  FEVV::Block::end("loading-PCLPointCloud");
292  }
293 #endif // FEVV_USE_PCL
294  }
295 
296 #ifdef DEBUG_VISU2
297  std::cout << "*** file " << __FILE__ << " line " << __LINE__ << std::endl;
298 #endif
299 
300  // run GUI
301 
302  gui.show();
303 
304 #ifdef DEBUG_VISU2
305  std::cout << "*** file " << __FILE__ << " line " << __LINE__ << std::endl;
306 #endif
307 
308  int ret = app.exec();
309 
310 #ifdef DEBUG_VISU2
311  std::cout << "*** file " << __FILE__ << " line " << __LINE__ << std::endl;
312 #endif
313 
314  return ret;
315 }
MAINWINDOW_TITLE
#define MAINWINDOW_TITLE
Definition: mepp-gui.h:16
PCL_VERSION_PRETTY
#define PCL_VERSION_PRETTY
FEVV::CGALPointSet
CGAL::Point_set_3< CGALPointSetPoint > CGALPointSet
Definition: DataStructures_cgal_point_set.h:71
FEVV::SimpleApplication
SimpleApplication is a specialization of QApplication. This is useful if we want to catch exception.
Definition: SimpleApplication.h:31
FEVV::MeshLCC
CGAL::Linear_cell_complex_for_combinatorial_map< 2, 3, CGALLCCTraits, CGALItem > MeshLCC
Definition: DataStructures_cgal_linear_cell_complex.h:43
tr
double tr(double &n)
Truncate a number to 1/1000 (only if BOOLEAN_OPERATIONS_DEBUG is enable)
Definition: boolops_definitions.hpp:127
SimpleWindow.h
FEVV::Block::begin
static void begin(const std::string &_uid, const std::string &_message)
Definition: Block.h:67
FEVV::PCLPointCloud
pcl::PointCloud< PCLEnrichedPoint > PCLPointCloud
Definition: DataStructures_pcl_point_cloud.h:28
BUILD_TYPE
#define BUILD_TYPE
Definition: mepp-gui.h:27
FEVV::Block::end
static void end(const std::string &_uid)
Definition: Block.h:100
OPEN_WITH_CGALPOINTSET
@ OPEN_WITH_CGALPOINTSET
Definition: mepp-gui.cpp:46
FEVV::MeshSurface
CGAL::Surface_mesh< CGALPoint > MeshSurface
Definition: DataStructures_cgal_surface_mesh.h:23
FEVV::SimpleWindow
SimpleWindow is a specialization of QMainWindow. This class the Main Window.
Definition: SimpleWindow.h:80
OPEN_WITH_LCC
@ OPEN_WITH_LCC
Definition: mepp-gui.cpp:43
OSGHelpers.h
OPEN_WITH_ALL
@ OPEN_WITH_ALL
Definition: mepp-gui.cpp:40
Block.h
DataStructures.h
MEPP_VERSION
#define MEPP_VERSION
Definition: mepp-gui.h:14
FEVV::SimpleWindow::loadQtPlugins
void loadQtPlugins()
Definition: SimpleWindow.inl:547
OPEN_WITH_AIF
@ OPEN_WITH_AIF
Definition: mepp-gui.cpp:45
OPEN_WITH_OPENMESH
@ OPEN_WITH_OPENMESH
Definition: mepp-gui.cpp:44
SimpleViewer.h
OPEN_WITH_PCLPOINTCLOUD
@ OPEN_WITH_PCLPOINTCLOUD
Definition: mepp-gui.cpp:47
OPEN_WITH_POLYHEDRON
@ OPEN_WITH_POLYHEDRON
Definition: mepp-gui.cpp:41
OPEN_WITH_NONE
@ OPEN_WITH_NONE
Definition: mepp-gui.cpp:39
ARCHITECTURE
#define ARCHITECTURE
Definition: mepp-gui.h:23
FEVV::SimpleWindow::init
void init() override
Definition: SimpleWindow.inl:194
FEVV::SimpleWindow::open_SPACE_TIME
void open_SPACE_TIME(FEVV::SimpleViewer *viewer, const std::vector< std::string > &filenames)
Open meshes in a viewer with datastructure HalfedgeGraph.
Definition: SimpleWindow.inl:897
FEVV::MeshOpenMesh
OpenMesh::PolyMesh_ArrayKernelT< MyTraits > MeshOpenMesh
Definition: DataStructures_openmesh.h:51
main
int main(int argc, char **argv)
Definition: mepp-gui.cpp:52
Color.hpp
FEVV::DataStructures::AIF::AIFMesh
This class represents an AIF structure. AIF structure can deal with both manifold and non-manifold su...
Definition: AIFMesh.hpp:47
OpenWith
OpenWith
Definition: mepp-gui.cpp:38
FEVV::FileUtils::has_extension
bool has_extension(const std::string &file_name)
Definition: FileUtilities.hpp:58
OPEN_WITH_SURFACEMESH
@ OPEN_WITH_SURFACEMESH
Definition: mepp-gui.cpp:42
FileUtilities.hpp
SimpleApplication.h
FEVV::MeshPolyhedron
CGAL::Polyhedron_3< CGALKernel, CGAL::Polyhedron_items_with_id_3 > MeshPolyhedron
Definition: DataStructures_cgal_polyhedron_3.h:33
mepp-gui.h