예제 #1
0
//Connect randomly to one of the adjacent points in the spanning tree
void con_frnt()
{
    int n, which, ydelt = 0, xdelt = 0;
    int choice[4];
    int cnt = 0, y, x;

    //Choose a random frontier
    n = rnd(frcnt);
    ny = fr_y[n];
    nx = fr_x[n];
    fr_y[n] = fr_y[frcnt - 1];
    fr_x[n] = fr_x[--frcnt];
    //Count and collect the adjacent points we can connect to
    if (maze_at({ nx, ny - 2 }) > 0) choice[cnt++] = 0;
    if (maze_at({ nx, ny + 2 }) > 0) choice[cnt++] = 1;
    if (maze_at({ nx - 2, ny }) > 0) choice[cnt++] = 2;
    if (maze_at({ nx + 2, ny }) > 0) choice[cnt++] = 3;
    //Choose one of the open places, connect to it and then the task is complete
    which = choice[rnd(cnt)];
    splat({ nx,ny });
    switch (which)
    {
    case 0: which = 1; ydelt = -1; break;
    case 1: which = 0; ydelt = 1; break;
    case 2: which = 3; xdelt = -1; break;
    case 3: which = 2; xdelt = 1; break;
    }
    y = ny + ydelt;
    x = nx + xdelt;
    if (inrange({ x,y })) splat({ x,y });
}
예제 #2
0
    inline void splatFiltered(Vec2f pixel, Vec3f w)
    {
        if (_filter.isDirac()) {
            return;
        } else if (_filter.isBox()) {
            splat(Vec2u(pixel), w);
        } else {
            float px = pixel.x() - 0.5f;
            float py = pixel.y() - 0.5f;

            uint32 minX = max(int(px + 1.0f - _filter.width()), 0);
            uint32 maxX = min(int(px        + _filter.width()), int(_w) - 1);
            uint32 minY = max(int(py + 1.0f - _filter.width()), 0);
            uint32 maxY = min(int(py        + _filter.width()), int(_h) - 1);

            // Maximum filter width is 2 pixels
            float weightX[4], weightY[4];
            for (uint32 x = minX; x <= maxX; ++x)
                weightX[x - minX] = _filter.evalApproximate(x - px);
            for (uint32 y = minY; y <= maxY; ++y)
                weightY[y - minY] = _filter.evalApproximate(y - py);

            for (uint32 y = minY; y <= maxY; ++y)
                for (uint32 x = minX; x <= maxX; ++x)
                    splat(Vec2u(x, y), w*weightX[x - minX]*weightY[y - minY]);
        }
    }
예제 #3
0
static int
printtable(Paragraph *pp, MMIOT *f)
{
    /* header, dashes, then lines of content */

    Line *hdr, *dash, *body;
    Istring align;
    int start;
    int hcols;
    char *p;

    if ( !(pp->text && pp->text->next && pp->text->next->next) )
	return 0;

    hdr = pp->text;
    dash= hdr->next;
    body= dash->next;

    /* first figure out cell alignments */

    CREATE(align);

    for (p=T(dash->text), start=0; start < S(dash->text); ) {
	char first, last;
	int end;
	
	last=first=0;
	for (end=start ; (end < S(dash->text)) && p[end] != '|'; ++ end ) {
	    if ( !isspace(p[end]) ) {
		if ( !first) first = p[end];
		last = p[end];
	    }
	}
	EXPAND(align) = ( first == ':' ) ? (( last == ':') ? CENTER : LEFT)
					 : (( last == ':') ? RIGHT : 0 );
	start = 1+end;
    }

    Qstring("<table>\n", f);
    Qstring("<thead>\n", f);
    hcols = splat(hdr, "th", align, 0, f);
    Qstring("</thead>\n", f);

    if ( hcols > S(align) )
	S(align) = hcols;
    else
	while ( hcols > S(align) )
	    EXPAND(align) = 0;

    Qstring("<tbody>\n", f);
    for ( ; body; body = body->next)
	splat(body, "td", align, 1, f);
    Qstring("</tbody>\n", f);
    Qstring("</table>\n", f);

    DELETE(align);
    return 1;
}
예제 #4
0
void SplatterSystem::spray( const QVector3D & source, float size )
{
	if( size < 10.0f ) size = 10.0f;
	if( size > 100.0f ) size = 100.0f;
	int numToEmit = 0.5f * size;
	if( numToEmit < 1 ) numToEmit = 1;
	mParticleSystem->emitSpherical( source, numToEmit, 0.25f*size, 1.0f*size );

	if( mSplatBelow && mTerrain->getHeightAboveGround( source ) < size*0.5f )
		splat( source, size * RandomNumber::minMax( 0.2f, 0.3f ) );

	int maxSecOffset = 0;
	for( int i=0; i<mBurstSampleSources.size(); ++i )
	{
		if( !mBurstSampleSources[i]->isPlaying() )
		{
			maxSecOffset = i;
			break;
		}
		if( mBurstSampleSources[i]->secOffset() > mBurstSampleSources[maxSecOffset]->secOffset() )
		{
			maxSecOffset = i;
		}
	}
	mBurstSampleSources[maxSecOffset]->setPosition( source );
	mBurstSampleSources[maxSecOffset]->rewind();
	mBurstSampleSources[maxSecOffset]->setPitch( RandomNumber::minMax( 1.0f-mBurstPitchRange*0.5, 1.0+mBurstPitchRange*0.5 ) );
	mBurstSampleSources[maxSecOffset]->play();
}
예제 #5
0
void draw_maze(struct Room *room)
{
    int y, x;
    int fy[MAXFRNT], fx[MAXFRNT];
    int psgcnt;
    Coord spos;

    fr_y = fy;
    fr_x = fx;
    maxx = maxy = 0;
    topy = room->m_ul_corner.y;
    if (topy == 0) topy = ++room->m_ul_corner.y;
    topx = room->m_ul_corner.x;
    //Choose a random spot in the maze and initialize the frontier to be the immediate neighbors of this random spot.
    y = topy;
    x = topx;
    splat({ x,y });
    new_frontier({ x,y });
    //While there are new frontiers, connect them to the path and possibly expand the frontier even more.
    while (frcnt) {
        con_frnt();
        new_frontier({ nx,ny });
    }
    //According to the Grand Beeking, every maze should have a loop. Don't worry if you don't understand this.
    room->m_size.x = maxx - room->m_ul_corner.x + 1;
    room->m_size.y = maxy - room->m_ul_corner.y + 1;
    do
    {
        static Coord ld[4] = { -1, 0, 0, 1, 1, 0, 0, -1 };
        Coord *cp;
        int sh;

        rnd_pos(room, &spos);
        for (psgcnt = 0, cp = ld, sh = 1; cp < &ld[4]; sh <<= 1, cp++)
        {
            y = cp->y + spos.y; x = cp->x + spos.x;
            if (!offmap({ x,y }) && game->level().get_tile({ x, y }) == PASSAGE) psgcnt += sh;
        }
    } while (game->level().get_tile(spos) == PASSAGE || psgcnt % 5);
    splat(spos);
}
예제 #6
0
void BrickDensityRegion::loadOceanData(string file, Vec3 vol_res, int iso_min, int iso_max) {

     m_brickData = BrickGrid(vol_res.x(),vol_res.y(),vol_res.z());

     SciDataParser parser = SciDataParser();

     parser.parseFile(file);

     vector<SciData> data = parser.getData();
     
     Vec3 minLoc = parser.getMinLoc();
     Vec3 maxLoc = parser.getMaxLoc();
     Vec3 locDiff = maxLoc - minLoc;

     printf("MIN: <%f, %f, %f>\n", minLoc.x(), minLoc.y(), minLoc.z());

     printf("MAX: <%f, %f, %f>\n", maxLoc.x(), maxLoc.y(), maxLoc.z());

     double minO2 = parser.getMinO2();
     double maxO2 = parser.getMaxO2();
     double O2diff = maxO2 - minO2;

     printf("MIN: %f, MAX: %f\n", minO2, maxO2);

     Vec3 tmpLoc;
     double tmpO2;
     SciData dPoint;

     int end_x, end_y, end_z;
     double end_density;

     for( int i = 0; i < data.size(); i++ ) {
         dPoint = data.at(i);

         // Normalize location
         tmpLoc = dPoint.getLocation();
         tmpLoc = tmpLoc - minLoc;
         tmpLoc.x( tmpLoc.x() / locDiff.x());
         tmpLoc.y( tmpLoc.y() / locDiff.y());
         tmpLoc.z( tmpLoc.z() / locDiff.z());

         tmpO2 = dPoint.getO2Concenration();
         tmpO2 -= minO2;
         tmpO2 /= O2diff;
/*
         printf("WRITING %d\n", tmpO2 * m_density_mult);
         printf("AT LOCATION <%d, %d, %d>\n", (int)(tmpLoc.x() * vol_res.x()),
                 (int)(tmpLoc.y() * vol_res.y()),
                 (int)(tmpLoc.z() * vol_res.z()));
*/
         end_x = (int)(tmpLoc.x() * vol_res.x());
         end_y = (int)(tmpLoc.y() * vol_res.y());
         end_z = (int)(tmpLoc.z() * vol_res.z());
         end_density = tmpO2 * m_density_mult;

         int splatVal;

         if(tmpO2 < 0.4) {
             splatVal = 0;
         }else if(tmpO2 < 0.6) {
             splatVal = 1;
         }else if(tmpO2 < 0.9) {
             splatVal = 2;
         }else if(tmpO2 < 0.95) {
             splatVal = 3;
         }else{
             splatVal = 4;
         }

         if(end_x > 1 && end_x < (vol_res.x() - 1)) {
             if(end_y > 1 && end_y < (vol_res.y() - 1)) {
                if(end_z > 1 && end_z < (vol_res.z() - 1)) {
                    splat(end_x,end_y,end_z, end_density, splatVal);
                }
            }
         }
     }

}
예제 #7
0
파일: cd.c 프로젝트: j0sh/thesis
int main(int argc, char **argv)
{
    if (argc < 6) print_usage(argv);
    char *path = argv[1];
    int start = atoi(argv[2]), end = atoi(argv[3]), i, *bkgc;
    //IplImage *bkg = alignedImageFrom(mkname(path, 1), 8);
    IplImage *bkg = alignedImageFrom(argv[4], 8);
    int dim = plane_coeffs[0] + plane_coeffs[1] + plane_coeffs[2];
    CvSize bsz = cvGetSize(bkg);
    IplImage *d8 = alignedImageFrom(argv[5], 8);
    //IplImage *d8 = alignedImageFrom(mkname(path, 1), 8);
    int w = bsz.width - 8 + 1, h = bsz.height - 8 + 1, sz = w*h;
    kd_tree kdt;

    printf("cd: %s %d %d %s %s\n", path, start, end, argv[4], argv[5]);
    init_g(bkg);
    memset(&kdt, 0, sizeof(kd_tree));

    /*
    IplImage *b32 = cvCreateImage(bsz, IPL_DEPTH_32F, bkg->nChannels);
    IplImage *i32 = cvCreateImage(bsz, IPL_DEPTH_32F, bkg->nChannels);
    IplImage *d32 = cvCreateImage(bsz, IPL_DEPTH_32F, bkg->nChannels);
    IplImage *diff= cvCreateImage(bsz, IPL_DEPTH_32F, bkg->nChannels);
    cvXor(b32, b32, b32, NULL);
    cvXor(d32, d32, d32, NULL);
    cvConvertScale(bkg, b32, 1/255.0, 0);
    for (i = 1; i < start; i++) {
        IplImage *img = alignedImageFrom(mkname(path, i), 8);
        cvConvertScale(img, i32, 1/256.0, 0);
        cvAbsDiff(i32, b32, diff);
        cvRunningAvg(diff, d32, 1.0/start, NULL);
        cvRunningAvg(i32, b32, 1.0/start, NULL);
        cvReleaseImage(&img);
        cvShowImage("avg diff", d32);
        cvWaitKey(1);
        printf("i: %d\r", i);
    }
    cvConvertScale(b32, bkg, 255, 0);
    cvReleaseImage(&b32);
    cvReleaseImage(&i32);
    if (argc >= 6) {
        cvSaveImage(argv[4], bkg, 0);
        cvConvertScale(d32, d8, 255, 0);
        cvSaveImage(argv[5], d8, 0); // difference image
        return 0;
    }
    */

    int *imgc = block_coeffs(d8, plane_coeffs);
    IplImage *rev = splat(imgc, bsz, plane_coeffs);
    free(imgc);
    cvReleaseImage(&rev);
    prop_coeffs(bkg, plane_coeffs, &bkgc);
    kdt_new(&kdt, bkgc, sz, dim);

    /*thread_ctx ctxs[3];
    pthread_t thrs[sizeof(ctxs)/sizeof(thread_ctx)];
    for (i = 0; i < (int)(sizeof(ctxs)/sizeof(thread_ctx)); i++) {
        thread_ctx *ctx = &ctxs[i];
        ctx->start = i+1;
        ctx->end = end;
        ctx->nb = sizeof(ctxs)/sizeof(thread_ctx);
        ctx->path = path;
        ctx->outfile = argc >= 7 ? argv[6] : NULL;
        ctx->bkg = bkg;
        ctx->diff = d8;
        ctx->kdt = &kdt;
        pthread_create(&thrs[i], NULL, run_thr, ctx);
    }
    for (i = 0; i < (int)(sizeof(ctxs)/sizeof(thread_ctx)); i++) {
        pthread_join(thrs[i], NULL);
    }
    printf("all done!\n");*/

    double t;
    char outname[1024];
    memset(outname, '\0', sizeof(outname));
    for (i = start; i <= end; i++) {
        IplImage *img = alignedImageFrom(mkname(path, i), 8);
        double start = get_time();
        if (argc >= 7) snprintf(outname, sizeof(outname), "%s/bin%06d.png", argv[6], i);
        //process(&kdt, bkg, d8, img, outname);
        //test(img);
        cvShowImage("image", img);
        t += (get_time() - start);
        if ((cvWaitKey(1)&255)==27)break; // esc
        cvReleaseImage(&img);
    }
    //free_g();
    kdt_free(&kdt);
    free(bkgc);
    cvReleaseImage(&bkg);
    cvReleaseImage(&d8);
    return 0;
}
예제 #8
0
파일: cd.c 프로젝트: j0sh/thesis
static void process(kd_tree *kdt, IplImage *bkg, IplImage *diff,
    IplImage *img, char *outname)
{
    //int *imgc = block_coeffs(img, plane_coeffs);
    cvAbsDiff(img, bkg, diff_g);
    int *imgc = block_coeffs(diff_g, plane_coeffs);
    CvSize blksz = {(img->width/8)+7, (img->height/8)+7};
    IplImage *xy = prop_match_complete(kdt, imgc, bkg, blksz);
    IplImage *rev = splat(imgc, cvGetSize(img), plane_coeffs);
    xy2blks_special(xy, diff, recon_g, 8);
    cvAbsDiff(rev, recon_g, diff_g);
    cvReleaseImage(&rev);
    /*int *imgc;
    prop_coeffs(diff_g, plane_coeffs, &imgc);
    CvSize blksz = cvGetSize(bkg);
    IplImage *xy = prop_match_complete(kdt, imgc, bkg, blksz);
    xy2img(xy, diff, recon_g);
    cvAbsDiff(diff_g, recon_g, diff_g);*/
    //cvShowImage("diff_g before mul", diff_g);
    //cvAbsDiff(diff_g, diff, diff_g);
    //cvMul(diff_g, idiff, diff_g, 1);
    cvCvtColor(diff_g, gray_g, CV_BGR2GRAY);

    // full pixel dc
    //IplImage *dc = make_dc(gray_g);
    IplImage *mask = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1);
    IplImage *dc_f = cvCreateImage(cvGetSize(img), IPL_DEPTH_32F, 1);
    int *graydc = gck_calc_2d((uint8_t*)gray_g->imageData, img->width, img->height, KERNS, 1);
    IplImage *dc = cvCreateImageHeader(cvGetSize(img), IPL_DEPTH_32S, 1);
    int step = img->width + KERNS - 1;
    cvSetData(dc, graydc, step*sizeof(int));
    cvConvertScale(dc, dc_f, 1/255.0, 0);
    cvThreshold(gray_g, mask, 25, 255.0, CV_THRESH_BINARY);

    mask->width = orig_w;
    mask->height = orig_h;
    if (*outname) cvSaveImage(outname, mask, 0);

    /*double min = 0, max = 0;
    cvMinMaxLoc(dc, &min, &max, NULL, NULL, NULL);
    printf("min: %3f max: %3f\n", min, max);
    CvScalar scalar = cvRealScalar(-min);
    cvAddS(dc, scalar, dc_f, NULL);
    cvConvertScale(dc_f, dc_f, 1.0/(max - min), 0);*/

    // macroblock based counts
    //cvAdaptiveThreshold(gray_g, mask_g, 255, CV_ADAPTIVE_THRESH_GAUSSIAN_C, CV_THRESH_BINARY, 3, 0);

    //cvSmooth(mask_g, mask_g, CV_GAUSSIAN, 9, 9, 0, 0);
    //cvSmooth(diff_g, diff_g, CV_GAUSSIAN, 5, 5, 0, 0);
    //cvLaplace(diff_g, lap_g, 3);
    //IplImage *xy = prop_match(bkg, img);
    //xy2img(xy, bkg, recon_g);
    //cvAbsDiff(recon_g, img, diff_g);
    /*cvShowImage("recon", recon_g);
    //cvShowImage("diff", rev);
    cvShowImage("diff_g", diff_g);
    cvShowImage("img", img);
    cvShowImage("gray", gray_g);
    cvShowImage("dc float", dc_f);
    cvShowImage("mask", mask);
    cvShowImage("dc", dc);*/
    free(imgc);
    cvReleaseImage(&xy);
    cvReleaseImageHeader(&dc);
    free(graydc);
    cvReleaseImage(&mask);
    cvReleaseImage(&dc_f);
}
예제 #9
0
int main(int argc, const char *argv[])
{
   ALLEGRO_EVENT event;
   ALLEGRO_KEYBOARD_STATE kst;
   bool blend;

   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
      return 1;
   }

   al_init_primitives_addon();
   al_install_keyboard();
   al_install_mouse();

   display = al_create_display(W, H);
   if (!display) {
      abort_example("Error creating display\n");
      return 1;
   }

   black = al_map_rgb_f(0.0, 0.0, 0.0);
   white = al_map_rgb_f(1.0, 1.0, 1.0);
   background = al_map_rgb_f(0.5, 0.5, 0.6);

   if (argc > 1 && 0 == strcmp(argv[1], "--memory-bitmap")) {
      al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
   }
   dbuf = al_create_bitmap(W, H);
   if (!dbuf) {
      abort_example("Error creating double buffer\n");
      return 1;
   }

   al_set_target_bitmap(dbuf);
   al_clear_to_color(background);
   draw_clip_rect();
   flip();

   queue = al_create_event_queue();
   al_register_event_source(queue, al_get_keyboard_event_source());
   al_register_event_source(queue, al_get_mouse_event_source());

   while (true) {
      al_wait_for_event(queue, &event);
      if (event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) {
         al_get_keyboard_state(&kst);
         blend = al_key_down(&kst, ALLEGRO_KEY_LSHIFT) ||
            al_key_down(&kst, ALLEGRO_KEY_RSHIFT);
         if (event.mouse.button == 1) {
            plonk(event.mouse.x, event.mouse.y, blend);
         } else {
            splat(event.mouse.x, event.mouse.y, blend);
         }
      }
      else if (event.type == ALLEGRO_EVENT_DISPLAY_SWITCH_OUT) {
         last_x = last_y = -1;
      }
      else if (event.type == ALLEGRO_EVENT_KEY_DOWN &&
         event.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
      {
         break;
      }
   }

   al_destroy_event_queue(queue);
   al_destroy_bitmap(dbuf);

   return 0;
}
void FFTMagnitudeSelectionUGenInternal::processBlock(bool& shouldDelete, const unsigned int blockID, const int /*channel*/) throw()
{
	const int blockSize = uGenOutput.getBlockSize();
	int numSamplesToProcess = blockSize;
	float* inputSamples = inputs[Input].processBlock(shouldDelete, blockID, 0);
	float* bufferSamples = inputBuffer.getData();
	
	// get output pointers
	for(int channel = 0; channel < bins.length(); channel++)
	{
		outputSampleData[channel] = proxies[channel]->getSampleData();
	}	
	
	
	while(numSamplesToProcess > 0)
	{
		int bufferSamplesToProcess = fftSize - bufferIndex;
		
		if(bufferSamplesToProcess > numSamplesToProcess)
		{							
			memcpy(bufferSamples + bufferIndex, inputSamples, numSamplesToProcess * sizeof(float));
			
			bufferIndex += numSamplesToProcess;
			inputSamples += numSamplesToProcess;
			numSamplesToProcess = 0;
		}
		else
		{
			numSamplesToProcess -= bufferSamplesToProcess;
									
			memcpy(bufferSamples + bufferIndex, inputSamples, bufferSamplesToProcess * sizeof(float));
			
			bufferIndex += bufferSamplesToProcess;
			inputSamples += bufferSamplesToProcess;
			bufferSamplesToProcess = 0;
			
			fftEngine.fft(outputBuffer, inputBuffer, true);
			
			magnitudes = fftEngine.rawToMagnitude(outputBuffer, 0, maxNumBins);
			FloatArray floatMag = magnitudes.toArray<float>(0).at(bins);
			magnitudes = Buffer(floatMag);
			
			if(overlap_ > 1)
			{
				memcpy(inputBuffer.getData(), inputBuffer.getData() + hopSize, overlapSize * sizeof(float));
				bufferIndex = fftSize - hopSize;
			}
			else
			{
				bufferIndex = 0;
			}
		}
		
		const int outputSamplesToProcess = hopSize < blockSize ? hopSize : blockSize;
		
		for(int channel = 0; channel < bins.length(); channel++)
		{
			float magnitude = magnitudes.getSampleUnchecked(channel);
			
			splat(outputSampleData[channel], magnitude, outputSamplesToProcess);
			
			outputSampleData[channel] += outputSamplesToProcess;
		}	
		
	}
	
}