bonjour
dans un de mes sujet je dois remplir une facette(carré) d'un couleur defini pixel par pixel, pour cela j'ai pu trouver sur internet un algo correspondant exactement a mon cahier des charges : http://fr.wikipedia.org/wiki/Algorit..._par_diffusion ( la vairante par 4-connexe).
je l'ai implemanté dans mon codemais celui ci arrivé a la fin de la premiere récursive passe en boucle infini entre la premiere et la deuxieme
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 void Facette::remplir(Point a,Ppm &pix) { //Point p; if(m_centre.getx() != /*(m_pt1.getx()+m_pt2.getx())*/ T/2 && m_centre.gety() != /*(m_pt2.gety()+m_pt3.gety())*/ T/ 2) { m_centre.setx(/*(m_pt1.getx()+m_pt2.getx())*/ T/2); m_centre.sety(/*(m_pt2.gety()+m_pt3.gety())*/ T/2); a = m_centre; cout << a.getx() << a.gety() << endl; } if(a.getcolor() != m_color) { a.setcolor(m_color); a.afficher(pix); cout << a.getx() << a.gety() << endl; remplir(a.conexite(1),pix); remplir(a.conexite(2),pix); remplir(a.conexite(3),pix); remplir(a.conexite(4),pix); } }auriez vous d'une idée de pourquoi cela ? car j'ai beau retourner le probleme dans tout les sens je ne vois pas.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 remplir(a.conexite(1),pix); remplir(a.conexite(2),pix);
main.cpp
Point.cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106 #include "Ppm.h" #include "Segment.h" #include "Cercle.h" #include "Facette.h" //#include "formes.h" #include <iostream> using namespace std; #define T 80 int main() { Ppm im(256,256); Point pt1(0,0,0,ROUGE), pt2(T,0,0,ROUGE), pt3(T,0,T,ROUGE), pt4(0,0,T,ROUGE); Point pt5(0,T,T,ROUGE), pt6(0,T,0,ROUGE), pt7(T,T,0,ROUGE), pt8(T,T,T,ROUGE); Facette fdessous(pt1,pt2,pt3,pt4,BLEU); Facette fface(pt8,pt5,pt4,pt3,ROUGE); Facette fgauche(pt5,pt6,pt1,pt4,VERT); Facette farriere(pt6,pt7,pt2,pt1,JAUNE); Facette fdroit(pt7,pt8,pt3,pt2,CYAN); Facette fdessus(pt5,pt8,pt7,pt6,ROSE);/* Cube C(fdessous,fface,fgauche,farriere,fdroit,fdessus); C.translation(100,100,0); C.rotation(20.,-30.,0.); //C.afficherFilDeFer(im); C.remplissage(im); Cercle cer(10); cer.translation(50,50,0); cer.afficher(im);*/ /*Segment* seg = new Segment(); Point pt1(15,10,10,ROUGE); Point pt2(10,10,10,ROUGE); Point result; bool test; result = pt1 + pt2; test = pt1 == pt2; cout << "salut" << endl; cout << result << endl; cout << test << endl; result.translate(5, 5, 5); cout << result << endl; cout << "salut" << endl;*/ /*pt1.afficher(im); pt2.afficher(im); pt6.afficher(im); Point ptr = pt1.conexite(BAS); // parametre = BAS HAUT GAUCHE ou DROITE voir define dans Point.h ptr.setcolor(BLEU); ptr.afficher(im); Cercle c(10); //cout << c.getx() << endl; c.afficherCercle(pt7 , im); Segment seg(pt7,pt5); seg.afficher(im,BLEU);*/ /*Point h(1,2,3,ROUGE); Point g(4,5,6,ROUGE); Segment s(g,h); Segment d(h,g); bool b; Segment r; b = s == d; r = s + d; cout << b << endl; cout << r << endl; Facette f(g,g,g,g,ROUGE); Facette t(g,g,g,g,ROUGE); Facette z; b = f == t; z = f + t; cout << b << endl; cout << z << endl;*/ Point p; //fdessus.tracer(im); //fdessous.tracer(im); fface.tracer(im); //farriere.tracer(im); //fgauche.tracer(im); //fdroit.tracer(im); fface.remplir(p,im); im.write("res.ppm"); return 0; }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154 #include "Point.h" Point::Point(): m_x(0), m_y(0), m_z(0), m_color(0) { } Point::Point(double x, double y, double z, ULONG color): m_x(x), m_y(y), m_z(z), m_color(color) { } Point::Point(Point const& objcop): m_x(objcop.m_x), m_y(objcop.m_y), m_z(objcop.m_z), m_color(objcop.m_color) { } Point::~Point() { //dtor } bool Point::operator==(Point const& b) { if(m_x == b.m_x && m_y == b.m_y && m_z == b.m_z) return true; else return false; } Point operator+(Point a,Point b) { Point result; result.setx(a.getx() + b.getx()); result.sety(a.gety() + b.gety()); result.setz(a.getz() + b.getz()); return result; } double Point::getx() { return m_x; } double Point::gety() { return m_y; } double Point::getz() { return m_z; } ULONG Point::getcolor() { return m_color; } void Point::setx(double x) { m_x = x; } void Point::sety(double y) { m_y = y; } void Point::setz(double z) { m_z = z; } void Point::setcolor(ULONG color) { m_color = color; } void Point::translate(double x, double y, double z) { //setx(getx() + x); //sety(gety() + y); //setz(getz() + z); m_x = m_x + x; m_y = m_y + y; m_z = m_z + z; } void Point::rotation(double alpha, double beta, double gamma) { double x = 0, y = 0, z = 0; x = (m_x *cos(beta) + z * cos(beta)) + (m_x * cos(gamma) - y * sin(gamma )); y = (m_x * sin(gamma) + m_y * cos(gamma)) + (m_y * cos(alpha) - m_z * sin(alpha)); z = ( - m_y * sin(alpha) + m_z * sin(alpha)) + (m_x * sin(beta) + m_z * cos(beta)); m_x = x; m_y = y; m_z = z; } void Point::afficher(Ppm &pix) { pix.setpixel(m_x, m_y, m_color); } Point Point::conexite(int nb) { Point a; switch(nb) { case 1: if(m_x > 0) { a.setx(m_x - 1); a.sety(m_y); return a; } else return *this; break; case 2: a.setx(m_x + 1); a.sety(m_y); return a; break; case 3: if(m_y > 0) { a.setx(m_x); a.sety(m_y - 1); return a; } else return *this; break; case 4: a.setx(m_x); a.sety(m_y + 1); return a; break; } //return a; } ostream &operator<<(ostream &flux, Point pt1) { flux << pt1.getx() << "," << pt1.gety() << "," << pt1.getz() << endl; return flux; }
pour toute autre fichier ou test voir .rar en piece jointe
merci d'avance pour vos reponses.
Partager