polygon_connection_attributes *get_connection(POLYGON *polygon,POLYGONVECTOR *polygons, long boundary, long displacement ,short print) { /*! * * \param polygon - (POLYGON *) polygon to which link are referred * \param polygons - (POLYGONS *) vector of polygons * \param boundary - (long) long value which indetifies the boundary * \param displacement - (long) displacement in the POLYNGONVECTOR polygons around the index value of polygon where to find the connections * \param print - (short) * * \author Emanuele Cordano * \date November 2008 * *\return a poygon_connection_atributes struct for a given polygon (polygon) within a polygon array (polygons) * */ polygon_connection_attributes *pca; long l,s,l_po1,l_po2,icnt; double dist; long A_min,A_max; /*! extremes of the search interval */ icnt=1; pca=(polygon_connection_attributes *)malloc((sizeof(polygon_connection_attributes))); if (!pca) printf("Error: polygon_connection_attributes was not allocated at %ld polygon",polygon->index); pca->connections=new_longvector(polygon->edge_indices->nh); pca->d_connections=new_doublevector(polygon->edge_indices->nh); initialize_longvector(pca->connections,boundary); initialize_doublevector(pca->d_connections,NULL_VALUE); A_min=fmax(polygon->index-displacement,polygons->nl); A_max=fmin(polygon->index+displacement,polygons->nh); for (l=A_min; l<=A_max; l++) { if (l!=polygon->index) { dist=1.0; l_po1=0; l_po2=0; s=shared_edges(polygon,polygons->element[l],NO_INTERSECTION,&l_po1,&l_po2,&dist); if (s!=NO_INTERSECTION ) { if (l_po1>polygon->edge_indices->nh) printf ("Error: Line %ld : (%ld for polygon %ld) Not coherent data!!! \n ",s,l_po1,polygon->index); pca->connections->element[l_po1]=polygons->element[l]->index; pca->d_connections->element[l_po1]=dist; // printf(" pca conn. %ld %lf",pca->connections->element[l_po1],pca->d_connections->element[l_po1]); } } } return pca; }
LONGBIN *read_line_indices(char *filename,short print) { /* * * \author Emanuele Cordano * date May 2009 * * \param (char*) - name of filename *\param (short) - * */ LONGVECTOR **lv; LONGBIN *lb; LONGVECTOR *vi; FILE *fd; long j,n_l,c; fd=t_fopen(filename,"r"); n_l=(long)read_index(fd,print); // printf("n_l=%ld",n_l); lv=(LONGVECTOR **)malloc((size_t)(n_l*sizeof(LONGVECTOR *))); // stop_execution(); for (j=0;j<=n_l-1;j++) { lv[j]=read_longarray(fd,print); } vi=new_longvector(n_l); for (j=vi->nl;j<=vi->nh;j++) { vi->element[j]=lv[j-1]->nh; } lb=new_longbin(vi); for (j=lb->index->nl;j<=lb->index->nh;j++) { for(c=1;c<=lb->index->element[j];c++) { lb->element[j][c]=lv[j-1]->element[c]; } } free_longvector(vi); for (j=0;j<=n_l-1;j++) { free_longvector(lv[j]); } free(lv); t_fclose(fd); if (print==1) printf("Function read_line_indices was successfully executed! \n"); return lb; }
polygon_connection_attributes *read_connections(FILE *fd,short print) { /*! * \author Emanuele Cordano * \date May 2009 * * \param fd - (FILE *) file pointer * \param print - (short) * * */ polygon_connection_attributes *pca; DOUBLEVECTOR *v_data; long j; v_data=read_doublearray(fd,no_PRINT); int s=(v_data->nh-1)%2; if (s!=0) printf("Error in read_connections (index %ld) odd number of elements in the vector after the first one which is the polygon index",v_data->nh); long l=(v_data->nh-1)/2; pca=(polygon_connection_attributes *)malloc((sizeof(polygon_connection_attributes))); if (!pca) printf("Error: polygon_connection_attributes was not allocated at %ld polygon",(long)v_data->element[1]); pca->connections=new_longvector(l); pca->d_connections=new_doublevector(l); for (j=pca->connections->nl;j<=pca->connections->nh;j++) { pca->connections->element[j]=(long)(v_data->element[j*2]); pca->d_connections->element[j]=v_data->element[j*2+1]; } free_doublevector(v_data); return pca; }
POLYGON *read_polygon(FILE *fd,short print) { /*! * \autor Emanuele Cordano * \date May 2009 * * \param (FILE *) - file pointer * \param (short) - print * */ int ix=1; /* x coordinate of the centroid */ int iy=ix+1; /* y coordinate of the centroid */ int ipolygon_index=iy+1; /* index of the polygon */ int iarea2d=ipolygon_index+1; /* area of the polygon */ int n_data=iarea2d; long i; DOUBLEVECTOR *v_data; POLYGON *po; v_data=read_doublearray(fd,print); if (v_data->nh<=n_data) printf ("Error in read_polygon there no sufficient data !!\n"); po=(POLYGON *)malloc(sizeof(POLYGON)); if (!po) t_error("Polygon in read_polygon struct was not allocated"); po->area2D=v_data->element[iarea2d]; po->index=v_data->element[ipolygon_index]; po->centroid=new_point(po->index,v_data->element[ix],v_data->element[iy],NULL_ELEVATION); po->edge_indices=new_longvector(v_data->nh-n_data); for(i=po->edge_indices->nl;i<=po->edge_indices->nh;i++) { po->edge_indices->element[i]=v_data->element[i+n_data]; } free_doublevector(v_data); return po; }
STRINGBIN *new_stringbin(LONGVECTOR *indx) { long i,sum=0; STRINGBIN *l; l=(STRINGBIN *)malloc(sizeof(STRINGBIN)); if (!l) t_error("allocation failure in new_stringcontainer()"); l->isdynamic=isDynamic; if(indx->nl!=1){ t_error("Not a proper index for stringcontainer"); }else{ l->index=new_longvector(indx->nh); (l->index)->nl=1; (l->index)->nh=indx->nh; for(i=indx->nl;i<=indx->nh;i++){ (l->index)->co[i]=indx->co[i]; } l->co=(char **)malloc((size_t) ((indx->nh+NR_END)*sizeof(char *))); if (!l->co) t_error("allocation failure in new_stringcontainer()"); l+=NR_END-1; for(i=1;i<=indx->nh; i++){ sum+=(l->index)->co[i]; } l->co[1]=(char *)malloc((size_t) ((sum+NR_END)*sizeof(char))); if(!(l->co[1])) t_error("allocation failure 2 in new_stringcontainer()"); l->co[1]+=NR_END; l->co[1]-=1; for(i=2;i<=indx->nh; i++){ l->co[i]=l->co[i-1]+indx->co[i-1]; } } l->next=NULL; return l; }
SHORTBIN *new_shortbin(LONGVECTOR *indx) { long i,sum=0; SHORTBIN *l; l=(SHORTBIN *)malloc(sizeof(SHORTBIN)); if (!l) t_error("allocation failure in new_shortbin()"); l->isdynamic=isDynamic; if(indx->nl!=1){ t_error("Not a proper index for shortbin"); }else{ l->index=new_longvector(indx->nh); (l->index)->nl=1; (l->index)->nh=indx->nh; for(i=indx->nl;i<=indx->nh;i++){ (l->index)->co[i]=indx->co[i]; } l->co=(short **)malloc((size_t) ((indx->nh+NR_END)*sizeof(short *))); if (!l->co) t_error("allocation failure in new_shortbin()"); l+=NR_END-1; for(i=1;i<=indx->nh; i++){ sum+=(l->index)->co[i]; } l->co[1]=(short *)malloc((size_t) ((sum+NR_END)*sizeof(short))); if(!(l->co[1])) t_error("allocation failure 2 in new_shortbin()"); l->co[1]+=NR_END; l->co[1]-=1; for(i=2;i<=indx->nh; i++){ l->co[i]=l->co[i-1]+indx->co[i-1]; } } return l; }
polygon_connection_attributes *get_connection_squares(POLYGON *polygon,POLYGONVECTOR *polygons, long boundary,long novalue, long r ,long c,LONGMATRIX *mask,short print) { /*! * * \param polygon - (POLYGON *) polygon to which link are referred * \param polygons - (POLYGONS *) vector of polygons * \param boundary - (long) long value which indetifies the boundary * \param novalue - (long) null value used in the pixel index matrix * \param r - (long) row * \param c - (long) column * \param (LONGMATRIX *) pixel index matrix * * \param print - (long) displacement in the POLYNGONVECTOR polygons around the index value of polygon where to find the connections * * \author Emanuele Cordano * \date July 2009 * *\return a poygon_connection_atributes struct for a given polygon (polygon) within a polygon array (polygons) * */ polygon_connection_attributes *pca; long l,s,l_po1,l_po2,icnt; double dist; long r_min,r_max,c_min,c_max; /*! extremes of the search interval */ long rs,cs; icnt=1; pca=(polygon_connection_attributes *)malloc((sizeof(polygon_connection_attributes))); if (!pca) printf("Error: polygon_connection_attributes was not allocated at %ld polygon",polygon->index); pca->connections=new_longvector(polygon->edge_indices->nh); pca->d_connections=new_doublevector(polygon->edge_indices->nh); initialize_longvector(pca->connections,boundary); initialize_doublevector(pca->d_connections,NULL_VALUE); r_min=fmax(r-1,mask->nrl); r_max=fmin(r+1,mask->nrh); c_min=fmax(c-1,mask->ncl); c_max=fmin(c+1,mask->nch); for (rs=r_min; rs<=r_max; rs++) { for (cs=c_min; cs<=c_max; cs++) { l=mask->element[rs][cs]; if ((l!=polygon->index) && (l!=novalue)) { dist=1.0; l_po1=0; l_po2=0; s=shared_edges(polygon,polygons->element[l],NO_INTERSECTION,&l_po1,&l_po2,&dist); if (s!=NO_INTERSECTION ) { if (l_po1>polygon->edge_indices->nh) printf ("Error: Line %ld : (%ld for polygon %ld) Not coherent data!!! \n ",s,l_po1,polygon->index); pca->connections->element[l_po1]=polygons->element[l]->index; pca->d_connections->element[l_po1]=dist; // printf(" pca conn. %ld %lf",pca->connections->element[l_po1],pca->d_connections->element[l_po1]); } } } } return pca; }