File: cryDispFuncMultiFS.c

package info (click to toggle)
xcrysden 1.5.60-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 8,520 kB
  • ctags: 5,658
  • sloc: ansic: 38,087; tcl: 33,153; fortran: 6,460; sh: 2,328; makefile: 657; awk: 368; f90: 33; pascal: 30
file content (286 lines) | stat: -rw-r--r-- 7,720 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/*
 
 *****************************************************************************
 * Author:                                                                   *
 * ------                                                                    *
 *  Anton Kokalj                                  Email: Tone.Kokalj@ijs.si  *
 *  Department of Physical and Organic Chemistry  Phone: x 386 1 477 3523    *
 *  Jozef Stefan Institute                          Fax: x 386 1 477 3811    *
 *  Jamova 39, SI-1000 Ljubljana                                             *
 *  SLOVENIA                                                                 *
 *                                                                           *
 * Source: $XCRYSDEN_TOPDIR/C/cryDispFuncMultiFS.c
 * ------                                                                    *
 * Copyright (c) 1996-2004 by Anton Kokalj                                   *
 *****************************************************************************

*/

#include <togl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "xcGLparam.h"
#include "struct.h"
#include "isosurf.h"
#include "memory.h"
#include "molsurf.h"
#include "vector.h"
#include "bz.h"
#include "wigner.h"
#include "lighting.h"
#include "xcfunc.h"

extern XCantialias    antialias;


extern NEW_WIN_CONTEXT *FindWinContextByTogl(struct Togl *togl);

extern void cryRenderSurface( NEW_WIN_CONTEXT *wc , int fs_mode);
extern void cryRenderRecCell( NEW_WIN_CONTEXT *wc , int fs_mode);

void cryDisplayMultiFS(struct Togl *togl);
static GLfloat _getSize (NEW_WIN_CONTEXT *wc);
static void _cryDisplayMultiFS(struct Togl *togl, NEW_WIN_CONTEXT *wc);

/*
  assign
  cry_dispfuncmultiFS <togl> ...
*/
int 
CRY_DispFuncMultiFSCmd(ClientData clientData,Tcl_Interp *interp,
		       int argc, char *argv[])
{
  struct Togl *togl;
  NEW_WIN_CONTEXT *wc;

  if ( argc < 2 || argc%2 ) {
    interp->result = "Usage: cry_dispfuncmultiFS <togl> ?-togllist? ?-antialias 0|1?";
    return TCL_ERROR;
  }

  if ( ( togl = Togl_FindTogl(argv[1]) ) == NULL ) {
    sprintf(interp->result, 
	    "couldn't find %s togl widget", argv[1]);
    return TCL_ERROR;
  }
  wc = FindWinContextByTogl( togl );
  LoadIdentity( wc->vec.crdmajor );
  vecMatToVec(  wc->vec.crdmajor, wc->vec.crdvec );

  wc->xcDisplay = cryDisplayMultiFS;

  wc->ss.minX = 0.0;
  wc->ss.maxX = 0.0;
  
  wc->ss.minY = 0.0;
  wc->ss.maxY = 0.0;
  
  wc->ss.minZ = 0.0;
  wc->ss.maxZ = 0.0;

  /* next lines are just for now */
  glEnable( GL_DITHER );
  glEnable( GL_DEPTH_TEST );      
  glEnable( GL_LIGHTING );
  glEnable( GL_LIGHT0 );
  glDepthFunc(GL_LEQUAL);
  /*glClearDepth( 1.0 );*/
  glClearColor( wc->bg[0], wc->bg[1], wc->bg[2], wc->bg[3] ); /* T.K. */
  LoadBlendfunc_And_Frontface();
  LoadIsoMaterial( MAT_ONELEVEL | MAT_ISOSURF );
  /*LoadLights();*/


  if (wc->fermiContext.toglVector)
    {
      free(wc->fermiContext.toglVector);
      wc->fermiContext.toglVector = NULL;
    }
  
  if (argc > 2) {
    int i, it, anti_alias;
    for (i=2; i<argc; i+=2)
      {
	/*
	  -TOGLLIST
	*/
	if ( strncmp(argv[i], "-togll", 6) == 0 ) {
	  int argcList;
	  char **argvList;
	  struct Togl **toglVector;
	  Tcl_SplitList(interp, argv[i+1], &argcList, &argvList);
	  toglVector = (struct Togl**) malloc ( sizeof(struct Togl*) * argcList );
	  for (it=0; it<argcList; it++)
	    {
	      NEW_WIN_CONTEXT *ith_wc;
	      if ( ( toglVector[it] = Togl_FindTogl(argvList[it]) ) == NULL ) {
		sprintf(interp->result, 
			"couldn't find %s togl widget", argvList[it]);
		return TCL_ERROR;
	      }
	      
	      ith_wc = FindWinContextByTogl( toglVector[it] );

	      if (ith_wc->VPf.stropened) 
		{
		  wc->VPf.stropened = 1;
		  wc->ss.minX = MIN(wc->ss.minX, ith_wc->ss.minX);
		  wc->ss.maxX = MAX(wc->ss.maxX, ith_wc->ss.maxX);
		  
		  wc->ss.minY = MIN(wc->ss.minY, ith_wc->ss.minY);
		  wc->ss.maxY = MAX(wc->ss.maxY, ith_wc->ss.maxY);
		  
		  wc->ss.minZ = MIN(wc->ss.minZ, ith_wc->ss.minZ);
		  wc->ss.maxZ = MAX(wc->ss.maxZ, ith_wc->ss.maxZ);
		}		
	    }
	  wc->fermiContext.ntogl      = argcList;
	  wc->fermiContext.toglVector = toglVector;
	}
	
	/*
	  -ANTIALIAS
	*/
	else if ( strncmp(argv[i], "-antialias", 6) == 0 ) {
	  if ( Tcl_GetInt(interp, argv[i+1], &anti_alias) == TCL_ERROR ) {
	    sprintf(interp->result,"wanted integer, but got \"%s\"", argv[i+1]);
	    return TCL_ERROR;
	  }
	  wc->VPf.antialias = anti_alias;
	} else {
	  sprintf(interp->result, 
		  "unknown option %s, must be -antialias or -togllist", argv[i]);
	  return TCL_ERROR;
	}
      }
  }
  
  return TCL_OK;
}


static GLfloat _getSize (NEW_WIN_CONTEXT *wc)
{
  wc->MVf.structsize = sqrt( wc->ss.maxX*wc->ss.maxX +
			     wc->ss.maxY*wc->ss.maxY +
			     wc->ss.maxZ*wc->ss.maxZ );  
  return wc->MVf.structsize / wc->tr.zoom;
}

/* 
 * when we enter this procedure we just Made a Display, that means that 
 * everything must be made before that
 */
void
cryDisplayMultiFS(struct Togl *togl)
{
  NEW_WIN_CONTEXT *wc;  
  wc = FindWinContextByTogl( togl );
  if (!wc->fermiContext.toglVector) return; /* no togls associated with this wc */

  /* debugging */
  if (wc == (NEW_WIN_CONTEXT *)NULL) return;

  /*
    line_color[0] = 1.0 - wc->bg[0];
    line_color[1] = 1.0 - wc->bg[1];
    line_color[2] = 1.0 - wc->bg[2];
  */

  if ( ! wc->VPf.antialias ) 
    {
      /* 
	 NO ANTIALIASING 
      */
      _cryDisplayMultiFS (togl, wc);
    } 
  else 
    {
      /* 
	 ANTIALIASING 
      */
      GLint viewport[4];
      GLfloat sx, sy, size, sizeX, sizeY, aspect;
      GLfloat scale, dx, dy;
      int min, max, count, i, j;
      int width  = Togl_Width (togl);
      int height = Togl_Height(togl);
      enum {
	XORG, YORG, WID, HT
      }; 
      
      size   = _getSize (wc);
      aspect = (GLfloat) width / (GLfloat) height;
      if ( aspect>1 ) {
	sizeX = aspect * size;
	sizeY = size;
      } else {
	sizeX = size;
	sizeY = size / aspect;
      }
      glGetIntegerv(GL_VIEWPORT, viewport);
      
      sx = 2.0 * sizeX / viewport[WID];
      sy = 2.0 * sizeX / viewport[WID];
      
      min    = -antialias.degree;
      max    = -min + 1;
      count  = -min + max;
      count *= count;
      
      /* uniform scaling, less than one pixel wide */
      scale = -antialias.offset / min;
      
      glClear(GL_ACCUM_BUFFER_BIT);
      
      for (j = min; j < max; j++) {
	for (i = min; i < max; i++) 
	  {
	    dx = sx * scale * i;
	    dy = sy * scale * j;
	    glMatrixMode(GL_PROJECTION);
	    glLoadIdentity();	    
	    glOrtho(-sizeX + dx, sizeX + dx, 
		    -sizeY + dy, sizeY + dy, 
		    -wc->MVf.structsize, 2*wc->MVf.structsize); /* see the crySetProj.c file !!! */

	    glMatrixMode(GL_MODELVIEW);
	    _cryDisplayMultiFS (togl, wc);
	    glAccum(GL_ACCUM, 1.0 / (GLfloat)count);
	  }
      }
      glAccum(GL_RETURN, 1.0);
    }
  
  Togl_SwapBuffers(togl);
}

static void _cryDisplayMultiFS(struct Togl *togl, NEW_WIN_CONTEXT *wc) 
{
  /*GLdouble size = (GLdouble) _getSize (wc);*/
  int it;

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  

  /* INSERT HERE ROTATION MATRIX */
  glLoadIdentity();
  glTranslated(0.0, 0.0, -0.5*wc->MVf.structsize); /* see crySetProj.c */
  glMultMatrixd( wc->vec.crdvec );
  
  /* fog */
  xcFog (togl, wc->VPf.fog, GL_FALSE);

  glDisable(GL_BLEND); 
  glDepthMask(GL_TRUE);  
  
  for (it=0; it<wc->fermiContext.ntogl; it++)
    {
      NEW_WIN_CONTEXT *ith_wc = FindWinContextByTogl( wc->fermiContext.toglVector[it] );
      if ( ith_wc->VPf.nsurface )    cryRenderSurface( ith_wc , FS_MULTI );
      if ( ith_wc->VPf.dispLattice ) cryRenderRecCell( ith_wc , FS_MULTI );
    }
  /*--------------------*/
  glFlush();      
}