//Headers: //#include #include #include //#include #include #include #include "principal.h" #include time_t first, second; using namespace std; using namespace Geometry; //using namespace principal; //-------------------------------------------------------------------------------------------------------------------------------- // RELLENA LA ESTRUCTURA DE VERTICES //-------------------------------------------------------------------------------------------------------------------------------- void Mesh2Estructura(Geometry::Mesh *mesh){ // Calcular el número de vértices long int countv=0; long int counth=0; long int pos=0; long int v1, v2, v3; for (unsigned int i=0; imSubMeshCount; i++){ countv+=mesh->mSubMesh[i].mVertexBuffer->mVertexCount; } Vertex = new float[countv][3]; for (unsigned int i=0; imSubMeshCount; i++){ for (unsigned int j=0; jmSubMesh[i].mVertexBuffer->mVertexCount; j++) { Vertex[pos][0] = mesh->mSubMesh[i].mVertexBuffer->mPosition[j].x; Vertex[pos][1] = mesh->mSubMesh[i].mVertexBuffer->mPosition[j].y; Vertex[pos][2] = mesh->mSubMesh[i].mVertexBuffer->mPosition[j].z; pos++; } } // Calcular el número de hojas for (unsigned int i=0; imSubMeshCount; i++){ counth+=mesh->mSubMesh[i].mIndexCount; } counth=counth/3; // Se supone que cada 3 índices forman una hoja. if ( counth > 0){ Hojasa = new Hoja[counth]; } activas = counth; // Insertar las hojas en la estructura pos=0; for (unsigned int i=0; imSubMeshCount; i++){ for (unsigned int j=0; jmSubMesh[i].mIndexCount/3; j++) { v1=mesh->mSubMesh[i].mIndex[j]; v2=mesh->mSubMesh[i].mIndex[j]; v3=mesh->mSubMesh[i].mIndex[j]; Hojasa[pos].Vertices[0]=(v1-1); Hojasa[pos].Vertices[1]=(v2-1); Hojasa[pos].Vertices[2]=(v3-1); Hojasa[pos].Vertices[3]=(v3-1); Centroh( Hojasa[pos]); GetNormal ( Hojasa[pos]); pos++; } } } //long int LeeVertices (char * arbol) // //{ // FILE* fp_origen; // char linea[256], str[20]; // float x,y,z; // long int countv=0; // bool fin_vertices = false; // // //cuento todos los vertices, y relleno la estructura // if ((fp_origen = fopen (arbol, "r")) == NULL) // printf ("No he podido abrir el fichero %s\n", arbol); // else // { // while ((fgets (linea, 255, fp_origen) != NULL) && (fin_vertices == false)) // // // switch (linea[0]) // { // case '#': // switch ( linea[2]) // { // case 'v': // sscanf(linea,"# %s %lu", str, &countv); // if ( countv > 0) Vertex = new float[2*countv][3]; // printf ( "hay %lu vertices\n",countv); // countv=0; // break; // // default: // break; // // } // break; // case 'v': // switch (linea[1]) // { // case ' ': // sscanf (linea, "v %f %f %f ", &x, &y, &z); // Vertex[countv][0] = x; Vertex[countv][1] = y; Vertex[countv][2] = z; // countv++; // break; // // default : // break; // // } // break; // // // default: // break; // // } // // fclose (fp_origen); // } // return ( countv); // // //} //-------------------------------------------------------------------------------------------------------------------------------- // CUENTA LAS HOJAS QUE HAY EN EL FICHERO //-------------------------------------------------------------------------------------------------------------------------------- //long int CuentaHojas ( char *hojas) //{ // // FILE* fp_hojas; // char linea[256]; // long int counth=0; // // if ((fp_hojas = fopen (hojas, "r")) == NULL) // printf ("No he podido abrir el fichero %s\n", hojas); // else // { // // while (fgets (linea, 255, fp_hojas) != NULL) // // switch (linea[0]) // { // case 'H': // counth++; // break; // // default : // break; // } // // // // fclose (fp_hojas); // // if ( counth > 0){ // Hojasa = new Hoja[2*counth]; // } // } // activas = counth; // return (counth); //} //-------------------------------------------------------------------------------------------------------------------------------- // LEO LAS HOJAS Y RELLENO LA ESTRUCTURA DE DATOS //-------------------------------------------------------------------------------------------------------------------------------- //void LeoHojas (char* hojas) //{ // FILE* fp_hojas; // char linea[256]; // long int v1, v2, v3, h=0; // // if ((fp_hojas = fopen (hojas, "r")) == NULL) // printf ("No he podido abrir el fichero %s\n", hojas); // // else // { // // // while (fgets (linea, 255, fp_hojas) != NULL) // // switch (linea[0]) // { // case 'H': // // fgets (linea, 255, fp_hojas); // sscanf(linea, "f %lu %lu %lu", &v1, &v2, &v3); // // Hojasa[h].Vertices[0]=(v1-1); // Hojasa[h].Vertices[1]=(v2-1); // Hojasa[h].Vertices[2]=(v3-1); // // fgets (linea, 255, fp_hojas); // sscanf(linea, "f %lu %lu %lu", &v1, &v2, &v3); // Hojasa[h].Vertices[3]=(v3-1); // // Centroh( Hojasa[h]); // GetNormal ( Hojasa[h]); // // h++; // break; // // default : // printf( "Hay un error al leer las hojas\n"); // break; // // } // // fclose(fp_hojas); // } // // //} //-------------------------------------------------------------------------------------------------------------------------------- // FUNCIONES AUXILIARES //-------------------------------------------------------------------------------------------------------------------------------- float max ( float a, float b) { if (a>b) return (a); else return(b); } float min ( float a, float b) { if (a>b) return (b); else return(a); } float distan (float x1, float y1, float z1, float x2, float y2, float z2) { float dist = 0; dist = ((x2-x1)*(x2-x1)) + ((y2-y1)*(y2-y1)) + ((z2-z1)*(z2-z1)); return ( dist); } //-------------------------------------------------------------------------------------------------------------------------------- // CALCULA EL CENTRO DE UNA HOJA //-------------------------------------------------------------------------------------------------------------------------------- void Centroh ( Hoja& Hoja1) { float max_x, min_x, max_y, min_y, max_z, min_z; //x1 max_x = max ( max (Vertex[Hoja1.Vertices[0]][0], Vertex[Hoja1.Vertices[1]][0]), max (Vertex[Hoja1.Vertices[2]][0], Vertex[Hoja1.Vertices[3]][0])); min_x = min ( min (Vertex[Hoja1.Vertices[0]][0], Vertex[Hoja1.Vertices[1]][0]), min (Vertex[Hoja1.Vertices[2]][0], Vertex[Hoja1.Vertices[3]][0])); Hoja1.Centro[0] = (max_x + min_x)/2; //y1 max_y = max ( max (Vertex[Hoja1.Vertices[0]][1], Vertex[Hoja1.Vertices[1]][1]), max (Vertex[Hoja1.Vertices[2]][1], Vertex[Hoja1.Vertices[3]][1])); min_y = min ( min (Vertex[Hoja1.Vertices[0]][1], Vertex[Hoja1.Vertices[1]][1]), min (Vertex[Hoja1.Vertices[2]][1], Vertex[Hoja1.Vertices[3]][1])); Hoja1.Centro[1] = (max_y + min_y)/2; //z1 max_z = max ( max (Vertex[Hoja1.Vertices[0]][2], Vertex[Hoja1.Vertices[1]][2]), max (Vertex[Hoja1.Vertices[2]][2], Vertex[Hoja1.Vertices[3]][2])); min_z = min ( min (Vertex[Hoja1.Vertices[0]][2], Vertex[Hoja1.Vertices[1]][2]), min (Vertex[Hoja1.Vertices[2]][2], Vertex[Hoja1.Vertices[3]][2])); Hoja1.Centro[2] = (max_z + min_z)/2; } //-------------------------------------------------------------------------------------------------------------------------------- // CALCULA LA NORMAL DE UNA HOJA //-------------------------------------------------------------------------------------------------------------------------------- void GetNormal (Hoja &aHoja) { float onex, oney, onez; float twox, twoy, twoz; float threex, threey, threez; onex=Vertex[aHoja.Vertices[0]][0]; oney= Vertex[aHoja.Vertices[0]][1]; onez = Vertex[aHoja.Vertices[0]][2]; twox = Vertex[aHoja.Vertices[1]][0]; twoy = Vertex[aHoja.Vertices[1]][1]; twoz = Vertex[aHoja.Vertices[1]][2]; threex = Vertex[aHoja.Vertices[2]][0]; threey = Vertex[aHoja.Vertices[2]][1]; threez = Vertex[aHoja.Vertices[2]][2]; aHoja.Normal[0] = ((twoz-onez)*(threey-oney)) - ((twoy-oney)*(threez-onez)); aHoja.Normal[1] = ((twox-onex)*(threez-onez)) - ((threex-onex)*(twoz-onez)); aHoja.Normal[2] = ((threex-onex)*(twoy-oney)) - ((twox-onex)*(threey-oney)); } //-------------------------------------------------------------------------------------------------------------------------------- // CALCULA LA distancia de Hausdorff ( distancia entre nubes de puntos) //-------------------------------------------------------------------------------------------------------------------------------- float Hausdorff (Hoja &aHoja, Hoja& h2) { float onex, oney, onez; float twox, twoy, twoz; float threex, threey, threez; float fourx, foury, fourz; float x1, y1, z1; float x2, y2, z2; float x3, y3, z3; float x4, y4, z4; float dist1, dist2, dist3, dist4, distmp, dista, distb, dist; onex=Vertex[aHoja.Vertices[0]][0]; oney= Vertex[aHoja.Vertices[0]][1]; onez = Vertex[aHoja.Vertices[0]][2]; twox = Vertex[aHoja.Vertices[1]][0]; twoy = Vertex[aHoja.Vertices[1]][1]; twoz = Vertex[aHoja.Vertices[1]][2]; threex = Vertex[aHoja.Vertices[2]][0]; threey = Vertex[aHoja.Vertices[2]][1]; threez = Vertex[aHoja.Vertices[2]][2]; fourx = Vertex[aHoja.Vertices[3]][0]; foury = Vertex[aHoja.Vertices[3]][1]; fourz = Vertex[aHoja.Vertices[3]][2]; x1 = Vertex[h2.Vertices[0]][0]; y1 = Vertex[h2.Vertices[0]][1]; z1 = Vertex[h2.Vertices[0]][2]; x2 = Vertex[h2.Vertices[1]][0]; y2 = Vertex[h2.Vertices[1]][1]; z2 = Vertex[h2.Vertices[1]][2]; x3 = Vertex[h2.Vertices[2]][0]; y3 = Vertex[h2.Vertices[2]][1]; z3 = Vertex[h2.Vertices[2]][2]; x4 = Vertex[h2.Vertices[3]][0]; y4 = Vertex[h2.Vertices[3]][1]; z4 = Vertex[h2.Vertices[3]][2]; // guardo las distancias mínimas de cada vértice a los 4 contrarios. dist1 = distan ( onex, oney,onez,x1,y1,z1); // vertice 1 con los 4 de la otra hoja distmp = distan ( onex, oney,onez,x2,y2,z2); if ( distmp < dist1) dist1 = distmp; distmp = distan ( onex, oney,onez,x3,y3,z3); if ( distmp < dist1) dist1 = distmp; distmp = distan ( onex, oney,onez,x4,y4,z4); if ( distmp < dist1) dist1 = distmp; // vertice 2 con los 4 de la otra hoja dist2 = distan ( twox, twoy,twoz,x1,y1,z1); distmp = distan ( twox, twoy,twoz,x2,y2,z2); if ( distmp < dist2) dist2 = distmp; distmp = distan ( twox, twoy,twoz,x3,y3,z3); if ( distmp < dist2) dist2 = distmp; distmp = distan ( twox, twoy,twoz,x4,y4,z4); if ( distmp < dist2) dist2 = distmp; // vertice 3 con los 4 de la otra hoja dist3 = distan ( threex, threey,threez,x1,y1,z1); distmp = distan ( threex, threey,threez,x2,y2,z2); if ( distmp < dist3) dist3 = distmp; distmp = distan ( threex, threey,threez,x3,y3,z3); if ( distmp < dist3) dist3 = distmp; distmp = distan ( threex, threey,threez,x4,y4,z4); if ( distmp < dist3) dist3 = distmp; // vertice 4 con los 4 de la otra hoja dist4 = distan ( fourx, foury,fourz,x1,y1,z1); distmp = distan ( fourx, foury,fourz,x2,y2,z2); if ( distmp < dist4) dist4 = distmp; distmp = distan ( fourx, foury,fourz,x3,y3,z3); if ( distmp < dist4) dist4 = distmp; distmp = distan ( fourx, foury,fourz,x4,y4,z4); if ( distmp < dist4) dist4 = distmp; //de entre estos cojo el máximo dista = max(dist1, max(dist2, max(dist3, dist4))); //LO MISMO PERO A LA INVERSA dist1 = distan ( x1,y1,z1, onex, oney, onez); // vertice 1 con los 4 de la otra hoja distmp = distan ( x1,y1,z1, twox, twoy, twoz); if ( distmp < dist1) dist1 = distmp; distmp = distan ( x1,y1,z1, threex, threey, threez); if ( distmp < dist1) dist1 = distmp; distmp = distan ( x1,y1,z1, fourx, foury, fourz); if ( distmp < dist1) dist1 = distmp; //2 dist2 = distan ( x2,y2,z2, onex, oney, onez); // vertice 2 con los 4 de la otra hoja distmp = distan ( x2,y2,z2, twox, twoy, twoz); if ( distmp < dist2) dist2 = distmp; distmp = distan ( x2,y2,z2, threex, threey, threez); if ( distmp < dist2) dist2 = distmp; distmp = distan ( x2,y2,z2, fourx, foury, fourz); if ( distmp < dist2) dist2 = distmp; //3 dist3 = distan ( x3,y3,z3, onex, oney, onez); // vertice 3 con los 4 de la otra hoja distmp = distan ( x3,y3,z3, twox, twoy, twoz); if ( distmp < dist3) dist3 = distmp; distmp = distan ( x3,y3,z3, threex, threey, threez); if ( distmp < dist3) dist3 = distmp; distmp = distan ( x3,y3,z3, fourx, foury, fourz); if ( distmp < dist3) dist3 = distmp; //4 dist4 = distan ( x4,y4,z4, onex, oney, onez); // vertice 4 con los 4 de la otra hoja distmp = distan ( x4,y4,z4, twox, twoy, twoz); if ( distmp < dist4) dist4 = distmp; distmp = distan ( x4,y4,z4, threex, threey, threez); if ( distmp < dist4) dist4 = distmp; distmp = distan ( x4,y4,z4, fourx, foury, fourz); if ( distmp < dist4) dist4 = distmp; // distb = max(dist1, max(dist2, max(dist3, dist4))); dist = max ( dista, distb); return ( dist); } //-------------------------------------------------------------------------------------------------------------------------------- // CALCULA LA DISTANCIA ENTRE HOJAS //-------------------------------------------------------------------------------------------------------------------------------- void DistanciaEntreHojas(void) { float dist, distmp ; int j; for ( int i=0;i Hojasa[i].dist) { mindist = Hojasa[i].dist; cual = i; } } } return (cual); } //-------------------------------------------------------------------------------------------------------------------------------- // CALCULA LA COPLANARIDAD ENTRE HOJAS //-------------------------------------------------------------------------------------------------------------------------------- void CoplanarEntreHojas(FILE* fp_coplanar) { float cop, coptmp ; int j, i; // char linea[250]; for ( i=0;i cop ) // COJO EL MAS COPLANAR , CERCANO A 1 { cop = coptmp; Hojasa[i].hoja_cop = j; } } } Hojasa[i].coplanar = 1 - cop; // 8/6/01 LO INVIERTO } } } //-------------------------------------------------------------------------------------------------------------------------------- // DEVUELVE LA HOJA QUE TIENE MÁS COPLANARIDAD// ya no vale. Ahora la buena será la minima 8/6/01 //-------------------------------------------------------------------------------------------------------------------------------- /*long int MaximaCoplanar ( void) { float maxcop =0; long int cual=-1; int i=0; //inicializo while (Hojasa[i].existe != true) i++; maxcop = Hojasa[i].coplanar; cual =i; //busco la minima for ( i=0;i Vertex[Hojasa[i].Vertices[j]][0]) xmin = Vertex[Hojasa[i].Vertices[j]][0]; if ( ymax < Vertex[Hojasa[i].Vertices[j]][1]) ymax = Vertex[Hojasa[i].Vertices[j]][1]; if ( ymin > Vertex[Hojasa[i].Vertices[j]][1]) ymin = Vertex[Hojasa[i].Vertices[j]][1]; if ( zmax < Vertex[Hojasa[i].Vertices[j]][2]) zmax = Vertex[Hojasa[i].Vertices[j]][2]; if ( zmin > Vertex[Hojasa[i].Vertices[j]][2]) zmin = Vertex[Hojasa[i].Vertices[j]][2]; } } cx = (xmax + xmin)/2; cy = (ymax + ymin)/2; cz = (zmax + zmin)/2; diametro = ((xmax-xmin)*(xmax-xmin)) + ((ymax-ymin)*(ymax-ymin)) + ((zmax-zmin)*(zmax-zmin)); //en la pantalla printf ("Centro %f %f %f\n", cx,cy,cz ); //en el fichero sprintf (linea,"Centro %f %f %f \n",cx, cy, cz); fputs (linea, fp_simplifica); // x sprintf (linea,"x %f %f\n",xmax, xmin); printf (linea,"x %f %f\n",xmax, xmin); fputs (linea, fp_simplifica); // y sprintf (linea,"y %f %f\n",ymax, ymin); printf (linea,"y %f %f\n",ymax, ymin); fputs (linea, fp_simplifica); // z sprintf (linea,"z %f %f\n",zmax, zmin); printf (linea,"z %f %f\n",zmax, zmin); fputs (linea, fp_simplifica); return (diametro); } //-------------------------------------------------------------------------------------------------------------------------------- // normaliza las distancia //-------------------------------------------------------------------------------------------------------------------------------- void NormalizaDistancia (float diametro) { float dtmp; for (int i=0; i criteriotmp) {Hojasa[i].criterio = criteriotmp; Hojasa[i].hoja_crit = j;} } } } // printf ( "Criterio establecido para hoja %i \n", i); } } } //-------------------------------------------------------------------------------------------------------------------------------- // establece el criterio despues de colapsar //-------------------------------------------------------------------------------------------------------------------------------- void EstableceCriterio2 ( float diametro, long int hojanueva) { //Para empezar establezco K1 y K2 con 0,5 float coptmp2, coptmp, distmp2, distmp, criteriotmp; int i, j, nhojasi, nhojasj; //ESTAN EN tres PROCEDIMIENTOS: COLAPSA, ESTABLECECRITERIO Y ESTABLECECRITERIO2 for ( i=0; i criteriotmp) {Hojasa[i].criterio = criteriotmp; Hojasa[i].hoja_crit = j;} } } } } else { // CALCULARE SI EL CRITERIO CON ESTA HOJA ES MENOR QUE EL ANTERIOR nhojasj = Hojasa[hojanueva].Cuantas_hojas;//17/09/01 if ( abs((nhojasi - nhojasj)) < 2) { //coplanaridad y lo invierto coptmp2 = Hojasa[i].Coplanaridad(Hojasa[hojanueva]); coptmp = 1 - coptmp2; //distancia y la normalizo //distmp2 = Hojasa[i].Distancia(Hojasa[hojanueva]); distmp2 = Hausdorff( Hojasa[i], Hojasa[hojanueva]); distmp = distmp2 / diametro; // calculo el criterio para esa hoja criteriotmp = (( K1 * distmp * distmp ) + (K2 * coptmp * distmp))/ (K1 + K2); //selecciono el criterio menor if (Hojasa[i].criterio > criteriotmp) {Hojasa[i].criterio = criteriotmp; Hojasa[i].hoja_crit = hojanueva; //printf ( "Cambio el criterio para hoja %i \n", i); } } } } } } //-------------------------------------------------------------------------------------------------------------------------------- // DEVUELVE LA HOJA QUE TIENE EL NUMERO EN EL CAMPO CRITERIO MENOR //-------------------------------------------------------------------------------------------------------------------------------- long int MinimoCriterio ( void) { float mincrit =0; long int cual=-1; int i=0; //inicializo while (Hojasa[i].existe != true) i++; mincrit = Hojasa[i].criterio; cual =i; //busco la minima for ( i=0;i Hojasa[i].criterio) { mincrit = Hojasa[i].criterio; cual = i; } } } return (cual); } //-------------------------------------------------------------------------------------------------------------------------------- // //-------------------------------------------------------------------------------------------------------------------------------- void ElijeVertices(Hoja& Hoja1, Hoja& Hoja2, long int count) { // criterio es el de los dos vertices más alejados del centro de la otra hoja float a,b,c; float dist[4]; int indices[4]; // primero de la primera hoja cojo los dos primeros vertices a = Vertex[Hoja1.Vertices[0]][0]; b = Vertex[Hoja1.Vertices[0]][1]; c = Vertex[Hoja1.Vertices[0]][2]; dist[0] = ((Hoja2.Centro[0]-a)*(Hoja2.Centro[0]-a)) + ((Hoja2.Centro[1]-b)*(Hoja2.Centro[1]-b)) + ((Hoja2.Centro[2]-c)*(Hoja2.Centro[2]-c)); a = Vertex[Hoja1.Vertices[1]][0]; b = Vertex[Hoja1.Vertices[1]][1]; c = Vertex[Hoja1.Vertices[1]][2]; dist[1] = ((Hoja2.Centro[0]-a)*(Hoja2.Centro[0]-a)) + ((Hoja2.Centro[1]-b)*(Hoja2.Centro[1]-b)) + ((Hoja2.Centro[2]-c)*(Hoja2.Centro[2]-c)); a = Vertex[Hoja1.Vertices[2]][0]; b = Vertex[Hoja1.Vertices[2]][1]; c = Vertex[Hoja1.Vertices[2]][2]; dist[2] = ((Hoja2.Centro[0]-a)*(Hoja2.Centro[0]-a)) + ((Hoja2.Centro[1]-b)*(Hoja2.Centro[1]-b)) + ((Hoja2.Centro[2]-c)*(Hoja2.Centro[2]-c)); a = Vertex[Hoja1.Vertices[3]][0]; b = Vertex[Hoja1.Vertices[3]][1]; c = Vertex[Hoja1.Vertices[3]][2]; dist[3] = ((Hoja2.Centro[0]-a)*(Hoja2.Centro[0]-a)) + ((Hoja2.Centro[1]-b)*(Hoja2.Centro[1]-b)) + ((Hoja2.Centro[2]-c)*(Hoja2.Centro[2]-c)); for ( int i=0;i<4;i++) indices[i]=i; DosMayores(dist, indices); Hojasa[counth].Vertices[0] = Hoja1.Vertices[indices[0]]; Hojasa[counth].Vertices[1] = Hoja1.Vertices[indices[1]]; // segunda hoja los dos ultimos vertices a = Vertex[Hoja2.Vertices[0]][0]; b = Vertex[Hoja2.Vertices[0]][1]; c = Vertex[Hoja2.Vertices[0]][2]; dist[0] = ((Hoja1.Centro[0]-a)*(Hoja1.Centro[0]-a)) + ((Hoja1.Centro[1]-b)*(Hoja1.Centro[1]-b)) + ((Hoja1.Centro[2]-c)*(Hoja1.Centro[2]-c)); a = Vertex[Hoja2.Vertices[1]][0]; b = Vertex[Hoja2.Vertices[1]][1]; c = Vertex[Hoja2.Vertices[1]][2]; dist[1] = ((Hoja2.Centro[0]-a)*(Hoja2.Centro[0]-a)) + ((Hoja1.Centro[1]-b)*(Hoja1.Centro[1]-b)) + ((Hoja2.Centro[2]-c)*(Hoja2.Centro[2]-c)); a = Vertex[Hoja2.Vertices[2]][0]; b = Vertex[Hoja2.Vertices[2]][1]; c = Vertex[Hoja2.Vertices[2]][2]; dist[2] = ((Hoja1.Centro[0]-a)*(Hoja1.Centro[0]-a)) + ((Hoja1.Centro[1]-b)*(Hoja1.Centro[1]-b)) + ((Hoja1.Centro[2]-c)*(Hoja1.Centro[2]-c)); a = Vertex[Hoja2.Vertices[3]][0]; b = Vertex[Hoja2.Vertices[3]][1]; c = Vertex[Hoja2.Vertices[3]][2]; dist[3] = ((Hoja1.Centro[0]-a)*(Hoja1.Centro[0]-a)) + ((Hoja1.Centro[1]-b)*(Hoja1.Centro[1]-b)) + ((Hoja1.Centro[2]-c)*(Hoja1.Centro[2]-c)); for ( int i=0;i<4;i++) indices[i]=i; DosMayores(dist, indices); Hojasa[counth].Vertices[2] = Hoja2.Vertices[indices[0]]; Hojasa[counth].Vertices[3] = Hoja2.Vertices[indices[1]]; } //-------------------------------------------------------------------------------------------------------------------------------- // AÑADE HOJAS //-------------------------------------------------------------------------------------------------------------------------------- long int Colapsa (FILE *fp_simplifica, float diametro) { long int i=0, cual=-1; long int otra = -1; float coptmp, coptmp2, distmp, distmp2, criteriotmp; char linea[250]; // cual=MinimaDistancia(); cual=MinimoCriterio(); // otra = Hojasa[cual].hoja_cerca; //para la distancia // otra = Hojasa[cual].hoja_cop; otra = Hojasa[cual].hoja_crit; //desactivo las hojas cercanas Hojasa[cual].existe = false; Hojasa[otra].existe = false; //creo la hoja nueva Hojasa[counth].hoja_cerca = -1; Hojasa[counth].dist = 0; Hojasa[counth].hoja_cop = -1; Hojasa[counth].coplanar = 0; Hojasa[counth].Cuantas_hojas = Hojasa[cual].Cuantas_hojas + Hojasa[otra].Cuantas_hojas; ElijeVertices(Hojasa[cual], Hojasa[otra], counth); Centroh (Hojasa[counth]); GetNormal ( Hojasa[counth]); //18/09/01 if ( Hojasa[counth].Cuantas_hojas > 60 ) { Hojasa[counth].existe = false; activas--; } else { //establezco el criterio para la hoja nueva Hojasa[counth].existe = true; Hojasa[counth].criterio = 1000; //coplanaridad for ( int j =0; j<(counth+1);j++) { if (( j != counth) && ( Hojasa[j].existe == true)) // si la hoja aun existe { //coplanaridad y lo invierto coptmp2 = Hojasa[counth].Coplanaridad(Hojasa[j]); coptmp = 1 - coptmp2; //distancia y la normalizo //distmp2 = Hojasa[counth].Distancia(Hojasa[j]); distmp2 = Hausdorff( Hojasa[counth], Hojasa[j]); distmp = distmp2 / diametro; // calculo el criterio para esa hoja criteriotmp = (( K1 * distmp * distmp ) + (K2 * coptmp * distmp))/ (K1 + K2); //selecciono el criterio menor if (Hojasa[counth].criterio > criteriotmp) {Hojasa[counth].criterio = criteriotmp; Hojasa[counth].hoja_crit = j;} } } } //en la pantalla // printf ("Nuevo %i Ver %lu %lu %lu %lu Tviej %lu %lu Engloba %i\n", // counth, Hojasa[counth].Vertices[0], Hojasa[counth].Vertices[1], Hojasa[counth].Vertices[2], // Hojasa[counth].Vertices[3], cual, otra, Hojasa[counth].Cuantas_hojas); //en el fichero sprintf (linea,"Nuevo %i Ver %lu %lu %lu %lu T_viej %lu %lu Engloba %i\n", counth, Hojasa[counth].Vertices[0], Hojasa[counth].Vertices[1], Hojasa[counth].Vertices[2], Hojasa[counth].Vertices[3], cual, otra, Hojasa[counth].Cuantas_hojas); fputs (linea, fp_simplifica); //incremento el numero de hojas counth++; activas--; return (counth-1);//porque lo he incrementado en la linea de antes } void simplifica(void){ long int totalv=0, hnueva; float diam; FILE* fp_simplifica; diam = DiametroEsferaEnvolvente(fp_simplifica ); EstableceCriterio (diam); while ( activas > 20) { hnueva=Colapsa(fp_simplifica, diam); EstableceCriterio2 (diam, hnueva); } } //-------------------------------------------------------------------------------------------------------------------------------- // MAIN DEL PROGRAMA //-------------------------------------------------------------------------------------------------------------------------------- //int main (int argc, char ** argv) //{ // // long int totalv=0, hnueva; // float diam; // FILE* fp_simplifica; //// FILE* fp_criterio; // // first = time(NULL); // // char fvertices[100],fhojas[100],fsalida[100]; // strcpy(fvertices,"H:\\GTGeometry\\tests\\bin\\vertices.obj\0"); // strcpy(fhojas,"H:\\GTGeometry\\tests\\bin\\hojas.obj\0"); // strcpy(fsalida,"H:\\GTGeometry\\tests\\bin\\salida.kk\0"); // // argc=4; // if (argc != 4) {// el 0 es el nombre del programa // puts ("Sintaxis: fichero_arbol fichero_hojas fichero_simplif"); // getchar(); // return -1; // } // // //cuento todos los vertices, y relleno la estructura // totalv = LeeVertices(fvertices); // // //cuento las hojas // counth= CuentaHojas (fhojas); // printf ("Hay %lu hojas\n", counth); // // // lleno la estructura de datos de las hojas ( inicial y activas) // printf ("Ahora las leo\n"); // LeoHojas(fhojas); //// DistanciaEntreHojas(); //// CoplanarEntreHojas(fp_coplanar); // if ((fp_simplifica = fopen (fsalida, "w")) == NULL) // printf ("No puedo abrir el fichero %s\n", argv[3]); // else // { // // diam = DiametroEsferaEnvolvente(fp_simplifica ); // EstableceCriterio (diam); // // // /*if ((fp_criterio = fopen ("criterio.obj", "w")) == NULL) // printf ("No puedo abrir el fichero distancias\n"); // else // EscribeCriterio(fp_criterio); // // */while ( activas > 20) // { // hnueva=Colapsa(fp_simplifica, diam); // EstableceCriterio2 (diam, hnueva); // // EscribeCriterio(fp_criterio); // // // } // // fclose ( fp_simplifica); // // fclose ( fp_criterio); // } // // second = time(NULL); // printf("Diferencia: %f segundos\n", difftime(second, first)); // getchar(); // return 0; //}//main