#ifndef __MODELS_H__ #define __MODELS_H__ #include #include /*Types of each function*/ typedef double phi_function(int i, r3_t* normal,void* l_data); /*Given the coeficient number{i}, the normal {n} and given lighting model {l_data} computes the value of Phi{i}*/ typedef int number_components_function(void* l_data); /*Give the number of the coeficients for the LS system*/ typedef void retrieve_function(double* C, int n,void* l_data); /*Given the {n} computed LS coeficients {C}, returns the values of the lighting model ${l_data}*/ typedef void update_weight_function(void* l_data,r3_t* X, double* F,double* weights, int n,double* sigma); /*updates the weights {weights} and value of ${sigma} given the lighting model {l_data} values and {X} and F(X)*/ typedef double shading_function(r3_t* normal,void* l_data); /*Given a normal and the lighting model, returns its light intensity*/ typedef void write_light_function(FILE* arq,void* l_data); /*writes {l_data} parameters into {arq} the parameters in humam-readable fashion*/ typedef int validate_function(double* c, int basis_size, bool_t* validity_array) ; /*Given a coeficient array and its size, fills in a validity array wich tells wich coeficients are valid*/ typedef void* copy_lighting_data_function(void* l_data); /*Given a lighting_data structure creates a copy of it with same parameters*/ typedef double compare_lightings_function(void* l_data1,void* l_data2); /*Given two lighting data structures , compute its difference*/ typedef void release_lighting_data_function(void* l_data); /*Releases a given lighting data structure*/ typedef enum{ POINTLIKE_MODEL, HARMONIC_MODEL, RADIALBASIS_MODEL } lighting_type_t; struct Lighting_Model_t{ lighting_type_t type; void* lighting_data; phi_function* phi; number_components_function* get_num_components; retrieve_function* retrieve_components; update_weight_function* update_weights; validate_function* validate_results; shading_function* shading; write_light_function* write_param; copy_lighting_data_function* copy_lighting_data; compare_lightings_function* compare_lightings; release_lighting_data_function* release_lighting_data; }; typedef struct Lighting_Model_t lighting_model_t; /*Generic Lighting model functions*/ lighting_model_t* create_lighting_model(lighting_type_t type); /*Pointlike Model Functions*/ struct Pointlike_Lighting_t{ r3_t f; /*Light source direction*/ double Ed;/*Light source intensity*/ double Eb;/*Back Plane light intensity*/ double Ei;/*Isotropic term intensity*/ bool_t BPL;/*Enables/disables BackPlane Ligthing model*/ double albedo; /*Gauge albedo*/ }; typedef struct Pointlike_Lighting_t pointlike_lighting_t; pointlike_lighting_t* pointlike_init_components(double albedo,bool_t BPL); /*The lighting model initialization cannot be not generic, since each one has its init params For the Pointlike case, they are the gauge albedo{albedo} and if the model supports BackPlane Lighting or not*/ double pointlike_phi(int r, r3_t *normal,void* l_data); int pointlike_get_number_components(void* l_data); void pointlike_retrieve_components(double* C, int n,void* l_data); void pointlike_update_weights(void* l_data,r3_t* X, double* F,double* weights, int n,double* sigma); double pointlike_shading(r3_t* normal,void* l_data); void pointlike_write_params(FILE* arq,void* l_data); void* pointlike_copy_lighting_data(void* l_data); double pointlike_compare_lightings(void* l_data1,void* l_data2); void pointlike_release_lighting_data(void* l_data); /*Harmonic Model Functions*/ struct Harmonic_Lighting_t{ int num_comp; /*Number of triplests in the harmonic function*/ double** triplets; /*Set of triplets of the harmonic function*/ double* coeficients /*Value of each coeficient of the harmonic function*/; }; typedef struct Harmonic_Lighting_t harmonic_lighting_t; harmonic_lighting_t* harmonic_init_components(int g); /*Determines the degree of the triplets of the harmonic model*/ double harmonic_phi(int r, r3_t* normal, void* l_data); int harmonic_get_number_components(void* l_data); void harmonic_retrieve_components(double* C, int n,void* l_data); void harmonic_update_weights(void* l_data,r3_t* X, double* F,double* weights, int n,double * sigma); double harmonic_shading(r3_t* normal,void* l_data); void harmonic_write_params(FILE* arq,void* l_data); void* harmonic_copy_lighting_data(void* l_data); double harmonic_compare_lightings(void* l_data1,void* l_data2); void harmonic_release_lighting_data(void* l_data); /*Radial Basis model*/ struct RadialBasis_Lighting_t{ int num_comp; /*Number of radial bases*/ r3_t* bcenter; /*centers of each radial basis coeficient*/ double* bradius;/*radius of each radial basis coeficient*/ double* coeficients; /*ditto*/ }; typedef struct RadialBasis_Lighting_t radialbasis_lighting_t; radialbasis_lighting_t* radialbasis_init_components(int resolution,double span,r2_t center,double raio, r2_t estica,r3_t pole); /*Given Resolution, Span, center, radius,stretch and "north pole" direction, generate the terms of the radial basis */ double radialbasis_phi(int r, r3_t* normal, void* l_data); int radialbasis_get_number_components(void* l_data); void radialbasis_retrieve_components(double* C, int n,void* l_data); void radialbasis_update_weights(void* l_data,r3_t* X, double* F,double* weights, int n,double * sigma); double radialbasis_shading(r3_t* normal,void* l_data); void radialbasis_write_params(FILE* arq,void* l_data); void* radialbasis_copy_lighting_data(void* l_data); double radialbasis_compare_lightings(void* l_data1,void* l_data2); void radialbasis_release_lighting_data(void* l_data); /*Validation functions*/ int NoValidation(double* c, int basis_size, bool_t* validity_array); /*Dummy function that aways returns as valid a given array */ #endif