Mesh segmentation

This commit is contained in:
wmayer 2012-05-21 15:53:46 +02:00 committed by logari81
parent d6b6f6b379
commit 87f1e93fea
2 changed files with 23 additions and 1 deletions

View File

@ -41,6 +41,7 @@ public:
: minFacets(minFacets) {}
virtual ~MeshSurfaceSegment() {}
virtual bool TestFacet (const MeshFacet &rclFacet) const = 0;
virtual const char* GetType() const = 0;
virtual void Initialize(unsigned long);
virtual void AddFacet(const MeshFacet& rclFacet);
void AddSegment(const std::vector<unsigned long>&);
@ -70,6 +71,7 @@ public:
MeshDistancePlanarSegment(const MeshKernel& mesh, unsigned long minFacets, float tol);
virtual ~MeshDistancePlanarSegment();
bool TestFacet (const MeshFacet& rclFacet) const;
const char* GetType() const { return "Plane"; }
void Initialize(unsigned long);
void AddFacet(const MeshFacet& rclFacet);
@ -97,6 +99,7 @@ public:
MeshCurvaturePlanarSegment(const std::vector<CurvatureInfo>& ci, unsigned long minFacets, float tol)
: MeshCurvatureSurfaceSegment(ci, minFacets), tolerance(tol) {}
virtual bool TestFacet (const MeshFacet &rclFacet) const;
virtual const char* GetType() const { return "Plane"; }
private:
float tolerance;
@ -109,6 +112,7 @@ public:
float tolMin, float tolMax, float radius)
: MeshCurvatureSurfaceSegment(ci, minFacets), toleranceMin(tolMin), toleranceMax(tolMax) { curvature = 1/radius;}
virtual bool TestFacet (const MeshFacet &rclFacet) const;
virtual const char* GetType() const { return "Cylinder"; }
private:
float curvature;
@ -122,6 +126,7 @@ public:
MeshCurvatureSphericalSegment(const std::vector<CurvatureInfo>& ci, unsigned long minFacets, float tol, float radius)
: MeshCurvatureSurfaceSegment(ci, minFacets), tolerance(tol) { curvature = 1/radius;}
virtual bool TestFacet (const MeshFacet &rclFacet) const;
virtual const char* GetType() const { return "Sphere"; }
private:
float curvature;
@ -136,6 +141,7 @@ public:
: MeshCurvatureSurfaceSegment(ci, minFacets), c1(c1), c2(c2),
toleranceMin(tolMin), toleranceMax(tolMax) {}
virtual bool TestFacet (const MeshFacet &rclFacet) const;
virtual const char* GetType() const { return "Freeform"; }
private:
float c1, c2;

View File

@ -24,12 +24,14 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <sstream>
#endif
#include "Segmentation.h"
#include "ui_Segmentation.h"
#include <App/Application.h>
#include <App/Document.h>
#include <App/DocumentObjectGroup.h>
#include <Mod/Mesh/App/Core/Segmentation.h>
#include <Mod/Mesh/App/Core/Curvature.h>
@ -89,18 +91,32 @@ void Segmentation::accept()
finder.FindSegments(segm);
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);
for (std::vector<MeshCore::MeshSurfaceSegment*>::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) {
Mesh::MeshObject* segment = mesh->meshFromSegment(*jt);
Mesh::Feature* feaSegm = static_cast<Mesh::Feature*>(document->addObject("Mesh::Feature", "Segment"));
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());
}
delete (*it);
}
document->commitTransaction();
}
void Segmentation::changeEvent(QEvent *e)