Developer Documentation
DecimaterViewerWidget.cc
1 /* ========================================================================= *
2  * *
3  * OpenMesh *
4  * Copyright (c) 2001-2015, RWTH-Aachen University *
5  * Department of Computer Graphics and Multimedia *
6  * All rights reserved. *
7  * www.openmesh.org *
8  * *
9  *---------------------------------------------------------------------------*
10  * This file is part of OpenMesh. *
11  *---------------------------------------------------------------------------*
12  * *
13  * Redistribution and use in source and binary forms, with or without *
14  * modification, are permitted provided that the following conditions *
15  * are met: *
16  * *
17  * 1. Redistributions of source code must retain the above copyright notice, *
18  * this list of conditions and the following disclaimer. *
19  * *
20  * 2. Redistributions in binary form must reproduce the above copyright *
21  * notice, this list of conditions and the following disclaimer in the *
22  * documentation and/or other materials provided with the distribution. *
23  * *
24  * 3. Neither the name of the copyright holder nor the names of its *
25  * contributors may be used to endorse or promote products derived from *
26  * this software without specific prior written permission. *
27  * *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39  * *
40  * ========================================================================= */
41 
42 
43 
44 
45 //== INCLUDES =================================================================
46 
47 #ifdef _MSC_VER
48 # pragma warning(disable: 4267 4311)
49 #endif
50 
51 #include <iostream>
52 #include <fstream>
53 
54 #include <qapplication.h>
55 #include <qdatetime.h>
56 
57 #include <OpenMesh/Core/IO/BinaryHelper.hh>
58 #include <OpenMesh/Core/IO/MeshIO.hh>
59 
60 #include <OpenMesh/Apps/Decimating/DecimaterViewerWidget.hh>
61 
62 
63 //== IMPLEMENTATION ==========================================================
64 
65 
66 //-----------------------------------------------------------------------------
67 
68 void DecimaterViewerWidget::keyPressEvent(QKeyEvent* _event)
69 {
70  switch (_event->key())
71  {
72  case Key_H:
73  std::cout << "Press '+' to increase the number of decimating steps\n"
74  << "Press '-' to decrease the number of decimating steps\n"
75  << "Press 'd' to perform the set number of decimating steps\n"
76  << "Press 'S' to save the mesh to 'result.off'\n"
77  << "Press 'q' or 'Esc' quit the application" << std::endl;
78  break;
79  case Key_D:
80  {
81  int rc;
82  if ( (rc=decimater_->decimate(steps_)) )
83  {
84  decimater_->mesh().garbage_collection();
85  std::cout << rc << " vertices removed!\n";
86  updateGL();
87  }
88  else
89  std::cout << "Decimation failed\n";
90  break;
91  }
92 
93  case Key_Plus:
94  ++steps_;
95  steps_ = std::min( steps_ , (size_t)( mesh_.n_vertices() / 10 ) );
96  updateGL();
97  std::cout << "# decimating steps increased to " << steps_ << std::endl;
98  break;
99 
100  case Key_Minus:
101  --steps_;
102  steps_ = std::max( steps_ , size_t(1) );
103  updateGL();
104  std::cout << "# decimating steps increased to " << steps_ << std::endl;
105  break;
106 
107  case Key_S:
108  {
110 
112 
113  if (OpenMesh::IO::write_mesh( mesh(), "result.off", opt ))
114  std::cout << "mesh saved in 'result.off'\n";
115  }
116  break;
117 
118  case Key_Q:
119  qApp->quit();
120  break;
121  case Key_Escape:
122  qApp->quit();
123  break;
124  default:
125  this->inherited_t::keyPressEvent(_event);
126  break;
127  }
128 }
129 
130 void DecimaterViewerWidget::animate( void )
131 {
132 // updateGL();
133 // timer_->start(300, true);
134 }
135 
136 //=============================================================================
bool write_mesh(const Mesh &_mesh, const std::string &_filename, Options _opt=Options::Default, std::streamsize _precision=6)
Write a mesh to the file _filename.
Definition: MeshIO.hh:190
Set options for reader/writer modules.
Definition: Options.hh:90
Set binary mode for r/w.
Definition: Options.hh:100