52 #include "SmootherPlugin.hh"
58 SmootherPlugin::SmootherPlugin() :
64 SmootherPlugin::~SmootherPlugin()
69 void SmootherPlugin::initializePlugin()
72 QWidget* toolBox =
new QWidget();
73 QGridLayout* layout =
new QGridLayout(toolBox);
75 QPushButton* smoothButton =
new QPushButton(
"&Smooth",toolBox);
76 smoothButton->setToolTip(tr(
"Smooths an Object using Laplacian Smoothing."));
77 smoothButton->setWhatsThis(tr(
"Smooths an Object using Laplacian Smoothing. Use the Smooth Plugin for more options."));
86 iterationsSpinbox_->setWhatsThis(tr(
"Give the number, how often the Laplacian Smoothing should modify the object."));
88 QLabel* label =
new QLabel(
"Iterations:");
90 layout->addWidget( label , 0, 0);
91 layout->addWidget( smoothButton , 1, 1);
94 layout->addItem(
new QSpacerItem(10,10,QSizePolicy::Expanding,QSizePolicy::Expanding),2,0,1,2);
96 connect( smoothButton, SIGNAL(clicked()),
this, SLOT(
simpleLaplace()) );
98 QIcon* toolIcon =
new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"smoother1.png");
99 emit addToolbox( tr(
"Simple Smoother") , toolBox, toolIcon );
105 emit setSlotDescription(tr(
"simpleLaplace(int)"), tr(
"Smooth mesh using the Laplace operator with uniform weights."),
106 QStringList(tr(
"iterations")), QStringList(tr(
"Number of iterations")));
118 if(!OpenFlipper::Options::nogui()) {
136 bool selectionExists =
false;
147 mesh->add_property( origPositions,
"SmootherPlugin_Original_Positions" );
149 for (
int i = 0 ; i < _iterations ; ++i ) {
152 TriMesh::VertexIter v_it, v_end=mesh->vertices_end();
153 for (v_it=mesh->vertices_begin(); v_it!=v_end; ++v_it) {
154 mesh->property( origPositions, *v_it ) = mesh->point(*v_it);
156 selectionExists |= mesh->status(*v_it).selected();
160 for (v_it=mesh->vertices_begin(); v_it!=v_end; ++v_it) {
162 if(selectionExists && mesh->status(*v_it).selected() ==
false) {
166 TriMesh::Point point = TriMesh::Point(0.0,0.0,0.0);
172 TriMesh::VertexOHalfedgeIter voh_it(*mesh,*v_it);
173 for ( ; voh_it.is_valid(); ++voh_it ) {
175 point += mesh->property( origPositions, mesh->to_vertex_handle(*voh_it) );
179 if ( mesh->is_boundary( *voh_it ) ) {
187 point /= mesh->valence( *v_it );
191 mesh->point(*v_it) = point;
198 mesh->remove_property( origPositions );
200 mesh->update_normals();
216 mesh->add_property( origPositions,
"SmootherPlugin_Original_Positions" );
218 for (
int i = 0 ; i < _iterations ; ++i ) {
221 PolyMesh::VertexIter v_it, v_end=mesh->vertices_end();
222 for (v_it=mesh->vertices_begin(); v_it!=v_end; ++v_it) {
223 mesh->property( origPositions, *v_it ) = mesh->point(*v_it);
225 selectionExists |= mesh->status(*v_it).selected();
229 for (v_it=mesh->vertices_begin(); v_it!=v_end; ++v_it) {
231 if(selectionExists && mesh->status(*v_it).selected() ==
false) {
242 for ( ; voh_it.is_valid(); ++voh_it ) {
244 point += mesh->property( origPositions, mesh->to_vertex_handle(*voh_it) );
248 if ( mesh->is_boundary( *voh_it ) ) {
256 point /= mesh->valence( *v_it );
260 mesh->point(*v_it) = point;
267 mesh->remove_property( origPositions );
278 emit log(
LOGERR,
"DataType not supported.");
283 emit scriptInfo(
"simpleLaplace(" + QString::number(_iterations) +
")");
289 #if QT_VERSION < 0x050000
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
Kernel::Point Point
Coordinate type.
const QStringList TARGET_OBJECTS("target")
Iterable object range.
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
void simpleLaplace()
simpleLaplace
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
Kernel::VertexOHalfedgeIter VertexOHalfedgeIter
Circulator.
void update_normals()
Compute normals for all primitives.
QSpinBox * iterationsSpinbox_
SpinBox for Number of iterations.
void pluginsInitialized()
Set the scripting slot descriptions.
#define DATA_TRIANGLE_MESH