28 #include "WGeometryFunctions.h"
30 void tesselateIcosahedron( std::vector< WVector3d >* vertices, std::vector< unsigned int >* triangles,
unsigned int level )
32 WAssert( vertices,
"Missing input vector." );
33 WAssert( triangles,
"Missing input vector." );
39 for(
unsigned int t = 1; t <= level; ++t )
44 vertices->reserve( nv );
45 triangles->reserve( nt );
48 double phi = 0.5 * ( 1.0 + sqrt( 5.0 ) );
50 std::vector< WVector3d > g;
52 vertices->push_back(
WVector3d( phi, 1, 0 ) );
53 vertices->push_back(
WVector3d( -phi, 1, 0 ) );
54 vertices->push_back(
WVector3d( phi, -1, 0 ) );
55 vertices->push_back(
WVector3d( -phi, -1, 0 ) );
57 vertices->push_back(
WVector3d( 1, 0, phi ) );
58 vertices->push_back(
WVector3d( -1, 0, phi ) );
59 vertices->push_back(
WVector3d( 1, 0, -phi ) );
60 vertices->push_back(
WVector3d( -1, 0, -phi ) );
62 vertices->push_back(
WVector3d( 0, phi, 1 ) );
63 vertices->push_back(
WVector3d( 0, -phi, 1 ) );
64 vertices->push_back(
WVector3d( 0, phi, -1 ) );
65 vertices->push_back(
WVector3d( 0, -phi, -1 ) );
67 for( std::vector< WVector3d >::iterator it = vertices->begin(); it != vertices->end(); ++it )
69 *it = normalize( *it );
73 unsigned int inc[ 60 ] =
96 triangles->assign( inc, inc + 60 );
98 std::map< utility::Edge, unsigned int > edgeVertices;
100 for(
unsigned int t = 0; t < level; ++t )
103 std::size_t numTriangles = triangles->size() / 3;
104 for( std::size_t k = 0; k < numTriangles; ++k )
106 unsigned int idx[ 3 ];
109 for(
int i = 0; i < 3; ++i )
111 utility::Edge e( ( *triangles )[ 3 * k + i ], ( *triangles )[ 3 * k + ( i + 1 ) % 3 ] );
112 if( edgeVertices.find( e ) == edgeVertices.end() )
118 vertices->push_back( v );
119 edgeVertices[ e ] = vertices->size() - 1;
121 idx[ i ] = edgeVertices[ e ];
126 triangles->push_back( ( *triangles )[ 3 * k + 0 ] );
127 triangles->push_back( idx[ 0 ] );
128 triangles->push_back( idx[ 2 ] );
131 triangles->push_back( ( *triangles )[ 3 * k + 1 ] );
132 triangles->push_back( idx[ 1 ] );
133 triangles->push_back( idx[ 0 ] );
136 triangles->push_back( ( *triangles )[ 3 * k + 2 ] );
137 triangles->push_back( idx[ 2 ] );
138 triangles->push_back( idx[ 1 ] );
141 ( *triangles )[ 3 * k + 0 ] = idx[ 0 ];
142 ( *triangles )[ 3 * k + 1 ] = idx[ 1 ];
143 ( *triangles )[ 3 * k + 2 ] = idx[ 2 ];
145 edgeVertices.clear();
ValueT & at(size_t row, size_t col)
Returns a reference to the component of an row and column in order to provide access to the component...
A helper class that is used to store edges as pairs of vertex indices.