55 #ifndef SUBDIVIDEWIDGET_CC
56 #define SUBDIVIDEWIDGET_CC
62 #include <QApplication>
63 #include <QFileDialog>
64 #include <QButtonGroup>
65 #include <QRadioButton>
66 #include <QVBoxLayout>
67 #include <QHBoxLayout>
68 #include <QPushButton>
71 #include <QMessageBox>
74 #include <OpenMesh/Core/IO/MeshIO.hh>
75 #include <OpenMesh/Core/Mesh/PolyConnectivity.hh>
84 #include <OpenMesh/Apps/Subdivider/SubdivideWidget.hh>
95 timer_(NULL), animate_step_(0), max_animate_steps_(4), msecs_(0)
98 setWindowTitle( QString(_name) );
100 QVBoxLayout* vbox =
new QVBoxLayout();
102 cur_topo_type = SOP_Undefined;
108 vbox->addWidget(viewer_widget_);
110 QHBoxLayout* hbox =
new QHBoxLayout();
112 vbox->addLayout(hbox);
115 QPushButton* subdiv_button =
new QPushButton(
"Subdivide");
116 subdiv_button->setMinimumWidth(50);
117 QObject::connect( subdiv_button, SIGNAL( clicked() ),
118 this, SLOT( subdiv_slot() ) );
119 hbox->addWidget(subdiv_button);
122 QPushButton* load_button =
new QPushButton(
"Load Mesh");
123 load_button->setMinimumWidth(50);
124 QObject::connect( load_button, SIGNAL( clicked() ),
125 this, SLOT( load_slot() ) );
126 hbox->addWidget(load_button);
129 QPushButton* save_button =
new QPushButton(
"Save Mesh");
130 save_button->setMinimumWidth(50);
131 QObject::connect( save_button, SIGNAL( clicked() ),
132 this, SLOT( save_slot() ) );
133 hbox->addWidget(save_button);
137 QPushButton* reset_button =
new QPushButton(
"Reset");
138 reset_button->setMinimumWidth(50);
139 QObject::connect( reset_button, SIGNAL( clicked() ),
140 this, SLOT( reset_slot() ) );
141 hbox->addWidget(reset_button);
147 QButtonGroup* buttonGroup =
new QButtonGroup();
149 buttonGroup->setExclusive(
true );
152 QRadioButton* radio1 =
new QRadioButton(
"Comp. Loop" );
153 QRadioButton* radio2 =
new QRadioButton(
"Comp. SQRT(3)" );
154 QRadioButton* radio3 =
new QRadioButton(
"Loop" );
155 QRadioButton* radio4 =
new QRadioButton(
"Sqrt(3)" );
156 QRadioButton* radio5 =
new QRadioButton(
"Interpolating Sqrt3" );
157 QRadioButton* radio6 =
new QRadioButton(
"Modified Butterfly" );
159 radio3->setChecked(
true );
160 sel_topo_type = SOP_UniformLoop;
162 buttonGroup->addButton(radio1, SOP_UniformCompositeLoop);
163 buttonGroup->addButton(radio2, SOP_UniformCompositeSqrt3);
164 buttonGroup->addButton(radio3, SOP_UniformLoop);
165 buttonGroup->addButton(radio4, SOP_UniformSqrt3);
166 buttonGroup->addButton(radio5, SOP_UniformInterpolatingSqrt3);
167 buttonGroup->addButton(radio6, SOP_ModifiedButterfly);
170 vbox->addWidget(radio1);
171 vbox->addWidget(radio2);
172 vbox->addWidget(radio3);
173 vbox->addWidget(radio4);
174 vbox->addWidget(radio5);
175 vbox->addWidget(radio6);
178 QObject::connect( buttonGroup, SIGNAL( buttonPressed(
int) ),
179 this, SLOT( slot_select_sop(
int) ) );
184 status_bar->showMessage(
"0 Faces, 0 Edges, 0 Vertices");
192 timer_ =
new QTimer(
this);
193 connect( timer_, SIGNAL( timeout() ),
this, SLOT( animate_slot() ) );
210 void SubdivideWidget::slot_select_sop(
int i)
214 case SOP_UniformCompositeLoop:
215 case SOP_UniformCompositeSqrt3:
216 case SOP_UniformLoop:
217 case SOP_UniformSqrt3:
218 case SOP_UniformInterpolatingSqrt3:
219 case SOP_ModifiedButterfly:
220 case SOP_CatmullClark: sel_topo_type = (SOPType)i;
break;
221 default: sel_topo_type = SOP_Undefined;
228 void SubdivideWidget::keyPressEvent( QKeyEvent *k )
230 bool timerStopped =
false;
231 if ( timer_->isActive())
254 if (timer_->isActive())
261 timer_->setSingleShot(
true );
276 void SubdivideWidget::update()
278 size_t n_faces = viewer_widget_->mesh().n_faces();
279 size_t n_edges = viewer_widget_->mesh().n_edges();
280 size_t n_vertices = viewer_widget_->mesh().n_vertices();
281 QString message(
""), temp;
282 message.append(temp.setNum(n_faces));
283 message.append(
" Faces, ");
284 message.append(temp.setNum(n_edges));
285 message.append(
" Edges, ");
286 message.append(temp.setNum(n_vertices));
287 message.append(
" Vertices. ");
290 message.append(temp.setNum(msecs_/1000.0));
300 void SubdivideWidget::reset_slot()
302 if (cur_topo_type != SOP_Undefined)
303 subdivider_[cur_topo_type]->detach();
305 viewer_widget_->mesh() = viewer_widget_->orig_mesh();
306 viewer_widget_->mesh().update_face_normals();
307 viewer_widget_->mesh().update_vertex_normals();
308 viewer_widget_->updateGL();
310 cur_topo_type = SOP_Undefined;
318 void SubdivideWidget::subdiv_slot()
320 assert( sel_topo_type != SOP_Undefined );
325 status_bar->showMessage(
"processing subdivision step...");
327 if (cur_topo_type != sel_topo_type)
329 if (cur_topo_type!=SOP_Undefined)
330 subdivider_[cur_topo_type]->detach();
331 subdivider_[cur_topo_type=sel_topo_type]->attach(viewer_widget_->mesh());
334 std::clog <<
"subdiving...\n";
335 (*subdivider_[sel_topo_type])(1);
336 std::clog <<
"subdiving...done\n";
339 viewer_widget_->mesh().update_normals();
340 viewer_widget_->updateGL();
354 if (viewer_widget_->
open_mesh(_filename, opt))
367 SubdivideWidget::save_slot()
371 QString write_filter(IOManager().qt_write_filters().c_str());
372 QString filename = QFileDialog::getSaveFileName(
this,
"",
"", write_filter);
374 if (!filename.isEmpty()){
379 std::cerr <<
"FAILED\n";
387 SubdivideWidget::load_slot()
391 QString read_filter(IOManager().qt_read_filters().c_str());
393 QFileDialog::getOpenFileName(
this,
"",
"", read_filter);
395 if (!filename.isNull())
398 if (cur_topo_type != SOP_Undefined)
399 subdivider_[cur_topo_type]->detach();
402 std::string file( filename.toStdString() );
404 if ( !viewer_widget_->
open_mesh(file.c_str() , opt) )
406 QString msg =
"Cannot read mesh from file ";
407 QMessageBox::critical(
this,
"", msg + filename, QMessageBox::Ok );
411 cur_topo_type = SOP_Undefined;
419 SubdivideWidget::animate_slot()
421 if (++animate_step_ < max_animate_steps_)
430 timer_->setSingleShot(
true);
431 timer_->start( 500 );
435 #endif //SUBDIVIDEWIDGET_CC deifined
bool open_mesh(const char *_filename)
open mesh from _filename
QStatusBar * status_bar
Updates Status Bar Information.
Set options for reader/writer modules.
SubdivideWidget(QWidget *_parent=0, const char *_name=0)
constructor
bool open_mesh(const char *_filename, OpenMesh::IO::Options _opt)
open mesh
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()