IcoSphere Class Reference

#include <icosphere.h>

Public Member Functions

 IcoSphere (unsigned int levels=1)
 
const std::vector< Eigen::Vector3f > & vertices () const
 
const std::vector< int > & indices (int level) const
 
void draw (int level)
 

Protected Member Functions

void _subdivide ()
 

Protected Attributes

std::vector< Eigen::Vector3f > mVertices
 
std::vector< std::vector< int > * > mIndices
 
std::vector< intmListIds
 

Constructor & Destructor Documentation

◆ IcoSphere()

IcoSphere::IcoSphere ( unsigned int  levels = 1)
31  {
32  // init with an icosahedron
33  for (int i = 0; i < 12; i++) mVertices.push_back(Map<Vector3f>(vdata[i]));
34  mIndices.push_back(new std::vector<int>);
35  std::vector<int>& indices = *mIndices.back();
36  for (int i = 0; i < 20; i++) {
37  for (int k = 0; k < 3; k++) indices.push_back(tindices[i][k]);
38  }
39  mListIds.push_back(0);
40 
41  while (mIndices.size() < levels) _subdivide();
42 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:96
std::vector< int > mListIds
Definition: icosphere.h:27
void _subdivide()
Definition: icosphere.cpp:49
std::vector< Eigen::Vector3f > mVertices
Definition: icosphere.h:25
std::vector< std::vector< int > * > mIndices
Definition: icosphere.h:26
const std::vector< int > & indices(int level) const
Definition: icosphere.cpp:44
static GLfloat vdata[12][3]
Definition: icosphere.cpp:23
static GLint tindices[20][3]
Definition: icosphere.cpp:26
char char char int int * k
Definition: level2_impl.h:374

References i, k, tindices, and vdata.

Member Function Documentation

◆ _subdivide()

void IcoSphere::_subdivide ( void  )
protected
49  {
50  typedef unsigned long long Key;
51  std::map<Key, int> edgeMap;
52  const std::vector<int>& indices = *mIndices.back();
53  mIndices.push_back(new std::vector<int>);
54  std::vector<int>& refinedIndices = *mIndices.back();
55  int end = indices.size();
56  for (int i = 0; i < end; i += 3) {
57  int ids0[3], // indices of outer vertices
58  ids1[3]; // indices of edge vertices
59  for (int k = 0; k < 3; ++k) {
60  int k1 = (k + 1) % 3;
61  int e0 = indices[i + k];
62  int e1 = indices[i + k1];
63  ids0[k] = e0;
64  if (e1 > e0) std::swap(e0, e1);
65  Key edgeKey = Key(e0) | (Key(e1) << 32);
66  std::map<Key, int>::iterator it = edgeMap.find(edgeKey);
67  if (it == edgeMap.end()) {
68  ids1[k] = mVertices.size();
69  edgeMap[edgeKey] = ids1[k];
70  mVertices.push_back((mVertices[e0] + mVertices[e1]).normalized());
71  } else
72  ids1[k] = it->second;
73  }
74  refinedIndices.push_back(ids0[0]);
75  refinedIndices.push_back(ids1[0]);
76  refinedIndices.push_back(ids1[2]);
77  refinedIndices.push_back(ids0[1]);
78  refinedIndices.push_back(ids1[1]);
79  refinedIndices.push_back(ids1[0]);
80  refinedIndices.push_back(ids0[2]);
81  refinedIndices.push_back(ids1[2]);
82  refinedIndices.push_back(ids1[1]);
83  refinedIndices.push_back(ids1[0]);
84  refinedIndices.push_back(ids1[1]);
85  refinedIndices.push_back(ids1[2]);
86  }
87  mListIds.push_back(0);
88 }
static constexpr lastp1_t end
Definition: IndexedViewHelper.h:79
EIGEN_BLAS_FUNC() swap(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
Definition: level1_impl.h:117

References Eigen::placeholders::end, i, k, and swap().

◆ draw()

void IcoSphere::draw ( int  level)
90  {
91  while (level >= int(mIndices.size())) const_cast<IcoSphere*>(this)->_subdivide();
92  if (mListIds[level] == 0) {
93  mListIds[level] = glGenLists(1);
94  glNewList(mListIds[level], GL_COMPILE);
95  glVertexPointer(3, GL_FLOAT, 0, mVertices[0].data());
96  glNormalPointer(GL_FLOAT, 0, mVertices[0].data());
97  glEnableClientState(GL_VERTEX_ARRAY);
98  glEnableClientState(GL_NORMAL_ARRAY);
99  glDrawElements(GL_TRIANGLES, mIndices[level]->size(), GL_UNSIGNED_INT, &(mIndices[level]->at(0)));
100  glDisableClientState(GL_VERTEX_ARRAY);
101  glDisableClientState(GL_NORMAL_ARRAY);
102  glEndList();
103  }
104  glCallList(mListIds[level]);
105 }
int data[]
Definition: Map_placement_new.cpp:1
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
Definition: icosphere.h:16

References data, and size.

Referenced by GpuHelper::drawUnitSphere().

◆ indices()

const std::vector< int > & IcoSphere::indices ( int  level) const
44  {
45  while (level >= int(mIndices.size())) const_cast<IcoSphere*>(this)->_subdivide();
46  return *mIndices[level];
47 }

◆ vertices()

const std::vector<Eigen::Vector3f>& IcoSphere::vertices ( ) const
inline
19 { return mVertices; }

References mVertices.

Member Data Documentation

◆ mIndices

std::vector<std::vector<int>*> IcoSphere::mIndices
protected

◆ mListIds

std::vector<int> IcoSphere::mListIds
protected

◆ mVertices

std::vector<Eigen::Vector3f> IcoSphere::mVertices
protected

Referenced by vertices().


The documentation for this class was generated from the following files: