kexAngle kexAngle::Diff(kexAngle &angle) { float an; kexAngle out; Clamp180(); angle.Clamp180(); #define DIFF(x) \ if(x <= angle.x) { \ an = angle.x + FULLCIRCLE; \ if(x - angle.x > an - x) { \ out.x = x - an; \ } \ else { \ out.x = x - angle.x; \ } \ } \ else { \ an = angle.x - FULLCIRCLE; \ if(angle.x - x <= x - an) { \ out.x = x - angle.x; \ } \ else { \ out.x = x - an; \ } \ } DIFF(yaw); DIFF(pitch); DIFF(roll); #undef DIFF return out; }
static void initfirst(allinfo *a, stype pb, stype wb) { partset *d; state *k; btype i; /* create table */ d = &(a->d); d->set1 = palloc(sizeof(state), MAXSTATES); d->setm = d->set1 + MAXSTATES - 1; d->size = 1; d->fset = d->set1; d->lset = d->set1; /* init first state */ k = d->fset; k->psum = pb; k->wsum = wb; k->vect = 0; /* init solution vector */ for (i = 0; i < MAXV; i++) d->vitem[i] = NULL; d->vno = MAXV-1; /* init full solution */ a->fullsol = FALSE; a->ffull = palloc(DIFF(a->fitem,a->litem), sizeof(item)); a->lfull = a->ffull + DIFF(a->fitem,a->litem); }
// Imperfect but quick and dirty line of sight check // Only works if the target point is at most two spaces // away in any direction bool LineOfSight(int x, int y, int z) { if(levelmap[x][y][z].flag & SITEBLOCK_KNOWN) return true; int x1, x2; int y1, y2; if(DIFF(x, locx) == 1) { x1 = locx; x2 = x; } else x1 = x2 = (x + locx) / 2; if(DIFF(y, locy) == 1) { y1 = locy; y2 = y; } else y1 = y2 = (y + locy) / 2; // Check for obstructions if(levelmap[x1][y2][z].flag & (SITEBLOCK_BLOCK | SITEBLOCK_DOOR | SITEBLOCK_EXIT)) { if(levelmap[x2][y1][z].flag & (SITEBLOCK_BLOCK | SITEBLOCK_DOOR | SITEBLOCK_EXIT)) { return 0; // Blocked on some axis } } return 1; }
static void surrelax(allinfo *a) { register item *i, *j, *m; item *f, *l, *b; ntype n, card1, card2, b1; stype u, minsur, maxsur, wsum; itype minw, maxp, maxw; long t1, t2; /* copy table */ give_time(&t1); relaxations++; n = DIFF(a->fitem, a->litem); f = palloc(n, sizeof(item)); l = f + n - 1; minw = a->fitem->w; maxp = maxw = wsum = 0; for (j = f, i = a->fitem, m = l+1; j != m; i++, j++) { *j = *i; wsum += i->w; if (i->w < minw) minw = i->w; if (i->w > maxw) maxw = i->w; if (i->p > maxp) maxp = i->p; } /* find cardinality */ b = a->b; b1 = DIFF(a->fitem, b-1); card1 = minweights(f, l, a->c) - f; /* sum_{j=1}^{n} x_{j} \leq card1 */ card2 = maxprofits(f, l, a->z) - f+1; /* sum_{j=1}^{n} x_{j} \geq card2 */ /* delimiters on sur.multipliers */ maxsur = maxw; /* should ideally be: maxp*maxp, but may cause overflow */ minsur = -maxw; /* should ideally be: -maxp*maxw, but may cause overflow */ /* choose strategy */ u = 0; for (;;) { if (card2 == b1+1) { solvesur(a, f, l, minsur, 0, b1+1, &u); /* min card constr */ if (u < a->z) u = a->z; /* since bound for IMPROVED solution */ break; } if (card1 == b1 ) { solvesur(a, f, l, 0, maxsur, b1, &u); /* max card constr */ break; } if (card1 == b1+1) { /* dichothomy: card <= b1 or card >= b1+1 */ solvesur(a, f, l, minsur, 0, b1+1, &u); solvesur(a, f, l, 0, maxsur, b1, &u); break; } if (card2 == b1 ) { /* dichothomy: card <= b1 or card >= b1+1 */ solvesur(a, f, l, 0, maxsur, b1, &u); solvesur(a, f, l, minsur, 0, b1+1, &u); break; } u = a->dantzig; break; } if (u < a->ub) a->ub = u; pfree(f); give_time(&t2); reltime = t2 - t1; }
int conhdr_compare(struct tuple *a, struct tuple *b) { DIFF(a->ip_src, b->ip_src); DIFF(a->ip_dst, b->ip_dst); DIFF(a->sport, b->sport); DIFF(a->dport, b->dport); return (0); }
int getmntany(FILE *fp, struct mnttab *mgetp, struct mnttab *mrefp) { int ret; while ( ((ret = _sol_getmntent(fp, mgetp)) == 0) && ( DIFF(mnt_special) || DIFF(mnt_mountp) || DIFF(mnt_fstype) || DIFF(mnt_mntopts))) { } return (ret); }
// Round pixel_intensity to nearest web safe color unsigned char recolor_for_web( unsigned char pixel_intensity ) { int smallest_diff = DIFF( pixel_intensity, WEB_COLORS[0] ) ; int i ; for( i = 1 ; i < NUMBER_OF_WEB_COLORS ; i++ ) { if( smallest_diff < DIFF( pixel_intensity, WEB_COLORS[i] )) break ; else smallest_diff = DIFF( pixel_intensity, WEB_COLORS[i] ) ; } return WEB_COLORS[i-1] ; }
/**************************************************************************** ** *F FuncDIFF( <self>, <opL>, <opR> ) . . . . . . . . . . . . . . call 'DIFF' */ Obj FuncDIFF ( Obj self, Obj opL, Obj opR ) { return DIFF( opL, opR ); }
void SingleSignal::_calculate() { int filter_n = getParam<int>("filter_n"); double filter_p = getParam<double>("filter_p"); string kpart(getParam<string>("kpart")); Indicator ind = m_ind(KDATA_PART(m_kdata, kpart)); Indicator dev = STDEV(DIFF(ind), filter_n); size_t start = dev.discard(); if (start < 3) { return; } size_t total = dev.size(); for (size_t i = start; i < total; ++i) { double dama = ind[i] - ind[i-1]; double dama2 = ind[i] - ind[i-2]; double dama3 = ind[i] - ind[i-3]; double sdama = dev[i] * filter_p; if (dama > 0 && (dama > sdama || dama2 > sdama || dama3 > sdama)) { _addBuySignal(m_kdata[i].datetime); } else if (dama < 0 && (dama < sdama || dama2 < sdama || dama3 < sdama)) { _addSellSignal(m_kdata[i].datetime); } } }
int main(int argc, char *argv[]) { pthread_t tid[4]; struct timeval t1, t2; tbb::task_scheduler_init init(4); gettimeofday(&t1, NULL); int nr_gpus = get_gpu_device_count(); gettimeofday(&t2, NULL); printf("time on the first cuda call: %lf s\n", DIFF(t1, t2)); // nr_gpus = 1; init_device_streams(nr_gpus); //printf("Number of CUDA devices: %d\n", nr_gpus); if(nr_gpus < 1) { fprintf(stderr, "Error: at least one CUDA device is required to run this program\n"); exit(1); } gettimeofday(&t1, NULL); for(int i = 0; i < 4; i++) { if(pthread_create(&tid[i], NULL, thread_pointers[i], (void *)&nr_gpus)) { fprintf(stderr, "failed to create thread %d\n", i); exit(1); } } for(int i = 0; i < 4; i++) { pthread_join(tid[i], NULL); } gettimeofday(&t2, NULL); printf("Time taken in pipeline: %lf s\n", DIFF(t1, t2)); fini_device_streams(); return 0; }
// Warnning: if count != 3, pls rework it static int pick_result(const u16* pData,u8 count,u16* result) { u8 i; u16 diff[3],diff_smallest; #if (TOUCH_SAMPLE_NUM!=3) //#error pls rework it #endif DIFF(pData[1],pData[0],diff[0]); DIFF(pData[2],pData[0],diff[1]); DIFF(pData[2],pData[1],diff[2]); i = 0; if(diff[1]<diff[0]) {i++;diff[0]=diff[1];} if(diff[2]<diff[0]) i+=2; if(i==0) {//Select diff[0] *result = (pData[0]+pData[1])/2; diff_smallest = diff[0]; }else if(i==1) {//Select diff[1] *result = (pData[0]+pData[2])/2; diff_smallest = diff[1]; }else { //Select diff[2] *result = (pData[1]+pData[2])/2; diff_smallest = diff[2]; } #ifdef LT_TOUCH_ENABLE_FILTER { int sample_offset = lt_touch->sample_offset; if(sample_offset&&(diff_smallest>sample_offset)){ ts_dbg("Find invalid sample,diff[0x%x,0x%x]\n",diff_smallest,sample_offset); return -EINVAL; } } #endif return 0; }
static int calibrate_samples(void *xbuf, void *ybuf, void *pbuf, int count) { unsigned long *xp = (unsigned long *)xbuf; unsigned long *yp = (unsigned long *)ybuf; unsigned long *pp = (unsigned long *)pbuf; unsigned long x_cal = 0, y_cal = 0, p_cal = 0; int i; int valid = 1; /* calculate the average of the rest */ for (i = 0; i < count; i++) { x_cal += xp[i]; y_cal += yp[i]; p_cal += pp[i]; } x_cal /= count; y_cal /= count; p_cal /= count; if (first_time) { first_time = 0; last_x = x_cal; last_y = y_cal; last_p = p_cal; } else { if ((DIFF(x_cal, last_x) > 50) || (DIFF(y_cal, last_y) > 50)) valid = 0; else valid = 1; } *xp = last_x = x_cal; *yp = last_y = y_cal; *pp = last_p = p_cal; return valid; }
/**************************************************************************** ** *F DiffVecFFEFFE(<vecL>,<elmR>) difference of a vector and a fin field elm ** ** 'DiffVecFFEFFE' returns the difference of the vector <vecL> and the ** finite field element <elmR>. The difference is a list, where each ** element is the difference of <elmR> and the corresponding element of ** <vecL>. ** ** 'DiffVecFFEFFE' is an improved version of 'DiffListScl', which does not ** call 'DIFF'. */ Obj DiffVecFFEFFE ( Obj vecL, Obj elmR ) { Obj vecD; /* handle of the difference */ Obj * ptrD; /* pointer into the difference */ FFV valD; /* the value of a difference */ Obj * ptrL; /* pointer into the left operand */ FFV valL; /* the value of an element in vecL */ UInt len; /* length */ UInt i; /* loop variable */ FF fld; /* finite field */ FF * succ; /* successor table */ FFV valR; /* the value of elmR */ /* get the field and check that vecL and elmR have the same field */ fld = FLD_FFE(ELM_PLIST(vecL, 1)); if (FLD_FFE(elmR) != fld) { /* check the characteristic */ if (CHAR_FF(fld) == CHAR_FF(FLD_FFE(elmR))) return DiffListScl(vecL, elmR); elmR = ErrorReturnObj( "<vec>-<elm>: <elm> and <vec> must belong to the same finite field", 0L, 0L, "you can replace <elm> via 'return <elm>;'"); return DIFF(vecL, elmR); } /* make the result list */ len = LEN_PLIST(vecL); vecD = NEW_PLIST(IS_MUTABLE_OBJ(vecL) ? T_PLIST_FFE : T_PLIST_FFE + IMMUTABLE, len); SET_LEN_PLIST(vecD, len); /* to subtract we need the successor table */ succ = SUCC_FF(fld); /* loop over the elements and subtract */ valR = VAL_FFE(elmR); valR = NEG_FFV(valR, succ); ptrL = ADDR_OBJ(vecL); ptrD = ADDR_OBJ(vecD); for (i = 1; i <= len; i++) { valL = VAL_FFE(ptrL[i]); valD = SUM_FFV(valL, valR, succ); ptrD[i] = NEW_FFE(fld, valD); } /* return the result */ return vecD; }
static void multiply(allinfo *a, item *h, int side) { register state *i, *j, *k, *m; register itype p, w; register btype mask0, mask1; state *r1, *rm; partset *d; d = &a->d; if (d->size == 0) return; if (side == RIGHT) { p = h->p; w = h->w; } else { p = -h->p; w = -h->w; } /* keep track on solution vector */ d->vno++; if (d->vno == MAXV) d->vno = 0; mask1 = ((btype) 1 << d->vno); mask0 = ~mask1; d->vitem[d->vno] = h; /* initialize limits */ r1 = d->fset; rm = d->lset; k = d->set1; m = rm + 1; k->psum = -1; k->wsum = r1->wsum + h->w + 1; m->wsum = rm->wsum + h->w + 1; for (i = r1, j = r1; (i != m) || (j != m); ) { if (i->wsum <= j->wsum + w) { if (i->psum > k->psum) { if (i->wsum > k->wsum) { k++; if ((k == i) || (k == j)) break; } k->psum = i->psum; k->wsum = i->wsum; k->vect = i->vect & mask0; } i++; } else { if (j->psum + p > k->psum) { if (j->wsum + w > k->wsum) { k++; if ((k == i) || (k == j)) break; } k->psum = j->psum + p; k->wsum = j->wsum + w; k->vect = j->vect | mask1; } j++; } } if ((k == i) || (k == j)) error("multiply, no space"); d->fset = d->set1; d->lset = k; d->size = DIFF(d->fset,d->lset); if (d->size > maxstates) maxstates = d->size; a->coresize++; if (a->master) coresize++; }
static int lt_micco_touch_read(struct lt_touch_data *p_lt, u16 *x, u16 *y, int *pen_state) { int ret = -EIO; u8 i = 0; u16 t_x[2], t_y[2], diff[2]; int intervalUs = p_lt->intervalUs_sample; micco_tsi_enable_tsi(1); /* Enable the auto measure of the TSI. */ micco_tsi_readxy(&t_x[0], &t_x[0], *pen_state); /* readout old data */ SAMPLE_UDELAY(intervalUs); micco_tsi_readxy(&t_x[0], &t_x[0], *pen_state); /* readout old data */ for(i=0; i<TOUCH_SAMPLE_RETRY; i++) { SAMPLE_UDELAY(intervalUs); micco_tsi_readxy(&(t_x[0]), &(t_y[0]), *pen_state); ts_raw_dbg("Raw ts data[0x%x,0x%x]\n", t_x[0], t_y[0]); SAMPLE_UDELAY(intervalUs); micco_tsi_readxy(&(t_x[1]), &(t_y[1]), *pen_state); ts_raw_dbg("Raw ts data[0x%x,0x%x]\n", t_x[1], t_y[1]); DIFF(t_x[0], t_x[1], diff[0]); DIFF(t_y[0], t_y[1], diff[1]); if (diff[0]<6 && diff[1]<6) { //get it ret = 0; *x = (t_x[0]+t_x[1])/2; *y = (t_y[0]+t_y[1])/2; break; } } micco_tsi_enable_tsi(0); return ret; }
static void reduceset(allinfo *a) { register state *i, *m, *k; register stype c, z; register prod p, w; state *v, *r1, *rm; boolean atstart, atend; if (a->d.size == 0) return; /* find break point and improve solution */ r1 = a->d.fset; rm = a->d.lset; v = findvect(a->c, r1, rm); if (v == NULL) v = r1 - 1; else if (v->psum > a->z) improvesol(a, v); /* expand core, and choose ps, ws, pt, wt */ expandcore(a, &atstart, &atend); /* now do the reduction */ /* NB! This is the most efficient implementation, no product q is needed */ c = a->c; z = a->z + 1; k = a->d.setm; if (!atstart) { p = a->ps; w = a->ws; for (i = rm, m = v; i != m; i--) { if (DET(i->psum-z, i->wsum-c, p, w) >= 0) { k--; *k = *i; } } } if (!atend) { p = a->pt; w = a->wt; for (i = v, m = r1 - 1; i != m; i--) { if (DET(i->psum-z, i->wsum-c, p, w) >= 0) { k--; *k = *i; } } } /* save limit */ a->d.fset = k; a->d.lset = a->d.setm - 1; /* reserve one record for multiplication */ a->d.size = DIFF(a->d.fset, a->d.lset); }
static int calibrate_samples(void *xbuf, void *ybuf, void *pbuf, int count) { unsigned long usd0,usd1,usd2; int xMaxError = XM,yMaxError = YM; int x_valid = 0,y_valid = 0,valid = 0; unsigned long x_cal = 0, y_cal = 0, p_cal = 0; unsigned long *xp = (unsigned long *)xbuf; unsigned long *yp = (unsigned long *)ybuf; unsigned long *pp = (unsigned long *)pbuf; usd0 = (xp[0] > xp[1]) ? (xp[0] - xp[1]) : (xp[1] - xp[0]); usd1 = (xp[1] > xp[2]) ? (xp[1] - xp[2]) : (xp[2] - xp[1]); usd2 = (xp[2] > xp[0]) ? (xp[2] - xp[0]) : (xp[0] - xp[2]); if ( usd0 < usd1) x_cal = xp[0] + ((usd2 < usd0) ? xp[2] : xp[1]); else x_cal= xp[2] + ((usd2 < usd1) ? xp[0] : xp[1]); x_cal >>= 1; if ( (usd0 < xMaxError) && (usd1 < xMaxError) && (usd2 < xMaxError) ) x_valid = 1; usd0 = (yp[0] > yp[1]) ? (yp[0] - yp[1]) : (yp[1] - yp[0]); usd1 = (yp[1] > yp[2]) ? (yp[1] - yp[2]) : (yp[2] - yp[1]); usd2 = (yp[2] > yp[0]) ? (yp[2] - yp[0]) : (yp[0] - yp[2]); if ( usd0 < usd1) y_cal = yp[0] + ((usd2 < usd0) ? yp[2] : yp[1]); else y_cal = yp[2] + ((usd2 < usd1) ? yp[0] : yp[1]); y_cal >>= 1; if ( (usd0 < yMaxError) && (usd1 < yMaxError) && (usd2 < yMaxError) ) y_valid = 1; if( x_valid && y_valid) valid = 1; usd0 = (pp[0] > pp[1]) ? (pp[0] - pp[1]) : (pp[1] - pp[0]); usd1 = (pp[1] > pp[2]) ? (pp[1] - pp[2]) : (pp[2] - pp[1]); usd2 = (pp[2] > pp[0]) ? (pp[2] - pp[0]) : (pp[0] - pp[2]); if ( usd0 < usd1) p_cal = pp[0] + ((usd2 < usd0) ? pp[2] : pp[1]); else p_cal= pp[2] + ((usd2 < usd1) ? pp[0] : pp[1]); p_cal >>= 1; if (first_time) { first_time = 0; last_x = x_cal; last_y = y_cal; last_p = p_cal; } else{ if ((DIFF(x_cal, last_x) > 50) || (DIFF(y_cal, last_y) > 50)) valid = 0; else valid = 1; } *xp = last_x = x_cal; *yp = last_y = y_cal; *pp = last_p = p_cal; return valid; }
bool OscilGen::needPrepare(void) { bool outdated = false; //Check function parameters if((oldbasepar != Pbasefuncpar) || (oldbasefunc != Pcurrentbasefunc) || DIFF(hmagtype) || DIFF(waveshaping) || DIFF(waveshapingfunction)) outdated = true; //Check filter parameters if(oldfilterpars != Pfiltertype * 256 + Pfilterpar1 + Pfilterpar2 * 65536 + Pfilterbeforews * 16777216) { outdated = true; oldfilterpars = Pfiltertype * 256 + Pfilterpar1 + Pfilterpar2 * 65536 + Pfilterbeforews * 16777216; } //Check spectrum adjustments if(oldsapars != Psatype * 256 + Psapar) { outdated = true; oldsapars = Psatype * 256 + Psapar; } //Check function modulation if(DIFF(basefuncmodulation) || DIFF(basefuncmodulationpar1) || DIFF(basefuncmodulationpar2) || DIFF(basefuncmodulationpar3)) outdated = true; //Check overall modulation if(DIFF(modulation) || DIFF(modulationpar1) || DIFF(modulationpar2) || DIFF(modulationpar3)) outdated = true; //Check harmonic shifts if(oldharmonicshift != Pharmonicshift + Pharmonicshiftfirst * 256) outdated = true; return outdated == true || oscilprepared == false; }
/**************************************************************************** ** *F DiffVecFFEVecFFE(<vecL>,<vecR>) . . . . . . . . difference of two vectors ** ** 'DiffVecFFEVecFFE' returns the difference of the two vectors <vecL> and ** <vecR>. The difference is a new list, where each element is the ** difference of the corresponding elements of <vecL> and <vecR>. ** ** 'DiffVecFFEVecFFE' is an improved version of 'DiffListList', which does ** not call 'DIFF'. */ Obj DiffVecFFEVecFFE ( Obj vecL, Obj vecR ) { Obj vecD; /* handle of the difference */ Obj * ptrD; /* pointer into the difference */ FFV valD; /* one element of difference list */ Obj * ptrL; /* pointer into the left operand */ FFV valL; /* one element of left operand */ Obj * ptrR; /* pointer into the right operand */ FFV valR; /* one element of right operand */ UInt len, lenL, lenR; /* length */ UInt lenmin; UInt i; /* loop variable */ FF fld; /* finite field */ FF * succ; /* successor table */ /* check the lengths */ lenL = LEN_PLIST(vecL); lenR = LEN_PLIST(vecR); if (lenR > lenL) { len = lenR; lenmin = lenL; } else { len = lenL; lenmin = lenR; } /* check the fields */ fld = FLD_FFE(ELM_PLIST(vecL, 1)); if (FLD_FFE(ELM_PLIST(vecR, 1)) != fld) { /* check the characteristic */ if (CHAR_FF(fld) == CHAR_FF(FLD_FFE(ELM_PLIST(vecR, 1)))) return DiffListList(vecL, vecR); vecR = ErrorReturnObj( "Vector -: vectors have different fields", 0L, 0L, "you can replace vector <right> via 'return <right>;'"); return DIFF(vecL, vecR); } /* make the result list */ vecD = NEW_PLIST((IS_MUTABLE_OBJ(vecL) || IS_MUTABLE_OBJ(vecR)) ? T_PLIST_FFE : T_PLIST_FFE + IMMUTABLE, len); SET_LEN_PLIST(vecD, len); /* to subtract we need the successor table */ succ = SUCC_FF(fld); /* loop over the elements and subtract */ ptrL = ADDR_OBJ(vecL); ptrR = ADDR_OBJ(vecR); ptrD = ADDR_OBJ(vecD); for (i = 1; i <= lenmin; i++) { valL = VAL_FFE(ptrL[i]); valR = VAL_FFE(ptrR[i]); valR = NEG_FFV(valR, succ); valD = SUM_FFV(valL, valR, succ); ptrD[i] = NEW_FFE(fld, valD); } if (lenL < lenR) for (; i <= len; i++) { valR = VAL_FFE(ptrR[i]); valD = NEG_FFV(valR, succ); ptrD[i] = NEW_FFE(fld, valD); } else for (; i <= len; i++) ptrD[i] = ptrL[i]; /* return the result */ return vecD; }
Obj GAP_DIFF(Obj a, Obj b) { return DIFF(a, b); }
static int lt_touch_report_data(struct lt_touch_data *p_lt,u16 x,u16 y) { int rx, ry; #ifdef LT_TOUCH_ENABLE_FILTER u16 diff[2]; int step = p_lt->max_step; if (step && (p_lt->last_x || p_lt->last_y)) {/* filter x,y */ if (p_lt->last_x > x) { if ((p_lt->last_x-x)>step) { ts_dbg("Find sample x step[0x%x, 0x%x]\n",x, p_lt->last_x); x = p_lt->last_x - step; } } else { if ((x-p_lt->last_x)>step) { ts_dbg("Find sample x step[0x%x, 0x%x]\n",x, p_lt->last_x); x = p_lt->last_x + step; } } if (p_lt->last_y > y) { if ((p_lt->last_y-y)>step) { ts_dbg("Find sample y step[0x%x, 0x%x]\n",y, p_lt->last_y); y = p_lt->last_y - step; } } else { if ((y-p_lt->last_y)>step) { ts_dbg("Find sample y step[0x%x, 0x%x]\n",y, p_lt->last_y); y = p_lt->last_y + step; } } } #endif #ifdef LT_TOUCH_ENABLE_STATISTIC p_lt->data_count++; #endif if (TSI_PEN_PRE_DOWN == p_lt->pen_state) { p_lt->pen_state = TSI_PEN_DOWN; ts_dbg("Touch pen down!\n"); #ifdef CONFIG_INPUT_ANDROID /* check inKeyEmu */ if (p_lt->keyemu.active && x>=p_lt->keyemu.x && x<=p_lt->keyemu.x+p_lt->keyemu.w && y>=p_lt->keyemu.y && y<=p_lt->keyemu.y+p_lt->keyemu.h) { ts_dbg("Touch pen down in keyEmu \n"); p_lt->inKeyEmu = 1; } else p_lt->inKeyEmu = 0; #endif } if (p_lt->last_x || p_lt->last_y) { DIFF(p_lt->last_x, x, diff[0]); DIFF(p_lt->last_y, y, diff[1]); if ((diff[0]>5) || (diff[1]>5)) { p_lt->move_detect++; } else p_lt->move_detect = 0; } #if 0 if (p_lt->last_x || p_lt->last_y) { /* report last data to discard the unstable pen-up sample */ rx = p_lt->last_x; ry = p_lt->last_y; } else { rx = x; ry = y; } #else rx = x; ry = y; #endif if (p_lt->move_detect==2) _lt_touch_report_data(p_lt, p_lt->last_x, p_lt->last_y); p_lt->last_x = x; p_lt->last_y = y; /* save to compare */ if (p_lt->move_detect==1) /* report at next move detect */ return 0; _lt_touch_report_data(p_lt, rx, ry); return 0; }
/* run md simulation */ static int run(void) { int t, i, id, etot = 0, eacc = 0; double r[DIM], r1[DIM], ep, ep1, dep; double x0 = 0, y0 = 0, x1 = 0, y1 = 0, dx, dy, alf = 0; ad2_t *al; hist2_t *hs; al = ad2_open(-M_PI, M_PI, M_PI/9.999, -M_PI, M_PI, M_PI/9.999, 0.001, 1.0, 0.0, 0.0); hs = hs2_opensqr1(-M_PI, M_PI, M_PI/9.999); for (i = 0; i < DIM; i++) { r[i] = (rnd0() * 2 - 1) * M_PI; } ep = force(r); id = ad2_getid(al, r[0], r[1]); for (t = 1; t <= nsteps; t++) { for (i = 0; i < DIM; i++) { r1[i] = WRAP( r[i] + (rnd0() - .5) * 1.0 ); } ep1 = force(r1); dep = ep1 - ep; etot++; if (dep <= 0 || rnd0() < exp(-dep)) { eacc++; for (i = 0; i < DIM; i++) { r[i] = r1[i]; } ep = ep1; } hs2_add1ez(hs, r[0], r[1], 0); /* register */ if (t % seglen == 0) { static const double fcmax = 1000000000.0; x1 = r[0]; y1 = r[1]; dx = DIFF(x1, x0); dy = DIFF(y1, y0); ad2_add(al, id, dx, dy); /* ad2_getcorr(al, id, &delx, &dely); dx += delx; dy += dely; */ alf = 0.1; al->fx[id] = dblconfine(al->fx[id] + dx * alf, -fcmax, fcmax); al->fy[id] = dblconfine(al->fy[id] + dy * alf, -fcmax, fcmax); /* set the new start point */ x0 = x1; y0 = y1; id = ad2_getid(al, x0, y0); if (t % nevery == 0) { printf("t %d, x %g, y %g\n", t, r[0], r[1]); } if (t % nreport == 0) { ad2_save(al, fnout); } } } printf("acc %g\n", 1.0*eacc/etot); ad2_close(al); hs2_save(hs, "xy.his", 0); return 0; }
/* * This is the handler to receive message for this test. It is used to * control and verify the behavior of the message transmitted by the * transaction. */ static pj_bool_t msg_receiver_on_rx_request(pjsip_rx_data *rdata) { if (pj_strcmp2(&rdata->msg_info.via->branch_param, TEST1_BRANCH_ID) == 0) { /* * The TEST1_BRANCH_ID test performs the verifications for transaction * retransmission mechanism. It will not answer the incoming request * with any response. */ pjsip_msg *msg = rdata->msg_info.msg; PJ_LOG(4,(THIS_FILE, " received request")); /* Only wants to take INVITE or OPTIONS method. */ if (msg->line.req.method.id != PJSIP_INVITE_METHOD && msg->line.req.method.id != PJSIP_OPTIONS_METHOD) { PJ_LOG(3,(THIS_FILE, " error: received unexpected method %.*s", msg->line.req.method.name.slen, msg->line.req.method.name.ptr)); test_complete = -600; return PJ_TRUE; } if (recv_count == 0) { recv_count++; //pj_gettimeofday(&recv_last); recv_last = rdata->pkt_info.timestamp; } else { pj_time_val now; unsigned msec_expected, msec_elapsed; int max_received; //pj_gettimeofday(&now); now = rdata->pkt_info.timestamp; PJ_TIME_VAL_SUB(now, recv_last); msec_elapsed = now.sec*1000 + now.msec; ++recv_count; msec_expected = (1<<(recv_count-2))*PJSIP_T1_TIMEOUT; if (msg->line.req.method.id != PJSIP_INVITE_METHOD) { if (msec_expected > PJSIP_T2_TIMEOUT) msec_expected = PJSIP_T2_TIMEOUT; max_received = 11; } else { max_received = 7; } if (DIFF(msec_expected, msec_elapsed) > TEST1_ALLOWED_DIFF) { PJ_LOG(3,(THIS_FILE, " error: expecting retransmission no. %d in %d " "ms, received in %d ms", recv_count-1, msec_expected, msec_elapsed)); test_complete = -610; } if (recv_count > max_received) { PJ_LOG(3,(THIS_FILE, " error: too many messages (%d) received", recv_count)); test_complete = -620; } //pj_gettimeofday(&recv_last); recv_last = rdata->pkt_info.timestamp; } return PJ_TRUE; } else if (pj_strcmp2(&rdata->msg_info.via->branch_param, TEST4_BRANCH_ID) == 0) { /* * The TEST4_BRANCH_ID test simulates transport failure after several * retransmissions. */ recv_count++; if (recv_count == TEST4_RETRANSMIT_CNT) { /* Simulate transport failure. */ pjsip_loop_set_failure(loop, 2, NULL); } else if (recv_count > TEST4_RETRANSMIT_CNT) { PJ_LOG(3,(THIS_FILE," error: not expecting %d-th packet!", recv_count)); test_complete = -631; } return PJ_TRUE; } else if (pj_strcmp2(&rdata->msg_info.via->branch_param, TEST5_BRANCH_ID) == 0) { /* * The TEST5_BRANCH_ID test simulates user terminating the transaction * after several retransmissions. */ recv_count++; if (recv_count == TEST5_RETRANSMIT_CNT+1) { pj_str_t key; pjsip_transaction *tsx; pjsip_tsx_create_key( rdata->tp_info.pool, &key, PJSIP_ROLE_UAC, &rdata->msg_info.msg->line.req.method, rdata); tsx = pjsip_tsx_layer_find_tsx(&key, PJ_TRUE); if (tsx) { pjsip_tsx_terminate(tsx, PJSIP_SC_REQUEST_TERMINATED); pj_mutex_unlock(tsx->mutex); } else { PJ_LOG(3,(THIS_FILE, " error: uac transaction not found!")); test_complete = -633; } } else if (recv_count > TEST5_RETRANSMIT_CNT+1) { PJ_LOG(3,(THIS_FILE," error: not expecting %d-th packet!", recv_count)); test_complete = -634; } return PJ_TRUE; } else if (pj_strcmp2(&rdata->msg_info.via->branch_param, TEST6_BRANCH_ID) == 0) { /* * The TEST6_BRANCH_ID test successfull non-INVITE transaction. */ pj_status_t status; recv_count++; if (recv_count > 1) { PJ_LOG(3,(THIS_FILE," error: not expecting %d-th packet!", recv_count)); test_complete = -635; } status = pjsip_endpt_respond_stateless(endpt, rdata, 202, NULL, NULL, NULL); if (status != PJ_SUCCESS) { app_perror(" error: unable to send response", status); test_complete = -636; } return PJ_TRUE; } else if (pj_strcmp2(&rdata->msg_info.via->branch_param, TEST7_BRANCH_ID) == 0) { /* * The TEST7_BRANCH_ID test successfull non-INVITE transaction * with provisional response. */ pj_status_t status; pjsip_response_addr res_addr; struct response *r; pjsip_tx_data *tdata; pj_time_val delay = { 2, 0 }; recv_count++; if (recv_count > 1) { PJ_LOG(3,(THIS_FILE," error: not expecting %d-th packet!", recv_count)); test_complete = -640; return PJ_TRUE; } /* Respond with provisional response */ status = pjsip_endpt_create_response(endpt, rdata, 100, NULL, &tdata); pj_assert(status == PJ_SUCCESS); status = pjsip_get_response_addr(tdata->pool, rdata, &res_addr); pj_assert(status == PJ_SUCCESS); status = pjsip_endpt_send_response(endpt, &res_addr, tdata, NULL, NULL); pj_assert(status == PJ_SUCCESS); /* Create the final response. */ status = pjsip_endpt_create_response(endpt, rdata, 202, NULL, &tdata); pj_assert(status == PJ_SUCCESS); /* Schedule sending final response in couple of of secs. */ r = pj_pool_alloc(tdata->pool, sizeof(*r)); r->res_addr = res_addr; r->tdata = tdata; if (r->res_addr.transport) pjsip_transport_add_ref(r->res_addr.transport); timer.entry.cb = &send_response_callback; timer.entry.user_data = r; pjsip_endpt_schedule_timer(endpt, &timer.entry, &delay); return PJ_TRUE; } else if (pj_strcmp2(&rdata->msg_info.via->branch_param, TEST8_BRANCH_ID) == 0) { /* * The TEST8_BRANCH_ID test failed INVITE transaction. */ pjsip_method *method; pj_status_t status; method = &rdata->msg_info.msg->line.req.method; recv_count++; if (method->id == PJSIP_INVITE_METHOD) { if (recv_count > 1) { PJ_LOG(3,(THIS_FILE," error: not expecting %d-th packet!", recv_count)); test_complete = -635; } status = pjsip_endpt_respond_stateless(endpt, rdata, 301, NULL, NULL, NULL); if (status != PJ_SUCCESS) { app_perror(" error: unable to send response", status); test_complete = -636; } } else if (method->id == PJSIP_ACK_METHOD) { if (recv_count == 2) { pj_str_t key; pj_time_val delay = { 5, 0 }; /* Schedule timer to destroy transaction after 5 seconds. * This is to make sure that transaction does not * retransmit ACK. */ pjsip_tsx_create_key(rdata->tp_info.pool, &key, PJSIP_ROLE_UAC, &pjsip_invite_method, rdata); pj_strcpy(&timer.tsx_key, &key); timer.entry.id = 301; timer.entry.cb = &terminate_tsx_callback; pjsip_endpt_schedule_timer(endpt, &timer.entry, &delay); } if (recv_count > 2) { PJ_LOG(3,(THIS_FILE," error: not expecting %d-th packet!", recv_count)); test_complete = -638; } } else { PJ_LOG(3,(THIS_FILE," error: not expecting %s", pjsip_rx_data_get_info(rdata))); test_complete = -639; } } else if (pj_strcmp2(&rdata->msg_info.via->branch_param, TEST9_BRANCH_ID) == 0) { /* * The TEST9_BRANCH_ID test failed INVITE transaction with * provisional response. */ pjsip_method *method; pj_status_t status; method = &rdata->msg_info.msg->line.req.method; recv_count++; if (method->id == PJSIP_INVITE_METHOD) { pjsip_response_addr res_addr; struct response *r; pjsip_tx_data *tdata; pj_time_val delay = { 2, 0 }; if (recv_count > 1) { PJ_LOG(3,(THIS_FILE," error: not expecting %d-th packet!", recv_count)); test_complete = -650; return PJ_TRUE; } /* Respond with provisional response */ status = pjsip_endpt_create_response(endpt, rdata, 100, NULL, &tdata); pj_assert(status == PJ_SUCCESS); status = pjsip_get_response_addr(tdata->pool, rdata, &res_addr); pj_assert(status == PJ_SUCCESS); status = pjsip_endpt_send_response(endpt, &res_addr, tdata, NULL, NULL); pj_assert(status == PJ_SUCCESS); /* Create the final response. */ status = pjsip_endpt_create_response(endpt, rdata, 302, NULL, &tdata); pj_assert(status == PJ_SUCCESS); /* Schedule sending final response in couple of of secs. */ r = pj_pool_alloc(tdata->pool, sizeof(*r)); r->res_addr = res_addr; r->tdata = tdata; if (r->res_addr.transport) pjsip_transport_add_ref(r->res_addr.transport); timer.entry.cb = &send_response_callback; timer.entry.user_data = r; pjsip_endpt_schedule_timer(endpt, &timer.entry, &delay); } else if (method->id == PJSIP_ACK_METHOD) { if (recv_count == 2) { pj_str_t key; pj_time_val delay = { 5, 0 }; /* Schedule timer to destroy transaction after 5 seconds. * This is to make sure that transaction does not * retransmit ACK. */ pjsip_tsx_create_key(rdata->tp_info.pool, &key, PJSIP_ROLE_UAC, &pjsip_invite_method, rdata); pj_strcpy(&timer.tsx_key, &key); timer.entry.id = 302; timer.entry.cb = &terminate_tsx_callback; pjsip_endpt_schedule_timer(endpt, &timer.entry, &delay); } if (recv_count > 2) { PJ_LOG(3,(THIS_FILE," error: not expecting %d-th packet!", recv_count)); test_complete = -638; } } else { PJ_LOG(3,(THIS_FILE," error: not expecting %s", pjsip_rx_data_get_info(rdata))); test_complete = -639; } return PJ_TRUE; } return PJ_FALSE; }
static CvStatus icvSegmFloodFill_Stage1(uchar* pImage, int step, uchar* pMask, int maskStep, CvSize /*roi*/, CvPoint seed, int* newVal, int d_lw, int d_up, CvConnectedComp* region, void* pStack) { uchar* img = pImage + step * seed.y; uchar* mask = pMask + maskStep * (seed.y + 1); unsigned Interval = (unsigned)(d_up + d_lw); Seg* stack = (Seg*)pStack; int StIn = 0; int i, L, R; int area = 0; int sum[] = { 0, 0, 0 }; int XMin, XMax, YMin = seed.y, YMax = seed.y; int val0[3]; L = R = seed.x; img = pImage + seed.y * step; mask = pMask + seed.y * maskStep; mask[L] = 1; val0[0] = img[seed.x*3]; val0[1] = img[seed.x*3 + 1]; val0[2] = img[seed.x*3 + 2]; while (DIFF(img + (R + 1) * 3, /*img + R*3*/val0) && !mask[R + 1]) { mask[++R] = 2; } while (DIFF(img + (L - 1) * 3, /*img + L*3*/val0) && !mask[L - 1]) { mask[--L] = 2; } XMax = R; XMin = L; PUSH(seed.y, L, R, R + 1, R, UP); while (StIn) { int k, YC, PL, PR, flag/*, curstep*/; POP(YC, L, R, PL, PR, flag); int data[][3] = { { -flag, L, R}, {flag, L, PL - 1}, {flag, PR + 1, R}}; if (XMax < R) { XMax = R; } if (XMin > L) { XMin = L; } if (YMax < YC) { YMax = YC; } if (YMin > YC) { YMin = YC; } for (k = 0; k < 3; k++) { flag = data[k][0]; /*curstep = flag * step;*/ img = pImage + (YC + flag) * step; mask = pMask + (YC + flag) * maskStep; int left = data[k][1]; int right = data[k][2]; for (i = left; i <= right; i++) { if (!mask[i] && DIFF(img + i * 3, /*img - curstep + i*3*/val0)) { int j = i; mask[i] = 2; while (!mask[j - 1] && DIFF(img + (j - 1) * 3, /*img + j*3*/val0)) { mask[--j] = 2; } while (!mask[i + 1] && (DIFF(img + (i + 1) * 3, /*img + i*3*/val0) || (DIFF(img + (i + 1) * 3, /*img + (i+1)*3 - curstep*/val0) && i < R))) { mask[++i] = 2; } PUSH(YC + flag, j, i, L, R, -flag); i++; } } } img = pImage + YC * step; for (i = L; i <= R; i++) { sum[0] += img[i*3]; sum[1] += img[i*3 + 1]; sum[2] += img[i*3 + 2]; } area += R - L + 1; } region->area = area; region->rect.x = XMin; region->rect.y = YMin; region->rect.width = XMax - XMin + 1; region->rect.height = YMax - YMin + 1; region->value = cvScalarAll(0); { double inv_area = area ? 1. / area : 0; newVal[0] = cvRound(sum[0] * inv_area); newVal[1] = cvRound(sum[1] * inv_area); newVal[2] = cvRound(sum[2] * inv_area); } return CV_NO_ERR; }
Obj SCTableProductHandler ( Obj self, Obj table, Obj list1, Obj list2 ) { Obj res; /* result list */ Obj row; /* one row of sc table */ Obj zero; /* zero from sc table */ Obj ai, aj; /* elements from list1 */ Obj bi, bj; /* elements from list2 */ Obj c, c1, c2; /* products of above */ Int dim; /* dimension of vectorspace */ Int i, j; /* loop variables */ /* check the arguments a bit */ if ( ! IS_SMALL_LIST(table) ) { table = ErrorReturnObj( "SCTableProduct: <table> must be a list (not a %s)", (Int)TNAM_OBJ(table), 0L, "you can replace <table> via 'return <table>;'" ); return SCTableProductHandler( self, table, list1, list2 ); } dim = LEN_LIST(table) - 2; if ( dim <= 0 ) { table = ErrorReturnObj( "SCTableProduct: <table> must be a list with at least 3 elements", 0L, 0L, "you can replace <table> via 'return <table>;'" ); return SCTableProductHandler( self, table, list1, list2 ); } zero = ELM_LIST( table, dim+2 ); if ( ! IS_SMALL_LIST(list1) || LEN_LIST(list1) != dim ) { list1 = ErrorReturnObj( "SCTableProduct: <list1> must be a list with %d elements", dim, 0L, "you can replace <list1> via 'return <list1>;'" ); return SCTableProductHandler( self, table, list1, list2 ); } if ( ! IS_SMALL_LIST(list2) || LEN_LIST(list2) != dim ) { list2 = ErrorReturnObj( "SCTableProduct: <list2> must be a list with %d elements", dim, 0L, "you can replace <list2> via 'return <list2>;'" ); return SCTableProductHandler( self, table, list1, list2 ); } /* make the result list */ res = NEW_PLIST( T_PLIST, dim ); SET_LEN_PLIST( res, dim ); for ( i = 1; i <= dim; i++ ) { SET_ELM_PLIST( res, i, zero ); } CHANGED_BAG( res ); /* general case */ if ( EQ( ELM_LIST( table, dim+1 ), INTOBJ_INT(0) ) ) { for ( i = 1; i <= dim; i++ ) { ai = ELM_LIST( list1, i ); if ( EQ( ai, zero ) ) continue; row = ELM_LIST( table, i ); for ( j = 1; j <= dim; j++ ) { bj = ELM_LIST( list2, j ); if ( EQ( bj, zero ) ) continue; c = PROD( ai, bj ); if ( ! EQ( c, zero ) ) { SCTableProdAdd( res, c, ELM_LIST( row, j ), dim ); } } } } /* commutative case */ else if ( EQ( ELM_LIST( table, dim+1 ), INTOBJ_INT(1) ) ) { for ( i = 1; i <= dim; i++ ) { ai = ELM_LIST( list1, i ); bi = ELM_LIST( list2, i ); if ( EQ( ai, zero ) && EQ( bi, zero ) ) continue; row = ELM_LIST( table, i ); c = PROD( ai, bi ); if ( ! EQ( c, zero ) ) { SCTableProdAdd( res, c, ELM_LIST( row, i ), dim ); } for ( j = i+1; j <= dim; j++ ) { bj = ELM_LIST( list2, j ); aj = ELM_LIST( list1, j ); if ( EQ( aj, zero ) && EQ( bj, zero ) ) continue; c1 = PROD( ai, bj ); c2 = PROD( aj, bi ); c = SUM( c1, c2 ); if ( ! EQ( c, zero ) ) { SCTableProdAdd( res, c, ELM_LIST( row, j ), dim ); } } } } /* anticommutative case */ else if ( EQ( ELM_LIST( table, dim+1 ), INTOBJ_INT(-1) ) ) { for ( i = 1; i <= dim; i++ ) { ai = ELM_LIST( list1, i ); bi = ELM_LIST( list2, i ); if ( EQ( ai, zero ) && EQ( bi, zero ) ) continue; row = ELM_LIST( table, i ); for ( j = i+1; j <= dim; j++ ) { bj = ELM_LIST( list2, j ); aj = ELM_LIST( list1, j ); if ( EQ( aj, zero ) && EQ( bj, zero ) ) continue; c1 = PROD( ai, bj ); c2 = PROD( aj, bi ); c = DIFF( c1, c2 ); if ( ! EQ( c, zero ) ) { SCTableProdAdd( res, c, ELM_LIST( row, j ), dim ); } } } } /* return the result */ return res; }
PView *GMSH_DistancePlugin::execute(PView *v) { int id_pt = (int) DistanceOptions_Number[0].def; int id_line = (int) DistanceOptions_Number[1].def; int id_face = (int) DistanceOptions_Number[2].def; double type = (double) DistanceOptions_Number[3].def; int ortho = (int) DistanceOptions_Number[6].def; PView *view = new PView(); _data = getDataList(view); #if defined(HAVE_SOLVER) #if defined(HAVE_TAUCS) linearSystemCSRTaucs<double> *lsys = new linearSystemCSRTaucs<double>; #else linearSystemCSRGmm<double> *lsys = new linearSystemCSRGmm<double>; lsys->setNoisy(1); lsys->setGmres(1); lsys->setPrec(5.e-8); #endif dofManager<double> * dofView = new dofManager<double>(lsys); #endif std::vector<GEntity*> _entities; GModel::current()->getEntities(_entities); if (!_entities.size() || !_entities[_entities.size()-1]->getMeshElement(0)) { Msg::Error("This plugin needs a mesh !"); return view; } GEntity* ge = _entities[_entities.size()-1]; int integrationPointTetra[2] = {0,0}; int numnodes = 0; for (unsigned int i = 0; i < _entities.size()-1; i++) numnodes += _entities[i]->mesh_vertices.size(); int totNodes = numnodes + _entities[_entities.size()-1]->mesh_vertices.size(); int order = ge->getMeshElement(0)->getPolynomialOrder(); int totNumNodes = totNodes + ge->getNumMeshElements()*integrationPointTetra[order-1]; std::vector<SPoint3> pts; std::vector<double> distances; std::vector<MVertex* > pt2Vertex; pts.clear(); distances.clear(); pt2Vertex.clear(); pts.reserve(totNumNodes); distances.reserve(totNumNodes); pt2Vertex.reserve(totNumNodes); std::map<MVertex*,double> _distanceE_map; std::map<MVertex*,int> _isInYarn_map; std::vector<int> index; std::vector<double> distancesE; std::vector<double> distances2; std::vector<double> distancesE2; std::vector<int> isInYarn; std::vector<int> isInYarn2; std::vector<SPoint3> closePts; std::vector<SPoint3> closePts2; for (int i=0; i<totNumNodes; i++) { distances.push_back(1.e22); } int k = 0; for (unsigned int i=0; i<_entities.size(); i++){ GEntity* ge = _entities[i]; _maxDim = std::max(_maxDim, ge->dim()); for (unsigned int j=0; j<ge->mesh_vertices.size(); j++) { MVertex *v = ge->mesh_vertices[j]; pts.push_back(SPoint3(v->x(), v->y(), v->z())); _distance_map.insert(std::make_pair(v, 0.0)); /* TO DO (by AM) SPoint3 p_empty(); _closePts_map.insert(std::make_pair(v, p_empty)); */ pt2Vertex[k] = v; k++; } } // Compute geometrical distance to mesh boundaries //------------------------------------------------------ if (type < 0.0 ) { bool existEntity = false; for (unsigned int i=0; i<_entities.size(); i++) { GEntity* g2 = _entities[i]; int gDim = g2->dim(); std::vector<int> phys = g2->getPhysicalEntities(); bool computeForEntity = false; for(unsigned int k = 0; k<phys.size(); k++) { int tagp = phys[k]; if (id_pt == 0 && id_line == 0 && id_face == 0 && gDim == _maxDim - 1) computeForEntity = true; else if ((tagp == id_pt && gDim == 0) || (tagp == id_line && gDim == 1) || (tagp == id_face && gDim == 2)) computeForEntity = true; } if (computeForEntity) { existEntity = true; for (unsigned int k = 0; k < g2->getNumMeshElements(); k++) { std::vector<double> iDistances; std::vector<SPoint3> iClosePts; std::vector<double> iDistancesE; std::vector<int> iIsInYarn; MElement *e = g2->getMeshElement(k); MVertex *v1 = e->getVertex(0); MVertex *v2 = e->getVertex(1); SPoint3 p1(v1->x(), v1->y(), v1->z()); SPoint3 p2(v2->x(), v2->y(), v2->z()); if ((e->getNumVertices() == 2 && order == 1) || (e->getNumVertices() == 3 && order == 2)) { signedDistancesPointsLine(iDistances, iClosePts, pts, p1, p2); } else if ((e->getNumVertices() == 3 && order == 1) || (e->getNumVertices() == 6 && order == 2)) { MVertex *v3 = e->getVertex(2); SPoint3 p3 (v3->x(),v3->y(),v3->z()); signedDistancesPointsTriangle(iDistances, iClosePts, pts, p1, p2, p3); } for (unsigned int kk=0; kk<pts.size(); kk++) { if (std::abs(iDistances[kk]) < distances[kk]) { distances[kk] = std::abs(iDistances[kk]); MVertex *v = pt2Vertex[kk]; _distance_map[v] = distances[kk]; /* TO DO (by AM) _closePts_map[v] = iClosePts[kk]; */ } } } } } if (!existEntity){ if (id_pt != 0) Msg::Error("The Physical Point does not exist !"); if (id_line != 0) Msg::Error("The Physical Line does not exist !"); if (id_face != 0) Msg::Error("The Physical Surface does not exist !"); return view; } printView(_entities, _distance_map); /* TO DO (by AM) printView(_entities, _closePts_map); */ } // Compute PDE for distance function //----------------------------------- else if (type > 0.0) { #if defined(HAVE_SOLVER) bool existEntity = false; SBoundingBox3d bbox; for(unsigned int i = 0; i < _entities.size(); i++){ GEntity* ge = _entities[i]; int gDim = ge->dim(); bool fixForEntity = false; std::vector<int> phys = ge->getPhysicalEntities(); for(unsigned int k = 0; k < phys.size(); k++) { int tagp = phys[k]; if (id_pt == 0 && id_line == 0 && id_face == 0 && gDim == _maxDim - 1) fixForEntity = true; else if ((tagp == id_pt && gDim == 0) || (tagp == id_line && gDim == 1) || (tagp == id_face && gDim == 2) ) fixForEntity = true; } if (fixForEntity) { existEntity = true; for (unsigned int i = 0; i < ge->getNumMeshElements(); ++i) { MElement *t = ge->getMeshElement(i); for (int k=0; k<t->getNumVertices(); k++) { MVertex *v = t->getVertex(k); dofView->fixVertex(v, 0, 1, 0.); bbox += SPoint3(v->x(), v->y(), v->z()); } } } } if (!existEntity){ if (id_pt != 0) Msg::Error("The Physical Point does not exist !"); if (id_line != 0) Msg::Error("The Physical Line does not exist !"); if (id_face != 0) Msg::Error("The Physical Surface does not exist !"); return view; } std::vector<MElement *> allElems; for(unsigned int ii = 0; ii < _entities.size(); ii++){ if(_entities[ii]->dim() == _maxDim) { GEntity *ge = _entities[ii]; for(unsigned int i = 0; i < ge->getNumMeshElements(); ++i) { MElement *t = ge->getMeshElement(i); allElems.push_back(t); for (int k = 0; k < t->getNumVertices(); k++) dofView->numberVertex(t->getVertex(k), 0, 1); } } } double L = norm(SVector3(bbox.max(), bbox.min())); double mu = type*L; simpleFunction<double> DIFF(mu*mu), ONE(1.0); distanceTerm distance(GModel::current(), 1, &DIFF, &ONE); for (std::vector<MElement* >::iterator it = allElems.begin(); it != allElems.end(); it++){ SElement se((*it)); distance.addToMatrix(*dofView, &se); } groupOfElements gr(allElems); distance.addToRightHandSide(*dofView, gr); Msg::Info("Distance Computation: Assembly done"); lsys->systemSolve(); Msg::Info("Distance Computation: System solved"); for (std::map<MVertex*,double >::iterator itv = _distance_map.begin(); itv != _distance_map.end() ; ++itv) { MVertex *v = itv->first; double value; dofView->getDofValue(v, 0, 1, value); value = std::min(0.9999, value); double dist = -mu * log(1. - value); itv->second = dist; } printView(_entities, _distance_map); #endif } _data->setName("distance"); _data->Time.push_back(0); _data->setFileName(_fileName.c_str()); _data->finalize(); // compute also orthogonal vector to distance field // A Uortho = -C DIST //------------------------------------------------ if (ortho > 0) { #if defined(HAVE_SOLVER) #ifdef HAVE_TAUCS linearSystemCSRTaucs<double> *lsys2 = new linearSystemCSRTaucs<double>; #else linearSystemCSRGmm<double> *lsys2 = new linearSystemCSRGmm<double>; lsys->setNoisy(1); lsys->setGmres(1); lsys->setPrec(5.e-8); #endif dofManager<double> myAssembler(lsys2); simpleFunction<double> ONE(1.0); double dMax = 1.0; //EMI TO CHANGE std::vector<MElement *> allElems; for(unsigned int ii = 0; ii < _entities.size(); ii++){ if (_entities[ii]->dim() == _maxDim) { GEntity *ge = _entities[ii]; for (unsigned int i=0; i<ge->getNumMeshElements(); ++i) { MElement *t = ge->getMeshElement(i); double vMean = 0.0; for (int k = 0; k < t->getNumVertices(); k++) { std::map<MVertex*, double>::iterator it = _distance_map.find(t->getVertex(k)); vMean += it->second; } vMean /= t->getNumVertices(); if (vMean < dMax) allElems.push_back(ge->getMeshElement(i)); } } } int mid = (int)floor(allElems.size() / 2.); MElement *e = allElems[mid]; MVertex *vFIX = e->getVertex(0); myAssembler.fixVertex(vFIX, 0, 1, 0.0); for (std::vector<MElement* >::iterator it = allElems.begin(); it != allElems.end(); it++){ MElement *t = *it; for(int k = 0; k < t->getNumVertices(); k++) myAssembler.numberVertex(t->getVertex(k), 0, 1); } orthogonalTerm *ortho; ortho = new orthogonalTerm(GModel::current(), 1, &ONE, &_distance_map); // if (type < 0) // ortho = new orthogonalTerm(GModel::current(), 1, &ONE, view); // else // ortho = new orthogonalTerm(GModel::current(), 1, &ONE, dofView); for (std::vector<MElement* >::iterator it = allElems.begin(); it != allElems.end(); it++){ SElement se((*it)); ortho->addToMatrix(myAssembler, &se); } groupOfElements gr(allElems); ortho->addToRightHandSide(myAssembler, gr); Msg::Info("Orthogonal Computation: Assembly done"); lsys2->systemSolve(); Msg::Info("Orthogonal Computation: System solved"); PView *view2 = new PView(); PViewDataList *data2 = getDataList(view2); data2->setName("ortogonal field"); Msg::Info("Writing orthogonal.pos"); FILE * f5 = Fopen("orthogonal.pos","w"); fprintf(f5,"View \"orthogonal\"{\n"); for (std::vector<MElement* >::iterator it = allElems.begin(); it != allElems.end(); it++){ MElement *e = *it; int numNodes = e->getNumVertices(); if (e->getType() == TYPE_POLYG) numNodes = e->getNumChildren() * e->getChild(0)->getNumVertices(); std::vector<double> x(numNodes), y(numNodes), z(numNodes); std::vector<double> *out2 = data2->incrementList(1, e->getType(), numNodes); std::vector<MVertex*> nods; std::vector<double> orth; if(!e->getNumChildren()) for(int i=0; i<numNodes; i++) nods.push_back(e->getVertex(i)); else for(int i = 0; i < e->getNumChildren(); i++) for(int j = 0; j < e->getChild(i)->getNumVertices(); j++) nods.push_back(e->getChild(i)->getVertex(j)); for(int nod = 0; nod < numNodes; nod++) out2->push_back((nods[nod])->x()); for(int nod = 0; nod < numNodes; nod++) out2->push_back((nods[nod])->y()); for(int nod = 0; nod < numNodes; nod++) out2->push_back((nods[nod])->z()); if (_maxDim == 2) switch (numNodes) { case 2: fprintf(f5,"SL("); break; case 3: fprintf(f5,"ST("); break; case 4: fprintf(f5,"SQ("); break; default: Msg::Fatal("Error in Plugin 'Distance' (numNodes=%g).",numNodes); break; } else if (_maxDim == 3) switch (numNodes) { case 4: fprintf(f5,"SS("); break; case 8: fprintf(f5,"SH("); break; case 6: fprintf(f5,"SI("); break; case 5: fprintf(f5,"SY("); break; default: Msg::Fatal("Error in Plugin 'Distance' (numNodes=%g).",numNodes); break; } for (int j=0; j<numNodes; j++) { MVertex *v = nods[j]; if (j) fprintf(f5, ",%g,%g,%g", v->x(), v->y(), v->z()); else fprintf(f5, "%g,%g,%g", v->x(), v->y(), v->z()); double value; myAssembler.getDofValue(v, 0, 1, value); orth.push_back(value); } fprintf(f5,"){"); for (unsigned int i=0; i<orth.size(); i++) { out2->push_back(orth[i]); if (i) fprintf(f5,",%g", orth[i]); else fprintf(f5,"%g", orth[i]); } fprintf(f5,"};\n"); } fprintf(f5,"};\n"); fclose(f5); lsys->clear(); lsys2->clear(); data2->Time.push_back(0); data2->setFileName("orthogonal.pos"); data2->finalize(); #endif } return view; }
void OscilGen::prepare(fft_t *freqs) { if((oldbasepar != Pbasefuncpar) || (oldbasefunc != Pcurrentbasefunc) || DIFF(basefuncmodulation) || DIFF(basefuncmodulationpar1) || DIFF(basefuncmodulationpar2) || DIFF(basefuncmodulationpar3)) changebasefunction(); for(int i = 0; i < MAX_AD_HARMONICS; ++i) hphase[i] = (Phphase[i] - 64.0f) / 64.0f * PI / (i + 1); for(int i = 0; i < MAX_AD_HARMONICS; ++i) { const float hmagnew = 1.0f - fabs(Phmag[i] / 64.0f - 1.0f); switch(Phmagtype) { case 1: hmag[i] = expf(hmagnew * logf(0.01f)); break; case 2: hmag[i] = expf(hmagnew * logf(0.001f)); break; case 3: hmag[i] = expf(hmagnew * logf(0.0001f)); break; case 4: hmag[i] = expf(hmagnew * logf(0.00001f)); break; default: hmag[i] = 1.0f - hmagnew; break; } if(Phmag[i] < 64) hmag[i] = -hmag[i]; } //remove the harmonics where Phmag[i]==64 for(int i = 0; i < MAX_AD_HARMONICS; ++i) if(Phmag[i] == 64) hmag[i] = 0.0f; clearAll(freqs, synth.oscilsize); if(Pcurrentbasefunc == 0) //the sine case for(int i = 0; i < MAX_AD_HARMONICS - 1; ++i) { freqs[i + 1] = std::complex<float>(-hmag[i] * sinf(hphase[i] * (i + 1)) / 2.0f, hmag[i] * cosf(hphase[i] * (i + 1)) / 2.0f); } else for(int j = 0; j < MAX_AD_HARMONICS; ++j) { if(Phmag[j] == 64) continue; for(int i = 1; i < synth.oscilsize / 2; ++i) { int k = i * (j + 1); if(k >= synth.oscilsize / 2) break; freqs[k] += basefuncFFTfreqs[i] * FFTpolar<fftw_real>( hmag[j], hphase[j] * k); } } if(Pharmonicshiftfirst != 0) shiftharmonics(freqs); if(Pfilterbeforews) { oscilfilter(freqs); waveshape(freqs); } else { waveshape(freqs); oscilfilter(freqs); } modulation(freqs); spectrumadjust(freqs); if(Pharmonicshiftfirst == 0) shiftharmonics(freqs); clearDC(freqs); oldhmagtype = Phmagtype; oldharmonicshift = Pharmonicshift + Pharmonicshiftfirst * 256; oscilprepared = 1; }
/* * Message receiver handler. */ static pj_bool_t on_rx_message(pjsip_rx_data *rdata) { pjsip_msg *msg = rdata->msg_info.msg; pj_str_t branch_param = rdata->msg_info.via->branch_param; pj_status_t status; if (pj_stricmp2(&branch_param, TEST1_BRANCH_ID) == 0 || pj_stricmp2(&branch_param, TEST2_BRANCH_ID) == 0) { /* * TEST1_BRANCH_ID tests that non-INVITE transaction transmits 2xx * final response using correct transport and terminates transaction * after 32 seconds. * * TEST2_BRANCH_ID performs similar test for non-2xx final response. */ int status_code = (pj_stricmp2(&branch_param, TEST1_BRANCH_ID) == 0) ? TEST1_STATUS_CODE : TEST2_STATUS_CODE; if (msg->type == PJSIP_REQUEST_MSG) { /* On received request, create UAS and respond with final * response. */ pjsip_transaction *tsx; status = pjsip_tsx_create_uas(&tsx_user, rdata, &tsx); if (status != PJ_SUCCESS) { app_perror(" error: unable to create transaction", status); test_complete = -110; return PJ_TRUE; } pjsip_tsx_recv_msg(tsx, rdata); save_key(tsx); send_response(rdata, tsx, status_code); } else { /* Verify the response received. */ ++recv_count; /* Verify status code. */ if (msg->line.status.code != status_code) { PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); test_complete = -113; } /* Verify that no retransmissions is received. */ if (recv_count > 1) { PJ_LOG(3,(THIS_FILE, " error: retransmission received")); test_complete = -114; } } return PJ_TRUE; } else if (pj_stricmp2(&branch_param, TEST3_BRANCH_ID) == 0) { /* TEST3_BRANCH_ID tests provisional response. */ if (msg->type == PJSIP_REQUEST_MSG) { /* On received request, create UAS and respond with provisional * response, then schedule timer to send final response. */ pjsip_transaction *tsx; status = pjsip_tsx_create_uas(&tsx_user, rdata, &tsx); if (status != PJ_SUCCESS) { app_perror(" error: unable to create transaction", status); test_complete = -116; return PJ_TRUE; } pjsip_tsx_recv_msg(tsx, rdata); save_key(tsx); send_response(rdata, tsx, TEST3_PROVISIONAL_CODE); schedule_send_response(rdata, &tsx->transaction_key, TEST3_STATUS_CODE, 2000); } else { /* Verify the response received. */ ++recv_count; if (recv_count == 1) { /* Verify status code. */ if (msg->line.status.code != TEST3_PROVISIONAL_CODE) { PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); test_complete = -123; } } else if (recv_count == 2) { /* Verify status code. */ if (msg->line.status.code != TEST3_STATUS_CODE) { PJ_LOG(3,(THIS_FILE, " error: incorrect status code")); test_complete = -124; } } else { PJ_LOG(3,(THIS_FILE, " error: retransmission received")); test_complete = -125; } } return PJ_TRUE; } else if (pj_stricmp2(&branch_param, TEST4_BRANCH_ID) == 0 || pj_stricmp2(&branch_param, TEST5_BRANCH_ID) == 0 || pj_stricmp2(&branch_param, TEST6_BRANCH_ID) == 0) { /* TEST4_BRANCH_ID: absorbs retransmissions in TRYING state. */ /* TEST5_BRANCH_ID: retransmit last response in PROCEEDING state. */ /* TEST6_BRANCH_ID: retransmit last response in COMPLETED state. */ if (msg->type == PJSIP_REQUEST_MSG) { /* On received request, create UAS. */ pjsip_transaction *tsx; PJ_LOG(4,(THIS_FILE, " received request (probably retransmission)")); status = pjsip_tsx_create_uas(&tsx_user, rdata, &tsx); if (status != PJ_SUCCESS) { app_perror(" error: unable to create transaction", status); test_complete = -130; return PJ_TRUE; } pjsip_tsx_recv_msg(tsx, rdata); save_key(tsx); if (pj_stricmp2(&branch_param, TEST4_BRANCH_ID) == 0) { } else if (pj_stricmp2(&branch_param, TEST5_BRANCH_ID) == 0) { send_response(rdata, tsx, TEST5_PROVISIONAL_CODE); } else if (pj_stricmp2(&branch_param, TEST6_BRANCH_ID) == 0) { PJ_LOG(4,(THIS_FILE, " sending provisional response")); send_response(rdata, tsx, TEST6_PROVISIONAL_CODE); PJ_LOG(4,(THIS_FILE, " sending final response")); send_response(rdata, tsx, TEST6_STATUS_CODE); } } else { /* Verify the response received. */ PJ_LOG(4,(THIS_FILE, " received response number %d", recv_count)); ++recv_count; if (pj_stricmp2(&branch_param, TEST4_BRANCH_ID) == 0) { PJ_LOG(3,(THIS_FILE, " error: not expecting response!")); test_complete = -132; } else if (pj_stricmp2(&branch_param, TEST5_BRANCH_ID) == 0) { if (rdata->msg_info.msg->line.status.code!=TEST5_PROVISIONAL_CODE) { PJ_LOG(3,(THIS_FILE, " error: incorrect status code!")); test_complete = -133; } if (recv_count > TEST5_RESPONSE_COUNT) { PJ_LOG(3,(THIS_FILE, " error: not expecting response!")); test_complete = -134; } } else if (pj_stricmp2(&branch_param, TEST6_BRANCH_ID) == 0) { int code = rdata->msg_info.msg->line.status.code; switch (recv_count) { case 1: if (code != TEST6_PROVISIONAL_CODE) { PJ_LOG(3,(THIS_FILE, " error: invalid code!")); test_complete = -135; } break; case 2: case 3: if (code != TEST6_STATUS_CODE) { PJ_LOG(3,(THIS_FILE, " error: invalid code %d " "(expecting %d)", code, TEST6_STATUS_CODE)); test_complete = -136; } break; default: PJ_LOG(3,(THIS_FILE, " error: not expecting response")); test_complete = -137; break; } } } return PJ_TRUE; } else if (pj_stricmp2(&branch_param, TEST7_BRANCH_ID) == 0 || pj_stricmp2(&branch_param, TEST8_BRANCH_ID) == 0) { /* * TEST7_BRANCH_ID and TEST8_BRANCH_ID test the retransmission * of INVITE final response */ if (msg->type == PJSIP_REQUEST_MSG) { /* On received request, create UAS. */ pjsip_transaction *tsx; status = pjsip_tsx_create_uas(&tsx_user, rdata, &tsx); if (status != PJ_SUCCESS) { app_perror(" error: unable to create transaction", status); test_complete = -140; return PJ_TRUE; } pjsip_tsx_recv_msg(tsx, rdata); save_key(tsx); if (pj_stricmp2(&branch_param, TEST7_BRANCH_ID) == 0) { send_response(rdata, tsx, TEST7_STATUS_CODE); } else { send_response(rdata, tsx, TEST8_STATUS_CODE); } } else { int code; ++recv_count; if (pj_stricmp2(&branch_param, TEST7_BRANCH_ID) == 0) code = TEST7_STATUS_CODE; else code = TEST8_STATUS_CODE; if (recv_count==1) { if (rdata->msg_info.msg->line.status.code != code) { PJ_LOG(3,(THIS_FILE," error: invalid status code")); test_complete = -141; } recv_last = rdata->pkt_info.timestamp; } else { pj_time_val now; unsigned msec, msec_expected; now = rdata->pkt_info.timestamp; PJ_TIME_VAL_SUB(now, recv_last); msec = now.sec*1000 + now.msec; msec_expected = (1 << (recv_count-2)) * pjsip_cfg()->tsx.t1; if (msec_expected > pjsip_cfg()->tsx.t2) msec_expected = pjsip_cfg()->tsx.t2; if (DIFF(msec, msec_expected) > MAX_ALLOWED_DIFF) { PJ_LOG(3,(THIS_FILE, " error: incorrect retransmission " "time (%d ms expected, %d ms received", msec_expected, msec)); test_complete = -142; } if (recv_count > 11) { PJ_LOG(3,(THIS_FILE," error: too many responses (%d)", recv_count)); test_complete = -143; } recv_last = rdata->pkt_info.timestamp; } } return PJ_TRUE; } else if (pj_stricmp2(&branch_param, TEST9_BRANCH_ID) == 0) { /* * TEST9_BRANCH_ID tests that the retransmission of INVITE final * response should cease when ACK is received. Transaction also MUST * terminate in T4 seconds. */ if (msg->type == PJSIP_REQUEST_MSG) { /* On received request, create UAS. */ pjsip_transaction *tsx; status = pjsip_tsx_create_uas(&tsx_user, rdata, &tsx); if (status != PJ_SUCCESS) { app_perror(" error: unable to create transaction", status); test_complete = -150; return PJ_TRUE; } pjsip_tsx_recv_msg(tsx, rdata); save_key(tsx); send_response(rdata, tsx, TEST9_STATUS_CODE); } else { ++recv_count; if (rdata->msg_info.msg->line.status.code != TEST9_STATUS_CODE) { PJ_LOG(3,(THIS_FILE," error: invalid status code")); test_complete = -151; } if (recv_count==1) { recv_last = rdata->pkt_info.timestamp; } else if (recv_count < 5) { /* Let UAS retransmit some messages before we send ACK. */ pj_time_val now; unsigned msec, msec_expected; now = rdata->pkt_info.timestamp; PJ_TIME_VAL_SUB(now, recv_last); msec = now.sec*1000 + now.msec; msec_expected = (1 << (recv_count-2)) * pjsip_cfg()->tsx.t1; if (msec_expected > pjsip_cfg()->tsx.t2) msec_expected = pjsip_cfg()->tsx.t2; if (DIFF(msec, msec_expected) > MAX_ALLOWED_DIFF) { PJ_LOG(3,(THIS_FILE, " error: incorrect retransmission " "time (%d ms expected, %d ms received", msec_expected, msec)); test_complete = -152; } recv_last = rdata->pkt_info.timestamp; } else if (recv_count == 5) { pjsip_tx_data *tdata; pjsip_sip_uri *uri; pjsip_via_hdr *via; status = pjsip_endpt_create_request_from_hdr( endpt, &pjsip_ack_method, rdata->msg_info.to->uri, rdata->msg_info.from, rdata->msg_info.to, NULL, rdata->msg_info.cid, rdata->msg_info.cseq->cseq, NULL, &tdata); if (status != PJ_SUCCESS) { app_perror(" error: unable to create ACK", status); test_complete = -153; return PJ_TRUE; } uri=(pjsip_sip_uri*)pjsip_uri_get_uri(tdata->msg->line.req.uri); uri->transport_param = pj_str("loop-dgram"); via = (pjsip_via_hdr*) pjsip_msg_find_hdr(tdata->msg, PJSIP_H_VIA, NULL); via->branch_param = pj_str(TEST9_BRANCH_ID); status = pjsip_endpt_send_request_stateless(endpt, tdata, NULL, NULL); if (status != PJ_SUCCESS) { app_perror(" error: unable to send ACK", status); test_complete = -154; } } else { PJ_LOG(3,(THIS_FILE," error: too many responses (%d)", recv_count)); test_complete = -155; } } return PJ_TRUE; } else if (pj_stricmp2(&branch_param, TEST10_BRANCH_ID) == 0 || pj_stricmp2(&branch_param, TEST11_BRANCH_ID) == 0 || pj_stricmp2(&branch_param, TEST12_BRANCH_ID) == 0) { int test_num, code1, code2; if (pj_stricmp2(&branch_param, TEST10_BRANCH_ID) == 0) test_num=10, code1 = 100, code2 = 0; else if (pj_stricmp2(&branch_param, TEST11_BRANCH_ID) == 0) test_num=11, code1 = 100, code2 = 200; else test_num=12, code1 = 200, code2 = 0; if (rdata->msg_info.msg->type == PJSIP_REQUEST_MSG) { /* On received response, create UAS. */ pjsip_transaction *tsx; status = pjsip_tsx_create_uas(&tsx_user, rdata, &tsx); if (status != PJ_SUCCESS) { app_perror(" error: unable to create transaction", status); test_complete = -150; return PJ_TRUE; } pjsip_tsx_recv_msg(tsx, rdata); save_key(tsx); schedule_send_response(rdata, &tsx_key, code1, 1000); if (code2) schedule_send_response(rdata, &tsx_key, code2, 2000); } else { } return PJ_TRUE; } return PJ_FALSE; }
// Funktion berechnet, ob ein Feuersystem aufgrund der Position des Schiffes, der Position des Systems auf dem Schiff und // dessen Feuerwinkel auch feuern kann. // @param arc Zeiger auf Schussfeld // @return Wahrheitswert bool CCombatShip::AllowFire(const CFireArc* arc) { if (m_pShip->IsStation()) return true; /* Ich fasse nochmal zusammen was benötigt wird und was mittels Variablen festgehalten werden müsste: - Ausrichtung des Schiffes (kann schnell berechnet werden) - Feuerwinkel jeder einzelnen Waffe (müsste noch als Attribut hinzugefügt werden -> Änderung des ShipEditors und der data Datei, horizontaler == vertikaler Winkel?) - Position des gegnerischen Schiffes (ist vorhanden) -> aus diesen Variablen muss ein boolescher Wert berechnet werden, ob ein Feuern gestattet ist */ int dirarc_V = arc->GetPosition(); int firearc_V = arc->GetAngle(); bool allow = false; //int m=2; //"Regelkonstante" vec3<float> v; // Besitzt das Schiff eine Flugroute, so ist dessen Ausrichtung der Vektor zwischen aktueller Position und dem // nächsten Punkt auf der Flugroute if (!m_lRoute.empty()) { vec3i p = m_lRoute[0] - m_KO; v.Set((float)p.x, (float)p.y, (float)p.z); v /= v.Length(); } // Ohne Flugziel richtet sich das Schiff automatisch zum Zentrum aus P(0,0,0) else { v.Set((float)-m_KO.x, (float)-m_KO.y, (float)-m_KO.z); v /= v.Length(); } // Vektor zwischen Schiff und Ziel vec3<float> diff; if (m_pTarget != 0) { vec3i p = m_pTarget->m_KO - m_KO; diff.Set((float)p.x, (float)p.y, (float)p.z); diff /= diff.Length(); } int diffarc = 0; // new_z =(v)x(diff)=(v2*diff3 - v3*diff2, v3*diff1 - v1*diff3, v1*diff2 - v2*diff1); vec3<float> new_z = v / diff; // Kreuzprodukt geht auch mit v ^ diff und ^-Operator // If (new_z=0) #Der Nullvektor, d.h. v=k*diff (k wäre ein Skalar) if (new_z.IsNull()) { // If Skalar(v,diff)>=0 then diffarc=0 else diffarc=180; #ginge auch über norm(diff+v)>norm(diff) if (v * diff >= 0) diffarc = 0; else diffarc = 180; } else { //Regeln für Verhindern der positiven Achsenausrichtung und damit immer gleiche Seite beim Feuern vec3<float> g_x; vec3<float> g_z; vec3<float> g_y(diff / diff.Length()); //unser g_y bleibt immer gleich, man hätte auch g_y verändern können, ich hab mich für g_x entschieden vec3<float> gYTemp((v * g_y) * g_y); //damit bleibt auch gYTemp immer gleich /*if (firepower_centroid > m) { g_x = ((gYTemp - v) / (gYTemp - v).Length()); g_z = ((-new_z) / new_z.Length()); } else if (firepower_centroid < m) { g_x = ((v - gYTemp) / (v - gYTemp).Length()); g_z((new_z) new_z.Length()); } else*/ if (diff.y < 0) { if (diff * v < 0) { g_x = ((gYTemp - v) / (gYTemp - v).Length()); g_z = ((-new_z) / new_z.Length()); } else { g_x = ((v - gYTemp) / (v - gYTemp).Length()); g_z = (new_z / new_z.Length()); } } else if (diff.y > 0) { if (diff * v < 0) { g_x = ((v - gYTemp) / (v - gYTemp).Length()); g_z = (new_z / new_z.Length()); } else { g_x = ((gYTemp - v) / (gYTemp - v).Length()); g_z = ((-new_z) / new_z.Length()); } } else if (diff.x < 0) { if (diff * v < 0) { g_x = ((gYTemp - v) / (gYTemp - v).Length()); g_z = ((-new_z) / new_z.Length()); } else { g_x = ((v - gYTemp) / (v - gYTemp).Length()); g_z = (new_z / new_z.Length()); } } else if (diff.x > 0) { if (diff * v < 0) { g_x = ((v - gYTemp) / (v - gYTemp).Length()); g_z = (new_z / new_z.Length()); } else { g_x = ((gYTemp - v) / (gYTemp - v).Length()); g_z = ((-new_z) / new_z.Length()); } } else if (diff.z < 0) { if (diff * v < 0) { g_x = ((gYTemp - v) / (gYTemp -v).Length()); g_z = ((-new_z) / new_z.Length()); } else { g_x = ((v - gYTemp) / (v - gYTemp).Length()); g_z = (new_z / new_z.Length()); } } else if (diff.z > 0) { if (diff * v < 0) { g_x = ((v - gYTemp) / (v - gYTemp).Length()); g_z = (new_z / new_z.Length()); } else { g_x = ((gYTemp - v) / (gYTemp - v).Length()); g_z = ((-new_z) / new_z.Length()); } } else { g_x = ((v - gYTemp) / (v - gYTemp).Length()); g_z = ((new_z) / new_z.Length()); } // v=Matrixprodukt((a1,a2,a3;b1,b2,b3;c1,c2,c3),(v1,v2,v3)) vec3<float> V(g_x.x * v.x + g_x.y * v.y + g_x.z * v.z, g_y.x * v.x + g_y.y * v.y + g_y.z * v.z, g_z.x * v.x + g_z.y * v.y + g_z.z * v.z); // diff=Matrixprodukt((a1,a2,a3;b1,b2,b3;c1,c2,c3),(diff1,diff2,diff3)) vec3<float> DIFF(g_x.x * diff.x + g_x.y * diff.y + g_x.z * diff.z, g_y.x * diff.x + g_y.y * diff.y + g_y.z * diff.z, g_z.x * diff.x + g_z.y * diff.y + g_z.z * diff.z); // diffv_arcdiff=(Skalarprodukt(diff_new,v_new),diff_new2*v_new1 - diff_new1*v_new2) #als komplex-konjugiert-multiplizierte komplexe Zahl und die wiederum als 2D-Vektor dargestellt. Der Fall dass diffv_arcdiff1 und diffv_arcdiff2 0 sind, also der gesamte Vektor der Nullvektor darstellt, kann nicht auftreten, den haben wir mit der If-Abfrage oben schon rausgenommen. vec3<float> diffv_arcdiff(DIFF * V / V.Length(), DIFF.y * V.x / V.Length(), 0); //DIFF.x = 0 ! d.h. es steht eigentlich nur DIFF.y*V.X und das ist 1*1=1 // diffarc_bogenmaß=arg(z)={arctan(y/x) für x<0, Pi/2 für x=0 und y>0, Pi + arctan(y/x) für x>0, 3/2 Pi für x=0, y<0} oder auch diffarc_bogenmaß=arg(z)={arccos(a/r) für y>=0, 2pi - arccos(a/r) für y<0} float diffarc_bogenmass; if (diffv_arcdiff.y < 0) //zweite Komponente kleiner 0, d.h. Vektor in unterer Halbebene und damit das Feindschiff links vom eigenen Schiff aus gesehen diffarc_bogenmass = (float)PI * 2 - acos((float)diffv_arcdiff.x / (float)diffv_arcdiff.Length()); else diffarc_bogenmass = acos((float)diffv_arcdiff.x / (float)diffv_arcdiff.Length()); //diffarc=diffarc_bogenmaß*180/Pi diffarc = (int)(diffarc_bogenmass * 180 / (float)PI); } if ( (dirarc_V - firearc_V/2 < diffarc - 360) || ((dirarc_V - firearc_V/2 < diffarc) && (diffarc < dirarc_V + firearc_V/2)) || (diffarc + 360 < dirarc_V + firearc_V/2) ) allow = true; return allow; }
/* * Acquire Raw pen coodinate data and compute touch screen * pressure resistance. Hold spinlock when calling. */ int AcquireEvent(struct jz_ts_t *ts, struct ts_event *event) { unsigned int x_raw[8], y_raw[8], p_raw[8]; int valid, i; unsigned int avl_x, avl_y, diff_x, diff_y; struct datasource *ds = &data_s; avl_x = avl_y = 0; for (i = 0; i < samples; i++) { if (jz4740_adc_read(ts)) { return 0; } x_raw[i] = ds->ybuf; y_raw[i] = ds->xbuf; p_raw[i] = ds->zbuf; avl_x += x_raw[i]; avl_y += y_raw[i]; #if 0 printk("x_raw=%x y_raw=%x z_raw=%x\n",x_raw[i],y_raw[i],p_raw[i]); #endif } avl_x /= samples; avl_y /= samples; #define MAX_DELTA 20 valid = 1; for (i = 1; i < samples; i++) { if ((100 * DIFF(x_raw[i],x_raw[i-1])/MIN(x_raw[i],x_raw[i-1])) > MAX_DELTA) { valid = 0; break; } if ((100 * DIFF(y_raw[i],y_raw[i-1])/MIN(y_raw[i],y_raw[i-1])) > MAX_DELTA) { valid = 0; break; } if ((100 * DIFF(p_raw[i],p_raw[i-1])/MIN(p_raw[i],p_raw[i-1])) > MAX_DELTA) { valid = 0; break; } } if (valid) { if (ts->first_read) { ts->first_read = 0; old_x = avl_x; old_y = avl_y; } diff_x = DIFF(old_x, avl_x); diff_y = DIFF(old_y, avl_y); if (diff_x < 100 && diff_y < 100) { old_x = avl_x; old_y = avl_y; } else valid = 0; } if (valid) { valid = calibrate_samples(x_raw, y_raw, p_raw, samples); } if (valid) { unsigned int x_scr, y_scr; if(ts->filter) { x_scr = transform_to_screen_x(ts, x_raw[0]); y_scr = transform_to_screen_y(ts, y_raw[0]); if (ts->prints) printk("x_raw=%d y_raw=%d x_transform=%d y_transform=%d\n", x_raw[0], y_raw[0], x_scr, y_scr); } else { x_scr = x_raw[0]; y_scr = y_raw[0]; if (ts->prints) printk("x_raw=%d y_raw=%d \n", x_raw[0], y_raw[0]); } event->x = x_scr; event->y = y_scr; event->pressure = (u16)p_raw[0]; event->status = PENDOWN; return 1; } return 0; }