Commit 26f2bce9 authored by Mike Kremer's avatar Mike Kremer

Suspended constraint handles from perObjectData class to plugin such that the...

Suspended constraint handles from perObjectData class to plugin such that the backup plugin can use the copy constructor for the perObjectData derived class.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9789 383ad7c9-94d9-4d36-a494-682f7c89f535
parent b83e4d2c
......@@ -42,79 +42,96 @@
#include "DecimaterInfo.hh"
DecimaterInfo::DecimaterInfo(TriMesh* _mesh) :
DecimaterInfo::DecimaterInfo() :
decimater_(),
normalDeviation_(false),
distance_(false),
roundness_(false)
{
decimater_ = std::tr1::shared_ptr< DecimaterType >( new DecimaterType( *_mesh ) );
roundness_(false) { }
decimater()->add( hModQuadric_priority );
decimater()->module( hModQuadric_priority ).unset_max_err();
DecimaterInfo::~DecimaterInfo() {
}
DecimaterInfo::~DecimaterInfo() {
PerObjectData* DecimaterInfo::copyPerObjectData() {
DecimaterInfo* di_copy = new DecimaterInfo(*this);
return di_copy;
}
//-----------------------------------------------------------------------------------
void DecimaterInfo::initialize( ModQuadricH& _handle, TriMesh* _mesh ) {
decimater_ = std::tr1::shared_ptr< DecimaterType >( new DecimaterType( *_mesh ) );
void DecimaterInfo::removeConstraints(){
decimater()->add( _handle );
decimater()->module( _handle ).unset_max_err();
}
decimater()->module( hModQuadric_priority ).unset_max_err();
//-----------------------------------------------------------------------------------
//remove modules
void DecimaterInfo::setDistanceConstraint( ModQuadricH& _handle, double _value ){
if ( normalDeviation_ ) {
decimater()->remove( hModNormalFlipping );
normalDeviation_ = false;
if ( decimater()->add( _handle ) ) {
decimater()->module( _handle ).set_max_err( _value );
distance_ = true;
}
}
if ( distance_ ) {
decimater()->remove( hModQuadric );
distance_ = false;
}
if ( roundness_ ) {
decimater()->remove( hModRoundness );
roundness_ = false;
}
//-----------------------------------------------------------------------------------
void DecimaterInfo::setNormalDeviationConstraint( ModNormalFlippingH& _handle, int _value ){
if ( decimater()->add( _handle ) ) {
decimater()->module( _handle ).set_normal_deviation( _value );
normalDeviation_ = true;
normalDeviation_value_ = _value;
}
}
//-----------------------------------------------------------------------------------
void DecimaterInfo::setDistanceConstraint( double _value ){
void DecimaterInfo::setRoundnessConstraint( ModRoundnessH& _handle, double _value ){
if ( decimater()->add( hModQuadric ) ) {
decimater()->module( hModQuadric ).set_max_err( _value );
distance_ = true;
if ( decimater()->add( _handle ) ) {
decimater()->module( _handle ).set_min_roundness( _value , true );
roundness_ = true;
roundness_value_ = _value;
}
}
//-----------------------------------------------------------------------------------
void DecimaterInfo::removeDistanceConstraint( ModQuadricH& _handle ){
if ( distance_ ) {
decimater()->remove( _handle );
distance_ = false;
}
}
//-----------------------------------------------------------------------------------
void DecimaterInfo::setNormalDeviationConstraint( int _value ){
void DecimaterInfo::removeNormalDeviationConstraint( ModNormalFlippingH& _handle ){
if ( decimater()->add( hModNormalFlipping ) ) {
decimater()->module( hModNormalFlipping ).set_normal_deviation( _value );
normalDeviation_ = true;
if ( normalDeviation_ ) {
decimater()->remove( _handle );
normalDeviation_ = false;
}
}
//-----------------------------------------------------------------------------------
void DecimaterInfo::setRoundnessConstraint( double _value ){
void DecimaterInfo::removeRoundnessConstraint( ModRoundnessH& _handle ){
if ( decimater()->add( hModRoundness ) ) {
decimater()->module( hModRoundness ).set_min_roundness( _value , true );
roundness_ = true;
if ( roundness_ ) {
decimater()->remove( _handle );
roundness_ = false;
}
}
......
......@@ -60,28 +60,39 @@ class DecimaterInfo : public PerObjectData
public :
typedef OpenMesh::Decimater::DecimaterT< TriMesh > DecimaterType;
private :
// Create Normal deviation ordering module
OpenMesh::Decimater::ModNormalFlippingT< DecimaterType >::Handle hModNormalFlipping;
OpenMesh::Decimater::ModQuadricT< DecimaterType >::Handle hModQuadric;
OpenMesh::Decimater::ModRoundnessT< DecimaterType >::Handle hModRoundness;
OpenMesh::Decimater::ModQuadricT< DecimaterType >::Handle hModQuadric_priority;
public :
typedef OpenMesh::Decimater::ModNormalFlippingT< DecimaterType >::Handle ModNormalFlippingH;
typedef OpenMesh::Decimater::ModQuadricT< DecimaterType >::Handle ModQuadricH;
typedef OpenMesh::Decimater::ModRoundnessT< DecimaterType >::Handle ModRoundnessH;
//Konstruktor
DecimaterInfo(TriMesh* _mesh);
DecimaterInfo();
//Destruktor
~DecimaterInfo();
void removeConstraints();
void setDistanceConstraint( double _value );
void setNormalDeviationConstraint( int _value );
void setRoundnessConstraint( double _value );
// 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 removeDistanceConstraint( ModQuadricH& _handle );
void removeNormalDeviationConstraint( ModNormalFlippingH& _handle );
void removeRoundnessConstraint( ModRoundnessH& _handle );
// Get/Set methods
bool normalDeviation() { return normalDeviation_; }
bool distance() { return distance_; }
bool roundness() { return roundness_; }
int normalDeviationValue() { return normalDeviation_value_; }
double distanceValue() { return distance_value_; }
double roundnessValue() { return roundness_value_; }
DecimaterType* decimater() { return decimater_.get(); };
......@@ -90,8 +101,13 @@ private :
std::tr1::shared_ptr< DecimaterType > decimater_;
bool normalDeviation_;
int normalDeviation_value_;
bool distance_;
double distance_value_;
bool roundness_;
double roundness_value_;
};
......@@ -61,8 +61,6 @@
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include "DecimaterInfo.hh"
#define DECIMATER "DecimaterData"
//== IMPLEMENTATION ==========================================================
......@@ -147,22 +145,25 @@ void DecimaterPlugin::slot_decimate()
if (decimater == 0){
TriMesh* mesh = PluginFunctions::triMesh(*o_it);
decimater = new DecimaterInfo( mesh );
decimater = new DecimaterInfo( );
decimater->initialize(hModPriorityQuadric_, mesh);
o_it->setObjectData(DECIMATER, decimater);
}
//remove old constraints
decimater->removeConstraints();
decimater->removeDistanceConstraint(hModDistance_);
decimater->removeNormalDeviationConstraint(hModNormalFlipping_);
decimater->removeRoundnessConstraint(hModRoundness_);
//and set new constraints
if ( tool_->cbDistance->isChecked() )
decimater->setDistanceConstraint( tool_->distance->value() );
decimater->setDistanceConstraint( hModDistance_, tool_->distance->value() );
if ( tool_->cbNormalDev->isChecked() )
decimater->setNormalDeviationConstraint( tool_->normalDeviation->value() );
decimater->setNormalDeviationConstraint( hModNormalFlipping_, tool_->normalDeviation->value() );
if ( tool_->cbRoundness->isChecked() )
decimater->setRoundnessConstraint( tool_->roundness->value() );
decimater->setRoundnessConstraint( hModRoundness_, tool_->roundness->value() );
//init the decimater
if( ! decimater->decimater()->initialize() ){
......@@ -218,12 +219,15 @@ void DecimaterPlugin::decimate(int _objID, QVariantMap _constraints) {
if (decimater == 0){
TriMesh* mesh = PluginFunctions::triMesh(baseObjectData);
decimater = new DecimaterInfo( mesh );
decimater = new DecimaterInfo( );
decimater->initialize(hModPriorityQuadric_, mesh);
object->setObjectData(DECIMATER, decimater);
}
//remove old constraints
decimater->removeConstraints();
decimater->removeDistanceConstraint(hModDistance_);
decimater->removeNormalDeviationConstraint(hModNormalFlipping_);
decimater->removeRoundnessConstraint(hModRoundness_);
//distance constraint
if ( _constraints.contains("distance") ){
......@@ -233,7 +237,7 @@ void DecimaterPlugin::decimate(int _objID, QVariantMap _constraints) {
double value = _constraints["distance"].toDouble(&ok);
if (ok)
decimater->setDistanceConstraint( value );
decimater->setDistanceConstraint( hModDistance_, value );
}
//normal deviation constraint
......@@ -244,7 +248,7 @@ void DecimaterPlugin::decimate(int _objID, QVariantMap _constraints) {
int value = _constraints["normal_deviation"].toInt(&ok);
if (ok)
decimater->setNormalDeviationConstraint( value );
decimater->setNormalDeviationConstraint( hModNormalFlipping_, value );
}
//roundness constraint
......@@ -255,7 +259,7 @@ void DecimaterPlugin::decimate(int _objID, QVariantMap _constraints) {
double value = _constraints["roundness"].toDouble(&ok);
if (ok)
decimater->setRoundnessConstraint( value );
decimater->setRoundnessConstraint( hModRoundness_, value );
}
//triangleCount constraint
......
......@@ -60,6 +60,7 @@
#include <ObjectTypes/TriangleMesh/TriangleMesh.hh>
#include "DecimaterInfo.hh"
#include "DecimaterToolbarWidget.hh"
......@@ -129,6 +130,12 @@ private :
/// Widget for Toolbox
DecimaterToolbarWidget* tool_;
/// Constraint handles for decimation
DecimaterInfo::ModNormalFlippingH hModNormalFlipping_;
DecimaterInfo::ModQuadricH hModDistance_;
DecimaterInfo::ModRoundnessH hModRoundness_;
DecimaterInfo::ModQuadricH hModPriorityQuadric_;
private slots:
......
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