예제 #1
0
파일: decomp.c 프로젝트: nhatcher/lie
local poly* decompose_character(poly* ch)
{   wt_init(ch->ncols); /* for building result */
    while (ch->coef[0]->size!=0) /* i.e., |while (ch!=0)| */
    {   bigint* c=ch->coef[0];
        if (c->size<0)

        {   cmpfn=sav_cmpfn;
            defaultgrp=sav_dfgrp;
            error ("Non-virtual decomposition failed.\n");
        }

        {   wt_ins(ch->elm[0],c,false); /* contribute weight to result */
            c=copybigint(c,NULL);
            c->size= -c->size;
            ch=Addmul_pol_pol_bin(ch,Domchar_irr(ch->elm[0],NULL),c);
        }
    }
    {   poly* result=wt_collect();

        {
            cmpfn=sav_cmpfn;
            defaultgrp=sav_dfgrp;
            clrsorted(result);
        }
        return result;
    }
}
예제 #2
0
파일: decomp.c 프로젝트: nhatcher/lie
local poly* simp_vdecomp_irr(entry* lambda, simpgrp* g)
{   the_g=g;
    wt_init(g->lierank);
    Weylloopinit(g);
    Weylloop(add_decomp_wt,lambda);
    Weylloopexit();
    return wt_collect();
}
예제 #3
0
파일: lr.c 프로젝트: d4g33z/lie
poly* LR_tensor_irr(entry* lambda,entry * mu, _index n)
{ _index i,j;
	entry* nu; entry** T;
  if (n==0) return poly_one(0);
  
  { nu=&mkintarray(n+1)[1]; copyrow(lambda,nu,n); nu[-1]=lambda[0]+mu[0];
  T=alloc_array(entry*,n+1);
    for (i=0;i<=n;++i) /* allocate row |T[i]| and place sentinel before it */
    	{ T[i]= &mkintarray(mu[i==0?0:i-1]+1)[1]; T[i][-1]=n-1-i; }
    for (i=0,j=mu[0]-1; j>=0; --j)
    { while (i<n && mu[i]>j) ++i; /* find first |i| with |mu[i]<=j| */
      T[i][j]=-1; /* place sentinel at bottom of column |j| */
    } 
  }
  wt_init(n); /* prepare to collect terms with exponents of size~|n| */

  
  { j=-1;  for (i=n-1; i>0 && mu[i]==0; --i) {} /* move to initial position */
  recurse: /* recursive starting point; */
    if (++j>=mu[i] &&(j=0,--i<0)) /* move to next empty position, if any */
      wt_ins(nu,one,false); /* if not, |T| is full; contribute |nu| once */
  else
    
    { _index k= T[i+1][j]; entry prev= nu[k];
      do
      { while (nu[++k]==prev) {} /* find next |k| with |nu[k]<nu[@t$k'$@>]| */
        ++nu[T[i][j]=k]; goto recurse;
          /* insert |k| into |T| and extend partition |nu|; recurse */
        resume: prev= --nu[k=T[i][j]];
          /* restore |k| and |nu|; set |prev=nu[k]| */
      } while (prev>nu[T[i][j-1]]);
          /* if so, there are still corners of |nu| to try */
    }
    if (j==0) j= ++i<n?mu[i]:0; /* return to end of row below if necessary */
    if (--j>=0) goto resume; /* do return jump unless empty row is reached */
  }
  
  { --nu; freearr(nu);
    for (i=0;i<=n;i++) { entry* t=&T[i][-1]; freearr(t); }
    freearr(T);
  }
  return wt_collect(); /* return sum of all contributed terms */
}
예제 #4
0
int main(int argc, char *argv[])
{
     int quit = False;
     
     if (argc != 2) {
   	  fprintf(stderr, "Usage:  wt <world file>\n");
   	  exit(EXIT_FAILURE);
     }

     if (wt_init(argv[1],320,200) == EXIT_FAILURE) {
   	  perror(argv[1]);
   	  exit(EXIT_FAILURE);   
     }

     while (!quit) {
       wt_render();
       quit = wt_input();
     }

     wt_term();
     return EXIT_SUCCESS;
}
예제 #5
0
파일: symg.c 프로젝트: nhatcher/lie
poly* MN_char(entry* lambda, lie_Index l)
{ lie_Index n=check_part(lambda,l);
  if (n==0) return poly_one(0); /* the character of $\Sym0$ */
  while (lambda[l-1]==0) --l; /* minimise |l| */
  wt_init(n); /* get ready for accumulating contributions to the character */
  { 
    entry* mu=mkintarray(3*n),* save=mu+n,* lambda_prime=save+n;
    int i, j, r, d=lambda[0]+l, k=0; /* sum of leg lengths */
    boolean* edge=alloc_array(boolean,2*d-2),* candidate=edge+d-2;
      /* lie_Index |2<=r<d| */
    enum {hor, vert}; /* values used for |edge| */
    
    for (i=0; i<n; ++i) mu[i]=0;
    
    { int r=l-1,c=0; /* current column number */
      for (j=0; r>=0; --r)
      { while (c<lambda[r]) { edge[j++]=hor; ++c; } /* columns of length |r| */
        edge[j++]=vert; /* row |r|, of length |c==lambda[r]| */
      }
    }
    
    for (r=2; r<d; ++r)
    { for (j=0; j+r<d; ++j)
        if (edge[j]==hor && edge[j+r]==vert) break;
      candidate[r]= j+r<d;
    }
    

    
    { i=0; /* index of last entry that was set in~|mu| */
      for (r=d-1; r>1; --r) /* try hooks of size |r| */
        if (candidate[r])
        { recurse: /* recursive starting point */
          
          { for (j=1; j<r; ++j) k+=edge[j]; /* leg length of hook first tried */
            for (j=0; j<d-r; ++j)
            { if (edge[j]==hor && edge[j+r]==vert)
              { edge[j]=vert; edge[j+r]=hor; mu[i]=r; save[i++]=j; goto recurse;
              resume: j=save[--i]; r=mu[i]; mu[i]=0; edge[j]=hor; edge[j+r]=vert;
              }
              k+= edge[j+r]-edge[j+1]; /* adjust |k| for hook tried next */
            }
            while (++j<d) k-= edge[j]; /* restore |k| */
          }
        }
    }
    
    { int r=l,c=0,s=0; /* size of |lambda_prime| */
      for (j=0; r>0; )
        if (edge[j++]==vert) s+=lambda_prime[--r]=c;  else ++c;
        /* build |lambda_prime| from edges */
      for (j=0; j<s; ++j) mu[i++]=1; /* extend |mu| with |s| ones */
      wt_ins(mu,n_tableaux(lambda_prime,l),k%2);
      for (j=0; j<s; ++j) mu[--i]=0; /* remove the ones again */
    }
    if (i>0) goto resume;
    
     
    { freearr(edge); freearr(mu); }
  }
  return wt_collect();
}
예제 #6
0
void do_tests()
{
  DBUG_ENTER("do_tests");

  skip_all(": this module is not used in MySQL");

  plan(12);
  compile_time_assert(THREADS >= 4);

  DBUG_PRINT("wt", ("================= initialization ==================="));

  bad= my_atomic_initialize();
  ok(!bad, "my_atomic_initialize() returned %d", bad);

  mysql_cond_init(0, &thread_sync, 0);
  mysql_mutex_init(0, &lock, 0);
  wt_init();
  for (cnt=0; cnt < THREADS; cnt++)
    mysql_mutex_init(0, & thds[cnt].lock, 0);
  {
    WT_RESOURCE_ID resid[4];
    for (i=0; i < array_elements(resid); i++)
    {
      wt_thd_lazy_init(& thds[i].thd,
                       & wt_deadlock_search_depth_short, & wt_timeout_short,
                       & wt_deadlock_search_depth_long, & wt_timeout_long);
      resid[i].value= i+1;
      resid[i].type= &restype;
    }

    DBUG_PRINT("wt", ("================= manual test ==================="));

#define ok_wait(X,Y, R) \
    ok(wt_thd_will_wait_for(& thds[X].thd, & thds[Y].thd, &resid[R]) == 0, \
      "thd[" #X "] will wait for thd[" #Y "]")
#define ok_deadlock(X,Y,R) \
    ok(wt_thd_will_wait_for(& thds[X].thd, & thds[Y].thd, &resid[R]) == WT_DEADLOCK, \
      "thd[" #X "] will wait for thd[" #Y "] - deadlock")

    ok_wait(0,1,0);
    ok_wait(0,2,0);
    ok_wait(0,3,0);

    mysql_mutex_lock(&lock);
    bad= wt_thd_cond_timedwait(& thds[0].thd, &lock);
    mysql_mutex_unlock(&lock);
    ok(bad == WT_TIMEOUT, "timeout test returned %d", bad);

    ok_wait(0,1,0);
    ok_wait(1,2,1);
    ok_deadlock(2,0,2);

    mysql_mutex_lock(&lock);
    ok(wt_thd_cond_timedwait(& thds[0].thd, &lock) == WT_TIMEOUT, "as always");
    ok(wt_thd_cond_timedwait(& thds[1].thd, &lock) == WT_TIMEOUT, "as always");
    wt_thd_release_all(& thds[0].thd);
    wt_thd_release_all(& thds[1].thd);
    wt_thd_release_all(& thds[2].thd);
    wt_thd_release_all(& thds[3].thd);

    for (i=0; i < array_elements(resid); i++)
    {
      wt_thd_release_all(& thds[i].thd);
      wt_thd_destroy(& thds[i].thd);
    }
    mysql_mutex_unlock(&lock);
  }

  wt_deadlock_search_depth_short=6;
  wt_timeout_short=1000;
  wt_timeout_long= 100;
  wt_deadlock_search_depth_long=16;
  DBUG_PRINT("wt", ("================= stress test ==================="));

  diag("timeout_short=%lu us, deadlock_search_depth_short=%lu",
       wt_timeout_short, wt_deadlock_search_depth_short);
  diag("timeout_long=%lu us, deadlock_search_depth_long=%lu",
       wt_timeout_long, wt_deadlock_search_depth_long);

#define test_kill_strategy(X)                   \
  diag("kill strategy: " #X);                   \
  DBUG_EXECUTE("reset_file",                    \
               { rewind(DBUG_FILE); my_chsize(fileno(DBUG_FILE), 0, 0, MYF(0)); }); \
  DBUG_PRINT("info", ("kill strategy: " #X));   \
  kill_strategy=X;                              \
  do_one_test();

  test_kill_strategy(LATEST);
  test_kill_strategy(RANDOM);
  /*
    these two take looong time on sol10-amd64-a
    the server doesn't use this code now, so we disable these tests

    test_kill_strategy(YOUNGEST);
    test_kill_strategy(LOCKS);
  */

  DBUG_PRINT("wt", ("================= cleanup ==================="));
  for (cnt=0; cnt < THREADS; cnt++)
    mysql_mutex_destroy(& thds[cnt].lock);
  wt_end();
  mysql_mutex_destroy(&lock);
  mysql_cond_destroy(&thread_sync);
  DBUG_VOID_RETURN;
}
예제 #7
0
파일: dwttest.c 프로젝트: soulsheng/wavelib
int main() {
	wave_object obj;
	wt_object wt;
	double *inp,*out,*diff;
	int N, i,J;

	FILE *ifp;
	double temp[1200];

	char *name = "db4";
	obj = wave_init(name);// Initialize the wavelet

	ifp = fopen(FILE_SIGNAL, "r");
	i = 0;
	if (!ifp) {
		printf("Cannot Open File");
		exit(100);
	}
	while (!feof(ifp)) {
		fscanf(ifp, "%lf \n", &temp[i]);
		i++;
	}
	N = 256;

	inp = (double*)malloc(sizeof(double)* N);
	out = (double*)malloc(sizeof(double)* N);
	diff = (double*)malloc(sizeof(double)* N);
	//wmean = mean(temp, N);

	for (i = 0; i < N; ++i) {
		inp[i] = temp[i];
		//printf("%g \n",inp[i]);
	}
	J = 3;

	wt = wt_init(obj, "dwt", N, J);// Initialize the wavelet transform object
	setDWTExtension(wt, "sym");// Options are "per" and "sym". Symmetric is the default option
	setWTConv(wt, "direct");
	
	dwt(wt, inp);// Perform DWT
	//DWT output can be accessed using wt->output vector. Use wt_summary to find out how to extract appx and detail coefficients
	
	for (i = 0; i < wt->outlength; ++i) {
	//	printf("%g ",wt->output[i]);
	}
	
	idwt(wt, out);// Perform IDWT (if needed)
	// Test Reconstruction
	for (i = 0; i < wt->siglength; ++i) {
		diff[i] = out[i] - inp[i];
	}
	
	printf("\n MAX %g \n", absmax(diff, wt->siglength)); // If Reconstruction succeeded then the output should be a small value.
	
	wt_summary(wt);// Prints the full summary.
	wave_free(obj);
	wt_free(wt);

	free(inp);
	free(out);
	free(diff);
	return 0;
}
예제 #8
0
파일: modwttest.c 프로젝트: rafat/wavelib
int main() {
	wave_object obj;
	wt_object wt;
	double *inp, *out, *diff;
	int N, i, J;

	FILE *ifp;
	double temp[1200];

	char *name = "db4";
	obj = wave_init(name);
	wave_summary(obj);

	ifp = fopen("signal.txt", "r");
	i = 0;
	if (!ifp) {
		printf("Cannot Open File");
		exit(100);
	}
	while (!feof(ifp)) {
		fscanf(ifp, "%lf \n", &temp[i]);
		i++;
	}
	N = 177;
	
	fclose(ifp);

	inp = (double*)malloc(sizeof(double)* N);
	out = (double*)malloc(sizeof(double)* N);
	diff = (double*)malloc(sizeof(double)* N);
	//wmean = mean(temp, N);

	for (i = 0; i < N; ++i) {
		inp[i] = temp[i];
		//printf("%g \n",inp[i]);
	}
	J = 2;

	wt = wt_init(obj, "modwt", N, J);// Initialize the wavelet transform object
	
	modwt(wt, inp);// Perform MODWT
	//MODWT output can be accessed using wt->output vector. Use wt_summary to find out how to extract appx and detail coefficients
	
	for (i = 0; i < wt->outlength; ++i) {
		printf("%g ",wt->output[i]);
	}

	imodwt(wt, out);// Perform ISWT (if needed)
	// Test Reconstruction


	for (i = 0; i < wt->siglength; ++i) {
		diff[i] = out[i] - inp[i];
	}

	printf("\n MAX %g \n", absmax(diff, wt->siglength));// If Reconstruction succeeded then the output should be a small value.
	
	wt_summary(wt);// Prints the full summary.

	wave_free(obj);
	wt_free(wt);

	free(inp);
	free(out);
	free(diff);
	return 0;
}
예제 #9
0
/////////////////////////////////////////////////////////////////////////////
// AppWndProc( hwnd, uiMessage, wParam, lParam )
//
// The window proc for the app's main (tiled) window.  This processes all
// of the parent window's messages.
//
LONG FAR PASCAL _export AppWndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
    PAINTSTRUCT ps;
    HDC hdc;
    BOOL f;

		//is it the registered message?  (this proc is called after the creation
		//of the msgApp).

	 if (msg == msgApp) {				
 		 if (bShowRendering) {
		 	HDC hdc = GetDC(hwndApp);
		 	AppPaint(hwndApp, hdc);
		 	ReleaseDC(hwndApp, hdc);
		 	bShowRendering = (int)wParam;	//sent a 0 to turn off bShowRendering.
		 }
	    return 0L;
	 }
		
		//well, how about standard Windows messages?

    switch (msg)
    {
    case WM_CREATE:
			//let WM_SIZE do all the work.
	      break;

    case WM_ACTIVATEAPP:
		    bAppActive = (BOOL)wParam;
			wt_reset_input();
			// *** Remap the system colors and deal with the palette
			AppActivate(bAppActive);

			if (hpalApp)
			{
				HDC hdc = GetDC(hwnd);

				UnrealizeObject(hpalApp);
				SelectPalette(hdc, hpalApp, FALSE);
				RealizePalette(hdc);

				ReleaseDC(hwnd, hdc);
			}
			break;

    case WM_SIZE:			
			wt_reset_input();
		   nBitmapW = LOWORD(lParam);			//new size.
		   nBitmapH = HIWORD(lParam);

			nBitmapW /= StretchFactor;
			nBitmapH /= StretchFactor;

			//Windows DIBs, including WinG bitmaps, are always a multiple of 
			//32-bits wide.  For us, using the typical 8-bit per pixel bitmap,
			//that means we need to ensure the width is a multiple of 4.  This
			//is important because the WT engine treats a bitmap's width and 
			//pitch as one - there is no way for WT to draw into a bitmap
			//using a width different than the pitch.  So we force the bitmap's
			//width to be a multiple of 4, to be both Windows and WT compatible.
			//Note we could have patched WT to deal with the concept of a 
			//bitmap pitch, but that's too much change.

			nBitmapW = ((nBitmapW+3)/4)*4;

			if(Buffer)
			{						//resizing, minimizing, maximizing.
			 	HBITMAP hbm;
			   int Counter;

				//Create a new 8-bit WinGBitmap with the new size
				BufferHeader.Header.biWidth = nBitmapW;
				BufferHeader.Header.biHeight = nBitmapH * Orientation;

				//probably don't need to do this, but do it anyway.
			   for(Counter = 0;Counter < 256;Counter++) {
				    	BufferHeader.aColors[Counter].rgbRed   = ColorTable[Counter].rgbRed;
				    	BufferHeader.aColors[Counter].rgbGreen = ColorTable[Counter].rgbGreen;
				    	BufferHeader.aColors[Counter].rgbBlue  = ColorTable[Counter].rgbBlue;
				    	BufferHeader.aColors[Counter].rgbReserved = 0;
				}

				hbm = WinG.pCreateBitmap(Buffer,
					(BITMAPINFO *)&BufferHeader, &pBuffer);

				//  Select it in and delete the old one
				hbm = (HBITMAP)SelectObject(Buffer, hbm);
				DeleteObject(hbm);

   			PatBlt(Buffer, 0,0,nBitmapW,nBitmapH, BLACKNESS);

	         wt_set_fb_mem(pBuffer);		//tell WT about new bitmap address.
			   wt_reinit(nBitmapW,nBitmapH);  //and about new bitmap size.
				wt_render();					//and have WT render a frame.

			}
			else						//first time.
			{
				//  Create a new WinGDC and 8-bit WinGBitmap

				HBITMAP hbm;
			   int Counter;

				//  Get WinG to recommend the fastest DIB format

				if(WinG.pRecommendDIBFormat((BITMAPINFO *)&BufferHeader))
				{
					//  make sure it's 8bpp and remember the orientation

					BufferHeader.Header.biBitCount = 8;
					BufferHeader.Header.biCompression = BI_RGB;
					Orientation = BufferHeader.Header.biHeight;
					if (Orientation > 0) {
						DebugMsg("WT requires a top-down bitmap!\nYou are about to hit a brick wall at 90 MPH!");
						PostQuitMessage(1);		//works but slams palette.  bummer.
					}
				}
				else
				{
					//  set it up ourselves
	
					BufferHeader.Header.biSize = sizeof(BITMAPINFOHEADER);
					BufferHeader.Header.biPlanes = 1;
					BufferHeader.Header.biBitCount = 8;
					BufferHeader.Header.biCompression = BI_RGB;
					BufferHeader.Header.biSizeImage = 0;
					BufferHeader.Header.biClrUsed = 0;
					BufferHeader.Header.biClrImportant = 0;
				}

				BufferHeader.Header.biWidth = nBitmapW;
				BufferHeader.Header.biHeight = nBitmapH * Orientation;

//#define BAD_PALETTE_CODE
#ifdef BAD_PALETTE_CODE
//This code sets an incorrect palette, but at least you can still use
//regular windows tools.  Good for debugging.
			   HDC Screen;
			   RGBQUAD *pColorTable;

				//  create an identity palette from the DIB's color table

				//  get the 20 system colors as PALETTEENTRIES
    
			    Screen = GetDC(0);

			    GetSystemPaletteEntries(Screen,0,10,LogicalPalette.aEntries);
			    GetSystemPaletteEntries(Screen,246,10,
								LogicalPalette.aEntries + 246);

				ReleaseDC(0,Screen);

				// initialize the logical palette and DIB color table

			    for(Counter = 0;Counter < 10;Counter++)
			    {
			    	// copy the system colors into the DIB header
			    	// WinG will do this in WinGRecommendDIBFormat,
			    	// but it may have failed above so do it here anyway
			    	
			    	BufferHeader.aColors[Counter].rgbRed =
			    					LogicalPalette.aEntries[Counter].peRed;
			    	BufferHeader.aColors[Counter].rgbGreen =
			    					LogicalPalette.aEntries[Counter].peGreen;
			    	BufferHeader.aColors[Counter].rgbBlue =
			    					LogicalPalette.aEntries[Counter].peBlue;
			    	BufferHeader.aColors[Counter].rgbReserved = 0;

   					LogicalPalette.aEntries[Counter].peFlags = 0;

			    	BufferHeader.aColors[Counter + 246].rgbRed =
		    					LogicalPalette.aEntries[Counter + 246].peRed;
			    	BufferHeader.aColors[Counter + 246].rgbGreen =
		    					LogicalPalette.aEntries[Counter + 246].peGreen;
			    	BufferHeader.aColors[Counter + 246].rgbBlue =
		    					LogicalPalette.aEntries[Counter + 246].peBlue;
			    	BufferHeader.aColors[Counter + 246].rgbReserved = 0;

   					LogicalPalette.aEntries[Counter + 246].peFlags = 0;
   				}

            for (i=0; i<256; i++) {
               ColorTable[i].rgbRed = 0;
               ColorTable[i].rgbGreen = 0;
               ColorTable[i].rgbBlue = 0;
            }

            nColors = wt_load_palette();
            for (i=0; i<nColors; i++) {
               int r,g,b;
               wt_get_palette_entry(i,&r,&g,&b);
               ColorTable[i].rgbRed = r;
               ColorTable[i].rgbGreen = g;
               ColorTable[i].rgbBlue = b;
            }
            pColorTable = &ColorTable[0];

			    for(Counter = 10;Counter < 246;Counter++)
			    {
			    	// copy from the original color table to the WinGBitmap's
			    	// color table and the logical palette

			    	BufferHeader.aColors[Counter].rgbRed =
    					LogicalPalette.aEntries[Counter].peRed =
    						pColorTable[Counter].rgbRed;
			    	BufferHeader.aColors[Counter].rgbGreen =
    					LogicalPalette.aEntries[Counter].peGreen =
    						pColorTable[Counter].rgbGreen;
			    	BufferHeader.aColors[Counter].rgbBlue =
    					LogicalPalette.aEntries[Counter].peBlue =
    						pColorTable[Counter].rgbBlue;
			    	BufferHeader.aColors[Counter].rgbReserved = 0;
  					LogicalPalette.aEntries[Counter].peFlags = PC_NOCOLLAPSE;
			    }

			    hpalApp = CreatePalette((LOGPALETTE *)&LogicalPalette);
#else
//GOOD_PALETTE_CODE
//Working palette code.  Has correct colors. And identity.  Same frame
//rate as bad palette code.  This really hoses Windows colors, so
//a GUI debugger's windows are really hard to read.  I couldn't read the
//Symantec IDDE's windows - so I #ifdef'd the bad palette code in for
//debugging.
//Anyway, this code works.  Need 3 things for identity, as far as I can tell:
//1. you have to be writing to your bitmap using a specific palette, 
//2. this palette has to be made into a Windows palette, and selected.
//3. this palette has to be copied into the BitmapInfo header of the WinG
//   bitmap, before creating it (actually as a parameter to creating it).
//
				ClearSystemPalette();
				CreateWTPalette();

			    for(Counter = 0;Counter < 256;Counter++) {
				    	BufferHeader.aColors[Counter].rgbRed   = ColorTable[Counter].rgbRed;
				    	BufferHeader.aColors[Counter].rgbGreen = ColorTable[Counter].rgbGreen;
				    	BufferHeader.aColors[Counter].rgbBlue  = ColorTable[Counter].rgbBlue;
				    	BufferHeader.aColors[Counter].rgbReserved = 0;
				}
#endif
			    
				//  Create a WinGDC and Bitmap, then select away
				Buffer = WinG.pCreateDC();
				hbm = WinG.pCreateBitmap(Buffer,
					(BITMAPINFO *)&BufferHeader, &pBuffer);

				//  Store the old hbitmap to select back in before deleting
				gbmOldMonoBitmap = (HBITMAP)SelectObject(Buffer, hbm);

   			PatBlt(Buffer, 0,0,nBitmapW,nBitmapH, BLACKNESS);

            wt_set_fb_mem(pBuffer);		//hack to get around WT's code.
            strcpy(szDefaultWorldFileName, szModulePath);
            strcat(szDefaultWorldFileName, DEFAULT_WORLD_FILEPATH);
            wt_init(szDefaultWorldFileName, nBitmapW,nBitmapH); 
				AppSetCaption(DEFAULT_WORLD_FILETITLE);

            wt_render();
			}
			bWTinitialized = TRUE;		
            break;

		case WM_KEYDOWN:
						//set WT's keyboard array, then do a WT cycle.
				switch (wParam) {
					case VK_UP:
						kbPressed[kbUpArrow] = 1; break;
					case VK_DOWN:
						kbPressed[kbDownArrow] = 1; break;
					case VK_LEFT:
						kbPressed[kbLeftArrow] = 1; break;
					case VK_RIGHT:
						kbPressed[kbRightArrow] = 1; break;
					case VK_CONTROL:
						kbPressed[kbCtrl] = 1; break;
					case VK_ESCAPE:
						kbPressed[kbEsc] = 1; 
						//DestroyWindow() here?  let's check to ensure that func
						//  will send the proper msgs to close stuff.
						break;
					case VK_SPACE:
						kbPressed[kbSpace] = 1; break;
					case VK_SHIFT:
						kbPressed[kbLeftShift] = 1; break;
					case VK_TAB:
						kbPressed[kbAlt] = 1; break;
				}

					//tried using wt_input/wt_render/InvalidateRect sequence
					//here, but was sometimes jerky (missed frames, actually), 
					//if there was too much keyboard activity.  
					//I think windows was collapsing queued/pending
					//WM_PAINT messages, so that the app got one instead of a 
					//sudden stream.  Anyhow now I draw immediately, and it works
					//great.  Note that AppIdle() processing is required to
					//have acceleration/deceleration/monsters/events occur without
					//keyboard input.  I guess a timer could also be used.
					//So I ended up using this helper routine to repaint.

				AppDoCycle();
				break;

		case WM_KEYUP:
						//set WT's keyboard array, then do a WT cycle.
				switch (wParam) {
					case VK_UP:
						kbPressed[kbUpArrow] = 0; break;
					case VK_DOWN:
						kbPressed[kbDownArrow] = 0; break;
					case VK_LEFT:
						kbPressed[kbLeftArrow] = 0; break;
					case VK_RIGHT:
						kbPressed[kbRightArrow] = 0; break;
					case VK_CONTROL:
						kbPressed[kbCtrl] = 0; break;
					case VK_ESCAPE:
						kbPressed[kbEsc] = 0; break;
					case VK_SPACE:
						kbPressed[kbSpace] = 0; break;
					case VK_SHIFT:
						kbPressed[kbLeftShift] = 0; break;
					case VK_TAB:
						kbPressed[kbAlt] = 0; break;
				}

				AppDoCycle();
				break;

		case WM_LBUTTONDOWN:
				break;

		case WM_RBUTTONDOWN:
				break;

      case WM_MOUSEMOVE:
        	break;

      case WM_COMMAND:
            return AppCommand(hwnd,msg,wParam,lParam);

		case WM_DESTROY:
            PostQuitMessage(0);
            break;

      case WM_CLOSE:
		 	   break;

      case WM_PALETTECHANGED:
		    	if ((HWND)wParam == hwnd)
					break;

	    // fall through to WM_QUERYNEWPALETTE

		case WM_QUERYNEWPALETTE:
		    hdc = GetDC(hwnd);

		    if (hpalApp)
				SelectPalette(hdc, hpalApp, FALSE);
	
		    f = RealizePalette(hdc);
		    ReleaseDC(hwnd,hdc);
	
		    if (f)
				InvalidateRect(hwnd,NULL,TRUE);
	
		    return f;
	
	     case WM_PAINT:
		    hdc = BeginPaint(hwnd,&ps);
			 SelectPalette(hdc, hpalApp, FALSE);
			 RealizePalette(hdc);
		    AppPaint (hwnd,hdc);
	       EndPaint(hwnd,&ps);
	       return 0L;
	    }
	return DefWindowProc(hwnd,msg,wParam,lParam);
}
예제 #10
0
파일: decomp.c 프로젝트: nhatcher/lie
void char_init(object g) {
    set_weight_sorting(g);
    wt_init(Lierank(g));
}
예제 #11
0
파일: tst_dwt.cpp 프로젝트: dsimba/wavelib
void ReconstructionTest()
{

	wave_object obj;
	wt_object wt;
	double *inp,*out;
	int N, i,J;
    double epsilon = 1e-15;
    char *type = (char*) "dwt";

    N = 79926;
    
    //N = 256;

	inp = (double*)malloc(sizeof(double)* N);
	out = (double*)malloc(sizeof(double)* N);
	//wmean = mean(temp, N);

	for (i = 0; i < N; ++i) {
        inp[i] = (rand() / (double)(RAND_MAX));
	}
    std::vector<std::string > waveletNames;

    for (unsigned int j = 0; j < 36; j++)
    {
        waveletNames.push_back(std::string("db") + patch::to_string(j + 1));
    }
    for (unsigned int j = 0; j < 17; j++)
    {
        waveletNames.push_back(std::string("coif") + patch::to_string(j + 1));
    }
    for (unsigned int j = 1; j < 20; j++)
    {
        waveletNames.push_back(std::string("sym") + patch::to_string(j + 1));
    }
    
    waveletNames.push_back("bior1.1");
    waveletNames.push_back("bior1.3");
    waveletNames.push_back("bior1.5");
    waveletNames.push_back("bior2.2");
    waveletNames.push_back("bior2.4");
    waveletNames.push_back("bior2.6");
    waveletNames.push_back("bior2.8");
    waveletNames.push_back("bior3.1");
    waveletNames.push_back("bior3.3");
    waveletNames.push_back("bior3.5");
    waveletNames.push_back("bior3.7");
    waveletNames.push_back("bior3.9");
    waveletNames.push_back("bior4.4");
    waveletNames.push_back("bior5.5");
    waveletNames.push_back("bior6.8");
    
    waveletNames.push_back("rbior1.1");
    waveletNames.push_back("rbior1.3");
    waveletNames.push_back("rbior1.5");
    waveletNames.push_back("rbior2.2");
    waveletNames.push_back("rbior2.4");
    waveletNames.push_back("rbior2.6");
    waveletNames.push_back("rbior2.8");
    waveletNames.push_back("rbior3.1");
    waveletNames.push_back("rbior3.3");
    waveletNames.push_back("rbior3.5");
    waveletNames.push_back("rbior3.7");
    waveletNames.push_back("rbior3.9");
    waveletNames.push_back("rbior4.4");
    waveletNames.push_back("rbior5.5");
    waveletNames.push_back("rbior6.8");

    for (unsigned int direct_fft = 0; direct_fft < 2; direct_fft++)
    {
        for (unsigned int sym_per = 0; sym_per < 2; sym_per++)
        {
            for (unsigned int j = 0; j < waveletNames.size(); j++)
            {
                char * name = new char[waveletNames[j].size() + 1];
                memcpy(name, waveletNames[j].c_str(), waveletNames[j].size() + 1);
                obj = wave_init(name);// Initialize the wavelet
                for (J = 1; J < 3; J++)
                {
                    //J = 3;

                    wt = wt_init(obj,(char*) "dwt", N, J);// Initialize the wavelet transform object
                    if (sym_per == 0)
                        setDWTExtension(wt, (char*) "sym");// Options are "per" and "sym". Symmetric is the default option
                    else
                        setDWTExtension(wt, (char*) "per");
                    if (direct_fft == 0)
                        setWTConv(wt, (char*) "direct");
                    else
                        setWTConv(wt, (char*) "fft");

                    dwt(wt, inp);// Perform DWT

                    idwt(wt, out);// Perform IDWT (if needed)
                    // Test Reconstruction

                    if (direct_fft == 0)
                        epsilon = 1e-8;
                    else
                        epsilon = 1e-10;
                    //BOOST_CHECK_SMALL(RMS_Error(out, inp, wt->siglength), epsilon); // If Reconstruction succeeded then the output should be a small value.
                    
					//printf("%g ",RMS_Error(out, inp, wt->siglength));
					if (RMS_Error(out, inp, wt->siglength) > epsilon) {
						printf("\n ERROR : DWT Reconstruction Unit Test Failed. Exiting. \n");
						exit(-1);
					}
                    wt_free(wt);
                }
                wave_free(obj);
                delete[] name;
            }
        }
    }
    
	free(out);
    free(inp);
}