43 #include "SmootherPlugin.hh" 49 #include <QGridLayout> 50 #include <QPushButton> 53 SmootherPlugin::SmootherPlugin() :
59 SmootherPlugin::~SmootherPlugin()
64 void SmootherPlugin::initializePlugin()
67 QWidget* toolBox =
new QWidget();
68 QGridLayout* layout =
new QGridLayout(toolBox);
70 QPushButton* smoothButton =
new QPushButton(
"&Smooth",toolBox);
71 smoothButton->setToolTip(tr(
"Smooths an Object using Laplacian Smoothing."));
72 smoothButton->setWhatsThis(tr(
"Smooths an Object using Laplacian Smoothing. Use the Smooth Plugin for more options."));
81 iterationsSpinbox_->setWhatsThis(tr(
"Give the number, how often the Laplacian Smoothing should modify the object."));
83 QLabel* label =
new QLabel(
"Iterations:");
85 layout->addWidget( label , 0, 0);
86 layout->addWidget( smoothButton , 1, 1);
89 layout->addItem(
new QSpacerItem(10,10,QSizePolicy::Expanding,QSizePolicy::Expanding),2,0,1,2);
91 connect( smoothButton, SIGNAL(clicked()),
this, SLOT(
simpleLaplace()) );
93 QIcon* toolIcon =
new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"smoother1.png");
94 emit addToolbox( tr(
"Simple Smoother") , toolBox, toolIcon );
100 emit setSlotDescription(tr(
"simpleLaplace(int)"), tr(
"Smooth mesh using the Laplace operator with uniform weights."),
101 QStringList(tr(
"iterations")), QStringList(tr(
"Number of iterations")));
113 if(!OpenFlipper::Options::nogui()) {
131 bool selectionExists =
false;
142 mesh->add_property( origPositions,
"SmootherPlugin_Original_Positions" );
144 for (
int i = 0 ; i < _iterations ; ++i ) {
147 TriMesh::VertexIter v_it, v_end=mesh->vertices_end();
148 for (v_it=mesh->vertices_begin(); v_it!=v_end; ++v_it) {
149 mesh->property( origPositions, *v_it ) = mesh->point(*v_it);
151 selectionExists |= mesh->status(*v_it).selected();
155 for (v_it=mesh->vertices_begin(); v_it!=v_end; ++v_it) {
157 if(selectionExists && mesh->status(*v_it).selected() ==
false) {
161 TriMesh::Point point = TriMesh::Point(0.0,0.0,0.0);
167 TriMesh::VertexOHalfedgeIter voh_it(*mesh,*v_it);
168 for ( ; voh_it.is_valid(); ++voh_it ) {
170 point += mesh->property( origPositions, mesh->to_vertex_handle(*voh_it) );
174 if ( mesh->is_boundary( *voh_it ) ) {
182 point /= mesh->valence( *v_it );
186 mesh->point(*v_it) = point;
193 mesh->remove_property( origPositions );
195 mesh->update_normals();
211 mesh->add_property( origPositions,
"SmootherPlugin_Original_Positions" );
213 for (
int i = 0 ; i < _iterations ; ++i ) {
216 PolyMesh::VertexIter v_it, v_end=mesh->vertices_end();
217 for (v_it=mesh->vertices_begin(); v_it!=v_end; ++v_it) {
218 mesh->property( origPositions, *v_it ) = mesh->point(*v_it);
220 selectionExists |= mesh->status(*v_it).selected();
224 for (v_it=mesh->vertices_begin(); v_it!=v_end; ++v_it) {
226 if(selectionExists && mesh->status(*v_it).selected() ==
false) {
230 PolyMesh::Point point = PolyMesh::Point(0.0,0.0,0.0);
236 PolyMesh::VertexOHalfedgeIter voh_it(*mesh,*v_it);
237 for ( ; voh_it.is_valid(); ++voh_it ) {
239 point += mesh->property( origPositions, mesh->to_vertex_handle(*voh_it) );
243 if ( mesh->is_boundary( *voh_it ) ) {
251 point /= mesh->valence( *v_it );
255 mesh->point(*v_it) = point;
262 mesh->remove_property( origPositions );
264 mesh->update_normals();
273 emit log(
LOGERR,
"DataType not supported.");
278 emit scriptInfo(
"simpleLaplace(" + QString::number(_iterations) +
")");
const QStringList TARGET_OBJECTS("target")
Iterable object range.
void pluginsInitialized()
Set the scripting slot descriptions.
QSpinBox * iterationsSpinbox_
SpinBox for Number of iterations.
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
#define DATA_TRIANGLE_MESH
void simpleLaplace()
simpleLaplace