예제 #1
0
GLvoid insertPolice(){
	
	// FOR PER TUTTE LE NAVETTE DELLA POLIZIA
	numPoliceDraw=0;	// se il numero di polizia è minore di 2 se ne disegna un'altra fuori dalla sfera dello sfondo
				// questo per evitare che i movimenti (laser, satelliti) siano troppo veloci
	me=g_camera.getPos();
	for(int i=0;i<NUM_POLICE;i++){
		dist=distance(police[i].pos,me);
		if(dist<=DIST_RADAR && police[i].life>0){
		//if(police[i].life>0){	
			if ( (isIllegal() || police[i].life<100) )
			{	// la polizia si muove solo se abbiamo commerciato illegalmente o gli stiamo sparando
				setPosDir(&police[i]);
			}
			drawPolice(policeModel,police[i].pos,police[i].dir);
			numPoliceDraw++;
			//drawShield(police[i].pos,radShootPolice);
			if( (isIllegal() || police[i].life<100) && police[i].dirCorr){
				if(abs(clock()-policeClock)>=CLOCKS_PER_SEC*1) {
					newPoliceLaser(i);
					policeClock=clock();
					glutPostRedisplay();
				}
				//newEnemyLaser(i);
			}
		}
	}
	while (numPoliceDraw<2){ // disegno tante navette fuori dalla sfera dello sfondo
		extraPos=pointDir(me, g_camera.getUp(), 1200);
		drawPolice(policeModel,extraPos,g_camera.getUp());
		numPoliceDraw++;
	}
}
예제 #2
0
/* DISEGNO DELLE NAVICELLE SPAZIALI (solar_system.c) */
GLvoid insertEnemy(){
	
	// FOR PER TUTTI I NEMICI
	numEnemyDraw=0;	// se il numero di polizia è minore di 2 se ne disegna un'altra fuori dalla sfera dello sfondo
				// questo per evitare che i movimenti (laser, satelliti) siano troppo veloci
	me=g_camera.getPos();
	for(int i=0;i<NUM_ENEMY;i++){
		dist=distance(enemy[i].pos,me);
		if(dist<=DIST_RADAR && enemy[i].life>0){
		//if(enemy[i].life>0){
			setPosDir(&enemy[i]);	// gli passo l'indirizzo di memoria dove sta quella variabile
			drawEnemy(enemyModel,enemy[i].pos,enemy[i].dir);
			numEnemyDraw++;
			//drawShield(enemy[i].pos,radShootEnemy);
			// sparo dei nemici
			if(enemy[i].dirCorr && abs(clock()-enemyClock)>=CLOCKS_PER_SEC*1) 
			{
				newEnemyLaser(i);
				enemyClock=clock();
				glutPostRedisplay();
			}
		}
	}
	while (numEnemyDraw<2){ // disegno tante navette fuori dalla sfera dello sfondo
		extraPos=pointDir(me, g_camera.getUp(), 1200);
		drawEnemy(enemyModel,extraPos,g_camera.getUp());
		numEnemyDraw++;
	}
}
예제 #3
0
파일: d8.cpp 프로젝트: kornholi/TauDEM
//Open files, Initialize grid memory, makes function calls to set flowDir, slope, and resolvflats, writes files
int setdird8(char* demfile, char* pointfile, char *slopefile, char *flowfile, int useflowfile)
{
    MPI_Init(NULL,NULL);

    int rank,size;
    MPI_Comm_rank(MCW,&rank);
    MPI_Comm_size(MCW,&size);

    if (rank==0) {
        printf("D8FlowDir version %s\n",TDVERSION);

        if (strlen(pointfile) == 0) {
            printf("WARNING: no output p file specified\n");
        }

        if (strlen(slopefile) == 0) {
            printf("WARNING: no output sd8 file specified\n");
        }

        fflush(stdout);
    }

    MPITimer t;

    t.start("Total");
    t.start("Header read");

    //Read DEM from file
    tiffIO dem(demfile, FLOAT_TYPE);

    long totalX = dem.getTotalX();
    long totalY = dem.getTotalY();
    double dx = dem.getdxA();
    double dy = dem.getdyA();

    linearpart<float> elevDEM(totalX, totalY, dx, dy, MPI_FLOAT, *(float*) dem.getNodata());

    int xstart, ystart;
    int nx = elevDEM.getnx();
    int ny = elevDEM.getny();
    elevDEM.localToGlobal(0, 0, xstart, ystart);
    elevDEM.savedxdyc(dem);

    t.end("Header read");

    if (rank==0) {
        float timeestimate=(2.8e-9*pow((double)(totalX*totalY),1.55)/pow((double) size,0.65))/60+1;  // Time estimate in minutes
        //fprintf(stderr,"%d %d %d\n",totalX,totalY,size);
        fprintf(stderr,"This run may take on the order of %.0f minutes to complete.\n",timeestimate);
        fprintf(stderr,"This estimate is very approximate. \nRun time is highly uncertain as it depends on the complexity of the input data \nand speed and memory of the computer. This estimate is based on our testing on \na dual quad core Dell Xeon E5405 2.0GHz PC with 16GB RAM.\n");
        fflush(stderr);
    }

    uint64_t bytes_to_read = (uint64_t) nx * ny * sizeof(float);
    if (rank == 0) { 
        fprintf(stderr, "Reading input data (%s)... ", humanReadableSize(bytes_to_read).c_str());
    }

    t.start("Data read");

    dem.read(xstart, ystart, ny, nx, elevDEM.getGridPointer(), elevDEM.getGridPointerStride());
    elevDEM.share();
    double data_read_time = t.end("Data read");
   
    if (rank == 0) {
        fprintf(stderr, "done (%s/s).\n", humanReadableSize(bytes_to_read / data_read_time).c_str());
    }

    //Creates empty partition to store new flow direction
    short flowDirNodata = MISSINGSHORT;

    linearpart<short> flowDir(totalX, totalY, dx, dy, MPI_SHORT, flowDirNodata);

    //If using a flowfile, read it in
    if (useflowfile == 1) {
        tiffIO flow(flowfile, SHORT_TYPE);

        linearpart<short> imposedflow(flow.getTotalX(), flow.getTotalY(),
                flow.getdxA(), flow.getdyA(), MPI_SHORT, *(short*) flow.getNodata());

        if (!dem.compareTiff(flow)) {
            printf("Error using imposed flow file.\n");
            return 1;
        }

        for (int j=0; j < elevDEM.getny(); j++) {
            for (int i=0; i < elevDEM.getnx(); i++ ) {
                short data = imposedflow.getData(i,j);

                if (imposedflow.isNodata(i,j) || !imposedflow.hasAccess(i-1,j) || !imposedflow.hasAccess(i+1,j) ||
                        !imposedflow.hasAccess(i,j-1) || !imposedflow.hasAccess(i,j+1)) {
                    //Do nothing
                } else if (data > 0 && data <= 8) {
                    flowDir.setData(i,j,data);
                }
            }
        }
    }

    if (rank == 0) fprintf(stderr, "Calculating flow directions... ");
    t.start("Calculate flow directions");
    uint64_t numFlat = setPosDir(elevDEM, flowDir);
    t.end("Calculate flow directions");
  
    flowDir.share();

    if (strlen(slopefile) > 0)
    {
        t.start("Calculate slope");
        
        //Creates empty partition to store new slopes
        float slopeNodata = -1.0f;
        linearpart<float> slope(totalX, totalY, dx, dy, MPI_FLOAT, slopeNodata);

        calcSlope(flowDir, elevDEM, slope);

        t.end("Calculate slope");

        t.start("Write slope");
        tiffIO slopeIO(slopefile, FLOAT_TYPE, &slopeNodata, dem);
        slopeIO.write(xstart, ystart, ny, nx, slope.getGridPointer(), slope.getGridPointerStride());
        t.end("Write slope");
    }

    uint64_t totalNumFlat = 0;
    MPI_Allreduce(&numFlat, &totalNumFlat, 1, MPI_UINT64_T, MPI_SUM, MCW);
   
    if (rank == 0) {
        fprintf(stderr, "done. %" PRIu64 " flats to resolve.\n", totalNumFlat);
        fflush(stderr);
    }

    t.start("Resolve flats");

    if (totalNumFlat > 0) {
        if (rank == 0) {
            fprintf(stderr, "Finding flat islands...\n");
        }

        std::vector<std::vector<node>> islands;
        std::vector<std::vector<node>> borderingIslands;

        t.start("Find islands");
        findIslands<D8>(flowDir, islands, borderingIslands);
        t.end("Find islands");

        uint64_t localSharedFlats = 0, sharedFlats = 0;
        for (auto& island : borderingIslands) {
            localSharedFlats += island.size();
        }

        t.start("Resolve shared flats");
        MPI_Allreduce(&localSharedFlats, &sharedFlats, 1, MPI_UINT64_T, MPI_SUM, MCW);

        if (rank == 0 && size > 1) {
            fprintf(stderr, "Processing partial flats\n");

            printf("PRL: %llu flats shared across processors (%llu local -> %.2f%% shared)\n",
                    sharedFlats, totalNumFlat - sharedFlats, 100. * sharedFlats / totalNumFlat);
        }

        if (sharedFlats > 0) {
            SparsePartition<int> inc(totalX, totalY, 0);
            size_t lastNumFlat = resolveFlats_parallel_async<D8>(elevDEM, inc, flowDir, borderingIslands);

            if (rank==0) {
                fprintf(stderr, "PRL: Iteration complete. Number of flats remaining: %zu\n", lastNumFlat);
                fflush(stderr);
            }

            // Repeatedly call resolve flats until there is no change across all processors
            while (lastNumFlat > 0) {
                SparsePartition<int> newInc(totalX, totalY, 0);

                lastNumFlat = resolveFlats_parallel_async<D8>(inc, newInc, flowDir, borderingIslands);
                inc = std::move(newInc);

                if (rank==0) {
                    fprintf(stderr, "PRL: Iteration complete. Number of flats remaining: %zu\n", lastNumFlat);
                    fflush(stderr);
                }
            }
        }
        t.end("Resolve shared flats");

        //printf("rank %d: Done, %d islands. Took %.2f seconds\n", rank, numIslands, MPI_Wtime() - flatFindStart);
        //printf("rank %d: %lu bordering islands with %d flats\n", rank, bordering_islands.size(), localSharedFlats);

        t.start("Resolve local flats");
        if (!islands.empty()) {
            SparsePartition<int> inc(totalX, totalY, 0);
            size_t lastNumFlat = resolveFlats<D8>(elevDEM, inc, flowDir, islands);

            if (rank==0) {
                fprintf(stderr, "Iteration complete. Number of flats remaining: %zu\n\n", lastNumFlat);
                fflush(stderr);
            }

            // Repeatedly call resolve flats until there is no change
            while (lastNumFlat > 0)
            {
                SparsePartition<int> newInc(totalX, totalY, 0);

                lastNumFlat = resolveFlats<D8>(inc, newInc, flowDir, islands); 
                inc = std::move(newInc);

                if (rank==0) {
                    fprintf(stderr, "Iteration complete. Number of flats remaining: %zu\n\n", lastNumFlat);
                    fflush(stderr);
                }
            } 
        }
        t.end("Resolve local flats");
    }

    t.end("Resolve flats");

    if (strlen(pointfile) > 0) {
        t.start("Write directions");
        tiffIO pointIO(pointfile, SHORT_TYPE, &flowDirNodata, dem);
        pointIO.write(xstart, ystart, ny, nx, flowDir.getGridPointer(), flowDir.getGridPointerStride());
        t.end("Write directions");
    }

    t.end("Total");
    t.stop();
    //t.save("timing_info");

    MPI_Finalize();
    return 0;
}