/// //Initializes a material // //Parameters: // mat: A pointer to the material to initialize // t: A pointer to the texture which this material represents an instance of void Material_Initialize(Material* mat, Texture* t) { //Allocate & Initialize color matrix mat->colorMatrix = Matrix_Allocate(); Matrix_Initialize(mat->colorMatrix, 4, 4); //Allocate & initialize tile vector mat->tile = Vector_Allocate(); Vector_Initialize(mat->tile, 2); mat->tile->components[0] = mat->tile->components[1] = 1.0f; mat->texture = t; }
/// //Initializes all members of a Game Object (GObject) // //Parameters: // GO: The Game Object to initialize void GObject_Initialize(GObject* GO) { GO->frameOfReference = FrameOfReference_Allocate(); FrameOfReference_Initialize(GO->frameOfReference); GO->colorMatrix = Matrix_Allocate(); Matrix_Initialize(GO->colorMatrix, 4, 4); GO->states = LinkedList_Allocate(); LinkedList_Initialize(GO->states); GO->mesh = NULL; GO->texture = NULL; GO->body = NULL; GO->collider = NULL; }
// strFile pointe vers l'image à ouvrir // QMu indique la direction de la transformée de Fourier Utilisée dans cette fonction void Construct_Vues_Frequentielles(char * strFile, Quaternion QMu, double seuil) { double **dblMatAngle,**dblMatLogModule,**dblMatLogModuleScaled, **dblMatAngleScaled,**dblMatAngleMod; int i,j,dim[2],type,blnReal; unsigned char ** blnLogModulusMaskMat; double *r,*g,*b, *dblData; Quaternion **QMatrix,**QMatFourier,**QMatrixShifted,**QMatAxe, **QMatAxeScaled,**QPureAxeMatMasked,**QAngleColourMasked,**QMatAxeScaled2; double dblMin,dblMax,dblRMin,dblRMax,dblIMin,dblIMax,dblJMin,dblJMax,dblKMin,dblKMax; char * result; //pour la chaine de caractere modifiant le nom du fichier //lecture de l'en-tete MgkTypeImage(strFile,dim,&type); //allocation des tableaux r,g et b r = (double *)malloc(dim[0]*dim[1]*sizeof(double)); g = (double *)malloc(dim[0]*dim[1]*sizeof(double)); b = (double *)malloc(dim[0]*dim[1]*sizeof(double)); //remplissage des tableaux MgkLireImgCouleur(strFile,r,g,b); //copie dans matrice quaternionique QMatrixAllocate(dim[0],dim[1],&QMatrix); QSetMatrix(r,g,b,dim[0],dim[1],&QMatrix); printf("Moyenne de l'image d'origine :R%lf G%lf B%lf\n",VectMean_Double(r,dim),VectMean_Double(g,dim),VectMean_Double(b,dim)); free(r); free(g); free(b); // traitement dans l'espace de fourier QMatrixAllocate(dim[0],dim[1],&QMatFourier); printf("quaternionic fourier transform is processing ...\n"); Quaternion_Matrix_Fourier_Transform_ExpLeft(QMatrix,&QMatFourier,QMu,dim[0],dim[1]); printf("done.\n"); QMatrixFree(dim[0],&QMatrix); QMatrixAllocate(dim[0],dim[1],&QMatrixShifted); QMatrixShift(QMatFourier,&QMatrixShifted,dim[0],dim[1]); QMatrixFree(dim[0],&QMatFourier); //maintenant on a la matrice QMatFourier qui comprend les informations fréquentielles de l'image // soucis avec cette méthode, on utilise des quaternions purs dans le domaine statial // faire attention qu'il n'y ait pas de partie réelle nulle dans le domaine fréquentiel // car problème après avec S(q)=0 pour calculer le phi=atan(|V(q)|/S(q)) // donc ici on vérifie pas de partie réelle nulle // à faire blnReal=IsRealPresent(QMatrixShifted,dim,0.00001); printf("La partie réelle de la transformée de Fourier Quaternionique est non nulle (1 oui, 0 non):%d\n",blnReal); // on alloue les différentes matrices qui vont nous servir juste après. Matrix_Allocate_Double(dim[0],dim[1],&dblMatLogModule); Matrix_Allocate_Double(dim[0],dim[1],&dblMatAngle); QMatrixAllocate(dim[0],dim[1],&QMatAxe); //puis on calcule pour chaque point de la matrice, son module, son angle et son axe. Calcul_Matrice_LogRo_Mu_Phi((const Quaternion **)QMatrixShifted,&dblMatLogModule,&dblMatAngle,&QMatAxe,dim[0],dim[1]); QMatrixFree(dim[0],&QMatrixShifted); /////////////////////////////////////////////////////////////////////////////////////////////// // MODULE printf("construction de la vue du module...\n"); //le log du module est calculé suivant cette formule: *LogRo = log(QNorm(q)); Dbl_Matrix_Min_Max((const double **) dblMatLogModule,dim,&dblMin,&dblMax); Matrix_Allocate_Double(dim[0],dim[1],&dblMatLogModuleScaled); Dbl_Mat_ChgScale_IntLvlMax((const double **) dblMatLogModule,dim,255,dblMin,dblMax,&dblMatLogModuleScaled); Matrix_Free_Double(dim[0],&dblMatLogModule); //on construit le masque a partir du log du module pour appliquer sur l'angle et l'axe Matrix_Allocate(dim[0],dim[1],&blnLogModulusMaskMat); Mask_From_LogModulus(seuil,dim,dblMatLogModuleScaled,&blnLogModulusMaskMat); //allocation sous forme de tableau monodimensionnel pour passe en argument a la fonction MgkEcrireImgGris dblData = (double *)malloc(dim[0]*dim[1]*sizeof(double)); //GetUsgCharMatrix(Spectre255,&dblData,dim); GetDblTabMatrix(dblMatLogModuleScaled,&dblData,dim); Matrix_Free_Double(dim[0],&dblMatLogModuleScaled); result = (char *)malloc((10+strlen(strFile))*sizeof(char)); strcpybtw(&result,strFile,"-qft-mod",'.'); MgkEcrireImgGris(result,dblData,dim); printf("\nimage %s creee\n\n",result); free(result); /////////////////////////////////////////////////////////////////////////////////////////////// // PHASE printf("construction de la vue de l'angle...\n"); //la phase est calculée suivant cette formule: *Phi = atan(QNorm(QImag(q))/QReal(q)); // -pi/2 < phi < pi/2 Dbl_Matrix_Min_Max((const double **) dblMatAngle,dim,&dblMin,&dblMax); printf("Angle min %lf Angle max %lf\n",dblMin,dblMax); //Matrix_Allocate_Double(dim[0],dim[1],&dblMatAngleScaled); //Dbl_Mat_ChgScale_LvlMin_LvlMax((const double **) dblMatAngle,dim,0.,2*M_PI,dblMin,dblMax,&dblMatAngleScaled); //Matrix_Free_Double(dim[0],&dblMatAngle); QMatrixAllocate(dim[0],dim[1],&QAngleColourMasked); QMat_Angle_Construct_WithLogModMask(dim,blnLogModulusMaskMat,dblMatAngle,&QAngleColourMasked); Matrix_Free_Double(dim[0],&dblMatAngle); r = (double *)malloc(dim[0]*dim[1]*sizeof(double)); g = (double *)malloc(dim[0]*dim[1]*sizeof(double)); b = (double *)malloc(dim[0]*dim[1]*sizeof(double)); QGetMatrixImagPart(&r,&g,&b,dim[0],dim[1],QAngleColourMasked); QMatrixFree(dim[0],&QAngleColourMasked); result = (char *)malloc((10+strlen(strFile))*sizeof(char)); strcpybtw(&result,strFile,"-qft-angle",'.'); MgkEcrireImgCouleur(result,r,g,b,dim); printf("\nimage %s creee\n\n",result); free(result); printf("Moyenne de l'image de l'angle :R%lf G%lf B%lf\n",VectMean_Double(r,dim),VectMean_Double(g,dim),VectMean_Double(b,dim)); free(r); free(g); free(b); /////////////////////////////////////////////////////////////////////////////////////////////// // AXE printf("construction de la vue de l'axe...\n"); //l'axe est calculé suivant cette formule: *qMu = QScalDiv(QImag(q),QNorm(QImag(q))); QMat_Min_Max2((const Quaternion **)QMatAxe,dim,&dblMin,&dblMax); QMatrixAllocate(dim[0],dim[1],&QPureAxeMatMasked); QMat_Axe_Construct_WithLogModMask(dim,blnLogModulusMaskMat,QMatAxe,&QPureAxeMatMasked); Matrix_Free(dim[0],&blnLogModulusMaskMat); QMatrixFree(dim[0],&QMatAxe); QMat_Min_Max((const Quaternion **)QPureAxeMatMasked,dim,&dblRMin,&dblRMax,&dblIMin,&dblIMax,&dblJMin,&dblJMax,&dblKMin,&dblKMax); QMatrixAllocate(dim[0],dim[1],&QMatAxeScaled); QMat_ChgScale_IntLvlMax((const Quaternion **)QPureAxeMatMasked,dim,255,dblRMin,dblRMax,dblIMin,dblIMax,dblJMin,dblJMax, dblKMin,dblKMax,&QMatAxeScaled); QMatrixFree(dim[0],&QPureAxeMatMasked); r = (double *)malloc(dim[0]*dim[1]*sizeof(double)); g = (double *)malloc(dim[0]*dim[1]*sizeof(double)); b = (double *)malloc(dim[0]*dim[1]*sizeof(double)); QGetMatrixImagPart(&r,&g,&b,dim[0],dim[1],QMatAxeScaled); QMatrixFree(dim[0],&QMatAxeScaled); result = malloc((10+strlen(strFile))*sizeof(char)); strcpybtw(&result,strFile,"-qft-axe",'.'); MgkEcrireImgCouleur(result,r,g,b,dim); printf("\nimage %s creee\n\n",result); free(result); free(r); free(g); free(b); }