Merge lp:~azonenberg/kicad/advanced-feature-bugfixes into lp:kicad/product

Proposed by Andrew Zonenberg
Status: Merged
Merged at revision: 5064
Proposed branch: lp:~azonenberg/kicad/advanced-feature-bugfixes
Merge into: lp:kicad/product
Diff against target: 129 lines (+27/-20)
1 file modified
3d-viewer/3d_mesh_model.cpp (+27/-20)
To merge this branch: bzr merge lp:~azonenberg/kicad/advanced-feature-bugfixes
Reviewer Review Type Date Requested Status
KiCad Lead Developers Pending
Review via email: mp+229341@code.launchpad.net

Description of the change

Parallelized 3D model vertex normal calculations to use all available CPU cores for significant speedup

To post a comment you must log in.
Revision history for this message
Maciej Suminski (orsonmmz) wrote :

Hi Andrew,

You are pretty fast, thank you for the patches once again! Would you please add one more thing? We already had issues on systems that do not support OpenMP out of the box, therefore could you wrap the appropriate parts with #ifdef USE_OPENMP..#endif? You may have a look at pcbnew/ratsnest_data.cpp if you want a reference.

Thank you in advance,
Orson

Revision history for this message
Wayne Stambaugh (stambaughw) wrote :

Please follow the KiCad Coding Policy when committing patches. Line 10 of your patch:

+ m_PerFaceVertexNormals.resize(m_CoordIndex.size());

should look like:

+ m_PerFaceVertexNormals.resize( m_CoordIndex.size() );

There is also trailing white space on line 8.

Thanks,

Wayne

Revision history for this message
Andrew Zonenberg (azonenberg) wrote :

r5047 should fix both of your concerns.

5045. By Cirilo Bernardo

export IDF without empty PLACEMENT section

5046. By Maciej Suminski

bugfix: modules are not selectable in the high contrast mode (GAL).

5047. By Maciej Suminski

Fixed module anchor drawing (GAL).

5048. By Maciej Suminski

Selected items do not disappear after rendering backend switch.

5049. By jean-pierre charras

3D viewer: move helper functions from 3d_draw.cpp to 3d_draw_helper_functions.cpp. Add comments in .h sources. Better management of background color. coding style fixes.

5050. By jean-pierre charras

Fix some case sensitive filename issues.

5051. By Martin Errenst

Anti-aliasing patch for the 3D-Viewer from Martin Janitschke

5052. By jean-pierre charras

Fix wx28 compatibility.

5053. By Maciej Suminski

Changed 'line width change' & 'change arc posture' to TOOL_ACTIONs.

5054. By Mario Luzeiro

3d-viewer: fix compil warning, by Mario Luzeiro, with some coding style fixes.
common.cpp: remove useless warning on wxWidgets < 3.0 about --with-gtkprint build option: on wxWidgets < 3.0 on Linux the print function does not work even with this build option.

5055. By Dick Hollenbeck

KIWAY support in 5054 is stable enough to use in view of all other new features.

5056. By Maciej Suminski

Disable highlight mode in the module editor (GAL).

5057. By Maciej Suminski

Items are either dragged by their origin or moved by a vector (depending on the number of selected items) (GAL).

5058. By Maciej Suminski

Fixed filled arcs drawing (GAL).

5059. By Maciej Suminski

Buried/blind vias indicate the layers they go through (GAL).

5060. By Maciej Suminski

Initalize fields in TOOL_EVENT constructors.

5061. By jean-pierre charras

Cosmetic enhancement: change plot icon in menus.
3dviewer: back to double (from float) in class S3D_MASTER for 3 members (m_MatScale, m_MatRotation, m_MatPosition) which are used in dialogs and r/w file functions, which expect double.
Using float create minor but unwanted issues in r/w file functions.
S3D_MATERIAL: enable all color options: if a 3d shape has bad color parameters, the shape must be modified, not the 3d rendering.
The rendering now matches what we see in other vrml viewer like FreeCAD.
Some minor coding style fixes.

5062. By Thiadmer Riemersma

Pcbnew: Commit patch (with very minor changes) about SVG file export with the layers ordered from bottom to top. ( bug 1286646 ), from Thiadmer Riemersma.

5063. By Maciej Suminski

FIxed invisible layers problem after changing the number of layers (GAL).

5064. By Andrew Zonenberg

3D viewer: Parallelized 3D model vertex normal calculations to use all available CPU cores for significant speedup.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '3d-viewer/3d_mesh_model.cpp'
--- 3d-viewer/3d_mesh_model.cpp 2014-08-02 07:46:47 +0000
+++ 3d-viewer/3d_mesh_model.cpp 2014-08-12 08:17:58 +0000
@@ -24,13 +24,17 @@
2424
25/**25/**
26 * @file 3d_mesh_model.cpp26 * @file 3d_mesh_model.cpp
27 * @brief 27 * @brief
28 */28 */
2929
3030
31#include <3d_mesh_model.h>31#include <3d_mesh_model.h>
32#include <boost/geometry/algorithms/area.hpp>32#include <boost/geometry/algorithms/area.hpp>
3333
34#ifdef USE_OPENMP
35#include <omp.h>
36#endif /* USE_OPENMP */
37
34S3D_MESH::S3D_MESH()38S3D_MESH::S3D_MESH()
35{39{
36 isPerFaceNormalsComputed = false;40 isPerFaceNormalsComputed = false;
@@ -118,21 +122,21 @@
118 for( unsigned int idx = 0; idx < m_CoordIndex.size(); idx++ )122 for( unsigned int idx = 0; idx < m_CoordIndex.size(); idx++ )
119 {123 {
120 if( m_MaterialIndex.size() > 1 )124 if( m_MaterialIndex.size() > 1 )
121 { 125 {
122 if( m_Materials )126 if( m_Materials )
123 {127 {
124 m_Materials->SetOpenGLMaterial( m_MaterialIndex[idx] );128 m_Materials->SetOpenGLMaterial( m_MaterialIndex[idx] );
125 }129 }
126 } 130 }
127 131
128 132
129 switch( m_CoordIndex[idx].size() )133 switch( m_CoordIndex[idx].size() )
130 {134 {
131 case 3: glBegin( GL_TRIANGLES );break;135 case 3: glBegin( GL_TRIANGLES );break;
132 case 4: glBegin( GL_QUADS ); break;136 case 4: glBegin( GL_QUADS ); break;
133 default: glBegin( GL_POLYGON ); break;137 default: glBegin( GL_POLYGON ); break;
134 }138 }
135 139
136140
137 if( m_PerVertexNormalsNormalized.size() > 0 )141 if( m_PerVertexNormalsNormalized.size() > 0 )
138 {142 {
@@ -167,7 +171,7 @@
167 glNormal3fv( &normal.x );171 glNormal3fv( &normal.x );
168172
169 glm::vec3 point = m_Point[m_CoordIndex[idx][ii]];173 glm::vec3 point = m_Point[m_CoordIndex[idx][ii]];
170 glVertex3fv( &point.x ); 174 glVertex3fv( &point.x );
171 }175 }
172 }176 }
173177
@@ -258,7 +262,7 @@
258262
259 //DBG( printf("m_CoordIndex.size %u\n", m_CoordIndex.size()) );263 //DBG( printf("m_CoordIndex.size %u\n", m_CoordIndex.size()) );
260 //DBG( printf("m_PointNormalized.size %u\n", m_PointNormalized.size()) );264 //DBG( printf("m_PointNormalized.size %u\n", m_PointNormalized.size()) );
261 265
262 for( unsigned int idx = 0; idx < m_CoordIndex.size(); idx++ )266 for( unsigned int idx = 0; idx < m_CoordIndex.size(); idx++ )
263 {267 {
264268
@@ -307,7 +311,7 @@
307 if( haveAlreadyNormals_from_model_file == false )311 if( haveAlreadyNormals_from_model_file == false )
308 {312 {
309313
310 // normalize vertex normal 314 // normalize vertex normal
311 float l = glm::length( cross_prod );315 float l = glm::length( cross_prod );
312316
313 if( l > FLT_EPSILON ) // avoid division by zero317 if( l > FLT_EPSILON ) // avoid division by zero
@@ -331,7 +335,7 @@
331335
332 m_PerFaceNormalsNormalized.push_back( cross_prod );336 m_PerFaceNormalsNormalized.push_back( cross_prod );
333 }337 }
334 338
335 }339 }
336340
337}341}
@@ -355,13 +359,18 @@
355359
356 m_PerFaceVertexNormals.clear();360 m_PerFaceVertexNormals.clear();
357361
362 // Pre-allocate space for the entire vector of vertex normals so we can do parallel writes
363 m_PerFaceVertexNormals.resize( m_CoordIndex.size() );
364
358 // for each face A in mesh365 // for each face A in mesh
366 #ifdef USE_OPENMP
367 #pragma omp parallel for
368 #endif /* USE_OPENMP */
359 for( unsigned int each_face_A_idx = 0; each_face_A_idx < m_CoordIndex.size(); each_face_A_idx++ )369 for( unsigned int each_face_A_idx = 0; each_face_A_idx < m_CoordIndex.size(); each_face_A_idx++ )
360 {370 {
361 // n = face A facet normal371 // n = face A facet normal
362 std::vector< glm::vec3 > face_A_normals;372 std::vector< glm::vec3 >& face_A_normals = m_PerFaceVertexNormals[each_face_A_idx];
363 face_A_normals.clear();373 face_A_normals.resize( m_CoordIndex[each_face_A_idx].size() );
364 face_A_normals.resize(m_CoordIndex[each_face_A_idx].size());
365374
366 // loop through all 3 vertices375 // loop through all 3 vertices
367 // for each vert in face A376 // for each vert in face A
@@ -393,16 +402,14 @@
393 }402 }
394 }403 }
395404
396 // normalize vertex normal 405 // normalize vertex normal
397 float l = glm::length( face_A_normals[each_vert_A_idx] );406 float l = glm::length( face_A_normals[each_vert_A_idx] );
398407
399 if( l > FLT_EPSILON ) // avoid division by zero408 if( l > FLT_EPSILON ) // avoid division by zero
400 {409 {
401 face_A_normals[each_vert_A_idx] /= l;410 face_A_normals[each_vert_A_idx] /= l;
402 }411 }
403 412
404 }413 }
405
406 m_PerFaceVertexNormals.push_back( face_A_normals );
407 }414 }
408}415}