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
37
|
///Method: setTextureType
/// Sets the internal texture_type, based on the data
/// size. Either 3D, 2D, 1D textures.
|
372b5963
Pavel Govyadinov
added support for...
|
38
39
40
41
42
43
44
45
46
47
48
|
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...
|
49
|
protected:
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
50
|
std::string path;
|
372b5963
Pavel Govyadinov
added support for...
|
51
52
|
GLuint texID; //OpenGL object
GLenum texture_type; //1D, 2D, 3D
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
53
|
using image_stack<T>::R;
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
54
|
using image_stack<T>::S;
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
55
56
|
using image_stack<T>::ptr;
using image_stack<T>::samples;
|
197e13de
Pavel Govyadinov
Added new class g...
|
57
58
59
|
public:
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
60
61
|
///Method: Basic Constructor
/// Creates an instance of the gl_texture object.
|
372b5963
Pavel Govyadinov
added support for...
|
62
63
64
|
gl_texture()
{
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
65
|
}
|
197e13de
Pavel Govyadinov
Added new class g...
|
66
|
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
67
68
69
|
///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...
|
70
|
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
71
72
|
gl_texture(std::string file_path)
{
|
197e13de
Pavel Govyadinov
Added new class g...
|
73
|
path = file_path;
|
372b5963
Pavel Govyadinov
added support for...
|
74
75
|
image_stack<T>::load_images(path.append("/*.jpg"));
setTextureType();
|
197e13de
Pavel Govyadinov
Added new class g...
|
76
|
}
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
77
|
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
///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...
|
106
|
|
197e13de
Pavel Govyadinov
Added new class g...
|
107
108
109
110
|
void
setPath(std::string file_path)
{
path = file_path;
|
372b5963
Pavel Govyadinov
added support for...
|
111
112
|
image_stack<T>::load_images(path.append("/*.jpg"));
setTextureType();
|
197e13de
Pavel Govyadinov
Added new class g...
|
113
114
|
}
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
115
116
117
|
///Method: getPath
///Outputs: string path
/// Returns the path associated with an instance of the gl_texture class.
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
118
|
|
197e13de
Pavel Govyadinov
Added new class g...
|
119
120
121
122
123
|
std::string
getPath()
{
return path;
}
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
124
|
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
125
126
127
128
|
///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...
|
129
|
|
197e13de
Pavel Govyadinov
Added new class g...
|
130
|
GLuint
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
131
|
getTexture()
|
197e13de
Pavel Govyadinov
Added new class g...
|
132
|
{
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
133
|
return texID;
|
197e13de
Pavel Govyadinov
Added new class g...
|
134
|
}
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
135
136
137
138
|
///Method: createTexture
/// Creates a texture and from the loaded data and
/// assigns that texture to texID
|
372b5963
Pavel Govyadinov
added support for...
|
139
140
141
142
|
//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...
|
143
144
145
|
void
createTexture()
{
|
154fe135
Pavel Govyadinov
fixed some bad co...
|
146
147
148
149
150
151
152
153
154
|
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glGenTextures(1, &texID);
glBindTexture(texture_type, texID);
glTexParameteri(texture_type,
GL_TEXTURE_MIN_FILTER,
GL_LINEAR);
glTexParameteri(texture_type,
GL_TEXTURE_MAG_FILTER,
GL_LINEAR);
|
372b5963
Pavel Govyadinov
added support for...
|
155
156
|
switch(texture_type)
{
|
372b5963
Pavel Govyadinov
added support for...
|
157
158
|
case GL_TEXTURE_3D:
glTexParameteri(texture_type,
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
159
|
GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
372b5963
Pavel Govyadinov
added support for...
|
160
|
glTexParameteri(texture_type,
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
161
|
GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
372b5963
Pavel Govyadinov
added support for...
|
162
|
glTexParameteri(texture_type,
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
163
|
GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
372b5963
Pavel Govyadinov
added support for...
|
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
glTexImage3D(texture_type,
0,
// GL_RGB16,
1,
R[1],
R[2],
R[3],
0,
GL_LUMINANCE,
GL_UNSIGNED_BYTE,
ptr);
//GL_UNSIGNED_BYTE can be TYPES, convert to GL equivalents
glPixelStorei(GL_PACK_ALIGNMENT,1);
break;
case GL_TEXTURE_2D:
glTexParameteri(texture_type,
GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(texture_type,
GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexImage2D(texture_type,
0,
1,
R[1],
R[2],
0,
GL_LUMINANCE,
GL_UNSIGNED_BYTE,
ptr);
break;
|
372b5963
Pavel Govyadinov
added support for...
|
193
|
}
|
197e13de
Pavel Govyadinov
Added new class g...
|
194
|
}
|
385d2447
Pavel Govyadinov
Checkpoint: Conve...
|
195
196
|
///Temporary methods for debugging and testing are below.
///Self-explanatory.
|
63fcb5c8
Pavel Govyadinov
added some tempor...
|
197
198
199
200
201
202
203
|
T*
getData()
{
return ptr;
}
|
197e13de
Pavel Govyadinov
Added new class g...
|
204
|
|
197e13de
Pavel Govyadinov
Added new class g...
|
205
|
|
a4042c24
Pavel Govyadinov
Updated the gl_te...
|
206
|
};
|
197e13de
Pavel Govyadinov
Added new class g...
|
207
208
209
210
211
212
213
214
|
}
#endif
|