Semantic Pointing for Object Picking in Complex 3D Environments
by Christian Kössler and Felix Kreuzer
 All Classes Files Functions Variables Macros Pages
utility.hpp
Go to the documentation of this file.
1 #pragma once
2 #pragma warning( disable : 4482 4996 4800 )
3 
4 #include <fstream>
5 #include <sstream>
6 #include <iostream>
7 #include <iomanip>
8 #include <glm/gtx/transform.hpp>
9 #include <assimp.hpp>
10 #include <aiScene.h>
11 #include <aiPostProcess.h>
12 
13 #include "common.hpp"
14 
17 //namespace glm {
18 //class mat3;
19 //}
20 
21 /*struct sStdGeomVertex
22 {
23  glm::vec4 pos;
24  glm::vec3 normal;
25  glm::vec2 tex;
26  glm::vec3 tangent;
27  glm::vec3 binormal;
28 };*/
29 
30 class Shader;
31 class Model;
32 
33 bool fileExists(const string &filename);
34 string readFile(const string &filename);
35 void getErrors(void);
36 
37 void printMatrix(glm::mat3 matrix);
38 void printMatrix(glm::mat4 matrix);
39 void printVector(glm::vec2 vec);
40 void printVector(glm::vec3 vec);
41 void printVector(glm::vec4 vec);
42 void printArray(float *printarray, int arraysize);
43 float randFloat(float a, float b);
44 int randInt(int a, int b);
45 int sign(float a);
46 GLbyte *gltReadTGABits(const char *szFileName, GLint *iWidth, GLint *iHeight, GLint *iComponents, GLenum *eFormat);
47 GLuint load2dTexture(const string& path, bool projection = false);
48 float *calculateNormals(const float *vertices_in, int arraysize);
49 
50 void setupCubeMap(GLuint& texture);
51 GLuint loadCubeMap(string paths[]);
52 void unloadCubeMap(GLuint& texture);
53 void initVboVao(const Shader& shader, GLuint *vbo_id, GLuint *vao_id, const GLfloat *positions, GLfloat *normals, const GLfloat *texcoordinates, int sizeofarray, int buffermode, bool update);
54 void initVboVaoFromModel(const Shader &shader, Model *model, const string& path, int buffermode);
55 void releaseVboVao(GLuint *vbo_id, GLuint *vao_id);
56 
65 bool initFbo(GLuint &fboId, GLuint &imgId, int width, int height);
66 int readPixel(unsigned int x, unsigned int y, GLuint fboId, GLuint imgId);
67 
78 int *readPixels(unsigned int xFrom, unsigned int yFrom, unsigned int width, unsigned int height, GLuint fboId, GLuint imgId);
79 template <class T> string string_tostring(const T& t, const int digits = 1) { std::stringstream ss; ss << std::setw(digits) << std::setfill('0') << t; return ss.str(); }
int * readPixels(unsigned int xFrom, unsigned int yFrom, unsigned int width, unsigned int height, GLuint fboId, GLuint imgId)
Reads pixels from the GPU in a rectangular form.
bool initFbo(GLuint &fboId, GLuint &imgId, int width, int height)
Initializes the FBO, which is used as PickBuffer (render objectIds for object picking).