Converts a triangular surface given in Wavefront .obj format into F5.
 
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <hdf5.h>
 
#include <F5/F5X.h>
#include <F5/F5F.h>
#include <F5/F5B.h>
#include <F5/F5R.h>
#include <F5/F5coordinates.h>
#include <F5/F5surface.h>
#include <F5/F5defs.h>
#include <math.h>
#include <stdlib.h>     
 
#define MAX_VERTICES  49325149
#define MAX_TRIANGLES 1000000
 
 
int     main(int argc, char*argv[])
{
     printf(" \n");
     printf("  \n");
     printf("##########################################################################\n");
     printf("                         OBJ to F5 \n");
     printf("   Usage: Either: \n");
     printf("   <ObjtoF5 file_name.obj> OR \n");
     printf("  <ObjtoF5 fileprefix_ 0.5 10 out> whereas 0.5 is delta t, 10 file numbers and out f5 file-name \nn");
     printf("  'FilePrefix must be: fileprefix_000000.obj fileprefix_000001,obj.... \n");
     printf("##########################################################################\n");
     printf("  \n");
     printf("  \n");
 
 
    hid_t       fileID;
    char        gridname[1024];
 
    char        buf[1024];
 
    FILE*what;
    int t, i;
 
 
 
    if (argc<2)
    {
        puts("Please specify <inputfile.obj>. Thanks.");
        return 1;
    }
 
 
    printf("\n");
    unsigned k=0;
    for (k=0; k < argc ; k++)
        printf("argv is: %s            at position %d \n", argv[k],k);
 
    printf("\n");
 
    unsigned file_number = 0;
    double delta_t = 0;
 
    if(argc > 2)
    {
            printf("time series is used: delta t: %s and file numbers: %s\n", argv[2],argv[3],argv[4]);
 
         delta_t     = atof(argv[2]);
         file_number = atoi(argv[3]);
 
 
          printf("delta t %f", delta_t );
          printf("delta t %d", file_number );
 
    }
    else
    {
        file_number = 1;
    }
 
    printf("\n");
 
    if (argc == 5)
           strcpy(buf, argv[4]);
    else
           strcpy(buf, argv[1]);
 
 
 
 
 
    char*c = strrchr(buf, '.');
 
        if (c)
        {
 
            *c = 0;
 
        char*n = strrchr(buf,'/');
 
            if( n != NULL )
            {
                strcpy(gridname, n+1);
            }
            else
            {
                strcpy(gridname, buf);
            }
 
            strcat(c, ".f5");
            fileID = H5Fcreate(buf,       
                        H5F_ACC_TRUNC,    
                        H5P_DEFAULT,      
                        H5P_DEFAULT);     
 
            printf("F5 file with single obj is: %s\n",buf);
        }
        else
        {
 
        char*n = strrchr(buf,'/');
 
 
                if( n != NULL )
                {
                        strcpy(gridname, n+1);
                }
                else
                {
                        strcpy(gridname, buf);
                }
 
                strcat(buf, ".f5");
                printf("right4 %s\n",buf);
                fileID = H5Fcreate(buf,       
                        H5F_ACC_TRUNC,    
                        H5P_DEFAULT,      
                        H5P_DEFAULT);     
 
                 printf("F5 file with multiple obj is: %s\n",buf);
 
        }
 
 
    
    unsigned which_file = 0;
 
    for (which_file=0; which_file < file_number; which_file++)
    {
         printf("This is file:  %d\n", which_file);
 
    int nCoords = 0,
        nVertexNormals = 0,
        nTexture = 0,
        nTriangles = 0;
 
 
        char fname[40]; fname;
        sprintf(fname,"%s%06d.obj", argv[1],which_file);
 
 
        if(argc < 3)
            sprintf(fname,"%s", argv[1]);
 
        what = fopen(fname, "rt");
        if (!what)
        {
            printf("Cannot open '%s'. That's not good.\n", fname );
            return 2;
        }
 
        while( fgets(buf, sizeof(buf), what) )
        {
            double      x,y,z;
 
            switch(*buf)
            {
            case 'v': 
                switch(buf[1])
                {
                case 't': 
                    if (sscanf(buf, "vt %lg %lg %lg\n", &x, &y, &z) != 2)
                        continue;
 
                    nTexture++;
                    continue;
 
                case 'n': 
                    if (sscanf(buf, "vn %lg %lg %lg\n", &x, &y, &z) != 3)
                        continue;
 
                    VertexNormals[nVertexNormals].
x = x;
                    VertexNormals[nVertexNormals].
y = y;
                    VertexNormals[nVertexNormals].
z = z;
                    nVertexNormals++;
                    continue;
 
                default:  
                    if (sscanf(buf, "v %lg %lg %lg\n", &x, &y, &z) != 3)
                        continue;
 
                    nCoords++;
                    continue;
                }
 
            case 'f':
                {
                int v0=0, vt0=0, vn0=0,  v1=0, vt1=0, vn1=0,  v2=0, vt2=0, vn2=0;
                if (sscanf(buf, "f %d/%d/%d %d/%d/%d %d/%d/%d\n",
                        &v0, &vt0, &vn0,  &v1, &vt1, &vn1,  &v2, &vt2, &vn2) != 9)
                    if (sscanf(buf, "f %d %d %d\n",
                            &v0, &v1, &v2 ) != 3)
                        if(sscanf(buf, "f %d/%d %d/%d %d/%d\n",
                              &v0, &vt0,  &v1, &vt1,  &v2, &vt2) != 6)
                            if(sscanf(buf, "f %d//%d %d//%d %d//%d\n",
                                  &v0, &vn0,  &v1, &vn1,  &v2, &vn2) != 6)
 
                                
                                v0 = v0; 
 
                
                Triangles[nTriangles].
i = v0-1;
                Triangles[nTriangles].
j = v1-1;
                Triangles[nTriangles].
k = v2-1;
 
                
 
                nTriangles++;
                continue;
                }
            }
        }
 
 
 
        if (!nCoords)
        {
            H5Fclose(fileID);
            return 0;
        }
        printf("Triangular surface: %d vertices, %d normals, %d texture coordinates, %d triangles\n",
                nCoords, nVertexNormals, nTexture, nTriangles);
 
 
             double     time = which_file*delta_t;
 
                               Coords,  nCoords,
                               Triangles, nTriangles);
 
 
 
    } 
 
        if (!myFields)
            puts("ERROR in writing surface...");
 
 
 
 
 
 
    H5Fclose(fileID);
 
    puts(" ****   Done    ****");
 
    return 0;
}
void F5Fclose(F5Path *f)
Definition: F5F.c:92
F5Path * F5write_triangular_surface(hid_t file_id, double time, const char *name, const F5_vec3_point_t *Coords, int nCoords, const F5_triangle_t *Triangles, int nTriangles)
Definition: F5surface.c:9
Definition: F5coordinates.h:58
Definition: F5coordinates.h:208
Definition: F5coordinates.h:246
Definition: F5coordinates.h:57