ReverseEngineering: implement mesh segmentation workflow
This commit is contained in:
@@ -171,6 +171,21 @@ float PlaneSurfaceFit::GetDistanceToSurface(const Base::Vector3f& pnt) const
|
||||
return fitter->GetDistanceToPlane(pnt);
|
||||
}
|
||||
|
||||
Base::Vector3f PlaneSurfaceFit::Project(const Base::Vector3f& pt) const
|
||||
{
|
||||
Base::Vector3f prj(pt);
|
||||
if (!fitter) {
|
||||
prj.ProjectToPlane(basepoint, normal);
|
||||
}
|
||||
else {
|
||||
Base::Vector3f base = fitter->GetBase();
|
||||
Base::Vector3f norm = fitter->GetNormal();
|
||||
prj.ProjectToPlane(base, norm);
|
||||
}
|
||||
|
||||
return prj;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------
|
||||
|
||||
CylinderSurfaceFit::CylinderSurfaceFit()
|
||||
@@ -257,6 +272,12 @@ float CylinderSurfaceFit::GetDistanceToSurface(const Base::Vector3f& pnt) const
|
||||
return (dist - radius);
|
||||
}
|
||||
|
||||
Base::Vector3f CylinderSurfaceFit::Project(const Base::Vector3f& pt) const
|
||||
{
|
||||
//TODO
|
||||
return pt;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------
|
||||
|
||||
SphereSurfaceFit::SphereSurfaceFit()
|
||||
@@ -332,6 +353,12 @@ float SphereSurfaceFit::GetDistanceToSurface(const Base::Vector3f& pnt) const
|
||||
return (dist - radius);
|
||||
}
|
||||
|
||||
Base::Vector3f SphereSurfaceFit::Project(const Base::Vector3f& pt) const
|
||||
{
|
||||
//TODO
|
||||
return pt;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------
|
||||
|
||||
MeshDistanceGenericSurfaceFitSegment::MeshDistanceGenericSurfaceFitSegment(AbstractSurfaceFit* fit,
|
||||
@@ -383,6 +410,17 @@ void MeshDistanceGenericSurfaceFitSegment::AddFacet(const MeshFacet& face)
|
||||
fitter->AddTriangle(triangle);
|
||||
}
|
||||
|
||||
std::vector<Base::Vector3f> MeshDistanceGenericSurfaceFitSegment::Project(const std::vector<Base::Vector3f>& pts) const
|
||||
{
|
||||
std::vector<Base::Vector3f> prj;
|
||||
prj.reserve(pts.size());
|
||||
for (const auto it : pts) {
|
||||
prj.push_back(fitter->Project(it));
|
||||
}
|
||||
|
||||
return prj;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------
|
||||
|
||||
bool MeshCurvaturePlanarSegment::TestFacet (const MeshFacet &rclFacet) const
|
||||
|
||||
@@ -99,6 +99,7 @@ public:
|
||||
virtual bool Done() const = 0;
|
||||
virtual float Fit() = 0;
|
||||
virtual float GetDistanceToSurface(const Base::Vector3f&) const = 0;
|
||||
virtual Base::Vector3f Project(const Base::Vector3f&) const = 0;
|
||||
};
|
||||
|
||||
class MeshExport PlaneSurfaceFit : public AbstractSurfaceFit
|
||||
@@ -114,6 +115,7 @@ public:
|
||||
bool Done() const;
|
||||
float Fit();
|
||||
float GetDistanceToSurface(const Base::Vector3f&) const;
|
||||
Base::Vector3f Project(const Base::Vector3f&) const;
|
||||
|
||||
private:
|
||||
Base::Vector3f basepoint;
|
||||
@@ -134,6 +136,7 @@ public:
|
||||
bool Done() const;
|
||||
float Fit();
|
||||
float GetDistanceToSurface(const Base::Vector3f&) const;
|
||||
Base::Vector3f Project(const Base::Vector3f&) const;
|
||||
|
||||
private:
|
||||
Base::Vector3f basepoint;
|
||||
@@ -155,6 +158,7 @@ public:
|
||||
bool Done() const;
|
||||
float Fit();
|
||||
float GetDistanceToSurface(const Base::Vector3f&) const;
|
||||
Base::Vector3f Project(const Base::Vector3f&) const;
|
||||
|
||||
private:
|
||||
Base::Vector3f center;
|
||||
@@ -173,6 +177,7 @@ public:
|
||||
void Initialize(unsigned long);
|
||||
bool TestInitialFacet(unsigned long) const;
|
||||
void AddFacet(const MeshFacet& rclFacet);
|
||||
std::vector<Base::Vector3f> Project(const std::vector<Base::Vector3f>&) const;
|
||||
|
||||
protected:
|
||||
AbstractSurfaceFit* fitter;
|
||||
|
||||
@@ -31,6 +31,7 @@ endif()
|
||||
set(ReenGui_MOC_HDRS
|
||||
FitBSplineSurface.h
|
||||
Poisson.h
|
||||
Segmentation.h
|
||||
)
|
||||
fc_wrap_cpp(ReenGui_MOC_SRCS ${ReenGui_MOC_HDRS})
|
||||
SOURCE_GROUP("Moc" FILES ${ReenGui_MOC_SRCS})
|
||||
@@ -38,6 +39,7 @@ SOURCE_GROUP("Moc" FILES ${ReenGui_MOC_SRCS})
|
||||
set(Dialogs_UIC_SRCS
|
||||
FitBSplineSurface.ui
|
||||
Poisson.ui
|
||||
Segmentation.ui
|
||||
)
|
||||
|
||||
if(BUILD_QT5)
|
||||
@@ -53,6 +55,8 @@ SET(Dialogs_SRCS
|
||||
FitBSplineSurface.h
|
||||
Poisson.cpp
|
||||
Poisson.h
|
||||
Segmentation.cpp
|
||||
Segmentation.h
|
||||
)
|
||||
SOURCE_GROUP("Dialogs" FILES ${Dialogs_SRCS})
|
||||
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
#ifndef _PreComp_
|
||||
# include <QApplication>
|
||||
# include <QMessageBox>
|
||||
# include <BRep_Builder.hxx>
|
||||
# include <BRepBuilderAPI_MakePolygon.hxx>
|
||||
# include <TopoDS_Compound.hxx>
|
||||
#endif
|
||||
|
||||
#include <sstream>
|
||||
@@ -34,7 +37,9 @@
|
||||
#include <Mod/Points/App/Structured.h>
|
||||
#include <Mod/Mesh/App/MeshFeature.h>
|
||||
#include <Mod/Mesh/App/Core/Approximation.h>
|
||||
#include <Mod/Mesh/App/Core/Algorithm.h>
|
||||
|
||||
#include <App/Document.h>
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/Control.h>
|
||||
@@ -47,6 +52,7 @@
|
||||
#include "../App/ApproxSurface.h"
|
||||
#include "FitBSplineSurface.h"
|
||||
#include "Poisson.h"
|
||||
#include "Segmentation.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -186,6 +192,89 @@ bool CmdApproxPlane::isActive(void)
|
||||
return false;
|
||||
}
|
||||
|
||||
DEF_STD_CMD_A(CmdSegmentation)
|
||||
|
||||
CmdSegmentation::CmdSegmentation()
|
||||
: Command("Reen_Segmentation")
|
||||
{
|
||||
sAppModule = "Reen";
|
||||
sGroup = QT_TR_NOOP("Reverse Engineering");
|
||||
sMenuText = QT_TR_NOOP("Create mesh segments...");
|
||||
sToolTipText = QT_TR_NOOP("Create mesh segments");
|
||||
sWhatsThis = "Reen_Segmentation";
|
||||
sStatusTip = sToolTipText;
|
||||
}
|
||||
|
||||
void CmdSegmentation::activated(int)
|
||||
{
|
||||
std::vector<Mesh::Feature*> objs = Gui::Selection().getObjectsOfType<Mesh::Feature>();
|
||||
Mesh::Feature* mesh = static_cast<Mesh::Feature*>(objs.front());
|
||||
Gui::TaskView::TaskDialog* dlg = Gui::Control().activeDialog();
|
||||
if (!dlg) {
|
||||
dlg = new ReverseEngineeringGui::TaskSegmentation(mesh);
|
||||
}
|
||||
Gui::Control().showDialog(dlg);
|
||||
}
|
||||
|
||||
bool CmdSegmentation::isActive(void)
|
||||
{
|
||||
if (Gui::Control().activeDialog())
|
||||
return false;
|
||||
return Gui::Selection().countObjectsOfType
|
||||
(Mesh::Feature::getClassTypeId()) == 1;
|
||||
}
|
||||
|
||||
DEF_STD_CMD_A(CmdMeshBoundary)
|
||||
|
||||
CmdMeshBoundary::CmdMeshBoundary()
|
||||
: Command("Reen_MeshBoundary")
|
||||
{
|
||||
sAppModule = "Reen";
|
||||
sGroup = QT_TR_NOOP("Reverse Engineering");
|
||||
sMenuText = QT_TR_NOOP("Wire from mesh...");
|
||||
sToolTipText = QT_TR_NOOP("Create wire from mesh");
|
||||
sWhatsThis = "Reen_Segmentation";
|
||||
sStatusTip = sToolTipText;
|
||||
}
|
||||
|
||||
void CmdMeshBoundary::activated(int)
|
||||
{
|
||||
std::vector<Mesh::Feature*> objs = Gui::Selection().getObjectsOfType<Mesh::Feature>();
|
||||
App::Document* document = App::GetApplication().getActiveDocument();
|
||||
document->openTransaction("Wire from mesh");
|
||||
for (auto it : objs) {
|
||||
const Mesh::MeshObject& mesh = it->Mesh.getValue();
|
||||
std::list<std::vector<Base::Vector3f> > bounds;
|
||||
MeshCore::MeshAlgorithm algo(mesh.getKernel());
|
||||
algo.GetMeshBorders(bounds);
|
||||
|
||||
BRep_Builder builder;
|
||||
TopoDS_Compound compound;
|
||||
builder.MakeCompound(compound);
|
||||
|
||||
for (auto bt = bounds.begin(); bt != bounds.end(); ++bt) {
|
||||
BRepBuilderAPI_MakePolygon mkPoly;
|
||||
for (std::vector<Base::Vector3f>::reverse_iterator it = bt->rbegin(); it != bt->rend(); ++it) {
|
||||
mkPoly.Add(gp_Pnt(it->x,it->y,it->z));
|
||||
}
|
||||
if (mkPoly.IsDone()) {
|
||||
builder.Add(compound, mkPoly.Wire());
|
||||
}
|
||||
}
|
||||
|
||||
Part::Feature* shapeFea = static_cast<Part::Feature*>(document->addObject("Part::Feature", "Wires from mesh"));
|
||||
shapeFea->Shape.setValue(compound);
|
||||
|
||||
}
|
||||
document->commitTransaction();
|
||||
}
|
||||
|
||||
bool CmdMeshBoundary::isActive(void)
|
||||
{
|
||||
return Gui::Selection().countObjectsOfType
|
||||
(Mesh::Feature::getClassTypeId()) > 0;
|
||||
}
|
||||
|
||||
DEF_STD_CMD_A(CmdPoissonReconstruction)
|
||||
|
||||
CmdPoissonReconstruction::CmdPoissonReconstruction()
|
||||
@@ -277,6 +366,8 @@ void CreateReverseEngineeringCommands(void)
|
||||
Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
|
||||
rcCmdMgr.addCommand(new CmdApproxSurface());
|
||||
rcCmdMgr.addCommand(new CmdApproxPlane());
|
||||
rcCmdMgr.addCommand(new CmdSegmentation());
|
||||
rcCmdMgr.addCommand(new CmdMeshBoundary());
|
||||
rcCmdMgr.addCommand(new CmdPoissonReconstruction());
|
||||
rcCmdMgr.addCommand(new CmdViewTriangulation());
|
||||
}
|
||||
|
||||
254
src/Mod/ReverseEngineering/Gui/Segmentation.cpp
Normal file
254
src/Mod/ReverseEngineering/Gui/Segmentation.cpp
Normal file
@@ -0,0 +1,254 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2012 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library 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 Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <sstream>
|
||||
# include <BRep_Builder.hxx>
|
||||
# include <BRepBuilderAPI_MakePolygon.hxx>
|
||||
# include <Standard_Failure.hxx>
|
||||
# include <TopoDS_Compound.hxx>
|
||||
# include <TopoDS_Wire.hxx>
|
||||
#endif
|
||||
|
||||
#include "Segmentation.h"
|
||||
#include "ui_Segmentation.h"
|
||||
#include <Base/Console.h>
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObjectGroup.h>
|
||||
#include <Gui/WaitCursor.h>
|
||||
|
||||
#include <Mod/Mesh/App/Core/Approximation.h>
|
||||
#include <Mod/Mesh/App/Core/Algorithm.h>
|
||||
#include <Mod/Mesh/App/Core/Segmentation.h>
|
||||
#include <Mod/Mesh/App/Core/Curvature.h>
|
||||
#include <Mod/Mesh/App/Core/Smoothing.h>
|
||||
#include <Mod/Mesh/App/Mesh.h>
|
||||
#include <Mod/Mesh/App/MeshFeature.h>
|
||||
#include <Mod/Part/App/PartFeature.h>
|
||||
#include <Mod/Part/App/FaceMakerCheese.h>
|
||||
|
||||
using namespace ReverseEngineeringGui;
|
||||
|
||||
Segmentation::Segmentation(Mesh::Feature* mesh, QWidget* parent, Qt::WindowFlags fl)
|
||||
: QWidget(parent, fl)
|
||||
, ui(new Ui_Segmentation)
|
||||
, myMesh(mesh)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->numPln->setRange(1, INT_MAX);
|
||||
ui->numPln->setValue(100);
|
||||
|
||||
ui->checkBoxSmooth->setChecked(false);
|
||||
}
|
||||
|
||||
Segmentation::~Segmentation()
|
||||
{
|
||||
}
|
||||
|
||||
void Segmentation::accept()
|
||||
{
|
||||
if (myMesh.expired())
|
||||
return;
|
||||
|
||||
Gui::WaitCursor wc;
|
||||
bool createUnused = ui->createUnused->isChecked();
|
||||
bool createCompound = ui->createCompound->isChecked();
|
||||
BRep_Builder builder;
|
||||
TopoDS_Compound compound;
|
||||
builder.MakeCompound(compound);
|
||||
|
||||
const Mesh::MeshObject* mesh = myMesh.get<Mesh::Feature>()->Mesh.getValuePtr();
|
||||
// make a copy because we might smooth the mesh before
|
||||
MeshCore::MeshKernel kernel = mesh->getKernel();
|
||||
MeshCore::MeshAlgorithm algo(kernel);
|
||||
|
||||
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->groupBoxPln->isChecked()) {
|
||||
segm.emplace_back(new MeshCore::MeshCurvaturePlanarSegment
|
||||
(meshCurv.GetCurvature(), ui->numPln->value(), ui->curvTolPln->value()));
|
||||
}
|
||||
finder.FindSegments(segm);
|
||||
|
||||
// For each planar segment compute a plane and use this then for a more accurate 2nd segmentation
|
||||
std::vector<MeshCore::MeshSurfaceSegmentPtr> segmSurf;
|
||||
for (std::vector<MeshCore::MeshSurfaceSegmentPtr>::iterator it = segm.begin(); it != segm.end(); ++it) {
|
||||
const std::vector<MeshCore::MeshSegment>& data = (*it)->GetSegments();
|
||||
for (std::vector<MeshCore::MeshSegment>::const_iterator jt = data.begin(); jt != data.end(); ++jt) {
|
||||
std::vector<unsigned long> indexes = kernel.GetFacetPoints(*jt);
|
||||
MeshCore::PlaneFit fit;
|
||||
fit.AddPoints(kernel.GetPoints(indexes));
|
||||
if (fit.Fit() < FLOAT_MAX) {
|
||||
Base::Vector3f base = fit.GetBase();
|
||||
Base::Vector3f axis = fit.GetNormal();
|
||||
MeshCore::AbstractSurfaceFit* fitter = new MeshCore::PlaneSurfaceFit(base, axis);
|
||||
segmSurf.emplace_back(new MeshCore::MeshDistanceGenericSurfaceFitSegment
|
||||
(fitter, kernel, ui->numPln->value(), ui->distToPln->value()));
|
||||
}
|
||||
}
|
||||
}
|
||||
finder.FindSegments(segmSurf);
|
||||
|
||||
App::Document* document = App::GetApplication().getActiveDocument();
|
||||
document->openTransaction("Segmentation");
|
||||
|
||||
std::string internalname = "Segments_";
|
||||
internalname += myMesh->getNameInDocument();
|
||||
|
||||
App::DocumentObjectGroup* group = static_cast<App::DocumentObjectGroup*>(document->addObject
|
||||
("App::DocumentObjectGroup", internalname.c_str()));
|
||||
std::string labelname = "Segments ";
|
||||
labelname += myMesh->Label.getValue();
|
||||
group->Label.setValue(labelname);
|
||||
|
||||
std::vector<App::DocumentObject*> failures;
|
||||
algo.SetFacetFlag(MeshCore::MeshFacet::TMP0);
|
||||
|
||||
for (std::vector<MeshCore::MeshSurfaceSegmentPtr>::iterator it = segmSurf.begin(); it != segmSurf.end(); ++it) {
|
||||
const std::vector<MeshCore::MeshSegment>& data = (*it)->GetSegments();
|
||||
std::shared_ptr<MeshCore::MeshDistanceGenericSurfaceFitSegment> genSegm = std::dynamic_pointer_cast
|
||||
<MeshCore::MeshDistanceGenericSurfaceFitSegment>(*it);
|
||||
|
||||
for (std::vector<MeshCore::MeshSegment>::const_iterator jt = data.begin(); jt != data.end(); ++jt) {
|
||||
// reset flag for facets of segment
|
||||
algo.ResetFacetsFlag(*jt, MeshCore::MeshFacet::TMP0);
|
||||
|
||||
Mesh::MeshObject* segment = mesh->meshFromSegment(*jt);
|
||||
Mesh::Feature* feaSegm = static_cast<Mesh::Feature*>(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());
|
||||
|
||||
if (createCompound) {
|
||||
std::list<std::vector<Base::Vector3f> > bounds;
|
||||
algo.GetFacetBorders(*jt, bounds);
|
||||
|
||||
std::vector<TopoDS_Wire> wires;
|
||||
for (auto bt = bounds.begin(); bt != bounds.end(); ++bt) {
|
||||
// project the points onto the surface
|
||||
auto prj = genSegm->Project(*bt);
|
||||
BRepBuilderAPI_MakePolygon mkPoly;
|
||||
for (std::vector<Base::Vector3f>::reverse_iterator it = prj.rbegin(); it != prj.rend(); ++it) {
|
||||
mkPoly.Add(gp_Pnt(it->x,it->y,it->z));
|
||||
}
|
||||
if (mkPoly.IsDone()) {
|
||||
wires.push_back(mkPoly.Wire());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
TopoDS_Shape shape = Part::FaceMakerCheese::makeFace(wires);
|
||||
if (!shape.IsNull()) {
|
||||
builder.Add(compound, shape);
|
||||
}
|
||||
else {
|
||||
failures.push_back(feaSegm);
|
||||
Base::Console().Warning("Failed to create face from %s\n", feaSegm->Label.getValue());
|
||||
}
|
||||
}
|
||||
catch (Standard_Failure&) {
|
||||
failures.push_back(feaSegm);
|
||||
Base::Console().Error("Fatal failure to create face from %s\n", feaSegm->Label.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (createUnused) {
|
||||
// collect all facets that don't have set the flag TMP0
|
||||
std::vector<unsigned long> unusedFacets;
|
||||
algo.GetFacetsFlag(unusedFacets, MeshCore::MeshFacet::TMP0);
|
||||
|
||||
if (!unusedFacets.empty()) {
|
||||
std::unique_ptr<Mesh::MeshObject> segment(mesh->meshFromSegment(unusedFacets));
|
||||
Mesh::Feature* feaSegm = static_cast<Mesh::Feature*>(group->addObject("Mesh::Feature", "Unused"));
|
||||
Mesh::MeshObject* feaMesh = feaSegm->Mesh.startEditing();
|
||||
feaMesh->swap(*segment);
|
||||
feaSegm->Mesh.finishEditing();
|
||||
}
|
||||
}
|
||||
if (createCompound) {
|
||||
Part::Feature* shapeFea = static_cast<Part::Feature*>(group->addObject("Part::Feature", "Compound"));
|
||||
shapeFea->Shape.setValue(compound);
|
||||
|
||||
// create a sub-group where to move the problematic segments
|
||||
if (!failures.empty()) {
|
||||
App::DocumentObjectGroup* subgroup = static_cast<App::DocumentObjectGroup*>(group->addObject
|
||||
("App::DocumentObjectGroup", "Failed"));
|
||||
failures = group->removeObjects(failures);
|
||||
subgroup->Group.setValues(failures);
|
||||
}
|
||||
}
|
||||
|
||||
document->commitTransaction();
|
||||
}
|
||||
|
||||
void Segmentation::changeEvent(QEvent *e)
|
||||
{
|
||||
if (e->type() == QEvent::LanguageChange) {
|
||||
ui->retranslateUi(this);
|
||||
}
|
||||
QWidget::changeEvent(e);
|
||||
}
|
||||
|
||||
// ---------------------------------------
|
||||
|
||||
/* TRANSLATOR MeshGui::TaskRemoveComponents */
|
||||
|
||||
TaskSegmentation::TaskSegmentation(Mesh::Feature* mesh)
|
||||
{
|
||||
widget = new Segmentation(mesh);
|
||||
taskbox = new Gui::TaskView::TaskBox(
|
||||
QPixmap(), widget->windowTitle(), false, 0);
|
||||
taskbox->groupLayout()->addWidget(widget);
|
||||
Content.push_back(taskbox);
|
||||
}
|
||||
|
||||
TaskSegmentation::~TaskSegmentation()
|
||||
{
|
||||
// automatically deleted in the sub-class
|
||||
}
|
||||
|
||||
bool TaskSegmentation::accept()
|
||||
{
|
||||
widget->accept();
|
||||
return true;
|
||||
}
|
||||
|
||||
#include "moc_Segmentation.cpp"
|
||||
78
src/Mod/ReverseEngineering/Gui/Segmentation.h
Normal file
78
src/Mod/ReverseEngineering/Gui/Segmentation.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2012 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library 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 Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef REVERSEENGINEERINGGUI_SEGMENTATION_H
|
||||
#define REVERSEENGINEERINGGUI_SEGMENTATION_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <Gui/TaskView/TaskDialog.h>
|
||||
#include <Gui/TaskView/TaskView.h>
|
||||
#include <App/DocumentObserver.h>
|
||||
#include <memory>
|
||||
|
||||
// forward declarations
|
||||
namespace Mesh { class Feature; }
|
||||
|
||||
namespace ReverseEngineeringGui {
|
||||
class Ui_Segmentation;
|
||||
|
||||
class Segmentation : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Segmentation(Mesh::Feature* mesh, QWidget* parent = 0, Qt::WindowFlags fl = 0);
|
||||
~Segmentation();
|
||||
void accept();
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent *e);
|
||||
|
||||
private:
|
||||
std::unique_ptr<Ui_Segmentation> ui;
|
||||
App::DocumentObjectWeakPtrT myMesh;
|
||||
};
|
||||
|
||||
/**
|
||||
* Embed the panel into a task dialog.
|
||||
*/
|
||||
class TaskSegmentation : public Gui::TaskView::TaskDialog
|
||||
{
|
||||
public:
|
||||
TaskSegmentation(Mesh::Feature* mesh);
|
||||
~TaskSegmentation();
|
||||
|
||||
public:
|
||||
bool accept();
|
||||
|
||||
virtual QDialogButtonBox::StandardButtons getStandardButtons() const
|
||||
{ return QDialogButtonBox::Ok | QDialogButtonBox::Cancel; }
|
||||
|
||||
private:
|
||||
Segmentation* widget;
|
||||
Gui::TaskView::TaskBox* taskbox;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // REVERSEENGINEERINGGUI_SEGMENTATION_H
|
||||
115
src/Mod/ReverseEngineering/Gui/Segmentation.ui
Normal file
115
src/Mod/ReverseEngineering/Gui/Segmentation.ui
Normal file
@@ -0,0 +1,115 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ReverseEngineeringGui::Segmentation</class>
|
||||
<widget class="QWidget" name="ReverseEngineeringGui::Segmentation">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>343</width>
|
||||
<height>242</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Mesh segmentation</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="1">
|
||||
<widget class="QSpinBox" name="smoothSteps">
|
||||
<property name="value">
|
||||
<number>3</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="createCompound">
|
||||
<property name="text">
|
||||
<string>Create compound</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="checkBoxSmooth">
|
||||
<property name="text">
|
||||
<string>Smooth mesh</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QGroupBox" name="groupBoxPln">
|
||||
<property name="title">
|
||||
<string>Plane</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Curvature tolerance</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QDoubleSpinBox" name="curvTolPln">
|
||||
<property name="singleStep">
|
||||
<double>0.010000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>0.010000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Distance to plane</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QDoubleSpinBox" name="distToPln">
|
||||
<property name="singleStep">
|
||||
<double>0.010000000000000</double>
|
||||
</property>
|
||||
<property name="value">
|
||||
<double>0.010000000000000</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Minimum number of faces</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QSpinBox" name="numPln">
|
||||
<property name="maximum">
|
||||
<number>100000</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>100</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="createUnused">
|
||||
<property name="text">
|
||||
<string>Create mesh from unused triangles</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -50,13 +50,13 @@ Workbench::~Workbench()
|
||||
|
||||
Gui::MenuItem* Workbench::setupMenuBar() const
|
||||
{
|
||||
Gui::MenuItem* root = StdWorkbench::setupMenuBar();
|
||||
Gui::MenuItem* item = root->findItem("&Windows");
|
||||
Gui::MenuItem* reen = new Gui::MenuItem;
|
||||
root->insertItem(item, reen);
|
||||
reen->setCommand("&REEN");
|
||||
*reen << "Reen_ApproxPlane"
|
||||
<< "Reen_ApproxSurface";
|
||||
Gui::MenuItem* root = StdWorkbench::setupMenuBar();
|
||||
Gui::MenuItem* item = root->findItem("&Windows");
|
||||
Gui::MenuItem* reen = new Gui::MenuItem;
|
||||
root->insertItem(item, reen);
|
||||
reen->setCommand("&REEN");
|
||||
*reen << "Reen_ApproxPlane"
|
||||
<< "Reen_ApproxSurface";
|
||||
|
||||
Gui::MenuItem *reconstruct = new Gui::MenuItem();
|
||||
reconstruct->setCommand("Surface reconstruction");
|
||||
@@ -64,7 +64,17 @@ Gui::MenuItem* Workbench::setupMenuBar() const
|
||||
<< "Reen_ViewTriangulation";
|
||||
*reen << reconstruct;
|
||||
|
||||
return root;
|
||||
Gui::MenuItem *segm = new Gui::MenuItem();
|
||||
segm->setCommand("Segmentation");
|
||||
*segm << "Mesh_RemeshGmsh"
|
||||
<< "Mesh_VertexCurvature"
|
||||
<< "Mesh_CurvatureInfo"
|
||||
<< "Separator"
|
||||
<< "Reen_Segmentation"
|
||||
<< "Reen_MeshBoundary";
|
||||
*reen << segm;
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
Gui::ToolBarItem* Workbench::setupToolBars() const
|
||||
|
||||
Reference in New Issue
Block a user