heat_display.c 6.0 KB

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