50 #ifndef SUBDIVIDEWIDGET_CC 51 #define SUBDIVIDEWIDGET_CC 57 #include <QApplication> 58 #include <QFileDialog> 59 #include <QButtonGroup> 60 #include <QRadioButton> 61 #include <QVBoxLayout> 62 #include <QHBoxLayout> 63 #include <QPushButton> 66 #include <QMessageBox> 69 #include <OpenMesh/Core/IO/MeshIO.hh> 70 #include <OpenMesh/Core/Mesh/PolyConnectivity.hh> 79 #include <OpenMesh/Apps/Subdivider/SubdivideWidget.hh> 90 timer_(NULL), animate_step_(0), max_animate_steps_(4), msecs_(0)
93 setWindowTitle( QString(_name) );
95 QVBoxLayout* vbox =
new QVBoxLayout();
97 cur_topo_type = SOP_Undefined;
103 vbox->addWidget(viewer_widget_);
105 QHBoxLayout* hbox =
new QHBoxLayout();
107 vbox->addLayout(hbox);
110 QPushButton* subdiv_button =
new QPushButton(
"Subdivide");
111 subdiv_button->setMinimumWidth(50);
112 QObject::connect( subdiv_button, SIGNAL( clicked() ),
113 this, SLOT( subdiv_slot() ) );
114 hbox->addWidget(subdiv_button);
117 QPushButton* load_button =
new QPushButton(
"Load Mesh");
118 load_button->setMinimumWidth(50);
119 QObject::connect( load_button, SIGNAL( clicked() ),
120 this, SLOT( load_slot() ) );
121 hbox->addWidget(load_button);
124 QPushButton* save_button =
new QPushButton(
"Save Mesh");
125 save_button->setMinimumWidth(50);
126 QObject::connect( save_button, SIGNAL( clicked() ),
127 this, SLOT( save_slot() ) );
128 hbox->addWidget(save_button);
132 QPushButton* reset_button =
new QPushButton(
"Reset");
133 reset_button->setMinimumWidth(50);
134 QObject::connect( reset_button, SIGNAL( clicked() ),
135 this, SLOT( reset_slot() ) );
136 hbox->addWidget(reset_button);
142 QButtonGroup* buttonGroup =
new QButtonGroup();
144 buttonGroup->setExclusive(
true );
147 QRadioButton* radio1 =
new QRadioButton(
"Comp. Loop" );
148 QRadioButton* radio2 =
new QRadioButton(
"Comp. SQRT(3)" );
149 QRadioButton* radio3 =
new QRadioButton(
"Loop" );
150 QRadioButton* radio4 =
new QRadioButton(
"Sqrt(3)" );
151 QRadioButton* radio5 =
new QRadioButton(
"Interpolating Sqrt3" );
152 QRadioButton* radio6 =
new QRadioButton(
"Modified Butterfly" );
154 radio3->setChecked(
true );
155 sel_topo_type = SOP_UniformLoop;
157 buttonGroup->addButton(radio1, SOP_UniformCompositeLoop);
158 buttonGroup->addButton(radio2, SOP_UniformCompositeSqrt3);
159 buttonGroup->addButton(radio3, SOP_UniformLoop);
160 buttonGroup->addButton(radio4, SOP_UniformSqrt3);
161 buttonGroup->addButton(radio5, SOP_UniformInterpolatingSqrt3);
162 buttonGroup->addButton(radio6, SOP_ModifiedButterfly);
165 vbox->addWidget(radio1);
166 vbox->addWidget(radio2);
167 vbox->addWidget(radio3);
168 vbox->addWidget(radio4);
169 vbox->addWidget(radio5);
170 vbox->addWidget(radio6);
173 QObject::connect( buttonGroup, SIGNAL( buttonPressed(
int) ),
174 this, SLOT( slot_select_sop(
int) ) );
179 status_bar->showMessage(
"0 Faces, 0 Edges, 0 Vertices");
187 timer_ =
new QTimer(
this);
188 connect( timer_, SIGNAL( timeout() ),
this, SLOT( animate_slot() ) );
205 void SubdivideWidget::slot_select_sop(
int i)
209 case SOP_UniformCompositeLoop:
210 case SOP_UniformCompositeSqrt3:
211 case SOP_UniformLoop:
212 case SOP_UniformSqrt3:
213 case SOP_UniformInterpolatingSqrt3:
214 case SOP_ModifiedButterfly:
215 case SOP_CatmullClark: sel_topo_type = (SOPType)i;
break;
216 default: sel_topo_type = SOP_Undefined;
223 void SubdivideWidget::keyPressEvent( QKeyEvent *k )
225 bool timerStopped =
false;
226 if ( timer_->isActive())
249 if (timer_->isActive())
256 timer_->setSingleShot(
true );
271 void SubdivideWidget::update()
273 size_t n_faces = viewer_widget_->mesh().n_faces();
274 size_t n_edges = viewer_widget_->mesh().n_edges();
275 size_t n_vertices = viewer_widget_->mesh().n_vertices();
276 QString message(
""), temp;
277 message.append(temp.setNum(n_faces));
278 message.append(
" Faces, ");
279 message.append(temp.setNum(n_edges));
280 message.append(
" Edges, ");
281 message.append(temp.setNum(n_vertices));
282 message.append(
" Vertices. ");
285 message.append(temp.setNum(msecs_/1000.0));
295 void SubdivideWidget::reset_slot()
297 if (cur_topo_type != SOP_Undefined)
298 subdivider_[cur_topo_type]->detach();
300 viewer_widget_->mesh() = viewer_widget_->orig_mesh();
301 viewer_widget_->mesh().update_face_normals();
302 viewer_widget_->mesh().update_vertex_normals();
303 viewer_widget_->updateGL();
305 cur_topo_type = SOP_Undefined;
313 void SubdivideWidget::subdiv_slot()
315 assert( sel_topo_type != SOP_Undefined );
320 status_bar->showMessage(
"processing subdivision step...");
322 if (cur_topo_type != sel_topo_type)
324 if (cur_topo_type!=SOP_Undefined)
325 subdivider_[cur_topo_type]->detach();
326 subdivider_[cur_topo_type=sel_topo_type]->attach(viewer_widget_->mesh());
329 std::clog <<
"subdiving...\n";
330 (*subdivider_[sel_topo_type])(1);
331 std::clog <<
"subdiving...done\n";
334 viewer_widget_->mesh().update_normals();
335 viewer_widget_->updateGL();
349 if (viewer_widget_->open_mesh(_filename, opt))
362 SubdivideWidget::save_slot()
366 QString write_filter(IOManager().qt_write_filters().c_str());
367 QString filename = QFileDialog::getSaveFileName(
this,
"",
"", write_filter);
369 if (!filename.isEmpty()){
374 std::cerr <<
"FAILED\n";
382 SubdivideWidget::load_slot()
386 QString read_filter(IOManager().qt_read_filters().c_str());
388 QFileDialog::getOpenFileName(
this,
"",
"", read_filter);
390 if (!filename.isNull())
393 if (cur_topo_type != SOP_Undefined)
394 subdivider_[cur_topo_type]->detach();
397 std::string file( filename.toStdString() );
399 if ( !viewer_widget_->open_mesh(file.c_str() , opt) )
401 QString msg =
"Cannot read mesh from file ";
402 QMessageBox::critical(
this,
"", msg + filename, QMessageBox::Ok );
406 cur_topo_type = SOP_Undefined;
414 SubdivideWidget::animate_slot()
416 if (++animate_step_ < max_animate_steps_)
425 timer_->setSingleShot(
true);
426 timer_->start( 500 );
430 #endif //SUBDIVIDEWIDGET_CC deifined SubdivideWidget(QWidget *_parent=0, const char *_name=0)
constructor
bool open_mesh(const char *_filename)
open mesh from _filename
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.
_IOManager_ & IOManager()
Set options for reader/writer modules.
QStatusBar * status_bar
Updates Status Bar Information.