SHELL uint ulist_disp(char *s) { uint i,c,j,f; f=(*s=='\0'||strcmp(s,"?")==SAME); if (user.member==0) { msgout(IC_err "メンバーがいません。"); return 0; } c=0; lo_line("user list"); for (i=1;i<=user.member;++i) { if (!f&& strfcmp(s,ulist_getid(i))!=SAME) continue; ++c; j=i; prt(lpu(i,-4),DC_norm FC_code_s ,nps(ulist_getid(i),LN_id),FC_code_e ,nps(ulist_gethandle(i),LN_handle),FC_str2_s ,nps(ulist_getmemo(i),34),FC_str2_e "\n",NULL); } lo_line1(); if (c==0) return 0; if (c==1) return j; else return ERROR; }
SHELL void BBS_add() { char buf[LN_buf+1]; char b_tel[12+1],b_time[11+1],b_host[6+1],b_name[46+1]; msgout("電話番号を入力してください。"); getstr(b_tel); if (*b_tel=='\0') { msgout("登録中止します。"); return; } msgout("運営時間は?(リターンのみだと24hr運営)"); getstr(b_time); msgout("ホストプログラムの種類は?(ex. RT-BBS,WWIV,RGWWIV等)"); getstr(b_host); msgout("そのネットの名前を入力してください。"); getstr(b_name); sprt(buf,nps(b_tel,12)," ",nps((*b_time=='\0'?"24hr":b_time),11) ," ",nps(b_host,6)," ",nps(b_name,46),NULL); add_text("bbslist",buf); }
SHELL void line_list() { uint i; lo_line("リスト"); for (i=0;i<varsize(stages->kind);++i) { prt(nps(mkkey(i,stages->kind),8),":",nps(getnvar(i,stages->kind),32) ," [",line_mptr(mkkey(i,stages->kind))>0?"●":" ","]\n",NULL); } lo_line1(); }
SHELL void line_main() { char buf[78-LN_handle+1]; prt(nps(line_handle,16)," :",NULL); ed.c=getestr(buf); /*dbprt("--Line:[",buf,"]\n",NULL);*/ if (iscntrl(ed.c)) ed.c='\0'; if (*buf=='\0') *where.param=*buf; else sprt(where.param,nps(line_handle,16)," :",buf,NULL); where_exec(where_comnum(buf)); }
void Foam::LocalInteraction<CloudType>::info(Ostream& os) { // retrieve any stored data labelList npe0(patchData_.size(), 0); this->getModelProperty("nEscape", npe0); scalarList mpe0(patchData_.size(), 0.0); this->getModelProperty("massEscape", mpe0); labelList nps0(patchData_.size(), 0); this->getModelProperty("nStick", nps0); scalarList mps0(patchData_.size(), 0.0); this->getModelProperty("massStick", mps0); // accumulate current data labelList npe(nEscape_, 0); Pstream::listCombineGather(npe, plusEqOp<label>()); npe = npe + npe0; scalarList mpe(massEscape_); Pstream::listCombineGather(mpe, plusEqOp<scalar>()); mpe = mpe + mpe0; labelList nps(nStick_); Pstream::listCombineGather(nps, plusEqOp<label>()); nps = nps + nps0; scalarList mps(massStick_); Pstream::listCombineGather(mps, plusEqOp<scalar>()); mps = mps + mps0; forAll(patchData_, i) { os << " Parcel fate (number, mass) : patch " << patchData_[i].patchName() << nl << " - escape = " << npe[i] << ", " << mpe[i] << nl << " - stick = " << nps[i] << ", " << mps[i] << nl; } if (this->outputTime()) { this->setModelProperty("nEscape", npe); nEscape_ = 0; this->setModelProperty("massEscape", mpe); massEscape_ = 0.0; this->setModelProperty("nStick", nps); nStick_ = 0; this->setModelProperty("massStick", mps); massStick_ = 0.0; } }
void ulist_rep(uint i,var_t *v) { char *p; struct tm tm; p=getvar("memo",v); if (p==NULL) p="メモなし。"; lstrcpy(ult(i)->memo ,nps(p,LN_memo)); lstrcpy(ult(i)->hoby ,nps(getvar("hoby",v),LN_memo)); lstrcpy(ult(i)->id ,nps(getvar("id",v),0)); lstrcpy(ult(i)->pass ,nps(getvar("pass",v),0)); lstrcpy(ult(i)->handle,nps(getvar("handle",v),LN_handle)); ult(i)->mpost =atoi(getvar("mpost",v)); ult(i)->post =atoi(getvar("post",v)); ult(i)->mlogin=atoi(getvar("mlogin",v)); ult(i)->login =atoi(getvar("login",v)); dtotm(getvar("birth",v),&tm); ult(i)->birthm=tm.tm_mon; ult(i)->birthd=tm.tm_mday; ult(i)->wp =atoi(getvar("wp",v)); }
void user_guest(char *s) { char buf[LN_buf+1]; op_user(); sion_sr("user",lpu(0,0)); sion_read(user.var); sion_sr("mptr",lpu(0,0)); sion_read(user.mptr); sion_close(); sprt(buf,nps(s,LN_handle-6),"(旅人)",NULL); setvar("handle",buf,user.var); user_rep(0); }
int main(int argc, char *argv[]) { double ne0, ne, ne1, ne2, ne3, ne4, ne5, ne6, ne7, ne8, ne9, ne10; double gl, gb, dordm, dist, xx, yy, zz, r, sl, cl, sb, cb, ll, hh; double nstep, dstep, dmstep; static double dd, dtest, dmpsr, rr; double dmm=0; double dm=0; double DM_MC=0; double DM_Gal=0; double DM_Host=0; double DDM; double tau_sc=0; double tau_Gal=0; double tau_MC=0; double tau_MC_sc=0; double R_g=0; double gd=0; //The localtion of Sun relative to GP and Warp double z_warp, zz_w, R_warp, theta_warp, theta_max; R_warp=8400;//pc theta_max=0.0; //In +x direction int WGN=0; int WLB=0; int WLI=0; int WFB=0; int np, ndir,vbs, nk, uu, nn; char str[5]; char dirname[64]="NULL",text[64]=""; char *p; static int i, ncount; int w_lmc=0; int w_smc=0; int umc=1; char *s; struct Warp_Sun t0; struct Thick t1; struct Thin t2; struct Spiral t3; struct GC t4; struct Gum t5; struct LB t6; struct LI t7; struct FB t8; struct LMC t9; struct Dora t10; struct SMC t11; vbs=0; argc--; argv++; if(argc < 5)usage(1); while(argc > 5){ /* Get command line inputs */ if((*argv)[0] == '-'){ s=argv[0]+1; argc--; argv++; switch(*s){ case 'h': case '?': usage(0); case 't': if(sscanf(*argv,"%s",text) != 1)usage(1); argc--; argv++; break; case 'd': if(sscanf(*argv,"%s",dirname) != 1)usage(1); argc--; argv++; break; case 'v': vbs=1; break; case 'V': vbs=2; break; default: usage(1); } } else{ if(argc>6){ printf("Extra parameters exist in input\n"); usage(1); } else break; } } if(argc==5){ if(sscanf(*argv,"%s",str) != 1){ printf("Incorrect arguments\n"); usage(1); } argc--; argv++; if(sscanf(*argv,"%lf",&gl) != 1){ printf("Incorrect arguments\n"); usage(1); } argc--; argv++; if(sscanf(*argv,"%lf",&gb) != 1){ printf("Incorrect arguments\n"); usage(1); } argc--; argv++; if(sscanf(*argv,"%lf",&dordm) != 1){ printf("Incorrect arguments\n"); usage(1); } argc--; argv++; if(sscanf(*argv,"%d",&ndir) != 1){ printf("Incorrect arguments\n"); usage(1); } DM_Host=100;//default } if(argc==6){ if(sscanf(*argv,"%s",str) != 1){ printf("Incorrect arguments\n"); usage(1); } argc--; argv++; if(sscanf(*argv,"%lf",&gl) != 1){ printf("Incorrect arguments\n"); usage(1); } argc--; argv++; if(sscanf(*argv,"%lf",&gb) != 1){ printf("Incorrect arguments\n"); usage(1); } argc--; argv++; if(sscanf(*argv,"%lf",&dordm) != 1){ printf("Incorrect arguments\n"); usage(1); } argc--; argv++; if(sscanf(*argv,"%lf",&DM_Host) != 1){ printf("Incorrect arguments\n"); usage(1); } argc--; argv++; if(sscanf(*argv,"%d",&ndir) != 1){ printf("Incorrect arguments\n"); usage(1); } } //convert to upper case p=strupr(str); if(strcmp(p,"IGM") == 0) np=-1; // IGM else if(strcmp(p,"MC") == 0) np=0; // Mag Clouds else if(strcmp(p,"GAL") == 0){ // Galaxy np=1; p="Gal"; } else{ printf("please input correct model\n"); usage(1); exit(1); } if(ndir!=1&&ndir!=2){ printf("please input correct ndir\n"); usage(1); } if(!strcmp(dirname,"NULL")){ if(getenv("YMW16_DIR")==NULL){ printf("Warning: YMW16_DIR set to local directory\n"); strcpy(dirname,"./"); }else{ strcpy(dirname,getenv("YMW16_DIR")); } } if(vbs>=1)printf("File directory: %s\n",dirname); ymw16par(&t0, &t1, &t2, &t3, &t4, &t5, &t6, &t7, &t8, &t9, &t10, &t11, dirname); if(ndir==1)printf("%s: gl=%8.3f gb=%8.3f DM=%8.2f", p, gl, gb, dordm); else printf("%s: gl=%8.3f gb=%8.3f Dist=%9.1f", p, gl, gb, dordm); ll=gl; gl=gl/RAD; gb=gb/RAD; sl=sin(gl); sb=sin(gb); cl=cos(gl); cb=cos(gb); dstep=5.0; if(np==-1){ // FRBs if(ndir==1)uu=0;//dm---dist else uu=1;//dist---dm ndir=2; DDM=dordm; dordm=100000; nk=20000; } if(np==0){ // Magellanic Cloud nk=20000; } if(np==1){ //Galactic pulsars nk=5000; } if(ndir==1){ dm=dordm; if(np==1)tau_sc=tsc(dm); dtest=dm/N0; nstep=dtest/dstep; if(nstep<200) dstep=dtest/200; if(vbs>=1){ printf("\ndtest=%lf, nstep=%lf, dstep=%lf\n", dtest, nstep, dstep); } } if(ndir==2){ dist=dordm; dtest=dist; nstep=dtest/dstep; if(nstep<200) dstep=dtest/200; if(vbs>=1){ printf("\ndtest=%lf, nstep=%lf, dstep=%lf\n", dtest, nstep, dstep); } } dd=-0.5*dstep; ncount=0; for(i=1;i<=nk;i++){ ncount++; if(vbs>=2){ printf("ncount=%d, dstep=%lf\n", ncount,dstep); } dd+=dstep; r=dd*cb; /* r is different from rr */ xx=r*sl; yy=R0*1000-r*cl; zz=dd*sb+t0.z_Sun; rr=sqrt(xx*xx+yy*yy); /* Definition of warp */ if(rr<R_warp){ zz_w=zz; }else{ theta_warp=atan2(yy,xx); z_warp=t0.Gamma_w*(rr-R_warp)*cos(theta_warp-theta_max); zz_w=zz-z_warp; } if(vbs>=2) { printf("dd=%lf, xx=%lf, yy=%lf, zz=%lf, rr=%lf\n", dd, xx, yy, zz, rr); printf("theta_warp=%lf, z_warp=%lf, zz_w=%lf\n",theta_warp,z_warp,zz_w); } R_g=sqrt(xx*xx+yy*yy+zz_w*zz_w); /* DM to Distance */ if(ndir==1){ if(dmm<=dm){ if(R_g<=35000){ thick(xx, yy, zz_w, &gd, &ne1, rr, t1); thin(xx, yy, zz_w, gd, &ne2, rr, t2); spiral(xx, yy, zz_w, gd, &ne3, rr, t3, dirname); galcen(xx, yy, zz, &ne4, t4); gum(xx, yy, zz, &ll, &ne5, t5); localbubble(xx, yy, zz, &ll, &ne6, &hh, t6); nps(xx, yy, zz, &ne7, &WLI, t7); fermibubble(xx, yy, zz, &WFB); }else{ if(np==1){ dstep=5; }else{ dstep=200; if(w_lmc>=1||w_smc>=1) dstep=5; lmc(gl,gb,dd,&w_lmc,&ne8,t9); dora(gl,gb,dd,&ne9,t10); smc(xx, yy, zz,&w_smc, &ne10, t11); } } if(WFB==1){ ne1=t8.J_FB*ne1; } ne0=ne1+max(ne2,ne3); if(hh>110){ /* Outside LB */ if(ne6>ne0 && ne6>ne5){ WLB=1; }else{ WLB=0; } }else{ /* Inside LB */ if(ne6>ne0){ WLB=1; }else{ ne1=t6.J_LB*ne1; ne0=ne1+max(ne2,ne3); WLB=0; } } if(ne7>ne0){ /* Loop I */ WLI=1; }else{ WLI=0; } if(ne5>ne0){ /* Gum Nebula */ WGN=1; }else{ WGN=0; } /* Galactic ne */ ne=(1-WLB)*((1-WGN)*((1-WLI)*(ne0+ne4+ne8+ne9+ne10)+WLI*ne7)+WGN*ne5)+WLB*ne6; if(vbs>=2){ printf("ne=%lf, ne1=%lf, ne2=%lf, ne3=%lf, ne4=%lf, ne5=%lf, ne6=%lf, ne7=%lf, ne8=%lf, ne9=%lf, ne10=%lf\n", ne, ne1, ne2, ne3, ne4, ne5, ne6, ne7, ne8, ne9, ne10); } dmstep=ne*dstep; if(dmstep<=0.000001)dmstep=0; if(vbs>=2){ printf("dmstep=%lf, dstep=%lf\n", dmstep, dstep); } dmm+=dmstep; dist=dd; if(np==0&&umc==1){ if(R_g>35000){ DM_Gal=dmm; tau_Gal=0.5*tsc(dmm); printf(" DM_Gal:%8.2f",DM_Gal); umc++; } } if(i==nk){ dist+=0.5*dstep; if(dist>100000)dist=100000; if(np==0){ DM_MC=dmm-DM_Gal; tau_MC=0.5*tsc(DM_MC); tau_MC_sc=max(tau_Gal, tau_MC); printf(" DM_MC:%8.2f",DM_MC); } if(np==0)printf(" Dist:%9.1f log(tau_sc):%7.3f %s\n",dist, log10(tau_MC_sc),text); if(np==1)printf(" DM_Gal:%8.2f Dist:%9.1f log(tau_sc):%7.3f %s\n", dmm, dist,log10(tau_sc),text); } if(vbs>=2){ printf("dmm=%lf\n", dmm); } } else{ dist=dd-0.5*dstep-(dstep*(dmm-dm))/dmstep; if(np==0){ DM_MC=dm-DM_Gal; if(DM_Gal==0){ DM_MC=0; DM_Gal=dm; tau_MC_sc=tsc(dm); printf(" DM_Gal:%8.2f ", DM_Gal); } else{ tau_MC=0.5*tsc(DM_MC); tau_MC_sc=max(tau_MC, tau_Gal); } printf(" DM_MC:%8.2f", DM_MC); } if(np==0)printf(" Dist:%9.1f log(tau_sc):%7.3f %s\n",dist,log10(tau_MC_sc),text); if(np==1)printf(" DM_Gal:%8.2f Dist:%9.1f log(tau_sc):%7.3f %s\n", dm, dist,log10(tau_sc),text); break; } } /* Distance to DM */ if(ndir==2){ if(dd<=dtest){ if(R_g<=35000){ thick(xx, yy, zz_w, &gd, &ne1, rr, t1); thin(xx, yy, zz_w, gd, &ne2, rr, t2); spiral(xx, yy, zz_w, gd, &ne3, rr, t3, dirname); galcen(xx, yy, zz, &ne4, t4); gum(xx, yy, zz, &ll, &ne5, t5); localbubble(xx, yy, zz, &ll, &ne6, &hh, t6); nps(xx, yy, zz, &ne7, &WLI, t7); fermibubble(xx, yy, zz, &WFB); }else{ if(np==1)dstep=5; else{ dstep=200; if(np==-1)dstep=5; if(w_lmc>=1||w_smc>=1) dstep=5; lmc(gl,gb,dd,&w_lmc,&ne8,t9); dora(gl,gb,dd,&ne9,t10); smc(xx, yy, zz,&w_smc, &ne10, t11); } } if(WFB==1){ ne1=t8.J_FB*ne1; } ne0=ne1+max(ne2,ne3); if(hh>110){ /* Outside LB */ if(ne6>ne0 && ne6>ne5){ WLB=1; }else{ WLB=0; } }else{ /* Inside LB */ if(ne6>ne0){ WLB=1; }else{ ne1=t6.J_LB*ne1; ne0=ne1+max(ne2,ne3); WLB=0; } } if(ne7>ne0){ /* Loop I */ WLI=1; }else{ WLI=0; } if(ne5>ne0){ /* Gum Nebula */ WGN=1; }else{ WGN=0; } /* Galactic ne */ ne=(1-WLB)*((1-WGN)*((1-WLI)*(ne0+ne4+ne8+ne9+ne10)+WLI*ne7)+WGN*ne5)+WLB*ne6; if(vbs>=2){ printf("ne=%lf, ne1=%lf, ne2=%lf, ne3=%lf, ne4=%lf, ne5=%lf, ne6=%lf, ne7=%lf, ne8=%lf, ne9=%lf, ne10=%lf\n", ne, ne1, ne2, ne3, ne4, ne5, ne6, ne7, ne8, ne9, ne10); } dmstep=ne*dstep; if(dmstep<=0.000001)dmstep=0; dm+=dmstep; if(np!=1&&umc==1){ if(R_g>35000){ DM_Gal=dm; tau_Gal=0.5*tsc(dm); printf(" DM_Gal:%8.2f",dm); umc++; } } if(i==nk&&np!=-1){ dmpsr=dm; if(np==0){ DM_MC=dm-DM_Gal; tau_MC=0.5*tsc(DM_MC); printf(" DM_MC:%8.2f", DM_MC); } tau_sc=tsc(dmpsr); tau_MC_sc=max(tau_Gal, tau_MC); if(np==0)printf(" DM:%8.2f log(tau_sc):%7.3f %s\n", dmpsr,log10(tau_MC_sc),text); if(np==1)printf(" DM:%8.2f log(tau_sc):%7.3f %s\n", dmpsr, log10(tau_sc),text); } if(i==nk&&np==-1){ if(dordm==100000){ DM_MC=dm-DM_Gal; printf(" DM_MC:%8.2f",DM_MC); } frb_d(DDM, DM_Gal, DM_MC, DM_Host, uu, vbs, text); break; } } else{ dmpsr=dm+(dmstep*(dtest-(dd-0.5*dstep)))/dstep; if(np==0){ DM_MC=dmpsr-DM_Gal; if(DM_Gal==0){ DM_MC=0; DM_Gal=dmpsr; tau_MC_sc=tsc(dmpsr); printf(" DM_Gal:%8.2f", DM_Gal); } else{ tau_MC=0.5*tsc(DM_MC); tau_MC_sc=max(tau_Gal, tau_MC); } printf(" DM_MC:%8.2f", DM_MC); } tau_sc=tsc(dmpsr); if(np==0)printf(" DM:%8.2f log(tau_sc):%7.3f %s\n", dmpsr,log10(tau_MC_sc),text); if(np==1)printf(" DM:%8.2f log(tau_sc):%7.3f %s\n", dmpsr, log10(tau_sc),text); break; } } } }
SHELL void chat() { char buf[LN_buf+1],temp[LN_buf+1]; char chat_id[LN_id+1]; time_t t; /* if (!iscall()) { msgout("自分とチャットは出来ません。"); return; }*/ msgout("チャットをします。要件は何でしょうか?"); getstr(buf); if (*buf=='\0') { msgout("中止しました。"); return; } sprt(temp,"| chat call (",buf,")",NULL); sys_log(temp); msgout("ではシスオペを呼び出します。"); timer_res(t); /* rsbufs(FLWSIG_ON2);*/ for(;;) { hcputc(_BEEP); if (kbhit()) { getch(); break; } if (rsgetc()!=ERROR) { msgout("やめました。"); /* rsbufs(FLWSIG_OFF);*/ return; } if (timer_pas(t)>30) { msgout("いないみたいですね・・・・。"); return; } } /* dbmsgout("chat_start"); */ strcpy(chat_id,"SYSOP"); ed.c='\0'; disp_text("chat"); srand(getdatime()&0xffff); for(;;) { /*dbmsgout("chat_main");*/ prt("[",nps(chat_id,8),"]",NULL); ed.c=getestr(buf); if (iscntrl(ed.c)) ed.c='\0'; switch(*buf) { case '\0': strcpy(chat_id,chat_chid(chat_id)); continue; case '.': if (buf[1]=='\0' ||buf[1]=='.') return ; continue; case '!': /* バトルチャットシステム(笑)。 */ prt("げしっ!! ",chat_chid(chat_id),"は",lpu(rand()%256+1,0) ,"のダメージを受けた\n",NULL); continue; case '/': switch(buf[1]) { case '/': return ; case '?': disp_text("chat.hlp"); continue; } default: continue; } } }
int main(int argc,char* argv[]) { /* Parse the command line and load the input files: */ LidarProcessOctree* basePoints=0; // Octree containing the base point data const char* subtractFileName=0; // Name of ASCII file containing the point set to subtract int asciiColumnIndices[3]; // Column indices of x, y, z point components in ASCII file Scalar epsilon=Scalar(1.0e-7); // Maximum match point distance const char* outputFileName=0; // Name of resulting LiDAR octree file unsigned int maxPointsPerNode=1024; // Node size of resulting LiDAR octree file PointAccumulator pa; // Point accumulator holding the subtracted point set std::string tempPointFileNameTemplate="/tmp/LidarPreprocessorTempPoints"; for(int i=1;i<argc;++i) { if(argv[i][0]=='-') { if(strcasecmp(argv[i]+1,"o")==0) { ++i; if(i<argc) outputFileName=argv[i]; else std::cerr<<"Dangling -o flag on command line"<<std::endl; } else if(strcasecmp(argv[i]+1,"np")==0) { ++i; if(i<argc) maxPointsPerNode=(unsigned int)(atoi(argv[i])); else std::cerr<<"Dangling -np flag on command line"<<std::endl; } else if(strcasecmp(argv[i]+1,"ooc")==0) { ++i; if(i<argc) pa.setMemorySize(atoi(argv[i]),pa.getMaxNumPointsPerNode()); else std::cerr<<"Dangling -ooc flag on command line"<<std::endl; } else if(strcasecmp(argv[i]+1,"to")==0) { ++i; if(i<argc) { std::string tempOctreeFileNameTemplate=argv[i]; pa.setTempOctreeFileNameTemplate(tempOctreeFileNameTemplate+"XXXXXX"); } else std::cerr<<"Dangling -to flag on command line"<<std::endl; } else if(strcasecmp(argv[i]+1,"tp")==0) { ++i; if(i<argc) tempPointFileNameTemplate=argv[i]; else std::cerr<<"Dangling -tp flag on command line"<<std::endl; } else if(strcasecmp(argv[i]+1,"eps")==0) { ++i; if(i<argc) epsilon=Scalar(atof(argv[i])); else std::cerr<<"Dangling -eps flag on command line"<<std::endl; } } else if(basePoints==0) { /* Create a processing octree: */ basePoints=new LidarProcessOctree(argv[i],size_t(64)*size_t(1024*1024)); } else if(subtractFileName==0) { /* Store the subtraction file name: */ subtractFileName=argv[i]; for(int i=0;i<3;++i) asciiColumnIndices[i]=i; } else std::cerr<<"Ignoring command line argument "<<argv[i]<<std::endl; } /* Load the subtraction point set into a kd-tree: */ std::vector<Point> subtractPoints; { std::cout<<"Loading subtraction points from "<<subtractFileName<<"..."<<std::flush; IO::ValueSource subtractSource(IO::openFile(subtractFileName)); subtractSource.setWhitespace(',',true); subtractSource.setPunctuation('\n',true); subtractSource.skipWs(); while(!subtractSource.eof()) { /* Read the next point: */ Point p; for(int i=0;i<3;++i) p[i]=Scalar(subtractSource.readNumber()); subtractPoints.push_back(p); /* Skip the rest of the line: */ subtractSource.skipLine(); subtractSource.skipWs(); } std::cout<<" done"<<std::endl; } std::cout<<"Creating kd-tree of "<<subtractPoints.size()<<" subtraction points..."<<std::flush; Geometry::ArrayKdTree<Point>* subtractPointTree=new Geometry::ArrayKdTree<Point>(subtractPoints.size()); Point* points=subtractPointTree->accessPoints(); for(size_t i=0;i<subtractPoints.size();++i) points[i]=subtractPoints[i]; subtractPointTree->releasePoints(4); std::cout<<" done"<<std::endl; /* Process the base point set: */ { std::cout<<"Subtracting points..."<<std::flush; NodePointSubtractor nps(*basePoints,*subtractPointTree,epsilon,pa); basePoints->processNodesPostfix(nps); pa.finishReading(); std::cout<<" done"<<std::endl; } /* Clear input data structures: */ delete basePoints; delete subtractPointTree; /* Construct an octree with less than maxPointsPerNode points per leaf: */ LidarOctreeCreator tree(pa.getMaxNumCacheablePoints(),maxPointsPerNode,pa.getTempOctrees(),tempPointFileNameTemplate+"XXXXXX"); /* Delete the temporary point octrees: */ pa.deleteTempOctrees(); /* Write the octree structure and data to the destination LiDAR file: */ tree.write(outputFileName); return 0; }
int main(int argc,char* argv[]) { /* Set default values for all parameters: */ unsigned int memoryCacheSize=512; unsigned int tempOctreeMaxNumPointsPerNode=4096; std::string tempOctreeFileNameTemplate="/tmp/LidarPreprocessorTempOctree"; unsigned int maxNumPointsPerNode=4096; int numThreads=1; std::string tempPointFileNameTemplate="/tmp/LidarPreprocessorTempPoints"; try { /* Open LidarViewer's configuration file: */ Misc::ConfigurationFile configFile(LIDARVIEWER_CONFIGFILENAME); Misc::ConfigurationFileSection cfg=configFile.getSection("/LidarPreprocessor"); /* Override program settings from configuration file: */ memoryCacheSize=cfg.retrieveValue<unsigned int>("./memoryCacheSize",memoryCacheSize); tempOctreeMaxNumPointsPerNode=cfg.retrieveValue<unsigned int>("./tempOctreeMaxNumPointsPerNode",tempOctreeMaxNumPointsPerNode); tempOctreeFileNameTemplate=cfg.retrieveValue<std::string>("./tempOctreeFileNameTemplate",tempOctreeFileNameTemplate); maxNumPointsPerNode=cfg.retrieveValue<unsigned int>("./maxNumPointsPerNode",maxNumPointsPerNode); numThreads=cfg.retrieveValue<int>("./numThreads",numThreads); tempPointFileNameTemplate=cfg.retrieveValue<std::string>("./tempPointFileNameTemplate",tempPointFileNameTemplate); } catch(std::runtime_error err) { /* Just ignore the error */ } /* Parse the command line and load the input files: */ unsigned baseMemoryCacheSize=64; // Memory cache size for base octree in MB LidarProcessOctree* basePoints=0; // Octree containing the base point data const char* subtractFileName=0; // Name of ASCII file containing the point set to subtract int asciiColumnIndices[3]={0,1,2}; // Column indices of x, y, z point components in ASCII file Scalar epsilon=Scalar(1.0e-7); // Maximum match point distance PointAccumulator pa; // Point accumulator holding the subtracted point set pa.setMemorySize(memoryCacheSize,tempOctreeMaxNumPointsPerNode); pa.setTempOctreeFileNameTemplate(tempOctreeFileNameTemplate+"XXXXXX"); PointAccumulator::Vector pointOffset=PointAccumulator::Vector::zero; // Offset vector added to points during octree creation const char* outputFileName=0; // Name of resulting LiDAR octree file bool haveOffset=false; // Flag whether an explicit point offset was specified on the command line for(int i=1;i<argc;++i) { if(argv[i][0]=='-') { if(strcasecmp(argv[i]+1,"o")==0) { ++i; if(i<argc) outputFileName=argv[i]; else std::cerr<<"Dangling -o flag on command line"<<std::endl; } else if(strcasecmp(argv[i]+1,"np")==0) { ++i; if(i<argc) maxNumPointsPerNode=(unsigned int)(atoi(argv[i])); else std::cerr<<"Dangling -np flag on command line"<<std::endl; } else if(strcasecmp(argv[i]+1,"nt")==0) { ++i; if(i<argc) numThreads=atoi(argv[i]); else std::cerr<<"Dangling -nt flag on command line"<<std::endl; } else if(strcasecmp(argv[i]+1,"ooc")==0) { ++i; if(i<argc) { memoryCacheSize=(unsigned int)(atoi(argv[i])); pa.setMemorySize(memoryCacheSize,tempOctreeMaxNumPointsPerNode); } else std::cerr<<"Dangling -ooc flag on command line"<<std::endl; } else if(strcasecmp(argv[i]+1,"to")==0) { ++i; if(i<argc) { tempOctreeFileNameTemplate=argv[i]; pa.setTempOctreeFileNameTemplate(tempOctreeFileNameTemplate+"XXXXXX"); } else std::cerr<<"Dangling -to flag on command line"<<std::endl; } else if(strcasecmp(argv[i]+1,"tp")==0) { ++i; if(i<argc) tempPointFileNameTemplate=argv[i]; else std::cerr<<"Dangling -tp flag on command line"<<std::endl; } else if(strcasecmp(argv[i]+1,"lasOffset")==0) { if(i+3<argc) { for(int j=0;j<3;++j) { ++i; pointOffset[j]=atof(argv[i]); } haveOffset=true; } else std::cerr<<"Dangling -lasOffset flag on command line"<<std::endl; } else if(strcasecmp(argv[i]+1,"lasOffsetFile")==0) { ++i; if(i<argc) { /* Read the point offset from a binary file: */ try { IO::FilePtr offsetFile=IO::openFile(argv[i]); offsetFile->setEndianness(Misc::LittleEndian); offsetFile->read(pointOffset.getComponents(),3); haveOffset=true; } catch(std::runtime_error err) { /* Print a warning and carry on: */ std::cerr<<"Ignoring lasOffsetFile argument due to error "<<err.what()<<" when reading file "<<argv[i]<<std::endl; } } else std::cerr<<"Dangling -lasOffsetFile flag on command line"<<std::endl; } else if(strcasecmp(argv[i]+1,"eps")==0) { ++i; if(i<argc) epsilon=Scalar(atof(argv[i])); else std::cerr<<"Dangling -eps flag on command line"<<std::endl; } else if(strcasecmp(argv[i]+1,"booc")==0) { ++i; if(i<argc) baseMemoryCacheSize=(unsigned int)(atoi(argv[i])); else std::cerr<<"Dangling -booc flag on command line"<<std::endl; } else if(strcasecmp(argv[i]+1,"columns")==0) { if(i+3<argc) { for(int j=0;j<3;++j) { ++i; asciiColumnIndices[j]=atoi(argv[i]); } } else std::cerr<<"Dangling -columns flag on command line"<<std::endl; } } else if(basePoints==0) { try { /* Create a processing octree: */ basePoints=new LidarProcessOctree(argv[i],size_t(baseMemoryCacheSize)*size_t(1024*1024)); } catch(std::runtime_error err) { std::cerr<<"Cannot open LiDAR file "<<argv[i]<<" due to exception "<<err.what()<<"; terminating"<<std::endl; return 1; } } else if(subtractFileName==0) { /* Store the subtraction file name: */ subtractFileName=argv[i]; } else std::cerr<<"Ignoring command line argument "<<argv[i]<<std::endl; } if(!haveOffset) { /* Use the base point set's point offset for the resulting file: */ pointOffset=-basePoints->getOffset(); } else { PointAccumulator::Vector totalOffset=pointOffset-PointAccumulator::Vector(basePoints->getOffset()); if(totalOffset!=PointAccumulator::Vector::zero) pa.setPointOffset(totalOffset); } /* Load the subtraction point set into a kd-tree: */ std::vector<Point> subtractPoints; try { std::cout<<"Loading subtraction points from "<<subtractFileName<<"..."<<std::flush; IO::ValueSource subtractSource(new IO::ReadAheadFilter(IO::openFile(subtractFileName))); subtractSource.setWhitespace(',',true); subtractSource.setPunctuation('\n',true); subtractSource.skipWs(); const LidarProcessOctree::OffsetVector& offset=basePoints->getOffset(); while(!subtractSource.eof()) { /* Read the next point and subtract the base file's point offset: */ Point p; for(int i=0;i<3;++i) p[i]=Scalar(subtractSource.readNumber()-offset[i]); subtractPoints.push_back(p); /* Skip the rest of the line: */ subtractSource.skipLine(); subtractSource.skipWs(); } std::cout<<" done"<<std::endl; } catch(std::runtime_error err) { std::cout<<" failed"<<std::endl; std::cerr<<"Caught exception "<<err.what()<<"while reading subtraction file "<<subtractFileName<<"; terminating"<<std::endl; return 1; } std::cout<<"Creating kd-tree of "<<subtractPoints.size()<<" subtraction points..."<<std::flush; Geometry::ArrayKdTree<Point>* subtractPointTree=new Geometry::ArrayKdTree<Point>(subtractPoints.size()); Point* points=subtractPointTree->accessPoints(); for(size_t i=0;i<subtractPoints.size();++i) points[i]=subtractPoints[i]; subtractPointTree->releasePoints(numThreads); std::cout<<" done"<<std::endl; /* Process the base point set: */ { std::cout<<"Subtracting points..."<<std::flush; NodePointSubtractor nps(*basePoints,*subtractPointTree,epsilon,pa); basePoints->processNodesPostfix(nps); pa.finishReading(); std::cout<<" done"<<std::endl; } /* Clear input data structures: */ delete basePoints; delete subtractPointTree; /* Construct an octree with less than maxPointsPerNode points per leaf: */ LidarOctreeCreator tree(pa.getMaxNumCacheablePoints(),maxNumPointsPerNode,numThreads,pa.getTempOctrees(),tempPointFileNameTemplate+"XXXXXX"); /* Delete the temporary point octrees: */ pa.deleteTempOctrees(); /* Write the octree structure and data to the destination LiDAR file: */ tree.write(outputFileName); /* Check if a point offset was defined: */ if(pointOffset!=PointAccumulator::Vector::zero) { /* Write the point offsets to an offset file: */ std::string offsetFileName=outputFileName; offsetFileName.append("/Offset"); IO::FilePtr offsetFile(IO::openFile(offsetFileName.c_str(),IO::File::WriteOnly)); offsetFile->setEndianness(Misc::LittleEndian); offsetFile->write(pointOffset.getComponents(),3); } return 0; }