51 #include "SubdividerPlugin.hh"
61 #if QT_VERSION >= 0x050000
67 SubdividerPlugin::SubdividerPlugin() :
75 void SubdividerPlugin::initializePlugin()
77 if ( OpenFlipper::Options::gui() ) {
82 connect(
tool_->subdivide_uniform_toolButton, SIGNAL( clicked() ),
this, SLOT( slotSubdivideUniformButton() ) );
83 connect(
tool_->simpleButton, SIGNAL( clicked() ),
this, SLOT( slotSimpleSubdivideButton() ) );
87 toolIcon_ =
new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"subdivider.png");
88 emit addToolbox( tr(
"Subdivider") ,
tool_, toolIcon_ );
92 void SubdividerPlugin::pluginsInitialized()
94 emit setSlotDescription(
"subdivide(int,QString,int,bool)",
"Subdivide a triangular or polygonal mesh. For polygonal meshes use catmullClark, the other algorithms are for triangular meshes.",
95 QString(
"object_id,algorithm,iterations,update_points").split(
","),
96 QString(
" id of an object, algorithm to use ( loop | sqrt3 | interpolating_sqrt3 | modifiedButterfly | catmullClark ), number of iterations, update original points").split(
","));
98 emit setSlotDescription(
"subdivide(int,QString,int)",
"Subdivide a triangular or polygonal mesh. For polygonal meshes use catmullClark, the other algorithms are for triangular meshes. This function will modify the original point locations.",
99 QString(
"object_id,algorithm,iterations").split(
","),
100 QString(
" id of an object, algorithm to use ( loop | sqrt3 | interpolating_sqrt3 | modifiedButterfly | catmullClark ), number of iterations").split(
","));
102 emit setSlotDescription(
"simpleSubdivide(int,QString,int,double,bool)",
"Subdivide a triangular mesh.",
103 QString(
"object_id,algorithm,iterations,parameter,update_points").split(
","),
104 QString(
" id of an object, algorithm to use ( longest ), number of iterations, additional parameter(e.g. maximal edge length for longest), update original points").split(
","));
106 emit setSlotDescription(
"simpleSubdivide(int,QString,int,double)",
"Subdivide a triangular mesh. This function will modify the original point locations.",
107 QString(
"object_id,algorithm,iterations,parameter").split(
","),
108 QString(
" id of an object, algorithm to use ( longest ), number of iterations, additional parameter(e.g. maximal edge length for longest)").split(
","));
113 void SubdividerPlugin::slotSubdivideUniformButton()
115 std::vector< int > ids;
119 for (
unsigned int i = 0; i < ids.size(); ++i)
121 if(
tool_->loop_radioButton->isChecked())
123 subdivide(ids[i],
"loop",
tool_->subdivision_steps_spinBox->value(),
tool_->updatePoints->isChecked());
125 else if (
tool_->sqrt3_radioButton->isChecked() )
127 subdivide(ids[i],
"sqrt3",
tool_->subdivision_steps_spinBox->value(),
tool_->updatePoints->isChecked());
129 else if (
tool_->LabsikGreiner_radioButton->isChecked() )
131 subdivide(ids[i],
"interpolating_sqrt3",
tool_->subdivision_steps_spinBox->value(),
tool_->updatePoints->isChecked());
133 else if (
tool_->modifiedButterfly_radioButton->isChecked() )
135 subdivide(ids[i],
"modifiedButterfly",
tool_->subdivision_steps_spinBox->value(),
tool_->updatePoints->isChecked());
137 else if (
tool_->catmullClark_radioButton->isChecked() )
139 subdivide(ids[i],
"catmullClark",
tool_->subdivision_steps_spinBox->value(),
tool_->updatePoints->isChecked());
152 void SubdividerPlugin::slotSimpleSubdivideButton()
154 std::vector< int > ids;
157 for (
unsigned int i = 0; i < ids.size(); ++i)
159 if(
tool_->longestEdgeSplit->isChecked())
162 tool_->maximalEdgeLength->value(),
tool_->updatePoints->isChecked());
177 if (!test_trimesh_object(_objectId,
object)) {
178 emit log(
LOGERR,
"The simple subdivision algorithms only work on triangular meshes.");
184 if (_algorithm.contains(
"longest", Qt::CaseInsensitive)) {
188 subdivider.set_max_edge_length(_parameter);
189 subdivider(*mesh, _steps, _update_points);
192 emit log(
LOGERR,
"Unsupported algorithm in simpleSubdivide: " + _algorithm);
196 mesh->garbage_collection();
198 mesh->update_face_normals();
199 mesh->update_vertex_normals();
213 emit log(
LOGERR,
"Unable to get Object in SubdividerPlugin::subdivide");
219 if ( _algorithm.contains(
"catmullClark",Qt::CaseInsensitive) ) {
223 emit log(
LOGERR,
"Error: Catmull Clark only works on Poly Meshes!");
229 subdivider.
attach(*polyMesh);
230 subdivider(_steps,_update_points);
233 polyMesh->garbage_collection();
250 emit log(
LOGERR,
"Error: Unable to get trisngular mesh in subdivider!");
254 if(_algorithm.contains(
"loop",Qt::CaseInsensitive))
259 subdivider(*mesh,_steps,_update_points);
262 else if ( _algorithm.contains(
"sqrt3",Qt::CaseInsensitive) )
267 subdivider(_steps,_update_points);
270 else if ( _algorithm.contains(
"interpolating_sqrt(3)",Qt::CaseInsensitive) )
275 subdivider(_steps,_update_points);
278 else if ( _algorithm.contains(
"modifiedButterfly",Qt::CaseInsensitive) )
283 subdivider(_steps,_update_points);
286 emit log(
LOGERR,
"Unsupported or unknown subdivider for triangular meshes: " + _algorithm);
289 mesh->garbage_collection();
291 mesh->update_face_normals();
292 mesh->update_vertex_normals();
306 bool SubdividerPlugin::test_trimesh_object(
int _identifier,
BaseObjectData*& _object)
308 if ( _identifier == -1)
319 #if QT_VERSION < 0x050000
subdividerToolbarWidget * tool_
Widget for Toolbox.
bool getObject(int _identifier, BSplineCurveObject *&_object)
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
bool attach(MeshType &_m)
bool dataType(DataType _type) const
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
void simpleSubdivide(int _objectId, QString _algorithm, int _steps, double _parameter, bool _update_points=true)
Scripting slot for the simple subdivision algorithms.
void update_vertex_normals()
Update normal vectors for all vertices.
void update_face_normals()
Update normal vectors for all faces.
const UpdateType UPDATE_TOPOLOGY(UpdateTypeSet(1)<< 3)
Topology updated.
bool getTargetIdentifiers(std::vector< int > &_identifiers)
Get the identifiers of all objects marked as a target object.
#define DATA_TRIANGLE_MESH
void subdivide(int _objectId, QString _algorithm, int _steps, bool _update_points=true)
Scripting slot for subdivision.