mesh segmentation algorithm for surfaces
This commit is contained in:
@@ -773,6 +773,15 @@ std::vector<unsigned long> MeshKernel::HasFacets (const MeshPointIterator &rclIt
|
||||
return aulBelongs;
|
||||
}
|
||||
|
||||
MeshPointArray MeshKernel::GetPoints(const std::vector<unsigned long>& indices) const
|
||||
{
|
||||
MeshPointArray ary;
|
||||
ary.reserve(indices.size());
|
||||
for (std::vector<unsigned long>::const_iterator it = indices.begin(); it != indices.end(); ++it)
|
||||
ary.push_back(this->_aclPointArray[*it]);
|
||||
return ary;
|
||||
}
|
||||
|
||||
MeshFacetArray MeshKernel::GetFacets(const std::vector<unsigned long>& indices) const
|
||||
{
|
||||
MeshFacetArray ary;
|
||||
|
||||
@@ -140,6 +140,10 @@ public:
|
||||
|
||||
/** Returns the array of all data points. */
|
||||
const MeshPointArray& GetPoints (void) const { return _aclPointArray; }
|
||||
/** Returns an array of points to the given indices. The indices
|
||||
* must not be out of range.
|
||||
*/
|
||||
MeshPointArray GetPoints(const std::vector<unsigned long>&) const;
|
||||
|
||||
/** Returns a modifier for the point array */
|
||||
MeshPointModifier ModifyPoints()
|
||||
|
||||
@@ -111,6 +111,13 @@ PlaneSurfaceFit::PlaneSurfaceFit()
|
||||
{
|
||||
}
|
||||
|
||||
PlaneSurfaceFit::PlaneSurfaceFit(const Base::Vector3f& b, const Base::Vector3f& n)
|
||||
: basepoint(b)
|
||||
, normal(n)
|
||||
, fitter(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
PlaneSurfaceFit::~PlaneSurfaceFit()
|
||||
{
|
||||
delete fitter;
|
||||
@@ -118,13 +125,15 @@ PlaneSurfaceFit::~PlaneSurfaceFit()
|
||||
|
||||
void PlaneSurfaceFit::Initialize(const MeshCore::MeshGeomFacet& tria)
|
||||
{
|
||||
fitter->Clear();
|
||||
if (fitter) {
|
||||
fitter->Clear();
|
||||
|
||||
basepoint = tria.GetGravityPoint();
|
||||
normal = tria.GetNormal();
|
||||
fitter->AddPoint(tria._aclPoints[0]);
|
||||
fitter->AddPoint(tria._aclPoints[1]);
|
||||
fitter->AddPoint(tria._aclPoints[2]);
|
||||
basepoint = tria.GetGravityPoint();
|
||||
normal = tria.GetNormal();
|
||||
fitter->AddPoint(tria._aclPoints[0]);
|
||||
fitter->AddPoint(tria._aclPoints[1]);
|
||||
fitter->AddPoint(tria._aclPoints[2]);
|
||||
}
|
||||
}
|
||||
|
||||
bool PlaneSurfaceFit::TestTriangle(const MeshGeomFacet&) const
|
||||
@@ -134,22 +143,32 @@ bool PlaneSurfaceFit::TestTriangle(const MeshGeomFacet&) const
|
||||
|
||||
void PlaneSurfaceFit::AddTriangle(const MeshCore::MeshGeomFacet& tria)
|
||||
{
|
||||
fitter->AddPoint(tria.GetGravityPoint());
|
||||
if (fitter)
|
||||
fitter->AddPoint(tria.GetGravityPoint());
|
||||
}
|
||||
|
||||
bool PlaneSurfaceFit::Done() const
|
||||
{
|
||||
return fitter->Done();
|
||||
if (!fitter)
|
||||
return true;
|
||||
else
|
||||
return fitter->Done();
|
||||
}
|
||||
|
||||
float PlaneSurfaceFit::Fit()
|
||||
{
|
||||
return fitter->Fit();
|
||||
if (!fitter)
|
||||
return 0;
|
||||
else
|
||||
return fitter->Fit();
|
||||
}
|
||||
|
||||
float PlaneSurfaceFit::GetDistanceToSurface(const Base::Vector3f& pnt) const
|
||||
{
|
||||
return fitter->GetDistanceToPlane(pnt);
|
||||
if (!fitter)
|
||||
return pnt.DistanceToPlane(basepoint, normal);
|
||||
else
|
||||
return fitter->GetDistanceToPlane(pnt);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------
|
||||
@@ -291,27 +310,27 @@ float SphereSurfaceFit::GetDistanceToSurface(const Base::Vector3f& pnt) const
|
||||
|
||||
// --------------------------------------------------------
|
||||
|
||||
MeshDistanceGenericSurfaceSegment::MeshDistanceGenericSurfaceSegment(AbstractSurfaceFit* fit,
|
||||
const MeshKernel& mesh,
|
||||
unsigned long minFacets,
|
||||
float tol)
|
||||
MeshDistanceGenericSurfaceFitSegment::MeshDistanceGenericSurfaceFitSegment(AbstractSurfaceFit* fit,
|
||||
const MeshKernel& mesh,
|
||||
unsigned long minFacets,
|
||||
float tol)
|
||||
: MeshDistanceSurfaceSegment(mesh, minFacets, tol)
|
||||
, fitter(fit)
|
||||
{
|
||||
}
|
||||
|
||||
MeshDistanceGenericSurfaceSegment::~MeshDistanceGenericSurfaceSegment()
|
||||
MeshDistanceGenericSurfaceFitSegment::~MeshDistanceGenericSurfaceFitSegment()
|
||||
{
|
||||
delete fitter;
|
||||
}
|
||||
|
||||
void MeshDistanceGenericSurfaceSegment::Initialize(unsigned long index)
|
||||
void MeshDistanceGenericSurfaceFitSegment::Initialize(unsigned long index)
|
||||
{
|
||||
MeshGeomFacet triangle = kernel.GetFacet(index);
|
||||
fitter->Initialize(triangle);
|
||||
}
|
||||
|
||||
bool MeshDistanceGenericSurfaceSegment::TestInitialFacet(unsigned long index) const
|
||||
bool MeshDistanceGenericSurfaceFitSegment::TestInitialFacet(unsigned long index) const
|
||||
{
|
||||
MeshGeomFacet triangle = kernel.GetFacet(index);
|
||||
for (int i=0; i<3; i++) {
|
||||
@@ -321,7 +340,7 @@ bool MeshDistanceGenericSurfaceSegment::TestInitialFacet(unsigned long index) co
|
||||
return fitter->TestTriangle(triangle);
|
||||
}
|
||||
|
||||
bool MeshDistanceGenericSurfaceSegment::TestFacet (const MeshFacet& face) const
|
||||
bool MeshDistanceGenericSurfaceFitSegment::TestFacet (const MeshFacet& face) const
|
||||
{
|
||||
if (!fitter->Done())
|
||||
fitter->Fit();
|
||||
@@ -334,7 +353,7 @@ bool MeshDistanceGenericSurfaceSegment::TestFacet (const MeshFacet& face) const
|
||||
return fitter->TestTriangle(triangle);
|
||||
}
|
||||
|
||||
void MeshDistanceGenericSurfaceSegment::AddFacet(const MeshFacet& face)
|
||||
void MeshDistanceGenericSurfaceFitSegment::AddFacet(const MeshFacet& face)
|
||||
{
|
||||
MeshGeomFacet triangle = kernel.GetFacet(face);
|
||||
fitter->AddTriangle(triangle);
|
||||
|
||||
@@ -101,6 +101,7 @@ class MeshExport PlaneSurfaceFit : public AbstractSurfaceFit
|
||||
{
|
||||
public:
|
||||
PlaneSurfaceFit();
|
||||
PlaneSurfaceFit(const Base::Vector3f& b, const Base::Vector3f& n);
|
||||
~PlaneSurfaceFit();
|
||||
void Initialize(const MeshGeomFacet&);
|
||||
bool TestTriangle(const MeshGeomFacet&) const;
|
||||
@@ -153,14 +154,14 @@ private:
|
||||
float radius;
|
||||
};
|
||||
|
||||
class MeshExport MeshDistanceGenericSurfaceSegment : public MeshDistanceSurfaceSegment
|
||||
class MeshExport MeshDistanceGenericSurfaceFitSegment : public MeshDistanceSurfaceSegment
|
||||
{
|
||||
public:
|
||||
MeshDistanceGenericSurfaceSegment(AbstractSurfaceFit*, const MeshKernel& mesh,
|
||||
unsigned long minFacets, float tol);
|
||||
virtual ~MeshDistanceGenericSurfaceSegment();
|
||||
MeshDistanceGenericSurfaceFitSegment(AbstractSurfaceFit*, const MeshKernel& mesh,
|
||||
unsigned long minFacets, float tol);
|
||||
virtual ~MeshDistanceGenericSurfaceFitSegment();
|
||||
bool TestFacet (const MeshFacet& rclFacet) const;
|
||||
const char* GetType() const { return "Generic"; }
|
||||
const char* GetType() const { return "GenericSurfaceFit"; }
|
||||
void Initialize(unsigned long);
|
||||
bool TestInitialFacet(unsigned long) const;
|
||||
void AddFacet(const MeshFacet& rclFacet);
|
||||
|
||||
@@ -1711,15 +1711,15 @@ std::vector<Segment> MeshObject::getSegmentsOfType(MeshObject::GeometryType type
|
||||
switch (type) {
|
||||
case PLANE:
|
||||
//surf.reset(new MeshCore::MeshDistancePlanarSegment(this->_kernel, minFacets, dev));
|
||||
surf.reset(new MeshCore::MeshDistanceGenericSurfaceSegment(new MeshCore::PlaneSurfaceFit,
|
||||
surf.reset(new MeshCore::MeshDistanceGenericSurfaceFitSegment(new MeshCore::PlaneSurfaceFit,
|
||||
this->_kernel, minFacets, dev));
|
||||
break;
|
||||
case CYLINDER:
|
||||
surf.reset(new MeshCore::MeshDistanceGenericSurfaceSegment(new MeshCore::CylinderSurfaceFit,
|
||||
surf.reset(new MeshCore::MeshDistanceGenericSurfaceFitSegment(new MeshCore::CylinderSurfaceFit,
|
||||
this->_kernel, minFacets, dev));
|
||||
break;
|
||||
case SPHERE:
|
||||
surf.reset(new MeshCore::MeshDistanceGenericSurfaceSegment(new MeshCore::SphereSurfaceFit,
|
||||
surf.reset(new MeshCore::MeshDistanceGenericSurfaceFitSegment(new MeshCore::SphereSurfaceFit,
|
||||
this->_kernel, minFacets, dev));
|
||||
break;
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user