Mesh: add overloaded mesh decimation to set target number of triangles
This commit is contained in:
@@ -95,3 +95,52 @@ void MeshSimplify::simplify(float tolerance, float reduction)
|
||||
|
||||
myKernel.Adopt(new_points, new_facets, true);
|
||||
}
|
||||
|
||||
void MeshSimplify::simplify(int targetSize)
|
||||
{
|
||||
Simplify alg;
|
||||
|
||||
const MeshPointArray& points = myKernel.GetPoints();
|
||||
for (std::size_t i = 0; i < points.size(); i++) {
|
||||
Simplify::Vertex v;
|
||||
v.p = points[i];
|
||||
alg.vertices.push_back(v);
|
||||
}
|
||||
|
||||
const MeshFacetArray& facets = myKernel.GetFacets();
|
||||
for (std::size_t i = 0; i < facets.size(); i++) {
|
||||
Simplify::Triangle t;
|
||||
for (int j = 0; j < 3; j++)
|
||||
t.v[j] = facets[i]._aulPoints[j];
|
||||
alg.triangles.push_back(t);
|
||||
}
|
||||
|
||||
// Simplification starts
|
||||
alg.simplify_mesh(targetSize, FLT_MAX);
|
||||
|
||||
// Simplification done
|
||||
MeshPointArray new_points;
|
||||
new_points.reserve(alg.vertices.size());
|
||||
for (std::size_t i = 0; i < alg.vertices.size(); i++) {
|
||||
new_points.push_back(alg.vertices[i].p);
|
||||
}
|
||||
|
||||
std::size_t numFacets = 0;
|
||||
for (std::size_t i = 0; i < alg.triangles.size(); i++) {
|
||||
if (!alg.triangles[i].deleted)
|
||||
numFacets++;
|
||||
}
|
||||
MeshFacetArray new_facets;
|
||||
new_facets.reserve(numFacets);
|
||||
for (std::size_t i = 0; i < alg.triangles.size(); i++) {
|
||||
if (!alg.triangles[i].deleted) {
|
||||
MeshFacet face;
|
||||
face._aulPoints[0] = alg.triangles[i].v[0];
|
||||
face._aulPoints[1] = alg.triangles[i].v[1];
|
||||
face._aulPoints[2] = alg.triangles[i].v[2];
|
||||
new_facets.push_back(face);
|
||||
}
|
||||
}
|
||||
|
||||
myKernel.Adopt(new_points, new_facets, true);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ public:
|
||||
MeshSimplify(MeshKernel&);
|
||||
~MeshSimplify();
|
||||
void simplify(float tolerance, float reduction);
|
||||
void simplify(int targetSize);
|
||||
|
||||
private:
|
||||
MeshKernel& myKernel;
|
||||
|
||||
@@ -989,6 +989,12 @@ void MeshObject::decimate(float fTolerance, float fReduction)
|
||||
dm.simplify(fTolerance, fReduction);
|
||||
}
|
||||
|
||||
void MeshObject::decimate(int targetSize)
|
||||
{
|
||||
MeshCore::MeshSimplify dm(this->_kernel);
|
||||
dm.simplify(targetSize);
|
||||
}
|
||||
|
||||
Base::Vector3d MeshObject::getPointNormal(unsigned long index) const
|
||||
{
|
||||
std::vector<Base::Vector3f> temp = _kernel.CalcVertexNormals();
|
||||
|
||||
@@ -217,6 +217,7 @@ public:
|
||||
void setPoint(unsigned long, const Base::Vector3d& v);
|
||||
void smooth(int iterations, float d_max);
|
||||
void decimate(float fTolerance, float fReduction);
|
||||
void decimate(int targetSize);
|
||||
Base::Vector3d getPointNormal(unsigned long) const;
|
||||
std::vector<Base::Vector3d> getPointNormals() const;
|
||||
void crossSections(const std::vector<TPlane>&, std::vector<TPolylines> §ions,
|
||||
|
||||
Reference in New Issue
Block a user