command_stream_t make_command_stream(int(*getbyte) (void *), void *arg) { initStackc(&s); initStacko(&o); struct command_stream *command_stream_t = (struct command_stream *)malloc(sizeof(struct command_stream)); initStream(command_stream_t); struct command*com = (struct command*)malloc(sizeof(struct command)); com->type = SIMPLE_COMMAND; com->input = com->output = NULL; struct oper o; char c; bool extra = false; bool done = false; int csize = 10; com->u.word = (char**)malloc(10 * sizeof(char*)); int count = 0; int length = 0; int mlength = 12; char* word = (char*)malloc(12 * sizeof(char)); c = getbyte(arg); int curline = 1; skipws(getbyte, arg, &c, &curline); while (c >= 0) { done = false; if (!isValidChar(c)) printError(curline); extra = false; if (isvalid(c)) { word[length] = c; length++; if (length >= mlength) { mlength += 5; word = (char*)realloc(word, mlength*sizeof(char)); } } else { if (c == '#') { while ((c = (char)getbyte(arg)) >= 0 && c != '\n'); } else if (c == '\\') { while (c == '\\') { c = (char)getbyte(arg); c = (char)getbyte(arg); } continue; } else if (c == ' ') { if (length > 0) { addWord(&com, &count, &length, word); if (count == csize - 1) { csize += 5; com->u.word = (char**)realloc(com->u.word, csize*sizeof(int)); } } else { c = (char)getbyte(arg); continue; } } else if (c == '|' || c == '&' || c == ';' || c == '\n' || c == '(' || c == ')') { /*if (com->type == SUBSHELL_COMMAND) { com = (struct command*)malloc(sizeof(struct command)); com->type = SIMPLE_COMMAND; com->u.word = (char**)malloc(10 * sizeof(char*)); com->input = com->output = NULL; count = 0; csize = 10; } */ addWord(&com, &count, &length, word); if (c == '|') { c = (char)getbyte(arg); if (c == '|') { o.type = OR; } else { o.type = PIPE; } } else if (c == '&') { o.type = AND; c = (char)getbyte(arg); if (c != '&') printError(curline); } else if (c == ';') { o.type = SEQ; c = (char)getbyte(arg); } else if (c == '(') { o.type = LEFT; } else if (c == ')') { o.type = RIGHT; } else if (c == '\n') { curline += 1; while ((c = (char)getbyte(arg)) == ' '); if (c < 0) break; while (c == '\\') { c = (char)getbyte(arg); c = (char)getbyte(arg); } if (c == '#') { while ((c = getbyte(arg)) >= 0 && c != '\n'); } if (c != '\n' && (com->u.word != NULL || com->u.subshell_command != NULL)) { o.type = SEQ; extra = true; } else { extra = false; if (count > 0) { com->u.word[count] = '\0'; pushc(&s, com); } o.type = SEQ; add(o, 't', curline); insert(command_stream_t, topc(&s)); popc(&s); done = true; reset(&com, &word, &length, &count, &csize, &mlength, 'f'); c = (char)getbyte(arg); skipws(getbyte, arg, &c, &curline); continue; } } if (o.type != PIPE && o.type != SEQ) { c = (char)getbyte(arg); } if (count > 0) { com->u.word[count] = '\0'; pushc(&s, com); } add(o, 'f', curline); if (o.type == RIGHT) reset(&com, &word, &length, &count, &csize, &mlength, 't'); else reset(&com, &word, &length, &count, &csize, &mlength, 'f'); if (o.type != RIGHT) { skipws(getbyte, arg, &c,&curline); } extra = true; } else if (c == '>' || c == '<') { char* ptr; int insize = 12; ptr = (char*)malloc(insize * sizeof(char)); int i = 0; char t = c; while ((c = (char)getbyte(arg)) == ' '); if (!isvalid(c)) printError(curline); while ((c >= 0)) { if (!isvalid(c)) { extra = true; break; } ptr[i] = c; i++; if (i == insize - 1) { insize += 5; ptr = (char*)realloc(ptr, insize*sizeof(char)); } c = (char)getbyte(arg); } ptr[i] = '\0'; if (t == '<') com->input = ptr; else com->output = ptr; } } if (!extra) c = (char)getbyte(arg); } if (!done) { addWord(&com, &count, &length, word); if (count > 0) { com->u.word[count] = '\0'; pushc(&s, com); } o.type = SEQ; add(o, 't', curline); if (sizec(&s) != 1) printError(curline); insert(command_stream_t, topc(&s)); popc(&s); } return command_stream_t; }
LUA_API int lua_rawequal (lua_State *L, int index1, int index2) { StkId o1 = index2addr(L, index1); StkId o2 = index2addr(L, index2); return (isvalid(o1) && isvalid(o2)) ? luaV_rawequalobj(o1, o2) : 0; }
void Gestion_Jeux(SDL_Surface **ecran, SDL_Surface **carte, char JeuxDeCarte[MAX][MAX], SDL_Rect *position_carte, int* MainJouer[NB_CARTE],FLAG *FLAG, int *Selection_Carte[NB_CARTE], int *JeuxActuel[NB_CARTE], char **JeuxActuel1, int MainGagnante[NB_CARTE], int *MainGarder[NB_CARTE], int *Credit) { SDL_Surface *initialisation = NULL; SDL_Rect position_initialisation; TTF_Font *police_contenu = NULL; int selection = 0; int compteur = 0; int MainEnCours[5] = RAZ_CARTE; int nombre; /* Le flag permet de vérifier que nous somme au debut d'une partie */ if (FLAG->FLAG_JEUX == 1){ MainGarder[0] = 0; MainGarder[1] = 0; MainGarder[2] = 0; MainGarder[3] = 0; MainGarder[4] = 0; MainGarder[5] = 0; MainJouer[0] = 7; MainJouer[1] = 7; MainJouer[2] = 7; MainJouer[3] = 7; MainJouer[4] = 7; MainJouer[5] = 7; /* Géneration des cartes aléatoire pour le premier tour*/ for (compteur = 0 ; compteur <= 4 ; compteur++) { if (MainJouer[compteur] == 7){ if (compteur == 0){ MainEnCours[compteur] = Random (1,52); }else{ do { MainEnCours[compteur] = Random (1,52); nombre = MainEnCours[compteur]; JeuxActuel[compteur] = nombre; } while(!isvalid(nombre, &MainEnCours, 4, compteur)); } } } for (compteur = 0 ; compteur <= 4 ; compteur++) { selection = MainEnCours[compteur]; MainGagnante[compteur] = selection; JeuxActuel[compteur] = selection; JeuxActuel1[compteur] = JeuxDeCarte[selection]; carte[compteur] = IMG_Load(JeuxDeCarte[selection]); } /*Blit du jeu generé */ for (compteur = 0 ; compteur <= 4 ; compteur++) { SDL_BlitSurface(carte[compteur], NULL, *ecran, &position_carte[compteur]); } } /* Le flag permet de vérifier que nous somme au second tour de la partie */ if (FLAG->FLAG_GAIM == 1){ for (compteur = 0 ; compteur <= 4 ; compteur++) { if (MainJouer[compteur]==7){ do { MainEnCours[compteur] = Random(1,52); nombre = MainEnCours[compteur]; JeuxActuel[compteur] = nombre; } while(!isvalid(nombre, JeuxActuel, 4, compteur)); } } for (compteur = 0 ; compteur <= 4 ; compteur++) { if (MainJouer[compteur]==7){ selection = MainEnCours[compteur]; MainGagnante[compteur] = selection; JeuxActuel1[compteur] = JeuxDeCarte[selection]; carte[compteur] = IMG_Load(JeuxDeCarte[selection]); } } /*Blit du jeu generé */ for (compteur = 0 ; compteur <= 4 ; compteur++) { SDL_BlitSurface(carte[compteur], NULL, *ecran, &position_carte[compteur]); } Affichage_Main(&initialisation, &police_contenu, &position_initialisation, JeuxActuel1, MainGagnante, Credit); SDL_BlitSurface(initialisation, NULL, *ecran, &position_initialisation); /*RAZ Flag permettant de reprendre une nouvelle partie */ FLAG->FLAG_GAIM = 0; FLAG->FLAG_INI = 1; FLAG->FLAG_JEUX = 0; FLAG->FLAG_SELECTION = 0; //FLAG permetant d'afficher le GAIN FLAG->FLAG_RESULTAT = 1; /* Remise a zéro des cartes */ MainJouer[0] = 7; MainJouer[1] = 7; MainJouer[2] = 7; MainJouer[3] = 7; MainJouer[4] = 7; } /* Mise en place des parametres afin de passer au second tour */ if (FLAG->FLAG_JEUX == 1){ FLAG->FLAG_JEUX = 0; FLAG->FLAG_SELECTION = 1; FLAG->FLAG_GAIM = 1; FLAG->FLAG_RESULTAT = 0; Selection_Carte[0] = 1; Selection_Carte[1] = 1; Selection_Carte[2] = 1; Selection_Carte[3] = 1; Selection_Carte[4] = 1; } /*Mise a jour de l'écran */ SDL_Flip(*ecran); }
bool Move::bfs( int x1 , int y1 , int x2 , int y2 , Component*** a , BFSOut &ConnectionPath ) { BFSOut outx; outx.check = false; int** vis = new int*[1400]; for ( int i = 0; i < 1400; i++ )vis[i] = new int[780]; for ( int i = 0; i < 1400; i++ )for ( int j = 0; j < 780; j++ )vis[i][j] = 0; int** ifc = new int*[780]; for ( int i = 0; i < 780; i++ )ifc[i] = new int[1400]; int** oth = new int*[780]; for ( int i = 0; i < 780; i++ )oth[i] = new int[1400]; for ( int i = 0; i < 780; i++ ) for ( int j = 0; j < 1400; j++ ) { if ( a[i][j] != NULL ) if ( dynamic_cast<Connection*>(a[i][j]) ) { if ( !dynamic_cast<Connection*>(a[y1][x1 - 15]) ) { if ( (( Connection* )(a[i][j]))->getSourcePin( ) == (a[y1][x1 - 15])->GetOutputPin( ) ) ifc[i][j] = 0; else ifc[i][j] = 1; oth[i][j] = 0; } } else { ifc[i][j] = 0; oth[i][j] = 1; } else { ifc[i][j] = 0; oth[i][j] = 0; } } int klk = 0; queue< pair<int , int> > qu; qu.push( make_pair( x1 , y1 ) ); while ( !qu.empty( ) ) { pair<int , int> pr = qu.front( ); vis[pr.first][pr.second] = 1; qu.pop( ); if ( isvalid( pr.first + 15 , pr.second , vis , ifc , oth , pr.first , pr.second , x2 , y2 , x1 ) ) { qu.push( make_pair( pr.first + 15 , pr.second ) ); outx.arr[pr.first + 15][pr.second] = make_pair( pr.first , pr.second ); vis[pr.first + 15][pr.second] = 1; if ( qu.back( ).first == x2 && qu.back( ).second == y2 ) break; } if ( isvalid( pr.first , pr.second + 15 , vis , ifc , oth , pr.first , pr.second , x2 , y2 , x1 ) ) { qu.push( make_pair( pr.first , pr.second + 15 ) ); outx.arr[pr.first][pr.second + 15] = make_pair( pr.first , pr.second ); vis[pr.first][pr.second + 15] = 1; if ( qu.back( ).first == x2 && qu.back( ).second == y2 ) break; } if ( isvalid( pr.first - 15 , pr.second , vis , ifc , oth , pr.first , pr.second , x2 , y2 , x1 ) ) { qu.push( make_pair( pr.first - 15 , pr.second ) ); outx.arr[pr.first - 15][pr.second] = make_pair( pr.first , pr.second ); vis[pr.first - 15][pr.second] = 1; if ( qu.back( ).first == x2 && qu.back( ).second == y2 ) break; } if ( isvalid( pr.first , pr.second - 15 , vis , ifc , oth , pr.first , pr.second , x2 , y2 , x1 ) ) { qu.push( make_pair( pr.first , pr.second - 15 ) ); outx.arr[pr.first][pr.second - 15] = make_pair( pr.first , pr.second ); vis[pr.first][pr.second - 15] = 1; if ( qu.back( ).first == x2 && qu.back( ).second == y2 ) break; } } if ( vis[x2][y2] == 1 ) { outx.check = true; for ( int i = 0; i < 780; i++ ) for ( int j = 0; j < 1400; j++ ) ConnectionPath.arr[j][i] = outx.arr[j][i]; } else outx.check = false; for ( int i = 0; i < 780; i++ ) { delete[]vis[i]; delete[]ifc[i]; delete[]oth[i]; } delete[]vis; delete[]ifc; delete[]oth; return outx.check; }
LUA_API int lua_type (lua_State *L, int idx) { StkId o = index2addr(L, idx); return (isvalid(o) ? ttypenv(o) : LUA_TNONE); }
Bit8u FCB_Parsename(Bit16u seg, Bit16u offset, Bit8u parser, char* string, Bit8u* change) { char* string_begin = string; Bit8u ret = 0; if (!(parser & PARSE_DFLT_DRIVE)) // Default drive forced, this intentionally invalidates an extended FCB vPC_rStosb(SegOff2Ptr(seg, offset), 0); DOS_FCB fcb(seg, offset, false); // Always a non-extended FCB // First get the old data from the fcb #pragma pack (1) union { struct { char drive[2]; char name[9]; char ext[4]; } part; char full[DOS_FCBNAME]; } fcb_name; #pragma pack() fcb.GetName(fcb_name.full); // Get the old information from the previous fcb fcb_name.part.drive[0] -= 'A'-1; fcb_name.part.drive[1] = 0; fcb_name.part.name[8] = 0; fcb_name.part.ext[3] = 0; if ((parser & PARSE_SEP_STOP) && *string) // Ignore leading seperator if (strchr(":.;,=+", *string)) string++; while ((*string == ' ') || (*string == '\t')) // Strip leading spaces string++; bool hasdrive, hasname, hasext, finished; hasdrive = hasname = hasext = finished = false; if (string[1] == ':') // Check for a drive { fcb_name.part.drive[0] = 0; hasdrive = true; if (isalpha(string[0]) && Drives[toupper(string[0])-'A']) fcb_name.part.drive[0] = (char)(toupper(string[0])-'A'+1); else ret = 0xff; string += 2; } if (string[0] == '.') // Special checks for . and .. { string++; if (!string[0]) { hasname = true; ret = PARSE_RET_NOWILD; strcpy(fcb_name.part.name, ". "); goto savefcb; } if (string[1] == '.' && !string[1]) { string++; hasname = true; ret = PARSE_RET_NOWILD; strcpy(fcb_name.part.name, ".. "); goto savefcb; } goto checkext; } hasname = true; // Copy the name finished = false; Bit8u fill = ' '; Bitu index = 0; while (index < 8) { if (!finished) { if (string[0] == '*') { fill = '?'; fcb_name.part.name[index] = '?'; if (!ret) ret = 1; finished = true; } else if (string[0] == '?') { fcb_name.part.name[index] = '?'; if (!ret) ret = 1; } else if (isvalid(string[0])) fcb_name.part.name[index] = (char)(toupper(string[0])); else { finished = true; continue; } string++; } else fcb_name.part.name[index] = fill; index++; } if (!(string[0] == '.')) goto savefcb; string++; checkext: hasext = true; // Copy the extension finished = false; fill = ' '; index = 0; while (index < 3) { if (!finished) { if (string[0] == '*') { fill = '?'; fcb_name.part.ext[index] = '?'; finished = true; } else if (string[0] == '?') { fcb_name.part.ext[index] = '?'; if (!ret) ret = 1; } else if (isvalid(string[0])) fcb_name.part.ext[index] = (char)(toupper(string[0])); else { finished = true; continue; } string++; } else fcb_name.part.ext[index] = fill; index++; } savefcb: if (!hasdrive & !(parser & PARSE_DFLT_DRIVE)) fcb_name.part.drive[0] = 0; if (!hasname & !(parser & PARSE_BLNK_FNAME)) strcpy(fcb_name.part.name, " "); if (!hasext & !(parser & PARSE_BLNK_FEXT)) strcpy(fcb_name.part.ext, " "); fcb.SetName(fcb_name.part.drive[0], fcb_name.part.name, fcb_name.part.ext); *change = (Bit8u)(string-string_begin); return ret; }
void RTC8564::begin(void) { Wire.begin(); if(isvalid() == false) init(); }
/** * Just like glXUseXFont() but with a rotation parameter. * \param rotation may be 0, 90, 180 or 270 only. */ void glXUseRotatedXFontMESA(Font font, int first, int count, int listbase, int rotation) { Display *dpy; Window win; Pixmap pixmap; GC gc; XFontStruct *fs; GLint swapbytes, lsbfirst, rowlength; GLint skiprows, skippixels, alignment; unsigned int maxCharWidth, maxCharHeight; GLubyte *bm; int i; if (rotation != 0 && rotation != 90 && rotation != 180 && rotation != 270) return; dpy = glXGetCurrentDisplay(); if (!dpy) return; /* I guess glXMakeCurrent wasn't called */ win = RootWindow(dpy, DefaultScreen(dpy)); fs = XQueryFont(dpy, font); if (!fs) { fprintf(stderr, "XQueryFont failed"); return; } /* Allocate a GL bitmap that can fit any character */ maxCharWidth = fs->max_bounds.rbearing - fs->min_bounds.lbearing; maxCharHeight = fs->max_bounds.ascent + fs->max_bounds.descent; /* use max, in case we're rotating */ if (rotation == 90 || rotation == 270) { /* swap width/height */ bm = (GLubyte *) malloc((maxCharHeight + 7) / 8 * maxCharWidth); } else { /* normal or upside down */ bm = (GLubyte *) malloc((maxCharWidth + 7) / 8 * maxCharHeight); } if (!bm) { XFreeFontInfo(NULL, fs, 1); fprintf(stderr, "Out of memory in glXUseRotatedXFontMESA"); return; } /* Save the current packing mode for bitmaps. */ glGetIntegerv(GL_UNPACK_SWAP_BYTES, &swapbytes); glGetIntegerv(GL_UNPACK_LSB_FIRST, &lsbfirst); glGetIntegerv(GL_UNPACK_ROW_LENGTH, &rowlength); glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skiprows); glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skippixels); glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment); /* Enforce a standard packing mode which is compatible with fill_bitmap() from above. This is actually the default mode, except for the (non)alignment. */ glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); /* Create pixmap and GC */ pixmap = XCreatePixmap(dpy, win, maxCharWidth, maxCharHeight, 1); { XGCValues values; unsigned long valuemask; values.foreground = BlackPixel(dpy, DefaultScreen(dpy)); values.background = WhitePixel(dpy, DefaultScreen(dpy)); values.font = fs->fid; valuemask = GCForeground | GCBackground | GCFont; gc = XCreateGC(dpy, pixmap, valuemask, &values); } for (i = 0; i < count; i++) { const unsigned int c = first + i; const int list = listbase + i; unsigned int charWidth, charHeight; unsigned int bitmapWidth, bitmapHeight; GLfloat xOrig, yOrig, xStep, yStep, dtemp; const XCharStruct *ch; int xPos, yPos; int valid; /* check on index validity and get the bounds */ ch = isvalid(fs, c); if (!ch) { ch = &fs->max_bounds; valid = 0; } else { valid = 1; } /* glBitmap()' parameters: straight from the glXUseXFont(3) manpage. */ charWidth = ch->rbearing - ch->lbearing; charHeight = ch->ascent + ch->descent; xOrig = -ch->lbearing; yOrig = ch->descent; xStep = ch->width; yStep = 0; /* X11's starting point. */ xPos = -ch->lbearing; yPos = ch->ascent; /* Apply rotation */ switch (rotation) { case 0: /* nothing */ bitmapWidth = charWidth; bitmapHeight = charHeight; break; case 90: /* xStep, yStep */ dtemp = xStep; xStep = -yStep; yStep = dtemp; /* xOrig, yOrig */ yOrig = xOrig; xOrig = charHeight - (charHeight - yPos); /* width, height */ bitmapWidth = charHeight; bitmapHeight = charWidth; break; case 180: /* xStep, yStep */ xStep = -xStep; yStep = -yStep; /* xOrig, yOrig */ xOrig = charWidth - xOrig - 1; yOrig = charHeight - yOrig - 1; bitmapWidth = charWidth; bitmapHeight = charHeight; break; case 270: /* xStep, yStep */ dtemp = xStep; xStep = yStep; yStep = -dtemp; /* xOrig, yOrig */ dtemp = yOrig; yOrig = charWidth - xOrig; xOrig = dtemp; /* width, height */ bitmapWidth = charHeight; bitmapHeight = charWidth; break; default: /* should never get here */ ; } glNewList(list, GL_COMPILE); if (valid && bitmapWidth > 0 && bitmapHeight > 0) { fill_bitmap(dpy, pixmap, gc, bitmapWidth, bitmapHeight, charWidth, charHeight, xPos, yPos, c, bm, rotation); glBitmap(bitmapWidth, bitmapHeight, xOrig, yOrig, xStep, yStep, bm); } else { glBitmap(0, 0, 0.0, 0.0, xStep, yStep, NULL); } glEndList(); } free(bm); XFreeFontInfo(NULL, fs, 1); XFreePixmap(dpy, pixmap); XFreeGC(dpy, gc); /* Restore saved packing modes. */ glPixelStorei(GL_UNPACK_SWAP_BYTES, swapbytes); glPixelStorei(GL_UNPACK_LSB_FIRST, lsbfirst); glPixelStorei(GL_UNPACK_ROW_LENGTH, rowlength); glPixelStorei(GL_UNPACK_SKIP_ROWS, skiprows); glPixelStorei(GL_UNPACK_SKIP_PIXELS, skippixels); glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); }
bool shamap::compare (shamap::ref othermap, delta& differences, int maxcount) { // compare two hash trees, add up to maxcount differences to the difference table // return value: true=complete table of differences given, false=too many differences // throws on corrupt tables or missing nodes // caution: othermap is not locked and must be immutable assert (isvalid () && othermap && othermap->isvalid ()); using stackentry = std::pair <shamaptreenode*, shamaptreenode*>; std::stack <stackentry, std::vector<stackentry>> nodestack; // track nodes we've pushed if (gethash () == othermap->gethash ()) return true; nodestack.push ({root.get(), othermap->root.get()}); while (!nodestack.empty ()) { shamaptreenode* ournode = nodestack.top().first; shamaptreenode* othernode = nodestack.top().second; nodestack.pop (); if (!ournode || !othernode) { assert (false); throw shamapmissingnode (mtype, uint256 ()); } if (ournode->isleaf () && othernode->isleaf ()) { // two leaves if (ournode->gettag () == othernode->gettag ()) { if (ournode->peekdata () != othernode->peekdata ()) { differences.insert (std::make_pair (ournode->gettag (), deltaref (ournode->peekitem (), othernode->peekitem ()))); if (--maxcount <= 0) return false; } } else { differences.insert (std::make_pair(ournode->gettag (), deltaref(ournode->peekitem(), shamapitem::pointer ()))); if (--maxcount <= 0) return false; differences.insert(std::make_pair(othernode->gettag (), deltaref(shamapitem::pointer(), othernode->peekitem ()))); if (--maxcount <= 0) return false; } } else if (ournode->isinner () && othernode->isleaf ()) { if (!walkbranch (ournode, othernode->peekitem (), true, differences, maxcount)) return false; } else if (ournode->isleaf () && othernode->isinner ()) { if (!othermap->walkbranch (othernode, ournode->peekitem (), false, differences, maxcount)) return false; } else if (ournode->isinner () && othernode->isinner ()) { for (int i = 0; i < 16; ++i) if (ournode->getchildhash (i) != othernode->getchildhash (i)) { if (othernode->isemptybranch (i)) { // we have a branch, the other tree does not shamaptreenode* inode = descendthrow (ournode, i); if (!walkbranch (inode, shamapitem::pointer (), true, differences, maxcount)) return false; } else if (ournode->isemptybranch (i)) { // the other tree has a branch, we do not shamaptreenode* inode = othermap->descendthrow(othernode, i); if (!othermap->walkbranch (inode, shamapitem::pointer(), false, differences, maxcount)) return false; } else // the two trees have different non-empty branches nodestack.push ({descendthrow (ournode, i), othermap->descendthrow (othernode, i)}); } } else assert (false); } return true; }
PUBLIC void glXUseXFont(Font font, int first, int count, int listbase) { Display *dpy; Window win; Pixmap pixmap; GC gc; XGCValues values; unsigned long valuemask; XFontStruct *fs; GLint swapbytes, lsbfirst, rowlength; GLint skiprows, skippixels, alignment; unsigned int max_width, max_height, max_bm_width, max_bm_height; GLubyte *bm; int i; dpy = glXGetCurrentDisplay(); if (!dpy) return; /* I guess glXMakeCurrent wasn't called */ i = DefaultScreen(dpy); win = RootWindow(dpy, i); fs = XQueryFont(dpy, font); if (!fs) { _mesa_error(NULL, GL_INVALID_VALUE, "Couldn't get font structure information"); return; } /* Allocate a bitmap that can fit all characters. */ max_width = fs->max_bounds.rbearing - fs->min_bounds.lbearing; max_height = fs->max_bounds.ascent + fs->max_bounds.descent; max_bm_width = (max_width + 7) / 8; max_bm_height = max_height; bm = (GLubyte *) malloc((max_bm_width * max_bm_height) * sizeof(GLubyte)); if (!bm) { XFreeFontInfo(NULL, fs, 1); _mesa_error(NULL, GL_OUT_OF_MEMORY, "Couldn't allocate bitmap in glXUseXFont()"); return; } #if 0 /* get the page info */ pages = fs->max_char_or_byte2 - fs->min_char_or_byte2 + 1; firstchar = (fs->min_byte1 << 8) + fs->min_char_or_byte2; lastchar = (fs->max_byte1 << 8) + fs->max_char_or_byte2; rows = fs->max_byte1 - fs->min_byte1 + 1; unsigned int first_char, last_char, pages, rows; #endif /* Save the current packing mode for bitmaps. */ glGetIntegerv(GL_UNPACK_SWAP_BYTES, &swapbytes); glGetIntegerv(GL_UNPACK_LSB_FIRST, &lsbfirst); glGetIntegerv(GL_UNPACK_ROW_LENGTH, &rowlength); glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skiprows); glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skippixels); glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment); /* Enforce a standard packing mode which is compatible with fill_bitmap() from above. This is actually the default mode, except for the (non)alignment. */ glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); pixmap = XCreatePixmap(dpy, win, 10, 10, 1); values.foreground = BlackPixel(dpy, DefaultScreen(dpy)); values.background = WhitePixel(dpy, DefaultScreen(dpy)); values.font = fs->fid; valuemask = GCForeground | GCBackground | GCFont; gc = XCreateGC(dpy, pixmap, valuemask, &values); XFreePixmap(dpy, pixmap); #ifdef DEBUG if (debug_xfonts) dump_font_struct(fs); #endif for (i = 0; i < count; i++) { unsigned int width, height, bm_width, bm_height; GLfloat x0, y0, dx, dy; XCharStruct *ch; int x, y; unsigned int c = first + i; int list = listbase + i; int valid; /* check on index validity and get the bounds */ ch = isvalid(fs, c); if (!ch) { ch = &fs->max_bounds; valid = 0; } else { valid = 1; } #ifdef DEBUG if (debug_xfonts) { char s[7]; sprintf(s, isprint(c) ? "%c> " : "\\%03o> ", c); dump_char_struct(ch, s); } #endif /* glBitmap()' parameters: straight from the glXUseXFont(3) manpage. */ width = ch->rbearing - ch->lbearing; height = ch->ascent + ch->descent; x0 = -ch->lbearing; y0 = ch->descent - 0; /* XXX used to subtract 1 here */ /* but that caused a conformace failure */ dx = ch->width; dy = 0; /* X11's starting point. */ x = -ch->lbearing; y = ch->ascent; /* Round the width to a multiple of eight. We will use this also for the pixmap for capturing the X11 font. This is slightly inefficient, but it makes the OpenGL part real easy. */ bm_width = (width + 7) / 8; bm_height = height; glNewList(list, GL_COMPILE); if (valid && (bm_width > 0) && (bm_height > 0)) { memset(bm, '\0', bm_width * bm_height); fill_bitmap(dpy, win, gc, bm_width, bm_height, x, y, c, bm); glBitmap(width, height, x0, y0, dx, dy, bm); #ifdef DEBUG if (debug_xfonts) { printf("width/height = %u/%u\n", width, height); printf("bm_width/bm_height = %u/%u\n", bm_width, bm_height); dump_bitmap(bm_width, bm_height, bm); } #endif } else { glBitmap(0, 0, 0.0, 0.0, dx, dy, NULL); } glEndList(); } free(bm); XFreeFontInfo(NULL, fs, 1); XFreeGC(dpy, gc); /* Restore saved packing modes. */ glPixelStorei(GL_UNPACK_SWAP_BYTES, swapbytes); glPixelStorei(GL_UNPACK_LSB_FIRST, lsbfirst); glPixelStorei(GL_UNPACK_ROW_LENGTH, rowlength); glPixelStorei(GL_UNPACK_SKIP_ROWS, skiprows); glPixelStorei(GL_UNPACK_SKIP_PIXELS, skippixels); glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); }
Bit8u FCB_Parsename(Bit16u seg,Bit16u offset,Bit8u parser ,char *string, Bit8u *change) { char * string_begin=string; Bit8u ret=0; if (!(parser & PARSE_DFLT_DRIVE)) { // default drive forced, this intentionally invalidates an extended FCB mem_writeb(PhysMake(seg,offset),0); } DOS_FCB fcb(seg,offset,false); // always a non-extended FCB bool hasdrive,hasname,hasext,finished; hasdrive=hasname=hasext=finished=false; Bitu index=0; Bit8u fill=' '; /* First get the old data from the fcb */ #ifdef _MSC_VER #pragma pack (1) #endif union { struct { char drive[2]; char name[9]; char ext[4]; } GCC_ATTRIBUTE (packed) part; char full[DOS_FCBNAME]; } fcb_name; #ifdef _MSC_VER #pragma pack() #endif /* Get the old information from the previous fcb */ fcb.GetName(fcb_name.full); fcb_name.part.drive[0]-='A'-1;fcb_name.part.drive[1]=0; fcb_name.part.name[8]=0;fcb_name.part.ext[3]=0; /* strip leading spaces */ while((*string==' ')||(*string=='\t')) string++; /* Strip of the leading separator */ if((parser & PARSE_SEP_STOP) && *string) { char sep[] = FCB_SEP;char a[2]; a[0] = *string;a[1] = '\0'; if (strcspn(a,sep) == 0) string++; } /* Skip following spaces as well */ while((*string==' ')||(*string=='\t')) string++; /* Check for a drive */ if (string[1]==':') { unsigned char d = *reinterpret_cast<unsigned char*>(&string[0]); if (!isvalid(toupper(d))) {string += 2; goto savefcb;} //TODO check (for ret value) fcb_name.part.drive[0]=0; hasdrive=true; if (isalpha(d) && Drives[toupper(d)-'A']) { //Floppies under dos always exist, but don't bother with that at this level ; //THIS* was here } else ret=0xff; fcb_name.part.drive[0]=DOS_ToUpper(string[0])-'A'+1; //Always do THIS* and continue parsing, just return the right code string+=2; } /* Check for extension only file names */ if (string[0] == '.') {string++;goto checkext;} /* do nothing if not a valid name */ if(!isvalid(string[0])) goto savefcb; hasname=true;finished=false;fill=' ';index=0; /* Copy the name */ while (true) { unsigned char nc = *reinterpret_cast<unsigned char*>(&string[0]); char ncs = (char)toupper(nc); //Should use DOS_ToUpper, but then more calls need to be changed. if (ncs == '*') { //Handle * fill = '?'; ncs = '?'; } if (ncs == '?' && !ret && index < 8) ret = 1; //Don't override bad drive if (!isvalid(ncs)) { //Fill up the name. while(index < 8) fcb_name.part.name[index++] = fill; break; } if (index < 8) { fcb_name.part.name[index++] = (fill == '?')?fill:ncs; } string++; } if (!(string[0]=='.')) goto savefcb; string++; checkext: /* Copy the extension */ hasext=true;finished=false;fill=' ';index=0; while (true) { unsigned char nc = *reinterpret_cast<unsigned char*>(&string[0]); char ncs = (char)toupper(nc); if (ncs == '*') { //Handle * fill = '?'; ncs = '?'; } if (ncs == '?' && !ret && index < 3) ret = 1; if (!isvalid(ncs)) { //Fill up the name. while(index < 3) fcb_name.part.ext[index++] = fill; break; } if (index < 3) { fcb_name.part.ext[index++] = (fill=='?')?fill:ncs; } string++; } savefcb: if (!hasdrive & !(parser & PARSE_DFLT_DRIVE)) fcb_name.part.drive[0] = 0; if (!hasname & !(parser & PARSE_BLNK_FNAME)) strcpy(fcb_name.part.name," "); if (!hasext & !(parser & PARSE_BLNK_FEXT)) strcpy(fcb_name.part.ext," "); fcb.SetName(fcb_name.part.drive[0],fcb_name.part.name,fcb_name.part.ext); fcb.ClearBlockRecsize(); //Undocumented bonus work. *change=(Bit8u)(string-string_begin); return ret; }
Bit8u FCB_Parsename(Bit16u seg,Bit16u offset,Bit8u parser ,char *string, Bit8u *change) { char * string_begin=string; Bit8u ret=0; if (!(parser & PARSE_DFLT_DRIVE)) { // default drive forced, this intentionally invalidates an extended FCB mem_writeb(PhysMake(seg,offset),0); } DOS_FCB fcb(seg,offset,false); // always a non-extended FCB bool hasdrive,hasname,hasext,finished; hasdrive=hasname=hasext=finished=false; Bitu index=0; Bit8u fill=' '; /* First get the old data from the fcb */ #ifdef _MSC_VER #pragma pack (1) #endif union { struct { char drive[2]; char name[9]; char ext[4]; } GCC_ATTRIBUTE (packed) part; char full[DOS_FCBNAME]; } fcb_name; #ifdef _MSC_VER #pragma pack() #endif /* Get the old information from the previous fcb */ fcb.GetName(fcb_name.full); fcb_name.part.drive[0]-='A'-1;fcb_name.part.drive[1]=0; fcb_name.part.name[8]=0;fcb_name.part.ext[3]=0; /* Strip of the leading sepetaror */ if((parser & PARSE_SEP_STOP) && *string) { //ignore leading seperator char sep[] = FCB_SEP;char a[2]; a[0]= *string;a[1]='\0'; if (strcspn(a,sep)==0) string++; } /* strip leading spaces */ while((*string==' ')||(*string=='\t')) string++; /* Check for a drive */ if (string[1]==':') { fcb_name.part.drive[0]=0; hasdrive=true; if (isalpha(string[0]) && Drives[toupper(string[0])-'A']) { fcb_name.part.drive[0]=(char)(toupper(string[0])-'A'+1); } else ret=0xff; string+=2; } /* Special checks for . and .. */ if (string[0]=='.') { string++; if (!string[0]) { hasname=true; ret=PARSE_RET_NOWILD; strcpy(fcb_name.part.name,". "); goto savefcb; } if (string[1]=='.' && !string[1]) { string++; hasname=true; ret=PARSE_RET_NOWILD; strcpy(fcb_name.part.name,".. "); goto savefcb; } goto checkext; } /* Copy the name */ hasname=true;finished=false;fill=' ';index=0; while (index<8) { if (!finished) { if (string[0]=='*') {fill='?';fcb_name.part.name[index]='?';if (!ret) ret=1;finished=true;} else if (string[0]=='?') {fcb_name.part.name[index]='?';if (!ret) ret=1;} else if (isvalid(string[0])) {fcb_name.part.name[index]=(char)(toupper(string[0]));} else { finished=true;continue; } string++; } else { fcb_name.part.name[index]=fill; } index++; } if (!(string[0]=='.')) goto savefcb; string++; checkext: /* Copy the extension */ hasext=true;finished=false;fill=' ';index=0; while (index<3) { if (!finished) { if (string[0]=='*') {fill='?';fcb_name.part.ext[index]='?';finished=true;} else if (string[0]=='?') {fcb_name.part.ext[index]='?';if (!ret) ret=1;} else if (isvalid(string[0])) {fcb_name.part.ext[index]=(char)(toupper(string[0]));} else { finished=true;continue; } string++; } else { fcb_name.part.ext[index]=fill; } index++; } savefcb: if (!hasdrive & !(parser & PARSE_DFLT_DRIVE)) fcb_name.part.drive[0] = 0; if (!hasname & !(parser & PARSE_BLNK_FNAME)) strcpy(fcb_name.part.name," "); if (!hasext & !(parser & PARSE_BLNK_FEXT)) strcpy(fcb_name.part.ext," "); fcb.SetName(fcb_name.part.drive[0],fcb_name.part.name,fcb_name.part.ext); *change=(Bit8u)(string-string_begin); return ret; }
int get_next_xml_token(FILE* F, a_string_t *tok, int *in_element) { int c,marker; while (isspace(c = fpeek(F))) xfgetc(F); a_strcpy(tok,""); c = xfgetc(F); if (*in_element>=TOK_BEGIN) { if (c=='\'' || c=='"') { marker = c; *in_element = TOK_STRING; for (;;) { c = xfgetc(F); if (c==marker) return XML_OK; if (c==EOF) { log_printf(LOG_ERROR,"unterminated quoted value"); return XML_ERROR; } a_strpushback(tok,c); } } if (c=='=') { *in_element = TOK_EQUAL; a_strcpy(tok,"="); return XML_OK; } if (c=='>') { a_strcpy(tok,">"); *in_element=TOK_GTE; return XML_OK; } if (c=='/') { c = xfgetc(F); if (c!='>') { log_printf(LOG_ERROR,"Expected '>'"); return XML_ERROR; } a_strcpy(tok,"/>"); *in_element=TOK_SLASH_GTE; return XML_OK; } *in_element=TOK_ATTRIBUTE; if (!isvalid(c)) return XML_ERROR; a_strpushback(tok,c); for (;;) { c = fpeek(F); if (c==EOF) { log_printf(LOG_ERROR,"Unterminated attribute '%s...'",a_strval(tok)); return XML_ERROR; } if (!isvalid(c)) return XML_OK; a_strpushback(tok,xfgetc(F)); } return XML_OK; } else { if (c=='<') { a_strpushback(tok,c); c = fgetc(F); if (c=='?' || c=='!' || c=='/') { if (c=='/') *in_element=TOK_END; else *in_element=TOK_INSTRUCTION; a_strpushback(tok,c); for (;;) { c = xfgetc(F); if (c==EOF) { log_printf(LOG_ERROR,"Unterminated '%s...'",a_strval(tok)); return XML_ERROR; } if (c=='>') { a_strpushback(tok,'>'); return XML_OK; } } } *in_element=TOK_BEGIN; if (!isvalid(c)) return XML_ERROR; a_strpushback(tok,c); for (;;) { c = fpeek(F); if (c==EOF) { log_printf(LOG_ERROR,"Unterminated element '%s...'",a_strval(tok)); return XML_ERROR; } if (!isvalid(c)) return XML_OK; a_strpushback(tok,xfgetc(F)); } } else /* if c=='<' */ { *in_element=TOK_TEXT; a_strpushback(tok,c); for (;;) { c = fpeek(F); if (c==EOF) { log_printf(LOG_ERROR,"Unterminated data '%s...'",a_strval(tok)); return XML_ERROR; } if (c=='<') return XML_OK; a_strpushback(tok,xfgetc(F)); } } /* else not c=='<' */ } /* else not in_element */ log_printf(LOG_ERROR,"Syntax error (should not happen)"); return XML_ERROR; }
// verify that we correctly identify malformed or invalid signatures void testmalformedsignatures () { testcase ("non-canonical signature checks", abort_on_fail); expect (!isvalid("3005" "0201ff" "0200"), "tooshort"); expect (!isvalid ("3006" "020101" "020202"), "slen-overlong"); expect (!isvalid ("3006" "020701" "020102"), "rlen-overlong-oob"); expect (!isvalid ("3006" "020401" "020102"), "rlen-overlong-oob"); expect (!isvalid ("3006" "020501" "020102"), "rlen-overlong-oob"); expect (!isvalid ("3006" "020201" "020102"), "rlen-overlong"); expect (!isvalid ("3006" "020301" "020202"), "rlen overlong and slen-overlong"); expect (!isvalid ("3006" "020401" "020202"), "rlen overlong and oob and slen-overlong"); expect (!isvalid("3047" "0221005990e0584b2b238e1dfaad8d6ed69ecc1a4a13ac85fc0b31d0df395eb1ba6105" "022200002d5876262c288beb511d061691bf26777344b702b00f8fe28621fe4e566695ed"), "toolong"); expect (!isvalid("3144" "02205990e0584b2b238e1dfaad8d6ed69ecc1a4a13ac85fc0b31d0df395eb1ba6105" "02202d5876262c288beb511d061691bf26777344b702b00f8fe28621fe4e566695ed"), "type"); expect (!isvalid("3045" "02205990e0584b2b238e1dfaad8d6ed69ecc1a4a13ac85fc0b31d0df395eb1ba6105" "02202d5876262c288beb511d061691bf26777344b702b00f8fe28621fe4e566695ed"), "totallength"); expect (!isvalid("301f" "01205990e0584b2b238e1dfaad8d6ed69ecc1a4a13ac85fc0b31d0df395eb1"), "slenoob"); expect (!isvalid("3045" "02205990e0584b2b238e1dfaad8d6ed69ecc1a4a13ac85fc0b31d0df395eb1ba6105" "02202d5876262c288beb511d061691bf26777344b702b00f8fe28621fe4e566695ed00"), "r+s"); expect (!isvalid("3044" "01205990e0584b2b238e1dfaad8d6ed69ecc1a4a13ac85fc0b31d0df395eb1ba6105" "02202d5876262c288beb511d061691bf26777344b702b00f8fe28621fe4e566695ed"), "rtype"); expect (!isvalid("3024" "0200" "02202d5876262c288beb511d061691bf26777344b702b00f8fe28621fe4e566695ed"), "rlen=0"); expect (!isvalid("3044" "02208990e0584b2b238e1dfaad8d6ed69ecc1a4a13ac85fc0b31d0df395eb1ba6105" "02202d5876262c288beb511d061691bf26777344b702b00f8fe28621fe4e566695ed"), "r<0"); expect (!isvalid("3045" "0221005990e0584b2b238e1dfaad8d6ed69ecc1a4a13ac85fc0b31d0df395eb1ba6105" "02202d5876262c288beb511d061691bf26777344b702b00f8fe28621fe4e566695ed"), "rpadded"); expect (!isvalid("3044" "02205990e0584b2b238e1dfaad8d6ed69ecc1a4a13ac85fc0b31d0df395eb1ba6105012" "02d5876262c288beb511d061691bf26777344b702b00f8fe28621fe4e566695ed"), "stype"); expect (!isvalid("3024" "02205990e0584b2b238e1dfaad8d6ed69ecc1a4a13ac85fc0b31d0df395eb1ba6105" "0200"), "slen=0"); expect (!isvalid("3044" "02205990e0584b2b238e1dfaad8d6ed69ecc1a4a13ac85fc0b31d0df395eb1ba6105" "0220fd5876262c288beb511d061691bf26777344b702b00f8fe28621fe4e566695ed"), "s<0"); expect (!isvalid("3045" "02205990e0584b2b238e1dfaad8d6ed69ecc1a4a13ac85fc0b31d0df395eb1ba6105" "0221002d5876262c288beb511d061691bf26777344b702b00f8fe28621fe4e566695ed"), "spadded"); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { // Input checks if (nrhs < 3) { printUsg(); return; } #define S1 prhs[0] #define S2 prhs[1] if(!IS_REAL_2D(S1)) // check S1 mexErrMsgTxt("S1 must be a real 2D matrix."); if(!IS_REAL_2D(S2)) // check S2 mexErrMsgTxt("S2 must be a real 2D matrix."); // init float* S1r = (float*)mxGetPr(S1); float* S2r = (float*)mxGetPr(S2); short B = static_cast<short>(mxGetM(S1)); // num of bins short m = static_cast<short>(mxGetN(S1))-1; // length of Seq1 short n = static_cast<short>(mxGetN(S2))-1; // length of Seq2 // Get parameters unsigned int maxIter; short nRes; short L; string dist; bool isVerbose; getParams(nrhs, prhs, L, maxIter, nRes, dist, isVerbose); Rset R1, R2; // Rectangle sets for splitting float lb, ub; // lower and upper bounds State topS; // top state priority_queue<State, vector<State>, CompareState> Q; // priority queue priority_queue<State, vector<State>, CompareState> Qtmp; // priority queue if (dist.compare("l1")!=0 && dist.compare("l2")!=0 && dist.compare("X2")!=0 && dist.compare("int")!=0) { mexPrintf("!!! We do not support \"%s\" distance. Please read the usage carefully!\n",dist.c_str()); mexPrintf("!!! Please select from these distance options: [\"l1\",\"l2\",\"X2\",\"int\"]\n"); return; } // Init output structure int dimOut1[2] = {1,nRes}; int numFields1 = 3; const char* fieldNames1[] = { "lo", "hi", "lb" }; plhs[0] = mxCreateStructArray(2, dimOut1, numFields1, fieldNames1); // creates fields int dimOut2[2] = {1,nRes}; int numFields2 = 1; const char* fieldNames2[] = { "nIter" }; plhs[1] = mxCreateStructArray(2, dimOut2, numFields2, fieldNames2); // creates fields // Main loop below mexPrintf("===============================================\n"); mexPrintf("+ Running TCD w/ %s distance\n", dist.c_str()); mexPrintf("===============================================\n"); for (short iRes=0; iRes<nRes; iRes++) { // init unsigned int nIter = 0; // counter for #iteration bool isConv = false; // flag for convergence Rset Rout = { {0,0,0,0}, {0,0,0,0}, false }; // Update Q Rset R; if (iRes == 0) { Rset R0 = { {1,1,1,1}, {m,m,n,n}, true }; // init R with everything R = R0; } else { Rout = topS.R; mexPrintf("+ Updating Q (size=%d -> ", Q.size()); // Clean Qtmp while (!Qtmp.empty()) Qtmp.pop(); // Copy Q into Qtmp and clean Q while(!Q.empty()) { Qtmp.push(Q.top()); Q.pop(); } // Being to update Q State tmpS; while(!Qtmp.empty()) { tmpS = Qtmp.top(); Qtmp.pop(); // Update R into R1 and R2 Rset R1, R2; updateR(topS.R, tmpS.R, m, n, R1, R2); // Push {bound(R1), R1} to Q getBounds(S1r, S2r, B, R1, lb, ub, dist); if (R1.isValid()) { State St1 = {lb, R1}; Q.push(St1); } // Push {bound(R2), R2} to Q getBounds(S1r, S2r, B, R2, lb, ub, dist); if (R2.isValid()) { State St2 = {lb, R2}; Q.push(St2); } } mexPrintf("%d)\n",Q.size()); // Get topS topS = Q.top(); R = topS.R; Q.pop(); } while (!isConv) { nIter++; // Split rect set into R1 and R2 split(R, R1, R2); // Push R1 into queue if valid if (isvalid(R1, L)) { getBounds(S1r, S2r, B, R1, lb, ub, dist); State S = {lb, R1}; Q.push(S); } // Push R2 into queue if valid if (isvalid(R2, L)) { getBounds(S1r, S2r, B, R2, lb, ub, dist); State S = {lb, R2}; Q.push(S); } // Update R by top state topS = Q.top(); R = topS.R; Q.pop(); if (isOverlap(Rout, R)) { mexPrintf("Rout: "); Rout.disp(); mexPrintf("R: "); R.disp(); return; } // Check stopping criterion if (nIter % 100 == 0 && isVerbose) { mexPrintf(" # Iter%4d: ",nIter); topS.disp(); } if (nIter >= maxIter) { mexPrintf(" # MaxIter%d reached: ", maxIter); topS.disp(); isConv = true; } if (isUniqR(R)) { mexPrintf(" # Iter%4d: ",nIter); topS.disp(); isConv = true; } } // end of main loop // Assign output structure setField<short>(&plhs[0], iRes, "lo", 4, mxINT16_CLASS, topS.R.lo); // set lo setField<short>(&plhs[0], iRes, "hi", 4, mxINT16_CLASS, topS.R.hi); // set hi setField<float>(&plhs[0], iRes, "lb", 1, mxSINGLE_CLASS, &topS.bound); // set lb setField<unsigned int>(&plhs[1], iRes, "nIter", 1, mxUINT16_CLASS, &nIter); // set info.nIter } // end of iRes return; }
void testApp::compute_raycast(const ofMatrix4x4 &tMatrix) { ofVec3f LightPosition(0,0,1000); cv::Mat rayimage(KINECT_HEIGHT,KINECT_WIDTH,CV_8UC1); float tStep = SIZE_TRIDE*0.8; ofVec3f startPosition = ofVec3f(-2,-2,0.5); int i=0,j=0; int num=0; int nnum =0; for(j=0;j<480;j++) { uchar *ptr = rayimage.ptr<uchar>(j); for(i=0;i<640;i++) { ptr[i] = 255; num = j*KINECT_WIDTH+i; pointsmap_final[num] = ofVec3f(0,0,0); normalmap_final[num] = ofVec3f(0,0,0); ofVec3f rayChange =nmmul(invKcam,ofVec3f(i,j,1)); rayChange = tMatrix * rayChange; ofVec3f rayOne = 0.5*rayChange - startPosition; ofVec3f rayTwo = 1.0*rayChange - startPosition; ofVec3f rayFirst = getTheGlobalPostion(rayOne); ofVec3f rayEnd = getTheGlobalPostion(rayTwo); ofVec3f rayDirct = rayTwo - rayOne;//rayEnd - rayFirst; rayDirct = rayDirct.normalize(); rayDirct.x = (rayDirct.x == 0.f) ? 1e-15 : rayDirct.x; rayDirct.y = (rayDirct.y == 0.f) ? 1e-15 : rayDirct.y; rayDirct.z = (rayDirct.z == 0.f) ? 1e-15 : rayDirct.z; float pretsdf = getTsdfData((int)rayFirst.x,(int)rayFirst.y,(int)rayFirst.z); float nowtsdf ; float turr = 0; float maxtime = getmaxtime(rayDirct,rayOne); ofVec3f rayLast = rayOne + rayDirct*maxtime; ofVec3f gLast = getTheGlobalPostion(rayLast); ofVec3f rayPre = rayOne; while(turr<maxtime) { ofVec3f rayNext = rayPre + rayDirct*tStep; ofVec3f gnum = getTheGlobalPostion(rayNext); if(!isvalid(gnum)) { break; } nowtsdf = getTsdfData((int)gnum.x,(int)gnum.y,(int)gnum.z); if(pretsdf>0&&nowtsdf<0)//&&!(pretsdf==1&&nowtsdf==-1)) { float Ftdt = triLinary(rayNext); if(isnan(Ftdt)) break; float Ft = triLinary(rayPre); if(isnan(Ft)) break; float realt = turr - (tStep*Ft/(Ftdt-Ft)); ofVec3f rayzero = rayPre + rayDirct*(realt-turr); pointsmap_final[num] = (rayzero + startPosition);//*100;// 显示用 //cout<<Ftdt<<" "<<Ft<<endl; ///计算法向//// ofVec3f pregnum = getTheGlobalPostion(rayzero); if(pregnum.x>1&&pregnum.y>1&&pregnum.z>1&&pregnum.x<TSDF_SIZE-2&&pregnum.y<TSDF_SIZE-2&&pregnum.z<TSDF_SIZE-2) { ofVec3f t; t = rayzero; t.x -= SIZE_TRIDE; float Fx1 = triLinary(t); t = rayzero; t.x += SIZE_TRIDE; float Fx2 = triLinary(t); float nx = (Fx2-Fx1);///(SIZE_TRIDE*2); t = rayzero; t.y -= SIZE_TRIDE; float Fy1 = triLinary(t); t = rayzero; t.y += SIZE_TRIDE; float Fy2 = triLinary(t); float ny = (Fy2-Fy1);///(SIZE_TRIDE*2); t = rayzero; t.z -= SIZE_TRIDE; float Fz1 = triLinary(t); t = rayzero; t.z += SIZE_TRIDE; float Fz2 = triLinary(t); float nz =(Fz2-Fz1);////(SIZE_TRIDE*2); ofVec3f n(nx,ny,nz); n = n.normalize(); normalmap_final[num] = n; nnum++; // 生成图像 ofVec3f pp = LightPosition - pointsmap_final[num]; pp = pp.normalize(); float r = fabs(pp.dot(n)); int br = (int)(r*205)+50; br = max((int)0,min(br,255)); ptr[i] = br; } //num++; break; } else if(pretsdf<0&&nowtsdf>0) break; else { pretsdf = nowtsdf; rayPre = rayNext; turr += tStep; } }// while() //}// if(Last<0) }// for(i) }// for(j) finalPointNum = num; //std::cout<<num<<" "<<nnum<<endl; cv::imshow("ray",rayimage); }