Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Enchente
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Harbor Registry
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
Vytor Calixto
Enchente
Commits
c26e008b
There was a problem fetching the pipeline summary.
Commit
c26e008b
authored
8 years ago
by
Vytor Calixto
Browse files
Options
Downloads
Patches
Plain Diff
Arruma floodfill para gerar o grafo
parent
80b8164f
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
libs/grafo.c
+68
-148
68 additions, 148 deletions
libs/grafo.c
libs/grafo.h
+1
-1
1 addition, 1 deletion
libs/grafo.h
with
69 additions
and
149 deletions
libs/grafo.c
+
68
−
148
View file @
c26e008b
...
@@ -55,158 +55,78 @@ void tabuleiroParaGrafo(Tblr t, Grafo g) {
...
@@ -55,158 +55,78 @@ void tabuleiroParaGrafo(Tblr t, Grafo g) {
v
->
peso
=
0
;
v
->
peso
=
0
;
insereVertice
(
g
,
v
);
insereVertice
(
g
,
v
);
//Chama o flood fill
//Chama o flood fill
int
auxi
=
i
;
floodFill
(
t
,
v
,
i
,
j
);
int
auxj
=
j
;
printf
(
"
\n
IN HERE
\n
"
);
floodFill
(
t
,
g
,
v
,
c
,
auxi
,
auxj
);
}
}
}
}
}
void
floodFill
(
Tblr
t
,
Grafo
g
,
Vertice
v
,
Celula
c
,
int
i
,
int
j
){
// A célula tendo um vértice, criamos os arcos pros vizinhos
c
->
vert
=
v
;
v
->
peso
=
v
->
peso
+
1
;
Celula
cima
,
baixo
,
esq
,
dir
;
Celula
cima
,
baixo
,
esq
,
dir
;
printf
(
"in floodfill, a cor foi: %d, o i foi: %d e o j foi: %d
\n
"
,
c
->
cor
,
i
,
j
);
int
auxi
=
i
;
int
auxj
=
j
;
//Cima
//Cima
if
(
i
>
0
)
{
if
(
i
>
0
)
{
cima
=
t
->
celulas
[(
i
-
1
)
*
t
->
y
+
j
];
cima
=
t
->
celulas
[(
i
-
1
)
*
t
->
y
+
j
];
if
(
(
cima
->
cor
==
c
->
cor
)
&&
(
cima
->
vert
==
NULL
)
)
{
if
(
cima
->
vert
&&
cima
->
cor
!=
c
->
cor
)
{
printf
(
"cima
\n
"
);
criaArco
(
cima
->
vert
,
c
->
vert
);
floodFill
(
t
,
g
,
v
,
cima
,
(
auxi
-
1
),
auxj
);
criaArco
(
c
->
vert
,
cima
->
vert
);
}
}
}
}
// Esquerda
// Esquerda
if
(
j
>
0
)
{
if
(
j
>
0
)
{
esq
=
t
->
celulas
[
i
*
t
->
y
+
(
j
-
1
)];
esq
=
t
->
celulas
[
i
*
t
->
y
+
(
j
-
1
)];
if
(
(
esq
->
cor
==
c
->
cor
)
&&
(
esq
->
vert
==
NULL
)
)
{
if
(
esq
->
vert
&&
esq
->
cor
!=
c
->
cor
)
{
printf
(
"esq
\n
"
);
criaArco
(
esq
->
vert
,
c
->
vert
);
floodFill
(
t
,
g
,
v
,
esq
,
auxi
,
(
auxj
-
1
)
);
criaArco
(
c
->
vert
,
esq
->
vert
);
}
}
}
}
// Baixo
// Baixo
if
(
i
<
t
->
x
-
1
)
{
if
(
i
<
t
->
x
-
1
)
{
baixo
=
t
->
celulas
[(
i
+
1
)
*
t
->
y
+
j
];
baixo
=
t
->
celulas
[(
i
+
1
)
*
t
->
y
+
j
];
if
(
(
baixo
->
cor
==
c
->
cor
)
&&
(
baixo
->
vert
==
NULL
)
)
{
if
(
baixo
->
vert
&&
baixo
->
cor
!=
c
->
cor
)
{
printf
(
"baixo
\n
"
);
criaArco
(
baixo
->
vert
,
c
->
vert
);
floodFill
(
t
,
g
,
v
,
baixo
,
(
auxi
+
1
),
auxj
);
criaArco
(
c
->
vert
,
baixo
->
vert
);
}
}
}
}
// Direita
// Direita
if
(
j
<
t
->
y
-
1
)
{
if
(
j
<
t
->
y
-
1
)
{
dir
=
t
->
celulas
[
i
*
t
->
y
+
(
j
+
1
)];
dir
=
t
->
celulas
[
i
*
t
->
y
+
(
j
+
1
)];
if
((
dir
->
cor
==
c
->
cor
)
&&
(
dir
->
vert
==
NULL
))
{
if
(
dir
->
vert
&&
dir
->
cor
!=
c
->
cor
)
{
printf
(
"dir
\n
"
);
criaArco
(
dir
->
vert
,
c
->
vert
);
floodFill
(
t
,
g
,
v
,
dir
,
auxi
,
(
auxj
+
1
));
criaArco
(
c
->
vert
,
dir
->
vert
);
}
}
}
}
}
}
return
;
}
}
/* Algoritmo inicial do vytor.
void
floodFill
(
Tblr
t
,
Vertice
v
,
int
i
,
int
j
){
Celula
c
=
t
->
celulas
[
i
*
t
->
y
+
j
];
Para cada celula do tabuleiro, indo da esquerda pra direita, de cima pra baixo.
// Se a cor da célula é diferente da do vértice retorna
verifica se a cor desta celula é a mesma da célula de cima e se a célula de cima já tem vértice
if
(
c
->
cor
!=
v
->
cor
)
return
;
se sim, esta célula será mapeada para o mesmo vértice.
// Se a célula já tem um vértice, retorna
o vértice recebe peso +1
if
(
c
->
vert
)
return
;
verifica para o da esquerda
" baixo
" direita
se esta célula nao se agrupou com nenhuma, entao cria sua própria
// Se as cores são iguais...
c
->
vert
=
v
;
v
->
peso
=
v
->
peso
+
1
;
void tabuleiroParaGrafo(Tblr t, Grafo g) {
for(int i=0; i < t->x; ++i) {
for(int j=0; j < t->y; ++j) {
Celula c = t->celulas[i * t->y + j];
// Primeiro, olho ao meu redor e vejo se posso me inserir em algum grupo existente
Celula cima, baixo, esq, dir;
// Olho no sentido anti-horário porque é mais provável que o cara acima e a esquerda de mim já tenham vértices
//Cima
//Cima
if
(
i
>
0
)
{
if
(
i
>
0
)
{
cima = t->celulas[(i-1) * t->y + j];
floodFill
(
t
,
v
,
(
i
-
1
),
j
);
if(cima->vert && (cima->cor == c->cor)) {
c->vert = cima->vert; //o vertice ao qual este vai ser agrupado sera o mesmo vertice do seu vizinho de cima
++(c->vert->peso);
}
}
}
// Esquerda
// Esquerda
if
(
j
>
0
)
{
if
(
j
>
0
)
{
esq = t->celulas[i * t->y + (j - 1)];
floodFill
(
t
,
v
,
i
,
(
j
-
1
));
if(esq->vert != NULL && (esq->cor == c->cor)) {
c->vert = esq->vert;
++(c->vert->peso);
}
}
}
// Baixo
// Baixo
if
(
i
<
t
->
x
-
1
)
{
if
(
i
<
t
->
x
-
1
)
{
baixo = t->celulas[(i + 1) * t->y + j];
floodFill
(
t
,
v
,
(
i
+
1
),
j
);
if(baixo->vert != NULL && (baixo->cor == c->cor)) {
c->vert = baixo->vert;
++(c->vert->peso);
}
}
}
// Direita
// Direita
if
(
j
<
t
->
y
-
1
)
{
if
(
j
<
t
->
y
-
1
)
{
dir = t->celulas[i * t->y + (j + 1)];
floodFill
(
t
,
v
,
i
,
(
j
+
1
));
if(dir->vert != NULL && (dir->cor == c->cor)) {
c->vert = dir->vert;
++(c->vert->peso);
}
}
// Se não me agrupei com ninguém
if(c->vert == NULL) {
// Crio um vértice para mim
Vertice v = criaVertice();
v->cor = c->cor;
v->peso = 1;
c->vert = v;
insereVertice(g, v);
}
// Com um vértice meu, crio arcos para os vizinhos
// Cima
if(i > 0) {
cima = t->celulas[(i-1) * t->y + j];
if(cima->vert && (cima->cor != c->cor)) {
criaArco(c->vert, cima->vert);
criaArco(cima->vert, c->vert);
}
}
// Direita
if(j < t->y - 1) {
dir = t->celulas[i * t->y + (j + 1)];
if(dir->vert && (dir->cor != c->cor)) {
criaArco(c->vert, dir->vert);
criaArco(dir->vert, c->vert);
}
}
// Baixo
if(i < t->x - 1) {
baixo = t->celulas[(i + 1) * t->y + j];
if(baixo->vert && (baixo->cor != c->cor)) {
criaArco(c->vert, baixo->vert);
criaArco(baixo->vert, c->vert);
}
}
// Esquerda
if(j > 0) {
esq = t->celulas[i * t->y + (j - 1)];
if(esq->vert && (esq->cor != c->cor)) {
criaArco(c->vert, esq->vert);
criaArco(esq->vert, c->vert);
}
}
}
}
}
return
;
return
;
}
}
*/
void
destroiGrafo
(
Grafo
g
)
{
void
destroiGrafo
(
Grafo
g
)
{
destroiLista
(
g
->
vertices
,
destroiVertice
);
destroiLista
(
g
->
vertices
,
destroiVertice
);
free
(
g
);
free
(
g
);
...
...
This diff is collapsed.
Click to expand it.
libs/grafo.h
+
1
−
1
View file @
c26e008b
...
@@ -17,7 +17,7 @@ void criaArco(Vertice v, Vertice w);
...
@@ -17,7 +17,7 @@ void criaArco(Vertice v, Vertice w);
void
tabuleiroParaGrafo
(
Tblr
t
,
Grafo
g
);
void
tabuleiroParaGrafo
(
Tblr
t
,
Grafo
g
);
void
floodFill
(
Tblr
t
,
Grafo
g
,
Vertice
v
,
Celula
c
,
int
i
,
int
j
);
void
floodFill
(
Tblr
t
,
Vertice
v
,
int
i
,
int
j
);
void
destroiGrafo
(
Grafo
g
);
void
destroiGrafo
(
Grafo
g
);
...
...
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