xp_comm_proj/nurbs/nurbutil.c
/* NRB_READ_PCH: read nrb patch data from a given file */
read nrb patch data from a given file
read nrb patch data from a given file
Qnurbs_pch *nrb_read_pch(char *filename)
{
    FILE       *fp;
    int        i, j, k;
    char       line[MAXLINE];
    Qnurbs_pch *pch;    
    int        ku, nu, kv, nv;
    Qfloat     *tu, *tv;
    Qpoint4    *cp;
    if (filename == NULL) return(NULL); 
    if ((fp = fopen(filename, "r")) == NULL) return(NULL); 
    fgets (line, MAXLINE, fp);
    fgets (line, MAXLINE, fp);
    fscanf (fp, "U: ORDER = %d, CPT NO = %d\n", &ku, &nu);
    fscanf (fp, "V: ORDER = %d, CPT NO = %d\n", &kv, &nv);
    pch = (Qnurbs_pch *) malloc (nrb_pch_size (ku, nu, kv, nv));
    pch->ku = ku; 
    pch->nu = nu; 
    pch->kv = kv; 
    pch->nv = nv;
    nrb_pch_data (pch, &pch->ku, &pch->nu, &pch->kv, &pch->nv, &tu, &tv, &cp);
    fgets (line, MAXLINE, fp);
    for (i = 0; i < ku + nu; i++) 
	fscanf (fp, "   %d ==> %f\n", &j, &tu[i]);
    fgets (line, MAXLINE, fp);
    for (i = 0; i < kv + nv; i++) 
	fscanf (fp, "   %d ==> %f\n", &j, &tv[i]);
    fgets (line, MAXLINE, fp);
    for (i = 0; i < nv; i++)
    for (j = 0; j < nu; j++) {
	k = i * nu + j;
	fscanf (fp, "%f, %f, %f, %f,\n", 
		&cp[k].x, &cp[k].y, &cp[k].z, &cp[k].w);
    }                                                      
    fclose(fp);
    return(pch);
}
Qnurbs_pch * nrb_read_pch ( char * filename ) { FILE * fp ; int i , j , k ; char line [ MAXLINE ] ; Qnurbs_pch * pch ; int ku , nu , kv , nv ; Qfloat * tu , * tv ; Qpoint4 * cp ; if ( filename == NULL ) return ( NULL ) ; if ( ( fp = fopen ( filename , " " ) ) == NULL ) return ( NULL ) ; fgets ( line , MAXLINE , fp ) ; fgets ( line , MAXLINE , fp ) ; fscanf ( fp , " \n " , & ku , & nu ) ; fscanf ( fp , " \n " , & kv , & nv ) ; pch = ( Qnurbs_pch * ) malloc ( nrb_pch_size ( ku , nu , kv , nv ) ) ; pch -> ku = ku ; pch -> nu = nu ; pch -> kv = kv ; pch -> nv = nv ; nrb_pch_data ( pch , & pch -> ku , & pch -> nu , & pch -> kv , & pch -> nv , & tu , & tv , & cp ) ; fgets ( line , MAXLINE , fp ) ; for ( i = 0 ; i < ku + nu ; i ++ ) fscanf ( fp , " \n " , & j , & tu [ i ] ) ; fgets ( line , MAXLINE , fp ) ; for ( i = 0 ; i < kv + nv ; i ++ ) fscanf ( fp , " \n " , & j , & tv [ i ] ) ; fgets ( line , MAXLINE , fp ) ; for ( i = 0 ; i < nv ; i ++ ) for ( j = 0 ; j < nu ; j ++ ) { k = i * nu + j ; fscanf ( fp , " \n " , & cp [ k ] . x , & cp [ k ] . y , & cp [ k ] . z , & cp [ k ] . w ) ; } fclose ( fp ) ; return ( pch ) ; }
NRB_READ_PCH: read nrb patch data from a given file
NRB_READ_PCH : read nrb patch data from a given file
/* skip first two lines of nurbs pch data */ /* get order and number of control points in both U and V directions */ /* allocate memory for a NURBS surface */ /* skip the line */ /* get U knot vector */ /* skip the line */ /* get V knot vector */ /* skip the line */ /* get 4D control points */ /* close the data file */