Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
Quadtree
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fabian.troller
Quadtree
Commits
9b664000
Commit
9b664000
authored
4 years ago
by
poulpe
Browse files
Options
Downloads
Patches
Plain Diff
[Update] Add tree2matrix
parent
fdf13216
No related branches found
No related tags found
No related merge requests found
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
.gitignore
+2
-1
2 additions, 1 deletion
.gitignore
Matrix.c
+10
-10
10 additions, 10 deletions
Matrix.c
Matrix.h
+1
-1
1 addition, 1 deletion
Matrix.h
main.c
+23
-3
23 additions, 3 deletions
main.c
quadtree.c
+63
-4
63 additions, 4 deletions
quadtree.c
quadtree.h
+8
-3
8 additions, 3 deletions
quadtree.h
with
107 additions
and
22 deletions
.gitignore
+
2
−
1
View file @
9b664000
...
...
@@ -4,3 +4,4 @@ tests
Exe
exe
.vscode
*.pgm
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Matrix.c
+
10
−
10
View file @
9b664000
...
...
@@ -8,19 +8,19 @@
#include
"Matrix.h"
// Alloc memory for matrix
error_code
matrix_alloc
(
matrix
*
mat
,
int32_t
m
,
int32_t
n
)
error_code
matrix_alloc
(
matrix
*
mat
,
int32_t
col
,
int32_t
li
n
)
{
mat
->
data
=
malloc
(
m
*
sizeof
(
int32_t
*
));
mat
->
col
=
m
;
mat
->
lin
=
n
;
mat
->
data
=
malloc
(
lin
*
sizeof
(
int32_t
*
));
mat
->
col
=
col
;
mat
->
lin
=
li
n
;
if
(
mat
->
data
==
NULL
){
return
UNINITIALIZED
;
}
for
(
int
i
=
0
;
i
<
m
;
i
+=
1
)
for
(
int
i
=
0
;
i
<
col
;
i
+=
1
)
{
mat
->
data
[
i
]
=
malloc
(
n
*
sizeof
(
int32_t
));
mat
->
data
[
i
]
=
malloc
(
li
n
*
sizeof
(
int32_t
));
}
if
(
mat
->
data
==
NULL
){
...
...
@@ -70,16 +70,16 @@ error_code matrix_destroy(matrix *mat){
}
// Init matrix from array of int32
error_code
matrix_init_from_array
(
matrix
*
mat
,
int32_t
m
,
int32_t
n
,
int32_t
data
[])
error_code
matrix_init_from_array
(
matrix
*
mat
,
int32_t
lin
,
int32_t
col
,
int32_t
data
[])
{
// if (mat->data != NULL){
// matrix_destroy(mat);
// }
matrix_alloc
(
mat
,
m
,
n
);
matrix_alloc
(
mat
,
lin
,
col
);
matrix_init
(
mat
);
for
(
int
i
=
0
,
k
=
0
;
i
<
m
;
i
+=
1
)
for
(
int
i
=
0
,
k
=
0
;
i
<
lin
;
i
+=
1
)
{
for
(
int
j
=
0
;
j
<
n
;
j
+=
1
,
k
+=
1
)
for
(
int
j
=
0
;
j
<
col
;
j
+=
1
,
k
+=
1
)
{
mat
->
data
[
i
][
j
]
=
data
[
k
];
}
...
...
This diff is collapsed.
Click to expand it.
Matrix.h
+
1
−
1
View file @
9b664000
...
...
@@ -20,7 +20,7 @@ typedef struct _matrix {
bool
matrix_is_equal
(
matrix
mat1
,
matrix
mat2
);
error_code
matrix_init
(
matrix
*
mat
);
error_code
matrix_alloc
(
matrix
*
mat
,
int32_t
m
,
int32_t
n
);
error_code
matrix_alloc
(
matrix
*
mat
,
int32_t
lin
,
int32_t
col
);
error_code
matrix_destroy
(
matrix
*
mat
);
error_code
matrix_init_from_array
(
matrix
*
mat
,
int32_t
m
,
int32_t
n
,
int32_t
data
[]);
error_code
matrix_to_array
(
matrix
mat
,
int32_t
*
table
);
...
...
This diff is collapsed.
Click to expand it.
main.c
+
23
−
3
View file @
9b664000
...
...
@@ -14,16 +14,36 @@ int main()
pgm_read_from_file
(
p
,
"buzz.pgm"
);
uint32_t
val
=
quadtree_get_depth_from_image_size
(
p
->
pixels
.
col
);
printf
(
"Depth : %u
\n
"
,
val
);
// matrix_print(p->pixels);
node
*
tree
=
quadtree_tree_create
(
val
);
matrix_print
(
p
->
pixels
);
//
matrix_print(p->pixels);
quadtree_matrix2tree
(
&
p
->
pixels
,
tree
);
quadtree_print
(
tree
,
1
,
"|"
);
pgm
*
pp
=
malloc
(
1
*
sizeof
(
pgm
));
pp
->
max
=
p
->
max
;
matrix_alloc
(
&
pp
->
pixels
,
p
->
pixels
.
lin
,
p
->
pixels
.
col
);
// matrix mat;
// matrix_alloc(&mat,p->pixels.lin,p->pixels.col);
// matrix_init(&mat);
quadtree_tree2matrix
(
tree
,
&
pp
->
pixels
);
// // matrix_print(mat);
// // quadtree_print(tree,1,"|");
// pgm *pp = malloc(1 * sizeof(pgm));
// pp->max = 256;
// pp->pixels = mat;
pgm_write_from_file
(
pp
,
"Test.pgm"
);
matrix_destroy
(
&
p
->
pixels
);
quadtree_tree_destroy
(
&
tree
);
matrix_destroy
(
&
pp
->
pixels
);
quadtree_tree_destroy_clean
(
&
tree
);
free
(
p
);
free
(
pp
);
return
0
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
quadtree.c
+
63
−
4
View file @
9b664000
...
...
@@ -64,7 +64,7 @@ void quadtree_print(node *arbre, int32_t decal, char *sep)
{
printf
(
"%s"
,
sep
);
}
printf
(
"%d
\n
"
,
arbre
->
info
);
printf
(
"%d
\n
"
,
(
uint32_t
)
arbre
->
data
);
decal
++
;
if
(
!
quadtree_is_leaf
(
arbre
))
{
...
...
@@ -94,7 +94,7 @@ void quadtree_sum(node *arbre)
}
for
(
int32_t
i
=
0
;
i
<
CHILDREN
;
i
++
)
{
arbre
->
info
+=
arbre
->
child
[
i
]
->
info
;
arbre
->
data
+=
arbre
->
child
[
i
]
->
data
;
}
}
}
...
...
@@ -106,13 +106,29 @@ node *quadtree_position(int32_t li, int32_t col, node *a, int32_t d)
{
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
int32_t
index
=
(
ligne
<<
1
)
|
colonne
;
// Exemple: 1<<1 = 10 | 1(col) = 11=>3
crt
=
crt
->
child
[
index
];
d
--
;
}
while
(
!
quadtree_is_leaf
(
crt
));
return
crt
;
}
double
quadtree_position_value
(
int32_t
li
,
int32_t
col
,
node
*
a
,
int32_t
d
)
{
node
*
crt
=
a
;
do
{
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
));
return
crt
->
data
;
}
void
quadtree_matrix2tree
(
matrix
*
mat
,
node
*
arbre
)
{
int32_t
d
=
quadtree_depth
(
arbre
)
-
1
;
...
...
@@ -121,11 +137,36 @@ void quadtree_matrix2tree(matrix *mat, node *arbre)
for
(
int32_t
co
=
0
;
co
<
mat
->
col
;
co
++
)
{
node
*
crt
=
quadtree_position
(
li
,
co
,
arbre
,
d
);
crt
->
info
=
mat
->
data
[
li
][
co
];
crt
->
data
=
mat
->
data
[
li
][
co
];
}
}
}
void
quadtree_tree2matrix
(
node
*
tree
,
matrix
*
mat
)
{
int32_t
d
=
quadtree_depth
(
tree
)
-
1
;
for
(
int32_t
li
=
0
;
li
<
mat
->
lin
;
li
++
)
{
for
(
int32_t
co
=
0
;
co
<
mat
->
col
;
co
++
)
{
mat
->
data
[
li
][
co
]
=
quadtree_position_value
(
li
,
co
,
tree
,
d
);
}
}
}
void
quadtree_vertical_symetry
(
node
*
tree
)
{
// Inversé les colones
}
void
quadtree_horizontal_symetry
(
node
*
tree
)
{
}
void
quadtree_central_symetry
(
node
*
tree
)
{
}
void
quadtree_tree_destroy
(
node
**
tree
)
{
node
*
a
=
*
tree
;
...
...
@@ -141,3 +182,21 @@ void quadtree_tree_destroy(node **tree)
}
}
}
void
quadtree_tree_destroy_clean
(
node
**
tree
)
{
if
(
NULL
!=
*
tree
)
{
if
(
!
quadtree_is_leaf
(
*
tree
))
{
for
(
uint32_t
i
=
0
;
i
<
CHILDREN
;
i
+=
1
)
{
quadtree_tree_destroy_clean
(
&
(
*
tree
)
->
child
[
i
]);
}
}
else
{
free
(
*
tree
);
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
quadtree.h
+
8
−
3
View file @
9b664000
...
...
@@ -10,7 +10,8 @@
#define CHILDREN 4
typedef
struct
_node
{
int
info
;
double
data
;
double
average_2
;
struct
_node
*
child
[
CHILDREN
];
}
node
;
...
...
@@ -37,3 +38,7 @@ node *quadtree_position(int32_t li, int32_t col, node *a, int32_t d);
void
quadtree_matrix2tree
(
matrix
*
mat
,
node
*
arbre
);
void
quadtree_tree_destroy
(
node
**
tree
);
void
quadtree_tree2matrix
(
node
*
tree
,
matrix
*
mat
);
void
quadtree_tree_destroy_clean
(
node
**
tree
);
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment