From fdf13216f5776fc8d4bb6e748894de8c1e7bcbc8 Mon Sep 17 00:00:00 2001 From: poulpe <poulpe@localhost.localdomain> Date: Sat, 8 May 2021 14:32:15 +0200 Subject: [PATCH] [Update] Help from Scott Birner for quadtree_position --- main.c | 11 +++++++++-- pgm_io.c | 4 ++-- pgm_io.h | 4 ++-- quadtree.c | 6 ++++-- quadtree.h | 2 +- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/main.c b/main.c index e010809..0e330a9 100644 --- a/main.c +++ b/main.c @@ -7,14 +7,21 @@ #include "quadtree.h" #include "Matrix.h" -int main(int argc,char** argvs) +int main() { + pgm* p = malloc(1 * sizeof(pgm)); pgm_read_from_file(p,"buzz.pgm"); - uint32_t val = quadtree_get_depth_from_image_size(p->pixels.col,p->pixels.lin); + uint32_t val = quadtree_get_depth_from_image_size(p->pixels.col); printf("Depth : %u\n",val); node* tree = quadtree_tree_create(val); + matrix_print(p->pixels); + quadtree_matrix2tree(&p->pixels,tree); + + + quadtree_print(tree,1,"|"); + matrix_destroy(&p->pixels); quadtree_tree_destroy(&tree); free(p); diff --git a/pgm_io.c b/pgm_io.c index 6bcb195..7d67a0e 100644 --- a/pgm_io.c +++ b/pgm_io.c @@ -14,7 +14,7 @@ * @param filename = the file path of the image to read * @return pgm_error */ -pgm_error pgm_read_from_file(pgm *p,char *filename) +pgm_error pgm_read_from_file(pgm *p,const char* const filename) { int sizex = 0; int sizey = 0; @@ -127,7 +127,7 @@ pgm_error pgm_duplicate(char *filename,char *newfile) * @param gray_scale = the gray scale max in file returned by pointed value * @return pgm_error */ -pgm_error pgm_read_header(char *filename,int *sizex,int *sizey,int *gray_scale) +pgm_error pgm_read_header(const char* const filename,int *sizex,int *sizey,int *gray_scale) { FILE *f; f = fopen(filename,"r"); diff --git a/pgm_io.h b/pgm_io.h index 5d71f27..7b99628 100644 --- a/pgm_io.h +++ b/pgm_io.h @@ -18,9 +18,9 @@ int32_t max; matrix pixels; } pgm; -pgm_error pgm_read_from_file(pgm *p,char *filename); +pgm_error pgm_read_from_file(pgm *p,const char* const filename); pgm_error pgm_write_from_file(pgm *p,char *filename); pgm_error pgm_duplicate(char *filename,char *newfile); -pgm_error pgm_read_header(char *filename,int *sizex,int *sizey,int *gray_scale); +pgm_error pgm_read_header(const char* const filename,int *sizex,int *sizey,int *gray_scale); #endif \ No newline at end of file diff --git a/quadtree.c b/quadtree.c index d7fb735..178184d 100644 --- a/quadtree.c +++ b/quadtree.c @@ -5,7 +5,7 @@ bool quadtree_is_leaf(node *nd) return (NULL == nd->child[0]); } -int32_t quadtree_get_depth_from_image_size(int32_t sizex, int sizey) +int32_t quadtree_get_depth_from_image_size(int32_t sizex) { return (int32_t)log2(sizex); } @@ -104,7 +104,9 @@ node *quadtree_position(int32_t li, int32_t col, node *a, int32_t d) node *crt = a; do { - int32_t index = 666666; //choisir le sous-cadran de <li> et <co> + int32_t ligne = (li>>d) & 1; // Permet de sélectionne le bit à considérer en fonction de la profondeur; Exemple: 10 >> 1 = 1 + int32_t colonne = (col>>d) & 1; //Exemple: 10 >> 1 = 1; + int32_t index = ligne<<1 | colonne; //Exemple: 1<<1 = 10 | 1(col) = 11=>3 crt = crt->child[index]; d--; } while (!quadtree_is_leaf(crt)); diff --git a/quadtree.h b/quadtree.h index 674ac74..1fdf349 100644 --- a/quadtree.h +++ b/quadtree.h @@ -18,7 +18,7 @@ node* quadtree_tree_create(int32_t depth); bool quadtree_is_leaf(node *nd); -int32_t quadtree_get_depth_from_image_size(int32_t sizex,int sizey); +int32_t quadtree_get_depth_from_image_size(int32_t sizex); int32_t quadtree_max(int32_t x, int32_t y); -- GitLab