Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Private Member Functions | Private Attributes
omni::visual::Sphere Class Reference

Draw Handler for visualizing a centered sphere. More...

#include <Sphere.h>

Inheritance diagram for omni::visual::Sphere:
Inheritance graph
[legend]
Collaboration diagram for omni::visual::Sphere:
Collaboration graph
[legend]

Public Types

enum  TexCoordsMode { EQUIRECTANGULAR, FISHEYE }
 

Public Member Functions

 Sphere (qreal _radius=1.0)
 
 ~Sphere ()
 
qreal radius () const
 Return radius of sphere. More...
 
void setRadius (qreal)
 Set new sphere radius. More...
 
int stacks () const
 Return number of stacks (in Z direction) More...
 
void setStacks (int _stacks)
 Set number of stacks. More...
 
int slices () const
 Return slices of sphere. More...
 
void setSlices (int _slices)
 Set number of slices and update mesh. More...
 
float top () const
 Return top position where to cut off sphere. More...
 
void setTop (float)
 Set new top position where to cut off sphere. More...
 
float bottom () const
 Return bottom position where to cut off sphere. More...
 
void setBottom (float)
 Set new bottom position where to cut off sphere. More...
 
TexCoordsMode texCoordsMode () const
 Return tex coords mode; fisheye or equirectangular. More...
 
void setTexCoordsMode (TexCoordsMode)
 Set tex coords mode, fisheye or equirectangular. More...
 
void draw () const
 Draws sphere from vertex buffer object. More...
 
void update ()
 Regenerates the mesh and updates the vertex buffer objects. More...
 
- Public Member Functions inherited from omni::visual::Interface
virtual ~Interface ()
 

Private Member Functions

void generateStack (float _top, float _bottom, float _topRadius, float _bottomRadius)
 

Private Attributes

int stacks_ = 64
 
int slices_ = 128
 
float top_ = 1.0
 
float bottom_ = -1.0
 
qreal radius_ = 1.0
 
VertexVBO vbo_
 
VertexVBO::vertex_buffer_type vertices_
 
VertexVBO::index_buffer_type indices_
 
TexCoordsMode texCoordsMode_ = EQUIRECTANGULAR
 

Additional Inherited Members

- Static Protected Member Functions inherited from omni::visual::Interface
static void vertex3 (QVector3D const &)
 glVertex3f from QVector3D More...
 
static void visualLine (QVector3D const &_from, QVector3D const &_to)
 Draws a line. More...
 
static void color (QColor _color, float _alpha=1.0)
 glColor4f from QColor More...
 

Detailed Description

Draw Handler for visualizing a centered sphere.

Member Enumeration Documentation

Enumerator
EQUIRECTANGULAR 
FISHEYE 
34  {
36  FISHEYE
37  };
Definition: Sphere.h:36

Constructor & Destructor Documentation

omni::visual::Sphere::Sphere ( qreal  _radius = 1.0)
27  :
28  radius_(_radius)
29  {
30  update();
31  }
qreal radius_
Definition: Sphere.h:95
void update()
Regenerates the mesh and updates the vertex buffer objects.
Definition: Sphere.cpp:110
omni::visual::Sphere::~Sphere ( )
34  {}

Member Function Documentation

float omni::visual::Sphere::bottom ( ) const

Return bottom position where to cut off sphere.

80  {
81  return bottom_;
82  }
float bottom_
Definition: Sphere.h:93
void omni::visual::Sphere::draw ( ) const
virtual

Draws sphere from vertex buffer object.

Implements omni::visual::Interface.

99  {
100  glPushMatrix();
101  withCurrentContext([this](QOpenGLFunctions& _)
102  {
103  // Scale offset
104  glScalef(radius_, radius_, radius_);
105  vbo_.bindAndDraw();
106  });
107  glPopMatrix();
108  }
void withCurrentContext(ContextFunctor f)
Do OpenGL operations with current context, if it exists.
Definition: ContextSwitch.cpp:45
qreal radius_
Definition: Sphere.h:95
void bindAndDraw(ARGS &&..._args) const
Definition: VertexVBO.h:63
VertexVBO vbo_
Definition: Sphere.h:97
void omni::visual::Sphere::generateStack ( float  _top,
float  _bottom,
float  _topRadius,
float  _bottomRadius 
)
private

Generate vertices

Top triangle

Bottom triangle

147  {
148  size_t _startIndex = vertices_.size();
149 
150  for (size_t i = 0; i <= slices_; ++i)
151  {
152  /// Generate vertices
153  float _m = 2.0 * M_PI * float(i) / slices_;
154  float _cos = cos(_m), _sin = sin(_m);
155  QVector3D _topPoint(_cos * _topRadius, _sin * _topRadius, _top);
156  QVector3D _bottomPoint(_cos * _bottomRadius, _sin * _bottomRadius,
157  _bottom);
158  QVector3D _normalTop(_topPoint.normalized());
159  QVector3D _normalBottom(_bottomPoint.normalized());
160 
161  auto getTexCoord = [this, &i](QVector3D const& _v) -> QVector2D {
162  QVector2D texCoords;
163  QVector3D uvw = _v.normalized();
164 
165  switch (this->texCoordsMode_) {
166  default:
167  case EQUIRECTANGULAR:
168  texCoords.setX(i / float(slices_));
169  texCoords.setY(1.0 - acos(uvw.z()) / M_PI);
170  break;
171 
172  case FISHEYE: {
173  float _phi = i / float(slices_) * M_PI * 2.0;
174  float _r = atan2(QVector2D(uvw.x(),
175  uvw.y()).length(),
176  uvw.z()) / M_PI;
177  texCoords.setX(_r * cos(_phi) + 0.5);
178  texCoords.setY(_r * sin(_phi) + 0.5);
179  break;
180  }
181  }
182 
183  return texCoords;
184  };
185 
186  QVector2D _texCoordTop(getTexCoord(_topPoint));
187  QVector2D _texCoordBottom(getTexCoord(_bottomPoint));
188 
189  vertices_.emplace_back(_topPoint, _normalTop, _texCoordTop); //
190  // QVector2D(float(i)/slices_,1.0
191  // -
192  // acos(_normalTop.z())
193  // /
194  // M_PI));
195  vertices_.emplace_back(_bottomPoint, _normalBottom, _texCoordBottom); //
196  // QVector2D(float(i)/slices_,1.0
197  // -
198  // acos(_normalBottom.z())
199  // /
200  // M_PI));
201 
202  /// Top triangle
203  indices_.push_back(_startIndex + 2 * i);
204  indices_.push_back(_startIndex + 2 * i + 1);
205  indices_.push_back(_startIndex + 2 * (i + 1));
206 
207  /// Bottom triangle
208  indices_.push_back(_startIndex + 2 * i + 1);
209  indices_.push_back(_startIndex + 2 * (i + 1) + 1);
210  indices_.push_back(_startIndex + 2 * (i + 1));
211  }
212  }
TexCoordsMode texCoordsMode_
Definition: Sphere.h:100
VertexVBO::index_buffer_type indices_
Definition: Sphere.h:99
VertexVBO::vertex_buffer_type vertices_
Definition: Sphere.h:98
int slices_
Definition: Sphere.h:90
Definition: Sphere.h:36
qreal omni::visual::Sphere::radius ( ) const

Return radius of sphere.

37  {
38  return radius_;
39  }
qreal radius_
Definition: Sphere.h:95
void omni::visual::Sphere::setBottom ( float  _bottom)

Set new bottom position where to cut off sphere.

85  {
86  bottom_ = _bottom;
87  update();
88  }
float bottom_
Definition: Sphere.h:93
void update()
Regenerates the mesh and updates the vertex buffer objects.
Definition: Sphere.cpp:110
void omni::visual::Sphere::setRadius ( qreal  _radius)

Set new sphere radius.

42  {
43  radius_ = _radius;
44  }
qreal radius_
Definition: Sphere.h:95
void omni::visual::Sphere::setSlices ( int  _slices)

Set number of slices and update mesh.

63  {
64  slices_ = _slices;
65  update();
66  }
int slices_
Definition: Sphere.h:90
void update()
Regenerates the mesh and updates the vertex buffer objects.
Definition: Sphere.cpp:110
void omni::visual::Sphere::setStacks ( int  _stacks)

Set number of stacks.

52  {
53  stacks_ = _stacks;
54  update();
55  }
int stacks_
Definition: Sphere.h:89
void update()
Regenerates the mesh and updates the vertex buffer objects.
Definition: Sphere.cpp:110
void omni::visual::Sphere::setTexCoordsMode ( TexCoordsMode  _texCoordsMode)

Set tex coords mode, fisheye or equirectangular.

94  {
95  texCoordsMode_ = _texCoordsMode;
96  }
TexCoordsMode texCoordsMode_
Definition: Sphere.h:100
void omni::visual::Sphere::setTop ( float  _top)

Set new top position where to cut off sphere.

74  {
75  top_ = _top;
76  update();
77  }
float top_
Definition: Sphere.h:92
void update()
Regenerates the mesh and updates the vertex buffer objects.
Definition: Sphere.cpp:110
int omni::visual::Sphere::slices ( ) const

Return slices of sphere.

58  {
59  return slices_;
60  }
int slices_
Definition: Sphere.h:90
int omni::visual::Sphere::stacks ( ) const

Return number of stacks (in Z direction)

47  {
48  return stacks_;
49  }
int stacks_
Definition: Sphere.h:89
Sphere::TexCoordsMode omni::visual::Sphere::texCoordsMode ( ) const

Return tex coords mode; fisheye or equirectangular.

90  {
91  return texCoordsMode_;
92  }
TexCoordsMode texCoordsMode_
Definition: Sphere.h:100
float omni::visual::Sphere::top ( ) const

Return top position where to cut off sphere.

69  {
70  return top_;
71  }
float top_
Definition: Sphere.h:92
void omni::visual::Sphere::update ( )
virtual

Regenerates the mesh and updates the vertex buffer objects.

Reimplemented from omni::visual::Interface.

111  {
112  primaryContextSwitch([&](QOpenGLFunctions& _) {
113  vertices_.clear();
114  indices_.clear();
115  vertices_.reserve(2 * slices_ * stacks_);
116  indices_.reserve(6 * slices_ * stacks_);
117 
118  // If there are M lines of latitude (horizontal) and
119  // N lines of longitude (vertical), then put dots at
120  // (x, y, z) = (sin(Pi * m/M) cos(2Pi * n/N), sin(Pi * m/M) sin(2Pi *
121  // n/N), cos(Pi * m/M))
122  auto stackRadius = [this](size_t index)
123  {
124  return sin(M_PI * float(index) / stacks_);
125  };
126  auto stackPos = [this](size_t index)
127  {
128  return cos(M_PI * float(index) / stacks_);
129  };
130 
131  for (size_t i = 0; i < stacks_; ++i)
132  {
133  if ((stackPos(i) > top_) || (stackPos(i + 1) < bottom_)) continue;
134 
135  generateStack(stackPos(i), stackPos(i + 1),
136  stackRadius(i), stackRadius(i + 1));
137  }
138 
140  vertices_.clear();
141  indices_.clear();
142  });
143  }
int stacks_
Definition: Sphere.h:89
float top_
Definition: Sphere.h:92
float bottom_
Definition: Sphere.h:93
VertexVBO::index_buffer_type indices_
Definition: Sphere.h:99
VertexVBO::vertex_buffer_type vertices_
Definition: Sphere.h:98
VertexVBO vbo_
Definition: Sphere.h:97
int slices_
Definition: Sphere.h:90
void primaryContextSwitch(ContextFunctor f)
Switch to primary context to create OpenGL objects like textures etc.
Definition: ContextSwitch.cpp:40
void buffer(vertex_buffer_type const &_vertices, index_buffer_type const &_indices)
Copy buffers to GPU.
Definition: VertexVBO.cpp:33
void generateStack(float _top, float _bottom, float _topRadius, float _bottomRadius)
Definition: Sphere.cpp:145

Field Documentation

float omni::visual::Sphere::bottom_ = -1.0
private
VertexVBO::index_buffer_type omni::visual::Sphere::indices_
private
qreal omni::visual::Sphere::radius_ = 1.0
private
int omni::visual::Sphere::slices_ = 128
private
int omni::visual::Sphere::stacks_ = 64
private
TexCoordsMode omni::visual::Sphere::texCoordsMode_ = EQUIRECTANGULAR
private
float omni::visual::Sphere::top_ = 1.0
private
VertexVBO omni::visual::Sphere::vbo_
private
VertexVBO::vertex_buffer_type omni::visual::Sphere::vertices_
private

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