heat_display.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010-2011 Université de Bordeaux
  4. * Copyright (C) 2010, 2011 CNRS
  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. {
  47. colorA_R = 1.0f; colorA_G = 1.0f; colorA_B = 1.0f;
  48. colorB_R = 1.0f; colorB_G = 1.0f; colorB_B = 1.0f;
  49. colorC_R = 1.0f; colorC_G = 1.0f; colorC_B = 1.0f;
  50. colorD_R = 1.0f; colorD_G = 1.0f; colorD_B = 1.0f;
  51. }
  52. else
  53. {
  54. float amplitude = maxval - minval;
  55. float coeffA, coeffB, coeffC, coeffD;
  56. coeffA = (result[nodeA] - minval)/amplitude;
  57. coeffB = (result[nodeB] - minval)/amplitude;
  58. coeffC = (result[nodeC] - minval)/amplitude;
  59. coeffD = (result[nodeD] - minval)/amplitude;
  60. colorA_R = coeffA>0.5f?1.0f:(2.0*coeffA)*1.0f;
  61. colorB_R = coeffB>0.5f?1.0f:(2.0*coeffB)*1.0f;
  62. colorC_R = coeffC>0.5f?1.0f:(2.0*coeffC)*1.0f;
  63. colorD_R = coeffD>0.5f?1.0f:(2.0*coeffD)*1.0f;
  64. colorA_B = 0.0f;
  65. colorB_B = 0.0f;
  66. colorC_B = 0.0f;
  67. colorD_B = 0.0f;
  68. colorA_G = coeffA<0.5f?1.0f:2.0*(1 - coeffA)*1.0f;
  69. colorB_G = coeffB<0.5f?1.0f:2.0*(1 - coeffB)*1.0f;
  70. colorC_G = coeffC<0.5f?1.0f:2.0*(1 - coeffC)*1.0f;
  71. colorD_G = coeffD<0.5f?1.0f:2.0*(1 - coeffD)*1.0f;
  72. }
  73. if (printmesh)
  74. {
  75. glColor3f (0.0f, 0.0f, 0.0f);
  76. glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  77. glLineWidth(3.0f);
  78. glBegin(GL_POLYGON);
  79. glVertex3f(pmesh[nodeA].x, pmesh[nodeA].y, 2.0f);
  80. glVertex3f(pmesh[nodeD].x, pmesh[nodeD].y, 2.0f);
  81. glVertex3f(pmesh[nodeC].x, pmesh[nodeC].y, 2.0f);
  82. glVertex3f(pmesh[nodeA].x, pmesh[nodeA].y, 2.0f);
  83. glEnd();
  84. glBegin(GL_POLYGON);
  85. glVertex3f(pmesh[nodeA].x, pmesh[nodeA].y, 1.0f);
  86. glVertex3f(pmesh[nodeC].x, pmesh[nodeC].y, 1.0f);
  87. glVertex3f(pmesh[nodeB].x, pmesh[nodeB].y, 1.0f);
  88. glVertex3f(pmesh[nodeA].x, pmesh[nodeA].y, 1.0f);
  89. glEnd();
  90. }
  91. glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  92. glBegin(GL_POLYGON);
  93. glColor3f (colorA_R, colorA_G, colorA_B);
  94. glVertex3f(pmesh[nodeA].x, pmesh[nodeA].y, 0.0f);
  95. glColor3f (colorD_R, colorD_G, colorD_B);
  96. glVertex3f(pmesh[nodeD].x, pmesh[nodeD].y, 0.0f);
  97. glColor3f (colorC_R, colorC_G, colorC_B);
  98. glVertex3f(pmesh[nodeC].x, pmesh[nodeC].y, 0.0f);
  99. glEnd();
  100. glBegin(GL_POLYGON);
  101. glColor3f (colorA_R, colorA_G, colorA_B);
  102. glVertex3f(pmesh[nodeA].x, pmesh[nodeA].y, 0.0f);
  103. glColor3f (colorC_R, colorC_G, colorC_B);
  104. glVertex3f(pmesh[nodeC].x, pmesh[nodeC].y, 0.0f);
  105. glColor3f (colorB_R, colorB_G, colorB_B);
  106. glVertex3f(pmesh[nodeB].x, pmesh[nodeB].y, 0.0f);
  107. glEnd();
  108. }
  109. }
  110. }
  111. static void display(void)
  112. {
  113. glClear (GL_COLOR_BUFFER_BIT);
  114. glLoadIdentity (); /* clear the matrix */
  115. float amplitude = STARPU_MAX(xmax - xmin, ymax - ymin);
  116. float factor = 1.0/amplitude;
  117. glScalef (factor, factor, factor); /* modeling transformation */
  118. gluLookAt (xcenter, ycenter, 30.0f, xcenter, ycenter, 0.0f, 0.0f, 1.0f, 0.0f);
  119. /* printf("factor %f\n", factor);
  120. glRotatef(-0,0.0,0.0,0.0); */
  121. generate_graph();
  122. glFlush ();
  123. }
  124. static void pressKey(unsigned char key, int x STARPU_ATTRIBUTE_UNUSED, int y STARPU_ATTRIBUTE_UNUSED)
  125. {
  126. switch (key)
  127. {
  128. case 'q':
  129. exit(0);
  130. default:
  131. printmesh = !printmesh;
  132. display();
  133. break;
  134. }
  135. }
  136. static void reshape (int w, int h)
  137. {
  138. glViewport (0, 0, (GLsizei) w, (GLsizei) h);
  139. glMatrixMode (GL_PROJECTION);
  140. glLoadIdentity ();
  141. glFrustum (xmin, xmax, ymin, ymax, 5.0f, 5.0f);
  142. glMatrixMode (GL_MODELVIEW);
  143. }
  144. void find_limits(void)
  145. {
  146. minval = 100000000.0f;
  147. maxval = -10000000.0f;
  148. unsigned i;
  149. for (i = 0; i < DIM; i++)
  150. {
  151. /* find min */
  152. minval = STARPU_MIN(result[i], minval);
  153. /* find max */
  154. maxval = STARPU_MAX(result[i], maxval);
  155. }
  156. xmin = 10000000.0f;
  157. xmax = -10000000.0f;
  158. ymin = 10000000.0f;
  159. ymax = -10000000.0f;
  160. unsigned theta, thick;
  161. for (theta = 0; theta < ntheta; theta++)
  162. {
  163. for (thick = 0; thick < nthick; thick++)
  164. {
  165. point *p = &pmesh[NODE_NUMBER(theta, thick)];
  166. if (p->x < xmin)
  167. xmin = p->x;
  168. if (p->x > xmax)
  169. xmax = p->x;
  170. if (p->y < ymin)
  171. ymin = p->y;
  172. if (p->y > ymax)
  173. ymax = p->y;
  174. }
  175. }
  176. ycenter = (ymin + ymax)/2;
  177. xcenter = (xmin + xmax)/2;
  178. }
  179. void opengl_render(unsigned _ntheta, unsigned _nthick, float *_result, point *_pmesh, int argc_, char **argv_)
  180. {
  181. FPRINTF(stderr, "OpenGL rendering ... \n");
  182. ntheta = _ntheta;
  183. nthick = _nthick;
  184. result = _result;
  185. printmesh = 0;
  186. pmesh = _pmesh;
  187. find_limits();
  188. glutInit(&argc_, argv_);
  189. glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
  190. glutInitWindowSize (800, 800);
  191. glutInitWindowPosition (100, 100);
  192. glutCreateWindow ("Temperature");
  193. /* init */
  194. glClearColor (0.0, 0.0, 0.0, 0.0);
  195. glShadeModel (GL_MODELVIEW);
  196. glutKeyboardFunc(pressKey);
  197. glutDisplayFunc(display);
  198. glutReshapeFunc(reshape);
  199. glutMainLoop();
  200. }
  201. #endif /* STARPU_OPENGL_RENDER */