52#include "DecimaterPlugin.hh"
54#include <OpenFlipper/BasePlugin/WhatsThisGenerator.hh>
56#define DECIMATER "DecimaterData"
73void DecimaterPlugin::initializePlugin()
76 if ( OpenFlipper::Options::gui()) {
90 connect(
tool_->edgeLength,SIGNAL(valueChanged(
double) ),
this,SLOT(slotUpdateEdgeLength()) );
91 connect(
tool_->normalDeviation,SIGNAL(valueChanged(
int) ),
this,SLOT(slotUpdateNormalDev()) );
92 connect(
tool_->normalDeviationSlider,SIGNAL(valueChanged(
int) ),
this,SLOT(slotUpdateNormalDev()) );
93 connect(
tool_->verticesCount,SIGNAL(valueChanged(
int) ),
this,SLOT(slotUpdateVertices()) );
94 connect(
tool_->verticesCountSlider,SIGNAL(valueChanged(
int) ),
this,SLOT(slotUpdateVertices()) );
95 connect(
tool_->trianglesCount,SIGNAL(valueChanged(
int) ),
this,SLOT(slotUpdateTriangles()) );
96 connect(
tool_->trianglesCountSlider,SIGNAL(valueChanged(
int) ),
this,SLOT(slotUpdateTriangles()) );
101 connect(
tool_->mixedFactorCounter, SIGNAL(valueChanged(
double)),
this, SLOT(slotMixedCounterValueChanged(
double)) );
102 connect(
tool_->mixedFactorSlider, SIGNAL(valueChanged(
int)),
this, SLOT(slotMixedSliderValueChanged(
int)) );
103 connect(
tool_->cbDistance, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
104 connect(
tool_->cbNormalDev, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
105 connect(
tool_->cbEdgeLength, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
106 connect(
tool_->cbIndependentSets, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
107 connect(
tool_->cbRoundness, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
108 connect(
tool_->cbAspectRatio, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
109 connect(
tool_->rbByDistance, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
110 connect(
tool_->rbByEdgeLength, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
111 connect(
tool_->rbByNormalDeviation, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
112 connect(
tool_->rbConstraintsOnly, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
113 connect(
tool_->rbTriangles, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
114 connect(
tool_->rbUseDecimater, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
115 connect(
tool_->rbUseMC, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
116 connect(
tool_->rbUseMixed, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
117 connect(
tool_->rbVertices, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
119 toolIcon_ =
new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"decimater.png");
120 emit addToolbox( tr(
"Decimater") ,
tool_, toolIcon_ );
124 tool_->pbDecimate->setWhatsThis(
tool_->pbDecimate->whatsThis()+generator.generateLink(
"quick_tutorial"));
125 tool_->pbInitialize->setWhatsThis(
tool_->pbInitialize->whatsThis()+generator.generateLink(
"quick_tutorial"));
126 tool_->rbUseDecimater->setWhatsThis(
tool_->rbUseDecimater->whatsThis()+generator.generateLink(
"incremental"));
127 tool_->rbUseMC->setWhatsThis(
tool_->rbUseMC->whatsThis()+generator.generateLink(
"multiple_choice"));
128 tool_->rbUseMixed->setWhatsThis(
tool_->rbUseMixed->whatsThis()+generator.generateLink(
"mixed"));
129 tool_->cbDistance->setWhatsThis(
tool_->cbDistance->whatsThis()+generator.generateLink());
130 tool_->cbNormalDev->setWhatsThis(
tool_->cbNormalDev->whatsThis()+generator.generateLink());
131 tool_->cbEdgeLength->setWhatsThis(
tool_->cbEdgeLength->whatsThis()+generator.generateLink());
132 tool_->cbIndependentSets->setWhatsThis(
tool_->cbIndependentSets->whatsThis()+generator.generateLink());
133 tool_->cbRoundness->setWhatsThis(
tool_->cbRoundness->whatsThis()+generator.generateLink());
134 tool_->cbAspectRatio->setWhatsThis(
tool_->cbAspectRatio->whatsThis()+generator.generateLink());
135 tool_->rbByDistance->setWhatsThis(
tool_->rbByDistance->whatsThis()+generator.generateLink());
136 tool_->rbByEdgeLength->setWhatsThis(
tool_->rbByEdgeLength->whatsThis()+generator.generateLink());
137 tool_->rbByNormalDeviation->setWhatsThis(
tool_->rbByNormalDeviation->whatsThis()+generator.generateLink());
138 tool_->rbConstraintsOnly->setWhatsThis(
tool_->rbConstraintsOnly->whatsThis()+generator.generateLink());
139 tool_->rbTriangles->setWhatsThis(
tool_->rbTriangles->whatsThis()+generator.generateLink());
140 tool_->rbVertices->setWhatsThis(
tool_->rbVertices->whatsThis()+generator.generateLink());
143 tool_->randomSamplesCounter->setWhatsThis(
tool_->randomSamplesCounter->whatsThis()+generator.generateLink(
"multiple_choice"));
144 tool_->mixedFactorCounter->setWhatsThis(
tool_->mixedFactorCounter->whatsThis()+generator.generateLink(
"mixed"));
145 tool_->roundness->setWhatsThis(
tool_->roundness->whatsThis()+generator.generateLink());
146 tool_->aspectRatio->setWhatsThis(
tool_->aspectRatio->whatsThis()+generator.generateLink());
147 tool_->distance->setWhatsThis(
tool_->distance->whatsThis()+generator.generateLink());
148 tool_->edgeLength->setWhatsThis(
tool_->edgeLength->whatsThis()+generator.generateLink());
149 tool_->normalDeviation->setWhatsThis(
tool_->normalDeviation->whatsThis()+generator.generateLink());
159 emit setSlotDescription(
"decimate(int,QVariantMap)",tr(
"Decimate a given object"),
160 QString(tr(
"objectId,constraints")).split(
","),
161 QString(tr(
"ID of an object; Object that can has one or more constraint properties ("
162 "decimater_type [0 (Incremental), 1 (MC), 2 (Mixed)], "
163 "random_samples [For MC/Mixed], "
164 "incremental_percentage [For Mixed], "
165 "decimation_order [0 (by distance), 1 (by normal deviation), 2 (by edge length)], "
170 "aspect_ratio,independent_sets, "
172 "triangles)")).split(
";"));
174 if ( OpenFlipper::Options::gui()) {
175 tool_->decTypeOps->setVisible(
false);
188 tool_->roundness->setValue( (
double) _value / 100.0 );
189 tool_->cbRoundness->setChecked (
true);
192void DecimaterPlugin::slotMixedCounterValueChanged(
double _value)
194 tool_->mixedFactorLabel->setText(QString::number(100-_value)+QString(
"%"));
195 tool_->mixedFactorSlider->setValue(100-_value);
197void DecimaterPlugin::slotMixedSliderValueChanged(
int _value)
199 tool_->mixedFactorLabel->setText(QString::number(_value)+QString(
"%"));
200 tool_->mixedFactorCounter->setValue(100.0-_value);
211 tool_->roundnessSlider->setValue( (
int) (_value * 100) );
212 tool_->cbRoundness->setChecked (
true);
224 tool_->aspectRatio->setValue( (
double) _value / 100.0 );
225 tool_->cbAspectRatio->setChecked (
true);
237 tool_->aspectRatioSlider->setValue( (
int) (_value * 100) );
238 tool_->cbAspectRatio->setChecked (
true);
249 if ( ! OpenFlipper::Options::gui())
252 decimater_objects_.clear();
255 initialize_object(o_it);
257 tool_->pbDecimate->setEnabled(
true);
265 emit log(
LOGWARN , tr(
"Unable to get object"));
277 ModAspectRatioH hModAspectRatio;
278 ModEdgeLengthH hModEdgeLength;
279 ModHausdorffH hModHausdorff;
280 ModIndependentH hModIndependent;
281 ModNormalDeviationH hModNormalDeviation;
282 ModNormalFlippingH hModNormalFlipping;
283 ModQuadricH hModQuadric;
284 ModRoundnessH hModRoundness;
287 ptr::shared_ptr<BaseDecimaterType> decimater_object;
288 if (
tool_->rbUseDecimater->isChecked())
289 decimater_object = ptr::shared_ptr<DecimaterType>(
new DecimaterType(*mesh));
290 else if(
tool_->rbUseMC->isChecked())
291 decimater_object = ptr::shared_ptr<McDecimaterType>(
new McDecimaterType(*mesh));
292 else if(
tool_->rbUseMixed->isChecked())
293 decimater_object = ptr::shared_ptr<MixedDecimaterType>(
new MixedDecimaterType(*mesh));
297 if(decimater->distance()) {
298 decimater->removeDistanceConstraint();
299 decimater_object->remove(hModHausdorff);
301 if(decimater->normalDeviation()) {
302 decimater->removeNormalDeviationConstraint();
303 decimater_object->remove(hModNormalDeviation);
305 if(decimater->normalFlipping()) {
306 decimater->removeNormalFlippingConstraint();
307 decimater_object->remove(hModNormalFlipping);
309 if(decimater->roundness()) {
310 decimater->removeRoundnessConstraint();
311 decimater_object->remove(hModRoundness);
313 if(decimater->aspectRatio()) {
314 decimater->removeAspectRatioConstraint();
315 decimater_object->remove(hModAspectRatio);
317 if(decimater->edgeLength()) {
318 decimater->removeEdgeLengthConstraint();
319 decimater_object->remove(hModEdgeLength);
321 if(decimater->independentSets()) {
322 decimater->removeIndependentSetsConstraint();
323 decimater_object->remove(hModIndependent);
327 if (
tool_->rbByDistance->isChecked()) {
328 decimater->setDecimationOrder(DecimaterInfo::DISTANCE);
329 decimater_object->add( hModQuadric );
330 decimater_object->module( hModQuadric ).unset_max_err();
331 }
else if (
tool_->rbByNormalDeviation->isChecked()) {
332 decimater->setDecimationOrder(DecimaterInfo::NORMALDEV);
333 decimater_object->add(hModNormalDeviation);
334 decimater_object->module(hModNormalDeviation).set_binary(
false);
335 }
else if (
tool_->rbByEdgeLength->isChecked()) {
336 decimater->setDecimationOrder(DecimaterInfo::EDGELENGTH);
337 decimater_object->add(hModEdgeLength);
338 decimater_object->module(hModEdgeLength).set_binary(
false);
342 ptr::shared_ptr<DecimaterInit> decInit (
new DecimaterInit);
343 if (
tool_->cbDistance->isChecked() ) {
344 if ( decimater_object->add( decInit->hModHausdorff ) ||
tool_->rbConstraintsOnly->isChecked() ) {
345 decimater->setDistanceConstraint(
tool_->distance->value() );
346 decimater_object->module( decInit->hModHausdorff ).set_tolerance( decimater->distanceValue() );
350 if (
tool_->cbNormalDev->isChecked() ) {
351 if ( decimater_object->add( decInit->hModNormalDeviation ) ||
tool_->rbConstraintsOnly->isChecked() ) {
352 decimater->setNormalDeviationConstraint(
tool_->normalDeviation->value() );
353 decimater_object->module( decInit->hModNormalDeviation ).set_normal_deviation( decimater->normalDeviationValue() );
356 if ( decimater_object->add( decInit->hModNormalFlipping ) ||
tool_->rbConstraintsOnly->isChecked() ) {
357 decimater->setNormalFlippingConstraint();
361 if (
tool_->cbRoundness->isChecked() ) {
362 if ( decimater_object->add( decInit->hModRoundness ) ||
tool_->rbConstraintsOnly->isChecked() ) {
363 decimater->setRoundnessConstraint(
tool_->roundness->value() );
364 decimater_object->module( decInit->hModRoundness ).set_min_roundness( decimater->roundnessValue(),
true );
368 if (
tool_->cbAspectRatio->isChecked() ) {
369 if ( decimater_object->add( decInit->hModAspectRatio ) ||
tool_->rbConstraintsOnly->isChecked() ) {
370 decimater->setAspectRatioConstraint(
tool_->aspectRatio->value() );
371 decimater_object->module( decInit->hModAspectRatio ).set_aspect_ratio( decimater->aspectRatioValue() );
375 if (
tool_->cbEdgeLength->isChecked() ) {
376 if ( decimater_object->add( decInit->hModEdgeLength ) ||
tool_->rbConstraintsOnly->isChecked() ) {
377 decimater->setEdgeLengthConstraint(
tool_->edgeLength->value() );
378 decimater_object->module( decInit->hModEdgeLength ).set_edge_length( decimater->edgeLengthValue() );
382 if (
tool_->cbIndependentSets->isChecked() ) {
383 if ( decimater_object->add( decInit->hModIndependent ) ||
tool_->rbConstraintsOnly->isChecked() ) {
384 decimater->setIndependentSetsConstraint();
390 if( ! decimater_object->initialize() ){
391 emit log(
LOGWARN, tr(
"Decimater could not be initialized"));
395 decInit->decimater = decimater_object;
396 decInit->objId = obj->
id();
398 decimater_objects_.push_back(decInit);
401void DecimaterPlugin::slot_initialize_object(
int obj_id,
bool clear) {
403 decimater_objects_.clear();
409 initialize_object(obj);
411 tool_->pbDecimate->setEnabled(
true);
421 if ( ! OpenFlipper::Options::gui())
425 runningJobs_ = decimater_objects_.size();
426 for (std::vector< ptr::shared_ptr<DecimaterInit> >::iterator decIter = decimater_objects_.begin();
427 decIter != decimater_objects_.end(); ++decIter)
429 ptr::shared_ptr<DecimaterInit> decInit = *decIter;
430 ptr::shared_ptr<BaseDecimaterType> decimater = decInit->decimater;
433 if (
tool_->cbDistance->isChecked() ) {
434 decimater->module( decInit->hModHausdorff ).set_tolerance(
tool_->distance->value() );
437 if (
tool_->cbNormalDev->isChecked() ) {
438 decimater->module( decInit->hModNormalDeviation ).set_normal_deviation(
tool_->normalDeviation->value() );
441 if (
tool_->cbRoundness->isChecked() ) {
442 decimater->module( decInit->hModRoundness ).set_min_roundness(
tool_->roundness->value(), true );
445 if (
tool_->cbAspectRatio->isChecked() ) {
446 decimater->module( decInit->hModAspectRatio ).set_aspect_ratio(
tool_->aspectRatio->value() );
449 if (
tool_->cbEdgeLength->isChecked() ) {
450 decimater->module( decInit->hModEdgeLength ).set_edge_length(
tool_->edgeLength->value() );
455 params.dec = (
tool_->rbUseDecimater->isChecked()) ?
dynamic_cast<DecimaterType*
>(decimater.get()) : NULL;
456 params.mcDec = (
tool_->rbUseMC->isChecked()) ?
dynamic_cast<McDecimaterType*
>(decimater.get()) : NULL;
457 params.mixedDec = (
tool_->rbUseMixed->isChecked()) ?
dynamic_cast<MixedDecimaterType*
>(decimater.get()) : NULL;
459 params.facesCount = (
tool_->rbTriangles->isChecked()) ?
tool_->trianglesCount->value() : -1;
460 params.verticesCount = (
tool_->rbVertices->isChecked() ) ?
tool_->verticesCount->value() : -1;
461 params.samples =
tool_->randomSamplesCounter->value();
462 params.mc_factor = 1.0 - (
tool_->mixedFactorCounter->value()*0.01);
463 params.selectionOnly =
tool_->selectionOnly->isChecked();
466 QString jobId = QString(
"Decimate_Object_%1").arg(decInit->objId);
468 connect(th, SIGNAL(finished(QString)),
this,SIGNAL(finishJob(QString)));
469 connect(th, SIGNAL(finished(QString)),
this, SLOT(slot_decimate_finished(QString)));
470 connect(th, SIGNAL(state(QString,
int)),
this, SIGNAL(setJobState(QString,
int)));
471 connect(
this, SIGNAL(jobCanceled(QString)), th, SLOT(slotCancel(QString)));
473 tool_->pbDecimate->setEnabled(
false);
474 tool_->pbInitialize->setEnabled(
false);
476 emit startJob(jobId , QString(
"Decimate Object with Id %1").arg(decInit->objId) , 0, 100,
false);
486void DecimaterPlugin::canceledJob (
const QString _job )
488 emit jobCanceled(_job);
491void DecimaterPlugin::slot_decimate_finished(
const QString& _jobId)
498 if (!thread->baseDecimater())
502 thread->baseDecimater()->mesh().garbage_collection();
503 thread->baseDecimater()->mesh().update_normals();
506 emit createBackup( thread->objectId(),
"Decimation");
510 if (runningJobs_ == 0)
512 tool_->pbDecimate->setEnabled(
true);
513 tool_->pbInitialize->setEnabled(
true);
522 QStringList constraintList = _constraints.split(
";");
526 for (
auto i = 0 ; i < constraintList.size() ; ++i) {
527 const auto& currentConstraint = constraintList[i];
529 int pos = currentConstraint.indexOf(
"=" );
532 emit log(
LOGERR,
"Wrong parameter format for decimater: " + currentConstraint);
536 QString constraintName = currentConstraint.left(pos);
537 QString constraintValue = currentConstraint.right(currentConstraint.size() - pos -1 );
541 double value = constraintValue.toDouble(&ok);
544 emit log(
LOGERR,
"Wrong parameter format for decimater. Conversion failed!");
545 emit log(
LOGERR,
"Got Name : " + constraintName );
546 emit log(
LOGERR,
"Got Value: " + constraintValue);
551 map[constraintName] = value;
565 emit log(
LOGERR,tr(
"Unable to get Object"));
573 emit log(
LOGWARN , tr(
"Unable to get object ( Only Triangle Meshes supported)"));
583 object->setObjectData(DECIMATER, decimater);
587 ModAspectRatioH hModAspectRatio;
588 ModEdgeLengthH hModEdgeLength;
589 ModHausdorffH hModHausdorff;
590 ModIndependentH hModIndependent;
591 ModNormalDeviationH hModNormalDeviation;
592 ModNormalFlippingH hModNormalFlipping;
593 ModQuadricH hModQuadric;
594 ModRoundnessH hModRoundness;
597 ptr::shared_ptr<BaseDecimaterType> decimater_object;
598 if (_constraints.contains(
"decimater_type"))
601 int value = _constraints[
"decimater_type"].toInt(&ok);
605 decimater_object = ptr::shared_ptr<DecimaterType>(
new DecimaterType(*mesh));
607 decimater_object = ptr::shared_ptr<McDecimaterType>(
new McDecimaterType(*mesh));
609 decimater_object = ptr::shared_ptr<MixedDecimaterType>(
new MixedDecimaterType(*mesh));
614 if (!decimater_object)
615 decimater_object = ptr::shared_ptr<DecimaterType>(
new DecimaterType(*mesh));
618 if(decimater->distance()) {
619 decimater->removeDistanceConstraint();
620 decimater_object->remove(hModHausdorff);
622 if(decimater->normalDeviation()) {
623 decimater->removeNormalDeviationConstraint();
624 decimater_object->remove(hModNormalDeviation);
626 if(decimater->normalFlipping()) {
627 decimater->removeNormalFlippingConstraint();
628 decimater_object->remove(hModNormalFlipping);
630 if(decimater->roundness()) {
631 decimater->removeRoundnessConstraint();
632 decimater_object->remove(hModRoundness);
634 if(decimater->aspectRatio()) {
635 decimater->removeAspectRatioConstraint();
636 decimater_object->remove(hModAspectRatio);
638 if(decimater->edgeLength()) {
639 decimater->removeEdgeLengthConstraint();
640 decimater_object->remove(hModEdgeLength);
642 if(decimater->independentSets()) {
643 decimater->removeIndependentSetsConstraint();
644 decimater_object->remove(hModIndependent);
648 if ( _constraints.contains(
"decimation_order") ){
651 int value = _constraints[
"decimation_order"].toInt(&ok);
656 decimater->setDecimationOrder(DecimaterInfo::DISTANCE);
657 decimater_object->add( hModQuadric );
658 decimater_object->module( hModQuadric ).unset_max_err();
661 decimater->setDecimationOrder(DecimaterInfo::NORMALDEV);
662 decimater_object->add(hModNormalDeviation);
663 decimater_object->module(hModNormalDeviation).set_binary(
false);
666 decimater->setDecimationOrder(DecimaterInfo::EDGELENGTH);
667 decimater_object->add(hModEdgeLength);
668 decimater_object->module(hModEdgeLength).set_binary(
false);
671 emit log(
LOGERR,tr(
"Invalid Decimation Order"));
676 emit log(
LOGERR,tr(
"No Decimation Order set"));
681 bool verticesCount =
false;
682 bool trianglesCount =
false;
686 if ( _constraints.contains(
"vertices") ){
690 int value = _constraints[
"vertices"].toInt(&ok);
693 verticesCount =
true;
696 }
else if ( _constraints.contains(
"triangles") ){
700 int value = _constraints[
"triangles"].toInt(&ok);
703 trianglesCount =
true;
709 if ( _constraints.contains(
"distance") ){
713 double value = _constraints[
"distance"].toDouble(&ok);
716 if ( decimater_object->add( hModHausdorff ) || (!verticesCount && !trianglesCount) ) {
717 decimater->setDistanceConstraint( value );
718 decimater_object->module( hModHausdorff ).set_tolerance( decimater->distanceValue() );
724 if ( _constraints.contains(
"normal_deviation") ){
728 int value = _constraints[
"normal_deviation"].toInt(&ok);
731 if ( decimater_object->add( hModNormalDeviation ) || (!verticesCount && !trianglesCount) ) {
732 decimater->setNormalDeviationConstraint( value );
733 decimater_object->module( hModNormalDeviation ).set_normal_deviation( decimater->normalDeviationValue() );
737 if ( decimater_object->add( hModNormalFlipping ) || (!verticesCount && !trianglesCount) ) {
738 decimater->setNormalFlippingConstraint();
744 if ( _constraints.contains(
"roundness") ){
748 double value = _constraints[
"roundness"].toDouble(&ok);
751 if ( decimater_object->add( hModRoundness ) || (!verticesCount && !trianglesCount) ) {
752 decimater->setRoundnessConstraint( value );
753 decimater_object->module( hModRoundness ).set_min_roundness( decimater->roundnessValue(),
true );
759 if ( _constraints.contains(
"aspect_ratio") ){
763 double value = _constraints[
"aspect_ratio"].toDouble(&ok);
766 if ( decimater_object->add( hModAspectRatio ) || (!verticesCount && !trianglesCount) ) {
767 decimater->setAspectRatioConstraint( value );
768 decimater_object->module( hModAspectRatio ).set_aspect_ratio( decimater->aspectRatioValue() );
774 if ( _constraints.contains(
"edge_length") ){
778 double value = _constraints[
"edge_length"].toDouble(&ok);
781 if ( decimater_object->add( hModEdgeLength ) || (!verticesCount && !trianglesCount) ) {
782 decimater->setEdgeLengthConstraint( value );
783 decimater_object->module( hModEdgeLength ).set_edge_length( decimater->edgeLengthValue() );
789 if ( _constraints.contains(
"independent_sets") ){
791 bool value = _constraints[
"independent_sets"].toBool();
794 if ( decimater_object->add( hModIndependent ) || (!verticesCount && !trianglesCount) ) {
795 decimater->setIndependentSetsConstraint();
801 bool selection_only =
false;
802 if ( _constraints.contains(
"selection_only") ){
804 selection_only = _constraints[
"selection_only"].toBool();
809 if( ! decimater_object->initialize() ){
810 emit log(
LOGWARN, tr(
"Decimater could not be initialized"));
814 float mc_factor = 0.5;
815 size_t randomSamples = 8;
817 if (_constraints.contains(
"random_samples"))
820 unsigned value =_constraints[
"random_samples"].toUInt(&ok);
822 randomSamples = value;
825 if (_constraints.contains(
"incremental_percentage"))
828 unsigned value =_constraints[
"incremental_percentage"].toUInt(&ok);
830 mc_factor = 1.f - (value*0.01f);
834 DecimaterType* dec =
dynamic_cast<DecimaterType*
>(decimater_object.get());
835 McDecimaterType* mcDec =
dynamic_cast<McDecimaterType*
>(decimater_object.get());
836 MixedDecimaterType* mixedDec =
dynamic_cast<MixedDecimaterType*
>(decimater_object.get());
841 dec->decimate_to(vertices,selection_only);
842 else if (trianglesCount )
843 dec->decimate_to_faces(0, triangles,selection_only);
845 dec->decimate_to_faces(0, 1,selection_only);
847 else if (mcDec && !mixedDec)
849 mcDec->set_samples(randomSamples);
851 mcDec->decimate_to(vertices,selection_only);
852 else if (trianglesCount)
853 mcDec->decimate_to_faces(0, triangles,selection_only);
855 mcDec->decimate_to_faces(0, 1,selection_only);
859 mixedDec->set_samples(randomSamples);
861 mixedDec->decimate_to(vertices,mc_factor,selection_only);
862 else if (trianglesCount)
863 mixedDec->decimate_to_faces(0, triangles,mc_factor,selection_only);
865 mixedDec->decimate_to_faces(0, 1,mc_factor,selection_only);
868 emit log(
LOGERR,tr(
"Could not find Decimater Type"));
871 object->mesh()->garbage_collection();
872 object->mesh()->update_normals();
877 emit createBackup(_objID,
"Decimation");
880 QString param =
"(" + (_constraints.contains(
"decimation_order") ? tr(
"decimation_order = %1").arg(_constraints[
"decimation_order"].toString()) :
"") +
881 ", " + (_constraints.contains(
"distance") ? tr(
"distance = %1").arg(_constraints[
"distance"].toString()) :
"") +
882 ", " + (_constraints.contains(
"normal_deviation") ? tr(
"normal_deviation = %1").arg(_constraints[
"normal_deviation"].toString()) :
"") +
883 ", " + (_constraints.contains(
"edge_length") ? tr(
"edge_length = %1").arg(_constraints[
"edge_length"].toString()) :
"") +
884 ", " + (_constraints.contains(
"roundness") ? tr(
"roundness = %1").arg(_constraints[
"roundness"].toString()) :
"") +
885 ", " + (_constraints.contains(
"aspect_ratio") ? tr(
"aspect_ratio = %1").arg(_constraints[
"aspect_ratio"].toString()) :
"") +
886 ", " + (_constraints.contains(
"independent_sets") ? tr(
"independent_sets = %1").arg(_constraints[
"independent_sets"].toString()) :
"") +
887 ", " + (_constraints.contains(
"triangles") ? tr(
"triangles = %1").arg(_constraints[
"triangles"].toString()) :
"") +
888 ", " + (_constraints.contains(
"vertices") ? tr(
"vertices = %1").arg(_constraints[
"vertices"].toString()) :
"") +
")";
890 emit scriptInfo(
"decimate(" + QString::number(_objID) +
", " + param +
")" );
894 emit log(
LOGERR,tr(
"Unsupported object type for decimater"));
906 if ( !OpenFlipper::Options::gui() || !
tool_->isVisible() ) {
914 emit functionExists(
"infomeshobject" ,
"vertexCount(int)", ok ) ;
917 tool_->currentNumVertices->setText (
"<not available>");
922 max = std::max( RPC::callFunctionValue<int> (
"infomeshobject" ,
"vertexCount",o_it->id()) , max );
927 tool_->currentNumVertices->setText (
"<not available>");
929 tool_->verticesCount->blockSignals(
true);
930 tool_->verticesCountSlider->blockSignals(
true);
932 tool_->currentNumVertices->setText (QString::number(max));
933 tool_->verticesCount->setMaximum(max);
934 tool_->verticesCountSlider->setMaximum(max);
936 if (
tool_->verticesCount->value() < 2 )
938 tool_->verticesCount->setValue( max / 2 );
939 tool_->verticesCountSlider->setValue( max / 2);
942 tool_->verticesCount->blockSignals(
false);
943 tool_->verticesCountSlider->blockSignals(
false);
954 if (!OpenFlipper::Options::gui() || !
tool_->isVisible())
962 max = std::max(mesh->n_faces(), max);
966 tool_->trianglesCount->blockSignals(
true);
967 tool_->trianglesCountSlider->blockSignals(
true);
969 tool_->trianglesCount->setMinimum(1);
970 tool_->trianglesCount->setMaximum(max);
971 tool_->trianglesCountSlider->setMinimum(1);
972 tool_->trianglesCountSlider->setMaximum(max);
974 if (
tool_->trianglesCount->value() < 2)
976 tool_->trianglesCount->setValue (max / 2 );
977 tool_->trianglesCountSlider->setValue( max / 2);
980 tool_->trianglesCount->blockSignals(
false);
981 tool_->trianglesCountSlider->blockSignals(
false);
986void DecimaterPlugin::slotObjectSelectionChanged(
int )
993void DecimaterPlugin::objectDeleted(
int _id)
995 slotDisableDecimation();
1000void DecimaterPlugin::slotAboutToRestore(
int _id)
1002 slotDisableDecimation();
1007void DecimaterPlugin::slotDisableDecimation()
1009 if ( ! OpenFlipper::Options::gui())
1012 decimater_objects_.clear();
1013 tool_->pbDecimate->setEnabled(
false);
1018void DecimaterPlugin::slotObjectUpdated(
int ,
const UpdateType& _type )
1029void DecimaterPlugin::slotUpdateVertices()
1031 tool_->rbVertices->setChecked (
true);
1037void DecimaterPlugin::slotUpdateTriangles()
1039 tool_->rbTriangles->setChecked (
true);
1045void DecimaterPlugin::slotUpdateNormalDev()
1047 tool_->cbNormalDev->setChecked (
true);
1053void DecimaterPlugin::slotUpdateEdgeLength()
1055 tool_->cbEdgeLength->setChecked (
true);
1063 tool_->cbDistance->setChecked (
true);
#define DATA_TRIANGLE_MESH
void setObjectData(QString _dataName, PerObjectData *_data)
PerObjectData * objectData(QString _dataName)
Returns the object data pointer.
bool dataType(DataType _type) const
void slotUpdateRoundness(int _value)
roundness slider - spinbox sync
void decimate(int _objID, QVariantMap _constraints)
decimate an object
void slotUpdateDistance()
slider / spinbox updates
void slot_decimate()
decimating called from button in toolbox
void slotUpdateNumTriangles()
gets and sets the current maximum number of triangles
~DecimaterPlugin()
Default destructor.
void slotUpdateNumVertices()
update number of vertices information
void slot_initialize()
init called from button in toolbox
DecimaterToolbarWidget * tool_
Widget for Toolbox.
void slotUpdateAspectRatio(int _value)
sync between values of aspect ratio slider and spinbox in the toolbox
void pluginsInitialized() override
Initialization of the plugin when it is loaded by the core.
DecimaterPlugin()
Default constructor.
void startProcessing()
start processing
Type for a MeshObject containing a triangle mesh.
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
a class which provides an link generator for WhatsThisMessages linking to the user doc If you have an...
const UpdateType UPDATE_TOPOLOGY(UpdateTypeSet(8))
Topology updated.
TriMeshObject * triMeshObject(BaseObjectData *_object)
Cast an BaseObject to a TriMeshObject if possible.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
const QStringList TARGET_OBJECTS("target")
Iterable object range.
ObjectRange objects(IteratorRestriction _restriction, DataType _dataType)
Iterable object range.