File: draw_several_windows.cpp

package info (click to toggle)
cgal 6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144,912 kB
  • sloc: cpp: 810,858; ansic: 208,477; sh: 493; python: 411; makefile: 286; javascript: 174
file content (91 lines) | stat: -rw-r--r-- 2,806 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/poisson_surface_reconstruction.h>
#include <CGAL/IO/read_points.h>
#include <CGAL/draw_polyhedron.h>
#include <CGAL/draw_point_set_3.h>
#include <CGAL/Graphics_scene_options.h>
#include <CGAL/Basic_viewer.h>

#ifdef CGAL_USE_BASIC_VIEWER
#include <QMainWindow>
#endif

#include <vector>
#include <iostream>

using Kernel=CGAL::Exact_predicates_inexact_constructions_kernel;
using Point=Kernel::Point_3;
using Vector=Kernel::Vector_3;
using Pwn=std::pair<Point, Vector>;
using Polyhedron=CGAL::Polyhedron_3<Kernel>;
using PS3=CGAL::Point_set_3<Point>;

int main(void)
{
  /// (1) Some CGAL code that create data structures and fill two Graphics_scene.
  std::vector<Pwn> points;

  if(!CGAL::IO::read_points(CGAL::data_file_path("points_3/kitten.xyz"), std::back_inserter(points),
                            CGAL::parameters::point_map(CGAL::First_of_pair_property_map<Pwn>())
                                             .normal_map(CGAL::Second_of_pair_property_map<Pwn>())))
  {
    std::cerr << "Error: cannot read input file " << CGAL::data_file_path("points_3/kitten.xyz") << std::endl;
    return EXIT_FAILURE;
  }

  Polyhedron output_mesh;

  double average_spacing = CGAL::compute_average_spacing<CGAL::Sequential_tag>
    (points, 6, CGAL::parameters::point_map(CGAL::First_of_pair_property_map<Pwn>()));

  if (!CGAL::poisson_surface_reconstruction_delaunay
      (points.begin(), points.end(),
       CGAL::First_of_pair_property_map<Pwn>(),
       CGAL::Second_of_pair_property_map<Pwn>(),
       output_mesh, average_spacing))
  { return EXIT_FAILURE; }

  PS3 point_set;
  for(Pwn& it: points)
  { point_set.insert(it.first); }

  CGAL::Graphics_scene scene1, scene2;
  CGAL::add_to_graphics_scene(point_set, scene1);
  CGAL::add_to_graphics_scene(output_mesh, scene2);

  /// (2) Qt code that create windows, add them in a layout, and create app.
#ifdef CGAL_USE_BASIC_VIEWER

#if defined(CGAL_TEST_SUITE)
  bool cgal_test_suite=true;
#else
  bool cgal_test_suite=qEnvironmentVariableIsSet("CGAL_TEST_SUITE");
#endif

  if (cgal_test_suite) { return EXIT_SUCCESS; }

  int argc=1;
  const char* argv[2]={"Draw several windows example","\0"};
  QApplication app(argc,const_cast<char**>(argv));

  QMainWindow* mainWindow=new QMainWindow;
  QWidget *centralWidget = new QWidget(mainWindow);
  QHBoxLayout* layout = new QHBoxLayout(mainWindow);

  CGAL::Qt::Basic_viewer bv1(mainWindow, scene1);
  CGAL::Qt::Basic_viewer bv2(mainWindow, scene2);
  bv1.draw_vertices(true);

  layout->addWidget(&bv1);
  layout->addWidget(&bv2);

  centralWidget->setLayout(layout);
  mainWindow->setCentralWidget(centralWidget);

  mainWindow->show();
  app.exec();
#endif

  return EXIT_SUCCESS;
}