Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cdo
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mpim-sw
cdo
Commits
04493319
Commit
04493319
authored
10 months ago
by
Uwe Schulzweida
Browse files
Options
Downloads
Patches
Plain Diff
grid_icosphere: improved performance
parent
f9d94adb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!234
M214003/develop
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/grid_icosphere.cc
+23
-23
23 additions, 23 deletions
src/grid_icosphere.cc
with
23 additions
and
23 deletions
src/grid_icosphere.cc
+
23
−
23
View file @
04493319
...
...
@@ -2,6 +2,7 @@
// https://schneide.wordpress.com/2016/07/15/generating-an-icosphere-in-c
#include
"vector3d.h"
#include
<inttypes.h>
#include
<utility>
#include
<limits>
...
...
@@ -18,7 +19,8 @@
#include
<map>
#endif
using
Index
=
size_t
;
// using Index = size_t;
using
Index
=
uint32_t
;
using
Vertex
=
Vector3d
;
using
Triangle
=
std
::
array
<
Index
,
3
>
;
using
TriangleList
=
std
::
vector
<
Triangle
>
;
...
...
@@ -58,7 +60,7 @@ namespace icosahedron
// 12 vertices
static
VertexList
vertices
(
12
);
void
static
void
init
(
void
)
{
constexpr
auto
pi_5
=
M_PI
*
0.2
;
...
...
@@ -111,6 +113,9 @@ subdivide(VertexList &vertices, const TriangleList &triangles)
Triangle
mid
;
auto
n
=
triangles
.
size
();
#ifdef UseUnorderedMap
lookup
.
reserve
(
1.5
*
n
);
#endif
TriangleList
result
(
4
*
n
);
for
(
size_t
i
=
0
;
i
<
n
;
++
i
)
{
...
...
@@ -126,20 +131,6 @@ subdivide(VertexList &vertices, const TriangleList &triangles)
return
result
;
}
using
IndexedMesh
=
std
::
pair
<
VertexList
,
TriangleList
>
;
static
IndexedMesh
make_icosphere
(
int
subdivisions
)
{
icosahedron
::
init
();
auto
vertices
=
icosahedron
::
vertices
;
auto
triangles
=
icosahedron
::
triangles
;
for
(
int
i
=
0
;
i
<
subdivisions
;
++
i
)
triangles
=
subdivide
(
vertices
,
triangles
);
return
{
vertices
,
triangles
};
}
static
inline
void
d_normalize
(
Vertex
&
v
)
{
...
...
@@ -185,9 +176,18 @@ size_t
gen_icosphere_coords
(
int
subdivisions
,
bool
withBounds
,
std
::
vector
<
double
>
&
xvals
,
std
::
vector
<
double
>
&
yvals
,
std
::
vector
<
double
>
&
xbounds
,
std
::
vector
<
double
>
&
ybounds
)
{
const
auto
mesh
=
make_icosphere
(
subdivisions
);
const
auto
&
vertices
=
mesh
.
first
;
const
auto
&
triangles
=
mesh
.
second
;
icosahedron
::
init
();
auto
triangles
=
icosahedron
::
triangles
;
auto
vertices
=
icosahedron
::
vertices
;
size_t
numTriangles
=
std
::
pow
(
4
,
subdivisions
)
*
20
;
if
(
numTriangles
>
(
size_t
)
std
::
numeric_limits
<
Index
>::
max
())
fprintf
(
stderr
,
"Too many grid cells:%zu (limit=%zu)!
\n
"
,
numTriangles
,
(
size_t
)
std
::
numeric_limits
<
Index
>::
max
());
size_t
numVerticies
=
std
::
pow
(
4
,
subdivisions
)
*
10
+
2
;
vertices
.
reserve
(
numVerticies
);
// printf("numTriangles %zu, numVerticies %zu\n", numTriangles, numVerticies);
for
(
int
i
=
0
;
i
<
subdivisions
;
++
i
)
triangles
=
subdivide
(
vertices
,
triangles
);
auto
numCells
=
triangles
.
size
();
xvals
.
resize
(
numCells
);
...
...
@@ -243,13 +243,13 @@ subDivdeAndVertexForEdgeTest(int subdivisions)
size_t
expectedNumVerticies
=
std
::
pow
(
4
,
subdivisions
)
*
10
+
2
;
if
(
triangles
.
size
()
!=
expectedNumTriangles
)
{
std
::
cout
<<
"ERROR: unexpected number of triangles
for T: std::map
, expected "
<<
expectedNumTriangles
<<
" got "
<<
triangles
.
size
()
<<
std
::
endl
;
std
::
cout
<<
"ERROR: unexpected number of triangles, expected "
<<
expectedNumTriangles
<<
" got "
<<
triangles
.
size
()
<<
std
::
endl
;
}
if
(
vertices
.
size
()
!=
expectedNumVerticies
)
{
std
::
cout
<<
"ERROR: unexpected number of verticies
for T: std::map
, expected "
<<
expectedNumVerticies
<<
" got "
<<
vertices
.
size
()
<<
std
::
endl
;
std
::
cout
<<
"ERROR: unexpected number of verticies, expected "
<<
expectedNumVerticies
<<
" got "
<<
vertices
.
size
()
<<
std
::
endl
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment