예제 #1
0
int main () {

int max,min;
int v[5] = {10,90,30,45,5};
maxmin(v,4,max,min);
std::cout << max << " e " << min << std::endl;

}
예제 #2
0
파일: Geom2D.cpp 프로젝트: reima/sep3d
void ConvexPolygon2D::ClipToRect(const D3DXVECTOR2 &min, const D3DXVECTOR2 &max) {
  D3DXVECTOR2 minmax(min.x, max.y);
  D3DXVECTOR2 maxmin(max.x, min.y);
  ClipToLine(Line2D(min, minmax));
  ClipToLine(Line2D(minmax, max));
  ClipToLine(Line2D(max, maxmin));
  ClipToLine(Line2D(maxmin, min));
}
예제 #3
0
파일: 10.c 프로젝트: miguelbrb/MP
int maxmin(int *v,int N,int tam,int *max,int *min){
    if(tam==N){
        return 0;
    }else{
        if(*max<v[tam]){
            *max=v[tam];
        }
        if(*min>v[tam]){
            *min=v[tam];
        }
        return maxmin(v,N,tam+1,max,min);
    }
}
예제 #4
0
파일: maxmin.cpp 프로젝트: wilsonsf/TI-LP1
void maxmin(int v[], int n, int *max, int *min){
	if (n == 0) {
		return;
	}

	int pos = n-1;
	if (v[pos] > *max) {
		*max = v[pos];
	}
	if (v[pos] < *min) {
		*min = v[pos];
	}
	maxmin(v,n-1,max,min);
}
예제 #5
0
파일: main.cpp 프로젝트: wilsonsf/TI-LP1
int main () {
    int arranjo[] = {1,2,99,5,61,2,3,5,1,23,6,12,-12};
    int tamanho = sizeof(arranjo)/sizeof(int);
    int max = INT_MIN;
    int min = INT_MAX;

    maxmin(arranjo, tamanho, max, min);

    std::cout << "Arranjo = {1,2,3,5,61,2,3,5,1,23,6,12,-12} - tamanho: " 
            << tamanho << std::endl;
    std::cout << "Valor maximo: " << max << std::endl;
    std::cout << "Valor minimo: " << min << std::endl;

    return 0;
}
예제 #6
0
파일: 10.c 프로젝트: miguelbrb/MP
int main(){
    int N=3,v[N];
    printf("Numero de elementos del vector: ");
    scanf("%d",&N);
    iniVector(v,N,0);
    int max=v[0],min=v[0];
    if(N==0){
        printf("Minimo debe haber 1 elemento en el vector\n");
    }else{
        maxmin(v,N,1,&max,&min);
        printf("Maximo: %d\nMinimo: %d\n",max,min);
    }
getch();
return 0;
}
예제 #7
0
int main(void)
{
	int i;
	int v;
	init();
	//for(DEPTH=63; DEPTH<64; DEPTH++)
	DEPTH = 63;
	{
		v = maxmin(lisB, lisA, DEPTH, 0, 0);
		for(i=1; i<=18; i++)
		{
			printf("%d ", lisB[i].x);
		}
		puts("");
		printf("depth:%d v=%d\n", 63-dmax, v);
		//if(v) break;
	}
	system("pause");
	return 0;
}
예제 #8
0
int maxmin(CARD *A, CARD *B, int depth, int flag, int card)
{
	int i, j, k, v, best = -1;
	int num = 0, *move;
	int tmp[5];
	move = movelis[depth];
	if(depth < dmax)
	{
		dmax=depth;
	}
	if(depth == -1) printf("ERROR: 2\n");
	//if(depth == -1) return 0;
	if(B->x == 0) return -1;
	switch(flag)
	{
		case 0:
			num = genall(move, A);
			break;
		case 1:
		case 2:
			num = genpart(move, A, flag, card);
			break;
		case 5:
			num = 0;
			break;
	}
	for(i=0; i<num; i++)
	{
		k = 0;
		for(j=1; j<=18; j++)
		{
			if((1<<j) & move[i])
			{
				tmp[k ++] = A[j].x;
				A[j].x = 0;
			}
		}
		A[0].x -= k;
		v = -maxmin(B, A, depth-1, k, tmp[0]);
		A[0].x += k;
		k = 0;
		for(j=1; j<=18; j++)
		{
			if((1<<j) & move[i])
			{
				A[j].x = tmp[k ++];
			}
		}
		if(v == 1)
		{
			if(depth == DEPTH)
			{
				for(j=1; j<=18; j++)
				{
					if((1<<j) & move[i])
					{
						printf("[%c %d]\t", A[j].x, A[j].y);
					}
				}
				puts("");
			}
			return v;
		}
		if(v == 0) best = 0;
	}
	if(flag && DEPTH != depth)
	{
		v = -maxmin(B, A, depth-1, 0, 0);
		if(v == 1)
		{
			if(depth == DEPTH)
			{
				for(j=1; j<=18; j++)
				{
					if((1<<j) & move[i])
					{
						printf("[%c %d]\t", A[j].x, A[j].y);
					}
				}
				puts("");
			}
			return v;
		}
		if(v == 0) best = 0;
	}
	return best;
}
예제 #9
0
void write_phcx(char* fileName, phcx* cand) {
    FILE* file;
    int indent;
    int i, block, s;
    int sb, si, bin;
    int p, d, a, j;
    int count;
    char *attr[64];
    char content[1024];

    double max, min;

    for (i = 0; i < 64; i++)
        attr[i] = (char*) malloc(1024);

    indent = 0;

    file = fopen(fileName, "w");
    fprintf(file, "<?xml version='1.0'?>\n");
    openTag(file, &indent, "phcf"); // <phcf>
    openTag(file, &indent, "head"); // <head>
    writeTag(file, &indent, "SourceID", cand->header.sourceID);
    writeTag(file, &indent, "Telescope", cand->header.telescope);

    openTag(file, &indent, "Coordinate"); // <Coordinate>
    strcpy(attr[0], "units");
    strcpy(attr[1], "degrees");
    sprintf(content, "%lf", cand->header.ra);
    writeTagAttr(file, &indent, "RA", attr, 1, content);
    sprintf(content, "%lf", cand->header.dec);
    writeTagAttr(file, &indent, "Dec", attr, 1, content);
    writeTag(file, &indent, "Epoch", "J2000");
    closeTag(file, &indent, "Coordinate"); //</Coordinate>

    strcpy(attr[0], "units");
    strcpy(attr[1], "MHz");
    sprintf(content, "%lf", cand->header.centreFreq);
    writeTagAttr(file, &indent, "CentreFreq", attr, 1, content);
    sprintf(content, "%lf", cand->header.bandwidth);
    writeTagAttr(file, &indent, "BandWidth", attr, 1, content);
    sprintf(content, "%lf", cand->header.mjdStart);
    writeTag(file, &indent, "MjdStart", content);
    strcpy(attr[0], "units");
    strcpy(attr[1], "seconds");
    sprintf(content, "%lf", cand->header.observationLength);
    writeTagAttr(file, &indent, "ObservationLength", attr, 1, content);
    for (i = 0; i < cand->nextrakey; i++) {
        strcpy(content,cand->extravalue[i]);
        strcpy(attr[0],cand->extrakey[i]);
        writeTagAttr(file, &indent, "Extra", attr, 1, content);
    }
    closeTag(file, &indent, "head"); //</head>


    for (s = 0; s < cand->nsections; s++) {
        phcx_section* section = cand->sections + s;
        strcpy(attr[0], "name");
        strcpy(attr[1], section->name);
        openTagAttr(file, &indent, "Section", attr, 1);
        openTag(file, &indent, "BestValues");
        strcpy(attr[0], "units");
        strcpy(attr[1], "seconds");
        sprintf(content, "%16.14lf", section->bestTopoPeriod);
        writeTagAttr(file, &indent, "TopoPeriod", attr, 1, content);
        sprintf(content, "%16.14lf", section->bestBaryPeriod);
        writeTagAttr(file, &indent, "BaryPeriod", attr, 1, content);
        sprintf(content, "%lf", section->bestDm);
        writeTag(file, &indent, "Dm", content);
        strcpy(attr[1], "m/s/s");
        sprintf(content, "%lf", section->bestAccn);
        writeTagAttr(file, &indent, "Accn", attr, 1, content);
        strcpy(attr[1], "m/s/s/s");
        sprintf(content, "%lf", section->bestJerk);
        writeTagAttr(file, &indent, "Jerk", attr, 1, content);

        sprintf(content, "%lf", section->bestSnr);
        writeTag(file, &indent, "Snr", content);

        sprintf(content, "%lf", section->bestWidth);
        writeTag(file, &indent, "Width", content);

        closeTag(file, &indent, "BestValues");
        sprintf(content, "%lf", section->tsamp);
        writeTag(file, &indent, "SampleRate", content);

        if (section->subints != NULL) {
            maxmin(section->subints, section->nsubints, section->nbins, &max, &min);
            strcpy(attr[0], "nBins");
            sprintf(attr[1], "%d", section->nbins);
            strcpy(attr[2], "nSub");
            sprintf(attr[3], "%d", section->nsubints);
            strcpy(attr[4], "format");
            strcpy(attr[5], "02X");
            strcpy(attr[6], "min");
            sprintf(attr[7], "%lf", min);
            strcpy(attr[8], "max");
            sprintf(attr[9], "%lf", max);


            openTagAttr(file, &indent, "SubIntegrations", attr, 5);
            hexprint(section->subints, section->nsubints, section->nbins, max, min, file);
            closeTag(file, &indent, "SubIntegrations");
        }

        if (section->subbands != NULL) {
            maxmin(section->subbands, section->nsubbands, section->nbins, &max, &min);
            strcpy(attr[0], "nBins");
            sprintf(attr[1], "%d", section->nbins);
            strcpy(attr[2], "nSub");
            sprintf(attr[3], "%d", section->nsubbands);
            strcpy(attr[4], "format");
            strcpy(attr[5], "02X");
            strcpy(attr[6], "min");
            sprintf(attr[7], "%lf", min);
            strcpy(attr[8], "max");
            sprintf(attr[9], "%lf", max);



            openTagAttr(file, &indent, "SubBands", attr, 5);
            hexprint(section->subbands, section->nsubbands, section->nbins, max, min, file);
            closeTag(file, &indent, "SubBands");
        }
        if (section->pulseProfile != NULL) {

            maxmin(&(section->pulseProfile), 1, section->nbins, &max, &min);
            strcpy(attr[0], "nBins");
            sprintf(attr[1], "%d", section->nbins);
            strcpy(attr[2], "format");
            strcpy(attr[3], "02X");
            strcpy(attr[4], "min");
            sprintf(attr[5], "%lf", min);
            strcpy(attr[6], "max");
            sprintf(attr[7], "%lf", max);


            openTagAttr(file, &indent, "Profile", attr, 4);
            hexprint(&(section->pulseProfile), 1, section->nbins, max, min, file);
            closeTag(file, &indent, "Profile");
        }
        if (section->snrBlock.block != NULL) {
            openTag(file, &indent, "SnrBlock");
            strcpy(attr[0], "nVals");
            sprintf(attr[1], "%d", section->snrBlock.nperiod);
            strcpy(attr[2], "format");
            strcpy(attr[3], "16.12f");
            openTagAttr(file, &indent, "PeriodIndex", attr, 2);
            for (i = 0; i < section->snrBlock.nperiod; i++) {
                fprintf(file, "%1.12f\n", section->snrBlock.periodIndex[i]);
            }
            closeTag(file, &indent, "PeriodIndex");

            strcpy(attr[0], "nVals");
            sprintf(attr[1], "%d", section->snrBlock.ndm);
            strcpy(attr[2], "format");
            strcpy(attr[3], "6.4f");
            openTagAttr(file, &indent, "DmIndex", attr, 2);
            for (i = 0; i < section->snrBlock.ndm; i++) {
                fprintf(file, "%6.4f\n", section->snrBlock.dmIndex[i]);
            }
            closeTag(file, &indent, "DmIndex");

            strcpy(attr[0], "nVals");
            sprintf(attr[1], "%d", section->snrBlock.naccn);
            strcpy(attr[2], "format");
            strcpy(attr[3], "6.4f");
            openTagAttr(file, &indent, "AccnIndex", attr, 2);
            for (i = 0; i < section->snrBlock.naccn; i++) {
                fprintf(file, "%6.4f\n", section->snrBlock.accnIndex[i]);
            }
            closeTag(file, &indent, "AccnIndex");

            strcpy(attr[0], "nVals");
            sprintf(attr[1], "%d", section->snrBlock.njerk);
            strcpy(attr[2], "format");
            strcpy(attr[3], "6.4f");
            openTagAttr(file, &indent, "JerkIndex", attr, 2);
            for (i = 0; i < section->snrBlock.njerk; i++) {
                fprintf(file, "%6.4f\n", section->snrBlock.jerkIndex[i]);
            }
            closeTag(file, &indent, "JerkIndex");

            max = -1e200;
            min = 1e200;
            for (d = 0; d < section->snrBlock.ndm; d++) {
                for (p = 0; p < section->snrBlock.nperiod; p++) {
                    for (a = 0; a < section->snrBlock.naccn; a++) {
                        for (j = 0; j < section->snrBlock.njerk; j++) {
                            if (section->snrBlock.block[d][p][a][j] > max)max = section->snrBlock.block[d][p][a][j];
                            if (section->snrBlock.block[d][p][a][j] < min)min = section->snrBlock.block[d][p][a][j];

                        }
                    }
                }
            }

            strcpy(attr[0], "format");
            sprintf(attr[1], "02X");
            strcpy(attr[2], "min");
            sprintf(attr[3], "%lf", min);
            strcpy(attr[4], "max");
            sprintf(attr[5], "%lf", max);
            openTagAttr(file, &indent, "DataBlock", attr, 3);
            count = 0;
            for (d = 0; d < section->snrBlock.ndm; d++) {
                for (p = 0; p < section->snrBlock.nperiod; p++) {
                    for (a = 0; a < section->snrBlock.naccn; a++) {
                        for (j = 0; j < section->snrBlock.njerk; j++) {
                            i = (int) (255*(section->snrBlock.block[d][p][a][j] - min) / (max - min) + 0.5);
                            fprintf(file, "%02X", i);
                            count++;
                            if (count == 40) {
                                fprintf(file, "\n");
                                count = 0;
                            }
                        }
                    }
                }
            }

            closeTag(file, &indent, "DataBlock");


            closeTag(file, &indent, "SnrBlock");
        }
        for (i = 0; i < section->nextrakey; i++) {
            strcpy(content,section->extravalue[i]);
            strcpy(attr[0],"key");
            strcpy(attr[1],section->extrakey[i]);

            writeTagAttr(file, &indent, "SecExtra", attr, 1, content);
        }

        closeTag(file, &indent, "Section");




    }
    closeTag(file, &indent, "phcf");

    fclose(file);

}
예제 #10
0
//-----------------------------------------------------------------------------
//! SLRectangle::buildMesh fills in the underlying arrays from the SLMesh object
void SLRectangle::buildMesh(SLMaterial* material)
{  
    deleteData();
   
    // Check max. allowed no. of verts
    SLuint uIntNumV64 = (_resX+1) * (_resY+1);
    if (uIntNumV64 > UINT_MAX)
        SL_EXIT_MSG("SLMesh supports max. 2^32 vertices.");

    // allocate new arrays of SLMesh
    numV = (_resX+1) * (_resY+1);
    numI = _resX * _resY * 2 * 3;
    P = new SLVec3f[numV];
    N = new SLVec3f[numV];
    Tc = new SLVec2f[numV];

    if (uIntNumV64 < 65535)
         I16 = new SLushort[numI];
    else I32 = new SLuint[numI];
   
    // Calculate normal from the first 3 corners
    SLVec3f maxmin(_max.x, _min.y, 0);
    SLVec3f minmax(_min.x, _max.y, 0);
    SLVec3f e1(maxmin - _min);
    SLVec3f e2(minmax - _min);
    SLVec3f curN(e1^e2);
    curN.normalize();
   
    //Set one default material index
    mat = material;
   
    // define delta vectors dX & dY and deltas for texCoord dS,dT
    SLVec3f dX = e1 / (SLfloat)_resX;
    SLVec3f dY = e2 / (SLfloat)_resY;
    SLfloat dS = (_tmax.x - _tmin.x) / (SLfloat)_resX;
    SLfloat dT = (_tmax.y - _tmin.y) / (SLfloat)_resY;

    // Build vertex data
    SLuint i = 0;
    for (SLuint y=0; y<=_resY; ++y)
    {  
        SLVec3f curV = _min;
        SLVec2f curT = _tmin;
        curV   += (SLfloat)y*dY;
        curT.y += (SLfloat)y*dT;

        for (SLuint x=0; x<=_resX; ++x, ++i)
        {  
            P[i]  = curV;
            Tc[i] = curT;
            N[i]  = curN;
            curV   += dX;
            curT.x += dS;
        }      
    }
   
    // Build face vertex indexes
    if (I16)
    {
        SLuint v = 0, i = 0; //index for vertices and indexes
        for (SLuint y=0; y<_resY; ++y)
        {  
            for (SLuint x=0; x<_resX; ++x, ++v)
            {  // triangle 1
                I16[i++] = v;
                I16[i++] = v+_resX+2;
                I16[i++] = v+_resX+1;

                // triangle 2
                I16[i++] = v;
                I16[i++] = v+1;
                I16[i++] = v+_resX+2;
            }      
            v++;
        }
    } else
    {
        SLuint v = 0, i = 0; //index for vertices and indexes
        for (SLuint y=0; y<_resY; ++y)
        {  
            for (SLuint x=0; x<_resX; ++x, ++v)
            {  // triangle 1
                I32[i++] = v;
                I32[i++] = v+_resX+2;
                I32[i++] = v+_resX+1;

                // triangle 2
                I32[i++] = v;
                I32[i++] = v+1;
                I32[i++] = v+_resX+2;
            }      
            v++;
        }
    }
}
예제 #11
0
int main(int argc, char* argv[]){
	
	FILE* parameters;
	
	/* parameters of the gaussian */
	int width;
	int length;
	double amplitude;
	double x_0;
	double y_0;
	double sigma_x0;
	double sigma_y0;
	double a_0;
	double b_0;
	double c_0;
	int max,min;
	
	/* parameters for the cookie cutter */
	double x0,y0;
	double FWHM_x,FWHM_y;
	int span_x,span_y;
	int dimx,dimy;
	int x,y;
	
	/* gaussian struct */
	fit_t results,test_g;
	
	/* indexes */
	int i,j;
	int temp;
	
	if(argc != 2){
		printf("NUMERO PARAMETRI INVALIDO\n");
		exit(EXIT_FAILURE);
	}
	
	parameters = fopen(argv[1],"r");
	
	/* LETTURA DEI PARAMETRI */
	fscanf(parameters,"%d\t%d\t",&width,&length);
	fscanf(parameters,"%lf\t%lf\t%lf\t",&amplitude,&x_0,&y_0);
	fscanf(parameters,"%lf\t%lf\t",&sigma_x0,&sigma_y0);
	fscanf(parameters,"%lf\t%lf\t%lf",&a_0,&b_0,&c_0);
	
	/* GAUSSIAN_MATRIX */
	unsigned char matrix[length][width];
	
#if DEBUG
	/* STAMPA DI DEBUG DEI PARAMETRI DELLA GAUSSIANA DA INTERPOLARE */
	printf("Dimensioni della matrice: %d %d\n",width,length);
	printf("Ampiezza: %f\nPosizione asse X: %f\nPosizione asse Y: %f\n",amplitude,x_0,y_0);
	printf("Varianza asse X: %f\nVarianza asse Y: %f\n",sigma_x0,sigma_y0);
	printf("A(x): %f\nB(y): %f\nC: %f\n",a_0,b_0,c_0);
#endif	
	
	/* ASSEGNAZIONE ALLA STRUCT */
	results.A = amplitude;
	results.x_0 = x_0;
	results.y_0 = y_0;
	results.sigma_x = sigma_x0;
	results.sigma_y = sigma_y0;
	results.a = a_0;
	results.b = b_0;
	results.c = c_0;	
	
	/* COSTRUZIONE DELL'IMMAGINE */
	for (i=0;i<length;i++){
		for(j=0;j<width;j++){
			temp = (int) evaluateGaussian(&results,j,i);
			//printf("%d\n",temp);
			matrix[i][j] = temp;
		}
	}
	
	/* WRITING THE IMAGE TO BE FITTED ON A TIFF FILE */
	writeImage((unsigned char *)matrix,(char *) OUTPUT_MATRIX, width, length);
	
	maxmin( (unsigned char*) matrix, width, length, &max, &min);
	
	printf("MAX: %d MIN: %d\n", max, min);
	
	/* a pixel mask is created in order to reduce the dimensione of the region to analyze with the centroid */
	unsigned char *mask = createMask( (unsigned char*) matrix, width, length, max, min, CROP_PARAMETER);
	
#if DEBUG
	writeImage(mask, (char *) "mask.tiff", width, length);
#endif
	
	centroid(mask, width, length, &x0, &y0, &FWHM_x, &FWHM_y);
	
#if DEBUG
	printf("centro in %f - %f\nCon ampiezza %f e %f\n", x0, y0, FWHM_x, FWHM_y);
#endif
	
	delete mask;
	
	/* inizialization for the diameter of the gaussian*/
	span_x = (int) (2 * FWHM_x);
	span_y = (int) (2 * FWHM_y);
	
	/* determination of the dimension of the crop */
	dimx = 2 * span_x + 1;
	dimy = 2 * span_y + 1;
	
	/* inizialization of the position coordinates */
	x = (int) x0;
	y = (int) y0;
	
	/**
	 inizialization of the test_g struct.
	 NOTE: the coordinates of the position (x,y) are relative to the cropped portion of the image.
	 the value of span_x, which is approximately the diameter of the gaussian, is generally not as bad
	 as you may think to start the fit. 
	 */
	test_g.A = max;
	test_g.x_0 = span_x;
	test_g.y_0 = span_y;
	test_g.sigma_x = FWHM_x;
	test_g.sigma_y = FWHM_y;
	test_g.a = 0;
	test_g.b = 0;
	test_g.c = min;
	
	fprintf(risultati, "%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\n", (&test_g)->A, (&test_g)->x_0 + x - span_x, (&test_g)->y_0 + y - span_y, (&test_g)->sigma_x, (&test_g)->sigma_y, (&test_g)->a, (&test_g)->b, (&test_g)->c);
	
	
	/* THIS PART CAN BE ITERATIVE */
	
	unsigned char *cropped = cropImage((unsigned char*) matrix, width, length, x - span_x, x + span_x, y - span_y, y + span_y);
	
#if DEBUG
	writeImage(cropped, (char *) "./CROP.tiff", dimx, dimy);
#endif
	
	for(i=0;i<ITERATION;i++){
		
		/* FIT FUNCTION */
		iteration(cropped, dimx, dimy, &test_g);
		
		fprintf(risultati, "%f\t%f\t%f\t%f\t%f\t%f\t%f\t%f\n", (&test_g)->A, (&test_g)->x_0 + x - span_x, (&test_g)->y_0 + y - span_y, (&test_g)->sigma_x, (&test_g)->sigma_y, (&test_g)->a, (&test_g)->b, (&test_g)->c);
	}
	return 0;
}