Commit 40a37a84 authored by Jan Möbius's avatar Jan Möbius
Browse files

Removed extra update for simple smoother

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@4191 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 12b73c75
...@@ -12,12 +12,12 @@ ...@@ -12,12 +12,12 @@
// it under the terms of the GNU Lesser General Public License as published by // it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// OpenFlipper is distributed in the hope that it will be useful, // OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details. // GNU Lesser General Public License for more details.
// //
// You should have received a copy of the GNU Lesser General Public License // You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>. // along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
// //
...@@ -32,176 +32,175 @@ ...@@ -32,176 +32,175 @@
#include <QtGui> #include <QtGui>
#include <QSpacerItem> #include <QSpacerItem>
#include "SmootherPlugin.hh" #include "SmootherPlugin.hh"
#include <iostream> #include <iostream>
#include <ACG/GL/GLState.hh> #include <ACG/GL/GLState.hh>
#include "OpenFlipper/BasePlugin/PluginFunctions.hh" #include "OpenFlipper/BasePlugin/PluginFunctions.hh"
bool SmootherPlugin::initializeToolbox(QWidget*& _widget) bool SmootherPlugin::initializeToolbox(QWidget*& _widget)
{ {
// Create the Toolbox Widget // Create the Toolbox Widget
tool_ = new QWidget(); tool_ = new QWidget();
_widget = tool_; _widget = tool_;
QSize size(300, 300); QSize size(300, 300);
tool_->resize(size); tool_->resize(size);
MeshDialogLayout_ = new QGridLayout( tool_); MeshDialogLayout_ = new QGridLayout( tool_);
smoothButton_ = new QPushButton("&Smooth",tool_); smoothButton_ = new QPushButton("&Smooth",tool_);
iterationsSpinbox_ = new QSpinBox(tool_) ; iterationsSpinbox_ = new QSpinBox(tool_) ;
iterationsSpinbox_->setMinimum(1); iterationsSpinbox_->setMinimum(1);
iterationsSpinbox_->setMaximum(1000); iterationsSpinbox_->setMaximum(1000);
iterationsSpinbox_->setSingleStep(1); iterationsSpinbox_->setSingleStep(1);
smootherTypeBox_ = new QComboBox(); smootherTypeBox_ = new QComboBox();
smootherTypeBox_->addItem("Simple Laplace"); smootherTypeBox_->addItem("Simple Laplace");
MeshDialogLayout_->addWidget( smootherTypeBox_,0 , 0 , 1 , 2 , Qt::AlignTop ); MeshDialogLayout_->addWidget( smootherTypeBox_,0 , 0 , 1 , 2 , Qt::AlignTop );
MeshDialogLayout_->addWidget( smoothButton_ , 1, 0 , Qt::AlignTop ); MeshDialogLayout_->addWidget( smoothButton_ , 1, 0 , Qt::AlignTop );
MeshDialogLayout_->addWidget( iterationsSpinbox_, 1, 1 , Qt::AlignTop ); MeshDialogLayout_->addWidget( iterationsSpinbox_, 1, 1 , Qt::AlignTop );
MeshDialogLayout_->addItem(new QSpacerItem(10,10,QSizePolicy::Expanding,QSizePolicy::Expanding),2,0,1,2); MeshDialogLayout_->addItem(new QSpacerItem(10,10,QSizePolicy::Expanding,QSizePolicy::Expanding),2,0,1,2);
connect(smoothButton_,SIGNAL(clicked()),this,SLOT(slotSmooth())); connect(smoothButton_,SIGNAL(clicked()),this,SLOT(slotSmooth()));
return true; return true;
} }
void SmootherPlugin::simpleLaplace() { void SmootherPlugin::simpleLaplace() {
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS,DATA_TRIANGLE_MESH) ; for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS,DATA_TRIANGLE_MESH) ;
o_it != PluginFunctions::objects_end(); ++o_it) { o_it != PluginFunctions::objects_end(); ++o_it) {
// Get the mesh to work on // Get the mesh to work on
TriMesh* mesh = PluginFunctions::triMesh(*o_it); TriMesh* mesh = PluginFunctions::triMesh(*o_it);
// Add a property to the mesh to store original vertex positions // Add a property to the mesh to store original vertex positions
mesh->add_property( orig_pos_, "SmootherPlugin_Original_Positions" ); mesh->add_property( orig_pos_, "SmootherPlugin_Original_Positions" );
for ( int i = 0 ; i < iterationsSpinbox_->value() ; ++i ) { for ( int i = 0 ; i < iterationsSpinbox_->value() ; ++i ) {
// Copy original positions to backup ( in Vertex property ) // Copy original positions to backup ( in Vertex property )
TriMesh::VertexIter v_it, v_end=mesh->vertices_end(); TriMesh::VertexIter v_it, v_end=mesh->vertices_end();
for (v_it=mesh->vertices_begin(); v_it!=v_end; ++v_it) { for (v_it=mesh->vertices_begin(); v_it!=v_end; ++v_it) {
mesh->property( orig_pos_ , v_it ) = mesh->point(v_it); mesh->property( orig_pos_ , v_it ) = mesh->point(v_it);
} }
// Do one smoothing step (For each point of the mesh ... ) // Do one smoothing step (For each point of the mesh ... )
for (v_it=mesh->vertices_begin(); v_it!=v_end; ++v_it) { for (v_it=mesh->vertices_begin(); v_it!=v_end; ++v_it) {
TriMesh::Point point = TriMesh::Point(0.0,0.0,0.0); TriMesh::Point point = TriMesh::Point(0.0,0.0,0.0);
// Flag, to skip boundary vertices // Flag, to skip boundary vertices
bool skip = false; bool skip = false;
// ( .. for each Outoing halfedge .. ) // ( .. for each Outoing halfedge .. )
TriMesh::VertexOHalfedgeIter voh_it(*mesh,v_it); TriMesh::VertexOHalfedgeIter voh_it(*mesh,v_it);
for ( ; voh_it; ++voh_it ) { for ( ; voh_it; ++voh_it ) {
// .. add the (original) position of the Neighbour ( end of the outgoing halfedge ) // .. add the (original) position of the Neighbour ( end of the outgoing halfedge )
point += mesh->property( orig_pos_ , mesh->to_vertex_handle(voh_it) ); point += mesh->property( orig_pos_ , mesh->to_vertex_handle(voh_it) );
// Check if the current Halfedge is a boundary halfedge // Check if the current Halfedge is a boundary halfedge
// If it is, abort and keep the current vertex position // If it is, abort and keep the current vertex position
if ( mesh->is_boundary( voh_it.handle() ) ) { if ( mesh->is_boundary( voh_it.handle() ) ) {
skip = true; skip = true;
break; break;
} }
} }
// Devide by the valence of the current vertex // Devide by the valence of the current vertex
point /= mesh->valence( v_it ); point /= mesh->valence( v_it );
if ( ! skip ) { if ( ! skip ) {
// Set new position for the mesh if its not on the boundary // Set new position for the mesh if its not on the boundary
mesh->point(v_it) = point; mesh->point(v_it) = point;
} }
} }
}// Iterations end }// Iterations end
// Remove the property // Remove the property
mesh->remove_property( orig_pos_); mesh->remove_property( orig_pos_);
mesh->update_normals(); mesh->update_normals();
emit updatedObject( o_it->id() ); emit updatedObject( o_it->id() );
} }
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS,DATA_POLY_MESH) ; for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS,DATA_POLY_MESH) ;
o_it != PluginFunctions::objects_end(); ++o_it) { o_it != PluginFunctions::objects_end(); ++o_it) {
// Get the mesh to work on // Get the mesh to work on
PolyMesh* mesh = dynamic_cast< MeshObject< PolyMesh,DATA_POLY_MESH >* > (*o_it)->mesh(); PolyMesh* mesh = dynamic_cast< MeshObject< PolyMesh,DATA_POLY_MESH >* > (*o_it)->mesh();
// Add a property to the mesh to store original vertex positions // Add a property to the mesh to store original vertex positions
mesh->add_property( orig_pos_, "SmootherPlugin_Original_Positions" ); mesh->add_property( orig_pos_, "SmootherPlugin_Original_Positions" );
for ( int i = 0 ; i < iterationsSpinbox_->value() ; ++i ) { for ( int i = 0 ; i < iterationsSpinbox_->value() ; ++i ) {
// Copy original positions to backup ( in Vertex property ) // Copy original positions to backup ( in Vertex property )
PolyMesh::VertexIter v_it, v_end=mesh->vertices_end(); PolyMesh::VertexIter v_it, v_end=mesh->vertices_end();
for (v_it=mesh->vertices_begin(); v_it!=v_end; ++v_it) { for (v_it=mesh->vertices_begin(); v_it!=v_end; ++v_it) {
mesh->property( orig_pos_ , v_it ) = mesh->point(v_it); mesh->property( orig_pos_ , v_it ) = mesh->point(v_it);
} }
// Do one smoothing step (For each point of the mesh ... ) // Do one smoothing step (For each point of the mesh ... )
for (v_it=mesh->vertices_begin(); v_it!=v_end; ++v_it) { for (v_it=mesh->vertices_begin(); v_it!=v_end; ++v_it) {
PolyMesh::Point point = PolyMesh::Point(0.0,0.0,0.0); PolyMesh::Point point = PolyMesh::Point(0.0,0.0,0.0);
// Flag, to skip boundary vertices // Flag, to skip boundary vertices
bool skip = false; bool skip = false;
// ( .. for each Outoing halfedge .. ) // ( .. for each Outoing halfedge .. )
PolyMesh::VertexOHalfedgeIter voh_it(*mesh,v_it); PolyMesh::VertexOHalfedgeIter voh_it(*mesh,v_it);
for ( ; voh_it; ++voh_it ) { for ( ; voh_it; ++voh_it ) {
// .. add the (original) position of the Neighbour ( end of the outgoing halfedge ) // .. add the (original) position of the Neighbour ( end of the outgoing halfedge )
point += mesh->property( orig_pos_ , mesh->to_vertex_handle(voh_it) ); point += mesh->property( orig_pos_ , mesh->to_vertex_handle(voh_it) );
// Check if the current Halfedge is a boundary halfedge // Check if the current Halfedge is a boundary halfedge
// If it is, abort and keep the current vertex position // If it is, abort and keep the current vertex position
if ( mesh->is_boundary( voh_it.handle() ) ) { if ( mesh->is_boundary( voh_it.handle() ) ) {
skip = true; skip = true;
break; break;
} }
} }
// Devide by the valence of the current vertex // Devide by the valence of the current vertex
point /= mesh->valence( v_it ); point /= mesh->valence( v_it );
if ( ! skip ) { if ( ! skip ) {
// Set new position for the mesh if its not on the boundary // Set new position for the mesh if its not on the boundary
mesh->point(v_it) = point; mesh->point(v_it) = point;
} }
} }
}// Iterations end }// Iterations end
// Remove the property // Remove the property
mesh->remove_property( orig_pos_); mesh->remove_property( orig_pos_);
mesh->update_normals(); mesh->update_normals();
emit updatedObject( o_it->id() ); emit updatedObject( o_it->id() );
} }
emit updateView();
} }
void SmootherPlugin::slotSmooth() void SmootherPlugin::slotSmooth()
{ {
switch (smootherTypeBox_->currentIndex() ) { switch (smootherTypeBox_->currentIndex() ) {
case 0 : case 0 :
simpleLaplace(); simpleLaplace();
break; break;
default : default :
std::cerr << "Smoother : Smoother type error" << std::endl; std::cerr << "Smoother : Smoother type error" << std::endl;
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment