Exemplo n.º 1
0
int main()
{
	Tent tent(11, 5, 13); //int baseRowPos, int baseColPos, int baseLength
	Box box(5, 65, 4, 7);//int rowPos, int colPos, int width, int height
	tent.draw(); //화면 출력
	box.draw(); //화면출력
	tent.setDirection(0, 1);
	box.setDirection(0, -1);
	for (int k = 0; k <= 20; k++)
	{
		Sleep(75);
		tent.move(); 
		box.move();
	}
	Shape *myShapes[] = { &tent, &box };
	ComplexShape cS(myShapes, 2);

	cS.setDirection(1, 1);
	for (int k = 0; k < 12; k++)
	{
		Sleep(75);
		cS.move();
	}
	box.setDirection(0, 1);
	for (int k = 0; k < 10; k++)
	{
		Sleep(75);
		box.move();
	}
	return 0;
}
Exemplo n.º 2
0
int simple_tent (struct face *given_face, int troid)
{
	double center[3];
	struct cycle *cyc;
	struct vertex *vtx0;
	struct surface *this_srf;

	this_srf = given_face -> srf;
	if (this_srf == NULL) return (0);

	cyc = given_face -> first_cycle;
	if (cyc == NULL)  {
		set_error1 ("(simple_tent): face has no boundary");
		return (0);
	}
	if (cyc -> next != NULL) {
		set_error1 ("(simple_tent): > 1 cycle");
		return (0);
	}
	if (!troid && given_face -> shape == CONVEX) {
		if (!face_center (given_face, center)) {
			if (!fac_centroid (given_face, center)) return (0);
		}
	}
	else {
		if (!fac_centroid (given_face, center)) return (0);
	}
	if (error()) return (0);


	vtx0 = new_vertex (center, NULL, NULL, (struct arc *) NULL, given_face);
	if (error()) return (0);
	link_vertex (this_srf, vtx0);

	if (!tent (given_face, vtx0)) return (0);
	if (error()) return (0);
	return (1);
}
Exemplo n.º 3
0
int multiple_tent (struct face *given_face)
{
	double center[3];
	struct cycle *cyc;
	struct vertex *vtx0;
	struct surface *this_srf;

	this_srf = given_face -> srf;
	if (this_srf == NULL) return (0);

	cyc = given_face -> first_cycle;
	if (cyc == NULL)  {
		set_error1 ("(multiple_tent): face has no boundary");
		return (0);
	}
	if (!fac_centroid (given_face, center)) return (0);
	if (error()) return (0);
	vtx0 = new_vertex (center, NULL, NULL, (struct arc *) NULL, given_face);
	if (error()) return (0);
	link_vertex (this_srf, vtx0);
	if (!tent (given_face, vtx0)) return (0);
	if (error()) return (0);
	return (1);
}
Exemplo n.º 4
0
int main(int argc, char* argv[])
{
    int n123, n1, i, ik, dim, nk, nf, sf, niter, nw;
    int n[SF_MAX_DIM], w[SF_MAX_DIM], k[SF_MAX_DIM];
    int sa[SF_MAX_DIM], na[SF_MAX_DIM], sc[SF_MAX_DIM], nc[SF_MAX_DIM];
    int ma[SF_MAX_DIM], mc[SF_MAX_DIM]; 
    float *data, *wind, *sign, eps, di, dabs;
    char varname[6], *lagfile;
    sf_filter saa, naa, sbb, nbb, scc, ncc;
    sf_file dat, signal, spef, npef, slag, nlag;

    sf_init (argc,argv);
    dat = sf_input("in");
    signal = sf_output("out");

    spef = sf_input("sfilt");
    npef = sf_input("nfilt");

    n123 = sf_filesize(dat);
    if (!sf_histint(spef,"dim",&dim)) sf_error("No dim= in sfilt");

    n1 = 1;
    for (i=0; i < dim; i++) {
	sprintf(varname,"n%d",i+1);
	if (!sf_histint(dat,varname,n+i)) 
	    sf_error("No %s= in input",varname);
	n1 *= n[i];
    }

    if (!sf_histints(spef,"w",w,dim)) sf_error("No w= in sfilt");
    if (!sf_histints(spef,"k",k,dim)) sf_error("No k= in sfilt");

    if (!sf_histints(spef,"a",sa,dim)) sf_error("No a= in sfilt");
    if (!sf_histints(npef,"a",na,dim)) sf_error("No a= in nfilt");

    if (!sf_histints(spef,"center",sc,dim)) sf_error("No center= in sfilt");
    if (!sf_histints(npef,"center",nc,dim)) sf_error("No center= in nfilt");

    nk=nw=1;
    for (i=0; i < dim; i++) {
	nw *= w[i];
	nk *= k[i];
    }

    if (!sf_histint(spef,"n1",&sf)) sf_error("No n1= in sfilt");
    if (!sf_histint(npef,"n1",&nf)) sf_error("No n1= in nfilt");

    sbb = sf_allocatehelix(sf);
    nbb = sf_allocatehelix(nf);

    if (NULL == (lagfile = sf_histstring(spef,"lag")) &&
	NULL == (lagfile = sf_getstring("slag"))) 
	sf_error("Need slag=");
    slag = sf_input(lagfile);
    if (NULL == (lagfile = sf_histstring(npef,"lag")) &&
	NULL == (lagfile = sf_getstring("nlag"))) 
	sf_error("Need nlag=");
    nlag = sf_input(lagfile);

    sf_intread(sbb->lag,sf,slag);
    sf_intread(nbb->lag,nf,nlag);

    if (!sf_getfloat("eps",&eps)) sf_error("Need eps=");
    /* regularization parameter */
    if (!sf_getint("niter",&niter)) niter=20;
    /* number of iterations */

    data = sf_floatalloc(n123);
    sign = sf_floatalloc(n123);

    sf_floatread(data,n123,dat);

    dabs = fabsf(data[0]);
    for (i=1; i < n123; i++) {
	di = fabsf(data[i]);
	if (di > dabs) dabs=di;
    }

    for (i=0; i < n123; i++) {
	data[i] /= dabs;
    }

    saa = (sf_filter) sf_alloc(nk,sizeof(*saa));
    naa = (sf_filter) sf_alloc(nk,sizeof(*naa));

    for (ik=0; ik < nk; ik++) {
	scc = saa+ik;
	ncc = naa+ik;
	scc->nh = sf;
	ncc->nh = nf;
	scc->flt = sf_floatalloc(sf);
	ncc->flt = sf_floatalloc(nf);
	scc->lag = sbb->lag;
	ncc->lag = nbb->lag;
	scc->mis = NULL;
	ncc->mis = NULL;
    }

    wind = sf_floatalloc(nw);

    for (i=0; i < dim; i++) {
	mc[i] = SF_MIN(sc[i],nc[i]);
	ma[i] = SF_MIN(sa[i],na[i]);
    }

    tent (dim, w, mc, ma, wind);
 
    for (i=0; i < n123-n1+1; i += n1) {
	signoi_init (naa, saa, niter, nw, eps, false);
	for (ik=0; ik < nk; ik++) {
	    sf_floatread((naa+ik)->flt,nf,npef);
	    sf_floatread((saa+ik)->flt,sf,spef);
	}
	patching (signoi_lop, data+i, sign+i, dim, k, n, w, wind);
    }

    sf_floatwrite (sign,n123,signal);

    exit(0);
}
Exemplo n.º 5
0
int main(int argc, char* argv[])
{
    int n[2], w[2], k[2], a[2], l[2], n12, w12, i;
    float *wall, *data, *windwt;
    sf_filter aa;
    sf_file wind, out;

    sf_init (argc, argv);
    out = sf_output("out");

    sf_setformat(out,"native_float");

    if (!sf_getint("n1",&n[0])) n[0] = 100;
    if (!sf_getint("n2",&n[1])) n[1] = 30;

    sf_putint(out,"n1",n[0]);
    sf_putint(out,"n2",n[1]);

    if (!sf_getint("w1",&w[0])) w[0] = 17;
    if (!sf_getint("w2",&w[1])) w[1] = 6;

    if (!sf_getint("k1",&k[0])) k[0] = 5;
    if (!sf_getint("k2",&k[1])) k[1] = 11;

    if (!sf_getint("a1",&a[0])) a[0] = 1;
    if (!sf_getint("a2",&a[1])) a[1] = 1;

    if (!sf_getint("lag1",&l[0])) l[0] = 1;
    if (!sf_getint("lag2",&l[1])) l[1] = 1;

    n12 = n[0]*n[1];
    w12 = w[0]*w[1];

    wall = sf_floatalloc(n12);
    data = sf_floatalloc(n12);
    windwt = sf_floatalloc(w12);

    for (i=0; i < n12; i++) {
        wall[i] = 1.;
    }

    aa = sf_allocatehelix (1);
    aa->lag[0] = 1;

    tent (2, w, l, a, windwt);

    if (NULL != sf_getstring("wind")) {
        /* optional output file for window weight */
        wind = sf_output("wind");
        sf_setformat(wind,"native_float");
        sf_putint(wind,"n1",w[0]);
        sf_putint(wind,"n2",w[1]);

        sf_floatwrite (windwt,w12,wind);
        sf_fileclose(wind);
    }

    sf_helicon_init (aa);
    patching (sf_helicon_lop, wall, data, 2, k, n, w, windwt);

    for (i=0; i < n12; i+= n[0]) {
        data[i] = 0.;
    }
    for (i=1; i < n12; i+= n[0]) {
        data[i] = 0.;
    }
    for (i=n[0]-2; i < n12; i+= n[0]) {
        data[i] = 0.;
    }
    for (i=n[0]-1; i < n12; i+= n[0]) {
        data[i] = 0.;
    }

    sf_floatwrite(data,n12,out);


    exit (0);
}
Exemplo n.º 6
0
void
process(int factor, char* filter_name,char* ims_name, char* imd_name) {

    pnm ims = pnm_load(ims_name);
    int cols = pnm_get_width(ims);
    int rows = pnm_get_height(ims);

    int new_cols = factor*cols;
    int new_rows = factor*rows;

    pnm imw = pnm_new(new_cols, rows, PnmRawPpm);
    pnm imd = pnm_new(new_cols, new_rows, PnmRawPpm);


    // ===== Columns interpolation =====
    for(int i=0; i<rows; i++) {
        for(int j=0; j<new_cols; j++) {
            float new_j = (float)j / factor;

            float WF = 0;
            if (strcmp(filter_name, "box")== 0)
                WF = 0.5;
            else if (strcmp(filter_name, "tent")== 0)
                WF = 1.0;
            else if (strcmp(filter_name, "bell")== 0)
                WF = 1.5;
            else if (strcmp(filter_name, "mitch")== 0)
                WF = 2.0;

            float left = new_j - WF;
            float right = new_j + WF;

            int l_int = floor(left);
            int r_int = floor(right);

            float S = 0.0;

            for (int k=l_int; k <= r_int; k++) {

                float h = 0.0;
                if (strcmp(filter_name, "box")== 0)
                    h = box((float)k-new_j);
                else if (strcmp(filter_name, "tent")== 0)
                    h = tent((float)k-new_j);
                else if (strcmp(filter_name, "bell")== 0)
                    h = bell((float)k-new_j);
                else if (strcmp(filter_name, "mitch")== 0)
                    h = mitch((float)k-new_j);

                if (k<0) {
                    S += pnm_get_component(ims, i, 0, 0)*h;
                }
                else if (k>=cols) {
                    S += pnm_get_component(ims, i, cols-1, 0)*h;
                }
                else {
                    S += pnm_get_component(ims, i, k, 0)*h;
                }
            }


            for (int c=0; c<3; c++) {
                pnm_set_component(imw, i, j, c, (unsigned short) S);
            }
        }
    }


    // ===== Rows interpolation =====
    for(int i=0; i<new_rows; i++) {
        for(int j=0; j<new_cols; j++) {
            float new_i = (float) i / factor;

            float WF = 0;
            if (strcmp(filter_name, "box")== 0)
                WF = 0.5;
            else if (strcmp(filter_name, "tent")== 0)
                WF = 1.0;
            else if (strcmp(filter_name, "bell")== 0)
                WF = 1.5;
            else if (strcmp(filter_name, "mitch")== 0)
                WF = 2.0;

            float above = new_i - WF;
            float below = new_i + WF;

            int a_int = floor(above);
            int b_int = floor(below);

            float S = 0.0;

            for (int k=a_int; k <= b_int; k++) {

                float h = 0.0;
                if (strcmp(filter_name, "box")== 0)
                    h = box((float)k-new_i);
                else if (strcmp(filter_name, "tent")== 0)
                    h = tent((float)k-new_i);
                else if (strcmp(filter_name, "bell")== 0)
                    h = bell((float)k-new_i);
                else if (strcmp(filter_name, "mitch")== 0)
                    h = mitch((float)k-new_i);

                if (k<0) {
                    S += pnm_get_component(imw, 0, j, 0)*h;
                }
                else if (k>=rows) {
                    S += pnm_get_component(imw, rows-1, j, 0)*h;
                }
                else {
                    S += pnm_get_component(imw, k, j, 0)*h;
                }
            }

            for (int c=0; c<3; c++) {
                pnm_set_component(imd, i, j, c, (unsigned short) S);
            }
        }
    }



    pnm_save(imd, PnmRawPpm, imd_name);
    pnm_free(ims);
    pnm_free(imw);
    pnm_free(imd);

}
Exemplo n.º 7
0
void qcolor_tent(struct qcolor c1, struct qcolor *output) {
    output->r = tent(c1.r);
    output->g = tent(c1.g);
    output->b = tent(c1.b);
}
Exemplo n.º 8
0
int main(int argc, char* argv[])
{
    bool verb, norm;


    int n[2], w[2], k[2], a[2], l[2], w_out[2], n_out[2];   
    int  n1, n2, n12, i3, n3, w12;
	int  n12_out, w12_out ;
    float d2; 			   /* data parameters */    
    int ntraces, order, L; /* input parameters */
 	float *wall, *data, *windwt;
    
    
    sf_file in, out;// mask;

    sf_init (argc,argv);
    in = sf_input("in");
    out = sf_output("out");
    
    if (SF_FLOAT !=sf_gettype(in)) sf_error("Need float type");    

    if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input");
 
    if (!sf_histint(in,"n2",&n2)) sf_error("No n2= in input");
    if (!sf_histfloat(in,"d2",&d2)) sf_error("No d2= in input");


    n3 = sf_leftsize(in,2); /*number of gathers in the line*/
	if (n3==0) n3=1;    

	n[0]=n1;
	n[1]=n2;	
		
	//TENT PARAMETERS
	a[0] = 1; a[1] = 1; l[0] = 1;	l[1] = 1;
	
	if (!sf_getint("w1",&w[0])) w[0] = n1; /*lenght of patch along the first dimension */
    if (!sf_getint("w2",&w[1])) w[1] = n2; /*lenght of patch along the second dimension */

    if (!sf_getint("k1",&k[0])) k[0] = 1;  /*number of patches along the first dimension */
    if (!sf_getint("k2",&k[1])) k[1] = 1;  /*number of patches along the second dimension */

    if (!sf_getint("order",&order)) order=3;
    /* linear PEF order*/
    if (!sf_getint("ntraces",&ntraces)) ntraces=1;
    /* number of traces to be interpolated */
    
    if (!sf_getbool("verb",&verb)) verb = false;
    /* verbosity flag */

	if (!sf_getbool("norm",&norm)) norm = true;
    /* output normalization flag */


    n12 = n[0]*n[1];
    
	L = ntraces+1;
	
	n_out[0] = n[0];
	n_out[1] = L * (n2-1) + 1;

	n12_out= n_out[0]*n_out[1];
		
	w_out[0] = w[0];
	w_out[1] = L * (w[1]-1) + 1;
	
	w12 = w[0]*w[1];
	w12_out= w_out[0]*w_out[1];

	
	/*sf_warning("n12 =%d",n12);
	sf_warning("n12_out =%d",n12_out);
	sf_warning("w12 =%d",w12);    
	sf_warning("w12_out =%d",w12_out);  
	sf_warning("patches =%d x %d",k[0],k[1]); */
	
	wall = sf_floatalloc(n12);
    data = sf_floatalloc(n12_out);
    windwt = sf_floatalloc(w12_out);


	
	sf_putint  (out,"n2",n_out[1]);
	sf_putfloat  (out,"d2",d2/(ntraces+1));	
  	tent (2, w_out, l, a, windwt);
	for (i3=0;i3<n3;i3++) { 	/*GATHERS LOOP [3rd dimension]*/
	    sf_warning("Gather %d/%d",i3+1,n3);
		
		sf_floatread(wall,n12,in);
 
		patching1(wall, data, 2, k, n, w, n_out, w_out, windwt, order, ntraces ,verb, norm);
	
    	sf_floatwrite(data,n12_out,out);
	} /* END GATHERS LOOP [3rd dimension]*/


	free(wall);
	free(data);
	free(windwt);

    exit(0);
}