60 #include "SmootherPlugin.hh"
62 #include "SmootherObject.hh"
64 #if QT_VERSION >= 0x050000
69 #define SMOOTHER "SmootherData"
73 SmootherPlugin::SmootherPlugin() :
85 if ( OpenFlipper::Options::gui() ) {
93 toolIcon_ =
new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"smoother2.png");
94 emit addToolbox( tr(
"Smoother") ,
tool_, toolIcon_ );
106 emit setSlotDescription(
"smooth(int,int,QString,QString,double,bool)",
"Smooth an object",
107 QString(
"object_id,iterations,direction,continuity,maxDistance,respectFeatures").split(
","),
108 QString(
"id of an object, number of smoothing iterations, Smoothing direction. (tangential;normal;tangential+normal), Continuity. (C1 or C2), max distance the smoothed mesh is allowed to differ from the original,Keep features intact").split(
","));
110 emit setSlotDescription(
"smooth(int,int,QString,QString,double)",
"Smooth an object",
111 QString(
"object_id,iterations,direction,continuity,maxDistance").split(
","),
112 QString(
"id of an object, number of smoothing iterations, Smoothing direction. (tangential;normal;tangential+normal), Continuity. (C1 or C2), max distance the smoothed mesh is allowed to differ from the original").split(
","));
114 emit setSlotDescription(
"smooth(int,int,QString,QString)",
"Smooth an object",
115 QString(
"object_id,iterations,direction,continuity").split(
","),
116 QString(
"id of an object, number of smoothing iterations, Smoothing direction. (tangential;normal;tangential+normal), Continuity. (C1 or C2)").split(
","));
137 QString jobDescription =
"Smoothed (";
142 emit log(
LOGWARN ,
"Unable to get object ( Only Triangle Meshes supported)");
153 if ( mesh == NULL ) {
154 emit log(
LOGERR,
"Unable to get mesh from object( Only Triangle Meshes supported)");
160 o_it->setObjectData(SMOOTHER, data);
167 if(
tool_->rbTangential_and_Normal->isChecked() ) {
169 jobDescription +=
"tangential and normal,";
170 }
else if(
tool_->rbNormal->isChecked() ) {
172 jobDescription +=
"normal,";
173 }
else if(
tool_->rbTangential->isChecked() ) {
175 jobDescription +=
"tangential,";
179 data->component(component);
182 if(
tool_->rB_c0->isChecked() ) {
184 jobDescription +=
"C0";
185 }
else if(
tool_->rB_c1->isChecked() ) {
187 jobDescription +=
"C1";
191 data->continuity(continuity);
194 if (
tool_->cbDistance->isChecked() ) {
196 value =
tool_->distance->text();
199 double absoluteError = value.toDouble(&ok);
202 data->distance(absoluteError);
205 emit log(
LOGWARN ,
"Unable to read distance error from LineEdit");
208 jobDescription +=
",max_error: " + QString::number(absoluteError);
212 data->features(
tool_->respectFeatures->isChecked());
213 data->iterations(
tool_->sB_iter->value());
217 if(
tool_->cbReinitialize->isChecked() || !data->initialized())
219 smoother.initialize(component,continuity );
220 data->initialized(
true);
225 smoother.
smooth( data->iterations() );
227 jobDescription +=
") " + QString::number(
tool_->sB_iter->value()) +
" iterations";
229 mesh->update_normals();
236 emit log(
LOGERR , tr(
"Unable to smooth. No triangle mesh selected as target!") );
243 void SmootherPlugin::smooth(
int _objectId ,
int _iterations , QString _direction , QString _continuity,
double _maxDistance,
bool _respectFeatures ) {
247 emit log(
LOGERR,
"Unable to get Object");
254 QString jobDescription =
"Smoothed (";
257 emit log(
LOGWARN ,
"Unable to get object ( Only Triangle Meshes supported)");
266 if ( mesh == NULL ) {
267 emit log(
LOGERR,
"Unable to get mesh from object( Only Triangle Meshes supported)");
273 object->setObjectData(SMOOTHER, data);
279 bool tangential = _direction.contains(
"tangential");
280 bool normal = _direction.contains(
"normal");
282 if ( tangential && normal ) {
284 jobDescription +=
"tangential and normal,";
285 }
else if ( tangential ) {
287 jobDescription +=
"normal,";
290 jobDescription +=
"tangential,";
294 data->component(component);
297 bool c0 = _continuity.contains(
"C0");
298 bool c1 = _continuity.contains(
"C1");
301 std::cerr <<
"Continuity C0 + C1 ? Using C1" << std::endl;
304 jobDescription +=
"C1";
307 jobDescription +=
"C0";
311 data->continuity(continuity);
313 if ( _maxDistance > 0.0) {
315 data->distance(_maxDistance);
317 jobDescription +=
",max_error: " + QString::number(_maxDistance);
320 data->distance( FLT_MAX );
325 data->features(_respectFeatures);
328 smoother.initialize(component,continuity);
330 smoother.
smooth( _iterations );
332 jobDescription +=
") " + QString::number(_iterations) +
" iterations";
334 mesh->update_normals();
341 emit scriptInfo(tr(
"smooth(%1, %2, %3, %4, %5)").arg(QString::number(_objectId), QString::number(_iterations),
342 _direction, _continuity, QString::number(_maxDistance)));
345 emit log(
LOGERR,
"Unsupported object type for smoother");
353 #if QT_VERSION < 0x050000
void smooth(unsigned int _n)
Do _n smoothing iterations.
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
Type for a MeshObject containing a triangle mesh.
bool getObject(int _identifier, BSplineCurveObject *&_object)
void skip_features(bool _state)
enable or disable feature handling
const QStringList TARGET_OBJECTS("target")
Iterable object range.
bool dataType(DataType _type) const
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
void set_absolute_local_error(Scalar _err)
Set local error as an absolute value.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
TriMeshObject * triMeshObject(BaseObjectData *_object)
Cast an BaseObject to a TriMeshObject if possible.
void smooth(int _objectId, int _iterations, QString _direction, QString _continuity, double _maxDistance=-1.0, bool _respectFeatures=true)
smooth an object
SmootherToolbarWidget * tool_
Widget for Toolbox.
void pluginsInitialized()
Set the scripting slot descriptions.
#define DATA_TRIANGLE_MESH
void slot_smooth()
Slot connected to the smooth button in the toolbox.