Commit ff79e4d2 authored by Andrew Zonenberg's avatar Andrew Zonenberg Committed by Maciej Suminski

3D viewer: Parallelized 3D model vertex normal calculations to use all...

3D viewer: Parallelized 3D model vertex normal calculations to use all available CPU cores for significant speedup.
parents b6495787 48c9a646
......@@ -31,6 +31,10 @@
#include <3d_mesh_model.h>
#include <boost/geometry/algorithms/area.hpp>
#ifdef USE_OPENMP
#include <omp.h>
#endif /* USE_OPENMP */
S3D_MESH::S3D_MESH()
{
isPerFaceNormalsComputed = false;
......@@ -355,13 +359,18 @@ void S3D_MESH::calcPerPointNormals ()
m_PerFaceVertexNormals.clear();
// Pre-allocate space for the entire vector of vertex normals so we can do parallel writes
m_PerFaceVertexNormals.resize( m_CoordIndex.size() );
// for each face A in mesh
#ifdef USE_OPENMP
#pragma omp parallel for
#endif /* USE_OPENMP */
for( unsigned int each_face_A_idx = 0; each_face_A_idx < m_CoordIndex.size(); each_face_A_idx++ )
{
// n = face A facet normal
std::vector< glm::vec3 > face_A_normals;
face_A_normals.clear();
face_A_normals.resize(m_CoordIndex[each_face_A_idx].size());
std::vector< glm::vec3 >& face_A_normals = m_PerFaceVertexNormals[each_face_A_idx];
face_A_normals.resize( m_CoordIndex[each_face_A_idx].size() );
// loop through all 3 vertices
// for each vert in face A
......@@ -402,7 +411,5 @@ void S3D_MESH::calcPerPointNormals ()
}
}
m_PerFaceVertexNormals.push_back( face_A_normals );
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment