fermisurfer  2.0.0
fermisurfer
draw.cpp
Go to the documentation of this file.
1 /*
2 The MIT License (MIT)
3 
4 Copyright (c) 2014 Mitsuaki KAWAMURA
5 
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12 
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15 
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 THE SOFTWARE.
23 */
24 /**@file
25  @brief Functions for actual displaying
26 */
27 #if defined(HAVE_CONFIG_H)
28 #include <config.h>
29 #endif
30 #include "wx/wx.h"
31 #include "wx/glcanvas.h"
32 #if defined(HAVE_GL_GL_H)
33 #include <GL/gl.h>
34 #elif defined(HAVE_OPENGL_GL_H)
35 #include <OpenGL/gl.h>
36 #endif
37 #include <cmath>
38 #include <cstdio>
39 #include <cstdlib>
40 #include "variable.hpp"
41 #include "operation.hpp"
42 /**
43  @brief Draw Fermi surfaces
44 
45  Modify : ::nmlp_rot, ::kvp_rot, ::kvnl_rot
46 
47  First, rotate ::nmlp and ::kvp with OpenMP then draw them.
48  Also draw nodeline in the same way.
49 */
50 static void draw_fermi() {
51  int ib, a0, a1, a2, ia;
52  GLfloat kshift[3];
53  /*
54  First, rotate k-vector and normal vector
55  */
56  for (a0 = 0; a0 < BZ_number[0]; a0++) {
57  for (a1 = 0; a1 < BZ_number[1]; a1++) {
58  for (a2 = 0; a2 < BZ_number[2]; a2++) {
59  for (ia = 0; ia < 3; ia++) kshift[ia] = bvec[0][ia] * a0 + bvec[1][ia] * a1 + bvec[2][ia] * a2;
60 #pragma omp parallel default(none) \
61 shared(nb,draw_band,ntri,rot,nmlp,arw,nmlp_rot,kvp,kvp_rot,arw_rot,trans,side,kshift) \
62 private(ib)
63  {
64  int i, j, l, itri;
65 
66  for (ib = 0; ib < nb; ib++) {
67  if (draw_band[ib] == 1) {
68 #pragma omp for nowait
69  for (itri = 0; itri < ntri[ib]; ++itri) {
70  for (i = 0; i < 3; ++i) {
71  for (j = 0; j < 3; ++j) {
72  kvp_rot[ib][j + 3 * i + 9 * itri]
73  = rot[j][0] * (kvp[ib][itri][i][0] + kshift[0])
74  + rot[j][1] * (kvp[ib][itri][i][1] + kshift[1])
75  + rot[j][2] * (kvp[ib][itri][i][2] + kshift[2])
76  + trans[j];
77  nmlp_rot[ib][j + 3 * i + 9 * itri]
78  = rot[j][0] * nmlp[ib][itri][i][0]
79  + rot[j][1] * nmlp[ib][itri][i][1]
80  + rot[j][2] * nmlp[ib][itri][i][2];
81  nmlp_rot[ib][j + 3 * i + 9 * itri] *= side;
82  for (l = 0; l < 2; ++l) {
83  arw_rot[ib][j + 3 * l + 6 * i + 18 * itri]
84  = rot[j][0] * (arw[ib][itri][i][l][0] + kshift[0])
85  + rot[j][1] * (arw[ib][itri][i][l][1] + kshift[1])
86  + rot[j][2] * (arw[ib][itri][i][l][2] + kshift[2])
87  + trans[j];
88  }
89  }
90  }/*for (i = 0; i < 3; ++i)*/
91  }/*for (itri = 0; itri < ntri[ib]; ++itri)*/
92  }/*if (draw_band[ib] == 1)*/
93  }/*for (ib = 0; ib < nb; ib++)*/
94  }/*End of parallel region*/
95  /*
96  Second, draw each triangle
97  */
98  glEnableClientState(GL_NORMAL_ARRAY);
99  glEnableClientState(GL_COLOR_ARRAY);
100  for (ib = 0; ib < nb; ib++) {
101  if (draw_band[ib] == 1) {
102  glVertexPointer(3, GL_FLOAT, 0, kvp_rot[ib]);
103  glNormalPointer(GL_FLOAT, 0, nmlp_rot[ib]);
104  glColorPointer(4, GL_FLOAT, 0, clr[ib]);
105  glDrawArrays(GL_TRIANGLES, 0, ntri[ib] * 3);
106  }/*if (draw_band[ib] == 1)*/
107  }/*for (ib = 0; ib < nb; ib++)*/
108  glDisableClientState(GL_NORMAL_ARRAY);
109  glDisableClientState(GL_COLOR_ARRAY);
110  /*
111  Arrow for 3D value
112  */
113  glNormal3f(0.0f, 0.0f, 1.0f);
114  if (color_scale == 3) {
115  for (ib = 0; ib < nb; ib++) {
116  if (draw_band[ib] == 1) {
117  glColor3f(1.0 - clr[ib][0], 1.0 - clr[ib][1], 1.0 - clr[ib][2]);
118  glVertexPointer(3, GL_FLOAT, 0, arw_rot[ib]);
119  glDrawArrays(GL_LINES, 0, ntri[ib] * 3 * 2);
120  }
121  }
122  }
123  /*
124  Nodeline
125  */
126  if (nodeline == 1) {
127  /*
128  First, rotate k-vector
129  */
130 #pragma omp parallel default(none) \
131 shared(nb,draw_band,nnl,rot,trans,kvnl,kvnl_rot,kshift) \
132 private(ib)
133  {
134  int i, j, itri;
135 
136  for (ib = 0; ib < nb; ib++) {
137  /**/
138  if (draw_band[ib] == 1) {
139 #pragma omp for nowait
140  for (itri = 0; itri < nnl[ib]; ++itri) {
141  for (i = 0; i < 2; ++i) {
142  /**/
143  for (j = 0; j < 3; ++j)
144  kvnl_rot[ib][j + 3 * i + 6 * itri]
145  = rot[j][0] * (kvnl[ib][itri][i][0] + kshift[0])
146  + rot[j][1] * (kvnl[ib][itri][i][1] + kshift[1])
147  + rot[j][2] * (kvnl[ib][itri][i][2] + kshift[2])
148  + trans[j];
149  kvnl_rot[ib][2 + 3 * i + 6 * itri] += 0.001f;
150  }/*for (i = 0; i < 2; ++i)*/
151  }/*for (itri = 0; itri < nnl[ib]; ++itri)*/
152  }/*if (draw_band[ib] == 1)*/
153  }/*for (ib = 0; ib < nb; ib++)*/
154  }/*End of parallel region*/
155  /*
156  Second, draw each lines
157  */
158  glColor3fv(black);
159  glNormal3f(0.0f, 0.0f, 1.0f);
160  for (ib = 0; ib < nb; ib++) {
161  if (draw_band[ib] == 1) {
162  glVertexPointer(3, GL_FLOAT, 0, kvnl_rot[ib]);
163  glDrawArrays(GL_LINES, 0, 2 * nnl[ib]);
164  }/*if (draw_band[ib] == 1)*/
165  }/* for (ib = 0; ib < nb; ib++)*/
166  }/*if (nodeline == 1)*/
167  /*
168  Equator
169  */
170  if (lequator == 1) {
171  /*
172  First, rotate k-vector
173  */
174 #pragma omp parallel default(none) \
175 shared(nb,draw_band,nequator,rot,trans,kveq,kveq_rot,kshift) \
176 private(ib)
177  {
178  int i, j, itri;
179 
180  for (ib = 0; ib < nb; ib++) {
181  /**/
182  if (draw_band[ib] == 1) {
183 #pragma omp for nowait
184  for (itri = 0; itri < nequator[ib]; ++itri) {
185  for (i = 0; i < 2; ++i) {
186  /**/
187  for (j = 0; j < 3; ++j)
188  kveq_rot[ib][j + 3 * i + 6 * itri]
189  = rot[j][0] * (kveq[ib][itri][i][0] + kshift[0])
190  + rot[j][1] * (kveq[ib][itri][i][1] + kshift[1])
191  + rot[j][2] * (kveq[ib][itri][i][2] + kshift[2])
192  + trans[j];
193  kveq_rot[ib][2 + 3 * i + 6 * itri] += 0.001f;
194  }/*for (i = 0; i < 2; ++i)*/
195  }/*for (itri = 0; itri < nequator[ib]; ++itri)*/
196  }/*if (draw_band[ib] == 1)*/
197  }/*for (ib = 0; ib < nb; ib++)*/
198  }/*End of parallel region*/
199  /*
200  Second, draw each lines
201  */
202  glColor3fv(black);
203  glNormal3f(0.0f, 0.0f, 1.0f);
204  for (ib = 0; ib < nb; ib++) {
205  if (draw_band[ib] == 1) {
206  glVertexPointer(3, GL_FLOAT, 0, kveq_rot[ib]);
207  glDrawArrays(GL_LINES, 0, 2 * nequator[ib]);
208  }/*if (draw_band[ib] == 1)*/
209  }/* for (ib = 0; ib < nb; ib++)*/
210  }/*if (nodeline == 1)*/
211  }
212  }
213  }
214 }/*void draw_fermi*/
215 /**
216  @brief Draw lines of BZ boundaries
217 */
218 static void draw_bz_lines() {
219  int ibzl, i, j, a0, a1, a2, ia, icount;
220  GLfloat bzl2[3], bvec2[3][3], linecolor[4], secvec2[3], kshift[3], arrow_c[3];
221  GLfloat vertices[300], sphere_v2[1140]/*190*2*3*/;
222  //
223  // Line color is oposit of BG color
224  //
225  for (i = 0; i < 4; i++) linecolor[i] = LineColor[i];
226  //
227  glLineWidth(linewidth);
228  for (a0 = 0; a0 < BZ_number[0]; a0++) {
229  for (a1 = 0; a1 < BZ_number[1]; a1++) {
230  for (a2 = 0; a2 < BZ_number[2]; a2++) {
231  for (ia = 0; ia < 3; ia++) kshift[ia] = bvec[0][ia] * a0 + bvec[1][ia] * a1 + bvec[2][ia] * a2;
232  //
233  // First Brillouin zone mode
234  //
235  if (fbz == 1) {
236  for (ibzl = 0; ibzl < nbzl; ++ibzl) {
237  for (i = 0; i < 2; ++i) {
238  for (j = 0; j < 3; ++j)
239  bzl2[j] = rot[j][0] * (bzl[ibzl][i][0] + kshift[0])
240  + rot[j][1] * (bzl[ibzl][i][1] + kshift[1])
241  + rot[j][2] * (bzl[ibzl][i][2] + kshift[2])
242  + trans[j];
243  for (j = 0; j < 3; j++) vertices[j + 3 * i] = bzl2[j];
244  }/*for (i = 0; i< 2; ++i)*/
245  glColor3fv(linecolor);
246  glNormal3f(0.0f, 0.0f, 1.0f);
247  glVertexPointer(3, GL_FLOAT, 0, vertices);
248  glDrawArrays(GL_LINES, 0, 2);
249  }/*for (ibzl = 0; ibzl < nbzl; ++ibzl)*/
250  }/*if (fbz == 1)*/
251  else {
252  //
253  // Premitive BZ mode
254  //
255  for (i = 0; i < 3; ++i) {
256  for (j = 0; j < 3; ++j) {
257  bvec2[i][j] = rot[j][0] * bvec[i][0]
258  + rot[j][1] * bvec[i][1]
259  + rot[j][2] * bvec[i][2];
260  }/*for (j = 0; j < 3; ++j)*/
261  }/*for (i = 0; i < 3; ++i)*/
262  for (i = 0; i < 3; ++i) vertices[i] = trans[i];
263  for (i = 0; i < 3; ++i) vertices[i + 3] = trans[i] + bvec2[0][i];
264  for (i = 0; i < 3; ++i) vertices[i + 3 * 2] = trans[i] + bvec2[0][i] + bvec2[1][i];
265  for (i = 0; i < 3; ++i) vertices[i + 3 * 3] = trans[i] + bvec2[0][i] + bvec2[1][i] + bvec2[2][i];
266  for (i = 0; i < 3; ++i) vertices[i + 3 * 4] = trans[i] + bvec2[1][i] + bvec2[2][i];
267  for (i = 0; i < 3; ++i) vertices[i + 3 * 5] = trans[i] + bvec2[1][i];
268  for (i = 0; i < 3; ++i) vertices[i + 3 * 6] = trans[i];
269  for (i = 0; i < 3; ++i) vertices[i + 3 * 7] = trans[i] + bvec2[2][i];
270  for (i = 0; i < 3; ++i) vertices[i + 3 * 8] = trans[i] + bvec2[0][i] + bvec2[2][i];
271  for (i = 0; i < 3; ++i) vertices[i + 3 * 9] = trans[i] + bvec2[0][i] + bvec2[1][i] + bvec2[2][i];
272  for (i = 0; i < 3; ++i) vertices[i + 3 * 10] = trans[i] + bvec2[0][i] + bvec2[2][i];
273  for (i = 0; i < 3; ++i) vertices[i + 3 * 11] = trans[i] + bvec2[0][i];
274  for (i = 0; i < 3; ++i) vertices[i + 3 * 12] = trans[i];
275  for (i = 0; i < 3; ++i) vertices[i + 3 * 13] = trans[i] + bvec2[2][i];
276  for (i = 0; i < 3; ++i) vertices[i + 3 * 14] = trans[i] + bvec2[1][i] + bvec2[2][i];
277  for (i = 0; i < 3; ++i) vertices[i + 3 * 15] = trans[i] + bvec2[1][i];
278  for (i = 0; i < 3; ++i) vertices[i + 3 * 16] = trans[i] + bvec2[0][i] + bvec2[1][i];
279  for (i = 0; i < 17; ++i) {
280  for (j = 0; j < 3; ++j) {
281  vertices[j + 3 * i] = vertices[j + 3 * i]
282  + rot[j][0] * kshift[0]
283  + rot[j][1] * kshift[1]
284  + rot[j][2] * kshift[2];
285  }/*for (j = 0; j < 3; ++j)*/
286  }/*for (i = 0; i < 3; ++i)*/
287  glColor3fv(linecolor);
288  glNormal3f(0.0f, 0.0f, 1.0f);
289  glVertexPointer(3, GL_FLOAT, 0, vertices);
290  glDrawArrays(GL_LINE_STRIP, 0, 17);
291  }/*if (fbz != 1)*/
292  }
293  }
294  }
295  //
296  // Arrow
297  //
298  for (i = 0; i < 2; ++i) {
299  for (j = 0; j < 3; ++j)
300  arrow_c[j] = bvec[0][j] * arrow[i][0]
301  + bvec[1][j] * arrow[i][1]
302  + bvec[2][j] * arrow[i][2];
303  for (j = 0; j < 3; ++j)
304  vertices[j + 3 * i] = rot[j][0] * arrow_c[0]
305  + rot[j][1] * arrow_c[1]
306  + rot[j][2] * arrow_c[2]
307  + trans[j];
308  }/*for (i = 0; i< 2; ++i)*/
309  glColor3fv(linecolor);
310  glNormal3f(0.0f, 0.0f, 1.0f);
311  glVertexPointer(3, GL_FLOAT, 0, vertices);
312  glDrawArrays(GL_LINES, 0, 2);
313  //
314  // Section for the 2D Fermi line
315  //
316  if (lsection == 1 && fbz == 1) {
317  for (j = 0; j < 3; ++j)
318  secvec2[j] = rot[j][0] * secvec[0]
319  + rot[j][1] * secvec[1]
320  + rot[j][2] * secvec[2];
321  for (ibzl = 0; ibzl < nbzl2d; ++ibzl) {
322  for (j = 0; j < 3; ++j)
323  bzl2[j] = rot[j][0] * bzl2d[ibzl][0]
324  + rot[j][1] * bzl2d[ibzl][1]
325  + rot[j][2] * bzl2d[ibzl][2]
326  + trans[j];
327  for (j = 0; j < 3; j++)vertices[j + 3 * ibzl] = bzl2[j];
328  }/*for (ibzl = 0; ibzl < nbzl2d; ++ibzl)*/
329  glColor3fv(SectionColor);
330  glNormal3fv(secvec2);
331  glVertexPointer(3, GL_FLOAT, 0, vertices);
332  glDrawArrays(GL_TRIANGLE_FAN, 0, nbzl2d);
333  }/*if (lsection == 1)*/
334  //
335  // Wireflame Sphere
336  //
337  for (ibzl = 0; ibzl < 190; ibzl++) {
338  for (i = 0; i < 2; ++i) {
339  for (j = 0; j < 3; ++j)
340  sphere_v2[j + 3 * i + 6 * ibzl] = rot[j][0] * sphere_v[ibzl][i][0]
341  + rot[j][1] * sphere_v[ibzl][i][1]
342  + rot[j][2] * sphere_v[ibzl][i][2]
343  + trans[j];
344  }/*for (i = 0; i< 2; ++i)*/
345  }
346  glColor3fv(linecolor);
347  glNormal3f(0.0f, 0.0f, 1.0f);
348  glVertexPointer(3, GL_FLOAT, 0, sphere_v2);
349  glDrawArrays(GL_LINES, 0, 380);
350 }/*draw bz_lines */
351 /**
352  @brief Draw color-bar or colr-circle (periodic)
353  as a color scale
354 */
355 static void draw_colorbar()
356 {
357  int i, j, k;
358  GLfloat mat2, vertices[366], colors[488], vector[18], vector_color[24],
359  norm;
360 
361  glEnableClientState(GL_COLOR_ARRAY);
362  /*
363  Reciplocal lattice vectors
364  */
365  for (i = 0; i < 6; i++) {
366  vector[3 * i] = -1.2f;
367  vector[3 * i + 1] = -1.05f;
368  vector[3 * i + 2] = 0.0f;
369  }
370  for (i = 0; i < 3; i++) {
371  norm = sqrtf(bvec[i][0] * bvec[i][0]+ bvec[i][1] * bvec[i][1]+ bvec[i][2] * bvec[i][2]);
372  for (j = 0; j < 3; j++) {
373  vector[j + 6 * i]
374  += (rot[j][0] * bvec[i][0]
375  + rot[j][1] * bvec[i][1]
376  + rot[j][2] * bvec[i][2]) * 0.2f / norm;
377  }
378  for (j = 0; j < 4; j++) {
379  vector_color[j + 8 * i] = BarColor[i * 2][j];
380  vector_color[j + 8 * i + 4] = BarColor[i * 2][j];
381  }
382  }
383  glLineWidth(linewidth);
384  glNormal3f(0.0f, 0.0f, 1.0f);
385  glVertexPointer(3, GL_FLOAT, 0, vector);
386  glColorPointer(4, GL_FLOAT, 0, vector_color);
387  glDrawArrays(GL_LINES, 0, 6);
388  /*
389  Cartesian (XYZ) flame
390  */
391  for (i = 0; i < 6; i++) {
392  vector[3 * i] = 1.2f;
393  vector[3 * i + 1] = -1.05f;
394  vector[3 * i + 2] = 0.0f;
395  }
396  for (i = 0; i < 3; i++) {
397  for (j = 0; j < 3; j++) {
398  vector[j + 6 * i] += rot[j][i] * 0.2f;
399  }
400  for (j = 0; j < 4; j++) {
401  vector_color[j + 8 * i] = BarColor[i * 2][j];
402  vector_color[j + 8 * i + 4] = BarColor[i * 2][j];
403  }
404  }
405  glLineWidth(linewidth);
406  glNormal3f(0.0f, 0.0f, 1.0f);
407  glVertexPointer(3, GL_FLOAT, 0, vector);
408  glColorPointer(4, GL_FLOAT, 0, vector_color);
409  glDrawArrays(GL_LINES, 0, 6);
410  /*
411  Color bar/circle/cube
412  */
413  if (color_scale == 1 || color_scale == 4) {
414  for (i = 0; i < 5; i++) {
415  for (j = 0; j < 2; j++) {
416  vertices[0 + j * 3 + i * 6] = -1.0f + 0.5f*(GLfloat)i;
417  vertices[1 + j * 3 + i * 6] = -1.0f - 0.1f*(GLfloat)j;
418  vertices[2 + j * 3 + i * 6] = 0.0f;
419  for (k = 0; k < 4; k++) colors[k + 4 * j + 8 * i] = BarColor[i][k];
420  }
421  }/*for (i = 0; i < 10; i++)*/
422  glNormal3f(0.0f, 0.0f, 1.0f);
423  glVertexPointer(3, GL_FLOAT, 0, vertices);
424  glColorPointer(4, GL_FLOAT, 0, colors);
425  glDrawArrays(GL_TRIANGLE_STRIP, 0, 10);
426  }/*if (color_scale == 1 || color_scale == 4)*/
427  else if (color_scale == 2) {
428  /*
429  Periodic color scale
430  */
431  vertices[0] = 0.0f;
432  vertices[1] = -1.0f;
433  vertices[2] = 0.0f;
434  for (j = 0; j < 4; j++) colors[j] = 1.0f - BackGroundColor[j];
435  /**/
436  for (i = 0; i <= 60; i++) {
437  /**/
438  mat2 = (GLfloat)i / 60.0f * 6.0f;
439  /**/
440  if (mat2 <= 1.0) {
441  for (j = 0; j<4; ++j) colors[j + 4 * (i + 1)] = yellow[j] * mat2 + red[j] * (1.0f - mat2);
442  }
443  else if (mat2 <= 2.0) {
444  mat2 = mat2 - 1.0f;
445  for (j = 0; j<4; ++j) colors[j + 4 * (i + 1)] = green[j] * mat2 + yellow[j] * (1.0f - mat2);
446  }
447  else if (mat2 <= 3.0) {
448  mat2 = mat2 - 2.0f;
449  for (j = 0; j<4; ++j) colors[j + 4 * (i + 1)] = cyan[j] * mat2 + green[j] * (1.0f - mat2);
450  }
451  else if (mat2 <= 4.0) {
452  mat2 = mat2 - 3.0f;
453  for (j = 0; j<4; ++j) colors[j + 4 * (i + 1)] = blue[j] * mat2 + cyan[j] * (1.0f - mat2);
454  }
455  else if (mat2 <= 5.0) {
456  mat2 = mat2 - 4.0f;
457  for (j = 0; j<4; ++j) colors[j + 4 * (i + 1)] = magenta[j] * mat2 + blue[j] * (1.0f - mat2);
458  }
459  else {
460  mat2 = mat2 - 5.0f;
461  for (j = 0; j<4; ++j) colors[j + 4 * (i + 1)] = red[j] * mat2 + magenta[j] * (1.0f - mat2);
462  }
463  /**/
464  vertices[0 + 3 * (i + 1)] = 0.2f * cosf((GLfloat)i / 60.0f * 6.283185307f);
465  vertices[1 + 3 * (i + 1)] = 0.2f * sinf((GLfloat)i / 60.0f * 6.283185307f) - 1.0f;
466  vertices[2 + 3 * (i + 1)] = 0.0f;
467  }/*for (i = 0; i <= 60; i++)*/
468  glNormal3f(0.0f, 0.0f, 1.0f);
469  glVertexPointer(3, GL_FLOAT, 0, vertices);
470  glColorPointer(4, GL_FLOAT, 0, colors);
471  glDrawArrays(GL_TRIANGLE_FAN, 0, 62);
472  }/*else if (color_scale == 2)*/
473  else if (color_scale == 6 || color_scale == 7) {
474  for (i = 0; i < 2; i++) {
475  for (j = 0; j < 2; j++) {
476  vertices[0 + j * 3 + i * 6] = -1.0f + 2.0f*(GLfloat)i;
477  vertices[1 + j * 3 + i * 6] = -1.0f - 0.1f*(GLfloat)j;
478  vertices[2 + j * 3 + i * 6] = 0.0f;
479  if (i == 0) for (k = 0; k < 4; k++) colors[k + 4 * j + 8 * i] = bgray[k];
480  else if (i == 1) for (k = 0; k < 4; k++) colors[k + 4 * j + 8 * i] = wgray[k];
481  }
482  }/*for (i = 0; i < 10; i++)*/
483  glNormal3f(0.0f, 0.0f, 1.0f);
484  glVertexPointer(3, GL_FLOAT, 0, vertices);
485  glColorPointer(4, GL_FLOAT, 0, colors);
486  glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
487  }/*if (color_scale == 6 || color_scale == 7)*/
488  glDisableClientState(GL_COLOR_ARRAY);
489 }/*void draw_colorbar*/
490 /**
491  @brief Draw eye-points for the stereogram
492 */
493 static void draw_circles(
494  GLfloat dx2d //!< [in] Translation used for the section-mode
495 ) {
496  int i, j;
497  GLfloat r, vertices[66];
498  /**/
499  r = 0.05f;
500  /**/
501  vertices[0] = 0.7f - dx2d;
502  vertices[1] = scl;
503  vertices[2] = 0.0f;
504  for (i = 0; i <= 20; i++) {
505  vertices[0 + (i + 1) * 3] = r * cosf((GLfloat)i / 20.0f * 6.283185307f) + 0.7f - dx2d;
506  vertices[1 + (i + 1) * 3] = r * sinf((GLfloat)i / 20.0f * 6.283185307f) + scl;
507  vertices[2 + (i + 1) * 3] = 0.0f;
508  }/*for (i = 0; i <= 20; i++)*/
509  glNormal3f(0.0f, 0.0f, 1.0f);
510  glColor3fv(LineColor);
511  glVertexPointer(3, GL_FLOAT, 0, vertices);
512  glDrawArrays(GL_TRIANGLE_FAN, 0, 22);
513  /**/
514  for (i = 0; i < 22; i++) vertices[3 * i] += -1.4f;
515  glVertexPointer(3, GL_FLOAT, 0, vertices);
516  glDrawArrays(GL_TRIANGLE_FAN, 0, 22);
517 }/*void draw_circles*/
518 /**
519  @brief Draw 2D Fermi lines
520 */
521 static void draw_fermi_line() {
522  int i, ib, ibzl;
523  GLfloat vertices[60];
524  /*
525  Draw 2D BZ lines
526  */
527  glLineWidth(linewidth);
528  for (ibzl = 0; ibzl < nbzl2d; ++ibzl) {
529  for (i = 0; i < 3; i++) vertices[i + 3 * ibzl] = bzl2d_proj[ibzl][i];
530  }/*for (ibzl = 0; ibzl < nbzl2d; ++ibzl)*/
531  glNormal3f(0.0f, 0.0f, 1.0f);
532  glColor3fv(LineColor);
533  glVertexPointer(3, GL_FLOAT, 0, vertices);
534  glDrawArrays(GL_LINE_LOOP, 0, nbzl2d);
535  /*
536  Draw Fermi lines
537  */
538  glLineWidth(linewidth);
539  glEnableClientState(GL_COLOR_ARRAY);
540  glNormal3f(0.0f, 0.0f, 1.0f);
541  for (ib = 0; ib < nb; ib++) {
542  if (draw_band[ib] == 1) {
543  glVertexPointer(3, GL_FLOAT, 0, kv2d[ib]);
544  glColorPointer(4, GL_FLOAT, 0, clr2d[ib]);
545  glDrawArrays(GL_LINES, 0, 2 * n2d[ib]);
546  }/*if (draw_band[ib] == 1)*/
547  }/* for (ib = 0; ib < nb; ib++)*/
548  glDisableClientState(GL_COLOR_ARRAY);
549 }/*void draw_fermi_line*/
550 /**
551  @brief Glut Display function
552  called by glutDisplayFunc
553 */
554 void TestGLCanvas::OnPaint(wxPaintEvent& WXUNUSED(event))
555 {
556  GLfloat pos[] = { 1.0f, 1.0f, 1.0f, 0.0f };
557  GLfloat amb[] = { 0.2f, 0.2f, 0.2f, 0.0f };
558  GLfloat dx, dx2d, theta, posz, phi;
559  GLfloat pos1[4], pos2[4];
560  int ierr;
561  char command_name[256];
562 
563  if (draw_band == NULL) return;
564 
565  // This is a dummy, to avoid an endless succession of paint messages.
566  // OnPaint handlers must always create a wxPaintDC.
567  wxPaintDC dc(this);
568 
569  // This is normally only necessary if there is more than one wxGLCanvas
570  // or more than one wxGLContext in the application.
571  SetCurrent(*m_glRC);
572 
573  if (lstereo == 2) {
574  /*
575  Parallel eyes
576  */
577  theta = 3.1416f / 180.0f * 2.5f;
578  posz = 5.0f;
579  dx = 0.7f;
580  phi = atanf(posz / dx) - theta;
581  theta = (3.1416f * 0.5f - phi) / 3.1416f * 180.0f;
582  /**/
583  pos1[0] = posz * cosf(phi) - dx;
584  pos1[1] = 0.0;
585  pos1[2] = posz * sinf(phi);
586  pos1[3] = 1.0;
587  /**/
588  pos2[0] = -posz * cosf(phi) + dx;
589  pos2[1] = 0.0;
590  pos2[2] = posz * sinf(phi);
591  pos2[3] = 1.0;
592  }/*if (lstereo == 2)*/
593  else if (lstereo == 3) {
594  /*
595  Cross eyes
596  */
597  theta = -3.1416f / 180.0f * 2.0f;
598  posz = 5.0;
599  dx = -0.7f;
600  /**/
601  pos1[0] = posz * sinf(theta) - dx;
602  pos1[1] = 0.0;
603  pos1[2] = posz * cosf(theta);
604  pos1[3] = 1.0;
605  /**/
606  pos2[0] = -posz * sinf(theta) + dx;
607  pos2[1] = 0.0;
608  pos2[2] = posz * cosf(theta);
609  pos2[3] = 1.0;
610  }/*if (lstereo == 3)*/
611  else {
612  theta = 0.0;
613  dx = 0.0;
614  }/*lstero == 1*/
615  if (lsection == 1 && fbz == 1) dx2d = 0.7f;
616  else dx2d = 0.0;
617  /*
618  Initialize
619  */
620  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
621  glLoadIdentity();
622  /*
623  Set view point & view line
624  */
625  glTranslatef(0.0, 0.0, -5.0);
626  //gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
627  /*
628  Set position of light
629  */
630  if (lstereo == 1) {
631  glLightfv(GL_LIGHT0, GL_POSITION, pos);
632  glTranslatef(-dx2d, 0.0, 0.0);
633  /*
634  Draw color scale
635  */
636  if (lcolorbar == 1) draw_colorbar();
637  }
638  else {
639  glLightfv(GL_LIGHT0, GL_POSITION, pos1);
640  draw_circles(dx2d);
641  glTranslatef(-dx-dx2d, 0.0, 0.0);
642  glRotatef(theta, 0.0, 1.0, 0.0);
643  }
644  glLightfv(GL_LIGHT1, GL_AMBIENT, amb);
645  /*
646  Rotation & Zoom
647  */
648  glScalef(scl, scl, scl);
649  /*
650  Draw Brillouin zone boundaries
651  */
652  draw_bz_lines();
653  /*
654  Draw Fermi surfaces
655  */
656  draw_fermi();
657  /*
658  Draw the second object for stereogram
659  */
660  if (lstereo != 1) {
661  glPushMatrix();
662  glLoadIdentity();
663  glTranslatef(0.0, 0.0, -5.0);
664  //gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
665  glLightfv(GL_LIGHT0, GL_POSITION, pos2);
666  /**/
667  glTranslatef(dx-dx2d, 0.0, 0.0);
668  glRotatef(-theta, 0.0, 1.0, 0.0);
669  /**/
670  glScalef(scl, scl, scl);
671  draw_bz_lines();
672  draw_fermi();
673  /**/
674  glPopMatrix();
675  }
676  /*
677  Draw 2D Fermi line
678  */
679  if (lsection == 1 && fbz == 1) {
680  glPushMatrix();
681  glLoadIdentity();
682  glTranslatef(0.0, 0.0, -5.0);
683  //gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
684  glLightfv(GL_LIGHT0, GL_POSITION, pos);
685  /**/
686  if (lstereo == 1) glTranslatef(dx2d, 0.0, 0.0);
687  else glTranslatef(2.0f * dx2d, 0.0, 0.0);
688  /**/
689  glScalef(scl, scl, scl);
690  draw_fermi_line();
691  /**/
692  glPopMatrix();
693  }/*if (lsection == 1)*/
694  glFlush(); // Not really necessary: buffer swapping below implies glFlush()
695  SwapBuffers();
696  if (lbatch == 1) {
697  char file2[256], batch2[256];
698  glFlush();
699  strncpy(file2, (const char*)frmsf_file_name.mb_str(wxConvUTF8), 255);
700  strncpy(batch2, (const char*)batch_name.mb_str(wxConvUTF8), 255);
701  sprintf(command_name, "import -window \"%s\" %s.png", file2, batch2);
702  ierr = system(command_name);
703  exit(0);
704  }
705 }/*void display*/
secvec
GLfloat secvec[3]
-vector to define section
Definition: fermisurfer.cpp:160
magenta
GLfloat magenta[4]
Magenta color code.
Definition: fermisurfer.cpp:203
operation.hpp
kvp
GLfloat **** kvp
-vectors of points [nb][ntri][3][3]
Definition: fermisurfer.cpp:140
wgray
GLfloat wgray[4]
Gray color code.
Definition: fermisurfer.cpp:199
bgray
GLfloat bgray[4]
Gray color code.
Definition: fermisurfer.cpp:200
side
GLfloat side
Which side is lighted.
Definition: fermisurfer.cpp:148
green
GLfloat green[4]
Green color code.
Definition: fermisurfer.cpp:206
n2d
int * n2d
Number of line segment.
Definition: fermisurfer.cpp:164
frmsf_file_name
wxString frmsf_file_name
Definition: fermisurfer.cpp:232
kveq_rot
GLfloat ** kveq_rot
-vector of equator [nb][nequator*2*3]
Definition: fermisurfer.cpp:177
ntri
int * ntri
The number of triangle patch [nb].
Definition: fermisurfer.cpp:136
draw_fermi_line
static void draw_fermi_line()
Draw 2D Fermi lines.
Definition: draw.cpp:521
kv2d
GLfloat ** kv2d
-vector for 2D plot [nb][n2d*2*3]
Definition: fermisurfer.cpp:165
linewidth
GLfloat linewidth
BZ/nodal-line/Fermiline width.
Definition: fermisurfer.cpp:193
trans
GLfloat trans[3]
Translation.
Definition: fermisurfer.cpp:186
black
GLfloat black[4]
Black color code.
Definition: fermisurfer.cpp:197
draw_bz_lines
static void draw_bz_lines()
Draw lines of BZ boundaries.
Definition: draw.cpp:218
lstereo
int lstereo
Switch for the stereogram.
Definition: fermisurfer.cpp:119
TestGLCanvas::m_glRC
wxGLContext * m_glRC
Definition: operation.hpp:46
TestGLCanvas::OnPaint
void OnPaint(wxPaintEvent &event)
Glut Display function called by glutDisplayFunc.
Definition: draw.cpp:554
LineColor
GLfloat LineColor[4]
Line color code.
Definition: fermisurfer.cpp:209
SectionColor
GLfloat SectionColor[4]
Line color code.
Definition: fermisurfer.cpp:210
batch_name
wxString batch_name
Definition: fermisurfer.cpp:231
arw_rot
GLfloat ** arw_rot
Definition: fermisurfer.cpp:144
nmlp
GLfloat **** nmlp
Normal vector of patchs [nb][ntri][3][3].
Definition: fermisurfer.cpp:139
color_scale
int color_scale
Switch for full color scale mode.
Definition: fermisurfer.cpp:115
variable.hpp
Global variables.
kveq
GLfloat **** kveq
-vector of equator [nb][nequator][2][3]
Definition: fermisurfer.cpp:176
kvp_rot
GLfloat ** kvp_rot
-vectors of points [nb][ntri*3*3]
Definition: fermisurfer.cpp:143
arrow
GLfloat arrow[2][3]
Definition: fermisurfer.cpp:213
clr
GLfloat ** clr
Colors of points [nb][ntri*3*4].
Definition: fermisurfer.cpp:146
arw
GLfloat ***** arw
Definition: fermisurfer.cpp:141
nodeline
int nodeline
Switch for node lines.
Definition: fermisurfer.cpp:117
BackGroundColor
GLfloat BackGroundColor[4]
BackGround color code.
Definition: fermisurfer.cpp:208
fbz
int fbz
Switch for 1st Brillouin zone mode.
Definition: fermisurfer.cpp:116
lbatch
int lbatch
Definition: fermisurfer.cpp:233
draw_colorbar
static void draw_colorbar()
Draw color-bar or colr-circle (periodic) as a color scale.
Definition: draw.cpp:355
bzl2d
GLfloat bzl2d[26][3]
Lines of 1st BZ [nbzl2d (max:26)][3].
Definition: fermisurfer.cpp:168
lequator
int lequator
Switch for equator.
Definition: fermisurfer.cpp:122
kvnl
GLfloat **** kvnl
-vector of nodeline [nb][nnl][2][3]
Definition: fermisurfer.cpp:155
nmlp_rot
GLfloat ** nmlp_rot
Normal vector of patchs [nb][ntri*3*3].
Definition: fermisurfer.cpp:142
nbzl2d
int nbzl2d
The number of Lines of 1st Brillouin zone.
Definition: fermisurfer.cpp:167
draw_circles
static void draw_circles(GLfloat dx2d)
Draw eye-points for the stereogram.
Definition: draw.cpp:493
red
GLfloat red[4]
Red color code.
Definition: fermisurfer.cpp:205
bzl
GLfloat bzl[676][2][3]
Lines of 1st BZ [nbzl(max:26*26=676)][2][3].
Definition: fermisurfer.cpp:128
sphere_v
GLfloat sphere_v[190][2][3]
Vertices for wisreflame sphere.
Definition: fermisurfer.cpp:219
nb
int nb
The number of Bands.
Definition: fermisurfer.cpp:99
nbzl
int nbzl
The number of Lines of 1st Brillouin zone.
Definition: fermisurfer.cpp:127
bzl2d_proj
GLfloat bzl2d_proj[26][3]
Lines of 1st BZ [nbzl2d (max:26)][3], projected into 2D plane.
Definition: fermisurfer.cpp:169
blue
GLfloat blue[4]
Blue color code.
Definition: fermisurfer.cpp:207
draw_band
int * draw_band
Switch for drawn bands [nb].
Definition: fermisurfer.cpp:137
bvec
GLfloat bvec[3][3]
Reciprocal lattice vector.
Definition: fermisurfer.cpp:101
kvnl_rot
GLfloat ** kvnl_rot
-vector of nodeline [nb][nnl*2*3]
Definition: fermisurfer.cpp:156
cyan
GLfloat cyan[4]
Cyan color code.
Definition: fermisurfer.cpp:202
nnl
int * nnl
The number of nodeline.
Definition: fermisurfer.cpp:154
clr2d
GLfloat ** clr2d
Matrix element for 2D plot [nb][n2d*2*4].
Definition: fermisurfer.cpp:166
BarColor
GLfloat BarColor[5][4]
Definition: fermisurfer.cpp:211
draw_fermi
static void draw_fermi()
Draw Fermi surfaces.
Definition: draw.cpp:50
BZ_number
int BZ_number[3]
Number of BZ.
Definition: fermisurfer.cpp:123
rot
GLfloat rot[3][3]
Rotation matrix.
Definition: fermisurfer.cpp:187
lcolorbar
int lcolorbar
Switch for colorbar.
Definition: fermisurfer.cpp:118
yellow
GLfloat yellow[4]
Yellow color code.
Definition: fermisurfer.cpp:204
scl
GLfloat scl
Initial scale.
Definition: fermisurfer.cpp:185
lsection
int lsection
Switch for the 2D Fermi lines.
Definition: fermisurfer.cpp:121
nequator
int * nequator
The number of equator.
Definition: fermisurfer.cpp:175