int main(int argc, char *argv[]) {
   int len;
   char *mat_file1, *mat_file2;
   double **mat1, **mat2, **result_mat;
   FILE *fp1, *fp2;

   mat_file1 = readLine();
   mat_file2 = readLine();

   fp1 = fopen(mat_file1, "r");
   fp2 = fopen(mat_file2, "r");

   len = mat_length(fp1);
   mat1 = write_matrix(fp1, len);
   norma(mat1, len);

   mat2 = write_matrix(fp2, len);
   norma(mat2, len);

   result_mat = matrix_sum(mat1, mat2, len);
   norma(result_mat, len);

   fclose(fp1);
   fclose(fp2);
   free(mat_file1);
   free(mat_file2);
   freePointers(mat1, len);
   freePointers(mat2, len);
   freePointers(result_mat, len);

   return 0;
}
示例#2
0
static void test_norma() {
    vec3 v;
    v.x = 1;
    v.y = 0;
    v.z = 0;
    assert(norma(&v) == 1);

    v.x = (float)0;
    v.y = (float)(-3);
    v.z = (float)4;
    assert(norma(&v) == 5);
}
void CalculosAlgebraicos::normalizarVector(std::vector<double>* v) {
    double normaDelVector = norma(v);

    for (unsigned int i = 0; i < v->size(); i++){
        v->at(i) /= normaDelVector;
    }
}
示例#4
0
void Vetor::normalizar()
{
	float n = norma();
	if(n == 0)
		return;
	
	m_escalar(1.0f/n);
}
示例#5
0
文件: TP2.c 项目: leagodoy/CamelCase
int validar(FILE * arch, char * cad, t_fecha * fecpr, t_alumno * alu)
{
    char * act=strchr(cad,'\n');
    if(!act)
        return 1;
    *act='\0';
    act=strrchr(cad,'|');
    sscanf(act+1,"%d/%d/%d",&alu->fec_baja.d,&alu->fec_baja.m,&alu->fec_baja.a);
    *act='\0';
    act=strrchr(cad,'|');
    alu->est=*(act+1);
    *act='\0';
    act=strrchr(cad,'|');
    sscanf(act+1,"%d/%d/%d",&alu->fec_ap_ult_mat.d,&alu->fec_ap_ult_mat.m,&alu->fec_ap_ult_mat.a);
    *act='\0';
    act=strrchr(cad,'|');
    sscanf(act+1,"%d",&alu->mat_ap);
    *act='\0';
    act=strrchr(cad,'|');
    strncpy(alu->carr,act+1,sizeof(alu->carr));
    *act='\0';
    act=strrchr(cad,'|');
    sscanf(act+1,"%d/%d/%d",&alu->fec_ing.d,&alu->fec_ing.m,&alu->fec_ing.a);
    *act='\0';
    act=strrchr(cad,'|');
    alu->sexo=*(act+1);
    *act='\0';
    act=strrchr(cad,'|');
    sscanf(act+1,"%d/%d/%d",&alu->fec_nac.d,&alu->fec_nac.m,&alu->fec_nac.a);
    *act='\0';
    act=strrchr(cad,'|');
    strncpy(alu->apyn,act+1,sizeof(alu->apyn));
    norma(alu->apyn);
    *act='\0';
    sscanf(cad,"%ld",&alu->dni);
    if(alu->dni<=10000||alu->dni>=100000000)
        return 1;
    if(alu->fec_baja.d!=31||alu->fec_baja.m!=12||alu->fec_baja.a!=9999)
        return 1;
    if(!validar_fnac(&alu->fec_nac,fecpr))
        return 1;
    if(!validar_fecha_ing(&alu->fec_ing,&alu->fec_nac,fecpr))
        return 1;
    if(!validar_ult_mat(&alu->fec_ap_ult_mat,fecpr,&alu->fec_ing))
        return 1;
    if(alu->sexo!='F'&&alu->sexo!='M')
        return 1;
    if(!validar_carrera(alu->carr))
        return 1;
    if(alu->mat_ap<0)
        return 1;
    if(alu->est!='R')
        return 1;
    return 0;

}
示例#6
0
double Vector::normalize(void) 
{
	double n=norma();

	if (n==0) return 0;

	x/=n;
	y/=n;
	z/=n;

	return n;
} /* normalize */ 
示例#7
0
文件: pde0.c 项目: Infovarius/findif
double deviation(double ****f,int i,int j,int k)
{
const int size_okr=min(1,ghost);
double flux = 0;
int kol=0,l;
   for(l=1;l<=size_okr;l++)
            {
            if(i-l>0)
               {flux += norma(f[1][i][j][k]-f[1][i-l][j][k],f[2][i][j][k]-f[2][i-l][j][k],f[3][i][j][k]-f[3][i-l][j][k],2);
            	kol++;
               }
            if(i+l<m1)
               {flux += norma(f[1][i][j][k]-f[1][i+l][j][k],f[2][i][j][k]-f[2][i+l][j][k],f[3][i][j][k]-f[3][i+l][j][k],2);
            	kol++;
               }
            if(j-l>0)
               {flux += norma(f[1][i][j][k]-f[1][i][j-l][k],f[2][i][j][k]-f[2][i][j-l][k],f[3][i][j][k]-f[3][i][j-l][k],2);
            	kol++;
               }
            if(j+l<m2)
               {flux += norma(f[1][i][j][k]-f[1][i][j+l][k],f[2][i][j][k]-f[2][i][j+l][k],f[3][i][j][k]-f[3][i][j+l][k],2);
            	kol++;
               }
            if(k-l>0)
               {flux += norma(f[1][i][j][k]-f[1][i][j][k-l],f[2][i][j][k]-f[2][i][j][k-l],f[3][i][j][k]-f[3][i][j][k-l],2);
                kol++;
               }
            if(k+l<m3)
               {flux += norma(f[1][i][j][k]-f[1][i][j][k+l],f[2][i][j][k]-f[2][i][j][k+l],f[3][i][j][k]-f[3][i][j][k+l],2);
                kol++;
               }
           };
   flux /= kol;
return(flux);
}                             
示例#8
0
Projetil::Projetil(Unidade &uni, double vx, double vy, double vz,
                   bool amigo)
{
    raio        = 3.0;
    altura      = 2 * raio;
    this->amigo = amigo;

    this->vx = vx;
    this->vy = vy;
    this->vz = vz;

    /* Posição inicial de projétil é exterior à unidade */
    double modulo = norma(vx, vy, vz);
    double k = (uni.getRaio() + raio)/modulo;
    x = uni.getX() + (k * vx);
    y = uni.getY() + (k * vy);
    z = uni.getZ() + (k * vz);
}
示例#9
0
void struct_func(double ****f,int q,double lambda,int size_okr)
       //structural function of order q and multiplier lambda getting from size_okr^3 cube
       // are putting in array s_func
{
int i,j,k,l,m,n,in,jn,dist;
double d,rx,ry,rz,logl;
logl=log(lambda);
for(k=ghost;k<mm3;k+=1)
	{
        for(i=0;i<=kol_masht-1;i++) s_func[k-ghost][i] = num_points[i] = 0;
        for(i=ghost;i<mm1;i++)
        for(j=ghost;j<mm2;j++)
                for(l=-size_okr;l<=size_okr;l++)
                for(m=-size_okr;m<=size_okr;m++)
		for(n=-min(size_okr,k-ghost);n<=min(size_okr,mm3-1-k);n++)
			 {
			 if ((l==0)&&(m==0)&&(n==0)) continue;
                         in = i+l; jn = j+m;
                         if (i+l<ghost) in += mm1-1-ghost;
                         if (j+m<ghost) jn += mm2-1-ghost;
                         if (i+l>=mm1) in -= mm1-1-ghost;
                         if (j+m>=mm2) jn -= mm2-1-ghost;
			 rx = abs(l)*dx[0];
                         ry = abs(m)*dx[1];
                         rz = abs(n)*dx[2];
                         d = sqrt(rx*rx+ry*ry+rz*rz);
                         d = log(d/min_d)/logl;    //(per wave number add "minus")
                         dist=floor(d);
                         s_func[k-ghost][dist]+=norma(f[0][in][jn][k+n]-f[0][i][j][k],
                                                f[1][in][jn][k+n]-f[1][i][j][k],
                                                f[2][in][jn][k+n]-f[2][i][j][k],
                                                q);
                         num_points[dist]++;
                         }
        for(i=0;i<=kol_masht-1&&num_points[i];i++)
                s_func[k-ghost][i]=(s_func[k-ghost][i]/num_points[i]);
	}//"for" per layers
}//struct_func
示例#10
0
void direct(int n, double *lb, double *ub, int maxint, double fglob, double *xbest, double *fbest, double funct(int, double*)){
	int i, nf, maxnf, nint, nconv, nelim;
	int halt, trovato, nmaxdimen;
	intervallo *primo, *start, *curr;
	vertice *convexhull, *currch;
	double fdir, toldiam, tolglob, eps;
	double maxdiam, mindiam, maxdimen, minder;
	double *xdir;
	char ch;

	xdir = (double *)malloc(n*sizeof(double));

	mod_box.lb    = (double *)malloc(n*sizeof(double));
	mod_box.ub    = (double *)malloc(n*sizeof(double));
	mod_box.xtemp = (double *)malloc(n*sizeof(double));
	mod_box.xbar  = (double *)malloc(n*sizeof(double));

	mod_suddividi.vetf1 = (double *)malloc(n*sizeof(double));
	mod_suddividi.vetf2 = (double *)malloc(n*sizeof(double));
	mod_suddividi.xsud  = (double *)malloc(n*sizeof(double));
	mod_suddividi.ysud  = (double *)malloc(n*sizeof(double));
	mod_suddividi.mask  = (int    *)malloc(n*sizeof(int   ));

	for(i=0;i<n;i++) {
		mod_box.lb[i]=lb[i];
		mod_box.ub[i]=ub[i];
		xbest[i] = (ub[i]+lb[i])/2.0;
		xdir[i]  = xbest[i];
		//printf("mb.lb[%d]=%f mb.ub[%d]=%f xbest[%d]=%f\n",
		//	i,mod_box.lb[i],i,mod_box.ub[i],i,xbest[i]);

	}
	printf("\n");

	primo  = (intervallo *)malloc(sizeof(intervallo));
	alloca_intervallo(n, primo);
	start = primo;
	
	/*for(i=0;i<4000000;i++){
		primo->next  = (intervallo *)malloc(sizeof(intervallo));
		primo = primo->next;
		alloca_intervallo(n, primo);
	}*/

	for(i=0;i<n;i++) {
		primo->cent[i]  = 0.5;
		primo->dimen[i] = 1.0;
	}
	primo->maxdim  = 1.0;
	primo->der     = 0.0;
	primo->diam    = norma(n,primo->dimen)/2.0;
	primo->flagloc = 0;
	primo->flagdiv = 1;
	primo->flagcon = 0;
	primo->id      = 1;

	unscalevars(n,primo->cent,xbest);
	*fbest      = funct(n,xbest);
	fdir        = *fbest;
	primo->fint = fdir;

	primo->next = NULL;

	nf          = 1;
	nint        = 1;
	nconv       = 1;
	nelim       = 1;
	toldiam     = 0.0 *sqrt((double)n)/2.0; 
	tolglob     = 1.e-4;
	eps         = 1.e-4;
	//maxnf       = 2000000000;
	halt        = 0;
	trovato     = 0;

	//printf("fbest = %f, nf = %d\n\n",*fbest,nf);

	while(!halt){
		curr     = start;
		maxdiam  = curr->diam;
		mindiam  = curr->diam;
		maxdimen = curr->dimen[0];
		for(i=1;i<n;i++) {
			if(maxdimen < curr->dimen[i]) maxdimen = curr->dimen[i];
		}
		nmaxdimen= 0;
		
		while (curr != NULL){
			if(maxdiam < curr->diam) maxdiam = curr->diam;
			if(mindiam > curr->diam) mindiam = curr->diam;
			if(maxdimen< maxval(n,curr->dimen)){
				maxdimen  = maxval(n,curr->dimen);
				nmaxdimen = 1;
			}
			else if(maxdimen == maxval(n,curr->dimen)){
				nmaxdimen = nmaxdimen + 1;
			}
			curr = curr->next;
		}
		if( ((*fbest-fglob)/(1.0 > fglob ? 1.0 : fglob)) < tolglob){
			trovato = 1;
		}
		else {
			trovato = 0;
		}
		//if( (nf > maxnf) || (nint > maxint) || trovato ){
		if( (nint > maxint) || trovato ){
			halt = 1;
			break;
		}

		convexhull = NULL;
		
		//printf("st %f\n",start->fint);

		ricintervallo(start,&convexhull,&nconv);
				
		//if(convexhull == NULL) printf("convexhull vuoto !!\n");

		riduciconvexhull(convexhull,&nelim,eps,toldiam,fdir);

		//printf("nconv = %d nelim = %d\n\n",nconv,nelim);
		//printf("cv    = %f\n\n",convexhull->inter->fint);

		currch = convexhull;
		
		for(i=1; i<=nelim; i++){
			currch = currch->next;
		}

		//printf("inizio suddivisioni\n\n");
		while (currch != NULL){
			//printf("currch id %d sta su conv.hull\n",currch->inter->id);
			if(currch->inter->flagdiv) 
			  suddividi(currch->inter,n,&nf,&nint,xdir,&fdir,funct);
			currch = currch->next;
		}
		//printf("fine   suddivisioni\n\n");
		
		unscalevars(n,xdir,xbest);
		*fbest = fdir;

	  /*!-------------------------------------------
		! dealloca la lista che memorizza gli
		! intervalli sul convex hull
		!------------------------------------------- */
		currch = convexhull;
		while (currch != NULL){
			currch->inter->flagcon = 0;
			currch = currch->next;
			convexhull->inter = NULL;
			convexhull->next  = NULL;
			free(convexhull);
			convexhull = currch;
		}
		
		//printf("fbest=%f nf=%d nconv=%d nelim=%d diam=%f DIAM=%f\n",fdir,nf,nconv,nelim,mindiam,maxdiam);
		//scanf("%c",&ch);
	}

	printf("\nDIRECT has satisfied the stopping condition.\n");
        //printf("a");
	//deallocate DIRECT structures
	deallocalistaint(start);
        //printf("b");
	free(xdir);
	free(mod_box.lb);
	free(mod_box.ub);
        //printf("c");
	free(mod_box.xtemp);
	free(mod_box.xbar);
	free(mod_suddividi.vetf1);
	free(mod_suddividi.vetf2);
        //printf("d");
	free(mod_suddividi.xsud);
	free(mod_suddividi.ysud);
	free(mod_suddividi.mask);
        //printf("e");
}
示例#11
0
void triplica(intervallo *primo, int n, int ind, double f1, double f2, 
			  int *nint, double *xdir, double *fdir){
	int i;
	intervallo *secondo, *terzo;
	
	secondo = (intervallo *)malloc(sizeof(intervallo));
	terzo   = (intervallo *)malloc(sizeof(intervallo));

	alloca_intervallo(n, secondo);
	alloca_intervallo(n, terzo);

	terzo->next   = primo->next;
	secondo->next = terzo;
	primo->next   = secondo;

	for(i=0;i<n;i++){
		secondo->cent[i] = primo->cent[i];
		terzo->cent[i]   = primo->cent[i];
	}

	secondo->cent[ind] = secondo->cent[ind] + 1.0*primo->dimen[ind]/3.0;
	terzo->cent[ind]   = terzo->cent[ind]   - 1.0*primo->dimen[ind]/3.0;

	for(i=0;i<n;i++){
		secondo->dimen[i] = primo->dimen[i];
		terzo->dimen[i]   = primo->dimen[i];
	}

	primo->dimen[ind]   = primo->dimen[ind]/3.0;
	secondo->dimen[ind] = secondo->dimen[ind]/3.0;
	terzo->dimen[ind]   = terzo->dimen[ind]/3.0;

	primo->maxdim = maxval(n,primo->dimen);
	primo->diam   = norma(n,primo->dimen)/2.0;

	secondo->maxdim = maxval(n,secondo->dimen);
	secondo->diam   = norma(n,secondo->dimen)/2.0;

	terzo->maxdim = maxval(n,terzo->dimen);
	terzo->diam   = norma(n,terzo->dimen)/2.0;

	secondo->fint = f1;

	if(f1 < *fdir){
		*fdir = f1;
		for(i=0;i<n;i++) xdir[i] = secondo->cent[i];
	}

	terzo->fint = f2;

	if(f2 < *fdir){
		*fdir = f2;
		for(i=0;i<n;i++) xdir[i] = terzo->cent[i];
	}

	secondo->flagloc = 0;
	terzo->flagloc   = 0;

	secondo->flagdiv = 1;
	terzo->flagdiv   = 1;

	secondo->flagcon = 0;
	terzo->flagcon   = 0;

	secondo->id      = *nint+1;
	terzo->id        = *nint+2;

	//printf("secondo: %f id: %d cent: %f %f \n",f1,secondo->id,secondo->cent[0],secondo->cent[1]);
	//printf("  terzo: %f id: %d cent: %f %f \n",f2,  terzo->id,  terzo->cent[0],  terzo->cent[1]);

	secondo = NULL;
	terzo   = NULL;
}
void pointline() {
    std::vector<std::string> names;
    std::vector<std::string> secondNames;
    std::ifstream names_fin("../имена.txt");
    std::ifstream secondNames_fin("../фамилии.txt");
    std::copy(std::istream_iterator<std::string>(names_fin),
              std::istream_iterator<std::string>(),
              std::back_inserter(names));

    std::copy(std::istream_iterator<std::string>(secondNames_fin),
              std::istream_iterator<std::string>(),
              std::back_inserter(secondNames));

    srand(621);
    DataBase &db = DataBase::getInstance();
    // create
    TableDescription roads, buildings;
    roads.setName("Дороги");
    roads.setSpatialKey("Дорога", SpatialType::LINE);
    roads.setTemporalKey("Время транзакции", TemporalType::TRANSACTION_TIME);

    buildings.setName("Строения");
    buildings.setSpatialKey("Позиция", SpatialType::POINT);
    buildings.setTemporalKey("Время транзакции", TemporalType::TRANSACTION_TIME);

    AttributeDescription roadName; roadName.type = Type::STRING;
    roadName.name = "Название"; roads.addColumn(roadName);
    AttributeDescription buildingName, buildingType;
    buildingName.type = Type::STRING; buildingName.name = "Название";
    buildingType.type = Type::STRING; buildingType.name = "Тип";
    buildings.addColumn(buildingName); buildings.addColumn(buildingType);

    db.createTable(roads);
    db.createTable(buildings);
    //
    db.showTableHeader("Дороги");
    db.showTableHeader("Строения");

    Attribute m4Atr;
    m4Atr.setName("Название");
    m4Atr.setValue("M4");
    Row m4; m4.addAttribute(m4Atr);
    m4.spatialKey.name = "Дорога";
    m4.spatialKey.type = SpatialType::LINE;
    m4.spatialKey.points = { make_float2(0.1, 0.1),
                                 make_float2(0.2, 0.1),
                                 make_float2(0.1, 0.2),
                                 make_float2(0.1, 0.3),
                                 make_float2(0.3, 0.4),
                                 make_float2(0.4, 0.0),
                                 make_float2(0.5, 0.0),
                                 make_float2(0.7, 0.1),
                                 make_float2(0.5, 0.4),
                                 make_float2(0.5, 0.6),
                                 make_float2(0.4, 0.6),
                                 make_float2(0.4, 0.7),
                                 make_float2(0.8, 0.7),
                                 make_float2(0.9, 0.0)};
    m4.temporalKey.name = "Время транзакции"; m4.temporalKey.type = TemporalType::TRANSACTION_TIME;

    db.insertRow("Дороги", m4);
    db.showTable("Дороги");

    std::vector<std::string> localTypes = {"Кинотеатр", "Кафе", "Ресторан", "Отель", "Шаурма", "Церковь \"Ктулху\"", "Стадион", "Памятник"};

    for (int i = 0; i < 35; i++) {
        Row newBuilding;
        newBuilding.spatialKey.name = "Позиция"; newBuilding.spatialKey.type = SpatialType::POINT;
        newBuilding.spatialKey.points.push_back(make_float2(((rand() / ((double)RAND_MAX))), ((rand() / ((double)RAND_MAX)))));
        newBuilding.temporalKey.name = "Время транзакции"; newBuilding.temporalKey.type = TemporalType::TRANSACTION_TIME;
        Attribute name, type;
        name.setName("Название");
        name.setValue("Улица \"" + names[((rand() / ((double)RAND_MAX))) * names.size()] + "\"");
        type.setName("Тип");
        type.setValue(localTypes[((rand() / ((double)RAND_MAX))) * localTypes.size()]);
        newBuilding.addAttribute(name);
        newBuilding.addAttribute(type);
        db.insertRow("Строения", newBuilding);
    }
    db.showTable("Строения");

    std::vector<Row> roadRows = db.selectRow("Дороги", SELECT_ALL_ROWS()).unwrap();
    auto buildingTT = db.selectTable("Строения").unwrap();
    auto roadTT = db.selectTable("Дороги").unwrap();
    double radious = 0.05;
    auto outTT = db.linexpointPointsInBufferLine(roadTT, buildingTT, radious).unwrap();
    std::vector<Row> buildingRows = db.selectRow("Строения", SELECT_ALL_ROWS()).unwrap();
    std::vector<Row> linexpointRows = db.selectRow(outTT, SELECT_ALL_ROWS()).unwrap();


    db.showTable(outTT);
    if( !glfwInit() )
    {
        fprintf( stderr, "Failed to initialize GLFW\n" );
        exit( EXIT_FAILURE );
    }
    glewExperimental = GL_TRUE;
    glewInit();
    glfwWindowHint(GLFW_SAMPLES, 4);
    GLFWwindow* window = glfwCreateWindow (1000, 1000, "Hello Triangle", NULL, NULL);
    if (!window) {
        fprintf (stderr, "ERROR: could not open window with GLFW3\n");
        glfwTerminate();
    }
    glfwMakeContextCurrent (window);
    reshape(1000, 1000);

    auto set = linexpointRows[0].getAttribute(1).unwrap().getSet().unwrap();
    auto setfiltered = db.filter(set, roadFilter()).unwrap();
    db.showTable(setfiltered);
    auto setRows = db.selectRow(set, SELECT_ALL_ROWS()).unwrap();
    auto setRowsFiltered = db.selectRow(setfiltered, SELECT_ALL_ROWS()).unwrap();

    do{
        glClearColor(1, 1, 1, 1);
        int width, height;
        glfwGetWindowSize(window, &width, &height);
        reshape(width, height);

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glLoadIdentity();
        glTranslatef(-1.0f, -1.0f, 0.0f);
        glScalef(2, 2, 1);
        glPointSize(10.0);
        glLineWidth(2.0);
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glEnable(GL_LINE_SMOOTH);
        glHint(GL_LINE_SMOOTH_HINT,  GL_NICEST);
        for (uint i = 0; i < roadRows.size(); i++) {
            glBegin(GL_LINE_STRIP);
            for (uint j = 0; j < roadRows[i].spatialKey.points.size(); j++) {
                glColor3f(0, 0, 1);
                glVertex2f(roadRows[i].spatialKey.points[j].x, roadRows[i].spatialKey.points[j].y);
            }
            glEnd();
        }
        // отрисовка lineBuffer
        for (uint i = 0; i < roadRows.size(); i++) {
            for (uint j = 0; j < roadRows[i].spatialKey.points.size(); j++) {
                glColor3f(0, 1, 0);
                drawCircle(roadRows[i].spatialKey.points[j].x, roadRows[i].spatialKey.points[j].y, radious, 32);

                if (j + 1 < roadRows[i].spatialKey.points.size()) {
                    float2 a = roadRows[i].spatialKey.points[j];
                    float2 b = roadRows[i].spatialKey.points[j + 1];
                    float2 n = b - a; n = norma(n);
                    n = make_float2(n.y, -n.x);
                    float2 v1 = a + n * radious;
                    float2 v2 = b + n * radious;
                    float2 v3 = b - n * radious;
                    float2 v4 = a - n * radious;
                    glBegin(GL_LINES);
                        glVertex2f(v1.x, v1.y);
                        glVertex2f(v2.x, v2.y);
                        glVertex2f(v3.x, v3.y);
                        glVertex2f(v4.x, v4.y);
                    glEnd();
                }
            }
        }

        for (uint i = 0; i < buildingRows.size(); i++) {
            glBegin(GL_POINTS);
            for (uint j = 0; j < buildingRows[i].spatialKey.points.size(); j++) {
                glColor3f(0, 0, 0);
                glVertex2f(buildingRows[i].spatialKey.points[j].x, buildingRows[i].spatialKey.points[j].y);
            }
            glEnd();
        }

        for (uint i = 0; i < buildingRows.size(); i++) {
            glBegin(GL_POINTS);
            for (uint j = 0; j < buildingRows[i].spatialKey.points.size(); j++) {
                glColor3f(0, 0, 0);
                glVertex2f(buildingRows[i].spatialKey.points[j].x, buildingRows[i].spatialKey.points[j].y);
            }
            glEnd();
        }



        for (uint i = 0; i < setRows.size(); i++) {
            glBegin(GL_POINTS);
                glColor3f(1, 0, 0);
                glVertex2f(setRows[i].spatialKey.points[0].x, setRows[i].spatialKey.points[0].y);
            glEnd();
        }

        for (uint i = 0; i < setRowsFiltered.size(); i++) {
            glBegin(GL_POINTS);
                glColor3f(0.8, 0.0, 0.8);
                glVertex2f(setRowsFiltered[i].spatialKey.points[0].x, setRowsFiltered[i].spatialKey.points[0].y);
            glEnd();
        }



        glfwSwapBuffers(window);
        glfwPollEvents();

    }
    while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS && glfwWindowShouldClose(window) == 0 );
}
示例#13
0
int main ()
{
 	 ifstream fin;
 	 ofstream fout;
 	 char buf[100],filename[100];
 	 char**opt,**param,*mol_package,*mol_prefix,sng[]=".sng",dst[]=".dst",d[]=".d",md[]=".md";
 	 double**points,*temp,*dist_all,*borders;
	  int*labels,**MD;
	  int size=0,size_all=0,usl=0;
 	 int beg,end,i,mol_number,d_number = 0;
 	 FILE*f;
 	 
 	 //for (d_number = 15; d_number < 16; d_number++)
	   //{
 	 temp=rzeros(temp,3);
 	 opt=new char*[4];
     param=new char*[4];
     
 	 for (int j=0;j<4;j++)
 	 {
	  	 opt[j]=new char[12];
         param[j]=new char[1gik jj,vi;[00];
     }
 	 
 	 strcpy(filename,"options.txt");
 	 strcpy(opt[0],"mol_package");//нужен слэш в конце
 	 opt[1]="mol_prefix";
     opt[2]="mol_number";
     opt[3]="d_number";
	  fin.open(filename);
	  cout<<"File with parameters"<<filename<<"\n";
	  if(fin.fail())
	  {
	   	   cerr<<"invalid filename";
	  	   return 0;
      }
      
      while (!fin.eof())
	  {
	   		fin.getline(buf,sizeof(buf));
	   		
	  		for (i=0;i<4;i++)
	  			if (strstr(buf,opt[i])!=0)
	  			   break;
 	 		if (i<4)//остальные параметры не учитываются, они для построения поверхности
	        {	   
			    for (beg=0;beg<100;beg++)
			    	if (buf[beg]=='"')
			    	   break;
	   	   
	   	        beg++;
	   	        
	   	        for (end=beg;end<100;end++)
			    	if (buf[end]=='"')
			    	   break;
			    	   
	   	        end--;
	   	        
	   	        for (int j=beg;j<=end;j++)
	   	        	param[i][j-beg]=buf[j];
	   	        	
	   			param[i][end-beg+1]='\0';
			}
       }
       
       fin.close();
       mol_package=new char[sizeof(param[0])];
       mol_prefix=new char[sizeof(param[1])];
       strcpy(mol_package,param[0]);
       strcpy(mol_prefix,param[1]);
       mol_number=atoi(param[2]);
	   d_number=atoi(param[3]);
	   
	   //cout<<"особые точки посчитаны? (1 - да,0 - нет)\n";
       //cin>>usl;
       usl = 0;
       
	   	   //temp=rzeros(temp,3);
       if (!usl)
		   for (int j=2;j<=mol_number;j++)
		   {	
		   		cout<<j<<"\n" ;  	   
			  singular_points(points,labels,&size,mol_package,mol_prefix,j);
			  cout<<size<<"1\n";
			  size_all+=(size*(size-1))/2;
			  
		  	  filename[0]='\0';
		  	  cout<<"1\n";
			  sprintf(filename,"%s%s%d%s",mol_package,mol_prefix,j,sng);
			  cout<<"File with singular points"<<filename<<"\n";
			  fout.open(filename);
		  	  
		  	  if(fout.fail())
		  	  {
			   	   cerr<<"invalid filename\n";
			  	   return 0;
	      	   }
	      	   
			   fout<<size<<"\n";
			   
			   for (int k=0;k<size;k++)
			   {
			   	   for (int l=0;l<3;l++)
			   	   	   fout<<points[k][l]<<" ";
			   	   	   
		   		   fout<<labels[k]<<"\n";
			   }
			   
			   fout.close();
			   filename[0]='\0';
			   sprintf(filename,"%s%s%d%s",mol_package,mol_prefix,j,dst);
			   cout<<"File with distances"<<filename<<"\n";
			   fout.open(filename);
		  
		  	   if(fout.fail())
		  	   {
		   	   			   cerr<<"invalid filename\n";
	 				  	   return 0;
	      	   }
	      	   
	      	   fout<<(size*(size-1))/2<<"\n";
	      	   
	      	   for (int k=0;k<size-1;k++)
	      	   	   for (int l=k+1;l<size;l++)
	      	   	   {
				   	   if (labels[l]>labels[k])
		               	  fout<<labels[k]<<" "<<labels[l]<<" ";
        	           else
        	           	   fout<<labels[l]<<" "<<labels[k]<<" ";
        	           	   
				   	   minus(temp,points[l],3,points[k],3);			   	   
	      	   	   	   fout<<norma(temp,3)<<"\n";
	      	   	   	   zeros(temp,3);
	               }
	            
				fout.close();
				destroy(points,size);
				delete[] labels;   
	       }
       else 
	       for (int j=1;j<=mol_number;j++)
		   {
		   	   cout<<j<<"\n";
		   	   
		  	  filename[0]='\0';
			  sprintf(filename,"%s%s%d%s",mol_package,mol_prefix,j,dst);
			  cout<<filename<<"\n";
			  f=fopen(filename,"r");
	      	   fscanf(f,"%d",&size);
	      	   size_all+=size;
	      	   fclose(f);
		   }
	   	   
	   dist_all=rzeros(dist_all,size_all);
	   size_all=0;
	   
	   for (int j=1;j<=mol_number;j++)
		   {
		  	  filename[0]='\0';			  
			   
		  	  filename[0]='\0';
			  sprintf(filename,"%s%s%d%s",mol_package,mol_prefix,j,dst);
			  cout<<filename<<"\n";
			  f=fopen(filename,"r");
 	          fscanf(f,"%d",&size);
	      	   
	      	   int l1,l2;
	      	   for (int k=0;k<size;k++)
	      	   	   fscanf(f,"%d %d %lf",&l1,&l2,&dist_all[size_all+k]);
	      	   	   
  	   		   size_all+=size;
	      	   fclose(f);
		   }
		   
		qsort(dist_all,size_all,sizeof(double),(*comp));
		borders=rzeros(borders,d_number-1);
		
		for (int j=0;j<d_number-1;j++)
		 	 borders[j]=dist_all[(int)floor((j+1)*size_all/d_number)];
		 	 
	    filename[0]='\0';
        sprintf(filename,"%s%s%s%d",mol_package,mol_prefix,d,d_number);
        cout<<filename<<"\n";
        fout.open(filename);
		  	  
  	    if (fout.fail())
  	    {
		   	   	 cerr<<"invalid filename";
		  	   	 return 0;
   	    }
	    
	    for (int j=0;j<d_number-1;j++)
 	         fout<<borders[j]<<"\n";
 	    
	    delete[] dist_all;
		MD=rzeros(MD,mol_number,36*d_number);     
        //cin>>i;
        
        for (int j=1;j<=mol_number;j++)
        {
		 	filename[0]='\0';
		    sprintf(filename,"%s%s%d%s",mol_package,mol_prefix,j,dst);
		    cout<<filename<<"\n";
		    f=fopen(filename,"r");
            fscanf(f,"%d",&size);
	      	   
	      	   int l1,l2,i=0;
	      	   double r;
	      	   
			for (int k=0;k<size;k++)
			{
			 	fscanf(f,"%d %d %lf",&l1,&l2,&r);
			 	i=0;
	      	    while ((i<d_number-1)&&(r>borders[i])) i++;	      	    
	      	    MD[j-1][l1-1+6*(l2-1)+36*i]++;
			}
			
			fclose(f);
		}
	filename[0]='\0';
    sprintf(filename,"%s%s%s%d",mol_package,mol_prefix,md,d_number);
    cout<<filename<<"\n";	
	print_f(MD,mol_number,36*d_number,filename);
	
	
	delete[]temp;
	delete[]borders;
	destroy(MD,mol_number);

 	delete[] mol_package;
	delete[] mol_prefix;
	cin>>i;

	return 1;
}