Commit 05a310f8 authored by Dirk Wilden's avatar Dirk Wilden

now also working from scripting

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5183 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 0895bd63
......@@ -12,12 +12,12 @@
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
......@@ -31,78 +31,82 @@
#include "DecimaterInfo.hh"
DecimaterInfo::DecimaterInfo(DecimaterToolbarWidget* _tool , TriMesh* _mesh) :
tool_(_tool),
DecimaterInfo::DecimaterInfo(TriMesh* _mesh) :
decimater_(0),
normalDeviation_(false),
distance_(false),
roundness_(false)
{
decimater_ = new DecimaterType( *_mesh );
decimater_->add( hModQuadric_priority );
decimater_->module( hModQuadric_priority ).unset_max_err();
update();
}
DecimaterInfo::~DecimaterInfo() {
if ( decimater_ )
delete decimater_;
delete decimater_;
}
//-----------------------------------------------------------------------------------
void DecimaterInfo::update() {
void DecimaterInfo::removeConstraints(){
decimater_->module( hModQuadric_priority ).unset_max_err();
//remove old module
if ( normalDeviation_ && !tool_->cbNormalDev->isChecked() ) {
decimater_->remove( hModNormalFlipping );
//remove modules
if ( normalDeviation_ ) {
decimater_->remove( hModNormalFlipping );
normalDeviation_ = false;
}
if ( distance_ && !tool_->cbDistance->isChecked() ) {
if ( distance_ ) {
decimater_->remove( hModQuadric );
distance_ = false;
}
if ( roundness_ && !tool_->cbRoundness->isChecked() ) {
if ( roundness_ ) {
decimater_->remove( hModRoundness );
roundness_ = false;
}
//add new module
if ( tool_->cbNormalDev->isChecked() ) {
if ( ! normalDeviation_)
if ( decimater_->add( hModNormalFlipping ) ) {
decimater_->module( hModNormalFlipping ).set_normal_deviation( tool_->sbNormalDev->value() );
normalDeviation_ = true;
}
}
//-----------------------------------------------------------------------------------
void DecimaterInfo::setDistanceConstraint( double _value ){
if ( decimater_->add( hModQuadric ) ) {
decimater_->module( hModQuadric ).set_max_err( _value );
distance_ = true;
}
if ( tool_->cbDistance->isChecked() ) {
if ( ! distance_)
if ( decimater_->add( hModQuadric ) ) {
decimater_->module( hModQuadric ).set_max_err( tool_->sbDistance->value() );
distance_ = true;
}
}
//-----------------------------------------------------------------------------------
void DecimaterInfo::setNormalDeviationConstraint( int _value ){
if ( decimater_->add( hModNormalFlipping ) ) {
decimater_->module( hModNormalFlipping ).set_normal_deviation( _value );
normalDeviation_ = true;
}
if ( tool_->cbRoundness->isChecked() ) {
if ( ! roundness_)
if ( ! decimater_->add( hModRoundness ) ) {
decimater_->module( hModRoundness ).set_min_roundness( tool_->roundness->value() , true );
roundness_ = true;
}
}
//-----------------------------------------------------------------------------------
void DecimaterInfo::setRoundnessConstraint( double _value ){
if ( decimater_->add( hModRoundness ) ) {
decimater_->module( hModRoundness ).set_min_roundness( _value , true );
roundness_ = true;
}
decimater_->initialize();
}
......@@ -12,12 +12,12 @@
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
......@@ -31,7 +31,6 @@
#include <OpenFlipper/common/perObjectData.hh>
#include <OpenFlipper/common/Types.hh>
#include "DecimaterToolbarWidget.hh"
#include <OpenMesh/Tools/Decimater/DecimaterT.hh>
#include <OpenMesh/Tools/Decimater/ModNormalFlippingT.hh>
......@@ -58,26 +57,26 @@ class DecimaterInfo : public PerObjectData
public :
//Konstruktor
DecimaterInfo(DecimaterToolbarWidget* _tool , TriMesh* _mesh);
DecimaterInfo(TriMesh* _mesh);
//Destruktor
~DecimaterInfo();
//remove/add priority and binary modules and initialize decimater
void update();
void removeConstraints();
void setDistanceConstraint( double _value );
void setNormalDeviationConstraint( int _value );
void setRoundnessConstraint( double _value );
DecimaterType* decimater() { return decimater_; };
private :
DecimaterToolbarWidget* tool_;
OpenMesh::Decimater::DecimaterT< TriMesh >* decimater_;
bool normalDeviation_;
bool distance_;
bool roundness_;
};
......@@ -12,12 +12,12 @@
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
......@@ -56,9 +56,12 @@
//== IMPLEMENTATION ==========================================================
bool
DecimaterPlugin::
initializeToolbox(QWidget*& _widget)
/** \brief Initialize the Toolbox
*
* @param _widget reference to the generated toolbox
* @return return if the toolbox was generated successfully
*/
bool DecimaterPlugin::initializeToolbox(QWidget*& _widget)
{
tool_ = new DecimaterToolbarWidget();
_widget = tool_;
......@@ -68,14 +71,42 @@ initializeToolbox(QWidget*& _widget)
// connect signals->slots
connect(tool_->pbDecimate,SIGNAL(clicked() ),this,SLOT(slot_decimate()));
return true;
connect(tool_->roundness,SIGNAL(valueChanged(double) ),this,SLOT(updateRoundness(double)) );
connect(tool_->roundnessSlider,SIGNAL(valueChanged(int) ),this,SLOT(updateRoundness(int)) );
return true;
}
//-----------------------------------------------------------------------------
/** \brief sync between values of roundness slider and spinbox in the toolbox
*
* @param _value new roundness value
*/
void DecimaterPlugin::updateRoundness(int _value)
{
tool_->roundness->setValue( (double) _value / 100.0 );
}
//-----------------------------------------------------------------------------
/** \brief sync between values of roundness slider and spinbox in the toolbox
*
* @param _value new roundness value
*/
void DecimaterPlugin::updateRoundness(double _value)
{
tool_->roundnessSlider->setValue( (int) (_value * 100) );
}
//-----------------------------------------------------------------------------
void
DecimaterPlugin::
slot_decimate()
/** \brief Decimation called by toolbox
*
*/
void DecimaterPlugin::slot_decimate()
{
for ( PluginFunctions::ObjectIterator o_it(PluginFunctions::TARGET_OBJECTS,DATA_TRIANGLE_MESH) ;
......@@ -91,14 +122,25 @@ slot_decimate()
if (decimater == 0){
TriMesh* mesh = PluginFunctions::triMesh(*o_it);
decimater = new DecimaterInfo( tool_, mesh );
decimater = new DecimaterInfo( mesh );
o_it->setObjectData(DECIMATER, decimater);
}
//remove old constraints
decimater->removeConstraints();
decimater->update();
//and set new constraints
if ( tool_->cbDistance->isChecked() )
decimater->setDistanceConstraint( tool_->distance->value() );
if( ! decimater->decimater()->is_initialized() ){
if ( tool_->cbNormalDev->isChecked() )
decimater->setNormalDeviationConstraint( tool_->normalDeviation->value() );
if ( tool_->cbRoundness->isChecked() )
decimater->setRoundnessConstraint( tool_->roundness->value() );
//init the decimater
if( ! decimater->decimater()->initialize() ){
emit log(LOGWARN, "Decimater could not be initialized");
continue;
}
......@@ -121,6 +163,12 @@ slot_decimate()
//-----------------------------------------------------------------------------
/** \brief Decimation called by Scripting
*
* @param _objID id of an object
* @param _constraints A string containing a comma separated list of constraints (distance,normal_deviation,roundness,triangles)
* @param _values a string containing a comma separated list of constraint values suited to the _constraints parameter
*/
void DecimaterPlugin::decimate(int _objID, QString _constraints, QString _values){
......@@ -142,28 +190,98 @@ void DecimaterPlugin::decimate(int _objID, QString _constraints, QString _values
if (decimater == 0){
TriMesh* mesh = PluginFunctions::triMesh(baseObjectData);
decimater = new DecimaterInfo( tool_, mesh );
decimater = new DecimaterInfo( mesh );
object->setObjectData(DECIMATER, decimater);
}
decimater->update();
//remove old constraints
decimater->removeConstraints();
//and set new constraints
QStringList constraints = _constraints.toLower().split(",");
QStringList values = _values.split(",");
//distance constraint
if ( constraints.contains("distance") ){
int i = constraints.indexOf("distance");
if ( i >= 0 && i < values.count() ){
bool ok;
double value = values[i].toDouble(&ok);
if (ok)
decimater->setDistanceConstraint( value );
}
}
if( ! decimater->decimater()->is_initialized() ){
//normal deviation constraint
if ( constraints.contains("normal_deviation") ){
int i = constraints.indexOf("normal_deviation");
if ( i >= 0 && i < values.count() ){
bool ok;
int value = values[i].toInt(&ok);
if (ok)
decimater->setNormalDeviationConstraint( value );
}
}
//roundness constraint
if ( constraints.contains("roundness") ){
int i = constraints.indexOf("roundness");
if ( i >= 0 && i < values.count() ){
bool ok;
double value = values[i].toDouble(&ok);
if (ok)
decimater->setRoundnessConstraint( value );
}
}
//triangleCount constraint
bool triangleCount = false;
int triangles = 0;
if ( constraints.contains("triangles") ){
int i = constraints.indexOf("triangles");
if ( i >= 0 && i < values.count() ){
bool ok;
int value = values[i].toInt(&ok);
if (ok){
triangleCount = true;
triangles = value;
}
}
}
//init the decimater
if( ! decimater->decimater()->initialize() ){
emit log(LOGWARN, "Decimater could not be initialized");
return;
}
//decimate
if ( tool_->cbTriangles->isChecked() )
decimater->decimater()->decimate_to( tool_->triangleCount->value() ); // do decimation
if ( triangleCount )
decimater->decimater()->decimate_to( triangles ); // do decimation
else
decimater->decimater()->decimate(); // do decimation
decimater->decimater()->decimate(); // do decimation
object->mesh()->garbage_collection();
object->mesh()->update_normals();
object->update();
} else {
emit log(LOGERR,"Unsupported object type for decimater");
return;
......
......@@ -12,12 +12,12 @@
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
......@@ -102,6 +102,10 @@ private slots:
/// decimating called from button in toolbox
void slot_decimate();
/// roundness slider - spinbox sync
void updateRoundness(int _value);
void updateRoundness(double _value);
//===========================================================================
/** @name Scripting Functions
* @{ */
......
......@@ -6,7 +6,7 @@
<x>0</x>
<y>0</y>
<width>311</width>
<height>404</height>
<height>383</height>
</rect>
</property>
<property name="windowTitle" >
......@@ -28,13 +28,19 @@
</item>
<item row="1" column="0" >
<widget class="QCheckBox" name="cbNormalDev" >
<property name="toolTip" >
<string>Restrict Normal Deviation</string>
</property>
<property name="statusTip" >
<string>Restrict Normal Deviation</string>
</property>
<property name="text" >
<string>Normal Dev.</string>
</property>
</widget>
</item>
<item row="1" column="2" >
<widget class="QSpinBox" name="sbNormalDev" >
<widget class="QSpinBox" name="normalDeviation" >
<property name="enabled" >
<bool>true</bool>
</property>
......@@ -46,6 +52,9 @@ p, li { white-space: pre-wrap; }
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">original normal and normals after &lt;/p>
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">decimation step defined in degrees.&lt;/p>&lt;/body>&lt;/html></string>
</property>
<property name="statusTip" >
<string>Restrict Normal deviation</string>
</property>
<property name="maximum" >
<number>180</number>
</property>
......@@ -71,7 +80,13 @@ p, li { white-space: pre-wrap; }
</widget>
</item>
<item row="2" column="1" >
<widget class="QSlider" name="horizontalSlider_2" >
<widget class="QSlider" name="roundnessSlider" >
<property name="maximum" >
<number>100</number>
</property>
<property name="value" >
<number>50</number>
</property>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
......@@ -88,7 +103,13 @@ p, li { white-space: pre-wrap; }
</widget>
</item>
<item row="3" column="1" >
<widget class="QSlider" name="horizontalSlider_3" >
<widget class="QSlider" name="triangleCountSlider" >
<property name="maximum" >
<number>100000</number>
</property>
<property name="value" >
<number>5000</number>
</property>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
......@@ -100,7 +121,7 @@ p, li { white-space: pre-wrap; }
<bool>true</bool>
</property>
<property name="maximum" >
<number>100000</number>
<number>99999</number>
</property>
<property name="value" >
<number>5000</number>
......@@ -127,7 +148,7 @@ p, li { white-space: pre-wrap; }
</widget>
</item>
<item row="0" column="2" >
<widget class="QDoubleSpinBox" name="sbDistance" >
<widget class="QDoubleSpinBox" name="distance" >
<property name="decimals" >
<number>3</number>
</property>
......@@ -143,24 +164,30 @@ p, li { white-space: pre-wrap; }
</widget>
</item>
<item row="1" column="1" >
<widget class="QSlider" name="horizontalSlider" >
<widget class="QSlider" name="normalDeviationSlider" >
<property name="toolTip" >
<string>&lt;html>&lt;head>&lt;meta name="qrichtext" content="1" />&lt;style type="text/css">
p, li { white-space: pre-wrap; }
&lt;/style>&lt;/head>&lt;body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Maximal normal deviation between &lt;/p>
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">original normal and normals after &lt;/p>
&lt;p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">decimation step defined in degrees.&lt;/p>&lt;/body>&lt;/html></string>
</property>
<property name="statusTip" >
<string>Restrict Normal Deviation</string>
</property>
<property name="maximum" >
<number>180</number>
</property>
<property name="value" >
<number>10</number>
</property>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
<zorder>cbDistance</zorder>
<zorder>cbNormalDev</zorder>
<zorder>sbNormalDev</zorder>
<zorder>cbRoundness</zorder>
<zorder>horizontalSlider_2</zorder>
<zorder>cbTriangles</zorder>
<zorder>horizontalSlider_3</zorder>
<zorder>triangleCount</zorder>
<zorder>roundness</zorder>
<zorder>sbDistance</zorder>
<zorder>horizontalSlider</zorder>
</widget>
</item>
<item>
......@@ -191,5 +218,70 @@ p, li { white-space: pre-wrap; }
<layoutdefault spacing="6" margin="11" />
<pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
<resources/>
<connections/>
<connections>
<connection>
<sender>normalDeviationSlider</sender>
<signal>valueChanged(int)</signal>
<receiver>normalDeviation</receiver>
<slot>setValue(int)</slot>
<hints>
<hint type="sourcelabel" >
<x>179</x>
<y>71</y>
</hint>
<hint type="destinationlabel" >
<x>258</x>
<y>76</y>
</hint>
</hints>
</connection>
<connection>
<sender>normalDeviation</sender>
<signal>valueChanged(int)</signal>
<receiver>normalDeviationSlider</receiver>
<slot>setValue(int)</slot>
<hints>
<hint type="sourcelabel" >
<x>232</x>
<y>81</y>
</hint>
<hint type="destinationlabel" >
<x>189</x>
<y>82</y>
</hint>
</hints>
</connection>
<connection>
<sender>triangleCountSlider</sender>
<signal>valueChanged(int)</signal>
<receiver>triangleCount</receiver>
<slot>setValue(int)</slot>
<hints>
<hint type="sourcelabel" >
<x>190</x>
<y>137</y>
</hint>
<hint type="destinationlabel" >
<x>261</x>
<y>141</y>
</hint>
</hints>
</connection>
<connection>
<sender>triangleCount</sender>
<signal>valueChanged(int)</signal>
<receiver>triangleCountSlider</receiver>
<slot>setValue(int)</slot>
<hints>
<hint type="sourcelabel" >
<x>232</x>
<y>133</y>
</hint>
<hint type="destinationlabel" >
<x>192</x>
<y>133</y>
</hint>
</hints>
</connection>
</connections>
</ui>
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