15 using namespace Eigen;
20 #define X .525731112119133606 21 #define Z .850650808352039932 24 {-
X, 0.0,
Z}, {
X, 0.0,
Z}, {-
X, 0.0, -
Z}, {
X, 0.0, -
Z},
25 {0.0,
Z,
X}, {0.0,
Z, -X}, {0.0, -
Z, X}, {0.0, -
Z, -X},
26 {
Z,
X, 0.0}, {-
Z,
X, 0.0}, {
Z, -
X, 0.0}, {-
Z, -
X, 0.0}
30 {0,4,1}, {0,9,4}, {9,5,4}, {4,5,8}, {4,8,1},
31 {8,10,1}, {8,3,10}, {5,3,8}, {5,2,3}, {2,7,3},
32 {7,10,3}, {7,6,10}, {7,11,6}, {11,0,6}, {0,1,6},
33 {6,1,10}, {9,0,11}, {9,11,2}, {9,2,5}, {7,2,11} };
39 for (
int i = 0;
i < 12;
i++)
41 mIndices.push_back(
new std::vector<int>);
42 std::vector<int>& indices = *mIndices.back();
43 for (
int i = 0; i < 20; i++)
45 for (
int k = 0; k < 3; k++)
48 mListIds.push_back(0);
50 while(mIndices.size()<levels)
56 while (level>=
int(mIndices.size()))
57 const_cast<IcoSphere*
>(
this)->_subdivide();
58 return *mIndices[
level];
63 typedef unsigned long long Key;
64 std::map<Key,int> edgeMap;
65 const std::vector<int>& indices = *mIndices.back();
66 mIndices.push_back(
new std::vector<int>);
67 std::vector<int>& refinedIndices = *mIndices.back();
68 int end = indices.size();
73 for (
int k=0; k<3; ++k)
76 int e0 = indices[
i+k];
77 int e1 = indices[
i+k1];
81 Key edgeKey =
Key(e0) | (
Key(e1)<<32);
82 std::map<Key,int>::iterator it = edgeMap.find(edgeKey);
83 if (it==edgeMap.end())
85 ids1[k] = mVertices.size();
86 edgeMap[edgeKey] = ids1[k];
87 mVertices.push_back( (mVertices[e0]+mVertices[e1]).normalized() );
92 refinedIndices.push_back(ids0[0]); refinedIndices.push_back(ids1[0]); refinedIndices.push_back(ids1[2]);
93 refinedIndices.push_back(ids0[1]); refinedIndices.push_back(ids1[1]); refinedIndices.push_back(ids1[0]);
94 refinedIndices.push_back(ids0[2]); refinedIndices.push_back(ids1[2]); refinedIndices.push_back(ids1[1]);
95 refinedIndices.push_back(ids1[0]); refinedIndices.push_back(ids1[1]); refinedIndices.push_back(ids1[2]);
97 mListIds.push_back(0);
102 while (level>=
int(mIndices.size()))
103 const_cast<IcoSphere*
>(
this)->_subdivide();
104 if (mListIds[level]==0)
106 mListIds[
level] = glGenLists(1);
107 glNewList(mListIds[level], GL_COMPILE);
108 glVertexPointer(3, GL_FLOAT, 0, mVertices[0].
data());
109 glNormalPointer(GL_FLOAT, 0, mVertices[0].
data());
110 glEnableClientState(GL_VERTEX_ARRAY);
111 glEnableClientState(GL_NORMAL_ARRAY);
112 glDrawElements(GL_TRIANGLES, mIndices[level]->
size(), GL_UNSIGNED_INT, &(mIndices[level]->at(0)));
113 glDisableClientState(GL_VERTEX_ARRAY);
114 glDisableClientState(GL_NORMAL_ARRAY);
117 glCallList(mListIds[level]);
static GLfloat vdata[12][3]
A matrix or vector expression mapping an existing array of data.
Namespace containing all symbols from the Eigen library.
const std::vector< int > & indices(int level) const
static GLint tindices[20][3]
IcoSphere(unsigned int levels=1)
std::uint64_t Key
Integer nonlinear key type.
void swap(mpfr::mpreal &x, mpfr::mpreal &y)