Mesh: modernize C++: use range-based for loop
This commit is contained in:
@@ -261,11 +261,10 @@ void SoSFMeshObject::writeValue(SoOutput *out) const
|
||||
const MeshCore::MeshPointArray& rPoints = value->getKernel().GetPoints();
|
||||
std::vector<float> verts;
|
||||
verts.reserve(3*rPoints.size());
|
||||
for (MeshCore::MeshPointArray::_TConstIterator it = rPoints.begin();
|
||||
it != rPoints.end(); ++it) {
|
||||
verts.push_back(it->x);
|
||||
verts.push_back(it->y);
|
||||
verts.push_back(it->z);
|
||||
for (const auto & rPoint : rPoints) {
|
||||
verts.push_back(rPoint.x);
|
||||
verts.push_back(rPoint.y);
|
||||
verts.push_back(rPoint.z);
|
||||
}
|
||||
|
||||
int32_t countPt = (int32_t)verts.size();
|
||||
@@ -275,11 +274,10 @@ void SoSFMeshObject::writeValue(SoOutput *out) const
|
||||
const MeshCore::MeshFacetArray& rFacets = value->getKernel().GetFacets();
|
||||
std::vector<uint32_t> faces;
|
||||
faces.reserve(3*rFacets.size());
|
||||
for (MeshCore::MeshFacetArray::_TConstIterator it = rFacets.begin();
|
||||
it != rFacets.end(); ++it) {
|
||||
faces.push_back((int32_t)it->_aulPoints[0]);
|
||||
faces.push_back((int32_t)it->_aulPoints[1]);
|
||||
faces.push_back((int32_t)it->_aulPoints[2]);
|
||||
for (const auto & rFacet : rFacets) {
|
||||
faces.push_back((int32_t)rFacet._aulPoints[0]);
|
||||
faces.push_back((int32_t)rFacet._aulPoints[1]);
|
||||
faces.push_back((int32_t)rFacet._aulPoints[2]);
|
||||
}
|
||||
|
||||
int32_t countFt = (int32_t)faces.size();
|
||||
@@ -749,11 +747,11 @@ void SoFCMeshObjectShape::drawFaces(const Mesh::MeshObject * mesh, SoMaterialBun
|
||||
}
|
||||
else {
|
||||
// clockwise ordering
|
||||
for (MeshCore::MeshFacetArray::_TConstIterator it = rFacets.begin(); it != rFacets.end(); ++it)
|
||||
for (const auto & rFacet : rFacets)
|
||||
{
|
||||
const MeshCore::MeshPoint& v0 = rPoints[it->_aulPoints[0]];
|
||||
const MeshCore::MeshPoint& v1 = rPoints[it->_aulPoints[1]];
|
||||
const MeshCore::MeshPoint& v2 = rPoints[it->_aulPoints[2]];
|
||||
const MeshCore::MeshPoint& v0 = rPoints[rFacet._aulPoints[0]];
|
||||
const MeshCore::MeshPoint& v1 = rPoints[rFacet._aulPoints[1]];
|
||||
const MeshCore::MeshPoint& v2 = rPoints[rFacet._aulPoints[2]];
|
||||
|
||||
// Calculate the normal n = -(v1-v0)x(v2-v0)
|
||||
float n[3];
|
||||
@@ -771,11 +769,11 @@ void SoFCMeshObjectShape::drawFaces(const Mesh::MeshObject * mesh, SoMaterialBun
|
||||
}
|
||||
else {
|
||||
glBegin(GL_TRIANGLES);
|
||||
for (MeshCore::MeshFacetArray::_TConstIterator it = rFacets.begin(); it != rFacets.end(); ++it)
|
||||
for (const auto & rFacet : rFacets)
|
||||
{
|
||||
glVertex(rPoints[it->_aulPoints[0]]);
|
||||
glVertex(rPoints[it->_aulPoints[1]]);
|
||||
glVertex(rPoints[it->_aulPoints[2]]);
|
||||
glVertex(rPoints[rFacet._aulPoints[0]]);
|
||||
glVertex(rPoints[rFacet._aulPoints[1]]);
|
||||
glVertex(rPoints[rFacet._aulPoints[2]]);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
@@ -887,13 +885,13 @@ void SoFCMeshObjectShape::generateGLArrays(SoState * state)
|
||||
face_indices.resize(3 * cF.size());
|
||||
|
||||
int indexed = 0;
|
||||
for (MeshCore::MeshFacetArray::const_iterator it = cF.begin(); it != cF.end(); ++it) {
|
||||
Base::Vector3f n = kernel.GetFacet(*it).GetNormal();
|
||||
for (int i=0; i<3; i++) {
|
||||
for (const auto & it : cF) {
|
||||
Base::Vector3f n = kernel.GetFacet(it).GetNormal();
|
||||
for (Mesh::PointIndex ptIndex : it._aulPoints) {
|
||||
face_vertices.push_back(n.x);
|
||||
face_vertices.push_back(n.y);
|
||||
face_vertices.push_back(n.z);
|
||||
const Base::Vector3f& v = cP[it->_aulPoints[i]];
|
||||
const Base::Vector3f& v = cP[ptIndex];
|
||||
face_vertices.push_back(v.x);
|
||||
face_vertices.push_back(v.y);
|
||||
face_vertices.push_back(v.z);
|
||||
@@ -1093,11 +1091,11 @@ void SoFCMeshObjectShape::generatePrimitives(SoAction* action)
|
||||
beginShape(action, TRIANGLES, &faceDetail);
|
||||
try
|
||||
{
|
||||
for (MeshCore::MeshFacetArray::_TConstIterator it = rFacets.begin(); it != rFacets.end(); ++it)
|
||||
for (const auto & rFacet : rFacets)
|
||||
{
|
||||
const MeshCore::MeshPoint& v0 = rPoints[it->_aulPoints[0]];
|
||||
const MeshCore::MeshPoint& v1 = rPoints[it->_aulPoints[1]];
|
||||
const MeshCore::MeshPoint& v2 = rPoints[it->_aulPoints[2]];
|
||||
const MeshCore::MeshPoint& v0 = rPoints[rFacet._aulPoints[0]];
|
||||
const MeshCore::MeshPoint& v1 = rPoints[rFacet._aulPoints[1]];
|
||||
const MeshCore::MeshPoint& v2 = rPoints[rFacet._aulPoints[2]];
|
||||
|
||||
// Calculate the normal n = (v1-v0)x(v2-v0)
|
||||
SbVec3f n;
|
||||
@@ -1110,28 +1108,28 @@ void SoFCMeshObjectShape::generatePrimitives(SoAction* action)
|
||||
|
||||
// Vertex 0
|
||||
if (mbind == PER_VERTEX_INDEXED || mbind == PER_FACE_INDEXED) {
|
||||
pointDetail.setMaterialIndex(it->_aulPoints[0]);
|
||||
vertex.setMaterialIndex(it->_aulPoints[0]);
|
||||
pointDetail.setMaterialIndex(rFacet._aulPoints[0]);
|
||||
vertex.setMaterialIndex(rFacet._aulPoints[0]);
|
||||
}
|
||||
pointDetail.setCoordinateIndex(it->_aulPoints[0]);
|
||||
pointDetail.setCoordinateIndex(rFacet._aulPoints[0]);
|
||||
vertex.setPoint(sbvec3f(v0));
|
||||
shapeVertex(&vertex);
|
||||
|
||||
// Vertex 1
|
||||
if (mbind == PER_VERTEX_INDEXED || mbind == PER_FACE_INDEXED) {
|
||||
pointDetail.setMaterialIndex(it->_aulPoints[1]);
|
||||
vertex.setMaterialIndex(it->_aulPoints[1]);
|
||||
pointDetail.setMaterialIndex(rFacet._aulPoints[1]);
|
||||
vertex.setMaterialIndex(rFacet._aulPoints[1]);
|
||||
}
|
||||
pointDetail.setCoordinateIndex(it->_aulPoints[1]);
|
||||
pointDetail.setCoordinateIndex(rFacet._aulPoints[1]);
|
||||
vertex.setPoint(sbvec3f(v1));
|
||||
shapeVertex(&vertex);
|
||||
|
||||
// Vertex 2
|
||||
if (mbind == PER_VERTEX_INDEXED || mbind == PER_FACE_INDEXED) {
|
||||
pointDetail.setMaterialIndex(it->_aulPoints[2]);
|
||||
vertex.setMaterialIndex(it->_aulPoints[2]);
|
||||
pointDetail.setMaterialIndex(rFacet._aulPoints[2]);
|
||||
vertex.setMaterialIndex(rFacet._aulPoints[2]);
|
||||
}
|
||||
pointDetail.setCoordinateIndex(it->_aulPoints[2]);
|
||||
pointDetail.setCoordinateIndex(rFacet._aulPoints[2]);
|
||||
vertex.setPoint(sbvec3f(v2));
|
||||
shapeVertex(&vertex);
|
||||
|
||||
@@ -1314,9 +1312,9 @@ void SoFCMeshSegmentShape::drawFaces(const Mesh::MeshObject * mesh, SoMaterialBu
|
||||
glBegin(GL_TRIANGLES);
|
||||
if (ccw) {
|
||||
// counterclockwise ordering
|
||||
for (std::vector<Mesh::FacetIndex>::const_iterator it = rSegm.begin(); it != rSegm.end(); ++it)
|
||||
for (Mesh::FacetIndex it : rSegm)
|
||||
{
|
||||
const MeshCore::MeshFacet& f = rFacets[*it];
|
||||
const MeshCore::MeshFacet& f = rFacets[it];
|
||||
const MeshCore::MeshPoint& v0 = rPoints[f._aulPoints[0]];
|
||||
const MeshCore::MeshPoint& v1 = rPoints[f._aulPoints[1]];
|
||||
const MeshCore::MeshPoint& v2 = rPoints[f._aulPoints[2]];
|
||||
@@ -1328,7 +1326,7 @@ void SoFCMeshSegmentShape::drawFaces(const Mesh::MeshObject * mesh, SoMaterialBu
|
||||
n[2] = (v1.x-v0.x)*(v2.y-v0.y)-(v1.y-v0.y)*(v2.x-v0.x);
|
||||
|
||||
if(perFace)
|
||||
mb->send(*it, true);
|
||||
mb->send(it, true);
|
||||
glNormal(n);
|
||||
if(perVertex)
|
||||
mb->send(f._aulPoints[0], true);
|
||||
@@ -1343,9 +1341,9 @@ void SoFCMeshSegmentShape::drawFaces(const Mesh::MeshObject * mesh, SoMaterialBu
|
||||
}
|
||||
else {
|
||||
// clockwise ordering
|
||||
for (std::vector<Mesh::FacetIndex>::const_iterator it = rSegm.begin(); it != rSegm.end(); ++it)
|
||||
for (Mesh::FacetIndex it : rSegm)
|
||||
{
|
||||
const MeshCore::MeshFacet& f = rFacets[*it];
|
||||
const MeshCore::MeshFacet& f = rFacets[it];
|
||||
const MeshCore::MeshPoint& v0 = rPoints[f._aulPoints[0]];
|
||||
const MeshCore::MeshPoint& v1 = rPoints[f._aulPoints[1]];
|
||||
const MeshCore::MeshPoint& v2 = rPoints[f._aulPoints[2]];
|
||||
@@ -1366,9 +1364,9 @@ void SoFCMeshSegmentShape::drawFaces(const Mesh::MeshObject * mesh, SoMaterialBu
|
||||
}
|
||||
else {
|
||||
glBegin(GL_TRIANGLES);
|
||||
for (std::vector<Mesh::FacetIndex>::const_iterator it = rSegm.begin(); it != rSegm.end(); ++it)
|
||||
for (Mesh::FacetIndex it : rSegm)
|
||||
{
|
||||
const MeshCore::MeshFacet& f = rFacets[*it];
|
||||
const MeshCore::MeshFacet& f = rFacets[it];
|
||||
glVertex(rPoints[f._aulPoints[0]]);
|
||||
glVertex(rPoints[f._aulPoints[1]]);
|
||||
glVertex(rPoints[f._aulPoints[2]]);
|
||||
@@ -1506,9 +1504,9 @@ void SoFCMeshSegmentShape::generatePrimitives(SoAction* action)
|
||||
beginShape(action, TRIANGLES, &faceDetail);
|
||||
try
|
||||
{
|
||||
for (std::vector<Mesh::FacetIndex>::const_iterator it = rSegm.begin(); it != rSegm.end(); ++it)
|
||||
for (Mesh::FacetIndex it : rSegm)
|
||||
{
|
||||
const MeshCore::MeshFacet& f = rFacets[*it];
|
||||
const MeshCore::MeshFacet& f = rFacets[it];
|
||||
const MeshCore::MeshPoint& v0 = rPoints[f._aulPoints[0]];
|
||||
const MeshCore::MeshPoint& v1 = rPoints[f._aulPoints[1]];
|
||||
const MeshCore::MeshPoint& v2 = rPoints[f._aulPoints[2]];
|
||||
@@ -1578,12 +1576,11 @@ void SoFCMeshSegmentShape::computeBBox(SoAction *action, SbBox3f &box, SbVec3f &
|
||||
const MeshCore::MeshPointArray& rPoint = mesh->getKernel().GetPoints();
|
||||
const MeshCore::MeshFacetArray& rFaces = mesh->getKernel().GetFacets();
|
||||
|
||||
for (std::vector<Mesh::FacetIndex>::const_iterator it = indices.begin();
|
||||
it != indices.end(); ++it) {
|
||||
const MeshCore::MeshFacet& face = rFaces[*it];
|
||||
cBox.Add(rPoint[face._aulPoints[0]]);
|
||||
cBox.Add(rPoint[face._aulPoints[1]]);
|
||||
cBox.Add(rPoint[face._aulPoints[2]]);
|
||||
for (Mesh::FacetIndex index : indices) {
|
||||
const MeshCore::MeshFacet& face = rFaces[index];
|
||||
cBox.Add(rPoint[face._aulPoints[0]]);
|
||||
cBox.Add(rPoint[face._aulPoints[1]]);
|
||||
cBox.Add(rPoint[face._aulPoints[2]]);
|
||||
}
|
||||
|
||||
box.setBounds(SbVec3f(cBox.MinX,cBox.MinY,cBox.MinZ),
|
||||
@@ -1660,11 +1657,11 @@ void SoFCMeshObjectBoundary::drawLines(const Mesh::MeshObject * mesh) const
|
||||
// Use the data structure directly and not through MeshFacetIterator as this
|
||||
// class is quite slowly (at least for rendering)
|
||||
glBegin(GL_LINES);
|
||||
for (MeshCore::MeshFacetArray::_TConstIterator it = rFacets.begin(); it != rFacets.end(); ++it) {
|
||||
for (const auto & rFacet : rFacets) {
|
||||
for (int i=0; i<3; i++) {
|
||||
if (it->_aulNeighbours[i] == MeshCore::FACET_INDEX_MAX) {
|
||||
glVertex(rPoints[it->_aulPoints[i]]);
|
||||
glVertex(rPoints[it->_aulPoints[(i+1)%3]]);
|
||||
if (rFacet._aulNeighbours[i] == MeshCore::FACET_INDEX_MAX) {
|
||||
glVertex(rPoints[rFacet._aulPoints[i]]);
|
||||
glVertex(rPoints[rFacet._aulPoints[(i+1)%3]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1691,20 +1688,20 @@ void SoFCMeshObjectBoundary::generatePrimitives(SoAction* action)
|
||||
vertex.setDetail(&pointDetail);
|
||||
|
||||
beginShape(action, LINES, &lineDetail);
|
||||
for (MeshCore::MeshFacetArray::_TConstIterator it = rFacets.begin(); it != rFacets.end(); ++it)
|
||||
for (const auto & rFacet : rFacets)
|
||||
{
|
||||
for (int i=0; i<3; i++) {
|
||||
if (it->_aulNeighbours[i] == MeshCore::FACET_INDEX_MAX) {
|
||||
const MeshCore::MeshPoint& v0 = rPoints[it->_aulPoints[i]];
|
||||
const MeshCore::MeshPoint& v1 = rPoints[it->_aulPoints[(i+1)%3]];
|
||||
if (rFacet._aulNeighbours[i] == MeshCore::FACET_INDEX_MAX) {
|
||||
const MeshCore::MeshPoint& v0 = rPoints[rFacet._aulPoints[i]];
|
||||
const MeshCore::MeshPoint& v1 = rPoints[rFacet._aulPoints[(i+1)%3]];
|
||||
|
||||
// Vertex 0
|
||||
pointDetail.setCoordinateIndex(it->_aulPoints[i]);
|
||||
pointDetail.setCoordinateIndex(rFacet._aulPoints[i]);
|
||||
vertex.setPoint(sbvec3f(v0));
|
||||
shapeVertex(&vertex);
|
||||
|
||||
// Vertex 1
|
||||
pointDetail.setCoordinateIndex(it->_aulPoints[(i+1)%3]);
|
||||
pointDetail.setCoordinateIndex(rFacet._aulPoints[(i+1)%3]);
|
||||
vertex.setPoint(sbvec3f(v1));
|
||||
shapeVertex(&vertex);
|
||||
|
||||
@@ -1729,8 +1726,8 @@ void SoFCMeshObjectBoundary::computeBBox(SoAction *action, SbBox3f &box, SbVec3f
|
||||
const MeshCore::MeshPointArray & rPoints = mesh->getKernel().GetPoints();
|
||||
if (!rPoints.empty()) {
|
||||
Base::BoundBox3f cBox;
|
||||
for (MeshCore::MeshPointArray::_TConstIterator it = rPoints.begin(); it != rPoints.end(); ++it)
|
||||
cBox.Add(*it);
|
||||
for (const auto & rPoint : rPoints)
|
||||
cBox.Add(rPoint);
|
||||
box.setBounds(SbVec3f(cBox.MinX,cBox.MinY,cBox.MinZ),
|
||||
SbVec3f(cBox.MaxX,cBox.MaxY,cBox.MaxZ));
|
||||
Base::Vector3f mid = cBox.GetCenter();
|
||||
@@ -1757,9 +1754,9 @@ void SoFCMeshObjectBoundary::getPrimitiveCount(SoGetPrimitiveCountAction * actio
|
||||
|
||||
// Count number of open edges first
|
||||
int ctEdges=0;
|
||||
for (MeshCore::MeshFacetArray::_TConstIterator jt = rFaces.begin(); jt != rFaces.end(); ++jt) {
|
||||
for (int i=0; i<3; i++) {
|
||||
if (jt->_aulNeighbours[i] == MeshCore::FACET_INDEX_MAX) {
|
||||
for (const auto & rFace : rFaces) {
|
||||
for (Mesh::FacetIndex nbIndex : rFace._aulNeighbours) {
|
||||
if (nbIndex == MeshCore::FACET_INDEX_MAX) {
|
||||
ctEdges++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user