double dlognormal(double *x, double *mean, double **var,int len) { // The log density of the multivariate normal distribution // (-nrow(y)/2)*log(2*pi)-0.5*log(det(cov))-0.5*t(y-mean)%*%solve(cov)%*%(y-mean) double dens,determinant,**invvar,**vartemp,bigsum=0; int i,j; vartemp = (double **)calloc(len, sizeof(double *)); for (i=0;i<len;i++) { vartemp[i] = (double *)calloc(len, sizeof(double)); } for(i=0;i<len;i++) { for(j=0;j<len;j++) { vartemp[i][j]=var[i][j]; } } determinant = deter(vartemp,len); invvar = generate_identity(len); GaussJordan(len,var,invvar); for(i=0;i<len;i++) { for(j=0;j<len;j++) { bigsum += (x[j]-mean[j])*(x[i]-mean[i])*invvar[i][j]; } } dens = -(double)len/2 * log(2*PI) - 0.5*log(determinant)-0.5*bigsum; return(dens); }
int generate_clut_texture2() { static unsigned int _texture_id = 0; if (_texture_id != 0) return _texture_id; //char *file_name = "custom_hald_clut.tga"; //int i; int level = 8; float *data; data = generate_identity(level); IF_ASSERT(data == NULL) return 0; for (int i = 0; i < level * level * level * level * level * level; i++) { correction_end_twist(&data[i * 3], 0.3f); // correction_mono_edge(&data[i * 3], 1); // correction_desaturate_darks(&data[i * 3]); // correction_dark_color(&data[i * 3], 0.6, 0.3, 1); // correction_deep_dark_color(&data[i * 3], 0.6, 0.3, 1); } for (int i = 0; i < 3 * level * level * level * level * level * level; i++) { if (data[i] > 1) data[i] = 1; if (data[i] < 0) data[i] = 0; } int w = level*level; int h = level*level; int d = level*level; glGenTextures(1, &_texture_id); glEnable(GL_TEXTURE_3D); glBindTexture(GL_TEXTURE_3D, _texture_id); glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //GLuint internalFormat = GL_SRGB8_ALPHA8_EXT; //GL_RGBA; //GLuint internalFormat = GL_SRGB8_ALPHA8; //GL_RGBA; GLuint internalFormat = GL_RGB; GLuint format = GL_RGB; //glTexImage3D(GL_TEXTURE_3D, 0, internalFormat, w, h, d, 0, format, GL_UNSIGNED_BYTE, data); // glTexImage3D(GL_TEXTURE_3D, 0, internalFormat, w, h, d, 0, format, GL_FLOAT, data); // //p_glTexImage3DEXT(GL_TEXTURE_3D, 0, GL_RGB, x, y, z, 0, GL_RGB, GL_FLOAT, data); glDisable(GL_TEXTURE_3D); CHECK_GL_ERROR(); GS_ASSERT(_texture_id != 0); free(data); return _texture_id; }
long int createBox(std::vector<Box*> &vectorBox, Data &data) { long int nbBoxComputed = 0; // Make a list of indices of facilities and sort them std::vector<int> sorted_fac( data.getnbFacility() ); // sorted_fac = 0...n-1 std::generate( sorted_fac.begin(), sorted_fac.end(), generate_identity() ); // Compute Box list using a GRASP (for capacitated) if ( Argument::capacitated && Argument::paving_grasp ) { initBoxCapacitated(vectorBox, data, sorted_fac); } // Add the first boxes with only one facility opened (for uncapacitated) else { Box *box0 = new Box(data); addChildren(box0, vectorBox, sorted_fac); delete box0; } for (unsigned int it = 0; it < vectorBox.size();) { ++nbBoxComputed; // If the box gives an unfeasible subproblem if ( !vectorBox[it]->isFeasible() ) { addChildren(vectorBox[it], vectorBox, sorted_fac); delete vectorBox[it]; vectorBox.erase(vectorBox.begin() + it); } //If the box is dominated by its origin by all the existing boxes else if ( isDominatedByItsOrigin(vectorBox, vectorBox[it]) ) { delete vectorBox[it]; vectorBox.erase(vectorBox.begin() + it); } else { //Compute all potential children of this box as candidates boxes addChildren(vectorBox[it], vectorBox, sorted_fac); //Compute bounds of this box vectorBox[it]->computeBox(); //If this box is dominated by all the boxes (existing + its children) regarding to its bounds if (isDominatedByItsBox(vectorBox, vectorBox[it])) { delete vectorBox[it]; vectorBox.erase(vectorBox.begin() + it); } else { //If one of all others boxes are dominated by this box, we delete it for (unsigned int it2 = 0; it2 != it;) { if (isDominatedBetweenTwoBoxes(vectorBox[it2], vectorBox[it])) { delete vectorBox[it2]; vectorBox.erase(vectorBox.begin() + it2); //We delete an element before (the list shift one step forward), so we shift one step backward --it; } else { ++it2; } } ++it; } } } if (Argument::mode_export) { ToFile::saveInitialBoxes(vectorBox, data); } return nbBoxComputed; }