Mesh: modernize C++: use range-based for loop

This commit is contained in:
wmayer
2023-08-15 10:55:05 +02:00
committed by wwmayer
parent 2ceb6edfe5
commit 375cb9a0fe
52 changed files with 1293 additions and 1329 deletions

View File

@@ -374,11 +374,11 @@ void MeshObject::save(const char* file, MeshCore::MeshIO::Format f,
// go through the segment list and put them to the exporter when
// the "save" flag is set
std::vector<MeshCore::Group> groups;
for (std::size_t index = 0; index < this->_segments.size(); index++) {
if (this->_segments[index].isSaved()) {
for (const auto & segment : this->_segments) {
if (segment.isSaved()) {
MeshCore::Group g;
g.indices = this->_segments[index].getIndices();
g.name = this->_segments[index].getName();
g.indices = segment.getIndices();
g.name = segment.getName();
groups.push_back(g);
}
}
@@ -403,11 +403,11 @@ void MeshObject::save(std::ostream& str, MeshCore::MeshIO::Format f,
// go through the segment list and put them to the exporter when
// the "save" flag is set
std::vector<MeshCore::Group> groups;
for (std::size_t index = 0; index < this->_segments.size(); index++) {
if (this->_segments[index].isSaved()) {
for (const auto & segment : this->_segments) {
if (segment.isSaved()) {
MeshCore::Group g;
g.indices = this->_segments[index].getIndices();
g.name = this->_segments[index].getName();
g.indices = segment.getIndices();
g.name = segment.getName();
groups.push_back(g);
}
}
@@ -566,18 +566,18 @@ void MeshObject::addFacets(const std::vector<Data::ComplexGeoData::Facet> &facet
{
std::vector<MeshCore::MeshFacet> facet_v;
facet_v.reserve(facets.size());
for (std::vector<Data::ComplexGeoData::Facet>::const_iterator it = facets.begin(); it != facets.end(); ++it) {
for (auto facet : facets) {
MeshCore::MeshFacet f;
f._aulPoints[0] = it->I1;
f._aulPoints[1] = it->I2;
f._aulPoints[2] = it->I3;
f._aulPoints[0] = facet.I1;
f._aulPoints[1] = facet.I2;
f._aulPoints[2] = facet.I3;
facet_v.push_back(f);
}
std::vector<Base::Vector3f> point_v;
point_v.reserve(points.size());
for (std::vector<Base::Vector3d>::const_iterator it = points.begin(); it != points.end(); ++it) {
Base::Vector3f p((float)it->x,(float)it->y,(float)it->z);
for (const auto & point : points) {
Base::Vector3f p((float)point.x,(float)point.y,(float)point.z);
point_v.push_back(p);
}
@@ -594,18 +594,18 @@ void MeshObject::setFacets(const std::vector<Data::ComplexGeoData::Facet> &facet
{
MeshCore::MeshFacetArray facet_v;
facet_v.reserve(facets.size());
for (std::vector<Data::ComplexGeoData::Facet>::const_iterator it = facets.begin(); it != facets.end(); ++it) {
for (auto facet : facets) {
MeshCore::MeshFacet f;
f._aulPoints[0] = it->I1;
f._aulPoints[1] = it->I2;
f._aulPoints[2] = it->I3;
f._aulPoints[0] = facet.I1;
f._aulPoints[1] = facet.I2;
f._aulPoints[2] = facet.I3;
facet_v.push_back(f);
}
MeshCore::MeshPointArray point_v;
point_v.reserve(points.size());
for (std::vector<Base::Vector3d>::const_iterator it = points.begin(); it != points.end(); ++it) {
Base::Vector3f p((float)it->x,(float)it->y,(float)it->z);
for (const auto & point : points) {
Base::Vector3f p((float)point.x,(float)point.y,(float)point.z);
point_v.push_back(p);
}
@@ -646,36 +646,32 @@ void MeshObject::deletedFacets(const std::vector<FacetIndex>& remFacets)
return; // nothing to do
// set an array with the original indices and mark the removed as MeshCore::FACET_INDEX_MAX
std::vector<FacetIndex> f_indices(_kernel.CountFacets()+remFacets.size());
for (std::vector<FacetIndex>::const_iterator it = remFacets.begin();
it != remFacets.end(); ++it) {
f_indices[*it] = MeshCore::FACET_INDEX_MAX;
for (FacetIndex remFacet : remFacets) {
f_indices[remFacet] = MeshCore::FACET_INDEX_MAX;
}
FacetIndex index = 0;
for (std::vector<FacetIndex>::iterator it = f_indices.begin();
it != f_indices.end(); ++it) {
if (*it == 0)
*it = index++;
for (FacetIndex& it : f_indices) {
if (it == 0)
it = index++;
}
// the array serves now as LUT to set the new indices in the segments
for (std::vector<Segment>::iterator it = this->_segments.begin();
it != this->_segments.end(); ++it) {
std::vector<FacetIndex> segm = it->_indices;
for (std::vector<FacetIndex>::iterator jt = segm.begin();
jt != segm.end(); ++jt) {
*jt = f_indices[*jt];
}
for (auto & segment : this->_segments) {
std::vector<FacetIndex> segm = segment._indices;
for (FacetIndex & jt : segm) {
jt = f_indices[jt];
}
// remove the invalid indices
std::sort(segm.begin(), segm.end());
std::vector<FacetIndex>::iterator ft = std::find_if
(segm.begin(), segm.end(), [](FacetIndex v) {
return v == MeshCore::FACET_INDEX_MAX;
});
if (ft != segm.end())
segm.erase(ft, segm.end());
it->_indices = segm;
// remove the invalid indices
std::sort(segm.begin(), segm.end());
std::vector<FacetIndex>::iterator ft = std::find_if
(segm.begin(), segm.end(), [](FacetIndex v) {
return v == MeshCore::FACET_INDEX_MAX;
});
if (ft != segm.end())
segm.erase(ft, segm.end());
segment._indices = segm;
}
}
@@ -830,11 +826,10 @@ void MeshObject::updateMesh() const
MeshCore::MeshAlgorithm alg(_kernel);
alg.ResetFacetFlag(MeshCore::MeshFacet::SEGMENT);
alg.ResetPointFlag(MeshCore::MeshPoint::SEGMENT);
for (std::vector<Segment>::const_iterator it = this->_segments.begin();
it != this->_segments.end(); ++it) {
for (const auto & segment : this->_segments) {
std::vector<PointIndex> points;
points = _kernel.GetFacetPoints(it->getIndices());
alg.SetFacetsFlag(it->getIndices(), MeshCore::MeshFacet::SEGMENT);
points = _kernel.GetFacetPoints(segment.getIndices());
alg.SetFacetsFlag(segment.getIndices(), MeshCore::MeshFacet::SEGMENT);
alg.SetPointsFlag(points, MeshCore::MeshPoint::SEGMENT);
}
}
@@ -869,14 +864,14 @@ unsigned long MeshObject::getPointDegree(const std::vector<FacetIndex>& indices,
const MeshCore::MeshFacetArray& faces = _kernel.GetFacets();
std::vector<PointIndex> pointDeg(_kernel.CountPoints());
for (MeshCore::MeshFacetArray::_TConstIterator it = faces.begin(); it != faces.end(); ++it) {
pointDeg[it->_aulPoints[0]]++;
pointDeg[it->_aulPoints[1]]++;
pointDeg[it->_aulPoints[2]]++;
for (const auto & face : faces) {
pointDeg[face._aulPoints[0]]++;
pointDeg[face._aulPoints[1]]++;
pointDeg[face._aulPoints[2]]++;
}
for (std::vector<PointIndex>::const_iterator it = indices.begin(); it != indices.end(); ++it) {
const MeshCore::MeshFacet& face = faces[*it];
for (FacetIndex it : indices) {
const MeshCore::MeshFacet& face = faces[it];
pointDeg[face._aulPoints[0]]--;
pointDeg[face._aulPoints[1]]--;
pointDeg[face._aulPoints[2]]--;
@@ -955,8 +950,8 @@ void MeshObject::offsetSpecial2(float fSize)
if (fliped.empty())
break;
for( std::set<FacetIndex>::iterator It= fliped.begin();It!=fliped.end();++It)
alg.CollapseFacet(*It);
for(FacetIndex It : fliped)
alg.CollapseFacet(It);
fliped.clear();
}
@@ -1071,9 +1066,9 @@ void MeshObject::crossSections(const std::vector<MeshObject::TPlane>& planes, st
MeshCore::MeshFacetGrid grid(kernel);
MeshCore::MeshAlgorithm algo(kernel);
for (std::vector<MeshObject::TPlane>::const_iterator it = planes.begin(); it != planes.end(); ++it) {
for (const auto & plane : planes) {
MeshObject::TPolylines polylines;
algo.CutWithPlane(it->first, it->second, grid, polylines, fMinEps, bConnectPolygons);
algo.CutWithPlane(plane.first, plane.second, grid, polylines, fMinEps, bConnectPolygons);
sections.push_back(polylines);
}
}
@@ -1339,10 +1334,10 @@ void MeshObject::splitEdges()
MeshCore::MeshFacetIterator cIter(_kernel);
MeshCore::MeshTopoAlgorithm topalg(_kernel);
for (std::vector<std::pair<FacetIndex, FacetIndex> >::iterator it = adjacentFacet.begin(); it != adjacentFacet.end(); ++it) {
cIter.Set(it->first);
for (const auto & it : adjacentFacet) {
cIter.Set(it.first);
Base::Vector3f mid = 0.5f*(cIter->_aclPoints[0]+cIter->_aclPoints[2]);
topalg.SplitEdge(it->first, it->second, mid);
topalg.SplitEdge(it.first, it.second, mid);
}
// clear the segments because we don't know how the new
@@ -1392,8 +1387,8 @@ void MeshObject::collapseFacet(FacetIndex facet)
void MeshObject::collapseFacets(const std::vector<FacetIndex>& facets)
{
MeshCore::MeshTopoAlgorithm alg(_kernel);
for (std::vector<FacetIndex>::const_iterator it = facets.begin(); it != facets.end(); ++it) {
alg.CollapseFacet(*it);
for (FacetIndex it : facets) {
alg.CollapseFacet(it);
}
deletedFacets(facets);
@@ -1932,8 +1927,8 @@ void MeshObject::addSegment(const Segment& s)
void MeshObject::addSegment(const std::vector<FacetIndex>& inds)
{
unsigned long maxIndex = _kernel.CountFacets();
for (std::vector<FacetIndex>::const_iterator it = inds.begin(); it != inds.end(); ++it) {
if (*it >= maxIndex)
for (FacetIndex it : inds) {
if (it >= maxIndex)
throw Base::IndexError("Index out of range");
}
@@ -1956,8 +1951,8 @@ MeshObject* MeshObject::meshFromSegment(const std::vector<FacetIndex>& indices)
facets.reserve(indices.size());
const MeshCore::MeshPointArray& kernel_p = _kernel.GetPoints();
const MeshCore::MeshFacetArray& kernel_f = _kernel.GetFacets();
for (std::vector<FacetIndex>::const_iterator it = indices.begin(); it != indices.end(); ++it) {
facets.push_back(kernel_f[*it]);
for (FacetIndex it : indices) {
facets.push_back(kernel_f[it]);
}
MeshCore::MeshKernel kernel;
@@ -1998,8 +1993,8 @@ std::vector<Segment> MeshObject::getSegmentsOfType(MeshObject::GeometryType type
finder.FindSegments(surfaces);
const std::vector<MeshCore::MeshSegment>& data = surf->GetSegments();
for (std::vector<MeshCore::MeshSegment>::const_iterator it = data.begin(); it != data.end(); ++it) {
segm.emplace_back(this, *it, false);
for (const auto & it : data) {
segm.emplace_back(this, it, false);
}
}