54#include "SmootherPlugin.hh"
56#include "SmootherObject.hh"
59#define SMOOTHER "SmootherData"
63SmootherPlugin::SmootherPlugin() :
70SmootherPlugin::~SmootherPlugin() {
81 if ( OpenFlipper::Options::gui() ) {
89 toolIcon_ =
new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"smoother2.png");
102 emit setSlotDescription(
"smooth(int,int,QString,QString,double,bool)",
"Smooth an object",
103 QString(
"object_id,iterations,direction,continuity,maxDistance,respectFeatures").split(
","),
104 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(
","));
106 emit setSlotDescription(
"smooth(int,int,QString,QString,double)",
"Smooth an object",
107 QString(
"object_id,iterations,direction,continuity,maxDistance").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").split(
","));
110 emit setSlotDescription(
"smooth(int,int,QString,QString)",
"Smooth an object",
111 QString(
"object_id,iterations,direction,continuity").split(
","),
112 QString(
"id of an object, number of smoothing iterations, Smoothing direction. (tangential;normal;tangential+normal), Continuity. (C1 or C2)").split(
","));
136 emit log(
LOGWARN ,
"Unable to get object ( Only Triangle Meshes supported)");
147 if ( mesh == NULL ) {
148 emit log(
LOGERR,
"Unable to get mesh from object( Only Triangle Meshes supported)");
154 o_it->setObjectData(SMOOTHER, data);
161 if(
tool_->rbTangential_and_Normal->isChecked() ) {
163 }
else if(
tool_->rbNormal->isChecked() ) {
165 }
else if(
tool_->rbTangential->isChecked() ) {
170 data->component(component);
173 if(
tool_->rB_c0->isChecked() ) {
175 }
else if(
tool_->rB_c1->isChecked() ) {
180 data->continuity(continuity);
183 if (
tool_->cbDistance->isChecked() ) {
185 value =
tool_->distance->text();
188 double absoluteError = value.toDouble(&ok);
191 data->distance(absoluteError);
194 emit log(
LOGWARN ,
"Unable to read distance error from LineEdit");
200 data->features(
tool_->respectFeatures->isChecked());
201 data->iterations(
tool_->sB_iter->value());
205 if(
tool_->cbReinitialize->isChecked() || !data->initialized())
207 smoother.initialize(component,continuity );
208 data->initialized(
true);
213 smoother.
smooth( data->iterations() );
222 emit log(
LOGERR , tr(
"Unable to smooth. No triangle mesh selected as target!") );
229void SmootherPlugin::smooth(
int _objectId ,
int _iterations , QString _direction , QString _continuity,
double _maxDistance,
bool _respectFeatures ) {
233 emit log(
LOGERR,
"Unable to get Object");
241 emit log(
LOGWARN ,
"Unable to get object ( Only Triangle Meshes supported)");
250 if ( mesh == NULL ) {
251 emit log(
LOGERR,
"Unable to get mesh from object( Only Triangle Meshes supported)");
257 object->setObjectData(SMOOTHER, data);
263 bool tangential = _direction.contains(
"tangential");
264 bool normal = _direction.contains(
"normal");
266 if ( tangential && normal ) {
268 }
else if ( tangential ) {
275 data->component(component);
278 bool c0 = _continuity.contains(
"C0");
279 bool c1 = _continuity.contains(
"C1");
282 std::cerr <<
"Continuity C0 + C1 ? Using C1" << std::endl;
290 data->continuity(continuity);
292 if ( _maxDistance > 0.0) {
294 data->distance(_maxDistance);
298 data->distance( FLT_MAX );
303 data->features(_respectFeatures);
306 smoother.initialize(component,continuity);
308 smoother.
smooth( _iterations );
317 emit scriptInfo(tr(
"smooth(%1, %2, %3, %4, %5)").arg(QString::number(_objectId), QString::number(_iterations),
318 _direction, _continuity, QString::number(_maxDistance)));
321 emit log(
LOGERR,
"Unsupported object type for smoother");
#define DATA_TRIANGLE_MESH
bool dataType(DataType _type) const
void update_normals()
Compute normals for all primitives.
void smooth(unsigned int _n)
Do _n smoothing iterations.
void set_absolute_local_error(Scalar _err)
Set local error as an absolute value.
void skip_features(bool _state)
enable or disable feature handling
QIcon * toolIcon_
Icon of the toolbox.
SmootherToolbarWidget * tool_
Widget for Toolbox.
void pluginsInitialized()
Set the scripting slot descriptions.
void smooth(int _objectId, int _iterations, QString _direction, QString _continuity, double _maxDistance=-1.0, bool _respectFeatures=true)
smooth an object
void slot_smooth()
Slot connected to the smooth button in the toolbox.
Type for a MeshObject containing a triangle mesh.
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(4))
Geometry updated.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
TriMeshObject * triMeshObject(BaseObjectData *_object)
Cast an BaseObject to a TriMeshObject if possible.
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.
const QStringList TARGET_OBJECTS("target")
Iterable object range.