heat_display.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010-2011 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011 Centre National de la Recherche Scientifique
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include "heat.h"
  18. #ifdef STARPU_OPENGL_RENDER
  19. /*
  20. * Just some dummy OpenGL code to display our results
  21. *
  22. */
  23. static float minval, maxval;
  24. static unsigned ntheta;
  25. static unsigned nthick;
  26. static float *result;
  27. static unsigned printmesh =0;
  28. static point *pmesh;
  29. float xmin, xmax, ymin, ymax;
  30. float xcenter, ycenter;
  31. static void generate_graph(void)
  32. {
  33. unsigned theta, thick;
  34. for (theta = 0; theta < ntheta-1; theta++)
  35. {
  36. for (thick = 0; thick < nthick-1; thick++)
  37. {
  38. unsigned nodeA = NODE_NUMBER(theta, thick);
  39. unsigned nodeB = NODE_NUMBER(theta, thick+1);
  40. unsigned nodeC = NODE_NUMBER(theta+1, thick+1);
  41. unsigned nodeD = NODE_NUMBER(theta+1, thick);
  42. float colorA_R, colorB_R, colorC_R, colorD_R;
  43. float colorA_G, colorB_G, colorC_G, colorD_G;
  44. float colorA_B, colorB_B, colorC_B, colorD_B;
  45. if (maxval == minval) {
  46. colorA_R = 1.0f; colorA_G = 1.0f; colorA_B = 1.0f;
  47. colorB_R = 1.0f; colorB_G = 1.0f; colorB_B = 1.0f;
  48. colorC_R = 1.0f; colorC_G = 1.0f; colorC_B = 1.0f;
  49. colorD_R = 1.0f; colorD_G = 1.0f; colorD_B = 1.0f;
  50. }
  51. else {
  52. float amplitude = maxval - minval;
  53. float coeffA, coeffB, coeffC, coeffD;
  54. coeffA = (result[nodeA] - minval)/amplitude;
  55. coeffB = (result[nodeB] - minval)/amplitude;
  56. coeffC = (result[nodeC] - minval)/amplitude;
  57. coeffD = (result[nodeD] - minval)/amplitude;
  58. colorA_R = coeffA>0.5f?1.0f:(2.0*coeffA)*1.0f;
  59. colorB_R = coeffB>0.5f?1.0f:(2.0*coeffB)*1.0f;
  60. colorC_R = coeffC>0.5f?1.0f:(2.0*coeffC)*1.0f;
  61. colorD_R = coeffD>0.5f?1.0f:(2.0*coeffD)*1.0f;
  62. colorA_B = 0.0f;
  63. colorB_B = 0.0f;
  64. colorC_B = 0.0f;
  65. colorD_B = 0.0f;
  66. colorA_G = coeffA<0.5f?1.0f:2.0*(1 - coeffA)*1.0f;
  67. colorB_G = coeffB<0.5f?1.0f:2.0*(1 - coeffB)*1.0f;
  68. colorC_G = coeffC<0.5f?1.0f:2.0*(1 - coeffC)*1.0f;
  69. colorD_G = coeffD<0.5f?1.0f:2.0*(1 - coeffD)*1.0f;
  70. }
  71. if (printmesh) {
  72. glColor3f (0.0f, 0.0f, 0.0f);
  73. glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  74. glLineWidth(3.0f);
  75. glBegin(GL_POLYGON);
  76. glVertex3f(pmesh[nodeA].x, pmesh[nodeA].y, 2.0f);
  77. glVertex3f(pmesh[nodeD].x, pmesh[nodeD].y, 2.0f);
  78. glVertex3f(pmesh[nodeC].x, pmesh[nodeC].y, 2.0f);
  79. glVertex3f(pmesh[nodeA].x, pmesh[nodeA].y, 2.0f);
  80. glEnd();
  81. glBegin(GL_POLYGON);
  82. glVertex3f(pmesh[nodeA].x, pmesh[nodeA].y, 1.0f);
  83. glVertex3f(pmesh[nodeC].x, pmesh[nodeC].y, 1.0f);
  84. glVertex3f(pmesh[nodeB].x, pmesh[nodeB].y, 1.0f);
  85. glVertex3f(pmesh[nodeA].x, pmesh[nodeA].y, 1.0f);
  86. glEnd();
  87. }
  88. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  89. glBegin(GL_POLYGON);
  90. glColor3f (colorA_R, colorA_G, colorA_B);
  91. glVertex3f(pmesh[nodeA].x, pmesh[nodeA].y, 0.0f);
  92. glColor3f (colorD_R, colorD_G, colorD_B);
  93. glVertex3f(pmesh[nodeD].x, pmesh[nodeD].y, 0.0f);
  94. glColor3f (colorC_R, colorC_G, colorC_B);
  95. glVertex3f(pmesh[nodeC].x, pmesh[nodeC].y, 0.0f);
  96. glEnd();
  97. glBegin(GL_POLYGON);
  98. glColor3f (colorA_R, colorA_G, colorA_B);
  99. glVertex3f(pmesh[nodeA].x, pmesh[nodeA].y, 0.0f);
  100. glColor3f (colorC_R, colorC_G, colorC_B);
  101. glVertex3f(pmesh[nodeC].x, pmesh[nodeC].y, 0.0f);
  102. glColor3f (colorB_R, colorB_G, colorB_B);
  103. glVertex3f(pmesh[nodeB].x, pmesh[nodeB].y, 0.0f);
  104. glEnd();
  105. }
  106. }
  107. }
  108. static void display(void)
  109. {
  110. glClear (GL_COLOR_BUFFER_BIT);
  111. glLoadIdentity (); /* clear the matrix */
  112. float amplitude = STARPU_MAX(xmax - xmin, ymax - ymin);
  113. float factor = 1.0/amplitude;
  114. glScalef (factor, factor, factor); /* modeling transformation */
  115. gluLookAt (xcenter, ycenter, 30.0f, xcenter, ycenter, 0.0f, 0.0f, 1.0f, 0.0f);
  116. /* printf("factor %f\n", factor);
  117. glRotatef(-0,0.0,0.0,0.0); */
  118. generate_graph();
  119. glFlush ();
  120. }
  121. static void pressKey(unsigned char key, int x __attribute__ ((unused)), int y __attribute__ ((unused)))
  122. {
  123. switch (key) {
  124. case 'q':
  125. exit(0);
  126. default:
  127. printmesh = !printmesh;
  128. display();
  129. break;
  130. }
  131. }
  132. static void reshape (int w, int h)
  133. {
  134. glViewport (0, 0, (GLsizei) w, (GLsizei) h);
  135. glMatrixMode (GL_PROJECTION);
  136. glLoadIdentity ();
  137. glFrustum (xmin, xmax, ymin, ymax, 5.0f, 5.0f);
  138. glMatrixMode (GL_MODELVIEW);
  139. }
  140. void find_limits(void)
  141. {
  142. minval = 100000000.0f;
  143. maxval = -10000000.0f;
  144. unsigned i;
  145. for (i = 0; i < DIM; i++)
  146. {
  147. /* find min */
  148. minval = STARPU_MIN(result[i], minval);
  149. /* find max */
  150. maxval = STARPU_MAX(result[i], maxval);
  151. }
  152. xmin = 10000000.0f;
  153. xmax = -10000000.0f;
  154. ymin = 10000000.0f;
  155. ymax = -10000000.0f;
  156. unsigned theta, thick;
  157. for (theta = 0; theta < ntheta; theta++)
  158. {
  159. for (thick = 0; thick < nthick; thick++)
  160. {
  161. point *p = &pmesh[NODE_NUMBER(theta, thick)];
  162. if (p->x < xmin)
  163. xmin = p->x;
  164. if (p->x > xmax)
  165. xmax = p->x;
  166. if (p->y < ymin)
  167. ymin = p->y;
  168. if (p->y > ymax)
  169. ymax = p->y;
  170. }
  171. }
  172. ycenter = (ymin + ymax)/2;
  173. xcenter = (xmin + xmax)/2;
  174. }
  175. void opengl_render(unsigned _ntheta, unsigned _nthick, float *_result, point *_pmesh, int argc_, char **argv_)
  176. {
  177. FPRINTF(stderr, "OpenGL rendering ... \n");
  178. ntheta = _ntheta;
  179. nthick = _nthick;
  180. result = _result;
  181. printmesh = 0;
  182. pmesh = _pmesh;
  183. find_limits();
  184. glutInit(&argc_, argv_);
  185. glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
  186. glutInitWindowSize (800, 800);
  187. glutInitWindowPosition (100, 100);
  188. glutCreateWindow ("Temperature");
  189. /* init */
  190. glClearColor (0.0, 0.0, 0.0, 0.0);
  191. glShadeModel (GL_MODELVIEW);
  192. glutKeyboardFunc(pressKey);
  193. glutDisplayFunc(display);
  194. glutReshapeFunc(reshape);
  195. glutMainLoop();
  196. }
  197. #endif /* STARPU_OPENGL_RENDER */