Can some one please provide suggestions as to how I can improve the
organization of main file ?
In my ray tracing project, I have to carry out following task (in
sequence)
1. Read the mesh from an ascii file and store it in the mesh data
structure.
2. Create the kd tree for fast mesh traversal.
4. Create rays, trace them on the fly and calculate the scattered and incident
electric fields.
currently it looks like this:
Code:
#include "initialize.h"
#include "mesh.h"
#include "vector.h"
#include "kdtree.h"
#include "common.h"
#include "ray.h"
#include <stdio.h>
#include <stdlib.h>
/* read_mesh, init_plwave and create_kdtree are functions defined in initialize.c */
/* which basically open mesh file, allocate memory, scan some data from user etc */
/* and finally call the program which does the actual processing on the data structure */
int initialize(mesh **m, char *zfname, kdtree **tree)
{
if(read_mesh(zfname, m) || init_plwave() || create_kdtree(tree, *m))
{
killall(); /* destroy all data structures */
return (1);
}
return (0);
}
int main(void)
{
mesh *m = NULL; /* pointer to mesh */
kdtree *tree = NULL; /* pointer to kd tree */
char *ptr = NULL;
char filename[50];
printf("Enter the file name\n");
if(fgets(filename, sizeof(filename), stdin) == NULL)
{
error_report("Bad file name");
exit(1);
}
if((ptr = strchr(filename, '\n')) != NULL)
*ptr = '\0';
if(initialize(&m, filename, &tree))
exit(1);
if(calc(m, tree)) /* do calculations */
{
killall();
return (1);
}
print_result(); /* display result */
killall(); /* destroy all data structures */
exit(0);
}