ManifoldMusic
music visualization
 All Classes Files Functions Variables Enumerations Enumerator
MeshViewerWidget.h
Go to the documentation of this file.
1 
6 #ifndef OPENMESHAPPS_VIEWERWIDGET_HH
7 #define OPENMESHAPPS_VIEWERWIDGET_HH
8 
9 //== INCLUDES =================================================================
10 #include <QWidget>
11 #include <QString>
12 #include <QFileDialog>
13 #include <QPushButton>
14 #include <QColor>
15 #include <QColorDialog>
16 #include <OpenMesh/Tools/Utils/getopt.h>
17 #include <OpenMesh/Tools/Utils/Timer.hh>
18 #include "MeshViewerWidgetT.h"
19 #include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
20 #include <math.h>
21 
22 #include <QVBoxLayout>
23 #include <QHBoxLayout>
24 #include <qpushbutton.h>
25 
26 
27 
28 //== CLASS DEFINITION =========================================================
29 
30 using namespace OpenMesh;
31 using namespace OpenMesh::Attributes;
32 
33 
34 
35 //== CLASS DEFINITION =========================================================
36 
37 //class MeshViewerWidget : public MeshViewerWidgetT<MyMesh>
38 class MeshViewerWidget : public MeshViewerWidgetT<OpenMesh::TriMesh_ArrayKernelT<OpenMesh::DefaultTraits>>
39 {
40  Q_OBJECT
41 public:
43  //MeshViewerWidget(QWidget* parent=0) : MeshViewerWidgetT<MyMesh>(parent)
44  MeshViewerWidget(QWidget* parent=0) : MeshViewerWidgetT<OpenMesh::TriMesh_ArrayKernelT<OpenMesh::DefaultTraits>>(parent)
45  {
46  mhMesh = new MHMesh();
47  mhMesh->mesh = &mesh_;
48  t=clock();
49  }
50  OpenMesh::IO::Options& options() { return _options; }
51  const OpenMesh::IO::Options& options() const { return _options; }
52  void setOptions(const OpenMesh::IO::Options& opts) { _options = opts; }
53 
54  void open_mesh_gui(QString fname)
55  {
56  OpenMesh::Utils::Timer t;
57  t.start();
58  LoadMeshErr err = open_mesh(fname.toLocal8Bit(), _options);
59 
60  if ( fname.isEmpty() || err==UNKNOWN)
61  {
62  QString msg = "Cannot read mesh from file:\n '";
63  msg += fname;
64  msg += "'";
65  QMessageBox::critical( NULL, windowTitle(), msg);
66  }
67  if(err==FEW_VERTS){
68  QString msg = "Your mesh must have at least 64 vertices!";
69  QMessageBox::information( NULL, windowTitle(), msg);
70  }
71  if(err==MANY_VERTS){
72  QString msg = "Computing the manifold harmonics of a mesh with n vertices includes ";
73  msg+="computing the eigenvectors of an nxn-matrix, which has a complexity of O(n^3). ";
74  msg+="So, for your own good, please try to load a mesh with less than 1000 vertices.";
75  QMessageBox::information( NULL, windowTitle(), msg);
76  }
77  if(err==CORRUPT){
78  QString msg = "Your mesh should be manifold and closed in order to look good after reconstruction.";
79  QMessageBox::information( NULL, windowTitle(), msg);
80  }
81 
82  t.stop();
83  std::cout << "Loaded mesh in ~" << t.as_string() << std::endl;
84  }
85 
86 
87  void open_audio_gui(QString fname)
88  {
89  if ( fname.isEmpty() || !open_audio( fname.toLocal8Bit() ) )
90  {
91  QString msg = "Cannot load audio file from file:\n '";
92  msg += fname;
93  QMessageBox::warning( NULL, windowTitle(), msg );
94  }
95  }
96 
97 
98 public slots:
99  void query_open_mesh_file() {
100  QString fileName = QFileDialog::getOpenFileName(this,
101  tr("Open mesh file"),
102  tr(""),
103  tr("OBJ Files (*.obj);;"
104  "OFF Files (*.off);;"
105  "STL Files (*.stl);;"
106  "All Files (*)"));
107  if (!fileName.isEmpty())
108  open_mesh_gui(fileName);
109  }
110  void query_open_audio_file() {
111  QString fileName = QFileDialog::getOpenFileName(this,
112  tr("Open audio file"),
113  tr(""),
114  tr("Mp3 Files (*.mp3);;"
115  "All Files (*)"));
116  if (!fileName.isEmpty())
117  open_audio_gui(fileName);
118  }
119  void changeFreqs(int freqs)
120  {
121  int newfreqs = (int)pow((double)2,freqs);
122  if(newfreqs > mhMesh->mesh->n_vertices()){
123  return;
124  }
125  Config::numFreqs = newfreqs;
126  audio.setFreqs(Config::numFreqs);
127  }
128  void changeSmoothing(int s)
129  {
130  Config::smoothing = s;
131  }
132 
133 
134  void playPause(){
135  audio.playPause();
136  }
137  void rePlay(){
138  audio.rePlay();
139  }
140 
141  void eqLow(int val){
142  audio.updateEQ(LOW, val);
143  }
144  void eqMid(int val){
145  audio.updateEQ(MID, val);
146  }
147  void eqHigh(int val){
148  audio.updateEQ(HIGH, val);
149  }
150  void query_change_color(){
151  QColor c = QColorDialog::getColor();
152  float r = (float)c.red()/255;
153  float g = (float)c.green()/255;
154  float b = (float)c.blue()/255;
155  change_color(r,g,b);
156  }
157 
158 
159 private:
160  OpenMesh::IO::Options _options;
161 };
162 
163 
164 #endif