rts_glRenderableDTGrid.cpp
7.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#include "rts_glRenderableDTGrid.h"
/*ITERATOR INITIALIZATION*/
void rts_glRenderableDTGrid::init_iter_ppp()
{
m_iterator = begin();
m_iter_type = PPP;
}
void rts_glRenderableDTGrid::init_iter_nnn()
{
m_iterator = last();
m_iter_type = NNN;
}
void rts_glRenderableDTGrid::init_iter_ppn()
{
m_iterator = begin(); //put the iterator at the beginning of the data set
if(m_iterator.grid->acc.size() > 1) //if there is more than one pcolumn
{
m_iterator.loc.iv = m_iterator.grid->proj2D.value[1].to_value - 1;
m_iterator.loc.z = zCoord[m_iterator.grid->proj2D.value[1].to_coord - 1];
}
else
{
m_iterator.loc.iv = value.size() - 1;
m_iterator.loc.z = zCoord.back();
}
m_iter_type = PPN;
}
void rts_glRenderableDTGrid::init_iter_npp()
{
//set the 1D iterator location
m_iterator.Iterator2D.Iterator1D.loc.iv = proj2D.proj1D.value.size()-1; //start at the last 1D p-column
m_iterator.Iterator2D.Iterator1D.loc.ic = proj2D.proj1D.xCoord.size() - 2;
m_iterator.Iterator2D.Iterator1D.loc.x = proj2D.proj1D.xCoord[m_iterator.Iterator2D.Iterator1D.loc.ic+1];
m_iterator.Iterator2D.Iterator1D.value = proj2D.proj1D.value[m_iterator.Iterator2D.Iterator1D.loc.iv];
m_iterator.Iterator2D.Iterator1D.grid = &(proj2D.proj1D);
//set the 2D iterator location
m_iterator.Iterator2D.loc.iv = proj2D.proj1D.value[m_iterator.Iterator2D.Iterator1D.loc.iv].to_value;
m_iterator.Iterator2D.loc.ic = proj2D.proj1D.value[m_iterator.Iterator2D.Iterator1D.loc.iv].to_coord;
m_iterator.Iterator2D.loc.y = proj2D.yCoord[m_iterator.Iterator2D.loc.ic];
m_iterator.Iterator2D.value = proj2D.value[m_iterator.Iterator2D.loc.iv];
m_iterator.Iterator2D.grid = &(proj2D);
//set the 3D iterator location
m_iterator.loc.iv = proj2D.value[m_iterator.Iterator2D.loc.iv].to_value;
m_iterator.loc.ic = proj2D.value[m_iterator.Iterator2D.loc.iv].to_coord;
m_iterator.loc.z = zCoord[m_iterator.loc.ic];
m_iterator.value = value[m_iterator.loc.iv];
m_iterator.grid = this;
m_iter_type = NPP;
}
void rts_glRenderableDTGrid::iter_next_npp()
{
//if we are at the end of a p-column
if(m_iterator.loc.iv == value.size() - 1 || //if we are at the end of the last p-column or
(m_iterator.Iterator2D.loc.iv != m_iterator.grid->proj2D.value.size() - 1 &&
m_iterator.loc.iv == proj2D.value[m_iterator.Iterator2D.loc.iv + 1].to_value - 1)) //we are at the end of a p-column
{
iter_next_npx(m_iterator.Iterator2D); //increment the 2D iterator
m_iterator.loc.iv = proj2D.value[m_iterator.Iterator2D.loc.iv].to_value;
m_iterator.loc.ic = proj2D.value[m_iterator.Iterator2D.loc.iv].to_coord;
m_iterator.loc.z = zCoord[m_iterator.loc.ic];
}
//if we are at the end of a connected component
else if(m_iterator.loc.z == zCoord[m_iterator.loc.ic+1])
{
m_iterator.loc.iv++;
m_iterator.loc.ic+=2;
m_iterator.loc.z = zCoord[m_iterator.loc.ic];
}
//else if we are in a p-column
else
{
m_iterator.loc.iv++;
m_iterator.loc.z++;
}
m_iterator.value = value[m_iterator.loc.iv];
}
void rts_glRenderableDTGrid::iter_next_ppn()
{
//if we are at the beginning of a p-column
if(m_iterator.loc.z == zCoord[m_iterator.loc.ic] &&
m_iterator.loc.ic == proj2D.value[m_iterator.Iterator2D.loc.iv].to_coord)
{
m_iterator.Iterator2D.increment(); //move to the next p-column
if(m_iterator.Iterator2D.loc.iv >= proj2D.value.size()) //return
return;
//now update the 3D locator
if(m_iterator.Iterator2D.loc.iv == proj2D.value.size() - 1) //if this is the last p-column
{
m_iterator.loc.iv = value.size() - 1;
m_iterator.loc.ic = zCoord.size() - 2;
m_iterator.loc.z = zCoord.back();
}
else
{
m_iterator.loc.iv = proj2D.value[m_iterator.Iterator2D.loc.iv+1].to_value - 1;
m_iterator.loc.ic = proj2D.value[m_iterator.Iterator2D.loc.iv+1].to_coord - 2;
m_iterator.loc.z = zCoord[m_iterator.loc.ic + 1];
}
}
//if we are at the beginning of a connected component
else if(m_iterator.loc.z == zCoord[m_iterator.loc.ic])
{
m_iterator.loc.iv-=1;
m_iterator.loc.ic-=2;
m_iterator.loc.z = zCoord[m_iterator.loc.ic + 1];
}
//if we're in the middle of a connected component
else
{
m_iterator.loc.iv--;
m_iterator.loc.z--;
}
m_iterator.value = value[m_iterator.loc.iv];
}
void rts_glRenderableDTGrid::iter_next_npx(rtsDTGrid2D<IndexPair>::iterator &i2d)
{
//if we are at the end of a p-column
if(i2d.loc.iv == i2d.grid->value.size() - 1 || //if this is the last p-column
(i2d.Iterator1D.loc.iv != i2d.grid->proj1D.value.size() - 1 && //we are not in the last p-column and
i2d.loc.iv == i2d.grid->proj1D.value[i2d.Iterator1D.loc.iv+1].to_value - 1))
{
//if(i2d.Iterator1D.loc.iv == 0) //if it is the first p-column
// return;
i2d.Iterator1D.decrement(); //decrement the 1D iterator
//update the 2D locator
i2d.loc.iv = i2d.grid->proj1D.value[i2d.Iterator1D.loc.iv].to_value;
i2d.loc.ic = i2d.grid->proj1D.value[i2d.Iterator1D.loc.iv].to_coord;
i2d.loc.y = i2d.grid->yCoord[i2d.loc.ic];
}
//if we are at the end of a connected component
else if(i2d.loc.y == i2d.grid->yCoord[i2d.loc.ic+1])
{
i2d.loc.iv++;
i2d.loc.ic+=2;
i2d.loc.y = i2d.grid->yCoord[i2d.loc.ic];
}
else
{
i2d.loc.iv++;
i2d.loc.y++;
}
//set value
i2d.value = i2d.grid->value[i2d.loc.iv];
}
void rts_glRenderableDTGrid::iter_next()
{
if(m_iter_type == PPP)
m_iterator.increment();
if(m_iter_type == NNN)
m_iterator.decrement();
if(m_iter_type == PPN)
iter_next_ppn();
if(m_iter_type == NPP)
iter_next_npp();
}
void rts_glRenderableDTGrid::RenderPoints(unsigned int size, float camera_x, float camera_y, float camera_z)
{
/*This function renders a single point to the screen for each voxel in the
DT-Grid.
*/
//determine which directions to iterate
if(camera_x > 0)
{
if(camera_y > 0)
{
if(camera_z > 0)
{
//cout<<"+++"<<endl;
init_iter_ppp();
}
else
{
//cout<<"++-"<<endl;
init_iter_ppn();
}
}
else
{
if(camera_z > 0)
{
//cout<<"+-+"<<endl;
init_iter_ppp();
}
else
{
//cout<<"+--"<<endl;
init_iter_ppp();
}
}
}
else
{
if(camera_y > 0)
{
if(camera_z > 0)
{
//cout<<"-++"<<endl;
init_iter_npp();
}
else
{
//cout<<"-+-"<<endl;
init_iter_nnn();
}
}
else
{
if(camera_z > 0)
{
//cout<<"--+"<<endl;
init_iter_nnn();
}
else
{
//cout<<"---"<<endl;
init_iter_nnn();
}
}
}
//init_iter_npp();
glPointSize(3);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBegin(GL_POINTS); //render voxels as points
unsigned int i;
unsigned int num_values = value.size();
for(i=0; i<num_values; i++)
{
glColor4f(m_iterator.value.r, m_iterator.value.g, m_iterator.value.b, m_iterator.value.a);
glVertex3f(m_iterator.getX()/(float)MaxX(), m_iterator.getY()/(float)MaxY(), m_iterator.getZ()/(float)MaxZ());
//cout<<"("<<m_iterator.getX()<<","<<m_iterator.getY()<<","<<m_iterator.getZ()<<"):"<<m_iterator.value<<endl;
iter_next();
}
//cout<<"---------------------------------------"<<endl;
i=0;
glEnd();
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
}