void WSortView::RecalcInversions() { if (!m_calc_inversions) { m_inversions = -1; return; } unsigned int inversions = 0; for (size_t i = 0; i < size(); ++i) { const ArrayItem& a = direct(i); for (size_t j = i+1; j < size(); ++j) { const ArrayItem& b = direct(j); if ( a.greater_direct(b) ) { inversions++; } } } m_inversions = inversions; }
int roll() { int by=23,bx=6,pow,dir,t=0,last=clock(),xmod=0,dmod=0; float tcount = CLOCKS_PER_SEC /8; mvaddch(by,bx+2,'o'|COLOR_PAIR(COLOR_GREEN)); dir=direct(); pow=power(); while(1) { t=clock()-last; if(t>=tcount) { xmod=(dir==0)?48:(dir==-1||dir==1)?10:5; dmod=(dir==0)?rand()%3-1:(dir>0)?1:-1; mvaddch(by,bx+2,board[by][bx]); if(rand()%xmod==0) { bx+=dmod; if(bx==0) {bx=1;dir=1;} if (bx==12) {bx=11;dir=-1;} } --by; mvaddch(by,bx+2,'o'|COLOR_PAIR(COLOR_GREEN)); refresh(); last=clock(); if(by==0||--pow==0) { if(by>=9&&by<=23) { while(by>=9&&by<=23) { mvaddch(by,bx+2,board[by][bx]); by++; mvaddch(by,bx+2,'o'|COLOR_PAIR(COLOR_GREEN)); refresh(); napms(200); } dir=direct(); pow=power(); by=23; mvaddch(by,bx+2,'o'|COLOR_PAIR(COLOR_GREEN)); refresh(); continue; } napms(1000); mvaddch(by,bx+2,board[by][bx]); if(by==0||by==8){return 0;} if(bx==1||bx==11||by==1||by==7){return 1;} if(by==2||by==3||by==6){return 2;} if(bx==6){return 4;} return 3; } } } }
/*Following the functions simulates the caches*/ void direct(Cache modify, size_t addMe){ modify->memory_access++; /*get the necessary bits for each tag, index, block*/ long long boff=extract(modify->HMblock,0, addMe); long long index1=extract(modify->HMindex,modify->HMblock, addMe); long long tag1=extract(modify->HMtag,modify->HMindex, addMe); long long index=index1 % modify->numofSet; if(modify->blocks[index][0].valid==1 && modify->blocks[index][0].tag==tag1){ /*is it the same tag? Hit, update LRU, return*/ modify->hits++; return; } if(modify->blocks[index][0].valid==0){ modify->cold_misses++; modify->total_misses++; /*call next level and see if they have it*/ if(modify->nextLevel!=NULL){ if(strcmp(modify->nextLevel->type, "direct")==0){ direct(modify->nextLevel, addMe); } if((strlen(modify->nextLevel->type)>=7)&&(strncmp(modify->nextLevel->type,"assoc:", 5)==0)){ // printf("I came here"); SA(modify->nextLevel, addMe, modify->nextLevel->assoc); } if((strlen(modify->nextLevel->type)==5)&& (strcmp(modify->nextLevel->type,"assoc")==0)){ FA(modify->nextLevel, addMe); } } /*once we're done, add the address' tag, index, off set to the index*/ modify->blocks[index][0].tag=tag1; modify->blocks[index][0].indexSet=index; modify->blocks[index][0].offSet=boff; modify->blocks[index][0].valid=1; } /*again, not equal? call the next cache*/ if(modify->blocks[index][0].valid==1 && modify->blocks[index][0].tag!=tag1){ if(modify->nextLevel!=NULL){ if(strcmp(modify->nextLevel->type, "direct")==0){ direct(modify->nextLevel, addMe); } if((strlen(modify->nextLevel->type)>=7)&&(strncmp(modify->nextLevel->type,"assoc:", 5)==0)){ // printf("I came here"); SA(modify->nextLevel, addMe, modify->nextLevel->assoc); } if((strlen(modify->nextLevel->type)==5)&& (strcmp(modify->nextLevel->type,"assoc")==0)){ FA(modify->nextLevel, addMe); } } /*once we're done, add the address' tag, index, off set to the index*/ modify->conflict_miss++; modify->total_misses++; modify->blocks[index][0].tag=tag1; modify->blocks[index][0].indexSet=index; modify->blocks[index][0].offSet=boff; } }
void InitPins() { direct(PinData,O); //as output direct(PinState,O); //as output direct(PinBlink,O); //as output direct(PinBuzzer,O); //as output on(PinBlink); off(PinData); off(PinState); off(PinBuzzer); }
void dir2ae(void) { double square; azimuth() = ((direct(Y) == 0) && (direct(X) == 0)) ? 0.0 : atan2 ( -(direct(Y)), -(direct(X)) ) / DEG2RAD; square = sqrt(direct(X) * direct(X) + direct(Y) * direct(Y)); elevation() = atan2 (-(direct(Z)), square) / DEG2RAD; }
void dir2ae(void) { double square; int zeroes = ZERO(direct(Y)) && ZERO(direct(X)); azimuth() = zeroes ? 0.0 : atan2 (-(direct(Y)), -(direct(X))) / DEG2RAD; square = sqrt(direct(X) * direct(X) + direct(Y) * direct(Y)); elevation() = atan2 (-(direct(Z)), square) / DEG2RAD; }
struct pair shortestDist(struct point *A,struct point *Ax, int n, int j1, int j2) { int k, l, mid; struct pair sd; float t; struct point *P; if((j2 - j1) <= 2) { sd = direct(A, j1, j2); return sd; } P = (struct point*)malloc(n*sizeof(struct point)); mid = (j1 + j2)/2; struct pair a = shortestDist(A, Ax, n, j1, mid); struct pair b = shortestDist(A, Ax, n, mid+1, j2); if(a.dist<b.dist) sd = a; else sd = b; int c = 0; for (k = 0; k < n; ++k) { if((Ax[k].y>= A[mid].y - sd.dist) && (Ax[k].y<= A[mid].y + sd.dist)) { P[c++] = Ax[k]; } } sd = strip(P, sd, c); return sd; }
void JavaUpload::checkResponse() { // call Java JByteBuffer direct(m_buffer.data(), m_buffer.size()); JMap hdr = JMap::fromQMap(m_headers); m_plugin->call("checkResponse", JSignature().add("java.nio.ByteBuffer").add("java.util.Map"), JArgs() << direct << hdr); }
void figure_sphere_backup(string sphere_filename, double noise_percent) { CRichModel model(sphere_filename); model.Preprocess(); string prefix = sphere_filename.substr(0, sphere_filename.length() - 4); double noise_len = model.GetMeanEdgeLength() * 0.1; vector<int> vert_index(model.GetNumOfVerts()); for (int i = 0; i < vert_index.size(); ++i) { vert_index[i] = i; } random_shuffle(vert_index.begin(), vert_index.end()); int noise_vert_num = noise_percent * model.GetNumOfVerts(); printf("noise_vert_num %d\n", noise_vert_num); std::random_device rd; std::mt19937 gen(rd()); std::normal_distribution<double> d(1, 1); for (int i = 0; i < noise_vert_num; ++i) { int vert = vert_index[i]; CPoint3D direct(d(gen), d(gen), d(gen)); direct.Normalize(); direct *= noise_len; model.m_Verts[vert] += direct; } char output_filename[256]; sprintf(output_filename, "%s_noise%.2lf.obj", prefix.c_str(), noise_percent); model.FastSaveObjFile(output_filename); }
glm::vec3 radiance (const Ray & r, int iterations = 3) { float t = 1.0f; glm::vec3 normale, normale2; Object* o = intersect(r, t, normale); if (t == noIntersect) return glm::vec3(0,0,0); glm::vec3 pointIntersection = r.origin + t*r.direction; // Calcul pour les ombres douces, point aléatoire de lumière autour de scene::light float pdf = 0; glm::vec3 normaleSphereLumiere = glm::normalize(pointIntersection - scene::light); glm::vec3 vecLumiere = sample_sphere(10, random_u(), random_u(), pdf, normaleSphereLumiere); glm::vec3 light = scene::light + vecLumiere; glm::vec3 directionLum = light - pointIntersection; glm::vec3 directionLumNormalize = glm::normalize(directionLum); Ray rayLum{pointIntersection+directionLumNormalize*0.1f, directionLumNormalize}; intersect(rayLum, t, normale2); glm::vec3 direct(0,0,0); if (t*t > longueurCarree(directionLum)) { direct = o->direct(normale, directionLumNormalize) / (pdf*longueurCarree(directionLum)); } glm::vec3 indirect(0,0,0); if (iterations > 0) indirect = o->indirect(r.direction, pointIntersection, normale, iterations); return direct + indirect; }
size_t WSortView::GetRuns() const { unsigned int runs = 1; for (size_t i = 1; i < size(); ++i) { const ArrayItem& a = direct(i-1); const ArrayItem& b = direct(i); if ( a.greater_direct(b) ) { runs++; } } return runs; }
void dump_state(const char *UNUSED(buffer), com_table *UNUSED(ctp), struct rt_i *UNUSED(rtip)) { char *c; static const char fmt_char[] = {'r', 'h', 'p', 'f', 'm', 'o', 'g'}; FILE *sfPtr; int f; outitem *oip; /* Pointer into list of output items */ if ((sfPtr = fopen(sf_name, "wb")) == NULL) { fprintf(stderr, "Cannot open statefile '%s'\n", sf_name); return; } printf("Dumping NIRT state to file '%s'...", sf_name); fprintf(sfPtr, "%c file created by the dump command of nirt\n", CMT_CHAR); fprintf(sfPtr, "xyz %g %g %g\n", target(X), target(Y), target(Z)); fprintf(sfPtr, "dir %g %g %g\n", direct(X), direct(Y), direct(Z)); fprintf(sfPtr, "useair %d\n", ap.a_rt_i->useair); fprintf(sfPtr, "units %s\n", local_u_name); if (BU_STR_EQUAL(dest_string, "stdout")) fputs("dest default\n", sfPtr); else fprintf(sfPtr, "dest %s\n", dest_string); fprintf(sfPtr, "overlap_claims %s\n", ocname[overlap_claims]); for (f = 0; f < FMT_NONE; ++f) { fprintf(sfPtr, "fmt %c \"", fmt_char[f]); /* Display the conversion specifications */ for (oip = oi_list[f]; oip != OUTITEM_NULL; oip = oip->next) for (c = oip->format; *c != '\0'; ++c) if (*c == '\n') fprintf(sfPtr, "\\n"); else fputc(*c, sfPtr); fprintf(sfPtr, "\""); /* Display the item name */ for (oip = oi_list[f]; oip != OUTITEM_NULL; oip = oip->next) if (ValTab[oip->code_nm].name) fprintf(sfPtr, " %s", ValTab[oip->code_nm].name); fprintf(sfPtr, "\n"); } printf("\n"); fclose(sfPtr); }
QVector3D MainWidget::getDirection() { QVector3D direct( std::cos(cameraDirection.y()) * std::sin(cameraDirection.x()), std::sin(cameraDirection.y()), -std::cos(cameraDirection.y()) * std::cos(cameraDirection.x())); direct.normalize(); return direct; }
bool intersect(Segment const & s1, Segment const & s2) { int d1 = direct(s2, s1.p1); int d2 = direct(s2, s1.p2); int d3 = direct(s1, s2.p1); int d4 = direct(s1, s2.p2); if (d1 * d2 == -1 && d3 * d4 == -1) { return true; } else if (d1 == 0 && on_segment(s2, s1.p1)) { return true; } else if (d2 == 0 && on_segment(s2, s1.p2)) { return true; } else if (d3 == 0 && on_segment(s1, s2.p1)) { return true; } else if (d4 == 0 && on_segment(s1, s2.p2)) { return true; } else { return false; } }
// only c1 and c2 can be modified static void interact(const struct cell *c1, const struct cell *c2) { if (is_leaf(c1) && is_leaf(c2)) { direct(c1, c2); } else if (is_leaf(c1)) { map(interact, product(c1, get_subcells(c2))); } else if (is_leaf(c2)) { map(interact, product(get_subcells(c1), c2)); } else { map(interact, product(get_subcells(c1), get_subcells(c2))); } }
int live(char *str, int i, t_param *param, t_cmd *cmd) { param->param[0] = 0x1; param->lenght = 1; while (str[i] != 0 && str[i] != ' ') i++; if (str[i] == 0) return (-1); i++; direct(param, str, i , cmd); return (0); }
CoordinateGridBasicTest() : la00lo00(0,0), la10lo10(to_rad(10),to_rad(10)), nullposition(), nullposition_init(0.0,0.0), northpole(to_rad( 90.0),0.0), southpole(to_rad(-90.0),0.0), sw(to_rad(55),to_rad(16)), ne(to_rad(59.5),to_rad(16.5)), center(0.0,0.0) { vdirection d = inverse(sw,ne); center = direct(sw,d.bearing1,d.distance/2.0); }
unsigned sys_erase(struct FAB *fab) { unsigned sts; int ifi_no = 1; int wcc_flag = 0; struct WCCFILE *wccfile = NULL; struct NAM *nam = fab->fab$l_nam; if (fab->fab$w_ifi != 0) return RMS$_IFI; while (ifi_table[ifi_no] != NULL && ifi_no < IFI_MAX) ifi_no++; if (ifi_no >= IFI_MAX) return RMS$_IFI; if (nam != NULL) { wccfile = (struct WCCFILE *) fab->fab$l_nam->nam$l_wcc; } if (wccfile == NULL) { sts = do_parse(fab,&wccfile); if (sts & 1) { wcc_flag = 1; if (wccfile->wcf_status & STATUS_WILDCARD) { sts = RMS$_WLD; } else { sts = do_search(fab,wccfile); } } } else { sts = 1; } if (sts & 1) { struct fibdef fibblk; struct dsc$descriptor fibdsc,serdsc; fibdsc.dsc$w_length = sizeof(struct fibdef); fibdsc.dsc$a_pointer = (char *) &fibblk; serdsc.dsc$w_length = wccfile->wcf_wcd.wcd_reslen; serdsc.dsc$a_pointer = wccfile->wcf_result + wccfile->wcf_wcd.wcd_prelen; memcpy(&fibblk.fib$w_did_num,&wccfile->wcf_wcd.wcd_dirid,sizeof(struct fiddef)); fibblk.fib$w_nmctl = 0; fibblk.fib$l_acctl = 0; fibblk.fib$w_fid_num = 0; fibblk.fib$w_fid_seq = 0; fibblk.fib$b_fid_rvn = 0; fibblk.fib$b_fid_nmx = 0; fibblk.fib$l_wcc = 0; sts = direct(wccfile->wcf_vcb,&fibdsc,&serdsc,NULL,NULL,1); if (sts & 1) sts = accesserase(wccfile->wcf_vcb,&wccfile->wcf_fid); } if (wcc_flag) { cleanup_wcf(wccfile); if (nam != NULL) nam->nam$l_wcc = 0; } return sts; }
void ae2dir(void) { double ar = azimuth() * DEG2RAD; double er = elevation() * DEG2RAD; int i; vect_t dir; dir[X] = -cos(ar) * cos(er); dir[Y] = -sin(ar) * cos(er); dir[Z] = -sin(er); VUNITIZE( dir ); for (i = 0; i < 3; ++i) direct(i) = dir[i]; }
void Dimap::createDirectGrid(double ulcSamp, double ulcLine, double stepPixel, int nbSamp, int nbLine, std::vector<double> const &vAltitude, std::vector<Pt2dr> &vPtCarto, std::string targetSyst, std::string inputSyst, std::vector<double> vRefineCoef,double rowCrop, double sampCrop)const { vPtCarto.clear(); // On cree un fichier de points geographiques pour les transformer avec proj4 { std::ofstream fic("processing/direct_ptGeo.txt"); fic << std::setprecision(15); for(size_t i=0;i<vAltitude.size();++i) { double altitude = vAltitude[i]; for(int l=0;l<nbLine;++l) { for(int c = 0;c<nbSamp;++c) { Pt2dr Pimg(ulcSamp + c * stepPixel, ulcLine + l * stepPixel); //pour affiner les coordonnees Pt2dr PimgRefined = ptRefined(Pimg, vRefineCoef, rowCrop, sampCrop); Pt2dr Pgeo = direct(PimgRefined,altitude); fic << Pgeo.y <<" "<<Pgeo.x<<";"<<std::endl; } } } } // transformation in the ground coordinate system std::string command; command = g_externalToolHandler.get("cs2cs").callName() + " " + inputSyst + " +to " + targetSyst + " -s processing/direct_ptGeo.txt > processing/direct_ptCarto.txt"; int res = system(command.c_str()); if (res != 0) std::cout<<"error calling cs2cs in createDirectGrid"<<std::endl; // loading points std::ifstream fic("processing/direct_ptCarto.txt"); while(!fic.eof()&&fic.good()) { double X,Y,Z; char c; fic >> Y >> X >> Z >> c; if (fic.good()) vPtCarto.push_back(Pt2dr(X,Y)); } std::cout << "createDirectGrid - Nombre de points lus : "<<vPtCarto.size()<<std::endl; }
void dir_vect(char *buffer, com_table *ctp, struct rt_i *UNUSED(rtip)) { extern int str_dbl(); /* function to convert string to double */ int i = 0; int rc = 0; /* the return code value from str_dbl() */ vect_t Dir; /* Direction vector x, y and z */ while (isspace((int)*(buffer+i))) ++i; if (*(buffer+i) == '\0') { /* display current direct coors */ fprintf(stdout, "(x, y, z) = (%4.2f, %4.2f, %4.2f)\n", direct(X), direct(Y), direct(Z)); return; } if ((rc = str_dbl(buffer+i, &Dir[X])) == 0) { /* get direct x coor */ com_usage(ctp); return; } i += rc; while (isspace((int)*(buffer+i))) ++i; if ((rc = str_dbl(buffer+i, &Dir[Y])) == 0) { /* get direct y coor */ com_usage(ctp); return; } i += rc; while (isspace((int)*(buffer+i))) ++i; if ((rc = str_dbl(buffer+i, &Dir[Z])) == 0) { /* get direct z coor */ com_usage(ctp); return; } i += rc; while (isspace((int)*(buffer+i))) ++i; if (*(buffer+i) != '\0') { /* check for garbage at the end of the line */ com_usage(ctp); return; } VUNITIZE(Dir); direct(X) = Dir[X]; direct(Y) = Dir[Y]; direct(Z) = Dir[Z]; dir2ae(); }
void WFGameEventReceiver::MouseEvents(const SEvent& event) { GameGlobal* global = GameGlobal::Instance(); if( event.MouseInput.isRightPressed() ) { // вращение камеры float a, b; a = (last_m_x - event.MouseInput.X); b = (event.MouseInput.Y - last_m_y); if( a != 0 || b != 0 ) { ctrl->CameraTurn( a, b ); } // last_time = D } if( event.MouseInput.Wheel != last_wheel ){ f32 d_wheel = event.MouseInput.Wheel - last_wheel; Controller::Instance()->Zoom( d_wheel ); } if( event.MouseInput.isLeftPressed() ){ vector2df direct( event.MouseInput.X - global->cfg->GetCfg()->Width / 2.0f, event.MouseInput.Y - global->cfg->GetCfg()->Height / 2.0f ); Controller::Instance()->Move( direct ); } last_m_x = event.MouseInput.X; last_m_y = event.MouseInput.Y; last_wheel = event.MouseInput.Wheel; }
void figure_sphere(string sphere_filename, double noise_strength) { CRichModel model(sphere_filename); model.Preprocess(); string prefix = sphere_filename.substr(0, sphere_filename.length() - 4); double noise_len = model.GetMeanEdgeLength() * noise_strength; printf("noise_strength %lf\n", noise_strength); std::random_device rd; std::mt19937 gen(rd()); std::normal_distribution<double> normal_d(1, 1); std::uniform_real_distribution<double> uniform_d(0, noise_len);//random noise len for (int i = 0; i < model.GetNumOfVerts(); ++i) { int vert = i; CPoint3D direct(normal_d(gen), normal_d(gen), normal_d(gen)); direct.Normalize(); direct *= uniform_d(gen); model.m_Verts[vert] += direct; } char output_filename[256]; sprintf(output_filename, "%s_noise_strength_%.2lf.obj", prefix.c_str(), noise_strength); model.FastSaveObjFile(output_filename); }
int m_brdf( /* color a ray that hit a BRDTfunc material */ OBJREC *m, RAY *r ) { int hitfront = 1; BRDFDAT nd; RAY sr; double mirtest=0, mirdist=0; double transtest=0, transdist=0; int hasrefl, hastrans; int hastexture; COLOR ctmp; FVECT vtmp; double d; MFUNC *mf; int i; /* check arguments */ if ((m->oargs.nsargs < 10) | (m->oargs.nfargs < 9)) objerror(m, USER, "bad # arguments"); nd.mp = m; nd.pr = r; /* dummy values */ nd.rspec = nd.tspec = 1.0; nd.trans = 0.5; /* diffuse reflectance */ if (r->rod > 0.0) setcolor(nd.rdiff, m->oargs.farg[0], m->oargs.farg[1], m->oargs.farg[2]); else setcolor(nd.rdiff, m->oargs.farg[3], m->oargs.farg[4], m->oargs.farg[5]); /* diffuse transmittance */ setcolor(nd.tdiff, m->oargs.farg[6], m->oargs.farg[7], m->oargs.farg[8]); /* get modifiers */ raytexture(r, m->omod); hastexture = DOT(r->pert,r->pert) > FTINY*FTINY; if (hastexture) { /* perturb normal */ nd.pdot = raynormal(nd.pnorm, r); } else { VCOPY(nd.pnorm, r->ron); nd.pdot = r->rod; } if (r->rod < 0.0) { /* orient perturbed values */ nd.pdot = -nd.pdot; for (i = 0; i < 3; i++) { nd.pnorm[i] = -nd.pnorm[i]; r->pert[i] = -r->pert[i]; } hitfront = 0; } copycolor(nd.mcolor, r->pcol); /* get pattern color */ multcolor(nd.rdiff, nd.mcolor); /* modify diffuse values */ multcolor(nd.tdiff, nd.mcolor); hasrefl = bright(nd.rdiff) > FTINY; hastrans = bright(nd.tdiff) > FTINY; /* load cal file */ nd.dp = NULL; mf = getfunc(m, 9, 0x3f, 0); /* compute transmitted ray */ setbrdfunc(&nd); errno = 0; setcolor(ctmp, evalue(mf->ep[3]), evalue(mf->ep[4]), evalue(mf->ep[5])); if ((errno == EDOM) | (errno == ERANGE)) objerror(m, WARNING, "compute error"); else if (rayorigin(&sr, TRANS, r, ctmp) == 0) { if (!(r->crtype & SHADOW) && hastexture) { /* perturb direction */ VSUM(sr.rdir, r->rdir, r->pert, -.75); if (normalize(sr.rdir) == 0.0) { objerror(m, WARNING, "illegal perturbation"); VCOPY(sr.rdir, r->rdir); } } else { VCOPY(sr.rdir, r->rdir); } rayvalue(&sr); multcolor(sr.rcol, sr.rcoef); addcolor(r->rcol, sr.rcol); if (!hastexture) { transtest = 2.0*bright(sr.rcol); transdist = r->rot + sr.rt; } } if (r->crtype & SHADOW) /* the rest is shadow */ return(1); /* compute reflected ray */ setbrdfunc(&nd); errno = 0; setcolor(ctmp, evalue(mf->ep[0]), evalue(mf->ep[1]), evalue(mf->ep[2])); if ((errno == EDOM) | (errno == ERANGE)) objerror(m, WARNING, "compute error"); else if (rayorigin(&sr, REFLECTED, r, ctmp) == 0) { VSUM(sr.rdir, r->rdir, nd.pnorm, 2.*nd.pdot); checknorm(sr.rdir); rayvalue(&sr); multcolor(sr.rcol, sr.rcoef); addcolor(r->rcol, sr.rcol); if (!hastexture && r->ro != NULL && isflat(r->ro->otype)) { mirtest = 2.0*bright(sr.rcol); mirdist = r->rot + sr.rt; } } /* compute ambient */ if (hasrefl) { if (!hitfront) flipsurface(r); copycolor(ctmp, nd.rdiff); multambient(ctmp, r, nd.pnorm); addcolor(r->rcol, ctmp); /* add to returned color */ if (!hitfront) flipsurface(r); } if (hastrans) { /* from other side */ if (hitfront) flipsurface(r); vtmp[0] = -nd.pnorm[0]; vtmp[1] = -nd.pnorm[1]; vtmp[2] = -nd.pnorm[2]; copycolor(ctmp, nd.tdiff); multambient(ctmp, r, vtmp); addcolor(r->rcol, ctmp); if (hitfront) flipsurface(r); } if (hasrefl | hastrans || m->oargs.sarg[6][0] != '0') direct(r, dirbrdf, &nd); /* add direct component */ d = bright(r->rcol); /* set effective distance */ if (transtest > d) r->rt = transdist; else if (mirtest > d) r->rt = mirdist; return(1); }
unsigned do_search(struct FAB *fab,struct WCCFILE *wccfile) { int sts; struct fibdef fibblk; struct WCCDIR *wcc; struct dsc$descriptor fibdsc,resdsc; struct NAM *nam = fab->fab$l_nam; wcc = &wccfile->wcf_wcd; if (fab->fab$w_ifi != 0) return RMS$_IFI; /* if first time through position at top directory... WCCDIR */ while ((wcc->wcd_status & STATUS_INIT) == 0 && wcc->wcd_next != NULL) { wcc = wcc->wcd_next; } fibdsc.dsc$w_length = sizeof(struct fibdef); fibdsc.dsc$a_pointer = (char *) &fibblk; while (1) { if ((wcc->wcd_status & STATUS_INIT) == 0 || wcc->wcd_wcc != 0) { wcc->wcd_status |= STATUS_INIT; resdsc.dsc$w_length = 256 - wcc->wcd_prelen; resdsc.dsc$a_pointer = wccfile->wcf_result + wcc->wcd_prelen; memcpy(&fibblk.fib$w_did_num,&wcc->wcd_dirid,sizeof(struct fiddef)); fibblk.fib$w_nmctl = 0; /* FIB$M_WILD; */ fibblk.fib$l_acctl = 0; fibblk.fib$w_fid_num = 0; fibblk.fib$w_fid_seq = 0; fibblk.fib$b_fid_rvn = 0; fibblk.fib$b_fid_nmx = 0; fibblk.fib$l_wcc = wcc->wcd_wcc; #ifdef DEBUG wcc->wcd_sernam[wcc->wcd_serdsc.dsc$w_length] = '\0'; wccfile->wcf_result[wcc->wcd_prelen + wcc->wcd_reslen] = '\0'; printf("Ser: '%s' (%d,%d,%d) WCC: %d Prelen: %d '%s'\n",wcc->wcd_sernam, fibblk.fib$w_did_num | (fibblk.fib$b_did_nmx << 16), fibblk.fib$w_did_seq,fibblk.fib$b_did_rvn, wcc->wcd_wcc,wcc->wcd_prelen,wccfile->wcf_result + wcc->wcd_prelen); #endif sts = direct(wccfile->wcf_vcb,&fibdsc,&wcc->wcd_serdsc,&wcc->wcd_reslen,&resdsc,0); } else { sts = SS$_NOMOREFILES; } if (sts & 1) { #ifdef DEBUG wccfile->wcf_result[wcc->wcd_prelen + wcc->wcd_reslen] = '\0'; printf("Fnd: '%s' (%d,%d,%d) WCC: %d\n",wccfile->wcf_result + wcc->wcd_prelen, fibblk.fib$w_fid_num | (fibblk.fib$b_fid_nmx << 16), fibblk.fib$w_fid_seq,fibblk.fib$b_fid_rvn, wcc->wcd_wcc); #endif wcc->wcd_wcc = fibblk.fib$l_wcc; if (wcc->wcd_prev) {/* go down directory */ if (wcc->wcd_prev->wcd_next != wcc) printf("wcd_PREV corruption\n"); if (fibblk.fib$w_fid_num != 4 || fibblk.fib$b_fid_nmx != 0 || wcc == &wccfile->wcf_wcd || memcmp(wcc->wcd_sernam,"000000.",7) == 0) { memcpy(&wcc->wcd_prev->wcd_dirid,&fibblk.fib$w_fid_num,sizeof(struct fiddef)); if (wcc->wcd_next) wccfile->wcf_result[wcc->wcd_prelen - 1] = '.'; wcc->wcd_prev->wcd_prelen = wcc->wcd_prelen + wcc->wcd_reslen - 5; wcc = wcc->wcd_prev; /* go down one level */ if (wcc->wcd_prev == NULL) wccfile->wcf_result[wcc->wcd_prelen - 1] = ']'; } } else { if (nam != NULL) { int fna_size[5]; memcpy(&nam->nam$w_fid_num,&fibblk.fib$w_fid_num,sizeof(struct fiddef)); nam->nam$b_rsl = wcc->wcd_prelen + wcc->wcd_reslen; name_delim(wccfile->wcf_result,nam->nam$b_rsl,fna_size); nam->nam$l_dev = nam->nam$l_rsa; nam->nam$b_dev = fna_size[0]; nam->nam$l_dir = nam->nam$l_dev + fna_size[0]; nam->nam$b_dir = fna_size[1]; nam->nam$l_name = nam->nam$l_dir + fna_size[1]; nam->nam$b_name = fna_size[2]; nam->nam$l_type = nam->nam$l_name + fna_size[2]; nam->nam$b_type = fna_size[3]; nam->nam$l_ver = nam->nam$l_type + fna_size[3]; nam->nam$b_ver = fna_size[4]; if (nam->nam$b_rsl <= nam->nam$b_rss) { memcpy(nam->nam$l_rsa,wccfile->wcf_result,nam->nam$b_rsl); } else { return RMS$_RSS; } } memcpy(&wccfile->wcf_fid,&fibblk.fib$w_fid_num,sizeof(struct fiddef)); return 1; } } else { #ifdef DEBUG printf("Err: %d\n",sts); #endif if (sts == SS$_BADIRECTORY) { if (wcc->wcd_next != NULL) { if (wcc->wcd_next->wcd_status & STATUS_INIT) sts = SS$_NOMOREFILES; } } if (sts == SS$_NOMOREFILES) { wcc->wcd_status &= ~STATUS_INIT; wcc->wcd_wcc = 0; wcc->wcd_reslen = 0; if (wcc->wcd_status & STATUS_TMPDIR) { struct WCCDIR *savwcc = wcc; if (wcc->wcd_next != NULL) wcc->wcd_next->wcd_prev = wcc->wcd_prev; if (wcc->wcd_prev != NULL) wcc->wcd_prev->wcd_next = wcc->wcd_next; wcc = wcc->wcd_next; memcpy(wccfile->wcf_result + wcc->wcd_prelen + wcc->wcd_reslen - 6,".DIR;1",6); free(savwcc); } else { if ((wccfile->wcf_status & STATUS_RECURSE) && wcc->wcd_prev == NULL) { struct WCCDIR *newwcc; newwcc = (struct WCCDIR *) malloc(sizeof(struct WCCDIR) + 8); newwcc->wcd_next = wcc->wcd_next; newwcc->wcd_prev = wcc; newwcc->wcd_wcc = 0; newwcc->wcd_status = STATUS_TMPDIR; newwcc->wcd_reslen = 0; if (wcc->wcd_next != NULL) { wcc->wcd_next->wcd_prev = newwcc; } wcc->wcd_next = newwcc; memcpy(&newwcc->wcd_dirid,&wcc->wcd_dirid,sizeof(struct fiddef)); newwcc->wcd_serdsc.dsc$w_length = 7; newwcc->wcd_serdsc.dsc$a_pointer = newwcc->wcd_sernam; memcpy(newwcc->wcd_sernam,"*.DIR;1",7); newwcc->wcd_prelen = wcc->wcd_prelen; wcc = newwcc; } else { if (wcc->wcd_next != NULL) { #ifdef DEBUG if (wcc->wcd_next->wcd_prev != wcc) printf("wcd_NEXT corruption\n"); #endif wcc = wcc->wcd_next; /* backup one level */ memcpy(wccfile->wcf_result + wcc->wcd_prelen + wcc->wcd_reslen - 6,".DIR;1",6); } else { sts = RMS$_NMF; break; /* giveup */ } } } } else { if (sts == SS$_NOSUCHFILE) { if (wcc->wcd_prev) { sts = RMS$_DNF; } else { sts = RMS$_FNF; } } break; /* error - abort! */ } } } cleanup_wcf(wccfile); if (nam != NULL) nam->nam$l_wcc = 0; fab->fab$w_ifi = 0; /* must dealloc memory blocks! */ return sts; }
int m_brdf2( /* color a ray that hit a BRDF material */ OBJREC *m, RAY *r ) { BRDFDAT nd; COLOR ctmp; FVECT vtmp; double dtmp; /* always a shadow */ if (r->crtype & SHADOW) return(1); /* check arguments */ if ((m->oargs.nsargs < (hasdata(m->otype)?4:2)) | (m->oargs.nfargs < ((m->otype==MAT_TFUNC)|(m->otype==MAT_TDATA)?6:4))) objerror(m, USER, "bad # arguments"); /* check for back side */ if (r->rod < 0.0) { if (!backvis) { raytrans(r); return(1); } raytexture(r, m->omod); flipsurface(r); /* reorient if backvis */ } else raytexture(r, m->omod); nd.mp = m; nd.pr = r; /* get material color */ setcolor(nd.mcolor, m->oargs.farg[0], m->oargs.farg[1], m->oargs.farg[2]); /* get specular component */ nd.rspec = m->oargs.farg[3]; /* compute transmittance */ if ((m->otype == MAT_TFUNC) | (m->otype == MAT_TDATA)) { nd.trans = m->oargs.farg[4]*(1.0 - nd.rspec); nd.tspec = nd.trans * m->oargs.farg[5]; dtmp = nd.trans - nd.tspec; setcolor(nd.tdiff, dtmp, dtmp, dtmp); } else { nd.tspec = nd.trans = 0.0; setcolor(nd.tdiff, 0.0, 0.0, 0.0); } /* compute reflectance */ dtmp = 1.0 - nd.trans - nd.rspec; setcolor(nd.rdiff, dtmp, dtmp, dtmp); nd.pdot = raynormal(nd.pnorm, r); /* perturb normal */ multcolor(nd.mcolor, r->pcol); /* modify material color */ multcolor(nd.rdiff, nd.mcolor); multcolor(nd.tdiff, nd.mcolor); /* load auxiliary files */ if (hasdata(m->otype)) { nd.dp = getdata(m->oargs.sarg[1]); getfunc(m, 2, 0, 0); } else { nd.dp = NULL; getfunc(m, 1, 0, 0); } /* compute ambient */ if (nd.trans < 1.0-FTINY) { copycolor(ctmp, nd.mcolor); /* modified by material color */ scalecolor(ctmp, 1.0-nd.trans); multambient(ctmp, r, nd.pnorm); addcolor(r->rcol, ctmp); /* add to returned color */ } if (nd.trans > FTINY) { /* from other side */ flipsurface(r); vtmp[0] = -nd.pnorm[0]; vtmp[1] = -nd.pnorm[1]; vtmp[2] = -nd.pnorm[2]; copycolor(ctmp, nd.mcolor); scalecolor(ctmp, nd.trans); multambient(ctmp, r, vtmp); addcolor(r->rcol, ctmp); flipsurface(r); } /* add direct component */ direct(r, dirbrdf, &nd); return(1); }
bool ourDirect() const { return direct() && ourRestart; }
bool theirDirect() const { return direct() && !ourRestart; }
//- Calculate addressing for interpolative mapping void topoCellMapper::calcAddressing() const { if (directAddrPtr_ || interpolationAddrPtr_) { FatalErrorIn("void topoCellMapper::calcAddressing() const") << "Addressing already calculated." << abort(FatalError); } // Allocate for inserted cell labels label nInsertedCells = 0; insertedCellLabelsPtr_ = new labelList(mesh_.nCells(), -1); labelList& insertedCells = *insertedCellLabelsPtr_; if (direct()) { // Direct addressing, no weights directAddrPtr_ = new labelList(mpm_.cellMap()); } else { // Interpolative addressing interpolationAddrPtr_ = new labelListList(mesh_.nCells()); labelListList& addr = *interpolationAddrPtr_; const List<objectMap>& cfc = mpm_.cellsFromCellsMap(); forAll (cfc, cfcI) { // Get addressing const labelList& mo = cfc[cfcI].masterObjects(); label cellI = cfc[cfcI].index(); if (addr[cellI].size() > 0) { FatalErrorIn("void topoCellMapper::calcAddressing() const") << "Master cell " << cellI << " mapped from cells " << mo << " is already destination for mapping." << abort(FatalError); } // Set master objects addr[cellI] = mo; } // Do mapped cells. Note that this can already be set by cellsFromCells // so check if addressing size still zero. const labelList& cm = mpm_.cellMap(); forAll (cm, cellI) { // Mapped from a single cell if (cm[cellI] > -1 && addr[cellI].empty()) { addr[cellI] = labelList(1, cm[cellI]); } // Check for inserted cells without any addressing if (cm[cellI] < 0 && addr[cellI].empty()) { insertedCells[nInsertedCells++] = cellI; } } } // Shorten inserted cells to actual size insertedCells.setSize(nInsertedCells); if (nInsertedCells) { FatalErrorIn("void topoCellMapper::calcAddressing() const") << " Found " << nInsertedCells << " which are" << " not mapped from any parent cells." << nl << " List: " << nl << insertedCells << abort(FatalError); } }
void FA(Cache modify, size_t addMe){ int index2; modify->memory_access++; long long boff=extract(modify->HMblock,0, addMe); long long tag1=extract(modify->HMtag,modify->HMblock, addMe); for (int j=0;j<modify->numofSet; j++){ if(modify->blocks[j][0].valid==1 && modify->blocks[j][0].tag==tag1){ /*is it the same tag? Hit, update LRU, return*/ if(modify->LRU!=NULL){ SLInsert(modify->LRU, j); modify->hits++; return; } else{ /*do nothing to fifo*/ modify->hits++; return; } } if(modify->blocks[j][0].valid==0){ if(modify->nextLevel!=NULL){ if(strcmp(modify->nextLevel->type, "direct")==0){ direct(modify->nextLevel, addMe); } if((strlen(modify->nextLevel->type)>=7)&&(strncmp(modify->nextLevel->type,"assoc:", 5)==0)){ // printf("I came here"); SA(modify->nextLevel, addMe, modify->nextLevel->assoc); } if((strlen(modify->nextLevel->type)==5)&& (strcmp(modify->nextLevel->type,"assoc")==0)){ FA(modify->nextLevel, addMe); } } modify->cold_misses++; modify->total_misses++; /*updates the queue or DLL*/ if(modify->LRU!=NULL){ SLInsert(modify->LRU, j); } else{ enqueue(modify->FIFO,j); } //printf("%d", j); modify->blocks[j][0].tag=tag1; modify->blocks[j][0].offSet=boff; modify->blocks[j][0].valid=1; // printf("\nj is at %d\n", j); return; } if(modify->blocks[j][0].valid==1 &&modify->blocks[j][0].tag!=tag1 && j==(modify->numofSet-1)){ if(modify->nextLevel!=NULL){ if(strcmp(modify->nextLevel->type, "direct")==0){ direct(modify->nextLevel, addMe); } if((strlen(modify->nextLevel->type)>=7)&&(strncmp(modify->nextLevel->type,"assoc:", 5)==0)){ // printf("I came here"); SA(modify->nextLevel, addMe, modify->nextLevel->assoc); } if((strlen(modify->nextLevel->type)==5)&& (strcmp(modify->nextLevel->type,"assoc")==0)){ FA(modify->nextLevel, addMe); } } // printf("sadI came here %d\n", j); /*it's full. Call LRU*/ modify->total_misses++; if(modify->LRU!=NULL){ index2=getLRU(modify->LRU);} else{ index2=dequeue(modify->FIFO); } // printf("\n num: %d\n", index2); modify->blocks[index2][0].tag=tag1; modify->blocks[index2][0].offSet=boff; if(modify->LRU!=NULL){ SLInsert(modify->LRU, index2); } else{ enqueue(modify->FIFO,index2); } return; } } }