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
1=== modified file '3d-viewer/3d_mesh_model.cpp'
2--- 3d-viewer/3d_mesh_model.cpp 2014-08-02 07:46:47 +0000
3+++ 3d-viewer/3d_mesh_model.cpp 2014-08-12 08:17:58 +0000
4@@ -24,13 +24,17 @@
5
6 /**
7 * @file 3d_mesh_model.cpp
8- * @brief
9+ * @brief
10 */
11
12
13 #include <3d_mesh_model.h>
14 #include <boost/geometry/algorithms/area.hpp>
15
16+#ifdef USE_OPENMP
17+#include <omp.h>
18+#endif /* USE_OPENMP */
19+
20 S3D_MESH::S3D_MESH()
21 {
22 isPerFaceNormalsComputed = false;
23@@ -118,21 +122,21 @@
24 for( unsigned int idx = 0; idx < m_CoordIndex.size(); idx++ )
25 {
26 if( m_MaterialIndex.size() > 1 )
27- {
28+ {
29 if( m_Materials )
30 {
31 m_Materials->SetOpenGLMaterial( m_MaterialIndex[idx] );
32 }
33- }
34-
35-
36+ }
37+
38+
39 switch( m_CoordIndex[idx].size() )
40 {
41- case 3: glBegin( GL_TRIANGLES );break;
42- case 4: glBegin( GL_QUADS ); break;
43- default: glBegin( GL_POLYGON ); break;
44+ case 3: glBegin( GL_TRIANGLES );break;
45+ case 4: glBegin( GL_QUADS ); break;
46+ default: glBegin( GL_POLYGON ); break;
47 }
48-
49+
50
51 if( m_PerVertexNormalsNormalized.size() > 0 )
52 {
53@@ -167,7 +171,7 @@
54 glNormal3fv( &normal.x );
55
56 glm::vec3 point = m_Point[m_CoordIndex[idx][ii]];
57- glVertex3fv( &point.x );
58+ glVertex3fv( &point.x );
59 }
60 }
61
62@@ -258,7 +262,7 @@
63
64 //DBG( printf("m_CoordIndex.size %u\n", m_CoordIndex.size()) );
65 //DBG( printf("m_PointNormalized.size %u\n", m_PointNormalized.size()) );
66-
67+
68 for( unsigned int idx = 0; idx < m_CoordIndex.size(); idx++ )
69 {
70
71@@ -307,7 +311,7 @@
72 if( haveAlreadyNormals_from_model_file == false )
73 {
74
75- // normalize vertex normal
76+ // normalize vertex normal
77 float l = glm::length( cross_prod );
78
79 if( l > FLT_EPSILON ) // avoid division by zero
80@@ -331,7 +335,7 @@
81
82 m_PerFaceNormalsNormalized.push_back( cross_prod );
83 }
84-
85+
86 }
87
88 }
89@@ -355,13 +359,18 @@
90
91 m_PerFaceVertexNormals.clear();
92
93+ // Pre-allocate space for the entire vector of vertex normals so we can do parallel writes
94+ m_PerFaceVertexNormals.resize( m_CoordIndex.size() );
95+
96 // for each face A in mesh
97+ #ifdef USE_OPENMP
98+ #pragma omp parallel for
99+ #endif /* USE_OPENMP */
100 for( unsigned int each_face_A_idx = 0; each_face_A_idx < m_CoordIndex.size(); each_face_A_idx++ )
101 {
102 // n = face A facet normal
103- std::vector< glm::vec3 > face_A_normals;
104- face_A_normals.clear();
105- face_A_normals.resize(m_CoordIndex[each_face_A_idx].size());
106+ std::vector< glm::vec3 >& face_A_normals = m_PerFaceVertexNormals[each_face_A_idx];
107+ face_A_normals.resize( m_CoordIndex[each_face_A_idx].size() );
108
109 // loop through all 3 vertices
110 // for each vert in face A
111@@ -393,16 +402,14 @@
112 }
113 }
114
115- // normalize vertex normal
116+ // normalize vertex normal
117 float l = glm::length( face_A_normals[each_vert_A_idx] );
118
119 if( l > FLT_EPSILON ) // avoid division by zero
120 {
121 face_A_normals[each_vert_A_idx] /= l;
122 }
123-
124+
125 }
126-
127- m_PerFaceVertexNormals.push_back( face_A_normals );
128 }
129 }