Commit 9e54b27f authored by Mike Kremer's avatar Mike Kremer

DecimaterInfo which is derived from perObjectData does not contain any...

DecimaterInfo which is derived from perObjectData does not contain any pointers to decimaters anymore. All this is now handled by the decimater plugin. DecimaterInfo only holds the decimation values used for the decimation step.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9793 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 26f2bce9
......@@ -43,10 +43,12 @@
#include "DecimaterInfo.hh"
DecimaterInfo::DecimaterInfo() :
decimater_(),
normalDeviation_(false),
distance_(false),
roundness_(false) { }
roundness_(false),
normalDeviation_value_(0),
distance_value_(0),
roundness_value_(0) {}
DecimaterInfo::~DecimaterInfo() {
......@@ -61,77 +63,59 @@ PerObjectData* DecimaterInfo::copyPerObjectData() {
//-----------------------------------------------------------------------------------
void DecimaterInfo::initialize( ModQuadricH& _handle, TriMesh* _mesh ) {
decimater_ = std::tr1::shared_ptr< DecimaterType >( new DecimaterType( *_mesh ) );
void DecimaterInfo::setDistanceConstraint( double _value ){
decimater()->add( _handle );
decimater()->module( _handle ).unset_max_err();
}
//-----------------------------------------------------------------------------------
void DecimaterInfo::setDistanceConstraint( ModQuadricH& _handle, double _value ){
if ( decimater()->add( _handle ) ) {
decimater()->module( _handle ).set_max_err( _value );
distance_ = true;
}
distance_ = true;
distance_value_ = _value;
}
//-----------------------------------------------------------------------------------
void DecimaterInfo::setNormalDeviationConstraint( ModNormalFlippingH& _handle, int _value ){
void DecimaterInfo::setNormalDeviationConstraint( int _value ){
if ( decimater()->add( _handle ) ) {
decimater()->module( _handle ).set_normal_deviation( _value );
normalDeviation_ = true;
normalDeviation_value_ = _value;
}
normalDeviation_ = true;
normalDeviation_value_ = _value;
}
//-----------------------------------------------------------------------------------
void DecimaterInfo::setRoundnessConstraint( ModRoundnessH& _handle, double _value ){
void DecimaterInfo::setRoundnessConstraint( double _value ){
if ( decimater()->add( _handle ) ) {
decimater()->module( _handle ).set_min_roundness( _value , true );
roundness_ = true;
roundness_value_ = _value;
}
roundness_ = true;
roundness_value_ = _value;
}
//-----------------------------------------------------------------------------------
void DecimaterInfo::removeDistanceConstraint( ModQuadricH& _handle ){
void DecimaterInfo::removeDistanceConstraint(){
if ( distance_ ) {
decimater()->remove( _handle );
distance_ = false;
distance_value_ = 0;
}
}
//-----------------------------------------------------------------------------------
void DecimaterInfo::removeNormalDeviationConstraint( ModNormalFlippingH& _handle ){
void DecimaterInfo::removeNormalDeviationConstraint(){
if ( normalDeviation_ ) {
decimater()->remove( _handle );
normalDeviation_ = false;
normalDeviation_value_ = 0;
}
}
//-----------------------------------------------------------------------------------
void DecimaterInfo::removeRoundnessConstraint( ModRoundnessH& _handle ){
void DecimaterInfo::removeRoundnessConstraint(){
if ( roundness_ ) {
decimater()->remove( _handle );
roundness_ = false;
roundness_value_ = 0;
}
}
......
......@@ -58,12 +58,6 @@ class DecimaterInfo : public PerObjectData
{
public :
typedef OpenMesh::Decimater::DecimaterT< TriMesh > DecimaterType;
typedef OpenMesh::Decimater::ModNormalFlippingT< DecimaterType >::Handle ModNormalFlippingH;
typedef OpenMesh::Decimater::ModQuadricT< DecimaterType >::Handle ModQuadricH;
typedef OpenMesh::Decimater::ModRoundnessT< DecimaterType >::Handle ModRoundnessH;
//Konstruktor
DecimaterInfo();
......@@ -74,16 +68,13 @@ class DecimaterInfo : public PerObjectData
// Copy function
PerObjectData* copyPerObjectData();
// Initialize decimater
void initialize( ModQuadricH& _handle, TriMesh* _mesh );
void setDistanceConstraint( ModQuadricH& _handle, double _value );
void setNormalDeviationConstraint( ModNormalFlippingH& _handle, int _value );
void setRoundnessConstraint( ModRoundnessH& _handle, double _value );
void setDistanceConstraint( double _value );
void setNormalDeviationConstraint( int _value );
void setRoundnessConstraint( double _value );
void removeDistanceConstraint( ModQuadricH& _handle );
void removeNormalDeviationConstraint( ModNormalFlippingH& _handle );
void removeRoundnessConstraint( ModRoundnessH& _handle );
void removeDistanceConstraint();
void removeNormalDeviationConstraint();
void removeRoundnessConstraint();
// Get/Set methods
bool normalDeviation() { return normalDeviation_; }
......@@ -94,20 +85,14 @@ class DecimaterInfo : public PerObjectData
double distanceValue() { return distance_value_; }
double roundnessValue() { return roundness_value_; }
DecimaterType* decimater() { return decimater_.get(); };
private :
std::tr1::shared_ptr< DecimaterType > decimater_;
bool normalDeviation_;
int normalDeviation_value_;
bool distance_;
double distance_value_;
bool roundness_;
int normalDeviation_value_;
double distance_value_;
double roundness_value_;
};
......@@ -131,7 +131,7 @@ void DecimaterPlugin::updateRoundness(double _value)
*/
void DecimaterPlugin::slot_decimate()
{
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS,DATA_TRIANGLE_MESH) ;
o_it != PluginFunctions::objectsEnd(); ++o_it) {
......@@ -143,44 +143,76 @@ void DecimaterPlugin::slot_decimate()
DecimaterInfo* decimater = dynamic_cast< DecimaterInfo* > ( o_it->objectData(DECIMATER) );
TriMesh* mesh = PluginFunctions::triMesh(*o_it);
if (decimater == 0){
TriMesh* mesh = PluginFunctions::triMesh(*o_it);
decimater = new DecimaterInfo( );
decimater->initialize(hModPriorityQuadric_, mesh);
decimater = new DecimaterInfo();
o_it->setObjectData(DECIMATER, decimater);
}
//remove old constraints
decimater->removeDistanceConstraint(hModDistance_);
decimater->removeNormalDeviationConstraint(hModNormalFlipping_);
decimater->removeRoundnessConstraint(hModRoundness_);
// Constraint handles for decimation
ModNormalFlippingH hModNormalFlipping;
ModQuadricH hModDistance;
ModRoundnessH hModRoundness;
ModQuadricH hModPriorityQuadric;
// Create decimater
DecimaterType decimater_object( *mesh );
decimater_object.add( hModPriorityQuadric );
decimater_object.module( hModPriorityQuadric ).unset_max_err();
// Remove old constraints
if(decimater->distance()) {
decimater->removeDistanceConstraint();
decimater_object.remove(hModDistance);
}
if(decimater->normalDeviation()) {
decimater->removeNormalDeviationConstraint();
decimater_object.remove(hModNormalFlipping);
}
if(decimater->roundness()) {
decimater->removeRoundnessConstraint();
decimater_object.remove(hModRoundness);
}
//and set new constraints
if ( tool_->cbDistance->isChecked() )
decimater->setDistanceConstraint( hModDistance_, tool_->distance->value() );
if ( tool_->cbDistance->isChecked() ) {
if ( decimater_object.add( hModDistance ) ) {
decimater->setDistanceConstraint( tool_->distance->value() );
decimater_object.module( hModDistance ).set_max_err( decimater->distanceValue() );
}
}
if ( tool_->cbNormalDev->isChecked() )
decimater->setNormalDeviationConstraint( hModNormalFlipping_, tool_->normalDeviation->value() );
if ( tool_->cbNormalDev->isChecked() ) {
if ( decimater_object.add( hModNormalFlipping ) ) {
decimater->setNormalDeviationConstraint( tool_->normalDeviation->value() );
decimater_object.module( hModNormalFlipping ).set_normal_deviation( decimater->normalDeviationValue() );
}
}
if ( tool_->cbRoundness->isChecked() )
decimater->setRoundnessConstraint( hModRoundness_, tool_->roundness->value() );
if ( tool_->cbRoundness->isChecked() ) {
if ( decimater_object.add( hModRoundness ) ) {
decimater->setRoundnessConstraint( tool_->roundness->value() );
decimater_object.module( hModRoundness ).set_min_roundness( decimater->roundnessValue(), true );
}
}
//init the decimater
if( ! decimater->decimater()->initialize() ){
// Initialize the decimater
if( ! decimater_object.initialize() ){
emit log(LOGWARN, tr("Decimater could not be initialized"));
continue;
}
//decimate
if ( tool_->cbVertices->isChecked() )
decimater->decimater()->decimate_to( tool_->verticesCount->value() ); // do decimation
decimater_object.decimate_to(tool_->verticesCount->value());
else
decimater->decimater()->decimate(); // do decimation
decimater_object.decimate();
object->mesh()->garbage_collection();
object->mesh()->update_normals();
object->update();
// Create backup
emit createBackup(o_it->id(), "Decimation");
emit updatedObject( o_it->id() , UPDATE_TOPOLOGY );
......@@ -217,17 +249,37 @@ void DecimaterPlugin::decimate(int _objID, QVariantMap _constraints) {
DecimaterInfo* decimater = dynamic_cast< DecimaterInfo* > ( object->objectData(DECIMATER) );
TriMesh* mesh = PluginFunctions::triMesh(baseObjectData);
if (decimater == 0){
TriMesh* mesh = PluginFunctions::triMesh(baseObjectData);
decimater = new DecimaterInfo( );
decimater->initialize(hModPriorityQuadric_, mesh);
decimater = new DecimaterInfo();
object->setObjectData(DECIMATER, decimater);
}
//remove old constraints
decimater->removeDistanceConstraint(hModDistance_);
decimater->removeNormalDeviationConstraint(hModNormalFlipping_);
decimater->removeRoundnessConstraint(hModRoundness_);
// Constraint handles for decimation
ModNormalFlippingH hModNormalFlipping;
ModQuadricH hModDistance;
ModRoundnessH hModRoundness;
ModQuadricH hModPriorityQuadric;
// Create decimater
DecimaterType decimater_object( *mesh );
decimater_object.add( hModPriorityQuadric );
decimater_object.module( hModPriorityQuadric ).unset_max_err();
// Remove old constraints
if(decimater->distance()) {
decimater->removeDistanceConstraint();
decimater_object.remove(hModDistance);
}
if(decimater->normalDeviation()) {
decimater->removeNormalDeviationConstraint();
decimater_object.remove(hModNormalFlipping);
}
if(decimater->roundness()) {
decimater->removeRoundnessConstraint();
decimater_object.remove(hModRoundness);
}
//distance constraint
if ( _constraints.contains("distance") ){
......@@ -236,8 +288,12 @@ void DecimaterPlugin::decimate(int _objID, QVariantMap _constraints) {
double value = _constraints["distance"].toDouble(&ok);
if (ok)
decimater->setDistanceConstraint( hModDistance_, value );
if (ok) {
if ( decimater_object.add( hModDistance ) ) {
decimater->setDistanceConstraint( value );
decimater_object.module( hModDistance ).set_max_err( decimater->distanceValue() );
}
}
}
//normal deviation constraint
......@@ -247,8 +303,12 @@ void DecimaterPlugin::decimate(int _objID, QVariantMap _constraints) {
int value = _constraints["normal_deviation"].toInt(&ok);
if (ok)
decimater->setNormalDeviationConstraint( hModNormalFlipping_, value );
if (ok) {
if ( decimater_object.add( hModNormalFlipping ) ) {
decimater->setNormalDeviationConstraint( value );
decimater_object.module( hModNormalFlipping ).set_normal_deviation( decimater->normalDeviationValue() );
}
}
}
//roundness constraint
......@@ -258,8 +318,12 @@ void DecimaterPlugin::decimate(int _objID, QVariantMap _constraints) {
double value = _constraints["roundness"].toDouble(&ok);
if (ok)
decimater->setRoundnessConstraint( hModRoundness_, value );
if (ok) {
if ( decimater_object.add( hModRoundness ) ) {
decimater->setRoundnessConstraint( value );
decimater_object.module( hModRoundness ).set_min_roundness( decimater->roundnessValue(), true );
}
}
}
//triangleCount constraint
......@@ -279,16 +343,16 @@ void DecimaterPlugin::decimate(int _objID, QVariantMap _constraints) {
}
//init the decimater
if( ! decimater->decimater()->initialize() ){
if( ! decimater_object.initialize() ){
emit log(LOGWARN, tr("Decimater could not be initialized"));
return;
}
//decimate
if ( triangleCount )
decimater->decimater()->decimate_to( triangles ); // do decimation
decimater_object.decimate_to( triangles ); // do decimation
else
decimater->decimater()->decimate(); // do decimation
decimater_object.decimate(); // do decimation
object->mesh()->garbage_collection();
object->mesh()->update_normals();
......
......@@ -131,12 +131,12 @@ private :
/// Widget for Toolbox
DecimaterToolbarWidget* tool_;
/// Constraint handles for decimation
DecimaterInfo::ModNormalFlippingH hModNormalFlipping_;
DecimaterInfo::ModQuadricH hModDistance_;
DecimaterInfo::ModRoundnessH hModRoundness_;
DecimaterInfo::ModQuadricH hModPriorityQuadric_;
typedef OpenMesh::Decimater::DecimaterT< TriMesh > DecimaterType;
typedef OpenMesh::Decimater::ModNormalFlippingT< DecimaterType >::Handle ModNormalFlippingH;
typedef OpenMesh::Decimater::ModQuadricT< DecimaterType >::Handle ModQuadricH;
typedef OpenMesh::Decimater::ModRoundnessT< DecimaterType >::Handle ModRoundnessH;
private slots:
/// decimating called from button in toolbox
......
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