45 #include "SubdividerPlugin.hh" 57 SubdividerPlugin::SubdividerPlugin() :
65 void SubdividerPlugin::initializePlugin()
67 if ( OpenFlipper::Options::gui() ) {
72 connect(tool_->subdivide_uniform_toolButton, SIGNAL( clicked() ),
this, SLOT( slotSubdivideUniformButton() ) );
73 connect(tool_->simpleButton, SIGNAL( clicked() ),
this, SLOT( slotSimpleSubdivideButton() ) );
77 toolIcon_ =
new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"subdivider.png");
78 emit addToolbox( tr(
"Subdivider") , tool_, toolIcon_ );
82 void SubdividerPlugin::pluginsInitialized()
84 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.",
85 QString(
"object_id,algorithm,iterations,update_points").split(
","),
86 QString(
" id of an object, algorithm to use ( loop | sqrt3 | interpolating_sqrt3 | modifiedButterfly | catmullClark ), number of iterations, update original points").split(
","));
88 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.",
89 QString(
"object_id,algorithm,iterations").split(
","),
90 QString(
" id of an object, algorithm to use ( loop | sqrt3 | interpolating_sqrt3 | modifiedButterfly | catmullClark ), number of iterations").split(
","));
92 emit
setSlotDescription(
"simpleSubdivide(int,QString,int,double,bool)",
"Subdivide a triangular mesh.",
93 QString(
"object_id,algorithm,iterations,parameter,update_points").split(
","),
94 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(
","));
96 emit
setSlotDescription(
"simpleSubdivide(int,QString,int,double)",
"Subdivide a triangular mesh. This function will modify the original point locations.",
97 QString(
"object_id,algorithm,iterations,parameter").split(
","),
98 QString(
" id of an object, algorithm to use ( longest ), number of iterations, additional parameter(e.g. maximal edge length for longest)").split(
","));
103 void SubdividerPlugin::slotSubdivideUniformButton()
105 std::vector< int > ids;
109 for (
unsigned int i = 0; i < ids.size(); ++i)
111 if(tool_->loop_radioButton->isChecked())
113 subdivide(ids[i],
"loop",tool_->subdivision_steps_spinBox->value(), tool_->updatePoints->isChecked());
115 else if ( tool_->sqrt3_radioButton->isChecked() )
117 subdivide(ids[i],
"sqrt3",tool_->subdivision_steps_spinBox->value(), tool_->updatePoints->isChecked());
119 else if ( tool_->LabsikGreiner_radioButton->isChecked() )
121 subdivide(ids[i],
"interpolating_sqrt3",tool_->subdivision_steps_spinBox->value(), tool_->updatePoints->isChecked());
123 else if ( tool_->modifiedButterfly_radioButton->isChecked() )
125 subdivide(ids[i],
"modifiedButterfly",tool_->subdivision_steps_spinBox->value(), tool_->updatePoints->isChecked());
127 else if ( tool_->catmullClark_radioButton->isChecked() )
129 subdivide(ids[i],
"catmullClark",tool_->subdivision_steps_spinBox->value(), tool_->updatePoints->isChecked());
142 void SubdividerPlugin::slotSimpleSubdivideButton()
144 std::vector< int > ids;
147 for (
unsigned int i = 0; i < ids.size(); ++i)
149 if(tool_->longestEdgeSplit->isChecked())
151 simpleSubdivide(ids[i],
"longest",tool_->subdivision_steps_spinBox->value(),
152 tool_->maximalEdgeLength->value(), tool_->updatePoints->isChecked());
167 if (!test_trimesh_object(_objectId,
object)) {
168 emit log(
LOGERR,
"The simple subdivision algorithms only work on triangular meshes.");
174 if (_algorithm.contains(
"longest", Qt::CaseInsensitive)) {
178 subdivider.set_max_edge_length(_parameter);
179 subdivider(*mesh, _steps, _update_points);
182 emit log(
LOGERR,
"Unsupported algorithm in simpleSubdivide: " + _algorithm);
186 mesh->garbage_collection();
203 emit log(
LOGERR,
"Unable to get Object in SubdividerPlugin::subdivide");
209 if ( _algorithm.contains(
"catmullClark",Qt::CaseInsensitive) ) {
213 emit log(
LOGERR,
"Error: Catmull Clark only works on Poly Meshes!");
219 subdivider.
attach(*polyMesh);
220 subdivider(_steps,_update_points);
223 polyMesh->garbage_collection();
240 emit log(
LOGERR,
"Error: Unable to get trisngular mesh in subdivider!");
244 if(_algorithm.contains(
"loop",Qt::CaseInsensitive))
249 subdivider(*mesh,_steps,_update_points);
252 else if ( _algorithm.contains(
"sqrt3",Qt::CaseInsensitive) )
257 subdivider(_steps,_update_points);
260 else if ( _algorithm.contains(
"interpolating_sqrt(3)",Qt::CaseInsensitive) )
265 subdivider(_steps,_update_points);
268 else if ( _algorithm.contains(
"modifiedButterfly",Qt::CaseInsensitive) )
273 subdivider(_steps,_update_points);
276 emit log(
LOGERR,
"Unsupported or unknown subdivider for triangular meshes: " + _algorithm);
279 mesh->garbage_collection();
296 bool SubdividerPlugin::test_trimesh_object(
int _identifier,
BaseObjectData*& _object)
298 if ( _identifier == -1)
const UpdateType UPDATE_TOPOLOGY(UpdateTypeSet(8))
Topology updated.
#define DATA_TRIANGLE_MESH
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
virtual void updateView()
Update current view in Main Application.
virtual void setSlotDescription(QString _slotName, QString _slotDescription, QStringList _parameters, QStringList _descriptions)
Set a description for a public slot.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
bool dataType(DataType _type) const
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.
bool getTargetIdentifiers(std::vector< int > &_identifiers)
Get the identifiers of all objects marked as a target object.
void subdivide(int _objectId, QString _algorithm, int _steps, bool _update_points=true)
Scripting slot for subdivision.