54 #include "SmootherPlugin.hh" 56 #include "SmootherObject.hh" 59 #define SMOOTHER "SmootherData" 63 SmootherPlugin::SmootherPlugin() :
75 if ( OpenFlipper::Options::gui() ) {
83 toolIcon_ =
new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"smoother2.png");
84 emit addToolbox( tr(
"Smoother") ,
tool_, toolIcon_ );
96 emit setSlotDescription(
"smooth(int,int,QString,QString,double,bool)",
"Smooth an object",
97 QString(
"object_id,iterations,direction,continuity,maxDistance,respectFeatures").split(
","),
98 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(
","));
100 emit setSlotDescription(
"smooth(int,int,QString,QString,double)",
"Smooth an object",
101 QString(
"object_id,iterations,direction,continuity,maxDistance").split(
","),
102 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(
","));
104 emit setSlotDescription(
"smooth(int,int,QString,QString)",
"Smooth an object",
105 QString(
"object_id,iterations,direction,continuity").split(
","),
106 QString(
"id of an object, number of smoothing iterations, Smoothing direction. (tangential;normal;tangential+normal), Continuity. (C1 or C2)").split(
","));
127 QString jobDescription =
"Smoothed (";
132 emit log(
LOGWARN ,
"Unable to get object ( Only Triangle Meshes supported)");
143 if ( mesh == NULL ) {
144 emit log(
LOGERR,
"Unable to get mesh from object( Only Triangle Meshes supported)");
150 o_it->setObjectData(SMOOTHER, data);
157 if(
tool_->rbTangential_and_Normal->isChecked() ) {
159 jobDescription +=
"tangential and normal,";
160 }
else if(
tool_->rbNormal->isChecked() ) {
162 jobDescription +=
"normal,";
163 }
else if(
tool_->rbTangential->isChecked() ) {
165 jobDescription +=
"tangential,";
169 data->component(component);
172 if(
tool_->rB_c0->isChecked() ) {
174 jobDescription +=
"C0";
175 }
else if(
tool_->rB_c1->isChecked() ) {
177 jobDescription +=
"C1";
181 data->continuity(continuity);
184 if (
tool_->cbDistance->isChecked() ) {
186 value =
tool_->distance->text();
189 double absoluteError = value.toDouble(&ok);
192 data->distance(absoluteError);
195 emit log(
LOGWARN ,
"Unable to read distance error from LineEdit");
198 jobDescription +=
",max_error: " + QString::number(absoluteError);
202 data->features(
tool_->respectFeatures->isChecked());
203 data->iterations(
tool_->sB_iter->value());
207 if(
tool_->cbReinitialize->isChecked() || !data->initialized())
209 smoother.initialize(component,continuity );
210 data->initialized(
true);
215 smoother.
smooth( data->iterations() );
217 jobDescription +=
") " + QString::number(
tool_->sB_iter->value()) +
" iterations";
219 mesh->update_normals();
226 emit log(
LOGERR , tr(
"Unable to smooth. No triangle mesh selected as target!") );
233 void SmootherPlugin::smooth(
int _objectId ,
int _iterations , QString _direction , QString _continuity,
double _maxDistance,
bool _respectFeatures ) {
237 emit log(
LOGERR,
"Unable to get Object");
244 QString jobDescription =
"Smoothed (";
247 emit log(
LOGWARN ,
"Unable to get object ( Only Triangle Meshes supported)");
256 if ( mesh == NULL ) {
257 emit log(
LOGERR,
"Unable to get mesh from object( Only Triangle Meshes supported)");
263 object->setObjectData(SMOOTHER, data);
269 bool tangential = _direction.contains(
"tangential");
270 bool normal = _direction.contains(
"normal");
272 if ( tangential && normal ) {
274 jobDescription +=
"tangential and normal,";
275 }
else if ( tangential ) {
277 jobDescription +=
"normal,";
280 jobDescription +=
"tangential,";
284 data->component(component);
287 bool c0 = _continuity.contains(
"C0");
288 bool c1 = _continuity.contains(
"C1");
291 std::cerr <<
"Continuity C0 + C1 ? Using C1" << std::endl;
294 jobDescription +=
"C1";
297 jobDescription +=
"C0";
301 data->continuity(continuity);
303 if ( _maxDistance > 0.0) {
305 data->distance(_maxDistance);
307 jobDescription +=
",max_error: " + QString::number(_maxDistance);
310 data->distance( FLT_MAX );
315 data->features(_respectFeatures);
318 smoother.initialize(component,continuity);
320 smoother.
smooth( _iterations );
322 jobDescription +=
") " + QString::number(_iterations) +
" iterations";
324 mesh->update_normals();
331 emit scriptInfo(tr(
"smooth(%1, %2, %3, %4, %5)").arg(QString::number(_objectId), QString::number(_iterations),
332 _direction, _continuity, QString::number(_maxDistance)));
335 emit log(
LOGERR,
"Unsupported object type for smoother");
#define DATA_TRIANGLE_MESH
void smooth(unsigned int _n)
Do _n smoothing iterations.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
SmootherToolbarWidget * tool_
Widget for Toolbox.
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.
void pluginsInitialized()
Set the scripting slot descriptions.
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(4))
Geometry updated.
bool dataType(DataType _type) const
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
TriMeshObject * triMeshObject(BaseObjectData *_object)
Cast an BaseObject to a TriMeshObject if possible.
Type for a MeshObject containing a triangle mesh.
void slot_smooth()
Slot connected to the smooth button in the toolbox.
const QStringList TARGET_OBJECTS("target")
Iterable object range.
void smooth(int _objectId, int _iterations, QString _direction, QString _continuity, double _maxDistance=-1.0, bool _respectFeatures=true)
smooth an object
void skip_features(bool _state)
enable or disable feature handling