mesh segmentation algorithm for surfaces
This commit is contained in:
@@ -101,6 +101,90 @@ void MeshDistancePlanarSegment::AddFacet(const MeshFacet& face)
|
||||
|
||||
// --------------------------------------------------------
|
||||
|
||||
PlaneSurfaceFit::PlaneSurfaceFit()
|
||||
: fitter(new PlaneFit)
|
||||
{
|
||||
}
|
||||
|
||||
PlaneSurfaceFit::~PlaneSurfaceFit()
|
||||
{
|
||||
delete fitter;
|
||||
}
|
||||
|
||||
void PlaneSurfaceFit::Initialize(const MeshCore::MeshGeomFacet& tria)
|
||||
{
|
||||
fitter->Clear();
|
||||
|
||||
basepoint = tria.GetGravityPoint();
|
||||
normal = tria.GetNormal();
|
||||
fitter->AddPoint(tria._aclPoints[0]);
|
||||
fitter->AddPoint(tria._aclPoints[1]);
|
||||
fitter->AddPoint(tria._aclPoints[2]);
|
||||
}
|
||||
|
||||
void PlaneSurfaceFit::AddTriangle(const MeshCore::MeshGeomFacet& tria)
|
||||
{
|
||||
fitter->AddPoint(tria.GetGravityPoint());
|
||||
}
|
||||
|
||||
bool PlaneSurfaceFit::Done() const
|
||||
{
|
||||
return fitter->Done();
|
||||
}
|
||||
|
||||
float PlaneSurfaceFit::Fit()
|
||||
{
|
||||
return fitter->Fit();
|
||||
}
|
||||
|
||||
float PlaneSurfaceFit::GetDistanceToSurface(const Base::Vector3f& pnt)
|
||||
{
|
||||
return fitter->GetDistanceToPlane(pnt);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------
|
||||
|
||||
MeshDistanceGenericSurfaceSegment::MeshDistanceGenericSurfaceSegment(AbstractSurfaceFit* fit,
|
||||
const MeshKernel& mesh,
|
||||
unsigned long minFacets,
|
||||
float tol)
|
||||
: MeshDistanceSurfaceSegment(mesh, minFacets, tol)
|
||||
, fitter(fit)
|
||||
{
|
||||
}
|
||||
|
||||
MeshDistanceGenericSurfaceSegment::~MeshDistanceGenericSurfaceSegment()
|
||||
{
|
||||
delete fitter;
|
||||
}
|
||||
|
||||
void MeshDistanceGenericSurfaceSegment::Initialize(unsigned long index)
|
||||
{
|
||||
MeshGeomFacet triangle = kernel.GetFacet(index);
|
||||
fitter->Initialize(triangle);
|
||||
}
|
||||
|
||||
bool MeshDistanceGenericSurfaceSegment::TestFacet (const MeshFacet& face) const
|
||||
{
|
||||
if (!fitter->Done())
|
||||
fitter->Fit();
|
||||
MeshGeomFacet triangle = kernel.GetFacet(face);
|
||||
for (int i=0; i<3; i++) {
|
||||
if (fabs(fitter->GetDistanceToSurface(triangle._aclPoints[i])) > tolerance)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MeshDistanceGenericSurfaceSegment::AddFacet(const MeshFacet& face)
|
||||
{
|
||||
MeshGeomFacet triangle = kernel.GetFacet(face);
|
||||
fitter->AddTriangle(triangle);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------
|
||||
|
||||
bool MeshCurvaturePlanarSegment::TestFacet (const MeshFacet &rclFacet) const
|
||||
{
|
||||
for (int i=0; i<3; i++) {
|
||||
|
||||
@@ -82,6 +82,50 @@ protected:
|
||||
PlaneFit* fitter;
|
||||
};
|
||||
|
||||
class MeshExport AbstractSurfaceFit
|
||||
{
|
||||
public:
|
||||
AbstractSurfaceFit(){}
|
||||
virtual ~AbstractSurfaceFit(){}
|
||||
virtual void Initialize(const MeshGeomFacet&) = 0;
|
||||
virtual void AddTriangle(const MeshGeomFacet&) = 0;
|
||||
virtual bool Done() const = 0;
|
||||
virtual float Fit() = 0;
|
||||
virtual float GetDistanceToSurface(const Base::Vector3f&) = 0;
|
||||
};
|
||||
|
||||
class MeshExport PlaneSurfaceFit : public AbstractSurfaceFit
|
||||
{
|
||||
public:
|
||||
PlaneSurfaceFit();
|
||||
~PlaneSurfaceFit();
|
||||
void Initialize(const MeshGeomFacet&);
|
||||
void AddTriangle(const MeshGeomFacet&);
|
||||
bool Done() const;
|
||||
float Fit();
|
||||
float GetDistanceToSurface(const Base::Vector3f&);
|
||||
|
||||
private:
|
||||
Base::Vector3f basepoint;
|
||||
Base::Vector3f normal;
|
||||
PlaneFit* fitter;
|
||||
};
|
||||
|
||||
class MeshExport MeshDistanceGenericSurfaceSegment : public MeshDistanceSurfaceSegment
|
||||
{
|
||||
public:
|
||||
MeshDistanceGenericSurfaceSegment(AbstractSurfaceFit*, const MeshKernel& mesh,
|
||||
unsigned long minFacets, float tol);
|
||||
virtual ~MeshDistanceGenericSurfaceSegment();
|
||||
bool TestFacet (const MeshFacet& rclFacet) const;
|
||||
const char* GetType() const { return "Generic"; }
|
||||
void Initialize(unsigned long);
|
||||
void AddFacet(const MeshFacet& rclFacet);
|
||||
|
||||
protected:
|
||||
AbstractSurfaceFit* fitter;
|
||||
};
|
||||
|
||||
// --------------------------------------------------------
|
||||
|
||||
class MeshExport MeshCurvatureSurfaceSegment : public MeshSurfaceSegment
|
||||
|
||||
@@ -1710,8 +1710,10 @@ std::vector<Segment> MeshObject::getSegmentsFromType(MeshObject::GeometryType ty
|
||||
std::unique_ptr<MeshCore::MeshDistanceSurfaceSegment> surf;
|
||||
switch (type) {
|
||||
case PLANE:
|
||||
surf.reset(new MeshCore::MeshDistancePlanarSegment(this->_kernel, minFacets, dev));
|
||||
break;
|
||||
//surf.reset(new MeshCore::MeshDistancePlanarSegment(this->_kernel, minFacets, dev));
|
||||
surf.reset(new MeshCore::MeshDistanceGenericSurfaceSegment(new MeshCore::PlaneSurfaceFit,
|
||||
this->_kernel, minFacets, dev));
|
||||
break;
|
||||
// todo!
|
||||
case CYLINDER:
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user