-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregion.cpp
44 lines (43 loc) · 1.41 KB
/
region.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "region.h"
#include "mainwindow.h"
Region::Region(GLubyte *rang)
{
this->color[0]=rang[0];
this->color[1]=rang[1];
this->color[2]=rang[2];
this->color[3]=rang[3];
this->object_num=objectNumber;
this->object_name="Region";
this->thickness=1;
this->pattern[0]=1;
this->pattern[1]=1;
this->pattern[2]=1;
this->pattern[3]=1;
this->pattern[4]=1;
this->pattern[5]=1;
this->pattern[6]=1;
this->pattern[7]=1;
objectNumber++;
}
GLubyte current[3];
void Region::flood_fill(GLint x,GLint y, GLubyte fill_color[], GLubyte back_color[])
{
glReadPixels(x,win_height-y-1,1,1,GL_RGB,GL_UNSIGNED_BYTE,current);
// if(current[0]!=back_color[0]||current[1]!=back_color[1]||current[2]!=back_color[2])
// return;
// if(current[0]==fill_color[0]&¤t[1]==fill_color[1]&¤t[2]==fill_color[2])
// return;
if(current[0]==back_color[0]&¤t[1]==back_color[1]&¤t[2]==back_color[2]){
this->points.push_back(make_pair(x-win_width/2,win_height/2-y));
glColor3ubv(fill_color);
glPointSize(1);
glBegin(GL_POINTS);
glVertex2i(x - win_width/2,win_height/2 - y);
glEnd();
glFlush();
flood_fill(x+1,y,fill_color,back_color);
flood_fill(x-1,y,fill_color,back_color);
flood_fill(x,y+1,fill_color,back_color);
flood_fill(x,y-1,fill_color,back_color);
}
}