Skip to content
Snippets Groups Projects
Commit fdf13216 authored by poulpe's avatar poulpe
Browse files

[Update] Help from Scott Birner for quadtree_position

parent 56261beb
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
......@@ -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");
......
......@@ -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
......@@ -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));
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment