void sha256_hash_block(sha256_ctx *ctx, const unsigned char data[64], int perform_endian_swap) { ARCH_WORD_32 A, B, C, D, E, F, G, H, tmp, W[16]; #if ARCH_LITTLE_ENDIAN int i; if (perform_endian_swap) { for (i = 0; i < 16; ++i) W[i] = JOHNSWAP(*((ARCH_WORD_32*)&(data[i<<2]))); } else #endif memcpy(W, data, 16*sizeof(ARCH_WORD_32)); // Load state from all prior blocks (or init state) A = ctx->h[0]; B = ctx->h[1]; C = ctx->h[2]; D = ctx->h[3]; E = ctx->h[4]; F = ctx->h[5]; G = ctx->h[6]; H = ctx->h[7]; R(A, B, C, D, E, F, G, H, W[ 0], 0x428A2F98); R(H, A, B, C, D, E, F, G, W[ 1], 0x71374491); R(G, H, A, B, C, D, E, F, W[ 2], 0xB5C0FBCF); R(F, G, H, A, B, C, D, E, W[ 3], 0xE9B5DBA5); R(E, F, G, H, A, B, C, D, W[ 4], 0x3956C25B); R(D, E, F, G, H, A, B, C, W[ 5], 0x59F111F1); R(C, D, E, F, G, H, A, B, W[ 6], 0x923F82A4); R(B, C, D, E, F, G, H, A, W[ 7], 0xAB1C5ED5); R(A, B, C, D, E, F, G, H, W[ 8], 0xD807AA98); R(H, A, B, C, D, E, F, G, W[ 9], 0x12835B01); R(G, H, A, B, C, D, E, F, W[10], 0x243185BE); R(F, G, H, A, B, C, D, E, W[11], 0x550C7DC3); R(E, F, G, H, A, B, C, D, W[12], 0x72BE5D74); R(D, E, F, G, H, A, B, C, W[13], 0x80DEB1FE); R(C, D, E, F, G, H, A, B, W[14], 0x9BDC06A7); R(B, C, D, E, F, G, H, A, W[15], 0xC19BF174); R(A, B, C, D, E, F, G, H, M(16), 0xE49B69C1); R(H, A, B, C, D, E, F, G, M(17), 0xEFBE4786); R(G, H, A, B, C, D, E, F, M(18), 0x0FC19DC6); R(F, G, H, A, B, C, D, E, M(19), 0x240CA1CC); R(E, F, G, H, A, B, C, D, M(20), 0x2DE92C6F); R(D, E, F, G, H, A, B, C, M(21), 0x4A7484AA); R(C, D, E, F, G, H, A, B, M(22), 0x5CB0A9DC); R(B, C, D, E, F, G, H, A, M(23), 0x76F988DA); R(A, B, C, D, E, F, G, H, M(24), 0x983E5152); R(H, A, B, C, D, E, F, G, M(25), 0xA831C66D); R(G, H, A, B, C, D, E, F, M(26), 0xB00327C8); R(F, G, H, A, B, C, D, E, M(27), 0xBF597FC7); R(E, F, G, H, A, B, C, D, M(28), 0xC6E00BF3); R(D, E, F, G, H, A, B, C, M(29), 0xD5A79147); R(C, D, E, F, G, H, A, B, M(30), 0x06CA6351); R(B, C, D, E, F, G, H, A, M(31), 0x14292967); R(A, B, C, D, E, F, G, H, M(32), 0x27B70A85); R(H, A, B, C, D, E, F, G, M(33), 0x2E1B2138); R(G, H, A, B, C, D, E, F, M(34), 0x4D2C6DFC); R(F, G, H, A, B, C, D, E, M(35), 0x53380D13); R(E, F, G, H, A, B, C, D, M(36), 0x650A7354); R(D, E, F, G, H, A, B, C, M(37), 0x766A0ABB); R(C, D, E, F, G, H, A, B, M(38), 0x81C2C92E); R(B, C, D, E, F, G, H, A, M(39), 0x92722C85); R(A, B, C, D, E, F, G, H, M(40), 0xA2BFE8A1); R(H, A, B, C, D, E, F, G, M(41), 0xA81A664B); R(G, H, A, B, C, D, E, F, M(42), 0xC24B8B70); R(F, G, H, A, B, C, D, E, M(43), 0xC76C51A3); R(E, F, G, H, A, B, C, D, M(44), 0xD192E819); R(D, E, F, G, H, A, B, C, M(45), 0xD6990624); R(C, D, E, F, G, H, A, B, M(46), 0xF40E3585); R(B, C, D, E, F, G, H, A, M(47), 0x106AA070); R(A, B, C, D, E, F, G, H, M(48), 0x19A4C116); R(H, A, B, C, D, E, F, G, M(49), 0x1E376C08); R(G, H, A, B, C, D, E, F, M(50), 0x2748774C); R(F, G, H, A, B, C, D, E, M(51), 0x34B0BCB5); R(E, F, G, H, A, B, C, D, M(52), 0x391C0CB3); R(D, E, F, G, H, A, B, C, M(53), 0x4ED8AA4A); R(C, D, E, F, G, H, A, B, M(54), 0x5B9CCA4F); R(B, C, D, E, F, G, H, A, M(55), 0x682E6FF3); R(A, B, C, D, E, F, G, H, M(56), 0x748F82EE); R(H, A, B, C, D, E, F, G, M(57), 0x78A5636F); R(G, H, A, B, C, D, E, F, M(58), 0x84C87814); R(F, G, H, A, B, C, D, E, M(59), 0x8CC70208); R(E, F, G, H, A, B, C, D, M(60), 0x90BEFFFA); R(D, E, F, G, H, A, B, C, M(61), 0xA4506CEB); R(C, D, E, F, G, H, A, B, M(62), 0xBEF9A3F7); R(B, C, D, E, F, G, H, A, M(63), 0xC67178F2); // save state for usage in next block (or result if this was last block) ctx->h[0] += A; ctx->h[1] += B; ctx->h[2] += C; ctx->h[3] += D; ctx->h[4] += E; ctx->h[5] += F; ctx->h[6] += G; ctx->h[7] += H; }
/** * Transform a 4-element row vector (1x4 matrix) by a 4x4 matrix. This * function is used for transforming clipping plane equations and spotlight * directions. * Mathematically, u = v * m. * Input: v - input vector * m - transformation matrix * Output: u - transformed vector */ void _mesa_transform_vector( GLfloat u[4], const GLfloat v[4], const GLfloat m[16] ) { const GLfloat v0 = v[0], v1 = v[1], v2 = v[2], v3 = v[3]; #define M(row,col) m[row + col*4] u[0] = v0 * M(0,0) + v1 * M(1,0) + v2 * M(2,0) + v3 * M(3,0); u[1] = v0 * M(0,1) + v1 * M(1,1) + v2 * M(2,1) + v3 * M(3,1); u[2] = v0 * M(0,2) + v1 * M(1,2) + v2 * M(2,2) + v3 * M(3,2); u[3] = v0 * M(0,3) + v1 * M(1,3) + v2 * M(2,3) + v3 * M(3,3); #undef M }
/** * Apply a perspective projection matrix. * * \param mat matrix to apply the projection. * \param left left clipping plane coordinate. * \param right right clipping plane coordinate. * \param bottom bottom clipping plane coordinate. * \param top top clipping plane coordinate. * \param nearval distance to the near clipping plane. * \param farval distance to the far clipping plane. * * Creates the projection matrix and multiplies it with \p mat, marking the * MAT_FLAG_PERSPECTIVE flag. */ void _math_matrix_frustum( GLmatrix *mat, GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearval, GLfloat farval ) { GLfloat x, y, a, b, c, d; GLfloat m[16]; x = (2.0F*nearval) / (right-left); y = (2.0F*nearval) / (top-bottom); a = (right+left) / (right-left); b = (top+bottom) / (top-bottom); c = -(farval+nearval) / ( farval-nearval); d = -(2.0F*farval*nearval) / (farval-nearval); /* error? */ #define M(row,col) m[col*4+row] M(0,0) = x; M(0,1) = 0.0F; M(0,2) = a; M(0,3) = 0.0F; M(1,0) = 0.0F; M(1,1) = y; M(1,2) = b; M(1,3) = 0.0F; M(2,0) = 0.0F; M(2,1) = 0.0F; M(2,2) = c; M(2,3) = d; M(3,0) = 0.0F; M(3,1) = 0.0F; M(3,2) = -1.0F; M(3,3) = 0.0F; #undef M matrix_multf( mat, m, MAT_FLAG_PERSPECTIVE ); }
void EDSRSA(char *M_fname, char *n_fname, char *e_fname, char *d_fname) { std::ifstream in(M_fname); int *M_hash = (int*)md5(&in), i; BigInt M(intToChar(M_hash[3])), N(n_fname, false), E(e_fname, false), D(d_fname, false); M *= BigInt("10000000000"); M += BigInt(intToChar(M_hash[2])); M *= BigInt("10000000000"); M += BigInt(intToChar(M_hash[1])); M *= BigInt("10000000000"); M += BigInt(intToChar(M_hash[0])); BigInt Signature("1"), Encode("1"); BigInt DegreeNet[RNet]; DegreeNet[0] = M; DegreeNet[0] %= N; for(i = 1; i < RNet; i++) { DegreeNet[i] = DegreeNet[i-1] * DegreeNet[i-1]; DegreeNet[i] %= N; } BigInt degreeNum[RNet]; degreeNum[0] = BigInt("1"); for(int i = 1; i < RNet; i++) degreeNum[i] = degreeNum[i-1] * BigInt("2"); BigInt I("0"); for(int j = RNet-1; j >= 0;) { if(D >= I + degreeNum[j]) { Signature *= DegreeNet[j]; Signature %= N; I += degreeNum[j]; } else j--; } ///////////////////////////// DegreeNet[0] = Signature; DegreeNet[0] %= N; for(i = 1; i < RNet; i++) { DegreeNet[i] = DegreeNet[i-1] * DegreeNet[i-1]; DegreeNet[i] %= N; } I = BigInt("0"); for(int j = RNet-1; j >= 0;) { if(E >= I + degreeNum[j]) { Encode *= DegreeNet[j]; Encode %= N; I += degreeNum[j]; } else j--; } ///////////////////////////// M.TextWrite("hash.txt"); Signature.TextWrite("signature.txt"); Encode.TextWrite("encode.txt"); if( M % N == Encode) std::cout<<"OK\n"; else std::cout<<"NOT OK\n"; }
void CGuiToolButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { CDC* pdc= CDC::FromHandle(lpDrawItemStruct->hDC); CRect rc=lpDrawItemStruct->rcItem; UINT uState=lpDrawItemStruct->itemState; CBrush cb; if( uState & ODS_SELECTED) //the button is pressed { if(m_StyleDisplay==GUISTYLE_2003 || m_StyleDisplay == GUISTYLE_2003MENUBTN) cb.CreateSolidBrush(GuiDrawLayer::m_Theme? RGB(249,200,102):GuiDrawLayer::GetRGBPressBXP()); else cb.CreateSolidBrush(GuiDrawLayer::GetRGBPressBXP()); } else if (m_bMouserOver) { if(m_StyleDisplay==GUISTYLE_2003 || m_StyleDisplay== GUISTYLE_2003MENUBTN) cb.CreateSolidBrush(GuiDrawLayer::m_Theme? RGB(252,230,186):GuiDrawLayer::GetRGBFondoXP()); else cb.CreateSolidBrush(GuiDrawLayer::GetRGBFondoXP()); } else { if(m_StyleDisplay==GUISTYLE_2003) { if (m_Transparent && m_StyleDisplay ) cb.CreateStockObject(NULL_BRUSH); else { CGradient M(CSize(rc.Width(),rc.Height()+1)); M.PrepareReverseVertTab(pdc,m_StyleDisplay); M.Draw(pdc,rc.left,rc.top,0,0,rc.Width(),rc.Height(),SRCCOPY); } } else if (m_StyleDisplay== GUISTYLE_2003MENUBTN) cb.CreateSolidBrush(GuiDrawLayer::GetRGBColorFace(m_StyleDisplay)); else cb.CreateSolidBrush(m_clColor); } if (( uState & ODS_SELECTED) || m_bMouserOver ) { pdc->Draw3dRect(rc,GuiDrawLayer::GetRGBCaptionXP(),GuiDrawLayer::GetRGBCaptionXP()); rc.DeflateRect(1,1); } else if(m_ScrollButton || m_bSimple) { pdc->Draw3dRect(rc,GuiDrawLayer::GetRGBColorShadow(),GuiDrawLayer::GetRGBColorShadow()); rc.DeflateRect(1,1); } if (m_Transparent ) pdc->FillRect(rc,&cb); int calculodify; calculodify=rc.Height()-(m_SizeImage.cy); calculodify/=2; int nHeigh=calculodify+(m_bShowDark?1:0); int nWidth=m_ScrollButton?rc.Width()/2 :2; CPoint m_point=CPoint(nWidth,nHeigh); if (m_SizeImage.cx > 2) { if(m_bMouserOver == 1 && !(uState & ODS_DISABLED) && !(uState & ODS_SELECTED) && m_bShowDark) { CPoint p(m_point.x+1,m_point.y+1); pdc->DrawState(p,m_SizeImage,m_Icon,DSS_MONO,CBrush (GuiDrawLayer::GetRGBColorShadow())); m_point.x-=1; m_point.y-=1; } pdc->DrawState (m_point, m_SizeImage,m_Icon, (uState==ODS_DISABLED?DSS_DISABLED:DSS_NORMAL),(CBrush*)NULL); } if (m_SizeText.cx > 2) { int nMode = pdc->SetBkMode(TRANSPARENT); CRect rectletra=rc; int nt=m_ScrollButton?0:8; rectletra.left+=m_SizeImage.cx+nt; CPoint pt=CSize(rectletra.top,rectletra.left); if (uState & ODS_DISABLED) pdc->DrawState(pt, m_SizeText, m_szText, DSS_DISABLED, TRUE, 0, (CBrush*)NULL); else { if(m_bMouserOver != 1) pdc->SetTextColor(m_clrFont); pdc->DrawText(m_szText,rectletra,DT_SINGLELINE|DT_LEFT|DT_VCENTER); } pdc->SetBkMode(nMode); } // TODO: Add your code to draw the specified item }
void game_init(int ai) { static int once = 1; int x, y; BITMAP *tmp; int bc = makecol(200, 150, 50); clear_to_color(screen, makecol(0, 0, 0)); textout_centre(screen, font, "Generating&Caching Data", SCREEN_W / 2, 0, -1); textout_centre(screen, font, "May take a while", SCREEN_W / 2, SCREEN_H / 2, -1); textout_centre(screen, font, "(about 10 minutes for first run,", SCREEN_W / 2, SCREEN_H / 2 + 20, -1); textout_centre(screen, font, "about 1 minute every first game,", SCREEN_W / 2, SCREEN_H / 2 + 40, -1); textout_centre(screen, font, "few seconds else)", SCREEN_W / 2, SCREEN_H / 2 + 60, -1); if (once) { once = 0; animdata[0] = load_gfx("gravburn", 48); animdata[1] = load_gfx("shock", 48); animdata[2] = load_gfx("fireball", 48); animdata[3] = load_gfx("wheel", 48); animdata[4] = load_gfx("glow", 32); { int a; for (a = 0; a < ANIMS; a++) { anim[a] = 0; animlen[a] = dat_length(animdata[a]); } } tower = dat[TOWER_BMP].dat; explosion = dat[EXPLOSION_WAV].dat; radiating = dat[RADIATING_WAV].dat; teleport = dat[TELEPORT_WAV].dat; bonus = dat[BONUS_WAV].dat; nuclearegg = dat[NUCLEAREGG_BMP].dat; launcher = dat[LAUNCHER_BMP].dat; bonuspic[0] = dat[BONUS0_BMP].dat; bonuspic[1] = dat[BONUS1_BMP].dat; bonuspic[2] = dat[BONUS2_BMP].dat; map = create_bitmap(SCREEN_W, SCREEN_H); } ignore[0] = 0; ignore[1] = 0; think[0] = 0; think[1] = 0; memorized[0] = 0; memorized[1] = 0; AI[0] = 0; if (ai) AI[1] = 1; else AI[1] = 0; power[0] = 0; power[1] = 0; bonusnum = 0; life[0] = 100; life[1] = 100; go = 0; turn = 0; tmp = create_bitmap_ex(32, SCREEN_W, SCREEN_H); draw_back(tmp); for (y = 0; y < 16; y++) { for (x = 0; x < 16; x++) { hills[y][x] = rnd(); } } basex[0] = 4 * TW + TW / 2; basey[0] = 4 * TH + TH / 2; basex[1] = 12 * TW + TW / 2; basey[1] = 12 * TH + TH / 2; hills[4][4] = 1; hills[5][4] = 1; hills[5][5] = 1; hills[4][5] = 1; hills[12][12] = 1; hills[13][12] = 1; hills[13][13] = 1; hills[12][13] = 1; x = rnd() * 16; y = rnd() * 16; for (y = 0; y < MH; y++) { for (x = 0; x < MW; x++) { int c = 0; int t; float height = get_height(x, y); float h = 0, z = height * ZZZ; for (h = height, t = 0; z > 0 && t < 2; z--, h -= 1.0 / (float)ZZZ, t++) { int r, g, b; float l; if (h < 0.2) { float p = h / 0.2; r = 0; g = 100 * p; b = 155 + 100 * p; } else if (h < 0.5) { float p = (h - 0.2) / 0.3; r = 0; g = 100 + 155 * p; b = 255 - 155 * p; } else if (h < 0.8) { float p = (h - 0.5) / 0.3; r = 200 * p; g = 255 - 155 * p; b = 100; } else { float p = (h - 0.8) / 0.2; r = 200; g = 100 + 100 * p; b = 100 + 100 * p; } l = get_height(x + 1, y) - get_height(x, y + 1); r = r + l * 2000 + (rnd() - 0.5) * 20; g = g + l * 2000 + (rnd() - 0.5) * 20; b = b + l * 2000 + (rnd() - 0.5) * 20; c = makecol32(M(r), M(g), M(b)); if (y == MH - 1 && h < height) c = bc; putpixel(tmp, 88 + x, y + WINT - z, c); } } } { float filter[3][3] = { {0.025, 0.145, 0.025}, {0.145, 0.320, 0.145}, {0.025, 0.145, 0.025} }; for (y = 0; y < SCREEN_H; y++) { for (x = 0; x < SCREEN_W; x++) { int i = 0, j = 0; float r = 0, g = 0, b = 0; for (i = -1; i <= 1; i++) { for (j = -1; j <= 1; j++) { int c = getpixel(tmp, x + j, y + i); if (c < 0) c = makecol32(0, 0, 0); r += getr32(c) * filter[1 + i][1 + j]; g += getg32(c) * filter[1 + i][1 + j]; b += getb32(c) * filter[1 + i][1 + j]; } } putpixel(map, x, y, makecol(r, g, b)); } } } destroy_bitmap(tmp); ballx = 240; bally = 240; balldx = 0; balldy = 0; }
Bool prima_one_loop_round( Bool wait, Bool careOfApplication) { XEvent ev, next_event; fd_set read_set, write_set, excpt_set; struct timeval timeout; int r, i, queued_events; PTimerSysData timer; if ( guts. applicationClose) return false; if (( queued_events = XEventsQueued( DISP, QueuedAlready))) { goto FetchAndProcess; } read_set = guts.read_set; write_set = guts.write_set; excpt_set = guts.excpt_set; if ( guts. oldest) { gettimeofday( &timeout, nil); if ( guts. oldest-> when. tv_sec < timeout. tv_sec || ( guts. oldest-> when. tv_sec == timeout. tv_sec && guts. oldest-> when. tv_usec <= timeout. tv_usec)) { timer = guts. oldest; apc_timer_start( timer-> who); if ( timer-> who == CURSOR_TIMER) { prima_cursor_tick(); } else if ( timer-> who == MENU_TIMER) { apc_timer_stop( MENU_TIMER); if ( guts. currentMenu) { XEvent ev; ev. type = MenuTimerMessage; prima_handle_menu_event( &ev, M(guts. currentMenu)-> w-> w, guts. currentMenu); } } else if ( timer-> who == MENU_UNFOCUS_TIMER) { prima_end_menu(); } else { prima_simple_message( timer-> who, cmTimer, false); } gettimeofday( &timeout, nil); } if ( guts. oldest && wait) { if ( guts. oldest-> when. tv_sec < timeout. tv_sec) { timeout. tv_sec = 0; timeout. tv_usec = 0; } else { timeout. tv_sec = guts. oldest-> when. tv_sec - timeout. tv_sec; if ( guts. oldest-> when. tv_usec < timeout. tv_usec) { if ( timeout. tv_sec == 0) { timeout. tv_sec = 0; timeout. tv_usec = 0; } else { timeout. tv_sec--; timeout. tv_usec = 1000000 - (timeout. tv_usec - guts. oldest-> when. tv_usec); } } else { timeout. tv_usec = guts. oldest-> when. tv_usec - timeout. tv_usec; } } if ( timeout. tv_sec > 0 || timeout. tv_usec > 200000) { timeout. tv_sec = 0; timeout. tv_usec = 200000; } } else { timeout. tv_sec = 0; if ( wait) timeout. tv_usec = 200000; else timeout. tv_usec = 0; } } else { timeout. tv_sec = 0; if ( wait) timeout. tv_usec = 200000; else timeout. tv_usec = 0; } if (( r = select( guts.max_fd+1, &read_set, &write_set, &excpt_set, &timeout)) > 0 && FD_ISSET( guts.connection, &read_set)) { if (( queued_events = XEventsQueued( DISP, QueuedAfterFlush)) <= 0) { /* just like tcl/perl tk do, to avoid an infinite loop */ RETSIGTYPE oldHandler = signal( SIGPIPE, SIG_IGN); XNoOp( DISP); XFlush( DISP); (void) signal( SIGPIPE, oldHandler); } FetchAndProcess: if ( queued_events && ( application || !careOfApplication)) { XNextEvent( DISP, &ev); XCHECKPOINT; queued_events--; while ( queued_events > 0) { if (!application && careOfApplication) return false; XNextEvent( DISP, &next_event); XCHECKPOINT; prima_handle_event( &ev, &next_event); guts. total_events++; queued_events = XEventsQueued( DISP, QueuedAlready); memcpy( &ev, &next_event, sizeof( XEvent)); } if (!application && careOfApplication) return false; guts. total_events++; prima_handle_event( &ev, nil); } XNoOp( DISP); XFlush( DISP); } else if ( r < 0) { list_first_that( guts.files, (void*)purge_invalid_watchers, nil); } else { if ( r > 0) { for ( i = 0; i < guts.files->count; i++) { PFile f = (PFile)list_at( guts.files,i); if ( FD_ISSET( f->fd, &read_set) && (f->eventMask & feRead)) { prima_simple_message((Handle)f, cmFileRead, false); break; } else if ( FD_ISSET( f->fd, &write_set) && (f->eventMask & feWrite)) { prima_simple_message((Handle)f, cmFileWrite, false); break; } else if ( FD_ISSET( f->fd, &excpt_set) && (f->eventMask & feException)) { prima_simple_message((Handle)f, cmFileException, false); break; } } } else { XNoOp( DISP); XFlush( DISP); } } send_pending_events(); perform_pending_paints(); kill_zombies(); return application != nilHandle; }
void glOrtho( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near_val, GLfloat far_val ) { GLfloat mat[16]; if( left == right || bottom == top || near_val == far_val ) return; #define M(row,col) mat[col * 4 + row] M(0,0) = 2.0f / (right - left); M(0,1) = 0.0f; M(0,2) = 0.0f; M(0,3) = -(right + left) / (right - left); M(1,0) = 0.0f; M(1,1) = 2.0f / (top - bottom); M(1,2) = 0.0f; M(1,3) = -(top + bottom) / (top - bottom); M(2,0) = 0.0f; M(2,1) = 0.0f; M(2,2) = -2.0f / (far_val - near_val); M(2,3) = -(far_val + near_val) / (far_val - near_val); M(3,0) = 0.0f; M(3,1) = 0.0f; M(3,2) = 0.0f; M(3,3) = 1.0f; ur_matrixMult( matrixTop, mat, matrixTop ); }
void APIENTRY _gluLookAt( GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy, GLdouble upz ) { GLdouble m[16]; GLdouble x[3], y[3], z[3]; GLdouble mag; /* Make rotation matrix */ /* Z vector */ z[0] = eyex - centerx; z[1] = eyey - centery; z[2] = eyez - centerz; mag = sqrt( z[0]*z[0] + z[1]*z[1] + z[2]*z[2] ); if (mag) { /* mpichler, 19950515 */ z[0] /= mag; z[1] /= mag; z[2] /= mag; } /* Y vector */ y[0] = upx; y[1] = upy; y[2] = upz; /* X vector = Y cross Z */ x[0] = y[1]*z[2] - y[2]*z[1]; x[1] = -y[0]*z[2] + y[2]*z[0]; x[2] = y[0]*z[1] - y[1]*z[0]; /* Recompute Y = Z cross X */ y[0] = z[1]*x[2] - z[2]*x[1]; y[1] = -z[0]*x[2] + z[2]*x[0]; y[2] = z[0]*x[1] - z[1]*x[0]; /* mpichler, 19950515 */ /* cross product gives area of parallelogram, which is < 1.0 for * non-perpendicular unit-length vectors; so normalize x, y here */ mag = sqrt( x[0]*x[0] + x[1]*x[1] + x[2]*x[2] ); if (mag) { x[0] /= mag; x[1] /= mag; x[2] /= mag; } mag = sqrt( y[0]*y[0] + y[1]*y[1] + y[2]*y[2] ); if (mag) { y[0] /= mag; y[1] /= mag; y[2] /= mag; } #define M(row,col) m[col*4+row] M(0,0) = x[0]; M(0,1) = x[1]; M(0,2) = x[2]; M(0,3) = 0.0; M(1,0) = y[0]; M(1,1) = y[1]; M(1,2) = y[2]; M(1,3) = 0.0; M(2,0) = z[0]; M(2,1) = z[1]; M(2,2) = z[2]; M(2,3) = 0.0; M(3,0) = 0.0; M(3,1) = 0.0; M(3,2) = 0.0; M(3,3) = 1.0; #undef M glMultMatrixd( m ); /* Translate Eye to Origin */ glTranslated( -eyex, -eyey, -eyez ); }
//glu pick matrix implementation borrowed from Mesa3D glh::matrix4f gl_pick_matrix(GLfloat x, GLfloat y, GLfloat width, GLfloat height, GLint* viewport) { GLfloat m[16]; GLfloat sx, sy; GLfloat tx, ty; sx = viewport[2] / width; sy = viewport[3] / height; tx = (viewport[2] + 2.f * (viewport[0] - x)) / width; ty = (viewport[3] + 2.f * (viewport[1] - y)) / height; #define M(row,col) m[col*4+row] M(0,0) = sx; M(0,1) = 0.f; M(0,2) = 0.f; M(0,3) = tx; M(1,0) = 0.f; M(1,1) = sy; M(1,2) = 0.f; M(1,3) = ty; M(2,0) = 0.f; M(2,1) = 0.f; M(2,2) = 1.f; M(2,3) = 0.f; M(3,0) = 0.f; M(3,1) = 0.f; M(3,2) = 0.f; M(3,3) = 1.f; #undef M return glh::matrix4f(m); }
static cairo_time_t draw_spiral (cairo_t *cr, cairo_fill_rule_t fill_rule, align_t align, close_t close, int width, int height, int loops) { int i; int n=0; double x[MAX_SEGMENTS]; double y[MAX_SEGMENTS]; int step = 3; int side = width < height ? width : height; assert(5*(side/step/2+1)+2 < MAX_SEGMENTS); #define L(x_,y_) (x[n] = (x_), y[n] = (y_), n++) #define M(x_,y_) L(x_,y_) #define v(t) L(x[n-1], y[n-1] + (t)) #define h(t) L(x[n-1] + (t), y[n-1]) switch (align) { case PIXALIGN: M(0,0); break; case NONALIGN: M(0.1415926, 0.7182818); break; } while (side >= step && side >= 0) { v(side); h(side); v(-side); h(-side+step); v(step); side -= 2*step; } switch (close) { case RECTCLOSE: L(x[n-1],y[0]); break; case DIAGCLOSE: L(x[0],y[0]); break; } assert(n < MAX_SEGMENTS); cairo_save (cr); cairo_set_source_rgb (cr, 0, 0, 0); cairo_paint (cr); cairo_translate (cr, 1, 1); cairo_set_fill_rule (cr, fill_rule); cairo_set_source_rgb (cr, 1, 0, 0); cairo_new_path (cr); cairo_move_to (cr, x[0], y[0]); for (i = 1; i < n; i++) { cairo_line_to (cr, x[i], y[i]); } cairo_close_path (cr); cairo_perf_timer_start (); cairo_perf_set_thread_aware (cr, FALSE); while (loops--) { if (loops == 0) cairo_perf_set_thread_aware (cr, TRUE); cairo_fill_preserve (cr); } cairo_perf_timer_stop (); cairo_restore (cr); return cairo_perf_timer_elapsed (); }
static int plot_freqs(AVFilterLink *inlink, AVFrame *in) { AVFilterContext *ctx = inlink->dst; AVFilterLink *outlink = ctx->outputs[0]; ShowFreqsContext *s = ctx->priv; const int win_size = s->win_size; char *colors, *color, *saveptr = NULL; AVFrame *out; int ch, n; out = ff_get_video_buffer(outlink, outlink->w, outlink->h); if (!out) return AVERROR(ENOMEM); for (n = 0; n < outlink->h; n++) memset(out->data[0] + out->linesize[0] * n, 0, outlink->w * 4); /* fill FFT input with the number of samples available */ for (ch = 0; ch < s->nb_channels; ch++) { const float *p = (float *)in->extended_data[ch]; for (n = 0; n < in->nb_samples; n++) { s->fft_data[ch][n].re = p[n] * s->window_func_lut[n]; s->fft_data[ch][n].im = 0; } for (; n < win_size; n++) { s->fft_data[ch][n].re = 0; s->fft_data[ch][n].im = 0; } } /* run FFT on each samples set */ for (ch = 0; ch < s->nb_channels; ch++) { av_fft_permute(s->fft, s->fft_data[ch]); av_fft_calc(s->fft, s->fft_data[ch]); } #define RE(x, ch) s->fft_data[ch][x].re #define IM(x, ch) s->fft_data[ch][x].im #define M(a, b) (sqrt((a) * (a) + (b) * (b))) colors = av_strdup(s->colors); if (!colors) { av_frame_free(&out); return AVERROR(ENOMEM); } for (ch = 0; ch < s->nb_channels; ch++) { uint8_t fg[4] = { 0xff, 0xff, 0xff, 0xff }; int prev_y = -1, f; double a; color = av_strtok(ch == 0 ? colors : NULL, " |", &saveptr); if (color) av_parse_color(fg, color, -1, ctx); a = av_clipd(M(RE(0, ch), 0) / s->scale, 0, 1); plot_freq(s, ch, a, 0, fg, &prev_y, out, outlink); for (f = 1; f < s->nb_freq; f++) { a = av_clipd(M(RE(f, ch), IM(f, ch)) / s->scale, 0, 1); plot_freq(s, ch, a, f, fg, &prev_y, out, outlink); } } av_free(colors); out->pts = in->pts; return ff_filter_frame(outlink, out); }
/** * Description not yet available. * \param */ void laplace_approximation_calculator::generate_antithetical_rvs() { // number of random vectors const ivector & itmp=(*num_local_re_array)(1,num_separable_calls); //const ivector & itmpf=(*num_local_fixed_array)(1,num_separable_calls); for (int i=2;i<=num_separable_calls;i++) { if (itmp(i) != itmp(i-1)) { cerr << "At present can only use antithetical rv's when " "all separable calls are the same size" << endl; ad_exit(1); } } int n=itmp(1); int samplesize=num_importance_samples; // mesh size double delta=0.01; // maximum of distribution is near here double mid=sqrt(double(n-1)); dmatrix weights(1,2*n,1,2); double spread=15; if (mid-spread<=0.001) spread=mid-0.1; double ssum=0.0; double x=0.0; double tmax=(n-1)*log(mid)-0.5*mid*mid; for (x=mid-spread;x<=mid+spread;x+=delta) { ssum+=exp((n-1)*log(x)-0.5*x*x-tmax); } double tsum=0; dvector dist(1,samplesize+1); dist.initialize(); int is=0; int ii; for (x=mid-spread;x<=mid+spread;x+=delta) { tsum+=exp((n-1)*log(x)-0.5*x*x-tmax)/ssum*samplesize; int ns=int(tsum); for (ii=1;ii<=ns;ii++) { dist(++is)=x; } tsum-=ns; } if (is==samplesize-1) { dist(samplesize)=mid; } else if (is<samplesize-1) { cerr << "This can't happen" << endl; exit(1); } // get random numbers random_number_generator rng(rseed); if (antiepsilon) { if (allocated(*antiepsilon)) { delete antiepsilon; antiepsilon=0; } } antiepsilon=new dmatrix(1,samplesize,1,n); dmatrix & M=*antiepsilon; M.fill_randn(rng); for (int i=1;i<=samplesize;i++) { M(i)=M(i)/norm(M(i)); } int nvar=(samplesize-1)*n; independent_variables xx(1,nvar); ii=0; for (int i=2;i<=samplesize;i++) { for (int j=1;j<=n;j++) { xx(++ii)=M(i,j); } } fmmt1 fmc(nvar,5); //fmm fmc(nvar,5); fmc.noprintx=1; fmc.iprint=10; fmc.maxfn=2500; fmc.crit=1.e-6; double f; double fbest=1.e+50;; dvector g(1,nvar); dvector gbest(1,nvar); dvector xbest(1,nvar); gbest.fill_seqadd(1.e+50,0.); { while (fmc.ireturn>=0) { //int badflag=0; fmc.fmin(f,xx,g); if (fmc.ihang) { //int hang_flag=fmc.ihang; //double maxg=max(g); //double ccrit=fmc.crit; //int current_ifn=fmc.ifn; } if (fmc.ireturn>0) { f=fcomp1(xx,dist,samplesize,n,g,M); if (f < fbest) { fbest=f; gbest=g; xbest=xx; } } } xx=xbest; } ii=0; for (int i=2;i<=samplesize;i++) { for (int j=1;j<=n;j++) { M(i,j)=xx(++ii); } } for (int i=1;i<=samplesize;i++) { M(i)*=dist(i)/norm(M(i)); } }
/** * Description not yet available. * \param */ imatrix laplace_approximation_calculator::check_sparse_matrix_structure(void) { ivector rowsize(1,usize); rowsize.initialize(); imatrix tmp(1,usize,1,usize); tmp.initialize(); for (int ii=1;ii<=num_separable_calls;ii++) { if (allocated((*derindex)(ii))) { ivector iv = sort((*derindex)(ii)); int n=iv.indexmax(); if (n>1) // so we have off diagonal elements { for (int i=1;i<=n;i++) { int row=iv(i); for (int j=1;j<=n;j++) { if (i != j) { int col=iv(j); int foundmatch=0; for (int k=1;k<=rowsize(row);k++) { if (tmp(row,k)==col) { foundmatch=1; break; } } if (foundmatch==0) // add a new element to tmp(row) { rowsize(row)++; if (rowsize(row)> tmp(row).indexmax()) { tmp(row).reallocate(2); // double the size } tmp(row,rowsize(row))=col; } } } } } } } imatrix M(1,usize,1,rowsize); ofstream ofs("sparseness.info"); ofs << "# Number of parameters" << endl; ofs << usize << endl; ofs << "# Number of off diagonal elements in each row" << endl; ofs << rowsize << endl; ofs << "# The nonempty rows of M" << endl; for (int i=1;i<=usize;i++) { if (rowsize(i)>0) { M(i)=sort(tmp(i)(1,rowsize(i))); ofs << setw(4) << M(i) << endl; } } return M; }
void HeatTransfer::mass_residual( bool compute_jacobian, AssemblyContext& context, CachedValues& /*cache*/ ) { #ifdef GRINS_USE_GRVY_TIMERS this->_timer->BeginTimer("HeatTransfer::mass_residual"); #endif // First we get some references to cell-specific data that // will be used to assemble the linear system. // Element Jacobian * quadrature weights for interior integration const std::vector<libMesh::Real> &JxW = context.get_element_fe(_temp_vars.T_var())->get_JxW(); // The shape functions at interior quadrature points. const std::vector<std::vector<libMesh::Real> >& phi = context.get_element_fe(_temp_vars.T_var())->get_phi(); const std::vector<libMesh::Point>& u_qpoint = context.get_element_fe(this->_flow_vars.u_var())->get_xyz(); // The number of local degrees of freedom in each variable const unsigned int n_T_dofs = context.get_dof_indices(_temp_vars.T_var()).size(); // The subvectors and submatrices we need to fill: libMesh::DenseSubVector<libMesh::Real> &F = context.get_elem_residual(_temp_vars.T_var()); libMesh::DenseSubMatrix<libMesh::Real> &M = context.get_elem_jacobian(_temp_vars.T_var(), _temp_vars.T_var()); unsigned int n_qpoints = context.get_element_qrule().n_points(); for (unsigned int qp = 0; qp != n_qpoints; ++qp) { // For the mass residual, we need to be a little careful. // The time integrator is handling the time-discretization // for us so we need to supply M(u_fixed)*u for the residual. // u_fixed will be given by the fixed_interior_* functions // while u will be given by the interior_* functions. libMesh::Real T_dot = context.interior_value(_temp_vars.T_var(), qp); const libMesh::Number r = u_qpoint[qp](0); libMesh::Real jac = JxW[qp]; if( _is_axisymmetric ) { jac *= r; } for (unsigned int i = 0; i != n_T_dofs; ++i) { F(i) += _rho*_Cp*T_dot*phi[i][qp]*jac; if( compute_jacobian ) { for (unsigned int j=0; j != n_T_dofs; j++) { // We're assuming rho, cp are constant w.r.t. T here. M(i,j) += _rho*_Cp*phi[j][qp]*phi[i][qp]*jac; } }// End of check on Jacobian } // End of element dof loop } // End of the quadrature point loop #ifdef GRINS_USE_GRVY_TIMERS this->_timer->EndTimer("HeatTransfer::mass_residual"); #endif return; }
// Interpolate-then-integrate L0, L1, .... over several // sub-elements of a time element of width dt // void ResInt(double dt, const dTensorBC3& L0, const dTensorBC3& L1, const dTensorBC3& L2, const dTensorBC3& L3, const dTensorBC3& L4, const dTensorBC3& L5, dTensorBC4& ILout) { const int mbc = ILout.getmbc(); const int melems = ILout.getsize(1); const int meqn = ILout.getsize(2); const int kmax = ILout.getsize(3); const int meth2 = 1+ILout.getsize(4); // Choose order of accuracy in integration switch( meth2 ) { case 2: // 2nd order in time #pragma omp parallel for for (int i=(1-mbc); i<=(melems+mbc); i++) for (int m=1; m<=meqn; m++) for (int k=1; k<=kmax; k++) { double f0 = L0.get(i,m,k); double f1 = L1.get(i,m,k); double tmp = 0.5*dt*( f0 + f1 ); ILout.set(i,m,k,1, tmp ); } break; case 3: // 3rd order in time #pragma omp parallel for for (int i=(1-mbc); i<=(melems+mbc); i++) for (int m=1; m<=meqn; m++) for (int k=1; k<=kmax; k++) { double f0 = L0.get(i,m,k); double f1 = L1.get(i,m,k); double f2 = L2.get(i,m,k); double tmp = dt/24.0*( 5.0*f0 + 8.0*f1 - f2 ); ILout.set(i,m,k,1, tmp ); tmp = dt/24.0*( 5.0*f2 + 8.0*f1 - f0 ); ILout.set(i,m,k,2, tmp ); } break; case 4: // 4th order in time #pragma omp parallel for for (int i=(1-mbc); i<=(melems+mbc); i++) for (int m=1; m<=meqn; m++) for (int k=1; k<=kmax; k++) { double f0 = L0.get(i,m,k); double f1 = L1.get(i,m,k); double f2 = L2.get(i,m,k); double f3 = L3.get(i,m,k); double tmp = (dt/576.0)*(59.0*f0 - 14.0*f2 + 5.0*f3 + 94.0*f1); ILout.set(i,m,k,1, tmp ); tmp = -(dt/36.0)*(2.0*f0 - 11.0*f2 + 2.0*f3 - 11.0*f1); ILout.set(i,m,k,2, tmp ); tmp = (dt/576.0)*(5.0*f0 + 94.0*f2 + 59.0*f3 - 14.0*f1); ILout.set(i,m,k,3, tmp ); } break; case 5: // 5th order in time #pragma omp parallel for for (int i=(1-mbc); i<=(melems+mbc); i++) for (int m=1; m<=meqn; m++) for (int k=1; k<=kmax; k++) { double f0 = L0.get(i,m,k); double f1 = L1.get(i,m,k); double f2 = L2.get(i,m,k); double f3 = L3.get(i,m,k); double f4 = L4.get(i,m,k); double tmp = (dt/480.0)*((23.0+4.0*sq2)*f0 + (-13.0*sq2+64.0)*f1 + (-72.0*sq2+96.0)*f2 + (-43.0*sq2+64.0)*f3 + (-7.0+4.0*sq2)*f4); ILout.set(i,m,k,1, tmp ); tmp = (sq2*dt/960.0)*((-8.0-15.0*sq2)*f0 + 146.0*f1 + 144.0*f2 - 34.0*f3 + (-8.0+15.0*sq2)*f4); ILout.set(i,m,k,2, tmp ); tmp = (sq2*dt/960.0)*((-8.0+15.0*sq2)*f0 - 34.0*f1 + 144.0*f2 + 146.0*f3 + (-8.0-15.0*sq2)*f4); ILout.set(i,m,k,3, tmp ); tmp = (dt/480.0)*((-7.0+4.0*sq2)*f0 + (-43.0*sq2+64.0)*f1 + (-72.0*sq2+96.0)*f2 + (-13.0*sq2+64.0)*f3 + (23.0+4.0*sq2)*f4); ILout.set(i,m,k,4, tmp ); } break; case 6: // integrate the right hand side for each subinterval: dTensor2 M(6,5); M.set(1,1, 19.0/288.0); M.set(1,2, -3.0/800.0); M.set(1,3, 11.0/7200.0); M.set(1,4, -11.0/7200.0); M.set(1,5, 3.0/800.0); M.set(2,1, 1427.0/7200.0); M.set(2,2, 637.0/7200.0); M.set(2,3, -31.0/2400.0); M.set(2,4, 77.0/7200.0); M.set(2,5, -173.0/7200.0); M.set(3,1, -133.0/1200.0); M.set(3,2, 511.0/3600.0); M.set(3,3, 401.0/3600.0); M.set(3,4, -43.0/1200.0); M.set(3,5, 241.0/3600.0); M.set(4,1, 241.0/3600.0); M.set(4,2, -43.0/1200.0); M.set(4,3, 401.0/3600.0); M.set(4,4, 511.0/3600.0); M.set(4,5, -133.0/1200.0); M.set(5,1, -173.0/7200.0); M.set(5,2, 77.0/7200.0); M.set(5,3, -31.0/2400.0); M.set(5,4, 637.0/7200.0); M.set(5,5, 1427.0/7200.0); M.set(6,1, 3.0/800.0); M.set(6,2, -11.0/7200.0); M.set(6,3, 11.0/7200.0); M.set(6,4, -3.0/800.0); M.set(6,5, 19.0/288.0); // integration based on uniformly chosen quadrature points #pragma omp parallel for for (int i=(1-mbc); i<=(melems+mbc); i++) for (int m=1; m<=meqn; m++) for (int k=1; k<=kmax; k++) { double f0 = L0.get(i,m,k); double f1 = L1.get(i,m,k); double f2 = L2.get(i,m,k); double f3 = L3.get(i,m,k); double f4 = L4.get(i,m,k); double f5 = L5.get(i,m,k); double tmp = 0.; // in this case, dt = large time step dt ... tmp = dt*( M.get(1,1) * f0 + M.get(2,1) * f1 + M.get(3,1) * f2 + M.get(4,1) * f3 + M.get(5,1) * f4 + M.get(6,1) * f5 ); ILout.set(i,m,k,1, tmp ); tmp = dt*( M.get(1,2) * f0 + M.get(2,2) * f1 + M.get(3,2) * f2 + M.get(4,2) * f3 + M.get(5,2) * f4 + M.get(6,2) * f5 ); ILout.set(i,m,k,2, tmp ); tmp = dt*( M.get(1,3) * f0 + M.get(2,3) * f1 + M.get(3,3) * f2 + M.get(4,3) * f3 + M.get(5,3) * f4 + M.get(6,3) * f5 ); ILout.set(i,m,k,3, tmp ); tmp = dt*( M.get(1,4) * f0 + M.get(2,4) * f1 + M.get(3,4) * f2 + M.get(4,4) * f3 + M.get(5,4) * f4 + M.get(6,4) * f5 ); ILout.set(i,m,k,4, tmp ); tmp = dt*( M.get(1,5) * f0 + M.get(2,5) * f1 + M.get(3,5) * f2 + M.get(4,5) * f3 + M.get(5,5) * f4 + M.get(6,5) * f5 ); ILout.set(i,m,k,5, tmp ); } break; } }
void deflat(T& M, const Interface& i, double coef) { // deflate the Matrix for (Interface::const_iterator omit=i.begin();omit!=i.end();++omit) { for (Mesh::const_vertex_iterator vit1=omit->mesh().vertex_begin();vit1!=omit->mesh().vertex_end();++vit1) { #pragma omp parallel for #ifndef OPENMP_3_0 for (int i2=vit1-omit->mesh().vertex_begin();i2<omit->mesh().vertex_size();++i2) { const Mesh::const_vertex_iterator vit2 = omit->mesh().vertex_begin()+i2; #else for (Mesh::const_vertex_iterator vit2=vit1;vit2<omit->mesh().vertex_end();++vit2) { #endif M((*vit1)->index(),(*vit2)->index()) += coef; } } } } void assemble_HM(const Geometry& geo, SymMatrix& mat, const unsigned gauss_order) { mat = SymMatrix((geo.size()-geo.outermost_interface().nb_triangles())); mat.set(0.0); double K = 1.0 / (4.0 * M_PI); // We iterate over the meshes (or pair of domains) to fill the lower half of the HeadMat (since its symmetry) for ( Geometry::const_iterator mit1 = geo.begin(); mit1 != geo.end(); ++mit1) { for ( Geometry::const_iterator mit2 = geo.begin(); (mit2 != (mit1+1)); ++mit2) { // if mit1 and mit2 communicate, i.e they are used for the definition of a common domain const int orientation = geo.oriented(*mit1, *mit2); // equals 0, if they don't have any domains in common // equals 1, if they are both oriented toward the same domain // equals -1, if they are not if ( orientation != 0 ) { double Scoeff = orientation * geo.sigma_inv(*mit1, *mit2) * K; double Dcoeff = - orientation * geo.indicator(*mit1, *mit2) * K; double Ncoeff; if ( !(mit1->outermost() || mit2->outermost()) ) { // Computing S block first because it's needed for the corresponding N block operatorS(*mit1, *mit2, mat, Scoeff, gauss_order); Ncoeff = geo.sigma(*mit1, *mit2)/geo.sigma_inv(*mit1, *mit2); } else { Ncoeff = orientation * geo.sigma(*mit1, *mit2) * K; } if ( !mit1->outermost() ) { // Computing D block operatorD(*mit1, *mit2, mat, Dcoeff, gauss_order,false); } if ( ( *mit1 != *mit2 ) && ( !mit2->outermost() ) ) { // Computing D* block operatorD(*mit1, *mit2, mat, Dcoeff, gauss_order, true); } // Computing N block operatorN(*mit1, *mit2, mat, Ncoeff, gauss_order); } } } // Deflate the diagonal block (N33) of 'mat' : (in order to have a zero-mean potential for the outermost interface) const Interface i = geo.outermost_interface(); unsigned i_first = (*i.begin()->mesh().vertex_begin())->index(); deflat(mat, i, mat(i_first, i_first) / (geo.outermost_interface().nb_vertices())); }
G(GAME_EndWar, 224) #endif #if TERA G(GAME_Tera, 568) #endif #if HUNTED G(GAME_Hunted, 708) // real version is 709, which is incorrect #endif #if DND G(GAME_DND, 673) // real version is 674 #endif G(GAME_GoWJ, 828) // real version is 846 // Unreal engine 4 #if UNREAL4 M(0), M(1), M(2), M(3), M(4), M(5) #endif }; #undef G #undef M void FArchive::OverrideVersion() { int OldVer = ArVer; int OldLVer = ArLicenseeVer; for (int i = 0; i < ARRAY_COUNT(ue4versions); i++) { if (ue4versions[i].GameTag == Game)
} keypad[PADKEYS] = { {'y', 'Y', C('y')}, /* 7 */ {'k', 'K', C('k')}, /* 8 */ {'u', 'U', C('u')}, /* 9 */ {'m', C('p'), C('p')}, /* - */ {'h', 'H', C('h')}, /* 4 */ {'g', 'g', 'g'}, /* 5 */ {'l', 'L', C('l')}, /* 6 */ {'p', 'P', C('p')}, /* + */ {'b', 'B', C('b')}, /* 1 */ {'j', 'J', C('j')}, /* 2 */ {'n', 'N', C('n')}, /* 3 */ {'i', 'I', C('i')}, /* Ins */ {'.', ':', ':'} /* Del */ }, numpad[PADKEYS] = { {'7', M('7'), '7'}, /* 7 */ {'8', M('8'), '8'}, /* 8 */ {'9', M('9'), '9'}, /* 9 */ {'m', C('p'), C('p')}, /* - */ {'4', M('4'), '4'}, /* 4 */ {'g', 'G', 'g'}, /* 5 */ {'6', M('6'), '6'}, /* 6 */ {'p', 'P', C('p')}, /* + */ {'1', M('1'), '1'}, /* 1 */ {'2', M('2'), '2'}, /* 2 */ {'3', M('3'), '3'}, /* 3 */ {'i', 'I', C('i')}, /* Ins */ {'.', ':', ':'} /* Del */ }; /*
DoubleVector RowDoubleMatrix::preconditionedConjugateGradient(const DoubleVector &B, double epsilon, unsigned int niter, bool printMessages, unsigned int messageStep) const { DoubleVector X(size_, 0.0); // начальное приближение - вектор нулей DoubleVector resid(size_); // невязка DoubleVector M(size_); // предусловие DoubleVector Z(size_); DoubleVector P(size_); DoubleVector temp(size_); // ременное хранилище double resid_norm; for (size_type i = 0; i < size_; i++) { for (size_type j = 0; j < row_size_[i]; j++) { ColumnValuePair pair = data_[i][j]; if (pair.column == i) { M[i] = 1.0 / pair.value; } } } residual(X, B, resid); resid_norm = resid.norm_2(); if (printMessages) { std::cout << "Метод сопряженных градиентов для решения предобусловленной СЛАУ" << std::endl; std::cout << "Начальная невязка: " << resid_norm << std::endl; } if (resid_norm > epsilon) { double ha; Z = M.dotProduct( resid ); // z_0 P = Z; // p_0 ha = (resid * Z); for (unsigned int i = 0; i < niter; i++) { double alpha; double beta; double hanew; product(P, temp); alpha = ha / (P * temp); X += alpha * P; resid -= alpha * temp; resid_norm = resid.norm_2(); if (resid_norm <= epsilon) { if (printMessages) std::cout << "Решение найдено. Итераций: " << i << ", невязка: " << resid_norm << std::endl; return X; } if (printMessages && (i % messageStep == 0)) std::cout << i << ": " << resid_norm << std::endl; Z = M.dotProduct( resid ); // z_i hanew = (Z * resid); beta = hanew / (ha); ha = hanew; // p = z + beta * p P.scale(beta); P += Z; } } return X; }
NOX::Abstract::Group::ReturnType LOCA::BorderedSolver::LowerTriangularBlockElimination:: solve(Teuchos::ParameterList& params, const LOCA::BorderedSolver::AbstractOperator& op, const LOCA::MultiContinuation::ConstraintInterface& B, const NOX::Abstract::MultiVector::DenseMatrix& C, const NOX::Abstract::MultiVector* F, const NOX::Abstract::MultiVector::DenseMatrix* G, NOX::Abstract::MultiVector& X, NOX::Abstract::MultiVector::DenseMatrix& Y) const { string callingFunction = "LOCA::BorderedSolver::LowerTriangularBlockElimination::solve()"; NOX::Abstract::Group::ReturnType finalStatus = NOX::Abstract::Group::Ok; NOX::Abstract::Group::ReturnType status; // Determine if X or Y is zero bool isZeroF = (F == NULL); bool isZeroG = (G == NULL); bool isZeroB = B.isDXZero(); bool isZeroX = isZeroF; bool isZeroY = isZeroG && (isZeroB || isZeroX); // First compute X if (isZeroX) X.init(0.0); else { // Solve X = J^-1 F, note F must be nonzero status = op.applyInverse(params, *F, X); finalStatus = globalData->locaErrorCheck->combineAndCheckReturnTypes(status, finalStatus, callingFunction); } // Now compute Y if (isZeroY) Y.putScalar(0.0); else { // Compute G - B^T*X and store in Y if (isZeroG) B.multiplyDX(-1.0, X, Y); else { Y.assign(*G); if (!isZeroB && !isZeroX) { NOX::Abstract::MultiVector::DenseMatrix T(Y.numRows(),Y.numCols()); B.multiplyDX(1.0, X, T); Y -= T; } } // Overwrite Y with Y = C^-1 * (G - B^T*X) NOX::Abstract::MultiVector::DenseMatrix M(C); int *ipiv = new int[M.numRows()]; Teuchos::LAPACK<int,double> L; int info; L.GETRF(M.numRows(), M.numCols(), M.values(), M.stride(), ipiv, &info); if (info != 0) { status = NOX::Abstract::Group::Failed; finalStatus = globalData->locaErrorCheck->combineAndCheckReturnTypes( status, finalStatus, callingFunction); } L.GETRS('N', M.numRows(), Y.numCols(), M.values(), M.stride(), ipiv, Y.values(), Y.stride(), &info); delete [] ipiv; if (info != 0) { status = NOX::Abstract::Group::Failed; finalStatus = globalData->locaErrorCheck->combineAndCheckReturnTypes( status, finalStatus, callingFunction); } } return finalStatus; }
int main(int argc, char **argv) { const size_t n = 42, m = 87; matrix<std::pair<size_t, size_t> > M(n, m); size_t i, j; // Confirm sizes make sense. assert(M.size1() == n); assert(M.size2() == m); // Confirm storing values works. for (i = 0; i < n; i++) for (j = 0; j < m; j++) M(i, j) = std::make_pair<size_t, size_t>(i, j); // Confirm retrieving values in another order works. for (i = n; 0 < i--;) { for (j = m; 0 < j--;) { assert(M(i, j).first == i); assert(M(i, j).second == j); } } // Confirm copying works. matrix<std::pair<size_t, size_t> > N = M; assert(N.size1() == n); assert(N.size2() == m); for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { assert(N(i, j).first == i); assert(N(i, j).second == j); } } // Confirm assigning works. M = matrix<std::pair<size_t, size_t> >(1, 1); assert(M.size1() == 1); assert(M.size2() == 1); M(0, 0) = std::make_pair<size_t, size_t>(123456789, 8); assert(M(0, 0).first == 123456789); assert(M(0, 0).second == 8); // Confirm it did not affect the copy. assert(N.size1() == n); assert(N.size2() == m); for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { assert(N(i, j).first == i); assert(N(i, j).second == j); } } // Confirm MatrixD = matrix<double> by confirming the pointer // types are compatible. matrix<double> MD0(42, 42); MatrixD &MD1 = MD0; assert(&MD1 == &MD0); // Confirm overflow detection. try { const size_t size_max = std::numeric_limits<size_t>::max(); MatrixD MD2(size_max, size_max); } catch (std::bad_alloc &ba) { } return 0; }
void EncodingEDSRSA(char *M_fname, char *nA_fname, char *eA_fname, char *dA_fname, char *nB_fname, char *eB_fname, char *dB_fname) { std::ifstream in(M_fname); int *M_hash = (int*)md5(&in), i; BigInt M(intToChar(M_hash[3])), NA(nA_fname, false), EA(eA_fname, false), DA(dA_fname, false); M *= BigInt("10000000000"); M += BigInt(intToChar(M_hash[2])); M *= BigInt("10000000000"); M += BigInt(intToChar(M_hash[1])); M *= BigInt("10000000000"); M += BigInt(intToChar(M_hash[0])); BigInt NB(nB_fname, false), EB(eB_fname, false), DB(dB_fname, false); BigInt Signature("1"), Code("1"), Encode("1"), CheckSign("1"); BigInt DegreeNet[RNet]; DegreeNet[0] = M; DegreeNet[0] %= NA; for(i = 1; i < RNet; i++) { DegreeNet[i] = DegreeNet[i-1] * DegreeNet[i-1]; DegreeNet[i] %= NA; } BigInt degreeNum[RNet]; degreeNum[0] = BigInt("1"); for(int i = 1; i < RNet; i++) degreeNum[i] = degreeNum[i-1] * BigInt("2"); BigInt I("0"); for(int j = RNet-1; j >= 0;) { if(DA >= I + degreeNum[j]) { Signature *= DegreeNet[j]; Signature %= NA; I += degreeNum[j]; } else j--; } ////////////////////////////// DegreeNet[0] = Signature; DegreeNet[0] %= NB; for(i = 1; i < RNet; i++) { DegreeNet[i] = DegreeNet[i-1] * DegreeNet[i-1]; DegreeNet[i] %= NB; } I = BigInt("0"); for(int j = RNet-1; j >= 0;) { if(EB >= I + degreeNum[j]) { Code *= DegreeNet[j]; Code %= NB; I += degreeNum[j]; } else j--; } ////////////////////////////// DegreeNet[0] = Code; DegreeNet[0] %= NB; for(i = 1; i < RNet; i++) { DegreeNet[i] = DegreeNet[i-1] * DegreeNet[i-1]; DegreeNet[i] %= NB; } I = BigInt("0"); for(int j = RNet-1; j >= 0;) { if(DB >= I + degreeNum[j]) { Encode *= DegreeNet[j]; Encode %= NB; I += degreeNum[j]; } else j--; } ////////////////////////////// DegreeNet[0] = Encode; DegreeNet[0] %= NA; for(i = 1; i < RNet; i++) { DegreeNet[i] = DegreeNet[i-1] * DegreeNet[i-1]; DegreeNet[i] %= NA; } I = BigInt("0"); for(int j = RNet - 1; j >= 0;) { if(EA >= I + degreeNum[j]) { CheckSign *= DegreeNet[j]; CheckSign %= NA; I += degreeNum[j]; } else j--; } ////////////////////////////// M.TextWrite("hash.txt"); Code.TextWrite("code.txt"); Encode.TextWrite("encode.txt"); CheckSign.TextWrite("checksign.txt"); if( M % NA == CheckSign) std::cout<<"OK\n"; else std::cout<<"NOT OK\n"; }
static void gluLookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez, GLfloat centerx, GLfloat centery, GLfloat centerz, GLfloat upx, GLfloat upy, GLfloat upz) { GLfloat m[16]; GLfloat x[3], y[3], z[3]; GLfloat mag; z[0] = eyex - centerx; z[1] = eyey - centery; z[2] = eyez - centerz; mag = (float)sqrt(z[0] * z[0] + z[1] * z[1] + z[2] * z[2]); if (mag) { z[0] /= mag; z[1] /= mag; z[2] /= mag; } y[0] = upx; y[1] = upy; y[2] = upz; x[0] = y[1] * z[2] - y[2] * z[1]; x[1] = -y[0] * z[2] + y[2] * z[0]; x[2] = y[0] * z[1] - y[1] * z[0]; y[0] = z[1] * x[2] - z[2] * x[1]; y[1] = -z[0] * x[2] + z[2] * x[0]; y[2] = z[0] * x[1] - z[1] * x[0]; mag = (float)sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]); if (mag) { x[0] /= mag; x[1] /= mag; x[2] /= mag; } mag = (float)sqrt(y[0] * y[0] + y[1] * y[1] + y[2] * y[2]); if (mag) { y[0] /= mag; y[1] /= mag; y[2] /= mag; } #define M(row,col) m[col*4+row] M(0, 0) = x[0]; M(0, 1) = x[1]; M(0, 2) = x[2]; M(0, 3) = 0.0; M(1, 0) = y[0]; M(1, 1) = y[1]; M(1, 2) = y[2]; M(1, 3) = 0.0; M(2, 0) = z[0]; M(2, 1) = z[1]; M(2, 2) = z[2]; M(2, 3) = 0.0; M(3, 0) = 0.0; M(3, 1) = 0.0; M(3, 2) = 0.0; M(3, 3) = 1.0; #undef M { int a; GLfixed fixedM[16]; for (a = 0; a < 16; ++a) fixedM[a] = (GLfixed)(m[a] * 65536); glMultMatrixx(fixedM); } glTranslatex((GLfixed)(-eyex * 65536), (GLfixed)(-eyey * 65536), (GLfixed)(-eyez * 65536)); }
/** * Apply an orthographic projection matrix. * * \param mat matrix to apply the projection. * \param left left clipping plane coordinate. * \param right right clipping plane coordinate. * \param bottom bottom clipping plane coordinate. * \param top top clipping plane coordinate. * \param nearval distance to the near clipping plane. * \param farval distance to the far clipping plane. * * Creates the projection matrix and multiplies it with \p mat, marking the * MAT_FLAG_GENERAL_SCALE and MAT_FLAG_TRANSLATION flags. */ void _math_matrix_ortho( GLmatrix *mat, GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearval, GLfloat farval ) { GLfloat m[16]; #define M(row,col) m[col*4+row] M(0,0) = 2.0F / (right-left); M(0,1) = 0.0F; M(0,2) = 0.0F; M(0,3) = -(right+left) / (right-left); M(1,0) = 0.0F; M(1,1) = 2.0F / (top-bottom); M(1,2) = 0.0F; M(1,3) = -(top+bottom) / (top-bottom); M(2,0) = 0.0F; M(2,1) = 0.0F; M(2,2) = -2.0F / (farval-nearval); M(2,3) = -(farval+nearval) / (farval-nearval); M(3,0) = 0.0F; M(3,1) = 0.0F; M(3,2) = 0.0F; M(3,3) = 1.0F; #undef M matrix_multf( mat, m, (MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION)); }
static void Usage(int argc, char *argv[]) { if (!xkblist) M1("Usage: %s [options] input-file [ output-file ]\n", argv[0]); else M1("Usage: %s [options] file[(map)] ...\n", argv[0]); M("Legal options:\n"); M("-?,-help Print this message\n"); M("-version Print the version number\n"); if (!xkblist) { M("-a Show all actions\n"); M("-C Create a C header file\n"); } #ifdef DEBUG M("-d [flags] Report debugging information\n"); #endif M("-em1 <msg> Print <msg> before printing first error message\n"); M("-emp <msg> Print <msg> at the start of each message line\n"); M("-eml <msg> If there were any errors, print <msg> before exiting\n"); if (!xkblist) { M("-dflts Compute defaults for missing parts\n"); M("-I[<dir>] Specifies a top level directory for include\n"); M(" directives. Multiple directories are legal.\n"); M("-l [flags] List matching maps in the specified files\n"); M(" f: list fully specified names\n"); M(" h: also list hidden maps\n"); M(" l: long listing (show flags)\n"); M(" p: also list partial maps\n"); M(" R: recursively list subdirectories\n"); M(" default is all options off\n"); } M("-i <deviceid> Specifies device ID (not name) to compile for\n"); M("-m[ap] <map> Specifies map to compile\n"); M("-o <file> Specifies output file name\n"); if (!xkblist) { M("-opt[ional] <parts> Specifies optional components of keymap\n"); M(" Errors in optional parts are not fatal\n"); M(" <parts> can be any combination of:\n"); M(" c: compat map g: geometry\n"); M(" k: keycodes s: symbols\n"); M(" t: types\n"); } if (xkblist) { M("-p <count> Specifies the number of slashes to be stripped\n"); M(" from the front of the map name on output\n"); } M("-R[<DIR>] Specifies the root directory for\n"); M(" relative path names\n"); M("-synch Force synchronization\n"); if (xkblist) { M("-v [<flags>] Set level of detail for listing.\n"); M(" flags are as for the -l option\n"); } M("-w [<lvl>] Set warning level (0=none, 10=all)\n"); if (!xkblist) { M("-xkb Create an XKB source (.xkb) file\n"); M("-xkm Create a compiled key map (.xkm) file\n"); } return; }
/** * Generate a 4x4 transformation matrix from glRotate parameters, and * post-multiply the input matrix by it. * * \author * This function was contributed by Erich Boleyn ([email protected]). * Optimizations contributed by Rudolf Opalla ([email protected]). */ void _math_matrix_rotate( GLmatrix *mat, GLfloat angle, GLfloat x, GLfloat y, GLfloat z ) { GLfloat xx, yy, zz, xy, yz, zx, xs, ys, zs, one_c, s, c; GLfloat m[16]; GLboolean optimized; s = (GLfloat) sin( angle * DEG2RAD ); c = (GLfloat) cos( angle * DEG2RAD ); memcpy(m, Identity, sizeof(GLfloat)*16); optimized = GL_FALSE; #define M(row,col) m[col*4+row] if (x == 0.0F) { if (y == 0.0F) { if (z != 0.0F) { optimized = GL_TRUE; /* rotate only around z-axis */ M(0,0) = c; M(1,1) = c; if (z < 0.0F) { M(0,1) = s; M(1,0) = -s; } else { M(0,1) = -s; M(1,0) = s; } } } else if (z == 0.0F) { optimized = GL_TRUE; /* rotate only around y-axis */ M(0,0) = c; M(2,2) = c; if (y < 0.0F) { M(0,2) = -s; M(2,0) = s; } else { M(0,2) = s; M(2,0) = -s; } } } else if (y == 0.0F) { if (z == 0.0F) { optimized = GL_TRUE; /* rotate only around x-axis */ M(1,1) = c; M(2,2) = c; if (x < 0.0F) { M(1,2) = s; M(2,1) = -s; } else { M(1,2) = -s; M(2,1) = s; } } } if (!optimized) { const GLfloat mag = SQRTF(x * x + y * y + z * z); if (mag <= 1.0e-4) { /* no rotation, leave mat as-is */ return; } x /= mag; y /= mag; z /= mag; /* * Arbitrary axis rotation matrix. * * This is composed of 5 matrices, Rz, Ry, T, Ry', Rz', multiplied * like so: Rz * Ry * T * Ry' * Rz'. T is the final rotation * (which is about the X-axis), and the two composite transforms * Ry' * Rz' and Rz * Ry are (respectively) the rotations necessary * from the arbitrary axis to the X-axis then back. They are * all elementary rotations. * * Rz' is a rotation about the Z-axis, to bring the axis vector * into the x-z plane. Then Ry' is applied, rotating about the * Y-axis to bring the axis vector parallel with the X-axis. The * rotation about the X-axis is then performed. Ry and Rz are * simply the respective inverse transforms to bring the arbitrary * axis back to its original orientation. The first transforms * Rz' and Ry' are considered inverses, since the data from the * arbitrary axis gives you info on how to get to it, not how * to get away from it, and an inverse must be applied. * * The basic calculation used is to recognize that the arbitrary * axis vector (x, y, z), since it is of unit length, actually * represents the sines and cosines of the angles to rotate the * X-axis to the same orientation, with theta being the angle about * Z and phi the angle about Y (in the order described above) * as follows: * * cos ( theta ) = x / sqrt ( 1 - z^2 ) * sin ( theta ) = y / sqrt ( 1 - z^2 ) * * cos ( phi ) = sqrt ( 1 - z^2 ) * sin ( phi ) = z * * Note that cos ( phi ) can further be inserted to the above * formulas: * * cos ( theta ) = x / cos ( phi ) * sin ( theta ) = y / sin ( phi ) * * ...etc. Because of those relations and the standard trigonometric * relations, it is pssible to reduce the transforms down to what * is used below. It may be that any primary axis chosen will give the * same results (modulo a sign convention) using thie method. * * Particularly nice is to notice that all divisions that might * have caused trouble when parallel to certain planes or * axis go away with care paid to reducing the expressions. * After checking, it does perform correctly under all cases, since * in all the cases of division where the denominator would have * been zero, the numerator would have been zero as well, giving * the expected result. */ xx = x * x; yy = y * y; zz = z * z; xy = x * y; yz = y * z; zx = z * x; xs = x * s; ys = y * s; zs = z * s; one_c = 1.0F - c; /* We already hold the identity-matrix so we can skip some statements */ M(0,0) = (one_c * xx) + c; M(0,1) = (one_c * xy) - zs; M(0,2) = (one_c * zx) + ys; /* M(0,3) = 0.0F; */ M(1,0) = (one_c * xy) + zs; M(1,1) = (one_c * yy) + c; M(1,2) = (one_c * yz) - xs; /* M(1,3) = 0.0F; */ M(2,0) = (one_c * zx) - ys; M(2,1) = (one_c * yz) + xs; M(2,2) = (one_c * zz) + c; /* M(2,3) = 0.0F; */ /* M(3,0) = 0.0F; M(3,1) = 0.0F; M(3,2) = 0.0F; M(3,3) = 1.0F; */ } #undef M matrix_multf( mat, m, MAT_FLAG_ROTATION ); }
void track(const char *tag, uint64_t cnt, TINFO *tinfo) { static int lastlen = 0; int len; char msg[128]; if (g.c_quiet || tag == NULL) return; if (tinfo == NULL && cnt == 0) len = snprintf(msg, sizeof(msg), "%4d: %s", g.run_cnt, tag); else if (tinfo == NULL) len = snprintf( msg, sizeof(msg), "%4d: %s: %" PRIu64, g.run_cnt, tag, cnt); else len = snprintf(msg, sizeof(msg), "%4d: %s: " "search %" PRIu64 "%s, " "insert %" PRIu64 "%s, " "update %" PRIu64 "%s, " "remove %" PRIu64 "%s", g.run_cnt, tag, tinfo->search > M(9) ? tinfo->search / M(1) : tinfo->search, tinfo->search > M(9) ? "M" : "", tinfo->insert > M(9) ? tinfo->insert / M(1) : tinfo->insert, tinfo->insert > M(9) ? "M" : "", tinfo->update > M(9) ? tinfo->update / M(1) : tinfo->update, tinfo->update > M(9) ? "M" : "", tinfo->remove > M(9) ? tinfo->remove / M(1) : tinfo->remove, tinfo->remove > M(9) ? "M" : ""); if (lastlen > len) { memset(msg + len, ' ', (size_t)(lastlen - len)); msg[lastlen] = '\0'; } lastlen = len; if (printf("%s\r", msg) < 0) testutil_die(EIO, "printf"); if (fflush(stdout) == EOF) testutil_die(errno, "fflush"); }
static av_always_inline void idct(uint8_t *dst, int stride, int16_t *input, int type) { int16_t *ip = input; int A, B, C, D, Ad, Bd, Cd, Dd, E, F, G, H; int Ed, Gd, Add, Bdd, Fd, Hd; int i; /* Inverse DCT on the rows now */ for (i = 0; i < 8; i++) { /* Check for non-zero values */ if ( ip[0] | ip[1] | ip[2] | ip[3] | ip[4] | ip[5] | ip[6] | ip[7] ) { A = M(xC1S7, ip[1]) + M(xC7S1, ip[7]); B = M(xC7S1, ip[1]) - M(xC1S7, ip[7]); C = M(xC3S5, ip[3]) + M(xC5S3, ip[5]); D = M(xC3S5, ip[5]) - M(xC5S3, ip[3]); Ad = M(xC4S4, (A - C)); Bd = M(xC4S4, (B - D)); Cd = A + C; Dd = B + D; E = M(xC4S4, (ip[0] + ip[4])); F = M(xC4S4, (ip[0] - ip[4])); G = M(xC2S6, ip[2]) + M(xC6S2, ip[6]); H = M(xC6S2, ip[2]) - M(xC2S6, ip[6]); Ed = E - G; Gd = E + G; Add = F + Ad; Bdd = Bd - H; Fd = F - Ad; Hd = Bd + H; /* Final sequence of operations over-write original inputs. */ ip[0] = Gd + Cd ; ip[7] = Gd - Cd ; ip[1] = Add + Hd; ip[2] = Add - Hd; ip[3] = Ed + Dd ; ip[4] = Ed - Dd ; ip[5] = Fd + Bdd; ip[6] = Fd - Bdd; } ip += 8; /* next row */ } ip = input; for ( i = 0; i < 8; i++) { /* Check for non-zero values (bitwise or faster than ||) */ if ( ip[1 * 8] | ip[2 * 8] | ip[3 * 8] | ip[4 * 8] | ip[5 * 8] | ip[6 * 8] | ip[7 * 8] ) { A = M(xC1S7, ip[1*8]) + M(xC7S1, ip[7*8]); B = M(xC7S1, ip[1*8]) - M(xC1S7, ip[7*8]); C = M(xC3S5, ip[3*8]) + M(xC5S3, ip[5*8]); D = M(xC3S5, ip[5*8]) - M(xC5S3, ip[3*8]); Ad = M(xC4S4, (A - C)); Bd = M(xC4S4, (B - D)); Cd = A + C; Dd = B + D; E = M(xC4S4, (ip[0*8] + ip[4*8])) + 8; F = M(xC4S4, (ip[0*8] - ip[4*8])) + 8; if(type==1){ //HACK E += 16*128; F += 16*128; } G = M(xC2S6, ip[2*8]) + M(xC6S2, ip[6*8]); H = M(xC6S2, ip[2*8]) - M(xC2S6, ip[6*8]); Ed = E - G; Gd = E + G; Add = F + Ad; Bdd = Bd - H; Fd = F - Ad; Hd = Bd + H; /* Final sequence of operations over-write original inputs. */ if(type==0){ ip[0*8] = (Gd + Cd ) >> 4; ip[7*8] = (Gd - Cd ) >> 4; ip[1*8] = (Add + Hd ) >> 4; ip[2*8] = (Add - Hd ) >> 4; ip[3*8] = (Ed + Dd ) >> 4; ip[4*8] = (Ed - Dd ) >> 4; ip[5*8] = (Fd + Bdd ) >> 4; ip[6*8] = (Fd - Bdd ) >> 4; }else if(type==1){
//Input Port #0: Buffer_Size = 1, Params_Type = SourceDrainMono_Sensor_stm32comm_Params, Data_Type = SourceDrainMono_Sensor_stm32comm_Data bool DECOFUNC(processMonoDrainData)(void * paramsPtr, void * varsPtr, QVector<void *> drainParams, QVector<void *> drainData) { VisualizationMono_Sensor_stm32comm_Params * params=(VisualizationMono_Sensor_stm32comm_Params *)paramsPtr; VisualizationMono_Sensor_stm32comm_Vars * vars=(VisualizationMono_Sensor_stm32comm_Vars *)varsPtr; QVector<SourceDrainMono_Sensor_stm32comm_Params *> drainparams; copyQVector(drainparams,drainParams); QVector<SourceDrainMono_Sensor_stm32comm_Data *> draindata; copyQVector(draindata,drainData); /*======Please Program below======*/ /* Function: process draindata. */ // vars->comm_label->setText(QString("YAW: %1\nrightodom: %2\nleftodom: %3\nrightspeed: %4\nleftspeed: %5\n"). // arg(draindata.front()->yaw). // arg(draindata.front()->rightodom).arg(draindata.front()->leftodom). // arg(draindata.front()->rightspeed).arg(draindata.front()->leftspeed)); if(draindata.size()==0) { vars->qmap->setText("No Data"); return 0; } /*======Please Program below======*/ /* Function: process draindata. */ int minshiftx = 1, minshifty = 1; int i,j,dx,dy; cv::Point2d p; p.x = ((int) (draindata.front()->x / params->pixelsize)) * params->pixelsize; p.y = ((int) (draindata.front()->y / params->pixelsize)) * params->pixelsize; dx = (p.x-vars->mapzero.x)/params->pixelsize; dy = (p.y-vars->mapzero.y)/params->pixelsize; if ( ! (abs(dx)<=minshiftx && abs(dy)<=minshifty))//ÐèÒªÒƶ¯ { vars->mapzero = p; if (abs(dx)>=vars->map.cols/2 || abs(dy)>=vars->map.rows/2)//Òƶ¯¹ýŽó£¬Ö±œÓÖØÖà { vars->map.setTo(0); } else { cv::Mat M(2,3,CV_32F); M.at<float>(0,0)=1;M.at<float>(0,1)=0;M.at<float>(0,2)=-dx; M.at<float>(1,0)=0;M.at<float>(1,1)=1;M.at<float>(1,2)=dy; cv::warpAffine(vars->map,vars->map,M,vars->map.size()); } } //QtÊÇbgrµÄÑÕÉ« cv::Scalar c_red = CV_RGB(0,0,255); cv::Scalar c_blue = CV_RGB(255,144,30); cv::Scalar c_green = CV_RGB(37,225,132); cv::Scalar c_gold = CV_RGB(1,215,255); cv::Point2d mapp = cv::Point2d(draindata.front()->x,draindata.front()->y); mapp -= vars->mapzero; mapp.x = mapp.x / params->pixelsize + params->mapsize/2; mapp.y = mapp.y / params->pixelsize + params->mapsize/2; circle(vars->map,mapp,2,c_gold,-1); //Ê®Ã×Ò»žöÍøžñ cv::Mat gridmap3(cv::Size(params->mapsize,params->mapsize),CV_8UC3); gridmap3.setTo(0); cv::Mat gridmap1(cv::Size(params->mapsize,params->mapsize),CV_8UC1); gridmap1.setTo(0); int grid = 10.0 / params->pixelsize; for(int i = params->mapsize % grid ; i < params->mapsize ; i+= grid) { cv::line(gridmap3,cv::Point(i,0),cv::Point(i,params->mapsize),c_blue,1); cv::line(gridmap1,cv::Point(i,0),cv::Point(i,params->mapsize),cv::Scalar(255),1); } for(int i = params->mapsize - grid ; i > 0 ; i -= grid) { cv::line(gridmap3,cv::Point(0,i),cv::Point(params->mapsize,i),c_blue,1); cv::line(gridmap1,cv::Point(0,i),cv::Point(params->mapsize,i),cv::Scalar(255),1); } cv::bitwise_not(gridmap1,gridmap1); vars->map.copyTo(gridmap3,gridmap1); cv::circle(gridmap3,cv::Point(params->mapsize/2,params->mapsize/2),1,c_red); //compass gridmap3(cv::Rect(params->mapsize-grid+1,0,grid-1,grid-1)).setTo(0); cv::Point composso = cv::Point(params->mapsize-grid/2,grid/2); cv::circle(gridmap3,composso,grid/2-1,c_green,1,CV_AA); cv::line(gridmap3,composso,cv::Point(composso.x + cos(draindata.front()->theta)*(grid-1)/2-1, composso.y - sin(draindata.front()->theta)*(grid-1)/2-1), c_green,1,CV_AA); //speed + odometry + (x,y) gridmap3(cv::Rect(0,0,2*grid-1,grid-1)).setTo(0); cv::putText(gridmap3,QString("(%1, %2)").arg(draindata.front()->x).arg(draindata.front()->y).toStdString(), cv::Point(0,20),CV_FONT_HERSHEY_SCRIPT_SIMPLEX,0.5,c_red,1,CV_AA); cv::putText(gridmap3,QString("leftspeed: %1 m/s").arg(draindata.front()->theta).toStdString(), cv::Point(0,40),CV_FONT_HERSHEY_SCRIPT_SIMPLEX,0.5,c_red,1,CV_AA); cv::putText(gridmap3,QString("rightspeed: %1 m").arg(draindata.front()->rightodom).toStdString(), cv::Point(0,60),CV_FONT_HERSHEY_SCRIPT_SIMPLEX,0.5,c_red,1,CV_AA); cv::putText(gridmap3,QString("leftodom: %1 m").arg(draindata.front()->leftodom).toStdString(), cv::Point(0,80),CV_FONT_HERSHEY_SCRIPT_SIMPLEX,0.5,c_red,1,CV_AA); cv::putText(gridmap3,QString("angle: %1 deg").arg(draindata.front()->theta).toStdString(), cv::Point(0,100),CV_FONT_HERSHEY_SCRIPT_SIMPLEX,0.5,c_red,1,CV_AA); int timestamp=((draindata.front()->timestamp.hour()*60+draindata.front()->timestamp.minute())*60 +draindata.front()->timestamp.second())*1000+draindata.front()->timestamp.msec(); cv::putText(gridmap3,QString("%1 ms").arg(timestamp).toStdString(), cv::Point(0,120),CV_FONT_HERSHEY_SCRIPT_SIMPLEX,0.5,c_red,1,CV_AA); int showWidth = vars->showheight; cv::Mat showImage (cv::Size(showWidth, vars->showheight),CV_8UC3); cv::resize(gridmap3,showImage,showImage.size()); QImage colorimg=QImage((const uchar*)(showImage.data),showImage.cols,showImage.rows, showImage.cols*showImage.channels(),QImage::Format_RGB888); // QImage colorimg=QImage((const uchar*)(vars->map.data),vars->map.cols,vars->map.rows,QImage::Format_RGB888); vars->qmap->setPixmap(QPixmap::fromImage(colorimg)); return 1; }