| | |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #include <limits> |
| | #include <sstream> |
| |
|
| | #include <App/Application.h> |
| | #include <App/Document.h> |
| | #include <App/DocumentObjectGroup.h> |
| | #include <Mod/Mesh/App/Core/Curvature.h> |
| | #include <Mod/Mesh/App/Core/Segmentation.h> |
| | #include <Mod/Mesh/App/Core/Smoothing.h> |
| | #include <Mod/Mesh/App/MeshFeature.h> |
| |
|
| | #include "Segmentation.h" |
| | #include "ui_Segmentation.h" |
| |
|
| |
|
| | using namespace MeshGui; |
| |
|
| | Segmentation::Segmentation(Mesh::Feature* mesh, QWidget* parent, Qt::WindowFlags fl) |
| | : QWidget(parent, fl) |
| | , ui(new Ui_Segmentation) |
| | , myMesh(mesh) |
| | { |
| | constexpr int max = std::numeric_limits<int>::max(); |
| | ui->setupUi(this); |
| | ui->numPln->setRange(1, max); |
| | ui->numPln->setValue(100); |
| | ui->crvCyl->setRange(0, max); |
| | ui->numCyl->setRange(1, max); |
| | ui->numCyl->setValue(100); |
| | ui->crvSph->setRange(0, max); |
| | ui->numSph->setRange(1, max); |
| | ui->numSph->setValue(100); |
| | ui->crv1Free->setRange(-max, max); |
| | ui->crv2Free->setRange(-max, max); |
| | ui->numFree->setRange(1, max); |
| | ui->numFree->setValue(100); |
| |
|
| | ui->checkBoxSmooth->setChecked(false); |
| | } |
| |
|
| | Segmentation::~Segmentation() |
| | { |
| | |
| | delete ui; |
| | } |
| |
|
| | void Segmentation::accept() |
| | { |
| | const Mesh::MeshObject* mesh = myMesh->Mesh.getValuePtr(); |
| | |
| | MeshCore::MeshKernel kernel = mesh->getKernel(); |
| |
|
| | if (ui->checkBoxSmooth->isChecked()) { |
| | MeshCore::LaplaceSmoothing smoother(kernel); |
| | smoother.Smooth(ui->smoothSteps->value()); |
| | } |
| |
|
| | MeshCore::MeshSegmentAlgorithm finder(kernel); |
| | MeshCore::MeshCurvature meshCurv(kernel); |
| | meshCurv.ComputePerVertex(); |
| |
|
| | std::vector<MeshCore::MeshSurfaceSegmentPtr> segm; |
| | if (ui->groupBoxFree->isChecked()) { |
| | segm.emplace_back( |
| | std::make_shared<MeshCore::MeshCurvatureFreeformSegment>( |
| | meshCurv.GetCurvature(), |
| | ui->numFree->value(), |
| | ui->tol1Free->value(), |
| | ui->tol2Free->value(), |
| | ui->crv1Free->value(), |
| | ui->crv2Free->value() |
| | ) |
| | ); |
| | } |
| | if (ui->groupBoxCyl->isChecked()) { |
| | segm.emplace_back( |
| | std::make_shared<MeshCore::MeshCurvatureCylindricalSegment>( |
| | meshCurv.GetCurvature(), |
| | ui->numCyl->value(), |
| | ui->tol1Cyl->value(), |
| | ui->tol2Cyl->value(), |
| | ui->crvCyl->value() |
| | ) |
| | ); |
| | } |
| | if (ui->groupBoxSph->isChecked()) { |
| | segm.emplace_back( |
| | std::make_shared<MeshCore::MeshCurvatureSphericalSegment>( |
| | meshCurv.GetCurvature(), |
| | ui->numSph->value(), |
| | ui->tolSph->value(), |
| | ui->crvSph->value() |
| | ) |
| | ); |
| | } |
| | if (ui->groupBoxPln->isChecked()) { |
| | segm.emplace_back( |
| | std::make_shared<MeshCore::MeshCurvaturePlanarSegment>( |
| | meshCurv.GetCurvature(), |
| | ui->numPln->value(), |
| | ui->tolPln->value() |
| | ) |
| | ); |
| | } |
| | finder.FindSegments(segm); |
| |
|
| | App::Document* document = App::GetApplication().getActiveDocument(); |
| | document->openTransaction("Segmentation"); |
| |
|
| | std::string internalname = "Segments_"; |
| | internalname += myMesh->getNameInDocument(); |
| | auto* group = document->addObject<App::DocumentObjectGroup>(internalname.c_str()); |
| | std::string labelname = "Segments "; |
| | labelname += myMesh->Label.getValue(); |
| | group->Label.setValue(labelname); |
| | for (const auto& it : segm) { |
| | const std::vector<MeshCore::MeshSegment>& data = it->GetSegments(); |
| | for (const auto& jt : data) { |
| | Mesh::MeshObject* segment = mesh->meshFromSegment(jt); |
| | auto* feaSegm = group->addObject<Mesh::Feature>("Segment"); |
| | Mesh::MeshObject* feaMesh = feaSegm->Mesh.startEditing(); |
| | feaMesh->swap(*segment); |
| | feaSegm->Mesh.finishEditing(); |
| | delete segment; |
| |
|
| | std::stringstream label; |
| | label << feaSegm->Label.getValue() << " (" << it->GetType() << ")"; |
| | feaSegm->Label.setValue(label.str()); |
| | } |
| | } |
| | document->commitTransaction(); |
| | } |
| |
|
| | void Segmentation::changeEvent(QEvent* e) |
| | { |
| | if (e->type() == QEvent::LanguageChange) { |
| | ui->retranslateUi(this); |
| | } |
| | QWidget::changeEvent(e); |
| | } |
| |
|
| | |
| |
|
| | |
| |
|
| | TaskSegmentation::TaskSegmentation(Mesh::Feature* mesh) |
| | { |
| | widget = new Segmentation(mesh); |
| | addTaskBox(widget, false); |
| | } |
| |
|
| | bool TaskSegmentation::accept() |
| | { |
| | widget->accept(); |
| | return true; |
| | } |
| |
|