38#ifndef GL_GLEXT_PROTOTYPES
39 #define GL_GLEXT_PROTOTYPES
48 #include "OpenGL/gl.h"
49 #include "OpenGL/glu.h"
50 #include "OpenGL/glext.h"
60GLuint GLUtil::buffer[2] = {0, 0};
62unsigned int GLUtil::gen_glu_mipmaps(
const EMData*
const emdata)
64 if (emdata->get_data() == 0) {
66 "without internally stored data");
71 unsigned int tex_name;
72 glGenTextures(1, &tex_name);
74 if (emdata->
ny == 1 && emdata->
nz == 1) {
75 glBindTexture(GL_TEXTURE_1D, tex_name);
76 gluBuild1DMipmaps(GL_TEXTURE_1D, GL_LUMINANCE, emdata->
nx, GL_LUMINANCE,
77 GL_FLOAT, (
void*)(emdata->get_data()));
78 }
else if (emdata->
nz == 1) {
79 glBindTexture(GL_TEXTURE_2D, tex_name);
80 gluBuild2DMipmaps(GL_TEXTURE_2D, GL_LUMINANCE, emdata->
nx, emdata->
ny,
81 GL_LUMINANCE, GL_FLOAT, (
void*)(emdata->get_data()));
87 printf(
"3D OpenGL mipmaps are not available on this platform.\n");
89 glBindTexture(GL_TEXTURE_3D, tex_name);
90 gluBuild3DMipmaps(GL_TEXTURE_3D, GL_LUMINANCE, emdata->
nx, emdata->
ny,
91 emdata->
nz, GL_LUMINANCE, GL_FLOAT, (
void*)(emdata->get_data()));
102 if (emdata->get_data() == 0) {
104 " without internally stored data");
109 unsigned int tex_name;
110 glGenTextures(1, &tex_name);
112 if (emdata->
ny == 1 && emdata->
nz == 1) {
113 glBindTexture(GL_TEXTURE_1D, tex_name);
114 glTexImage1D(GL_TEXTURE_1D, 0, format, emdata->
nx, 0, format, GL_FLOAT,
115 (
void*)(emdata->get_data()));
116 }
else if (emdata->
nz == 1) {
117 glBindTexture(GL_TEXTURE_2D, tex_name);
118 glTexImage2D(GL_TEXTURE_2D, 0, format, emdata->
nx, emdata->
ny, 0, format,
119 GL_FLOAT, (
void*)(emdata->get_data()));
122 glBindTexture(GL_TEXTURE_3D, tex_name);
124 PFNGLTEXIMAGE3DPROC glTexImage3D;
126 glTexImage3D(GL_TEXTURE_3D, 0, format,
127 emdata->
nx, emdata->
ny, emdata->
nz, 0, format, GL_FLOAT,
128 (
void*)(emdata->get_data()));
137 int x0,
int y0,
int ixsize,
int iysize,
int bpl,
float scale,
138 int mingray,
int maxgray,
float render_min,
float render_max,
139 float gamma,
int flags)
141 if (emdata==NULL)
return 9999999;
142 string pixels =
render_amp8(emdata, x0, y0, ixsize,iysize, bpl, scale,
143 mingray, maxgray, render_min, render_max, gamma, flags);
145 unsigned int tex_name;
146 glGenTextures(1, &tex_name);
148 glBindTexture(GL_TEXTURE_2D, tex_name);
149 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, ixsize, iysize , 0,
150 GL_LUMINANCE, GL_UNSIGNED_BYTE, pixels.c_str());
157#ifdef GL_GLEXT_PROTOTYPES
158#undef GL_GLEXT_PROTOTYPES
162 const vector<float>& proj_matrix,
const vector<int>& view_matrix,
163 const vector<Vec3f>& points,
const float mouse_x,
const float mouse_y,
164 const float& nearness)
170 copy(proj_matrix.begin(), proj_matrix.end(), proj);
171 copy(model_matrix.begin(), model_matrix.end(), model);
172 copy(view_matrix.begin(), view_matrix.end(), view);
174 vector<Vec3f> unproj_points;
178 for (vector<Vec3f>::const_iterator it = points.begin(); it != points.end(); ++it) {
179 r = (double) (*it)[0];
180 s = (double) (*it)[1];
181 t = (double) (*it)[2];
183 gluProject(r,s,t, model, proj, view, &
x, &
y, &z);
184 unproj_points.push_back(
Vec3f(
x,
y, z));
187 vector<int> intersections;
189 float n_squared = nearness * nearness;
191 for(
unsigned int i = 0; i < unproj_points.size(); ++i) {
192 Vec3f& v = unproj_points[i];
193 float dx = v[0] - mouse_x;
195 float dy = v[1] - mouse_y;
198 if ((dx+dy) <= n_squared) intersections.push_back((
int)i);
201 int intersection = -1;
204 for(vector<int>::const_iterator it = intersections.begin(); it != intersections.end(); ++it) {
205 if (intersection == -1 || unproj_points[*it][2] < near_z) {
207 near_z = unproj_points[*it][2];
215 const float& alpha,
const bool center_point)
217 glBegin(GL_LINE_LOOP);
218 glColor4f(data[0], data[1], data[2], alpha);
219 glVertex2i(data[3], data[4]);
220 glVertex2i(data[5], data[4]);
221 glVertex2i(data[5], data[6]);
222 glVertex2i(data[3], data[6]);
227 glVertex2f( (data[3]+data[5])/2, (data[4]+data[6])/2);
233 const vector<float>& text_color,
const vector<float>& bg_color)
235 glDisable(GL_TEXTURE_2D);
238 if (bg_color.size() == 4) {
239 glColor4f(bg_color[0], bg_color[1], bg_color[2], bg_color[3]);
242 glColor3f(bg_color[0], bg_color[1], bg_color[2]);
245 glVertex3f(data[0]-1, data[1]-1, -.1f);
246 glVertex3f(data[3]+1, data[1]-1, -.1f);
247 glVertex3f(data[3]+1, data[4]+1, -.1f);
248 glVertex3f(data[0]-1, data[4]+1, -.1f);
253 if (text_color.size() == 4) {
254 glColor4f(text_color[0], text_color[1], text_color[2], text_color[3]);
257 glColor3f(text_color[0], text_color[1], text_color[2]);
262 int iysize,
int bpl,
float scale,
int min_gray,
int max_gray,
263 float render_min,
float render_max,
float gamma,
int flags)
271 if (emdata==NULL)
return EMBytes();
272 bool invert = (min_gray > max_gray);
273 int mingray, maxgray;
285 int hist = (flags & 2)/2;
286 int invy = (flags & 4)?1:0;
291 int nxy = emdata->
nx * emdata->
ny;
293 if (emdata->get_ndim() > 2) {
297 if (emdata->is_complex()) {
301 if (render_max <= render_min) {
302 render_max = render_min + 0.01f;
305 if (gamma <= 0) gamma = 1.0;
314 static int smg0 = 0, smg1 = 0;
316 static unsigned char gammamap[4096];
318 if (gamma != 1.0 && (smg0 != mingray || smg1 != maxgray || sgam != gamma)) {
319 for (
int i=0; i<4096; i++) {
320 if (mingray<maxgray) {
321 gammamap[i] = (
unsigned char)(mingray+(maxgray-mingray+0.999)*pow(((
float)i/4096.0f),gamma));
324 gammamap[4095-i] = (
unsigned char)(mingray+(maxgray-mingray+0.999)*pow(((
float)i/4096.0f),gamma));
332 if (flags & 8) asrgb = 4;
333 else if (flags & 1) asrgb = 3;
339 ret.assign(iysize*bpl + hist*1024,
char(invert ? maxgray : mingray));
341 unsigned char *data = (
unsigned char *)ret.data();
342 unsigned int *histd = (
unsigned int *)(data + iysize*bpl);
345 for (
int i=0; i<256; i++) histd[i]=0;
348 float rm = render_min;
349 float inv_scale = 1.0f / scale;
355 if (iysize * inv_scale > ny) {
356 ymin = (int) (iysize - ny / inv_scale);
359 float gs = (maxgray - mingray) / (render_max - render_min);
360 float gs2 = 4095.999f / (render_max - render_min);
363 if (render_max < render_min) {
372 const int scale_n = 100000;
377 if (inv_scale == floor(inv_scale)) {
378 dsx = (int) inv_scale;
379 dsy = (int) (inv_scale * nx);
382 addi = (int) floor(inv_scale);
383 addr = (int) (scale_n * (inv_scale - floor(inv_scale)));
389 xmin = (int) (-x0 / inv_scale);
390 xsize -= (int) floor(x0 / inv_scale);
394 if ((xsize - xmin) * inv_scale > (nx - x0)) {
395 xsize = (int) ((nx - x0) / inv_scale + xmin);
398 int ymax = ysize - 1;
401 ymax = (int) (ysize + y0 / inv_scale - 1);
402 ymin += (int) floor(y0 / inv_scale);
406 if (xmin < 0) xmin = 0;
407 if (ymin < 0) ymin = 0;
408 if (xsize > ixsize) xsize = ixsize;
409 if (ymax > iysize) ymax = iysize;
411 int lmax = nx * ny - 1;
414 float * image_data = emdata->get_data();
418 const int rangemax = 4082;
419 int gaussianwide = 5000;
420 unsigned int* grayhe = NULL;
421 float* gaussianpdf = NULL;
422 float* gaussiancdf = NULL;
423 int* gaussianlookup = NULL;
425 unsigned int* graypdftwo = NULL;
428 int binlocation = -1;
431 int graypdf[rangemax] = {0};
432 int graycdf[rangemax-2] = {0};
436 graypdftwo =
new unsigned int[maxgray-mingray];
437 grayhe =
new unsigned int[rangemax-2];
440 for (
int i=0; i<(int)(rangemax-2); i++) {
444 for (
int i=0; i<(maxgray-mingray); i++) {
449 int l = x0 + y0 * nx;
451 for (
int j = ymax; j >= ymin; j--) {
453 for (
int i = xmin; i < xsize; i++) {
462 if (dsx == 1) t=image_data[l];
466 if ((l+dsx+dsy) > lmax) {
470 for (
int iii=0; iii<dsx; iii++) {
471 for (
int jjj=0; jjj<dsy; jjj+=nx) {
472 t += image_data[l+iii+jjj];
479 if (t <= rm) graypdf[0]++;
480 else if (t >= render_max) graypdf[rangemax-1]++;
482 graypdf[(int)(ceil((rangemax-2)*(t - render_min)/(render_max-render_min)))]++;
483 graypdftwo[(
unsigned char) (gs * (t - render_min))]++;
493 int l = x0 + y0 * nx;
495 for (
int j = ymax; j >= ymin; j--) {
501 if ((l + addi*nx) >= nxy) {
504 if (addj <= 0)
continue;
510 for (
int i = xmin; i < xsize; i++) {
514 if (addi <= 1) t = image_data[l];
518 for (
int jjj=0; jjj<addj; jjj++) {
519 for (
int iii=0; iii<addi; iii++) {
520 t += image_data[l+iii+jjj*nx];
528 if (t <= rm) graypdf[0]++;
529 else if (t >= render_max) graypdf[rangemax-1]++;
531 graypdf[(int)(ceil((rangemax-2)*(t - render_min)/(render_max-render_min)))]++;
539 if (remx > scale_n) {
548 if (remy > scale_n) {
555 for (
int i=0; i<(rangemax-2); i++) {
556 for (
int j=0;j<(i+1);j++) {
557 graycdf[i]=graycdf[i]+graypdf[j+1];
564 for (
int i=1; i<(maxgray-mingray); i++) {
565 if (((
float)graypdftwo[i]/graycdf[rangemax-3])>0.2) {
574 for (
int i=(binlocation*16+1); i<((binlocation+1)*16); i++) {
579 for (
int i=0; i<(rangemax-2); i++) {
583 for (
int i=0; i<(rangemax-2); i++) {
584 for (
int j=0;j<(i+1);j++) {
585 graycdf[i] = graycdf[i]+graypdf[j+1];
591 float mean = abs(rangemax-2)/2;
592 float standdv = abs(mean)/3;
594 gaussianpdf =
new float[rangemax-2];
595 gaussiancdf =
new float[rangemax-2];
596 gaussianlookup =
new int[rangemax-2];
598 for (
int i=0; i<(rangemax-2); i++) {
599 gaussianpdf[i]=exp(-(i-mean)*(i-mean)/(2*standdv*standdv))/
sqrt(standdv * standdv * 2 * M_PI);
602 gaussiancdf[i] = gaussiancdf[i-1]+gaussianpdf[i];
605 gaussiancdf[i] = gaussianpdf[i];
609 for (
int i=0; i<(rangemax-2); i++) {
610 gaussiancdf[i] = graycdf[rangemax-3]*gaussiancdf[i]/gaussiancdf[rangemax-3];
613 for (
int i=0; i<(rangemax-2); i++) {
614 for (
int j=0; j<(rangemax-2); j++) {
615 if (graycdf[i] <= gaussiancdf[j]) {
616 gaussianlookup[i] = j;
622 for (
int i=0; i<(rangemax-2); i++) {
623 grayhe[i] = floor(0.5+(((
double)(rangemax-3)*graycdf[i])/graycdf[rangemax-3]));
628 if (emdata->is_complex()) {
632 for (
int j = ymax; j >= ymin; j--) {
635 for (
int i = xmin; i < xsize; i++) {
636 if (l + ll > lmax || ll >= nx - 2)
break;
642 if (l >= (ny - inv_scale) * nx) k = 2 * (ll - nx / 2) + 2;
643 else k = 2 * (ll - nx / 2) + l + 2 + nx;
645 else k = nx * ny - (l + 2 * ll) - 2;
647 if (k >= mid) k -= mid;
650 float t = image_data[k];
654 if (flags & 16 && asrgb>2) {
656 if (ll >= nx / 2) ph = (int)(image_data[k+1]*768/(2.0*M_PI))+384;
657 else ph = (int)(-image_data[k+1]*768/(2.0*M_PI))+384;
660 if (t <= rm) p = mingray;
661 else if (t >= render_max) p = maxgray;
662 else if (gamma != 1.0) {
663 k=(int)(gs2 * (t-render_min));
671 p = (
unsigned char) (gs * (t - render_min));
676 if (flags & 16 && asrgb>2) {
678 data[i * asrgb + j * bpl] = p*(255-ph)/256;
679 data[i * asrgb + j * bpl+1] = p*ph/256;
680 data[i * asrgb + j * bpl+2] = 0;
683 data[i * asrgb + j * bpl+1] = p*(511-ph)/256;
684 data[i * asrgb + j * bpl+2] = p*(ph-256)/256;
685 data[i * asrgb + j * bpl] = 0;
688 data[i * asrgb + j * bpl+2] = p*(767-ph)/256;
689 data[i * asrgb + j * bpl] = p*(ph-512)/256;
690 data[i * asrgb + j * bpl+1] = 0;
693 else data[i * asrgb + j * bpl] = p;
694 if (hist) histd[p]++;
705 for (
int j = ymax; j >= ymin; j--) {
710 for (
int i = xmin; i < xsize - 1; i++) {
711 if (l + ll > lmax || ll >= nx - 2) {
719 if (l >= (ny * nx - nx)) k = 2 * (ll - nx / 2) + 2;
720 else k = 2 * (ll - nx / 2) + l + 2 + nx;
722 else k = nx * ny - (l + 2 * ll) - 2;
724 if (k >= mid) k -= mid;
727 float t = image_data[k];
731 if (flags & 16 && asrgb>2) {
732 if (l >= (ny * nx - nx)) ph = (
int)(image_data[k+1]*768/(2.0*M_PI))+384;
733 else ph = (int)(-image_data[k+1]*768/(2.0*M_PI))+384;
738 else if (t >= render_max) {
741 else if (gamma != 1.0) {
742 k=(int)(gs2 * (t-render_min));
751 p = (
unsigned char) (gs * (t - render_min));
755 if (flags & 16 && asrgb>2) {
757 data[i * asrgb + j * bpl] = p*(255-ph)/256;
758 data[i * asrgb + j * bpl+1] = p*ph/256;
759 data[i * asrgb + j * bpl+2] = 0;
762 data[i * asrgb + j * bpl+1] = p*(511-ph)/256;
763 data[i * asrgb + j * bpl+2] = p*(ph-256)/256;
764 data[i * asrgb + j * bpl] = 0;
767 data[i * asrgb + j * bpl+2] = p*(767-ph)/256;
768 data[i * asrgb + j * bpl] = p*(ph-512)/256;
769 data[i * asrgb + j * bpl+1] = 0;
772 else data[i * asrgb + j * bpl] = p;
774 if (hist) histd[p]++;
779 if (remx > scale_n) {
788 if (remy > scale_n) {
797 int l = x0 + y0 * nx;
799 for (
int j = ymax; j >= ymin; j--) {
802 for (
int i = xmin; i < xsize; i++) {
811 if (dsx == 1) t=image_data[l];
815 if ((l+dsx+dsy) > lmax) {
819 for (
int iii=0; iii<dsx; iii++) {
820 for (
int jjj=0; jjj<dsy; jjj+=nx) {
821 t += image_data[l+iii+jjj];
828 if (t <= rm) p = mingray;
829 else if (t >= render_max) p = maxgray;
830 else if (gamma != 1.0) {
831 k=(int)(gs2 * (t-render_min));
844 p=(
unsigned char)(gaussianlookup[(
int)(floor((rangemax-2)*(t - render_min)/(render_max-render_min)))]*(maxgray-mingray-2)/(rangemax-3)+1);
847 p=(
unsigned char)(grayhe[(
int)((t - render_min)*(rangemax-3)/(render_max-render_min))]*(maxgray-mingray-2)/(rangemax-3)+1);}
852 p=(
unsigned char) (gs * (t - render_min));
859 p = mingray + maxgray - p;
862 data[i * asrgb + j * bpl] = p;
864 if (hist) histd[p]++;
874 int l = x0 + y0 * nx;
876 for (
int j = ymax; j >= ymin; j--) {
882 if ((l + addi*nx) >= nxy) {
885 if (addj <= 0)
continue;
891 for (
int i = xmin; i < xsize; i++) {
897 if (addi <= 1) t = image_data[l];
900 for (
int jjj=0; jjj<addj; jjj++) {
901 for (
int iii=0; iii<addi; iii++) {
902 t += image_data[l+iii+jjj*nx];
909 if (t <= rm) p = mingray;
910 else if (t >= render_max) p = maxgray;
911 else if (gamma != 1.0) {
912 k=(int)(gs2 * (t-render_min));
924 p = (
unsigned char)(gaussianlookup[(
int)(floor((rangemax-2)*(t - render_min)/(render_max-render_min)))]*(maxgray-mingray-2)/(rangemax-3)+1);
927 p = (
unsigned char)(grayhe[(
int)((t - render_min)*(rangemax-3)/(render_max-render_min))]*(maxgray-mingray-2)/(rangemax-3)+1);
933 p = (
unsigned char) (gs * (t - render_min));
940 p = mingray + maxgray - p;
943 data[i * asrgb + j * bpl] = p;
945 if (hist) histd[p]++;
950 if (remx > scale_n) {
959 if (remy > scale_n) {
968 if (asrgb == 3 && !(flags & 16)) {
969 for (
int j=ymin*bpl; j <= ymax*bpl; j+=bpl) {
970 for (
int i=xmin; i<xsize*3; i+=3) {
971 data[i+j+1] = data[i+j+2] = data[i+j];
976 if (asrgb == 4 && !(flags & 16)) {
977 for (
int j=ymin*bpl; j <= ymax*bpl; j+=bpl) {
978 for (
int i=xmin; i<xsize*4; i+=4) {
979 data[i+j+1] = data[i+j+2] = data[i+j+3] = data[i+j];
989 for (
int y=0;
y<iysize/2;
y++)
990 for (
int x=0;
x<ixsize;
x++)
991 std::swap(ret[
y*bpl+
x], ret[(iysize-
y-1)*bpl+
x]);
997 glDrawPixels(ixsize, iysize, GL_LUMINANCE, GL_UNSIGNED_BYTE,
998 (
const GLvoid *)ret.data());
1002 delete [] gaussianpdf;
1003 delete [] gaussiancdf;
1004 delete [] gaussianlookup;
1005 delete [] graypdftwo;
1013 unsigned int tex_id,
bool surface_face_z,
bool recontour)
1020#if MARCHING_CUBES_DEBUG
1021 cout <<
"There are " << ff.elem()/3 <<
" faces and " << pp.elem() <<
1022 " points and " << nn.elem() <<
" normals to render in generate dl" << endl;
1029 glGetIntegerv(GL_MAX_ELEMENTS_INDICES, & maxf);
1032#if MARCHING_CUBES_DEBUG
1034 glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, & maxv);
1036 cout <<
"Max vertices is " << maxv <<
" max indices is " << maxf << endl;
1037 cout <<
"Using OpenGL " << glGetString(GL_VERSION) << endl;
1041 for (
unsigned int i = 0; i < mc->
ff.elem(); ++i) mc->
ff[i] /= 3;
1044 if (maxf % 3 != 0) {
1045 maxf = maxf - (maxf%3);
1050 mc->
pp.mult3(1.0f/(
float) mc->
_emdata->get_xsize(),
1051 1.0f/(float)mc->
_emdata->get_ysize(),
1052 1.0f/(float)mc->
_emdata->get_zsize());
1053 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
1054 glDisableClientState(GL_NORMAL_ARRAY);
1055 glTexCoordPointer(3, GL_FLOAT, 0, mc->
pp.get_data());
1058 glEnableClientState(GL_NORMAL_ARRAY);
1059 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1060 glNormalPointer(GL_FLOAT, 0, mc->
nn.get_data());
1063 glEnableClientState(GL_VERTEX_ARRAY);
1064 glVertexPointer(3, GL_FLOAT, 0, mc->
pp.get_data());
1067 glEnableClientState(GL_COLOR_ARRAY);
1068 glColorPointer(3, GL_FLOAT, 0, mc->
cc.get_data());
1071 mc->
_isodl = glGenLists(1);
1073#if MARCHING_CUBES_DEBUG
1074 int time0 = clock();
1077 glNewList(mc->
_isodl,GL_COMPILE);
1080 glEnable(GL_TEXTURE_3D);
1081 glBindTexture(GL_TEXTURE_3D, tex_id);
1082 glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP);
1083 glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP);
1084 glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP);
1085 glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1086 glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1087 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
1093 bool drawRange =
true;
1095 if (drawRange ==
false) {
1096 glDrawElements(GL_TRIANGLES,mc->
ff.elem(),GL_UNSIGNED_INT, mc->
ff.get_data());
1098 for(
unsigned int i = 0; i < mc->
ff.elem(); i+=maxf)
1100 if ((i+maxf) > mc->
ff.elem())
1101 glDrawElements(GL_TRIANGLES, mc->
ff.elem()-i, GL_UNSIGNED_INT, &(mc->
ff[i]));
1103 glDrawElements(GL_TRIANGLES, maxf, GL_UNSIGNED_INT, &(mc->
ff[i]));
1114 if (tex_id != 0) glDisable(GL_TEXTURE_3D);
1118#if MARCHING_CUBES_DEBUG
1119 int time1 = clock();
1121 cout <<
"It took " << (time1-time0) <<
" " <<
1122 (
float)(time1-time0)/CLOCKS_PER_SEC <<
" to draw elements" << endl;
1133 for (
unsigned int i = 0; i < mc->
ff.elem(); ++i ) mc->
ff[i] /= 3;
1140 bool surface_face_z)
1145 typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers);
1146 PFNGLGENBUFFERSPROC glGenBuffers;
1147 glGenBuffers = (PFNGLGENBUFFERSPROC) wglGetProcAddress(
"glGenBuffers");
1149 typedef GLboolean (APIENTRYP PFNGLISBUFFERPROC) (GLuint
buffer);
1150 PFNGLISBUFFERPROC glIsBuffer;
1151 glIsBuffer = (PFNGLISBUFFERPROC) wglGetProcAddress(
"glIsBuffer");
1160 if (!glIsBuffer(mc->
buffer[0])) glGenBuffers(4, mc->
buffer);
1172 glGetIntegerv(GL_MAX_ELEMENTS_INDICES, & maxf);
1174 if (maxf % 3 != 0) {
1175 maxf = maxf - (maxf%3);
1179 typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint
buffer);
1180 PFNGLBINDBUFFERPROC glBindBuffer;
1181 glBindBuffer = (PFNGLBINDBUFFERPROC) wglGetProcAddress(
"glBindBuffer");
1183 typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size,
1184 const GLvoid *data, GLenum usage);
1185 PFNGLBUFFERDATAPROC glBufferData;
1186 glBufferData = (PFNGLBUFFERDATAPROC) wglGetProcAddress(
"glBufferData");
1190 glEnableClientState(GL_NORMAL_ARRAY);
1191 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
1192 glBindBuffer(GL_ARRAY_BUFFER, mc->
buffer[2]);
1195 glBufferData(GL_ARRAY_BUFFER, 4*mc->
nn.elem(), mc->
nn.get_data(),
1199 glNormalPointer(GL_FLOAT,0,0);
1202 glBindBuffer(GL_ARRAY_BUFFER, mc->
buffer[0]);
1205 glBufferData(GL_ARRAY_BUFFER, 4*mc->
pp.elem(), mc->
pp.get_data(),
1209 glEnableClientState(GL_VERTEX_ARRAY);
1210 glVertexPointer(3,GL_FLOAT,0,0);
1214 glEnableClientState(GL_COLOR_ARRAY);
1215 glBindBuffer(GL_ARRAY_BUFFER, mc->
buffer[3]);
1218 glBufferData(GL_ARRAY_BUFFER, 4*mc->
cc.elem(), mc->
cc.get_data(),
1222 glColorPointer(3,GL_FLOAT,0, 0);
1226 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mc->
buffer[1]);
1229 glBufferData(GL_ELEMENT_ARRAY_BUFFER, 4*mc->
ff.elem(), mc->
ff.get_data(),
1234 if (!glIsBuffer(mc->
buffer[0])) {
1235 cout <<
"Can't Generate GL Vertex Buffers. glGenBuffer error" << endl;
1241 glDrawElements(GL_TRIANGLES, mc->
ff.elem(), GL_UNSIGNED_INT, 0);
1248static void transpose_4_by_4_matrix (vector <float> & v)
1250 std::swap (v [ 1], v [ 4]);
1251 std::swap (v [ 2], v [ 8]);
1252 std::swap (v [ 3], v [12]);
1253 std::swap (v [ 6], v [ 9]);
1254 std::swap (v [ 7], v [13]);
1255 std::swap (v [11], v [14]);
1262 transpose_4_by_4_matrix (xformlist);
1264 glLoadMatrixf (
reinterpret_cast <GLfloat *
> (& xformlist [0]));
1271 transpose_4_by_4_matrix (xformlist);
1273 glMultMatrixf (
reinterpret_cast <GLfloat *
> (& xformlist [0]));
1279 float x = width/2.0f;
1280 float y = height/2.0f;
1281 float z = depth/2.0f;
1283 float vertices[72] = {-
x,-
y,-z,
x,-
y,-z,
x,-
y,-z,
x,
y,-z,
x,
y,-z, -
x,
y,-z, -
x,
y,-z, -
x,-
y,-z,
1284 -
x,-
y,-z, -
x,-
y,z,
x,-
y,-z,
x,-
y,z,
x,
y,-z,
x,
y,z, -
x,
y,-z, -
x,
y,z,
1285 -
x,-
y,z,
x,-
y,z,
x,-
y,z,
x,
y,z,
x,
y,z, -
x,
y,z, -
x,
y,z, -
x,-
y,z };
1288 for (
int i=0; i<72; i+=3) glVertex3f(vertices[i],vertices[i+1],vertices[i+2]);
1335 typedef void (APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers);
1336 PFNGLGENBUFFERSPROC glGenBuffers;
1337 glGenBuffers = (PFNGLGENBUFFERSPROC) wglGetProcAddress(
"glGenBuffers");
1339 typedef GLboolean (APIENTRYP PFNGLISBUFFERPROC) (GLuint
buffer);
1340 PFNGLISBUFFERPROC glIsBuffer;
1341 glIsBuffer = (PFNGLISBUFFERPROC) wglGetProcAddress(
"glIsBuffer");
1343 typedef void (APIENTRYP PFNGLBINDBUFFERPROC) (GLenum target, GLuint
buffer);
1344 PFNGLBINDBUFFERPROC glBindBuffer;
1345 glBindBuffer = (PFNGLBINDBUFFERPROC) wglGetProcAddress(
"glBindBuffer");
1347 typedef void (APIENTRYP PFNGLBUFFERDATAPROC) (GLenum target, GLsizeiptr size,
1348 const GLvoid *data, GLenum usage);
1349 PFNGLBUFFERDATAPROC glBufferData;
1350 glBufferData = (PFNGLBUFFERDATAPROC) wglGetProcAddress(
"glBufferData");
1354 int arraysize = 4*pow((
double)2, (
double)spokes);
1355 int sideofarray = pow((
double)2, (
double)spokes);
1358 vector<float> vertices(3*arraysize + 3);
1361 vertices[3*arraysize] = 0.0;
1362 vertices[3*arraysize+1] = 0.0;
1363 vertices[3*arraysize+2] = 0.0;
1366 vertices[1] = radius;
1369 vertices[sideofarray*3] = radius;
1370 vertices[sideofarray*3 + 1] = 0.0;
1371 vertices[sideofarray*3 + 2] = 0.0;
1373 vertices[sideofarray*6] = 0.0;
1374 vertices[sideofarray*6 + 1] = -radius;
1375 vertices[sideofarray*6 + 2] = 0.0;
1377 vertices[sideofarray*9] = -radius;
1378 vertices[sideofarray*9 + 1] = 0.0;
1379 vertices[sideofarray*9 + 2] = 0.0;
1382 for (
int step = 0; step < spokes; step++) {
1384 int x = sideofarray/pow(2.0,(
double)(step+1));
1386 for (
int i = 1; i <= 4*pow(2.0,(
double)step); i++) {
1388 int index =
x + 2*
x*(i-1);
1389 int index_f = (index +
x) % arraysize;
1390 int index_i = index -
x;
1392 cout << index <<
" " << index_f <<
" " << index_i << endl;
1395 vertices[index_f*3] = (vertices[index_f*3] - vertices[index_i*3])/2.0f;
1396 vertices[index_f*3 + 1] = (vertices[index_f*3 + 1] - vertices[index_i*3 + 1])/2.0f;
1397 vertices[index_f*3 + 2] = (vertices[index_f*3 + 2] - vertices[index_i*3 + 2])/2.0f;
1410 glBufferData(GL_ARRAY_BUFFER, vertices.size(), &(vertices[0]),
1412 glEnableClientState(GL_VERTEX_ARRAY);
1413 glVertexPointer(3, GL_FLOAT, 0, 0);
bool getNeedToRecolor()
Lets us know if we need to recalculate colors.
EMData stores an image's data and defines core image processing routines.
static void mx_bbox(const vector< float > &data, const vector< float > &text_color, const vector< float > &bg_color)
static void render_using_VBOs(MarchingCubes *mc, unsigned int tex_id=0, bool surface_face_z=false)
Render a isosurface using buffer objects, this uses non-deprecated methods and improves performance.
static void colored_rectangle(const vector< float > &data, const float &alpha, const bool center_point=false)
static EMBytes render_amp8(EMData *emdata, int x, int y, int xsize, int ysize, int bpl, float scale, int min_gray, int max_gray, float min_render, float max_render, float gamma, int flags)
Render the image into an 8-bit image.
static void glDrawBoundingBox(float width, float height, float depth)
Draw a bounding box.
static void glMultMatrix(const Transform &xform)
Mult a EMAN style transform to open GL w/o having to go through python Calls glMultTransposeMatrix ra...
static int nearest_projected_points(const vector< float > &model_matrix, const vector< float > &proj_matrix, const vector< int > &view_matrix, const vector< Vec3f > &points, const float mouse_x, const float mouse_y, const float &nearnes)
Determine the intersection of ....
static unsigned int render_amp8_gl_texture(EMData *emdata, int x0, int y0, int ixsize, int iysize, int bpl, float scale, int mingray, int maxgray, float render_min, float render_max, float gamma, int flags)
create an OpenGL texture using render_amp8
static void contour_isosurface(MarchingCubes *mc)
Recountour isosurface, for use with VBOs.
static void glLoadMatrix(const Transform &xform)
Load a EMAN style transform to open GL w/o having to go through python Calls glLoadTransposeMatrix ra...
static void glDrawDisk(float radius, int spokes)
static unsigned int gen_gl_texture(const EMData *const emdata, GLenum format=GL_LUMINANCE)
create an OpenGL texture
static unsigned long get_isosurface_dl(MarchingCubes *mc, unsigned int tex_id=0, bool surface_face_z=false, bool recontour=true)
Get an isosurface display list Traverses the tree, marches the cubes, and renders a display list usin...
void calculate_surface()
Calculate and generate the entire set of vertices and normals using current states Calls draw_cube(0,...
ColorRGBGenerator rgbgenerator
Color by radius generator.
int getRGBmode()
Return RGB mode.
CustomVector< unsigned int > ff
void color_vertices()
Color the vertices.
CustomVector< float > pp
.Custom vectors for storing points, normals and faces
EMData * copy() const
This file is a part of "emdata.h", to use functions in this file, you should "#include "emdata....
EMData * sqrt() const
return square root of current image
#define ImageDimensionException(desc)
#define NullPointerException(desc)