int main(int argc,char *argv[]) { FILE *fp; int state=0; double min[4]={35,3,10,0}; double max[4]={2000,50,1000,200}; int yr,mo,dy,hr,mt; double sc; int index=0,num=0; int mode=0,nbox=3; int n,r; fp=fopen(argv[1],"r"); if (fp==NULL) { fprintf(stderr,"File not found.\n"); exit(-1); } while(FitFreadRadarScan(fp,&state,&src[index],&prm,&fit,0,0,0) !=-1) { TimeEpochToYMDHMS(src[index].st_time,&yr,&mo,&dy,&hr,&mt,&sc); fprintf(stderr,"%.4d-%.2d-%.2d %.2d:%.2d:%.2d\n", yr,mo,dy,hr,mt,(int) sc); FilterBound(15,&src[index],min,max); if (num>2) { FilterRadarScan(mode,nbox,index,src,&dst,15); for (n=0;n<dst.num;n++) { cfit.stid=dst.stid; cfit.time=dst.bm[n].time; cfit.bmnum=dst.bm[n].bm; cfit.cp=dst.bm[n].cpid; cfit.intt.sc=dst.bm[n].intt.sc; cfit.intt.us=dst.bm[n].intt.us; cfit.nave=dst.bm[n].nave; cfit.frang=dst.bm[n].frang; cfit.rsep=dst.bm[n].rsep; cfit.rxrise=dst.bm[n].rxrise; cfit.tfreq=dst.bm[n].freq; cfit.noise=dst.bm[n].noise; cfit.atten=dst.bm[n].atten; cfit.channel=dst.bm[n].channel; cfit.nrang=MAX_RANGE; if (n==0) cfit.scan=1; else cfit.scan=0; cfit.num=0; for (r=0;r<MAX_RANGE;r++) { if (dst.bm[n].sct[r]==0) continue; cfit.rng[cfit.num]=r; cfit.data[cfit.num].gsct=dst.bm[n].rng[r].gsct; cfit.data[cfit.num].p_0=dst.bm[n].rng[r].p_0; cfit.data[cfit.num].p_0_e=dst.bm[n].rng[r].p_0_e; cfit.data[cfit.num].v=dst.bm[n].rng[r].v; cfit.data[cfit.num].v_e=dst.bm[n].rng[r].v_e; cfit.data[cfit.num].p_l=dst.bm[n].rng[r].p_l; cfit.data[cfit.num].p_l_e=dst.bm[n].rng[r].p_l_e; cfit.data[cfit.num].w_l=dst.bm[n].rng[r].w_l; cfit.data[cfit.num].w_l_e=dst.bm[n].rng[r].w_l_e; cfit.num++; } } CFitFwrite(stdout,&cfit); } index++; if (index>2) index=0; num++; } fclose(fp); return 0; }
// // Recursively filter a set of polys defining a convex hull down the Bsp, // splitting it into two halves at each node and adding in the appropriate // face polys at splits. // static void FilterBound ( UModel* Model, FBox* ParentBound, int32 iNode, FPoly** PolyList, int32 nPolys, int32 Outside ) { FMemMark Mark(FMemStack::Get()); FBspNode& Node = Model->Nodes [iNode]; FBspSurf& Surf = Model->Surfs [Node.iSurf]; FVector Base = Surf.Plane * Surf.Plane.W; FVector& Normal = Model->Vectors[Surf.vNormal]; FBox Bound(0); Bound.Min.X = Bound.Min.Y = Bound.Min.Z = +WORLD_MAX; Bound.Max.X = Bound.Max.Y = Bound.Max.Z = -WORLD_MAX; // Split bound into front half and back half. FPoly** FrontList = new(FMemStack::Get(),nPolys*2+16)FPoly*; int32 nFront=0; FPoly** BackList = new(FMemStack::Get(),nPolys*2+16)FPoly*; int32 nBack=0; // Keeping track of allocated FPoly structures to delete later on. TArray<FPoly*> AllocatedFPolys; FPoly* FrontPoly = new FPoly; FPoly* BackPoly = new FPoly; // Keep track of allocations. AllocatedFPolys.Add( FrontPoly ); AllocatedFPolys.Add( BackPoly ); for( int32 i=0; i<nPolys; i++ ) { FPoly *Poly = PolyList[i]; switch( Poly->SplitWithPlane( Base, Normal, FrontPoly, BackPoly, 0 ) ) { case SP_Coplanar: // UE_LOG(LogBSPOps, Log, TEXT("FilterBound: Got coplanar") ); FrontList[nFront++] = Poly; BackList[nBack++] = Poly; break; case SP_Front: FrontList[nFront++] = Poly; break; case SP_Back: BackList[nBack++] = Poly; break; case SP_Split: FrontList[nFront++] = FrontPoly; BackList [nBack++] = BackPoly; FrontPoly = new FPoly; BackPoly = new FPoly; // Keep track of allocations. AllocatedFPolys.Add( FrontPoly ); AllocatedFPolys.Add( BackPoly ); break; default: UE_LOG(LogBSPOps, Fatal, TEXT("FZoneFilter::FilterToLeaf: Unknown split code") ); } } if( nFront && nBack ) { // Add partitioner plane to front and back. FPoly InfiniteEdPoly = FBSPOps::BuildInfiniteFPoly( Model, iNode ); InfiniteEdPoly.iBrushPoly = iNode; SplitPartitioner(Model,PolyList,FrontList,BackList,0,nPolys,nFront,nBack,InfiniteEdPoly,AllocatedFPolys); } else { // if( !nFront ) UE_LOG(LogBSPOps, Log, TEXT("FilterBound: Empty fronthull") ); // if( !nBack ) UE_LOG(LogBSPOps, Log, TEXT("FilterBound: Empty backhull") ); } // Recursively update all our childrens' bounding volumes. if( nFront > 0 ) { if( Node.iFront != INDEX_NONE ) FilterBound( Model, &Bound, Node.iFront, FrontList, nFront, Outside || Node.IsCsg() ); else if( Outside || Node.IsCsg() ) UpdateBoundWithPolys( Bound, FrontList, nFront ); else UpdateConvolutionWithPolys( Model, iNode, FrontList, nFront ); } if( nBack > 0 ) { if( Node.iBack != INDEX_NONE) FilterBound( Model, &Bound,Node.iBack, BackList, nBack, Outside && !Node.IsCsg() ); else if( Outside && !Node.IsCsg() ) UpdateBoundWithPolys( Bound, BackList, nBack ); else UpdateConvolutionWithPolys( Model, iNode, BackList, nBack ); } // Update parent bound to enclose this bound. if( ParentBound ) *ParentBound += Bound; // Delete FPolys allocated above. We cannot use FMemStack::Get() for FPoly as the array data FPoly contains will be allocated in regular memory. for( int32 i=0; i<AllocatedFPolys.Num(); i++ ) { FPoly* AllocatedFPoly = AllocatedFPolys[i]; delete AllocatedFPoly; } Mark.Pop(); }
// Build bounding volumes for all Bsp nodes. The bounding volume of the node // completely encloses the "outside" space occupied by the nodes. Note that // this is not the same as representing the bounding volume of all of the // polygons within the node. // // We start with a practically-infinite cube and filter it down the Bsp, // whittling it away until all of its convex volume fragments land in leaves. void FBSPOps::bspBuildBounds( UModel* Model ) { if( Model->Nodes.Num()==0 ) return; FPoly Polys[6], *PolyList[6]; for( int32 i=0; i<6; i++ ) { PolyList[i] = &Polys[i]; PolyList[i]->Init(); PolyList[i]->iBrushPoly = INDEX_NONE; } new(Polys[0].Vertices)FVector(-HALF_WORLD_MAX,-HALF_WORLD_MAX,HALF_WORLD_MAX); new(Polys[0].Vertices)FVector( HALF_WORLD_MAX,-HALF_WORLD_MAX,HALF_WORLD_MAX); new(Polys[0].Vertices)FVector( HALF_WORLD_MAX, HALF_WORLD_MAX,HALF_WORLD_MAX); new(Polys[0].Vertices)FVector(-HALF_WORLD_MAX, HALF_WORLD_MAX,HALF_WORLD_MAX); Polys[0].Normal =FVector( 0.000000, 0.000000, 1.000000 ); Polys[0].Base =Polys[0].Vertices[0]; new(Polys[1].Vertices)FVector(-HALF_WORLD_MAX, HALF_WORLD_MAX,-HALF_WORLD_MAX); new(Polys[1].Vertices)FVector( HALF_WORLD_MAX, HALF_WORLD_MAX,-HALF_WORLD_MAX); new(Polys[1].Vertices)FVector( HALF_WORLD_MAX,-HALF_WORLD_MAX,-HALF_WORLD_MAX); new(Polys[1].Vertices)FVector(-HALF_WORLD_MAX,-HALF_WORLD_MAX,-HALF_WORLD_MAX); Polys[1].Normal =FVector( 0.000000, 0.000000, -1.000000 ); Polys[1].Base =Polys[1].Vertices[0]; new(Polys[2].Vertices)FVector(-HALF_WORLD_MAX,HALF_WORLD_MAX,-HALF_WORLD_MAX); new(Polys[2].Vertices)FVector(-HALF_WORLD_MAX,HALF_WORLD_MAX, HALF_WORLD_MAX); new(Polys[2].Vertices)FVector( HALF_WORLD_MAX,HALF_WORLD_MAX, HALF_WORLD_MAX); new(Polys[2].Vertices)FVector( HALF_WORLD_MAX,HALF_WORLD_MAX,-HALF_WORLD_MAX); Polys[2].Normal =FVector( 0.000000, 1.000000, 0.000000 ); Polys[2].Base =Polys[2].Vertices[0]; new(Polys[3].Vertices)FVector( HALF_WORLD_MAX,-HALF_WORLD_MAX,-HALF_WORLD_MAX); new(Polys[3].Vertices)FVector( HALF_WORLD_MAX,-HALF_WORLD_MAX, HALF_WORLD_MAX); new(Polys[3].Vertices)FVector(-HALF_WORLD_MAX,-HALF_WORLD_MAX, HALF_WORLD_MAX); new(Polys[3].Vertices)FVector(-HALF_WORLD_MAX,-HALF_WORLD_MAX,-HALF_WORLD_MAX); Polys[3].Normal =FVector( 0.000000, -1.000000, 0.000000 ); Polys[3].Base =Polys[3].Vertices[0]; new(Polys[4].Vertices)FVector(HALF_WORLD_MAX, HALF_WORLD_MAX,-HALF_WORLD_MAX); new(Polys[4].Vertices)FVector(HALF_WORLD_MAX, HALF_WORLD_MAX, HALF_WORLD_MAX); new(Polys[4].Vertices)FVector(HALF_WORLD_MAX,-HALF_WORLD_MAX, HALF_WORLD_MAX); new(Polys[4].Vertices)FVector(HALF_WORLD_MAX,-HALF_WORLD_MAX,-HALF_WORLD_MAX); Polys[4].Normal =FVector( 1.000000, 0.000000, 0.000000 ); Polys[4].Base =Polys[4].Vertices[0]; new(Polys[5].Vertices)FVector(-HALF_WORLD_MAX,-HALF_WORLD_MAX,-HALF_WORLD_MAX); new(Polys[5].Vertices)FVector(-HALF_WORLD_MAX,-HALF_WORLD_MAX, HALF_WORLD_MAX); new(Polys[5].Vertices)FVector(-HALF_WORLD_MAX, HALF_WORLD_MAX, HALF_WORLD_MAX); new(Polys[5].Vertices)FVector(-HALF_WORLD_MAX, HALF_WORLD_MAX,-HALF_WORLD_MAX); Polys[5].Normal =FVector(-1.000000, 0.000000, 0.000000 ); Polys[5].Base =Polys[5].Vertices[0]; // Empty hulls. Model->LeafHulls.Empty(); for( int32 i=0; i<Model->Nodes.Num(); i++ ) Model->Nodes[i].iCollisionBound = INDEX_NONE; FilterBound( Model, NULL, 0, PolyList, 6, Model->RootOutside ); // UE_LOG(LogBSPOps, Log, TEXT("bspBuildBounds: Generated %i hulls"), Model->LeafHulls.Num() ); }
int main(int argc,char *argv[]) { char *envstr; FILE *fp; int s; int state=0; int yr,mo,dy,hr,mt; double sc; int iflg=0; int avlen=120; unsigned char xtd=0; char wrtlog[256]; int pval=0; double min[4]={35,3,10,0}; double max[4]={2000,50,1000,200}; int tflg=0; double alt=300.0; grid.st_time=-1; grid.status=0; grid.pnt=NULL; grid.gsct=0; grid.chn=0; envstr=getenv("SD_RADAR"); if (envstr==NULL) { fprintf(stderr,"Environment variable 'SD_RADAR' must be defined.\n"); exit(-1); } fp=fopen(envstr,"r"); if (fp==NULL) { fprintf(stderr,"Could not locate radar information file.\n"); exit(-1); } network=RadarLoad(fp); fclose(fp); if (network==NULL) { fprintf(stderr,"Failed to read radar information.\n"); exit(-1); } envstr=getenv("SD_HDWPATH"); if (envstr==NULL) { fprintf(stderr,"Environment variable 'SD_HDWPATH' must be defined.\n"); exit(-1); } RadarLoadHardware(envstr,network); fp=fopen(argv[1],"r"); if (fp==NULL) { fprintf(stderr,"File not found.\n"); exit(-1); } while(FitFreadRadarScan(fp,&state,&scn,&prm,&fit,0,0,0) !=-1) { TimeEpochToYMDHMS(scn.st_time,&yr,&mo,&dy,&hr,&mt,&sc); fprintf(stderr,"%.4d-%.2d-%.2d %.2d:%.2d:%.2d\n", yr,mo,dy,hr,mt,(int) sc); FilterBoundType(&scn,tflg); FilterBound(pval,&scn,min,max); if (site==NULL) { radar=RadarGetRadar(network,scn.stid); if (radar==NULL) { fprintf(stderr,"Failed to get radar information.\n"); exit(-1); } site=RadarYMDHMSGetSite(radar,prm.time.yr,prm.time.mo, prm.time.dy,prm.time.hr,prm.time.mt, prm.time.sc); } s=GridTableTest(&grid,&scn,avlen); if (s==1) { GridTableFwrite(stdout,&grid,wrtlog,xtd); } if (scn.num>=16) GridTableMap(&grid,&scn,site,avlen,iflg,alt); } fclose(fp); return 0; }