Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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  * $Revision$ *
45  * $Date$ *
46  * *
47 \*===========================================================================*/
48 
49 
50 //== INCLUDES =================================================================
51 
52 #ifdef _MSC_VER
53 # pragma warning(disable: 4267 4311)
54 #endif
55 
56 #include <iostream>
57 #include <fstream>
58 
59 #include <qapplication.h>
60 #include <qdatetime.h>
61 
62 #include <OpenMesh/Core/IO/BinaryHelper.hh>
63 #include <OpenMesh/Core/IO/MeshIO.hh>
64 
65 #include <OpenMesh/Apps/Decimating/DecimaterViewerWidget.hh>
66 
67 
68 //== IMPLEMENTATION ==========================================================
69 
70 
71 //-----------------------------------------------------------------------------
72 
73 void DecimaterViewerWidget::keyPressEvent(QKeyEvent* _event)
74 {
75  switch (_event->key())
76  {
77  case Key_H:
78  std::cout << "Press '+' to increase the number of decimating steps\n"
79  << "Press '-' to decrease the number of decimating steps\n"
80  << "Press 'd' to perform the set number of decimating steps\n"
81  << "Press 'S' to save the mesh to 'result.off'\n"
82  << "Press 'q' or 'Esc' quit the application" << std::endl;
83  break;
84  case Key_D:
85  {
86  int rc;
87  if ( (rc=decimater_->decimate(steps_)) )
88  {
89  decimater_->mesh().garbage_collection();
90  std::cout << rc << " vertices removed!\n";
91  updateGL();
92  }
93  else
94  std::cout << "Decimation failed\n";
95  break;
96  }
97 
98  case Key_Plus:
99  ++steps_;
100  steps_ = std::min( steps_ , (size_t)( mesh_.n_vertices() / 10 ) );
101  updateGL();
102  std::cout << "# decimating steps increased to " << steps_ << std::endl;
103  break;
104 
105  case Key_Minus:
106  --steps_;
107  steps_ = std::max( steps_ , size_t(1) );
108  updateGL();
109  std::cout << "# decimating steps increased to " << steps_ << std::endl;
110  break;
111 
112  case Key_S:
113  {
115 
117 
118  if (OpenMesh::IO::write_mesh( mesh(), "result.off", opt ))
119  std::cout << "mesh saved in 'result.off'\n";
120  }
121  break;
122 
123  case Key_Q:
124  qApp->quit();
125  break;
126  case Key_Escape:
127  qApp->quit();
128  break;
129  default:
130  this->inherited_t::keyPressEvent(_event);
131  break;
132  }
133 }
134 
135 void DecimaterViewerWidget::animate( void )
136 {
137 // updateGL();
138 // timer_->start(300, true);
139 }
140 
141 //=============================================================================
Set options for reader/writer modules.
Definition: Options.hh:95
Set binary mode for r/w.
Definition: Options.hh:105
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:199