-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathombres.cpp
More file actions
executable file
·96 lines (82 loc) · 2.44 KB
/
ombres.cpp
File metadata and controls
executable file
·96 lines (82 loc) · 2.44 KB
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
#include "fastMarching.h"
#include <iostream>
const int w = 512, h = 512;
const float TOL = 0.1f; // Seuil de tolerance d'imprecision numerique
// Selection a la souris d'un rectangle.
bool selectionRect(int &x1, int &y1, int &x2, int &y2, const Image<Color> &I) {
Event e;
do {
getEvent(0, e);
if (e.type == EVT_BUT_ON) {
x1 = x2 = e.pix[0];
y1 = y2 = e.pix[1];
if (e.button == 3)
return false;
}
if (e.type == EVT_MOTION) {
x2 = e.pix[0];
y2 = e.pix[1];
display(I);
fillRect(std::min(x1, x2), std::min(y1, y2), abs(x1 - x2), abs(y1 - y2),
RED);
}
} while (e.type != EVT_BUT_OFF || abs(x1 - x2) < 5 || abs(y1 - y2) < 5);
if (x1 > x2) std::swap(x1, x2);
if (y1 > y2) std::swap(y1, y2);
return true;
}
int main() {
Window W1 = openWindow(w, h);
Image<Color> I(w, h);
I.fill(WHITE);
cout << "Dessinez des rectangles, clic droit pour terminer." << endl;
int x1, y1, x2, y2;
while (selectionRect(x1, y1, x2, y2, I)) {
for (int i = x1; i < x2; i++) {
for (int j = y1; j < y2; j++) {
I(i, j) = RED;
}
}
}
cout << "Cliquez pour créer la source lumineuse." << endl;
vector<PointDist> v;
int x, y;
getMouse(x, y);
while (I(x, y) == RED) {
getMouse(x, y);
}
fillCircle(x, y, 2, GREEN);
PointDist p(x, y, 0.f);
v.push_back(p);
// Remplissage des cartes de cout avec et sans obstacles
Image<float> Wavec(w, h), Wsans(w, h);
Wavec.fill(1.0f);
Wsans.fill(1.0f);
for (int i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {
if (I(i, j) == RED) {
Wavec(i, j) = INF;
}
}
}
cout << "Calcul" << endl;
Image<float> Davec = fastMarching(Wavec, v);
Image<float> Dsans = fastMarching(Wsans, v);
for (int i = 0; i < w; i++) {
for (int j = 0; j < h; j++) {
if (I(i, j) == WHITE && Davec(i, j) - Dsans(i, j) > TOL) {
I(i, j) = BLUE;
}
}
}
affiche(Dsans);
//Ordre d'affichage un peu alambiqué, permet d'afficher l'image avec les ombres en premier
Window W2 = openWindow(w, h);
Window W3 = openWindow(w, h);
setActiveWindow(W2);
affiche(Davec);
setActiveWindow(W3);
display(I);
endGraphics();
return 0;
}