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
|
/// Sets the internal texture_type, based on the data
/// size. Either 3D, 2D, 1D textures.
|
035d798f
Pavel Govyadinov
modified the spid...
|
36
|
|
372b5963
Pavel Govyadinov
added support for...
|
37
38
39
40
41
42
43
44
45
46
|
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...
|
47
|
protected:
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
48
|
std::string path;
|
372b5963
Pavel Govyadinov
added support for...
|
49
50
|
GLuint texID; //OpenGL object
GLenum texture_type; //1D, 2D, 3D
|
b710b044
Pavel Govyadinov
Added more tempor...
|
51
52
53
54
|
GLint interpType;
GLint texWrap;
GLenum type;
GLenum format;
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
55
|
using image_stack<T>::R;
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
56
|
using image_stack<T>::S;
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
57
58
|
using image_stack<T>::ptr;
using image_stack<T>::samples;
|
197e13de
Pavel Govyadinov
Added new class g...
|
59
60
61
|
public:
|
035d798f
Pavel Govyadinov
modified the spid...
|
62
|
///default constructor
|
372b5963
Pavel Govyadinov
added support for...
|
63
64
|
gl_texture()
{
|
b710b044
Pavel Govyadinov
Added more tempor...
|
65
|
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
66
|
}
|
197e13de
Pavel Govyadinov
Added new class g...
|
67
|
|
035d798f
Pavel Govyadinov
modified the spid...
|
68
69
|
///@param string path to the directory with the image files.
///Creates an instance of the gl_texture object with a path to the data.
|
372b5963
Pavel Govyadinov
added support for...
|
70
|
|
34ec8a82
David Mayerich
added comments
|
71
|
gl_texture(std::string file_mask)
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
72
|
{
|
34ec8a82
David Mayerich
added comments
|
73
74
|
//path = file_mask;
image_stack<T>::load_images(file_mask);
|
372b5963
Pavel Govyadinov
added support for...
|
75
|
setTextureType();
|
197e13de
Pavel Govyadinov
Added new class g...
|
76
|
}
|
035d798f
Pavel Govyadinov
modified the spid...
|
77
78
|
///returns the dimentions of the data in the x, y, z directions.
|
b710b044
Pavel Govyadinov
Added more tempor...
|
79
80
81
82
83
84
|
vec<int>
getSize()
{
stim::vec<int> size(R[1], R[2], R[3]);
return size;
}
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
85
|
|
b710b044
Pavel Govyadinov
Added more tempor...
|
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
///@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;
}
|
035d798f
Pavel Govyadinov
modified the spid...
|
102
|
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
103
104
105
106
107
108
109
110
111
112
113
114
|
///@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;
}
|
035d798f
Pavel Govyadinov
modified the spid...
|
115
|
///Returns a stim::vec that contains the x, y, z sizes of the voxel.
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
116
117
118
119
120
121
122
|
vec<float>
getDims()
{
vec<float> dims(S[1], S[2], S[3]);
return dims;
}
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
123
124
|
///@param file_Path location of the directory with the files
/// Sets the path and calls the loader on that path.
|
197e13de
Pavel Govyadinov
Added new class g...
|
125
126
127
128
|
void
setPath(std::string file_path)
{
path = file_path;
|
372b5963
Pavel Govyadinov
added support for...
|
129
130
|
image_stack<T>::load_images(path.append("/*.jpg"));
setTextureType();
|
197e13de
Pavel Govyadinov
Added new class g...
|
131
132
|
}
|
035d798f
Pavel Govyadinov
modified the spid...
|
133
|
/// Returns an std::string path associated with an instance of the gl_texture class.
|
197e13de
Pavel Govyadinov
Added new class g...
|
134
135
136
137
138
|
std::string
getPath()
{
return path;
}
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
139
|
|
035d798f
Pavel Govyadinov
modified the spid...
|
140
|
/// Returns the GLuint id of the texture created by/associated with the
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
141
|
/// instance of the gl_texture class.
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
142
|
|
197e13de
Pavel Govyadinov
Added new class g...
|
143
|
GLuint
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
144
|
getTexture()
|
197e13de
Pavel Govyadinov
Added new class g...
|
145
|
{
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
146
|
return texID;
|
197e13de
Pavel Govyadinov
Added new class g...
|
147
|
}
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
148
|
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
149
150
|
/// Creates a texture and from the loaded data and
/// assigns that texture to texID
|
372b5963
Pavel Govyadinov
added support for...
|
151
152
153
154
|
//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...
|
155
156
157
|
void
createTexture()
{
|
154fe135
Pavel Govyadinov
fixed some bad co...
|
158
159
160
161
162
|
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...
|
163
|
interpType);
|
154fe135
Pavel Govyadinov
fixed some bad co...
|
164
165
|
glTexParameteri(texture_type,
GL_TEXTURE_MAG_FILTER,
|
b710b044
Pavel Govyadinov
Added more tempor...
|
166
|
interpType);
|
372b5963
Pavel Govyadinov
added support for...
|
167
168
|
switch(texture_type)
{
|
372b5963
Pavel Govyadinov
added support for...
|
169
170
|
case GL_TEXTURE_3D:
glTexParameteri(texture_type,
|
b710b044
Pavel Govyadinov
Added more tempor...
|
171
|
GL_TEXTURE_WRAP_S,texWrap);
|
5e7c7581
Pavel Govyadinov
Debugging build f...
|
172
173
|
// GL_REPEAT);
// GL_CLAMP_TO_EDGE);
|
372b5963
Pavel Govyadinov
added support for...
|
174
|
glTexParameteri(texture_type,
|
b710b044
Pavel Govyadinov
Added more tempor...
|
175
|
GL_TEXTURE_WRAP_T,texWrap);
|
5e7c7581
Pavel Govyadinov
Debugging build f...
|
176
177
|
// GL_REPEAT);
// GL_CLAMP_TO_EDGE);
|
372b5963
Pavel Govyadinov
added support for...
|
178
|
glTexParameteri(texture_type,
|
b710b044
Pavel Govyadinov
Added more tempor...
|
179
|
GL_TEXTURE_WRAP_R,texWrap);
|
5e7c7581
Pavel Govyadinov
Debugging build f...
|
180
181
|
// GL_REPEAT);
// GL_CLAMP_TO_EDGE);
|
372b5963
Pavel Govyadinov
added support for...
|
182
183
184
185
186
187
188
189
|
glTexImage3D(texture_type,
0,
// GL_RGB16,
1,
R[1],
R[2],
R[3],
0,
|
b710b044
Pavel Govyadinov
Added more tempor...
|
190
191
|
format,
type,
|
372b5963
Pavel Govyadinov
added support for...
|
192
193
194
195
196
197
|
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...
|
198
|
GL_TEXTURE_WRAP_S, texWrap);
|
372b5963
Pavel Govyadinov
added support for...
|
199
|
glTexParameteri(texture_type,
|
b710b044
Pavel Govyadinov
Added more tempor...
|
200
|
GL_TEXTURE_WRAP_T, texWrap);
|
372b5963
Pavel Govyadinov
added support for...
|
201
202
203
204
205
206
|
glTexImage2D(texture_type,
0,
1,
R[1],
R[2],
0,
|
b710b044
Pavel Govyadinov
Added more tempor...
|
207
208
|
format,
type,
|
372b5963
Pavel Govyadinov
added support for...
|
209
210
|
ptr);
break;
|
372b5963
Pavel Govyadinov
added support for...
|
211
|
}
|
197e13de
Pavel Govyadinov
Added new class g...
|
212
|
}
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
213
214
|
///Temporary methods for debugging and testing are below.
///Self-explanatory.
|
63fcb5c8
Pavel Govyadinov
added some tempor...
|
215
216
217
218
219
220
221
|
T*
getData()
{
return ptr;
}
|
197e13de
Pavel Govyadinov
Added new class g...
|
222
|
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
223
|
};
|
197e13de
Pavel Govyadinov
Added new class g...
|
224
225
226
227
228
229
230
231
|
}
#endif
|