52 #include "DecimaterPlugin.hh" 54 #include <OpenFlipper/BasePlugin/WhatsThisGenerator.hh> 56 #define DECIMATER "DecimaterData" 69 void DecimaterPlugin::initializePlugin()
72 if ( OpenFlipper::Options::gui()) {
86 connect(
tool_->edgeLength,SIGNAL(valueChanged(
double) ),
this,SLOT(slotUpdateEdgeLength()) );
87 connect(
tool_->normalDeviation,SIGNAL(valueChanged(
int) ),
this,SLOT(slotUpdateNormalDev()) );
88 connect(
tool_->normalDeviationSlider,SIGNAL(valueChanged(
int) ),
this,SLOT(slotUpdateNormalDev()) );
89 connect(
tool_->verticesCount,SIGNAL(valueChanged(
int) ),
this,SLOT(slotUpdateVertices()) );
90 connect(
tool_->verticesCountSlider,SIGNAL(valueChanged(
int) ),
this,SLOT(slotUpdateVertices()) );
91 connect(
tool_->trianglesCount,SIGNAL(valueChanged(
int) ),
this,SLOT(slotUpdateTriangles()) );
92 connect(
tool_->trianglesCountSlider,SIGNAL(valueChanged(
int) ),
this,SLOT(slotUpdateTriangles()) );
97 connect(
tool_->mixedFactorCounter, SIGNAL(valueChanged(
double)),
this, SLOT(slotMixedCounterValueChanged(
double)) );
98 connect(
tool_->mixedFactorSlider, SIGNAL(valueChanged(
int)),
this, SLOT(slotMixedSliderValueChanged(
int)) );
99 connect(
tool_->cbDistance, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
100 connect(
tool_->cbNormalDev, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
101 connect(
tool_->cbEdgeLength, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
102 connect(
tool_->cbIndependentSets, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
103 connect(
tool_->cbRoundness, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
104 connect(
tool_->cbAspectRatio, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
105 connect(
tool_->rbByDistance, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
106 connect(
tool_->rbByEdgeLength, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
107 connect(
tool_->rbByNormalDeviation, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
108 connect(
tool_->rbConstraintsOnly, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
109 connect(
tool_->rbTriangles, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
110 connect(
tool_->rbUseDecimater, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
111 connect(
tool_->rbUseMC, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
112 connect(
tool_->rbUseMixed, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
113 connect(
tool_->rbVertices, SIGNAL(toggled(
bool)),
this, SLOT(slotDisableDecimation()));
115 toolIcon_ =
new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"decimater.png");
116 emit addToolbox( tr(
"Decimater") ,
tool_, toolIcon_ );
121 tool_->pbInitialize->setWhatsThis(
tool_->pbInitialize->whatsThis()+generator.
generateLink(
"quick_tutorial"));
122 tool_->rbUseDecimater->setWhatsThis(
tool_->rbUseDecimater->whatsThis()+generator.
generateLink(
"incremental"));
133 tool_->rbByNormalDeviation->setWhatsThis(
tool_->rbByNormalDeviation->whatsThis()+generator.
generateLink());
139 tool_->randomSamplesCounter->setWhatsThis(
tool_->randomSamplesCounter->whatsThis()+generator.
generateLink(
"multiple_choice"));
140 tool_->mixedFactorCounter->setWhatsThis(
tool_->mixedFactorCounter->whatsThis()+generator.
generateLink(
"mixed"));
155 emit setSlotDescription(
"decimate(int,QVariantMap)",tr(
"Decimate a given object"),
156 QString(tr(
"objectId,constraints")).split(
","),
157 QString(tr(
"ID of an object; Object that can has one or more constraint properties (" 158 "decimater_type [0 (Incremental), 1 (MC), 2 (Mixed)], " 159 "random_samples [For MC/Mixed], " 160 "incremental_percentage [For Mixed], " 161 "decimation_order [0 (by distance), 1 (by normal deviation), 2 (by edge length)], " 166 "aspect_ratio,independent_sets, " 168 "triangles)")).split(
";"));
170 if ( OpenFlipper::Options::gui()) {
171 tool_->decTypeOps->setVisible(
false);
184 tool_->roundness->setValue( (
double) _value / 100.0 );
185 tool_->cbRoundness->setChecked (
true);
188 void DecimaterPlugin::slotMixedCounterValueChanged(
double _value)
190 tool_->mixedFactorLabel->setText(QString::number(100-_value)+QString(
"%"));
191 tool_->mixedFactorSlider->setValue(100-_value);
193 void DecimaterPlugin::slotMixedSliderValueChanged(
int _value)
195 tool_->mixedFactorLabel->setText(QString::number(_value)+QString(
"%"));
196 tool_->mixedFactorCounter->setValue(100.0-_value);
207 tool_->roundnessSlider->setValue( (
int) (_value * 100) );
208 tool_->cbRoundness->setChecked (
true);
220 tool_->aspectRatio->setValue( (
double) _value / 100.0 );
221 tool_->cbAspectRatio->setChecked (
true);
233 tool_->aspectRatioSlider->setValue( (
int) (_value * 100) );
234 tool_->cbAspectRatio->setChecked (
true);
245 if ( ! OpenFlipper::Options::gui())
248 decimater_objects_.clear();
251 initialize_object(o_it);
253 tool_->pbDecimate->setEnabled(
true);
261 emit log(
LOGWARN , tr(
"Unable to get object"));
273 ModAspectRatioH hModAspectRatio;
274 ModEdgeLengthH hModEdgeLength;
275 ModHausdorffH hModHausdorff;
276 ModIndependentH hModIndependent;
277 ModNormalDeviationH hModNormalDeviation;
278 ModNormalFlippingH hModNormalFlipping;
279 ModQuadricH hModQuadric;
280 ModRoundnessH hModRoundness;
283 ptr::shared_ptr<BaseDecimaterType> decimater_object;
284 if (
tool_->rbUseDecimater->isChecked())
285 decimater_object = ptr::shared_ptr<DecimaterType>(
new DecimaterType(*mesh));
286 else if(
tool_->rbUseMC->isChecked())
287 decimater_object = ptr::shared_ptr<McDecimaterType>(
new McDecimaterType(*mesh));
288 else if(
tool_->rbUseMixed->isChecked())
289 decimater_object = ptr::shared_ptr<MixedDecimaterType>(
new MixedDecimaterType(*mesh));
293 if(decimater->distance()) {
294 decimater->removeDistanceConstraint();
295 decimater_object->remove(hModHausdorff);
297 if(decimater->normalDeviation()) {
298 decimater->removeNormalDeviationConstraint();
299 decimater_object->remove(hModNormalDeviation);
301 if(decimater->normalFlipping()) {
302 decimater->removeNormalFlippingConstraint();
303 decimater_object->remove(hModNormalFlipping);
305 if(decimater->roundness()) {
306 decimater->removeRoundnessConstraint();
307 decimater_object->remove(hModRoundness);
309 if(decimater->aspectRatio()) {
310 decimater->removeAspectRatioConstraint();
311 decimater_object->remove(hModAspectRatio);
313 if(decimater->edgeLength()) {
314 decimater->removeEdgeLengthConstraint();
315 decimater_object->remove(hModEdgeLength);
317 if(decimater->independentSets()) {
318 decimater->removeIndependentSetsConstraint();
319 decimater_object->remove(hModIndependent);
323 if (
tool_->rbByDistance->isChecked()) {
324 decimater->setDecimationOrder(DecimaterInfo::DISTANCE);
325 decimater_object->add( hModQuadric );
326 decimater_object->module( hModQuadric ).unset_max_err();
327 }
else if (
tool_->rbByNormalDeviation->isChecked()) {
328 decimater->setDecimationOrder(DecimaterInfo::NORMALDEV);
329 decimater_object->add(hModNormalDeviation);
330 decimater_object->module(hModNormalDeviation).set_binary(
false);
331 }
else if (
tool_->rbByEdgeLength->isChecked()) {
332 decimater->setDecimationOrder(DecimaterInfo::EDGELENGTH);
333 decimater_object->add(hModEdgeLength);
334 decimater_object->module(hModEdgeLength).set_binary(
false);
339 if (
tool_->cbDistance->isChecked() ) {
340 if ( decimater_object->add( decInit->hModHausdorff ) ||
tool_->rbConstraintsOnly->isChecked() ) {
341 decimater->setDistanceConstraint(
tool_->distance->value() );
342 decimater_object->module( decInit->hModHausdorff ).set_tolerance( decimater->distanceValue() );
346 if (
tool_->cbNormalDev->isChecked() ) {
347 if ( decimater_object->add( decInit->hModNormalDeviation ) ||
tool_->rbConstraintsOnly->isChecked() ) {
348 decimater->setNormalDeviationConstraint(
tool_->normalDeviation->value() );
349 decimater_object->module( decInit->hModNormalDeviation ).set_normal_deviation( decimater->normalDeviationValue() );
352 if ( decimater_object->add( decInit->hModNormalFlipping ) ||
tool_->rbConstraintsOnly->isChecked() ) {
353 decimater->setNormalFlippingConstraint();
357 if (
tool_->cbRoundness->isChecked() ) {
358 if ( decimater_object->add( decInit->hModRoundness ) ||
tool_->rbConstraintsOnly->isChecked() ) {
359 decimater->setRoundnessConstraint(
tool_->roundness->value() );
360 decimater_object->module( decInit->hModRoundness ).set_min_roundness( decimater->roundnessValue(), true );
364 if (
tool_->cbAspectRatio->isChecked() ) {
365 if ( decimater_object->add( decInit->hModAspectRatio ) ||
tool_->rbConstraintsOnly->isChecked() ) {
366 decimater->setAspectRatioConstraint(
tool_->aspectRatio->value() );
367 decimater_object->module( decInit->hModAspectRatio ).set_aspect_ratio( decimater->aspectRatioValue() );
371 if (
tool_->cbEdgeLength->isChecked() ) {
372 if ( decimater_object->add( decInit->hModEdgeLength ) ||
tool_->rbConstraintsOnly->isChecked() ) {
373 decimater->setEdgeLengthConstraint(
tool_->edgeLength->value() );
374 decimater_object->module( decInit->hModEdgeLength ).set_edge_length( decimater->edgeLengthValue() );
378 if (
tool_->cbIndependentSets->isChecked() ) {
379 if ( decimater_object->add( decInit->hModIndependent ) ||
tool_->rbConstraintsOnly->isChecked() ) {
380 decimater->setIndependentSetsConstraint();
386 if( ! decimater_object->initialize() ){
387 emit log(
LOGWARN, tr(
"Decimater could not be initialized"));
391 decInit->decimater = decimater_object;
392 decInit->objId = obj->
id();
394 decimater_objects_.push_back(decInit);
397 void DecimaterPlugin::slot_initialize_object(
int obj_id,
bool clear) {
399 decimater_objects_.clear();
405 initialize_object(obj);
407 tool_->pbDecimate->setEnabled(
true);
417 if ( ! OpenFlipper::Options::gui())
421 runningJobs_ = decimater_objects_.size();
422 for (std::vector< ptr::shared_ptr<DecimaterInit> >::iterator decIter = decimater_objects_.begin();
423 decIter != decimater_objects_.end(); ++decIter)
425 ptr::shared_ptr<DecimaterInit> decInit = *decIter;
426 ptr::shared_ptr<BaseDecimaterType> decimater = decInit->decimater;
429 if (
tool_->cbDistance->isChecked() ) {
430 decimater->module( decInit->hModHausdorff ).set_tolerance(
tool_->distance->value() );
433 if (
tool_->cbNormalDev->isChecked() ) {
434 decimater->module( decInit->hModNormalDeviation ).set_normal_deviation(
tool_->normalDeviation->value() );
437 if (
tool_->cbRoundness->isChecked() ) {
438 decimater->module( decInit->hModRoundness ).set_min_roundness(
tool_->roundness->value(), true );
441 if (
tool_->cbAspectRatio->isChecked() ) {
442 decimater->module( decInit->hModAspectRatio ).set_aspect_ratio(
tool_->aspectRatio->value() );
445 if (
tool_->cbEdgeLength->isChecked() ) {
446 decimater->module( decInit->hModEdgeLength ).set_edge_length(
tool_->edgeLength->value() );
451 params.dec = (
tool_->rbUseDecimater->isChecked()) ? dynamic_cast<DecimaterType*>(decimater.get()) : NULL;
452 params.mcDec = (
tool_->rbUseMC->isChecked()) ? dynamic_cast<McDecimaterType*>(decimater.get()) : NULL;
453 params.mixedDec = (
tool_->rbUseMixed->isChecked()) ? dynamic_cast<MixedDecimaterType*>(decimater.get()) : NULL;
455 params.facesCount = (
tool_->rbTriangles->isChecked()) ?
tool_->trianglesCount->value() : -1;
456 params.verticesCount = (
tool_->rbVertices->isChecked() ) ?
tool_->verticesCount->value() : -1;
457 params.samples =
tool_->randomSamplesCounter->value();
458 params.mc_factor = 1.0 - (
tool_->mixedFactorCounter->value()*0.01);
459 params.selectionOnly =
tool_->selectionOnly->isChecked();
462 QString jobId = QString(
"Decimate_Object_%1").arg(decInit->objId);
464 connect(th, SIGNAL(finished(QString)),
this,SIGNAL(finishJob(QString)));
465 connect(th, SIGNAL(finished(QString)),
this, SLOT(slot_decimate_finished(QString)));
466 connect(th, SIGNAL(state(QString,
int)),
this, SIGNAL(setJobState(QString,
int)));
467 connect(
this, SIGNAL(jobCanceled(QString)), th, SLOT(slotCancel(QString)));
469 tool_->pbDecimate->setEnabled(
false);
470 tool_->pbInitialize->setEnabled(
false);
472 emit startJob(jobId , QString(
"Decimate Object with Id %1").arg(decInit->objId) , 0, 100,
false);
484 emit jobCanceled(_job);
487 void DecimaterPlugin::slot_decimate_finished(QString _jobId)
494 if (!thread->baseDecimater())
498 thread->baseDecimater()->mesh().garbage_collection();
499 thread->baseDecimater()->mesh().update_normals();
502 emit createBackup( thread->objectId(),
"Decimation");
506 if (runningJobs_ == 0)
508 tool_->pbDecimate->setEnabled(
true);
509 tool_->pbInitialize->setEnabled(
true);
518 QStringList constraintList = _constraints.split(
";");
522 for (
auto i = 0 ; i < constraintList.size() ; ++i) {
523 const auto& currentConstraint = constraintList[i];
525 int pos = currentConstraint.indexOf(
"=" );
528 emit log(
LOGERR,
"Wrong parameter format for decimater: " + currentConstraint);
532 QString constraintName = currentConstraint.left(pos);
533 QString constraintValue = currentConstraint.right(currentConstraint.size() - pos -1 );
537 double value = constraintValue.toDouble(&ok);
540 emit log(
LOGERR,
"Wrong parameter format for decimater. Conversion failed!");
541 emit log(
LOGERR,
"Got Name : " + constraintName );
542 emit log(
LOGERR,
"Got Value: " + constraintValue);
547 map[constraintName] = value;
561 emit log(
LOGERR,tr(
"Unable to get Object"));
569 emit log(
LOGWARN , tr(
"Unable to get object ( Only Triangle Meshes supported)"));
579 object->setObjectData(DECIMATER, decimater);
583 ModAspectRatioH hModAspectRatio;
584 ModEdgeLengthH hModEdgeLength;
585 ModHausdorffH hModHausdorff;
586 ModIndependentH hModIndependent;
587 ModNormalDeviationH hModNormalDeviation;
588 ModNormalFlippingH hModNormalFlipping;
589 ModQuadricH hModQuadric;
590 ModRoundnessH hModRoundness;
593 ptr::shared_ptr<BaseDecimaterType> decimater_object;
594 if (_constraints.contains(
"decimater_type"))
597 int value = _constraints[
"decimater_type"].toInt(&ok);
601 decimater_object = ptr::shared_ptr<DecimaterType>(
new DecimaterType(*mesh));
603 decimater_object = ptr::shared_ptr<McDecimaterType>(
new McDecimaterType(*mesh));
605 decimater_object = ptr::shared_ptr<MixedDecimaterType>(
new MixedDecimaterType(*mesh));
610 if (!decimater_object)
611 decimater_object = ptr::shared_ptr<DecimaterType>(
new DecimaterType(*mesh));
614 if(decimater->distance()) {
615 decimater->removeDistanceConstraint();
616 decimater_object->remove(hModHausdorff);
618 if(decimater->normalDeviation()) {
619 decimater->removeNormalDeviationConstraint();
620 decimater_object->remove(hModNormalDeviation);
622 if(decimater->normalFlipping()) {
623 decimater->removeNormalFlippingConstraint();
624 decimater_object->remove(hModNormalFlipping);
626 if(decimater->roundness()) {
627 decimater->removeRoundnessConstraint();
628 decimater_object->remove(hModRoundness);
630 if(decimater->aspectRatio()) {
631 decimater->removeAspectRatioConstraint();
632 decimater_object->remove(hModAspectRatio);
634 if(decimater->edgeLength()) {
635 decimater->removeEdgeLengthConstraint();
636 decimater_object->remove(hModEdgeLength);
638 if(decimater->independentSets()) {
639 decimater->removeIndependentSetsConstraint();
640 decimater_object->remove(hModIndependent);
644 if ( _constraints.contains(
"decimation_order") ){
647 int value = _constraints[
"decimation_order"].toInt(&ok);
652 decimater->setDecimationOrder(DecimaterInfo::DISTANCE);
653 decimater_object->add( hModQuadric );
654 decimater_object->module( hModQuadric ).unset_max_err();
657 decimater->setDecimationOrder(DecimaterInfo::NORMALDEV);
658 decimater_object->add(hModNormalDeviation);
659 decimater_object->module(hModNormalDeviation).set_binary(
false);
662 decimater->setDecimationOrder(DecimaterInfo::EDGELENGTH);
663 decimater_object->add(hModEdgeLength);
664 decimater_object->module(hModEdgeLength).set_binary(
false);
667 emit log(
LOGERR,tr(
"Invalid Decimation Order"));
672 emit log(
LOGERR,tr(
"No Decimation Order set"));
677 bool verticesCount =
false;
678 bool trianglesCount =
false;
682 if ( _constraints.contains(
"vertices") ){
686 int value = _constraints[
"vertices"].toInt(&ok);
689 verticesCount =
true;
692 }
else if ( _constraints.contains(
"triangles") ){
696 int value = _constraints[
"triangles"].toInt(&ok);
699 trianglesCount =
true;
705 if ( _constraints.contains(
"distance") ){
709 double value = _constraints[
"distance"].toDouble(&ok);
712 if ( decimater_object->add( hModHausdorff ) || (!verticesCount && !trianglesCount) ) {
713 decimater->setDistanceConstraint( value );
714 decimater_object->module( hModHausdorff ).set_tolerance( decimater->distanceValue() );
720 if ( _constraints.contains(
"normal_deviation") ){
724 int value = _constraints[
"normal_deviation"].toInt(&ok);
727 if ( decimater_object->add( hModNormalDeviation ) || (!verticesCount && !trianglesCount) ) {
728 decimater->setNormalDeviationConstraint( value );
729 decimater_object->module( hModNormalDeviation ).set_normal_deviation( decimater->normalDeviationValue() );
733 if ( decimater_object->add( hModNormalFlipping ) || (!verticesCount && !trianglesCount) ) {
734 decimater->setNormalFlippingConstraint();
740 if ( _constraints.contains(
"roundness") ){
744 double value = _constraints[
"roundness"].toDouble(&ok);
747 if ( decimater_object->add( hModRoundness ) || (!verticesCount && !trianglesCount) ) {
748 decimater->setRoundnessConstraint( value );
749 decimater_object->module( hModRoundness ).set_min_roundness( decimater->roundnessValue(), true );
755 if ( _constraints.contains(
"aspect_ratio") ){
759 double value = _constraints[
"aspect_ratio"].toDouble(&ok);
762 if ( decimater_object->add( hModAspectRatio ) || (!verticesCount && !trianglesCount) ) {
763 decimater->setAspectRatioConstraint( value );
764 decimater_object->module( hModAspectRatio ).set_aspect_ratio( decimater->aspectRatioValue() );
770 if ( _constraints.contains(
"edge_length") ){
774 double value = _constraints[
"edge_length"].toDouble(&ok);
777 if ( decimater_object->add( hModEdgeLength ) || (!verticesCount && !trianglesCount) ) {
778 decimater->setEdgeLengthConstraint( value );
779 decimater_object->module( hModEdgeLength ).set_edge_length( decimater->edgeLengthValue() );
785 if ( _constraints.contains(
"independent_sets") ){
787 bool value = _constraints[
"independent_sets"].toBool();
790 if ( decimater_object->add( hModIndependent ) || (!verticesCount && !trianglesCount) ) {
791 decimater->setIndependentSetsConstraint();
797 bool selection_only =
false;
798 if ( _constraints.contains(
"selection_only") ){
800 selection_only = _constraints[
"selection_only"].toBool();
805 if( ! decimater_object->initialize() ){
806 emit log(
LOGWARN, tr(
"Decimater could not be initialized"));
810 float mc_factor = 0.5;
811 size_t randomSamples = 8;
813 if (_constraints.contains(
"random_samples"))
816 unsigned value =_constraints[
"random_samples"].toUInt(&ok);
818 randomSamples = value;
821 if (_constraints.contains(
"incremental_percentage"))
824 unsigned value =_constraints[
"incremental_percentage"].toUInt(&ok);
826 mc_factor = 1.f - (value*0.01f);
830 DecimaterType* dec =
dynamic_cast<DecimaterType*
>(decimater_object.get());
831 McDecimaterType* mcDec =
dynamic_cast<McDecimaterType*
>(decimater_object.get());
832 MixedDecimaterType* mixedDec =
dynamic_cast<MixedDecimaterType*
>(decimater_object.get());
837 dec->decimate_to(vertices,selection_only);
838 else if (trianglesCount )
839 dec->decimate_to_faces(0, triangles,selection_only);
841 dec->decimate_to_faces(0, 1,selection_only);
843 else if (mcDec && !mixedDec)
845 mcDec->set_samples(randomSamples);
847 mcDec->decimate_to(vertices,selection_only);
848 else if (trianglesCount)
849 mcDec->decimate_to_faces(0, triangles,selection_only);
851 mcDec->decimate_to_faces(0, 1,selection_only);
855 mixedDec->set_samples(randomSamples);
857 mixedDec->decimate_to(vertices,mc_factor,selection_only);
858 else if (trianglesCount)
859 mixedDec->decimate_to_faces(0, triangles,mc_factor,selection_only);
861 mixedDec->decimate_to_faces(0, 1,mc_factor,selection_only);
864 emit log(
LOGERR,tr(
"Could not find Decimater Type"));
867 object->mesh()->garbage_collection();
868 object->mesh()->update_normals();
873 emit createBackup(_objID,
"Decimation");
876 QString param =
"(" + (_constraints.contains(
"decimation_order") ? tr(
"decimation_order = %1").arg(_constraints[
"decimation_order"].toString()) :
"") +
877 ", " + (_constraints.contains(
"distance") ? tr(
"distance = %1").arg(_constraints[
"distance"].toString()) :
"") +
878 ", " + (_constraints.contains(
"normal_deviation") ? tr(
"normal_deviation = %1").arg(_constraints[
"normal_deviation"].toString()) :
"") +
879 ", " + (_constraints.contains(
"edge_length") ? tr(
"edge_length = %1").arg(_constraints[
"edge_length"].toString()) :
"") +
880 ", " + (_constraints.contains(
"roundness") ? tr(
"roundness = %1").arg(_constraints[
"roundness"].toString()) :
"") +
881 ", " + (_constraints.contains(
"aspect_ratio") ? tr(
"aspect_ratio = %1").arg(_constraints[
"aspect_ratio"].toString()) :
"") +
882 ", " + (_constraints.contains(
"independent_sets") ? tr(
"independent_sets = %1").arg(_constraints[
"independent_sets"].toString()) :
"") +
883 ", " + (_constraints.contains(
"triangles") ? tr(
"triangles = %1").arg(_constraints[
"triangles"].toString()) :
"") +
884 ", " + (_constraints.contains(
"vertices") ? tr(
"vertices = %1").arg(_constraints[
"vertices"].toString()) :
"") +
")";
886 emit scriptInfo(
"decimate(" + QString::number(_objID) +
", " + param +
")" );
890 emit log(
LOGERR,tr(
"Unsupported object type for decimater"));
902 if ( !OpenFlipper::Options::gui() || !
tool_->isVisible() ) {
910 emit functionExists(
"infomeshobject" ,
"vertexCount(int)", ok ) ;
913 tool_->currentNumVertices->setText (
"<not available>");
918 max = std::max( RPC::callFunctionValue<int> (
"infomeshobject" ,
"vertexCount",o_it->id()) , max );
923 tool_->currentNumVertices->setText (
"<not available>");
925 tool_->verticesCount->blockSignals(
true);
926 tool_->verticesCountSlider->blockSignals(
true);
928 tool_->currentNumVertices->setText (QString::number(max));
929 tool_->verticesCount->setMaximum(max);
930 tool_->verticesCountSlider->setMaximum(max);
932 if (
tool_->verticesCount->value() < 2 )
934 tool_->verticesCount->setValue( max / 2 );
935 tool_->verticesCountSlider->setValue( max / 2);
938 tool_->verticesCount->blockSignals(
false);
939 tool_->verticesCountSlider->blockSignals(
false);
950 if (!OpenFlipper::Options::gui() || !
tool_->isVisible())
958 max = std::max(mesh->n_faces(), max);
962 tool_->trianglesCount->blockSignals(
true);
963 tool_->trianglesCountSlider->blockSignals(
true);
965 tool_->trianglesCount->setMinimum(1);
966 tool_->trianglesCount->setMaximum(max);
967 tool_->trianglesCountSlider->setMinimum(1);
968 tool_->trianglesCountSlider->setMaximum(max);
970 if (
tool_->trianglesCount->value() < 2)
972 tool_->trianglesCount->setValue (max / 2 );
973 tool_->trianglesCountSlider->setValue( max / 2);
976 tool_->trianglesCount->blockSignals(
false);
977 tool_->trianglesCountSlider->blockSignals(
false);
982 void DecimaterPlugin::slotObjectSelectionChanged(
int )
989 void DecimaterPlugin::objectDeleted(
int _id)
991 slotDisableDecimation();
996 void DecimaterPlugin::slotAboutToRestore(
int _id)
998 slotDisableDecimation();
1003 void DecimaterPlugin::slotDisableDecimation()
1005 if ( ! OpenFlipper::Options::gui())
1008 decimater_objects_.clear();
1009 tool_->pbDecimate->setEnabled(
false);
1014 void DecimaterPlugin::slotObjectUpdated(
int ,
const UpdateType& _type )
1025 void DecimaterPlugin::slotUpdateVertices()
1027 tool_->rbVertices->setChecked (
true);
1033 void DecimaterPlugin::slotUpdateTriangles()
1035 tool_->rbTriangles->setChecked (
true);
1041 void DecimaterPlugin::slotUpdateNormalDev()
1043 tool_->cbNormalDev->setChecked (
true);
1049 void DecimaterPlugin::slotUpdateEdgeLength()
1051 tool_->cbEdgeLength->setChecked (
true);
1059 tool_->cbDistance->setChecked (
true);
const UpdateType UPDATE_TOPOLOGY(UpdateTypeSet(8))
Topology updated.
a class which provides an link generator for WhatsThisMessages linking to the user doc If you have an...
#define DATA_TRIANGLE_MESH
void setObjectData(QString _dataName, PerObjectData *_data)
void canceledJob(QString _job)
A job has been canceled.
void slotUpdateRoundness(int _value)
roundness slider - spinbox sync
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
void pluginsInitialized()
Initialization of the plugin when it is loaded by the core.
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
void slot_decimate()
decimating called from button in toolbox
void startProcessing()
start processing
void slotUpdateNumVertices()
update number of vertices information
bool dataType(DataType _type) const
void slotUpdateAspectRatio(int _value)
sync between values of aspect ratio slider and spinbox in the toolbox
void decimate(int _objID, QVariantMap _constraints)
decimate an object
DecimaterToolbarWidget * tool_
Widget for Toolbox.
void slotUpdateDistance()
slider / spinbox updates
TriMeshObject * triMeshObject(BaseObjectData *_object)
Cast an BaseObject to a TriMeshObject if possible.
Type for a MeshObject containing a triangle mesh.
void slot_initialize()
init called from button in toolbox
const QStringList TARGET_OBJECTS("target")
Iterable object range.
ObjectRange objects(IteratorRestriction _restriction, DataType _dataType)
Iterable object range.
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
PerObjectData * objectData(QString _dataName)
Returns the object data pointer.
QString generateLink(const QString &_ref="", const QString &_site="index.html") const
generates a clickable link to the documentation for whatsThis Messages
void slotUpdateNumTriangles()
gets and sets the current maximum number of triangles
DecimaterPlugin()
Default constructor.