Пример #1
0
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;


}
Пример #2
0
LINE *get_line(DOUBLEVECTOR *vertex_x_coord, DOUBLEVECTOR *vertex_y_coord, long line_index, char *number_strings, short print){
	/*!
	 * \param vertex_x_coord - (DOUBLEVECTOR *) vector of x coordinates
	 * \param vertex_y_coord - (DOUBLEVECTOR *) vector of y coordinates
	 *
	 * \param line_index     - (long int) index of the line
	 * \param number_string  - (char *) string containing the number of two vertex points
	 * \param print          - (short) if activated it prints error or warning messages
	 * \author Emanuele Cordano
	 * \date November 2008
	 *
	 */
	POINT *P1, *P2;
	//long index1,index2,
	long j;
	LONGVECTOR *lvertices;
	LINE *li;

	lvertices=read_longarray_from_string(number_strings,DELIMITERS,MAX_POINTS,0);

    if (lvertices->nh<2) printf("Error:: line %s (%ld) cannot be created, there no vertices!!\n",number_strings,line_index);
    for (j=lvertices->nl;j<=2;j++){
    	if ((lvertices->element[j]>vertex_x_coord->nh) || (lvertices->element[j]>vertex_y_coord->nh)) {
    		printf ("Error:: line %s (%ld) cannot be created, point %ld has no coordinates or no atributes!!\n",number_strings,line_index,j);
    	}
    }

    j=1;
    P1=new_point(lvertices->element[j],vertex_x_coord->element[lvertices->element[j]],vertex_y_coord->element[lvertices->element[j]],NO_ELEVATION);

    j=2;
    P2=new_point(lvertices->element[j],vertex_x_coord->element[lvertices->element[j]],vertex_y_coord->element[lvertices->element[j]],NO_ELEVATION);

    if (print==1) printf ("The two vertices %ld (x=%lf,y=%lf) and %ld (x=%lf,y=%lf) of line %s (%ld) were succesfully created!!\n",P1->index,P1->x,P1->y,P2->index,P2->x,P2->y,number_strings,line_index);

    li=new_line_from_points(line_index, P1,P2);


    free_point(P1);
    free_point(P2);
    free_longvector(lvertices);


    return li;



}
Пример #3
0
POLYGON *get_polygon(long index,double x, double y, double z, char *edge_index_string,LINEVECTOR *all_lines, short print) {
	/*!
	 * \author Emanuele Cordano
	 * \date November 2008
	 *
	 * \param index - (long) index of the centroid and the polygons
	 * \param x  - (double) x of the centroid
	 * \param y  - (double) y of the centroid
	 * \param z  - (double) z of the centroid
	 *
	 * \param edge_line_index - (char *) string containing the edge indices
	 *
	 * \param all_lines       -  (LINEVECTOR *) vector of all lines
	 * \param print   - (short)
	 *
	 * \return a polygon (Attributes are not allocated!!)
	 *
	 */

	LINEVECTOR *edges;
	POLYGON *PO;
	LONGVECTOR *ledges;
	POINT *centroid;

	centroid=new_point(index,x,y,z);
	ledges=read_longarray_from_string(edge_index_string,DELIMITERS,MAX_POINTS,0);
	edges=extract_linvector_from_linevector(ledges,all_lines);
	PO=new_polygon_from_a_linevector(edges,centroid);

	free_point(centroid);
	free_longvector(ledges);
	free_linevector(edges);

	return PO;


}
Пример #4
0
void free_stringbin( STRINGBIN *l)







{



	







if(l==NULL || l->co==NULL || l->co[1]==NULL){



	printf("\nWarning::Cannot de-allocate a null stringbin\n");







}else if(l->index==NULL || (l->index)->nl!=1 || (l->index)->nl > (l->index)->nh || \



		(l->index)->isdynamic!=1){



				t_error("Wrong index in stringcontainer");



} else if(l->isdynamic==1){



	



	



	free((FREE_ARG) (l->co[1]+1-NR_END));



	free((FREE_ARG) (l->co+1-NR_END));



	free_longvector(l->index);



	



	free(l);



	



	return;



	



}else{



	



	printf("\nWarning::An attemp was made to free a non dynamic variable\n");



}



}