#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>

#include "rand_mersenne.h"


/* Constantes */

#define D_PI 6.28318530717958647692
#define T_PI 3.14159265358979
#define EPSILON  1e-12

#define CARRE(x) ((x)*(x))
#define CUBE(x) ((x)*(x)*(x))

#define LOG_POISSON 0
#define LOG_NORMAL 1
#define LOG_EXP 2
#define LOG_BESSEL 3

#define DISQUE 0
#define COS 1
#define EXP 2
#define CERCLE 3

#define ECLAIREMENT_CONE 0
#define ANGLE_SOLIDE 1
#define STEREOGRAPHIQUE 2

#define SUBDIVISION 0
#define EQUIANGULAIRE 1
#define HEALPIX 2


/* Structures */

typedef struct pointSphere
{
	double theta;
	double phi;
	double ri;
}pointSphere_t;

typedef struct point4d
{
	double x, y, z;
	double t;
}point4d_t;

typedef struct tri
{
	double x;
	int indice;
}tri_t;

typedef struct polynome
{
	double c1, c2, c3;
}polynome_t;

typedef struct spline
{
	polynome_t *x;
	polynome_t *y;
}spline_t;

typedef int triangleInd_t[3];


/* Variables globales */

double Ray, r_min, C, param1, param2, L;
int loi, version, motif, maillage;
int nb_sommets, nb_triangles;
point4d_t *liste_sommets;
triangleInd_t *liste_trianglesInd;
int *liste_triee_x;
double *liste_triee_y;
double *liste_phi;
unsigned long graine;
//double *filtre, *ifiltre;


/* Fonctions */

void lecture_sub(FILE *file1);
void lecture_equi(FILE *file1);
void lecture_healpix(FILE *file1);

void ecriture_sub(FILE *file2);
void ecriture_equi(FILE *file2);
void ecriture_healpix(FILE *file2);

double randn(void);

void synthese();

void synthese_eclairement(int nb_points, double umax, double *Wi);

void shaper_disque_eclairement(point4d_t pt_car, double Wi, double A, double coef, int inf_ind, int sup_ind);
void shaper_cos2_eclairement(point4d_t pt_car, double Wi, double A, double ri, double coef, int inf_ind, int sup_ind);
void shaper_exp_eclairement(point4d_t pt_car, double Wi, double A, double ri, double coef, int inf_ind, int sup_ind);

void synthese_angle(int nb_points, double umax, double *Wi);

void shaper_disque_angle(point4d_t pt_car, double Wi, double A, double coef, int inf_ind, int sup_ind);
void shaper_cercle_angle(point4d_t pt_car, pointSphere_t point_sphere, double Wi, double A, double ri, double coef, int inf_ind, int sup_ind);
void shaper_cos2_angle(point4d_t pt_car, double Wi, double A, double ri, double coef, int inf_ind, int sup_ind);
void shaper_exp_angle(point4d_t pt_car, double Wi, double A, double ri, double coef, int inf_ind, int sup_ind);
void shaper_etoile_angle(point4d_t pt_car, pointSphere_t point_sphere, double coef, double Wi, double A, int inf_ind, int sup_ind);

void synthese_stereo(int nb_points, double umax, double *Wi);

void shaper_disque_stereo(point4d_t pt_car, double Wi, double A, double coef, int inf_ind, int sup_ind);
void shaper_cos2_stereo(point4d_t pt_car, double Wi, double A, double ri, double coef, int inf_ind, int sup_ind);
void shaper_exp_stereo(point4d_t pt_car, double Wi, double A, double ri, double coef, int inf_ind, int sup_ind);

//	Maillage de subdivision
int dicho_sub_inf(double theta_inf);
int dicho_sub_sup(double theta_sup);

//	Maillage ˇquiangulaire
int dicho_equi_inf(double theta_inf);
int dicho_equi_sup(double theta_sup);

//	Maillage HEALPix
int dicho_healpix_inf(double theta_inf);
int dicho_healpix_sup(double theta_sup);




