File: Viewer.cpp

package info (click to toggle)
cgal 6.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144,952 kB
  • sloc: cpp: 811,597; ansic: 208,576; sh: 493; python: 411; makefile: 286; javascript: 174
file content (88 lines) | stat: -rw-r--r-- 2,949 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
// Copyright (c) 2011 CNRS and LIRIS' Establishments (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org)
//
// $URL$
// $Id$
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
//
// Author(s)     : Guillaume Damiand <guillaume.damiand@liris.cnrs.fr>
// Contributor(s): Kumar Snehasish <kumar.snehasish@gmail.com>
//                 Mostafa Ashraf <mostaphaashraf1996@gmail.com>
//

#include "Viewer.h"
#include <CGAL/Qt/vec.h>

Viewer::Viewer(QWidget *parent)
  : Base(parent, m_graphic_buffer, ""),
    m_previous_scene_empty(true)
{
  m_gs_options.face_color=[](const LCC & alcc,
                             Dart_const_descriptor dh)->CGAL::IO::Color
  {
    if(alcc.template is_free<3>(dh))
    { return alcc.template info<3>(dh).color(); }

    if(!alcc.template info<3>(dh).is_visible() ||
       !alcc.template info<3>(dh).is_filled())
    { return alcc.template info<3>(alcc.template beta<3>(dh)).color(); }

    if(!alcc.template info<3>(alcc.template beta<3>(dh)).is_visible() ||
       !alcc.template info<3>(alcc.template beta<3>(dh)).is_filled())
    { return alcc.template info<3>(dh).color(); }

    const CGAL::IO::Color& c1=alcc.template info<3>(dh).color();
    const CGAL::IO::Color& c2=alcc.template info<3>(alcc.template beta<3>(dh)).color();
    return CGAL::IO::Color((c1[0]+c2[0])/2, (c1[1]+c2[1])/2, (c1[2]+c2[2])/2);
  };

  m_gs_options.colored_face=[](const LCC &, Dart_const_descriptor)->bool
  { return true; };

  m_gs_options.draw_volume=[](const LCC & alcc, Dart_const_descriptor dh)->bool
  { return alcc.template info<3>(dh).is_visible(); };

  m_gs_options.volume_wireframe=[](const LCC& alcc, Dart_const_descriptor dh)->bool
  { return !(alcc.template info<3>(dh).is_filled()); };
}

void Viewer::setScene(Scene *scene_, bool doredraw)
{
  scene = scene_;

  if (scene->lcc!=nullptr)
  { CGAL::add_to_graphics_scene(*scene->lcc, m_graphic_buffer, m_gs_options); }

  if (doredraw)
  { Base::redraw(); }
}

void Viewer::sceneChanged()
{
  m_graphic_buffer.clear();
  CGAL::add_to_graphics_scene(*scene->lcc, m_graphic_buffer, m_gs_options);

  this->camera()->setSceneBoundingBox(
      CGAL::qglviewer::Vec(m_graphic_buffer.bounding_box().xmin(),
                           m_graphic_buffer.bounding_box().ymin(),
                           m_graphic_buffer.bounding_box().zmin()),
      CGAL::qglviewer::Vec(m_graphic_buffer.bounding_box().xmax(),
                           m_graphic_buffer.bounding_box().ymax(),
                           m_graphic_buffer.bounding_box().zmax()));
  Base::redraw();
  if (m_previous_scene_empty)
  { this->showEntireScene(); }

  m_previous_scene_empty=scene->lcc->is_empty(); // for the next call to sceneChanged
}

void Viewer::keyPressEvent(QKeyEvent *e)
{
  // const Qt::KeyboardModifiers modifiers = e->modifiers();
  Base::keyPressEvent(e);
}

QString Viewer::helpString() const
{ return Base::helpString("LCC Demo"); }