1
/***************************************************************************
2
* Copyright (c) 2012 Werner Mayer <wmayer[at]users.sourceforge.net> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library is distributed in the hope that it will be useful, *
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14
* GNU Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
23
#include "PreCompiled.h"
28
#include <App/Application.h>
29
#include <App/Document.h>
30
#include <App/DocumentObjectGroup.h>
31
#include <Mod/Mesh/App/Core/Curvature.h>
32
#include <Mod/Mesh/App/Core/Segmentation.h>
33
#include <Mod/Mesh/App/Core/Smoothing.h>
34
#include <Mod/Mesh/App/MeshFeature.h>
36
#include "Segmentation.h"
37
#include "ui_Segmentation.h"
40
using namespace MeshGui;
42
Segmentation::Segmentation(Mesh::Feature* mesh, QWidget* parent, Qt::WindowFlags fl)
44
, ui(new Ui_Segmentation)
48
ui->numPln->setRange(1, INT_MAX);
49
ui->numPln->setValue(100);
50
ui->crvCyl->setRange(0, INT_MAX);
51
ui->numCyl->setRange(1, INT_MAX);
52
ui->numCyl->setValue(100);
53
ui->crvSph->setRange(0, INT_MAX);
54
ui->numSph->setRange(1, INT_MAX);
55
ui->numSph->setValue(100);
56
ui->crv1Free->setRange(-INT_MAX, INT_MAX);
57
ui->crv2Free->setRange(-INT_MAX, INT_MAX);
58
ui->numFree->setRange(1, INT_MAX);
59
ui->numFree->setValue(100);
61
ui->checkBoxSmooth->setChecked(false);
64
Segmentation::~Segmentation()
66
// no need to delete child widgets, Qt does it all for us
70
void Segmentation::accept()
72
const Mesh::MeshObject* mesh = myMesh->Mesh.getValuePtr();
73
// make a copy because we might smooth the mesh before
74
MeshCore::MeshKernel kernel = mesh->getKernel();
76
if (ui->checkBoxSmooth->isChecked()) {
77
MeshCore::LaplaceSmoothing smoother(kernel);
78
smoother.Smooth(ui->smoothSteps->value());
81
MeshCore::MeshSegmentAlgorithm finder(kernel);
82
MeshCore::MeshCurvature meshCurv(kernel);
83
meshCurv.ComputePerVertex();
85
std::vector<MeshCore::MeshSurfaceSegmentPtr> segm;
86
if (ui->groupBoxFree->isChecked()) {
88
std::make_shared<MeshCore::MeshCurvatureFreeformSegment>(meshCurv.GetCurvature(),
90
ui->tol1Free->value(),
91
ui->tol2Free->value(),
92
ui->crv1Free->value(),
93
ui->crv2Free->value()));
95
if (ui->groupBoxCyl->isChecked()) {
97
std::make_shared<MeshCore::MeshCurvatureCylindricalSegment>(meshCurv.GetCurvature(),
100
ui->tol2Cyl->value(),
101
ui->crvCyl->value()));
103
if (ui->groupBoxSph->isChecked()) {
105
std::make_shared<MeshCore::MeshCurvatureSphericalSegment>(meshCurv.GetCurvature(),
108
ui->crvSph->value()));
110
if (ui->groupBoxPln->isChecked()) {
112
std::make_shared<MeshCore::MeshCurvaturePlanarSegment>(meshCurv.GetCurvature(),
114
ui->tolPln->value()));
116
finder.FindSegments(segm);
118
App::Document* document = App::GetApplication().getActiveDocument();
119
document->openTransaction("Segmentation");
121
std::string internalname = "Segments_";
122
internalname += myMesh->getNameInDocument();
123
App::DocumentObjectGroup* group = static_cast<App::DocumentObjectGroup*>(
124
document->addObject("App::DocumentObjectGroup", internalname.c_str()));
125
std::string labelname = "Segments ";
126
labelname += myMesh->Label.getValue();
127
group->Label.setValue(labelname);
128
for (const auto& it : segm) {
129
const std::vector<MeshCore::MeshSegment>& data = it->GetSegments();
130
for (const auto& jt : data) {
131
Mesh::MeshObject* segment = mesh->meshFromSegment(jt);
132
Mesh::Feature* feaSegm =
133
static_cast<Mesh::Feature*>(group->addObject("Mesh::Feature", "Segment"));
134
Mesh::MeshObject* feaMesh = feaSegm->Mesh.startEditing();
135
feaMesh->swap(*segment);
136
feaSegm->Mesh.finishEditing();
139
std::stringstream label;
140
label << feaSegm->Label.getValue() << " (" << it->GetType() << ")";
141
feaSegm->Label.setValue(label.str());
144
document->commitTransaction();
147
void Segmentation::changeEvent(QEvent* e)
149
if (e->type() == QEvent::LanguageChange) {
150
ui->retranslateUi(this);
152
QWidget::changeEvent(e);
155
// ---------------------------------------
157
/* TRANSLATOR MeshGui::TaskRemoveComponents */
159
TaskSegmentation::TaskSegmentation(Mesh::Feature* mesh)
161
widget = new Segmentation(mesh); // NOLINT
162
addTaskBox(widget, false);
165
bool TaskSegmentation::accept()