197e13de
Pavel Govyadinov
Added new class g...
|
1
2
3
4
|
#ifndef STIM_GL_TEXTURE_H
#define STIM_GL_TEXTURE_H
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
5
6
7
8
9
10
11
12
13
14
15
|
/*
includes not necessary (yet)
#include <iterator>
#include <algorithm>
*/
|
197e13de
Pavel Govyadinov
Added new class g...
|
16
17
|
#include <math.h>
#include <iostream>
|
197e13de
Pavel Govyadinov
Added new class g...
|
18
|
#include <vector>
|
197e13de
Pavel Govyadinov
Added new class g...
|
19
|
#include "../grids/image_stack.h"
|
846040be
Pavel Govyadinov
working version
|
20
21
|
#include <GL/glut.h>
//#include <GL/glext.h>
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
22
|
#include "./error.h"
|
197e13de
Pavel Govyadinov
Added new class g...
|
23
24
|
namespace stim{
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
25
26
27
28
29
|
/*
class gl_texture
Uses image_stack class in order to create a texture object.
*/
|
197e13de
Pavel Govyadinov
Added new class g...
|
30
|
template<typename T>
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
31
|
class gl_texture : public virtual image_stack<T>
|
197e13de
Pavel Govyadinov
Added new class g...
|
32
|
{
|
372b5963
Pavel Govyadinov
added support for...
|
33
|
private:
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
34
35
36
|
///Method: setTextureType
/// Sets the internal texture_type, based on the data
/// size. Either 3D, 2D, 1D textures.
|
372b5963
Pavel Govyadinov
added support for...
|
37
38
39
40
41
42
43
44
45
46
47
|
void
setTextureType()
{
if (R[3] > 1)
texture_type = GL_TEXTURE_3D;
else if (R[3] == 1 && R[2] == 0)
texture_type = GL_TEXTURE_1D;
else if (R[3] == 1)
texture_type = GL_TEXTURE_2D;
}
|
197e13de
Pavel Govyadinov
Added new class g...
|
48
|
protected:
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
49
|
std::string path;
|
372b5963
Pavel Govyadinov
added support for...
|
50
51
|
GLuint texID; //OpenGL object
GLenum texture_type; //1D, 2D, 3D
|
b710b044
Pavel Govyadinov
Added more tempor...
|
52
53
54
55
|
GLint interpType;
GLint texWrap;
GLenum type;
GLenum format;
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
56
|
using image_stack<T>::R;
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
57
|
using image_stack<T>::S;
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
58
59
|
using image_stack<T>::ptr;
using image_stack<T>::samples;
|
197e13de
Pavel Govyadinov
Added new class g...
|
60
61
62
|
public:
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
63
64
|
///Method: Basic Constructor
/// Creates an instance of the gl_texture object.
|
372b5963
Pavel Govyadinov
added support for...
|
65
66
|
gl_texture()
{
|
b710b044
Pavel Govyadinov
Added more tempor...
|
67
|
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
68
|
}
|
197e13de
Pavel Govyadinov
Added new class g...
|
69
|
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
70
71
72
|
///Method: Path Constructor
///@param string file_path path to the directory with the files.
/// Creates an instance of the gl_texture object with a path to the data.
|
372b5963
Pavel Govyadinov
added support for...
|
73
|
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
74
75
|
gl_texture(std::string file_path)
{
|
197e13de
Pavel Govyadinov
Added new class g...
|
76
|
path = file_path;
|
372b5963
Pavel Govyadinov
added support for...
|
77
78
|
image_stack<T>::load_images(path.append("/*.jpg"));
setTextureType();
|
197e13de
Pavel Govyadinov
Added new class g...
|
79
|
}
|
b710b044
Pavel Govyadinov
Added more tempor...
|
80
81
82
83
84
85
86
87
|
///Method:getSize
///returns the dimentions of
vec<int>
getSize()
{
stim::vec<int> size(R[1], R[2], R[3]);
return size;
}
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
88
|
|
b710b044
Pavel Govyadinov
Added more tempor...
|
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
///Method:setTexParam
///@param GLint interp --GL_LINEAR, GL_NEAREST...
///@param GLint twrap --GL_REPEAR, GL_CLAMP_TO_EDGE...
///@param GLenum dataType --GL_UNSIGNED_BYTE, GL_FLOAT16...
///@param GLenum dataFormat--GL_LUMINANCE, GL_RGB...
/// Texture paramenters.
void
setTexParam(GLint interp = GL_LINEAR,
GLint twrap = GL_CLAMP_TO_EDGE,
GLenum dataType = GL_UNSIGNED_BYTE,
GLenum dataFormat = GL_LUMINANCE)
{
interpType = interp;
texWrap = twrap;
type = dataType;
format = dataFormat;
}
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
///Method:setDims
///@param x size of the voxel in x direction
///@param y size of the voxel in y direction
///@param z size of the voxel in z direction
/// Sets the dimenstions of the voxels.
void
setDims(float x, float y, float z)
{
S[1] = x;
S[2] = y;
S[3] = z;
}
///Method:getDims
/// get the dimenstions of the voxels.
vec<float>
getDims()
{
vec<float> dims(S[1], S[2], S[3]);
return dims;
}
///Method:setPath
///@param file_Path location of the directory with the files
/// Sets the path and calls the loader on that path.
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
133
|
|
197e13de
Pavel Govyadinov
Added new class g...
|
134
135
136
137
|
void
setPath(std::string file_path)
{
path = file_path;
|
372b5963
Pavel Govyadinov
added support for...
|
138
139
|
image_stack<T>::load_images(path.append("/*.jpg"));
setTextureType();
|
197e13de
Pavel Govyadinov
Added new class g...
|
140
141
|
}
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
142
143
144
|
///Method: getPath
///Outputs: string path
/// Returns the path associated with an instance of the gl_texture class.
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
145
|
|
197e13de
Pavel Govyadinov
Added new class g...
|
146
147
148
149
150
|
std::string
getPath()
{
return path;
}
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
151
|
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
152
153
154
155
|
///Method: getTexture
///Outputs: GLuint texID
/// Returns the id of the texture create by/associated with the
/// instance of the gl_texture class.
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
156
|
|
197e13de
Pavel Govyadinov
Added new class g...
|
157
|
GLuint
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
158
|
getTexture()
|
197e13de
Pavel Govyadinov
Added new class g...
|
159
|
{
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
160
|
return texID;
|
197e13de
Pavel Govyadinov
Added new class g...
|
161
|
}
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
162
163
164
165
|
///Method: createTexture
/// Creates a texture and from the loaded data and
/// assigns that texture to texID
|
372b5963
Pavel Govyadinov
added support for...
|
166
167
168
169
|
//TO DO :::: 1D textures
//TO DO:::add methods for handling the cases of T
// and convert them to GL equivalent.
// i.e. an overloaded function that handles paramenter conversion.
|
197e13de
Pavel Govyadinov
Added new class g...
|
170
171
172
|
void
createTexture()
{
|
154fe135
Pavel Govyadinov
fixed some bad co...
|
173
174
175
176
177
|
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glGenTextures(1, &texID);
glBindTexture(texture_type, texID);
glTexParameteri(texture_type,
GL_TEXTURE_MIN_FILTER,
|
b710b044
Pavel Govyadinov
Added more tempor...
|
178
|
interpType);
|
154fe135
Pavel Govyadinov
fixed some bad co...
|
179
180
|
glTexParameteri(texture_type,
GL_TEXTURE_MAG_FILTER,
|
b710b044
Pavel Govyadinov
Added more tempor...
|
181
|
interpType);
|
372b5963
Pavel Govyadinov
added support for...
|
182
183
|
switch(texture_type)
{
|
372b5963
Pavel Govyadinov
added support for...
|
184
185
|
case GL_TEXTURE_3D:
glTexParameteri(texture_type,
|
b710b044
Pavel Govyadinov
Added more tempor...
|
186
|
GL_TEXTURE_WRAP_S,texWrap);
|
5e7c7581
Pavel Govyadinov
Debugging build f...
|
187
188
|
// GL_REPEAT);
// GL_CLAMP_TO_EDGE);
|
372b5963
Pavel Govyadinov
added support for...
|
189
|
glTexParameteri(texture_type,
|
b710b044
Pavel Govyadinov
Added more tempor...
|
190
|
GL_TEXTURE_WRAP_T,texWrap);
|
5e7c7581
Pavel Govyadinov
Debugging build f...
|
191
192
|
// GL_REPEAT);
// GL_CLAMP_TO_EDGE);
|
372b5963
Pavel Govyadinov
added support for...
|
193
|
glTexParameteri(texture_type,
|
b710b044
Pavel Govyadinov
Added more tempor...
|
194
|
GL_TEXTURE_WRAP_R,texWrap);
|
5e7c7581
Pavel Govyadinov
Debugging build f...
|
195
196
|
// GL_REPEAT);
// GL_CLAMP_TO_EDGE);
|
372b5963
Pavel Govyadinov
added support for...
|
197
198
199
200
201
202
203
204
|
glTexImage3D(texture_type,
0,
// GL_RGB16,
1,
R[1],
R[2],
R[3],
0,
|
b710b044
Pavel Govyadinov
Added more tempor...
|
205
206
|
format,
type,
|
372b5963
Pavel Govyadinov
added support for...
|
207
208
209
210
211
212
|
ptr);
//GL_UNSIGNED_BYTE can be TYPES, convert to GL equivalents
glPixelStorei(GL_PACK_ALIGNMENT,1);
break;
case GL_TEXTURE_2D:
glTexParameteri(texture_type,
|
b710b044
Pavel Govyadinov
Added more tempor...
|
213
|
GL_TEXTURE_WRAP_S, texWrap);
|
372b5963
Pavel Govyadinov
added support for...
|
214
|
glTexParameteri(texture_type,
|
b710b044
Pavel Govyadinov
Added more tempor...
|
215
|
GL_TEXTURE_WRAP_T, texWrap);
|
372b5963
Pavel Govyadinov
added support for...
|
216
217
218
219
220
221
|
glTexImage2D(texture_type,
0,
1,
R[1],
R[2],
0,
|
b710b044
Pavel Govyadinov
Added more tempor...
|
222
223
|
format,
type,
|
372b5963
Pavel Govyadinov
added support for...
|
224
225
|
ptr);
break;
|
372b5963
Pavel Govyadinov
added support for...
|
226
|
}
|
197e13de
Pavel Govyadinov
Added new class g...
|
227
|
}
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
228
229
|
///Temporary methods for debugging and testing are below.
///Self-explanatory.
|
63fcb5c8
Pavel Govyadinov
added some tempor...
|
230
231
232
233
234
235
236
|
T*
getData()
{
return ptr;
}
|
197e13de
Pavel Govyadinov
Added new class g...
|
237
|
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
238
|
};
|
197e13de
Pavel Govyadinov
Added new class g...
|
239
240
241
242
243
244
245
246
|
}
#endif
|