-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrid.html
277 lines (239 loc) · 12 KB
/
grid.html
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<html>
<head>
<title>Canvas Grid</title>
<link href='https://fonts.googleapis.com/icon?family=Material+Icons' rel='stylesheet'>
<link type='text/css' rel='stylesheet' href='css/materialize.css' media='screen,projection' />
<link rel='stylesheet' type='text/css' href='css/general.css'>
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' />
</head>
<body class="dark-theme">
<canvas id='canvas'></canvas>
<div class='draggable card card-menu blue-grey lighten-5'>
<div class='card-content'>
<div class='row'>
<ul class='collapsible'>
<li>
<div class='collapsible-header blue-grey lighten-4 blue-grey-text text-darken-1'>
<div class='valign-wrapper'>
<i class='material-icons ' id='collapsible-icon'>chevron_right</i>
<h5>Instructions</h5>
</div>
</div>
<div class='collapsible-body white'>
<p>Use the left mouse button to place or remove obstacles.
<span style='font-weight: bold'>Tip</span>: you can also click and drag!</p>
<p>Use the right mouse button to place
<span class='green-text text-darken-1'>start</span> and
<span class='red-text text-darken-1'>end</span> points. The path calculation will
immediately start after placing the
<span class='red-text text-darken-1'>end</span> point.</p>
<p>Path will be calculated using a planning algorithm picked from the selection below.</p>
</div>
</li>
</ul>
<br />
<div class='input-field col s12'>
<select id='algorithmSelect'></select>
<label>Planning algorithm</label>
</div>
<br />
<div class='input-field col s12'>
<p class='label instruction-header grey-text'>Grid theme</p>
<p>
<label>
<input type='radio' class='with-gap' name='theme' value='dark' onclick='updateTheme(this);'
checked />
<span class='theme-option blue-grey-text text-darken-4'>Dark</span>
</label>
</p>
<p>
<label>
<input type='radio' class='with-gap' name='theme' value='light' onclick='updateTheme(this);' />
<span class='theme-option blue-grey-text text-darken-4'>Light</span>
</label>
</p>
</div>
<br />
<div class='input-field col s12 button-container'>
<p>Adjust cells size
<button id='decreaseCellsSize' class='btn blue-grey white-text' disabled onclick='grid.decreaseCellsSize(this)'>
<i class='material-icons'>zoom_out</i>
</button>
<button id='increaseCellsSize' class='btn blue-grey white-text' onclick='grid.increaseCellsSize(this)'>
<i class='material-icons'>zoom_in</i>
</button>
</p>
</div>
<div id='potential-parameters-container' class='input-field col s12' hidden>
<p>
<label>
<input id='potential-checkbox' type='checkbox' onclick='grid.togglePotentialLabels()' class='filled-in' />
<span class="black-text">Show potential fields values</span>
</label>
<div class="col s6">
<input id="repulsive-value" type="number" value="30" min="1" max="500" step="1" class="validate"
onchange="grid.potentialParameters()" oninput="grid.potentialParameters()" />
<label for="repulsive-value">Repulsive Value</label>
</div>
<div class="col s6">
<input id="distance-of-influence" value="1" type="number" min="0" max="5" step="1" class="validate"
onchange="grid.potentialParameters()" oninput="grid.potentialParameters()" />
<label for="distance-of-influence">Obstacle Repulsive Range</label>
</div>
</p>
</div>
<div id='probabilistic-nodes-container' class="input-field col s12" hidden>
<input id="probabilistic-nodes" value="10" type="number" min="1" max="100" step="1" class="validate"
onchange="grid.probabilisticNodes()" oninput="grid.probabilisticNodes()">
<label for="probabilistic-nodes">Number of nodes</label>
</div>
</div>
<div class='card-action center-align'>
<button class='btn blue-grey white-text' onclick='grid.clearWalls()'>Clear obstacles</button>
<button class='btn blue-grey white-text' onclick='grid.clearPaths()'>Clear path</button>
</div>
<div class='card-action center-align'>
<button class='btn blue-grey white-text' onclick='grid.downloadMap()'>
<i class='material-icons left'>file_download</i>Save Map
</button>
<input type="file" id="selectedMap" onchange="grid.handleFiles(this.files)">
<button class='btn blue-grey white-text' onclick="document.getElementById('selectedMap').click();">
<i class='material-icons left'>file_upload</i>Upload Map
</button>
</div>
</div>
</div>
<div class='draggable card-performance blue-grey lighten-4'>
<h5 class='center card-title blue-grey-text text-darken-1'>Performance</h5>
<div class='card-content'>
<div class='performance blue-grey lighten-5 blue-grey-text text-darken-4'>
<ul class='collection'>
<li class='collection-item blue-grey lighten-5 blue-grey-text text-darken-4'>Compute time: <span id='time'>N/A</span>.</li>
<li class='collection-item blue-grey lighten-5 blue-grey-text text-darken-4'>Path length: <span id='length'>N/A</span>.</li>
</ul>
</li>
</div>
</div>
</div>
<script type='text/javascript' src='js/Grid.js'></script>
<script type='text/javascript' src='js/algorithms/Decomposition.js'></script>
<script type='text/javascript' src='js/algorithms/Visibility.js'></script>
<script type='text/javascript' src='js/algorithms/PotentialFields.js'></script>
<script type='text/javascript' src='js/algorithms/Bug.js'></script>
<script type='text/javascript' src='libs/graph.js'></script>
<script type='text/javascript' src='libs/loglevel.js'></script>
<script type='text/javascript' src='libs/download.js'></script>
<script src='https://code.jquery.com/jquery-3.3.1.min.js' integrity='sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8='
crossorigin='anonymous'></script>
<script type='text/javascript' src='libs/materialize.js'></script>
<script>
var grid;
var width = document.body.clientWidth,
height = document.body.clientHeight;
// implemented algorithms
var algorithms = {
'decomposition': 'Cellular Decomposition',
'visibility': 'Visibility Graph',
'probabilistic': 'Probabilistic Roadmap',
'potential': 'Simple Potential Field',
'potential-memory': 'Potential Field with Memory',
'bug1': 'Bug v1',
'bug2': 'Bug v2',
'tangent-bug': 'Tangent Bug'
};
// setting console log level
var logLevel = (new URL(document.location)).searchParams.get('debug');
//var logLevel = '';
switch (logLevel) {
case '':
case 'debug':
case 'on':
log.setLevel(log.levels.DEBUG);
break;
case 'info':
log.setLevel(log.levels.INFO);
break;
case 'trace':
log.setLevel(log.levels.TRACE);
break;
case 'warn':
log.setLevel(log.levels.WARN);
break;
case 'error':
log.setLevel(log.levels.ERROR);
break;
default:
log.setLevel(log.levels.WARN);
break;
}
// theme selection
function updateTheme(selectedTheme) {
if (selectedTheme.value == 'light') {
$('body').removeClass('dark-theme').addClass('light-theme');
grid.lightTheme(true);
} else if (selectedTheme.value == 'dark') { // switch to light
$('body').removeClass('light-theme').addClass('dark-theme');
grid.darkTheme(true);
}
}
$(document).ready(function () {
// initialize the algorithm select
$.each(algorithms, function (key, value) {
$('#algorithmSelect').append('<option value="' + key + '">' + value + '</option>');
});
$('#algorithmSelect').val('decomposition').prop('selected', true);
// materialize select initialization
$('select').formSelect();
// materialize collapsible panel initialization
$('.collapsible').collapsible();
// grid initialization
grid = new Grid('canvas', width, height);
grid.generate();
// path planning algorithm update on select change
grid.setAlgorithm($('#algorithmSelect').val());
$('#algorithmSelect').on('change', function () {
// show loading indicators
grid.setLoading(true);
setTimeout(() => {
grid.setAlgorithm($(this).val());
grid.evaluatePath();
if ($(this).val() == 'potential' || $(this).val() == 'potential-memory') {
$('#potential-parameters-container').show();
} else {
$('#potential-parameters-container').hide();
}
if ($(this).val() == 'probabilistic') {
$('#probabilistic-nodes-container').show();
} else {
$('#probabilistic-nodes-container').hide();
}
}, 200);
});
// instructions panel drag
var instructionsPanel = $('.draggable');
instructionsPanel.on('mousedown', function (e) {
if (!($(e.target).is($('input')))) {
e.preventDefault();
}
var dr = $(this).addClass('drag').css('cursor', 'move');
height = dr.outerHeight();
width = dr.outerWidth();
ypos = dr.offset().top + height - e.pageY,
xpos = dr.offset().left + width - e.pageX;
$(document.body).on('mousemove', function (e) {
var itop = e.pageY + ypos - height;
var ileft = e.pageX + xpos - width;
if (dr.hasClass('drag')) {
dr.offset({
top: itop,
left: ileft
});
}
}).on('mouseup', function (e) {
dr.removeClass('drag');
});
});
})
</script>
</body>
</html>