Commit 94b7cbb9 authored by Mike Kremer's avatar Mike Kremer

Suspended handling of smoother object to smoother plugin such that backup...

Suspended handling of smoother object to smoother plugin such that backup plugin can call the copy constructor of the SmootherObject which is derived from PerObjectData. No memory issues could occur anymore since the SmootherObject only contains the smoothing parameters and NOT the instance of the smoother itself.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9794 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 4737e85e
......@@ -43,11 +43,19 @@
#include "SmootherObject.hh"
SmootherObject::SmootherObject(TriMesh* _mesh){
smoother_ = std::tr1::shared_ptr< SmootherType >( new SmootherType( *_mesh ) );
SmootherObject::SmootherObject() :
distance_(0.0f),
respectFeatures_(false),
iterations_(0u) {
}
SmootherObject::~SmootherObject() {
}
SmootherObject::~SmootherObject(){
PerObjectData* SmootherObject::copyPerObjectData() {
SmootherObject* so_copy = new SmootherObject(*this);
return so_copy;
}
......@@ -54,15 +54,45 @@ class SmootherObject : public PerObjectData
{
public:
typedef OpenMesh::Smoother::JacobiLaplaceSmootherT< TriMesh > SmootherType;
SmootherObject();
~SmootherObject();
// Copy function
PerObjectData* copyPerObjectData();
SmootherObject(TriMesh* _mesh);
~SmootherObject();
private:
typedef OpenMesh::Smoother::SmootherT< TriMesh >::Component SmoothingComponent;
typedef OpenMesh::Smoother::SmootherT< TriMesh >::Continuity SmoothingContinuity;
public:
// Get/Set methods
void component(SmoothingComponent _comp) { component_ = _comp; }
void continuity(SmoothingContinuity _cont) { continuity_ = _cont; }
void distance(float _distance) { distance_ = _distance; }
void features(bool _features) { respectFeatures_ = _features; }
void iterations(uint _iterations) { iterations_ = _iterations; }
SmootherType* smoother() { return smoother_.get(); };
SmoothingComponent component() { return component_; }
SmoothingContinuity continuity() { return continuity_; }
float distance() { return distance_; }
bool features() { return respectFeatures_; }
uint iterations() { return iterations_; }
private:
std::tr1::shared_ptr< SmootherType > smoother_;
// Smoothing attributes
// Component:
SmoothingComponent component_;
// Continuity
SmoothingContinuity continuity_;
// Constraints
float distance_;
bool respectFeatures_;
// Iterations
uint iterations_;
};
......@@ -129,12 +129,16 @@ slot_smooth()
SmootherObject* data = dynamic_cast< SmootherObject* > ( o_it->objectData(SMOOTHER) );
if (data == 0){
// Get triangle mesh
TriMesh* mesh = PluginFunctions::triMesh(*o_it);
data = new SmootherObject(mesh);
if (data == 0){
data = new SmootherObject();
o_it->setObjectData(SMOOTHER, data);
}
// Create smoother
SmootherType smoother(*mesh);
OpenMesh::Smoother::SmootherT< TriMesh >::Component component = OpenMesh::Smoother::SmootherT< TriMesh >::Tangential_and_Normal;
if( tool_->rbTangential_and_Normal->isChecked() ) {
......@@ -148,6 +152,9 @@ slot_smooth()
jobDescription += "tangential,";
}
// Set perObjectData
data->component(component);
OpenMesh::Smoother::SmootherT< TriMesh >::Continuity continuity = OpenMesh::Smoother::SmootherT< TriMesh >::C0;
if( tool_->rB_c0->isChecked() ) {
continuity = OpenMesh::Smoother::SmootherT< TriMesh >::C0;
......@@ -157,6 +164,9 @@ slot_smooth()
jobDescription += "C1";
}
// Set perObjectData
data->continuity(continuity);
// Read maximum distance Error from lineEdit
if ( tool_->cbDistance->isChecked() ) {
QString value;
......@@ -165,22 +175,27 @@ slot_smooth()
double absoluteError = value.toDouble(&ok);
if ( ok )
data->smoother()->set_absolute_local_error( absoluteError );
else
if ( ok ) {
data->distance(absoluteError);
smoother.set_absolute_local_error( absoluteError );
} else {
emit log(LOGWARN , "Unable to read distance error from LineEdit");
}
jobDescription += ",max_error: " + QString::number(absoluteError);
}
data->smoother()->initialize(component,continuity );
data->smoother()->skip_features(tool_->respectFeatures->isChecked());
// Set perObjectData
data->features(tool_->respectFeatures->isChecked());
data->iterations(tool_->sB_iter->value());
data->smoother()->smooth( tool_->sB_iter->value() );
// Initialize smoother
smoother.initialize(component,continuity );
smoother.skip_features(data->features());
jobDescription += ") " + QString::number(tool_->sB_iter->value()) + " iterations";
smoother.smooth( data->iterations() );
TriMesh* mesh = PluginFunctions::triMesh(*o_it);
jobDescription += ") " + QString::number(tool_->sB_iter->value()) + " iterations";
if (mesh != 0)
mesh->garbage_collection();
......@@ -226,12 +241,16 @@ void SmootherPlugin::smooth(int _objectId , int _iterations , QString _direction
SmootherObject* data = dynamic_cast< SmootherObject* > ( object->objectData(SMOOTHER) );
if (data == 0){
// Get triangle mesh
TriMesh* mesh = PluginFunctions::triMesh(object);
data = new SmootherObject(mesh);
if (data == 0){
data = new SmootherObject();
object->setObjectData(SMOOTHER, data);
}
SmootherType smoother(*mesh);
OpenMesh::Smoother::SmootherT< TriMesh >::Component component = OpenMesh::Smoother::SmootherT< TriMesh >::Tangential_and_Normal;
bool tangential = _direction.contains("tangential");
bool normal = _direction.contains("normal");
......@@ -247,6 +266,8 @@ void SmootherPlugin::smooth(int _objectId , int _iterations , QString _direction
jobDescription += "tangential,";
}
// Set perObjectData
data->component(component);
OpenMesh::Smoother::SmootherT< TriMesh >::Continuity continuity = OpenMesh::Smoother::SmootherT< TriMesh >::C0;
bool c0 = _continuity.contains("C0");
......@@ -262,16 +283,23 @@ void SmootherPlugin::smooth(int _objectId , int _iterations , QString _direction
jobDescription += "C0";
}
// Set perObjectData
data->continuity(continuity);
if ( _maxDistance > 0.0) {
data->smoother()->set_absolute_local_error( _maxDistance );
// Set perObjectData
data->distance(_maxDistance);
smoother.set_absolute_local_error( _maxDistance );
jobDescription += ",max_error: " + QString::number(_maxDistance);
} else
data->smoother()->set_absolute_local_error( FLT_MAX );
} else {
// Set perObjectData
data->distance( FLT_MAX );
smoother.set_absolute_local_error( FLT_MAX );
}
data->smoother()->initialize(component,continuity);
smoother.initialize(component,continuity);
data->smoother()->smooth( _iterations );
TriMesh* mesh = PluginFunctions::triMesh(object);
smoother.smooth( _iterations );
jobDescription += ") " + QString::number(_iterations) + " iterations";
......
......@@ -152,6 +152,8 @@ public slots:
/** @} */
private:
typedef OpenMesh::Smoother::JacobiLaplaceSmootherT< TriMesh > SmootherType;
};
#endif //SMOOTHERPLUGIN_HH
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment