Commit c3aae7e7 authored by Jan Möbius's avatar Jan Möbius

Integrated OpenMesh CatmullClark algorithm into OpenFlipper subdivision plugin

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@14809 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 28ad7fd9
...@@ -59,6 +59,8 @@ ...@@ -59,6 +59,8 @@
#include <OpenMesh/Tools/Subdivider/Uniform/ModifiedButterFlyT.hh> #include <OpenMesh/Tools/Subdivider/Uniform/ModifiedButterFlyT.hh>
#include <OpenMesh/Tools/Subdivider/Uniform/LongestEdgeT.hh> #include <OpenMesh/Tools/Subdivider/Uniform/LongestEdgeT.hh>
#include <OpenMesh/Tools/Subdivider/Uniform/CatmullClarkT.hh>
SubdividerPlugin::SubdividerPlugin() : SubdividerPlugin::SubdividerPlugin() :
tool_(0), tool_(0),
...@@ -89,7 +91,7 @@ void SubdividerPlugin::pluginsInitialized() ...@@ -89,7 +91,7 @@ void SubdividerPlugin::pluginsInitialized()
{ {
emit setSlotDescription("subdivide(int,QString,int)", "Smooth a triangular mesh", emit setSlotDescription("subdivide(int,QString,int)", "Smooth a triangular mesh",
QString("object_id,algorithm,iterations").split(","), QString("object_id,algorithm,iterations").split(","),
QString("id of an object, algorithm to use (linear | loop | sqrt3 | interpolating_sqrt3 | modifiedButterfly ), number of iterations").split(",")); QString("id of an object, algorithm to use (linear | loop | sqrt3 | interpolating_sqrt3 | modifiedButterfly | catmullClark ), number of iterations").split(","));
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -117,6 +119,10 @@ void SubdividerPlugin::slotSubdivideUniform() ...@@ -117,6 +119,10 @@ void SubdividerPlugin::slotSubdivideUniform()
{ {
subdivide(ids[i],"modifiedButterfly",tool_->subdivision_steps_spinBox->value()); subdivide(ids[i],"modifiedButterfly",tool_->subdivision_steps_spinBox->value());
} }
else if ( tool_->catmullClark_radioButton->isChecked() )
{
subdivide(ids[i],"catmullClark",tool_->subdivision_steps_spinBox->value());
}
} }
} }
emit updateView(); emit updateView();
...@@ -178,51 +184,90 @@ void SubdividerPlugin::simpleSubdivide(int _objectId, QString _algorithm , int _ ...@@ -178,51 +184,90 @@ void SubdividerPlugin::simpleSubdivide(int _objectId, QString _algorithm , int _
void SubdividerPlugin::subdivide(int _objectId, QString _algorithm , int _steps) { void SubdividerPlugin::subdivide(int _objectId, QString _algorithm , int _steps) {
BaseObjectData* object; BaseObjectData* object;
if(!test_trimesh_object(_objectId , object)) PluginFunctions::getObject(_objectId,object);
if(!object) {
emit log(LOGERR,"Unable to get Object in SubdividerPlugin::subdivide");
return; return;
}
TriMesh* mesh = PluginFunctions::triMesh(object); TriMesh* mesh = PluginFunctions::triMesh(object);
PolyMesh* polyMesh = PluginFunctions::polyMesh(object);
if(_algorithm.contains("loop",Qt::CaseInsensitive)) if ( mesh ) {
{ if(_algorithm.contains("loop",Qt::CaseInsensitive))
OpenMesh::Subdivider::Uniform::LoopT<TriMesh,double> subdivider; {
OpenMesh::Subdivider::Uniform::LoopT<TriMesh,double> subdivider;
subdivider.attach(*mesh);
subdivider(*mesh,_steps,tool_->updatePoints->isChecked()); subdivider.attach(*mesh);
subdivider.detach(); subdivider(*mesh,_steps,tool_->updatePoints->isChecked());
} subdivider.detach();
else if ( _algorithm.contains("sqrt3",Qt::CaseInsensitive) ) }
{ else if ( _algorithm.contains("sqrt3",Qt::CaseInsensitive) )
OpenMesh::Subdivider::Uniform::Sqrt3T<TriMesh,double> subdivider; {
OpenMesh::Subdivider::Uniform::Sqrt3T<TriMesh,double> subdivider;
subdivider.attach(*mesh);
subdivider(_steps,tool_->updatePoints->isChecked()); subdivider.attach(*mesh);
subdivider.detach(); subdivider(_steps,tool_->updatePoints->isChecked());
} subdivider.detach();
else if ( _algorithm.contains("interpolating_sqrt(3)",Qt::CaseInsensitive) ) }
{ else if ( _algorithm.contains("interpolating_sqrt(3)",Qt::CaseInsensitive) )
OpenMesh::Subdivider::Uniform::InterpolatingSqrt3LGT<TriMesh,double> subdivider; {
OpenMesh::Subdivider::Uniform::InterpolatingSqrt3LGT<TriMesh,double> subdivider;
subdivider.attach(*mesh);
subdivider(_steps,tool_->updatePoints->isChecked()); subdivider.attach(*mesh);
subdivider.detach(); subdivider(_steps,tool_->updatePoints->isChecked());
} subdivider.detach();
else if ( _algorithm.contains("modifiedButterfly",Qt::CaseInsensitive) ) }
{ else if ( _algorithm.contains("modifiedButterfly",Qt::CaseInsensitive) )
OpenMesh::Subdivider::Uniform::ModifiedButterflyT<TriMesh,double> subdivider; {
OpenMesh::Subdivider::Uniform::ModifiedButterflyT<TriMesh,double> subdivider;
subdivider.attach(*mesh);
subdivider(_steps,tool_->updatePoints->isChecked()); subdivider.attach(*mesh);
subdivider.detach(); subdivider(_steps,tool_->updatePoints->isChecked());
subdivider.detach();
} else {
emit log(LOGERR,"Unsupported or unknown subdivider for triangular meshes: " + _algorithm);
}
mesh->garbage_collection();
mesh->update_face_normals();
mesh->update_vertex_normals();
//TriMeshObject* tmo = PluginFunctions::triMeshObject(object);
//tmo->update();
} }
mesh->garbage_collection(); if ( polyMesh ) {
mesh->update_face_normals(); if ( _algorithm.contains("catmullClark",Qt::CaseInsensitive) )
mesh->update_vertex_normals(); {
TriMeshObject* tmo = PluginFunctions::triMeshObject(object);
tmo->update(); PolyMesh* polyMesh = PluginFunctions::polyMesh(object);
if ( ! polyMesh) {
emit log(LOGERR,"Error: Catmull Clark only works on Poly Meshes!");
return;
}
OpenMesh::Subdivider::Uniform::CatmullClarkT<PolyMesh> subdivider;
subdivider.attach(*polyMesh);
subdivider(_steps,tool_->updatePoints->isChecked());
subdivider.detach();
polyMesh->garbage_collection();
polyMesh->update_face_normals();
polyMesh->update_vertex_normals();
//PolyMeshObject* pmo = PluginFunctions::polyMeshObject(object);
//pmo->update();
} else {
emit log(LOGERR,"Unsupported or unknown subdivider for polygonal meshes: " + _algorithm);
}
}
// Create backup // Create backup
emit createBackup(object->id(), "Subdivider", UPDATE_TOPOLOGY); emit createBackup(object->id(), "Subdivider", UPDATE_TOPOLOGY);
......
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#include <OpenFlipper/BasePlugin/BackupInterface.hh> #include <OpenFlipper/BasePlugin/BackupInterface.hh>
#include <OpenFlipper/common/Types.hh> #include <OpenFlipper/common/Types.hh>
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh> #include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
#include <ObjectTypes/PolyMesh/PolyMesh.hh>
#include "subdividerToolbar.hh" #include "subdividerToolbar.hh"
......
...@@ -109,6 +109,16 @@ of SIGGRAPH 1996, ACM SIGGRAPH, 1996, pp. 189-192.</string> ...@@ -109,6 +109,16 @@ of SIGGRAPH 1996, ACM SIGGRAPH, 1996, pp. 189-192.</string>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QRadioButton" name="catmullClark_radioButton">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Catmull Clark subdivision&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Note: Only works on quadrangular meshes!&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Catmull Clark</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>
......
Markdown is supported
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