This repository has been archived by the owner on Nov 14, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
224 lines (163 loc) · 5.8 KB
/
index.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
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>DDM - Uebung 5 - DBSCAN</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" href="css/default.css" type="text/css">
<link rel="stylesheet" href="http://code.jquery.com/ui/1.8.20/themes/base/jquery-ui.css" type="text/css" media="all" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js" type="text/javascript"></script>
<script src="js/lib/underscore-min.js"></script>
<script src="js/lib/jquery.transform2d.js"></script>
<script src="js/lib/jquery.transformable-v.3.js"></script>
<script src="js/lib/jquery.mousewheel.min.js"></script>
<script type="text/javascript">
var ctx,
img,
imgWidth = 7200,
imgHeight = 3600,
originalPixels = [],
currentPixels = [],
newImageData,
pixelWorker,
dbscanWorker,
canvasScale = 1;
$( document ).ready( function() {
$( window ).resize( setLayout );
setLayout();
$("#canvas").draggable();
$( window ).on("mousewheel", handleMousewheel);
$( "#analyzePictureBtn" ).on("click", function(){
pixelWorker = new Worker("js/pixelAnalyzer.worker.js");
pixelWorker .onmessage = function(e){
console.log("PIXELANALYSIS COMPLETE");
originalPixels = e.data;
reducePixels();
};
pixelWorker .postMessage( {
data : ctx.getImageData(0, 0, imgWidth, imgHeight),
width : imgWidth,
height: imgHeight
});
$( "#analyzePictureBtn" ).attr("disabled","true");
$( "#maxIntensityBtn").removeAttr("disabled");
$( "#startDBScanBtn").removeAttr("disabled");
});
$( "#maxIntensityBtn" ).on("click", function(){
reducePixels();
});
$( "#startDBScanBtn" ).on("click", function(){
if( $( "#startDBScanBtn").val() === "Start DBScan"){
$( "#startDBScanBtn").val("Stop DBScan");
dbscanWorker = new Worker("js/dbscan.worker.js");
newImageData = ctx.createImageData(imgWidth,imgHeight);
$("#forceDrawingBtn").removeAttr("disabled");
dbscanWorker.onmessage = function( e ){
if(e.data.status === "COMPLETE"){
alert( "DBSCAN COMPLETE");
drawResult();
$( "#startDBScanBtn").val("Start DBScan");
}
else{
// console.log( "POINT ADDED x : ", e.data.x, ", y : ", e.data.y, ", color : ", e.data.color );
setPixel(
newImageData,
e.data.x,
e.data.y,
e.data.color >> 16 & 0xff,
e.data.color>> 8 & 0xff,
e.data.color & 0xff,
255
);
}
};
dbscanWorker.postMessage( {
data : currentPixels,
eps : parseFloat( $( "#epsValue" ).val() ),
minPts : parseInt( $( "#minPtsValue" ).val() ),
distFuncName : $( "#distFuncSelect" ).val() }
);
}
else{
$( "#startDBScanBtn").val("Start DBScan");
dbscanWorker.terminate();
}
});
$( "#forceDrawingBtn" ).on("click", drawResult);
//Loading the source-image
img = new Image();
img.onload = function() {
ctx = $( "canvas" )[0].getContext( "2d" );
ctx.drawImage(img,0,0);
$( "#analyzePictureBtn" ).removeAttr("disabled");
}
img.src= "data/nlights.png";
});
function setLayout() {
var ratio = $( "#canvas" ).width() / $( "#canvas" ).height();
$( "#canvas" ).css( "width" , $( window ).width() ).css( "height" , $( window ).width() / ratio | 0 );
}
function redrawCanvasFromPixels(pixels, color){
var imageData = ctx.createImageData(imgWidth, imgHeight),
i = 0,
l = pixels.length;
if(!color){
for( ; i < l; i++ ){
setPixel( imageData, pixels[i]["x"], pixels[i]["y"], pixels[i]["val"], pixels[i]["val"] , pixels[i]["val"] , 255 );
}
}
else{
for( ; i < l; i++ ){
setPixel( imageData, pixels[i]["x"], pixels[i]["y"], color.r, color.g, color.b, 255 );
}
}
ctx.putImageData( imageData, 0, 0 );
}
function setPixel(imageData, x, y, r, g, b, a) {
index = (x + y * imageData.width) * 4;
imageData.data[index+0] = r;
imageData.data[index+1] = g;
imageData.data[index+2] = b;
imageData.data[index+3] = a;
}
function drawResult(){
ctx.putImageData( newImageData, 0, 0 );
}
function reducePixels(){
var min = parseInt( $( "#minIntesity" ).val()),
max = parseInt( $( "#maxIntesity" ).val());
currentPixels = _.reject( originalPixels, function(pixel){
return pixel.val < min || pixel.val > max }
) ;
redrawCanvasFromPixels( currentPixels, { r: 255, g: 255, b: 255} );
}
function handleMousewheel(event, delta, deltaX, deltaY){
event.preventDefault();
var step = (delta < 0) ? -0.3 : 0.3;
canvasScale += step;
if(canvasScale <= 0.3) canvasScale = 0.3;
$( "#canvas" ).css( "transform", "scale(" + canvasScale+ ")");
}
</script>
</head>
<body>
<div id="menu">
<input id="analyzePictureBtn" type="button" value="Analyze Picture" disabled/>
Min-Intensity: <input id="minIntesity" type="text" value=90 />
Max-Intensity: <input id="maxIntesity" type="text" value=100 />
<input id="maxIntensityBtn" type="button" value="Update" disabled />
<div style="float:right">
Distance-Function:
<select id="distFuncSelect">
<option value="manhattan">Manhattan</option>
<option value="euclid">Euklid</option>
</select>
eps (ɛ): <input id="epsValue" type="text" value=2 />
MinPts: <input id="minPtsValue" type="text" value=10 />
<input id="startDBScanBtn" type="button" value="Start DBScan" disabled />
<input id="forceDrawingBtn" type="button" value="Force Drawing" disabled />
</div>
</div>
<canvas id="canvas" width=7200 height=3600 />
</body>
</html>