P
pereges
By main file, I mean the one which contains the main routine. Can some
one please provide suggestions as to how I can improve the
organization of main file ? I have just though about a rough skeleton.
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 a ray list and store it in a ray list.
3. Create the binary space partitioning tree for fast mesh traversal.
4. Trace all the rays and calculate the scattered and incident
electric fields.
I'm thinking of writing a function for every task.
#include "main.h"
static mesh *m; /* pointer to the mesh */
static bsptree *tree; /* pointer to the bsp tree */
static ray *raylist; /* pointer to the ray list */
/* function prototypes */
int read_mesh(char *);
int init_plane_wave(void);
int create_bsp_tree(void);
int calc_e_fields (void);
/* Provide the name of the ascii file(from which mesh is to be read)
as a command line argument eg. main sphere.dat */
int main(int argc char *argv[])
{
if(argc < 2)
{
fprintf(stderr, "Insufficient argumens\n");
return -1;
}
if(argc > 2)
{
fprintf(stderr, "Too many arguments\n");
return -1;
}
if(read_mesh(argv[1])
return -1;
if(init_plane_wave())
return -1;
if(create_bsp_tree())
return -1;
if(calc_e_fields())
return -1;
return 0;
}
/* I decided to make the above data structures as static global
because they are needed throughout the program */
int read_mesh(char *filename)
{
FILE *fp;
fp = fopen(filename, "r");
if(fp == NULL)
{
fprintf(stderr, "Error while opening the file %s\n", filename);
return -1;
}
m = malloc(sizeof *m);
if(m == NULL)
{
fprintf(stderr, "Couldn't allocate memory for the mesh\n");
return -1;
}
/* parse_dat_file returns -1 if error occured while parsing file */
if(parse_dat_file(fp, &m))
return -1;
}
/* This function will initiailize the plane as in read the
specification related to a plane wave like frequency, electric field
at reference point, direction of the plane wave etc. It will allocate
memory for the ray list. After this it will call init_rays which
initializes a set of parallel rays. A plane wave is being simulated by
a dense grid of parallel rays */
int init_plane_wave(void)
{
...
...
}
/* This function will read the maximum allowable depth for the tree ,
allocate memory for it*/
int create_bsp_tree(void)
{
}
/* This function will call the raytrace function and after that it
will perform some calculations to find out the scattered and incident
electric fields */
int calc_e_fields (void)
{
}
one please provide suggestions as to how I can improve the
organization of main file ? I have just though about a rough skeleton.
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 a ray list and store it in a ray list.
3. Create the binary space partitioning tree for fast mesh traversal.
4. Trace all the rays and calculate the scattered and incident
electric fields.
I'm thinking of writing a function for every task.
#include "main.h"
static mesh *m; /* pointer to the mesh */
static bsptree *tree; /* pointer to the bsp tree */
static ray *raylist; /* pointer to the ray list */
/* function prototypes */
int read_mesh(char *);
int init_plane_wave(void);
int create_bsp_tree(void);
int calc_e_fields (void);
/* Provide the name of the ascii file(from which mesh is to be read)
as a command line argument eg. main sphere.dat */
int main(int argc char *argv[])
{
if(argc < 2)
{
fprintf(stderr, "Insufficient argumens\n");
return -1;
}
if(argc > 2)
{
fprintf(stderr, "Too many arguments\n");
return -1;
}
if(read_mesh(argv[1])
return -1;
if(init_plane_wave())
return -1;
if(create_bsp_tree())
return -1;
if(calc_e_fields())
return -1;
return 0;
}
/* I decided to make the above data structures as static global
because they are needed throughout the program */
int read_mesh(char *filename)
{
FILE *fp;
fp = fopen(filename, "r");
if(fp == NULL)
{
fprintf(stderr, "Error while opening the file %s\n", filename);
return -1;
}
m = malloc(sizeof *m);
if(m == NULL)
{
fprintf(stderr, "Couldn't allocate memory for the mesh\n");
return -1;
}
/* parse_dat_file returns -1 if error occured while parsing file */
if(parse_dat_file(fp, &m))
return -1;
}
/* This function will initiailize the plane as in read the
specification related to a plane wave like frequency, electric field
at reference point, direction of the plane wave etc. It will allocate
memory for the ray list. After this it will call init_rays which
initializes a set of parallel rays. A plane wave is being simulated by
a dense grid of parallel rays */
int init_plane_wave(void)
{
...
...
}
/* This function will read the maximum allowable depth for the tree ,
allocate memory for it*/
int create_bsp_tree(void)
{
}
/* This function will call the raytrace function and after that it
will perform some calculations to find out the scattered and incident
electric fields */
int calc_e_fields (void)
{
}