コード例 #1
0
ファイル: approximation.c プロジェクト: NoRomaneNoCry/MG
Table_flottant steps_computation(Table_triplet points, Booleen uniformConf) {

	int i;

	Table_flottant steps;
	steps.nb = points.nb;
	ALLOUER(steps.table, steps.nb);

	if(uniformConf) {
		for(i = 0; i < steps.nb; i++)
			steps.table[i] = i * (1.f / (points.nb - 1));
	}
	else {
		double totalDistance = 0;
		steps.table[0] = 0.f;
		for(i = 1; i < steps.nb; i++) {
			totalDistance += distance(points.table[i-1], points.table[i]);
			steps.table[i] = totalDistance;
		}
		for(i = 1; i < steps.nb; i++)
			steps.table[i] /= totalDistance;
	}

	return steps;
}
コード例 #2
0
ファイル: sys_lin.c プロジェクト: Apolerag/MG
Grille_flottant duplique_Grille_flottant(Grille_flottant *original)
{
  int i,j;  
  Grille_flottant copie;

  ALLOUER(copie.grille,original->nb_lignes);
  copie.nb_lignes = original->nb_lignes;
  copie.nb_colonnes = original->nb_colonnes;
   
  for (i=0 ; i<original->nb_lignes ; i++)
  {
    ALLOUER(copie.grille[i],original->nb_colonnes);
    for (j=0 ; j<original->nb_colonnes ; j++)
      copie.grille[i][j] = original->grille[i][j];
  }

  return copie;
}
コード例 #3
0
ファイル: sf.c プロジェクト: duythanhphan/DCT-4
/*
 * Allocation des la structure et remplissage des champs pour initialiser
 * le tableau des événements avec l'événement ESCAPE (avec une occurrence).
 */
struct shannon_fano* open_shannon_fano()
{
	struct shannon_fano* sf;
	ALLOUER(sf,1);
	sf->nb_evenements = 1; 
	sf->evenements[0].valeur = VALEUR_ESCAPE;
	sf->evenements[0].nb_occurrences = 1; 
	return sf;
}
コード例 #4
0
ファイル: pile.c プロジェクト: Apolerag/Projet_GAM
Pile* initialiserPile()
{
	Pile *p;
	ALLOUER(p,1);
	p->dernierPile = NULL;
	p->nbPile = 0;
	p->maxPile = 0;
	return p;
}
コード例 #5
0
ファイル: sys_lin.c プロジェクト: Apolerag/MG
Grille_flottant produit_matrice(Grille_flottant *a, Grille_flottant *b)
{
  int j, i, k ;
  Grille_flottant res;
  res.nb_lignes = a->nb_lignes;
  res.nb_colonnes = b->nb_colonnes;

  ALLOUER(res.grille, res.nb_lignes);
  for (i=0 ; i < res.nb_lignes ; i++) {
    ALLOUER(res.grille[i],res.nb_colonnes);
  }

  for(i=0; i < a->nb_lignes; ++i){
    for(j=0; j < b->nb_colonnes; ++j) {
      res.grille[i][j] = 0 ;
      for(k=0; k < a->nb_colonnes; ++k)
        res.grille[i][j] += a->grille[i][k]*b->grille[k][j] ;
    }
  }
  return res;
}
コード例 #6
0
ファイル: sys_lin.c プロジェクト: Apolerag/MG
Table_flottant duplique_Table_flottant(Table_flottant *original)
{
   int i;  
   Table_flottant copie;

   ALLOUER(copie.table,original->nb);
   copie.nb = original->nb ;
   
   for (i=0 ; i<original->nb ; i++)     
            copie.table[i] = original->table[i];

   return copie;
}
コード例 #7
0
ファイル: surface_bezier.c プロジェクト: Apolerag/MG
void calcul_surface_bezier(surface_bezier *sb)
{
	int i,j;
	Grille_quadruplet Ginv;
	Grille_triplet courbeU;

	courbeU.nb_lignes = sb->G.nb_lignes;
	courbeU.nb_colonnes = sb->u;
	sb->surface.nb_lignes = sb->u;
	sb->surface.nb_colonnes = sb->v;
	printf("u %d, v %d \n", sb->u, sb->v);

	Ginv.nb_lignes = courbeU.nb_colonnes;
	Ginv.nb_colonnes = courbeU.nb_lignes;

	ALLOUER(courbeU.grille, courbeU.nb_lignes);
	for (i = 0; i < courbeU.nb_lignes; i++)
		ALLOUER(courbeU.grille[i], courbeU.nb_colonnes);

	ALLOUER(Ginv.grille, Ginv.nb_lignes);
	for (i = 0; i < Ginv.nb_lignes; i++)
		ALLOUER(Ginv.grille[i], Ginv.nb_colonnes);

	ALLOUER(sb->surface.grille, sb->surface.nb_lignes);
	for (i = 0; i < sb->surface.nb_lignes; i++)
		ALLOUER(sb->surface.grille[i], sb->surface.nb_colonnes);

	for (i = 0; i < courbeU.nb_lignes; i++)
	{
		Casteljau(courbeU.grille[i] ,sb->G.grille[i],
			sb->G.nb_colonnes, courbeU.nb_colonnes);
	}

	for (i = 0; i < Ginv.nb_colonnes; i++)
	{
		for (j = 0; j < Ginv.nb_lignes; j++)
		{
			Ginv.grille[j][i].x = courbeU.grille[i][j].x;
			Ginv.grille[j][i].y = courbeU.grille[i][j].y;
			Ginv.grille[j][i].z = courbeU.grille[i][j].z;
			Ginv.grille[j][i].h = 1;
		}
	}


	for (i = 0; i < sb->surface.nb_lignes; i++)
	{
		Casteljau(sb->surface.grille[i] ,Ginv.grille[i],
			Ginv.nb_colonnes, sb->surface.nb_colonnes);
	}

	for (i = 0; i < Ginv.nb_lignes; i++)
		free(Ginv.grille[i]);
	free(Ginv.grille);

	for (i = 0; i < courbeU.nb_lignes; i++)
		free(courbeU.grille[i]);
	free(courbeU.grille);
}
コード例 #8
0
ファイル: nurbs.c プロジェクト: NoRomaneNoCry/MG
Table_quadruplet computeAllPointsNurbs(Table_quadruplet controlPoints, int ptNumber,
	int degree, Table_flottant nodalVector) {

	int i;
	double step = 1.f / (ptNumber - 1);

	Table_quadruplet points;
	points.nb = ptNumber;
	ALLOUER(points.table, ptNumber);

	for(i = 0; i < ptNumber; i++)
		points.table[i] = computePointNurbs(controlPoints, i * step, degree, nodalVector);

	return points;
}
コード例 #9
0
ファイル: nurbs.c プロジェクト: NoRomaneNoCry/MG
Table_flottant computeNodalVector(int n, int k) {

	int i;
	Table_flottant tab;
	tab.nb = n+k+1;
	ALLOUER(tab.table, n+k+1);

	for(i = 0; i < k; i++)
		tab.table[i] = 0;
	for(i = k; i <= n ; i++)
		tab.table[i] = (i - k + 1.f)/(n - k + 2.f);
	for(i = n+1; i <= n+k; i++)
		tab.table[i] = 1;

	return tab;
}
コード例 #10
0
ファイル: sys_lin.c プロジェクト: Apolerag/MG
Table_flottant produit_matrice_vecteur(Grille_flottant *mat, Table_flottant *v)
{
  int i, k ;
  Table_flottant res;
  res.nb = v->nb;

  ALLOUER(res.table, res.nb);

  for(i=0; i < mat->nb_lignes; ++i){
    res.table[i] = 0 ;
    for(k=0; k < mat->nb_colonnes; ++k)
      res.table[i] += mat->grille[i][k]*v->table[k] ;
    
  }
  return res;
}
コード例 #11
0
ファイル: nurbs.c プロジェクト: NoRomaneNoCry/MG
Quadruplet computePointNurbs(Table_quadruplet controlPoints, double u, int degree,
	Table_flottant nodalVector) {

	Quadruplet coords;
	int i, j, r;
	int k = degree + 1;
	double ui, uikj;
	double coefi, coefi1;

	Quadruplet * temp;
	ALLOUER(temp, controlPoints.nb);

	for(i = 0; i < nodalVector.nb-1; i++) {
		if(u >= nodalVector.table[i] && (u < nodalVector.table[i+1])) {
			r = i;
			break;
		}
	}

	for(i = 0; i < controlPoints.nb; i++) {
		temp[i].x = controlPoints.table[i].x * controlPoints.table[i].h;
		temp[i].y = controlPoints.table[i].y * controlPoints.table[i].h;
		temp[i].z = controlPoints.table[i].z * controlPoints.table[i].h;
		temp[i].h = controlPoints.table[i].h;
	}

	for(j = 1; j <= degree; j++) {		
		for(i = r - k + 1 + j; i <= r; i++) {
			ui = nodalVector.table[i];
			uikj = nodalVector.table[i+k-j];
			coefi = (u - ui) / (uikj - ui);
			coefi1 = (uikj - u) / (uikj - ui);
			temp[i].x = coefi * temp[i].x + coefi1 * temp[i-1].x;
			temp[i].y = coefi * temp[i].y + coefi1 * temp[i-1].y;
			temp[i].z = coefi * temp[i].z + coefi1 * temp[i-1].z;
			temp[i].h = coefi * temp[i].h + coefi1 * temp[i-1].h;
		}
	}

	coords.x = temp[r].x / temp[r].h;
	coords.y = temp[r].y / temp[r].h;
	coords.z = temp[r].z / temp[r].h;
	coords.h = temp[r].h;

	free(temp);
	return coords;
}
コード例 #12
0
ファイル: approximation.c プロジェクト: NoRomaneNoCry/MG
double * matrix_vector_mult(double ** B, double * V, int size) {

	int i, j;
  	double s;

  	double * mult;
  	ALLOUER(mult, size);

  	for(j = 0; j < size; j++)
    {
      	s = 0;
      	for(i = 0; i < size; i++)
			s += B[j][i] * V[i];
      	
      	mult[j] = s;
    }

    return mult;
}
コード例 #13
0
static void ac_update_curve_points(struct approximation_curve* ac)
{
  int i;
  float step;

  // Réallocation de la table de points si nécessaire
  if (ac->curve_points.nb != ac->curve_point_count)
  {
    free(ac->curve_points.table);

    ac->curve_points.nb = ac->curve_point_count;
    ALLOUER(ac->curve_points.table, ac->curve_points.nb);
  }

  step = 1.f / (ac->curve_point_count - 1);

  for (i = 0; i < ac->curve_point_count; ++i)
    ac->curve_points.table[i] = casteljau(&ac->curve_polygon, i * step);
}
コード例 #14
0
ファイル: intstream.c プロジェクト: Apolerag/TP_DCT
struct intstream* open_intstream(struct bitstream *bitstream
				 , enum intstream_type type
				 , struct shannon_fano *shannon_fano)
{
  struct intstream *is ;

  ALLOUER(is, 1) ;
  is->bitstream = bitstream ;
  is->type = type ;

  if ( type == Shannon_fano )
    {
      if ( shannon_fano == NULL )
	EXIT ;
      is->shannon_fano = shannon_fano ;
    }

  return(is) ;
}
コード例 #15
0
ファイル: surface_bezier.c プロジェクト: Apolerag/MG
void Casteljau(Triplet * courbe, Quadruplet *poly, const int nbPoly, const int nbAffiche)
{          
	int i,j,k;

	double u = (double)1/(nbAffiche + 1);

	Quadruplet* Quad;                       

	ALLOUER(Quad, nbPoly);//Allocation du tableau de Quad

	for(k = 0; k < nbAffiche; ++k)
	{
		for (j = 0; j < nbPoly; j++)
		{
			Quad[j] = poly[j];
		}

		for(j = nbPoly -1; j > 0 ; --j)
		{
			for(i = 0; i < j ; i++)
			{
				//Calcul
				Quad[i].x = (u * Quad[i+1].x) + (1-u) * Quad[i].x;	
				Quad[i].y = (u * Quad[i+1].y) + (1-u) * Quad[i].y;
				Quad[i].z = (u * Quad[i+1].z) + (1-u) * Quad[i].z;
				Quad[i].h = (u * Quad[i+1].h) + (1-u) * Quad[i].h;
			}
		}
		if(Quad[0].h == 0) Quad[0].h = 1;
	    courbe[k].x = Quad[0].x /Quad[0].h;
	    courbe[k].y = Quad[0].y /Quad[0].h;
		courbe[k].z = Quad[0].z /Quad[0].h;

		u +=  (double)1/(nbAffiche + 1);
	}
	free(Quad);
}
コード例 #16
0
ファイル: approximation.c プロジェクト: NoRomaneNoCry/MG
Table_quadruplet least_squares_approximation(Table_triplet points, 
	Booleen uniformConf) {

	int i, j;

	Table_quadruplet res;
	res.nb = points.nb;
	ALLOUER(res.table, points.nb);

	Table_flottant steps = steps_computation(points, uniformConf);

	double ** B;
	ALLOUER(B, points.nb);
	for(i = 0; i < points.nb; i++)
		ALLOUER(B[i], points.nb);

	B[0][0] = B[points.nb - 1][points.nb - 1] = 1;
	for(i = 1; i < points.nb; i++)
		B[0][i] = 0;
	for(i = 0; i < points.nb; i++) { 
		for(j = 1; j < points.nb - 1; j++) {
			B[j][i] = bernsteinPolynomial(i, points.nb - 1, steps.table[j]);
		}
	}
	for(i = 0; i < points.nb - 1; i++)
		B[points.nb - 1][i] = 0;

	double ** BT = transposedMatrix(B, points.nb);

	Grille_flottant Aprime;
	Aprime.nb_lignes = Aprime.nb_colonnes = points.nb;
	Aprime.grille = matrix_matrix_mult(B, BT, points.nb);

	for(i = 0; i < points.nb; i++)
		free(BT[i]);
	free(BT);

	double * pointsX, * pointsY, * pointsZ;
	ALLOUER(pointsX, points.nb);
	ALLOUER(pointsY, points.nb);
	ALLOUER(pointsZ, points.nb);
	split_x_y_z(points, pointsX, pointsY, pointsZ);

	Table_flottant BprimeX, BprimeY, BprimeZ;
	BprimeX.nb = BprimeY.nb = BprimeZ.nb = points.nb;
	BprimeX.table = matrix_vector_mult(B, pointsX, points.nb);
	BprimeY.table = matrix_vector_mult(B, pointsY, points.nb);
	BprimeZ.table = matrix_vector_mult(B, pointsZ, points.nb);

	free(pointsX); free(pointsY); free(pointsZ);
	for(i = 0; i < points.nb; i++)
		free(B[i]);
	free(B);

	Table_flottant resX, resY, resZ;
	resX.nb = resY.nb = resZ.nb = points.nb;
	ALLOUER(resX.table, points.nb);
	ALLOUER(resY.table, points.nb);
	ALLOUER(resZ.table, points.nb);

	resolution_systeme_lineaire(&Aprime, &BprimeX, &resX);
	resolution_systeme_lineaire(&Aprime, &BprimeY, &resY);
	resolution_systeme_lineaire(&Aprime, &BprimeZ, &resZ);

	for(i = 0; i < points.nb; i++) {
		res.table[i].x = resX.table[i];
		res.table[i].y = resY.table[i];
		res.table[i].z = resZ.table[i];
		res.table[i].h = 1;
	}

	free(BprimeX.table); free(BprimeY.table); free(BprimeZ.table);
	free(resX.table); free(resY.table); free(resZ.table);
	for(i = 0; i < Aprime.nb_lignes; i++)
		free(Aprime.grille[i]);
	free(Aprime.grille);

	return res;
}
コード例 #17
0
static void ac_update_curve_polygon(struct approximation_curve* ac)
{
  Grille_flottant* m;
  Grille_flottant* mt;
  Grille_flottant* mmt;

  Table_flottant* p;
  Table_flottant* a;
  Table_flottant* mp;

  Table_flottant* params;

  // Allocation de la table des points de contrôle de la courbe d'approximation
  if (ac->curve_polygon.nb != (ac->degree + 1))
  {
    free(ac->curve_polygon.table);

    ac->curve_polygon.nb = ac->degree + 1;
    ALLOUER(ac->curve_polygon.table, ac->curve_polygon.nb);
  }

  // Paramétrisation de la courbe d'approximation
  if (ac->use_uniform_parameterization)
    params = ac_uniform_parameterization(&ac->points);
  else
    params = ac_non_uniform_parameterization(&ac->points);

  // Construction de la matrice de Bernstein, de sa transposée et de leur produit
  m = matrix_create(ac->degree + 1, ac->points.nb);
  ac_bernstein_matrix(m, params);

  mt = matrix_transpose(m);
  mmt = matrix_product(m, mt);

  // Résolution des 3 systèmes d'équations (composantes x, y et z) des points de contrôle recherchés
  p = malloc_table_flottant(ac->points.nb);
  a = malloc_table_flottant(ac->degree + 1);
  mp = malloc_table_flottant(m->nb_lignes);

  // X
  get_triplets_x_values(&ac->points, p);
  matrix_vector_product(m, p, mp);
  if (resolution_systeme_lineaire(mmt, mp, a))
    EXIT;
  set_triplets_x_values(&ac->curve_polygon, a);

  // Y
  get_triplets_y_values(&ac->points, p);
  matrix_vector_product(m, p, mp);
  if (resolution_systeme_lineaire(mmt, mp, a))
    EXIT;
  set_triplets_y_values(&ac->curve_polygon, a);

  // Z
  get_triplets_z_values(&ac->points, p);
  matrix_vector_product(m, p, mp);
  if (resolution_systeme_lineaire(mmt, mp, a))
    EXIT;
  set_triplets_z_values(&ac->curve_polygon, a);

  // Libération des ressources
  matrix_delete(m);
  matrix_delete(mt);
  matrix_delete(mmt);

  free_table_flottant(a);
  free_table_flottant(p);
  free_table_flottant(mp);
  free_table_flottant(params);
}
コード例 #18
0
ファイル: sys_lin.c プロジェクト: Apolerag/MG
int resolution_systeme_lineaire(Grille_flottant  *A, 
                                Table_flottant  *f, 
                                Table_flottant  *x)
{
 double  s,r;
 int i,j,k,n;
 Grille_flottant T;
 Table_flottant  b;
 

   n = A->nb_lignes; 
   if ( (A->nb_lignes != A->nb_colonnes) || (f->nb != A->nb_lignes) ) 
     return 1;

/* copie de la matrice et du second membre pour triangulation  */
   T = duplique_Grille_flottant(A);
   b = duplique_Table_flottant(f);

   /* allocation  solution */ 
   ALLOUER(x->table,n);
   x->nb = n; 

   for (k=0 ; k<n ; k++)
     {
       traite_pivot_max(&T,&b,k);
       if ( fabs(T.grille[k][k]) < ZERO)
         {
          free(x->table);
	  x->nb = 0;
          return(1);
	 }
       for (i=k+1 ; i<n ; i++)
       {   
          
         s = T.grille[i][k]/T.grille[k][k];	
         for (j=k+1 ; j<n ; j++)
             T.grille[i][j]=T.grille[i][j] - T.grille[k][j]*s;	
         b.table[i] -= s*b.table[k]; 
       }
     }

   if (fabs(T.grille[n-1][n -1]) < ZERO)  
   {
       free(x->table);
       x->nb = 0;
       return(1);
   }  

   x->table[n-1] = b.table[n-1]/T.grille[n-1][n-1];
   for (i=n-2 ; i>=0 ; i--)
   {
      r = 0.0;
      for (j=i+1 ; j<n ; j++)
         r += (T.grille[i][j])*(x->table[j]);
      if (fabs(T.grille[i][i]) < ZERO)   return(1);  
      x->table[i] =  (b.table[i] - r)/T.grille[i][i]; 
   }



   free(b.table);
   for (i=0 ; i<T.nb_lignes ; i++)
     free(T.grille[i]);
   free(T.grille);
   
   return(0); 
} 
コード例 #19
0
ファイル: main.c プロジェクト: Apolerag/GAM
int main(int argc, char **argv)  
{  

	int c;
	int pol,conv;
	int option1 = 0, option2 = 0, option3 = 0, option4 = 0;
	int nbPoints = 50;
	vertex *v;
	
	opterr = 0;
	while ((c = getopt(argc, argv, "1i:2o:34n:")) != EOF)
	{
		switch (c)
		{
			case '1': 
				option1 = 1;
				break;
			case '2': 
				option2 = 1;
				break;
			case '3': 
				option3 = 1;
				break;
			case '4': 
				option4 = 1;
				break;
			case 'n': 
				if ((sscanf(optarg, "%d", &nbPoints) != 1) || nbPoints <= 0)
					nbPoints = 50;
				break;
			case 'o': /*verifier non null*/
				out = optarg;
				break;
			case 'i': /*verifier non null*/
				in = optarg; 
				break;
			case 'h': 
			case '?': 
				printf("-1 partie 1 du tp\n");
				printf("-2 partie 2 du tp\n");
				printf("-3 partie 3 du tp\n");
				printf("-ichaine ouvre le fichier \"chaine\" en lecture \n");
				printf("-ochaine ouvre le fichier \"chaine\" en écriture \n");
				return EXIT_SUCCESS;  
				break;
			default : printf("Shouldn't be here, really...\n");
				break;
		}
	}

	glutInit(&argc, argv);  
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);  
	glutInitWindowPosition(5,5);  
	glutInitWindowSize(500,500);

	glutCreateWindow("fenetre"); 
	definitionFenetre(0, 500, 0, 500, 10);
	winInit();

	if(option1 && out != NULL)
	{
		glutDisplayFunc(display);	
		glutMouseFunc(coordonnesPoint);
		ecrireFichier(out, &P);
	}
	else if(option2 && in != NULL)
	{
		lireFichier(in, &P);
		assert(P.p != NULL);
		pol = controlePolygoneSimple();
		printf("controlePolygoneSimple : %d\n", pol);
		//glutDisplayFunc(displayPolygone);
	}
	else if(option3 && in != NULL)
	{
		lireFichier(in, &P);
		assert(P.p != NULL);
		if(controlePolygoneSimple())
			conv = estConvexe();
	}
	else if(option4 && in != NULL)
	{

		lireFichier(in, &P);
		assert(P.p != NULL);
		ALLOUER(v,nbPoints);
		selectPoints (v, nbPoints);
		if(controlePolygoneSimple() && estConvexe())
			positionPointsParRapportPolygone(v, nbPoints);
		free(v);
	}

	glutMainLoop(); 
	clearFenetre();
	return EXIT_SUCCESS;  
}