Skip to content
Snippets Groups Projects
Commit 4caf2844 authored by Jan Möbius's avatar Jan Möbius
Browse files

Smoother script interface

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@4977 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 0cd33bb3
No related branches found
No related tags found
No related merge requests found
......@@ -107,6 +107,71 @@ slot_smooth()
}
void SmootherPlugin::smooth(int _objectId , int _iterations , QString _direction , QString _continuity) {
BaseObjectData* baseObjectData;
if ( ! PluginFunctions::getObject(_objectId,baseObjectData) ) {
emit log(LOGERR,"Unable to get Object");
return;
}
if ( baseObjectData->dataType() == DATA_TRIANGLE_MESH ) {
TriMeshObject* object = PluginFunctions::triMeshObject(baseObjectData);
if ( object == 0 ) {
emit log(LOGWARN , "Unable to get object ( Only Triangle Meshes supported)");
return;
}
SmootherObject* data = dynamic_cast< SmootherObject* > ( object->objectData(SMOOTHER) );
if (data == 0){
TriMesh* mesh = PluginFunctions::triMesh(object);
data = new SmootherObject(mesh);
object->setObjectData(SMOOTHER, data);
}
OpenMesh::Smoother::SmootherT< TriMesh >::Component component = OpenMesh::Smoother::SmootherT< TriMesh >::Tangential_and_Normal;
bool tangential = _direction.contains("tangential");
bool normal = _direction.contains("normal");
if ( tangential && normal )
component = OpenMesh::Smoother::SmootherT< TriMesh >::Tangential_and_Normal;
else if ( tangential )
component = OpenMesh::Smoother::SmootherT< TriMesh >::Tangential;
else
component = OpenMesh::Smoother::SmootherT< TriMesh >::Normal;
OpenMesh::Smoother::SmootherT< TriMesh >::Continuity continuity = OpenMesh::Smoother::SmootherT< TriMesh >::C0;
bool c0 = _continuity.contains("C0");
bool c1 = _continuity.contains("C1");
if ( c0 && c1 )
std::cerr << "Continuity C0 + C1 ? Using C1" << std::endl;
if( c1 )
continuity = OpenMesh::Smoother::SmootherT< TriMesh >::C1;
else if( c0 )
continuity = OpenMesh::Smoother::SmootherT< TriMesh >::C0;
data->smoother->initialize(component,continuity);
data->smoother->smooth( _iterations );
TriMesh* mesh = PluginFunctions::triMesh(object);
if (mesh != 0) {
mesh->garbage_collection();
mesh->update_normals();
}
emit updatedObject( object->id() );
} else {
emit log(LOGERR,"Unsupported object type for smoother");
return;
}
}
//-----------------------------------------------------------------------------
Q_EXPORT_PLUGIN2( SmootherPlugin , SmootherPlugin );
......
......@@ -87,6 +87,15 @@ private slots:
public slots:
QString version() { return QString("1.0"); };
/** \brief Smooth object
*
* @param _objectId Object to smooth
* @param _iterations Number of smoothing iterations
* @param _direction tangential/normal/tangential+normal
* @param _continuity C0/C1
*/
void smooth(int _objectId , int _iterations , QString _direction , QString _continuity);
};
#endif //SMOOTHERPLUGIN_HH
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment