Statistiques
| Révision :

root / bin / compute_shapes.cpp @ 1

Historique | Voir | Annoter | Télécharger (1,04 ko)

1
#include "constants.h"
2
#include "compute_shapes.h"
3
#include <stdio.h>
4

    
5
/* this function computes the shape of each cell, as its covariance matrix */
6

    
7
void compute_shapes(double *vertices, int *cells_vertices, int *vertices_number_in_each_cell,
8
                    int cell_number, double *barycenters, double *shapes){
9

    
10
int i,j,min,max; double N;
11

    
12
for (i=0;i<cell_number;i++){ shapes[3*i]=0; shapes[3*i+1]=0; shapes[3*i+2]=0;}
13

    
14
for (i=0;i<cell_number;i++){ min=vertices_number_in_each_cell[i]; max=vertices_number_in_each_cell[i+1]; N=(double)(max-min);
15
    for (j=0;j<max-min;j++){
16
        shapes[3*i]+=(vertices[2*cells_vertices[min+j]]-barycenters[2*i])*(vertices[2*cells_vertices[min+j]]-barycenters[2*i]);
17
        shapes[3*i+1]+=(vertices[2*cells_vertices[min+j]+1]-barycenters[2*i+1])*(vertices[2*cells_vertices[min+j]+1]-barycenters[2*i+1]);
18
        shapes[3*i+2]+=(vertices[2*cells_vertices[min+j]+1]-barycenters[2*i+1])*(vertices[2*cells_vertices[min+j]]-barycenters[2*i]);}
19

    
20
    shapes[3*i]/=N; shapes[3*i+1]/=N; shapes[3*i+2]/=N;}
21
}