Changeset 188 for js/viewer-f0/js/NeuronDrawer.js
- Timestamp:
- 03/23/14 12:52:58 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
js/viewer-f0/js/NeuronDrawer.js
r161 r188 1 function NeuronDrawer( ) {1 function NeuronDrawer(context) { 2 2 this._scene = undefined; 3 3 this._camera = undefined; 4 4 this._renderer = undefined; 5 this._canvasWidth = 500;6 this._canvasHeight = 500;7 this._containerContext = undefined;5 this._canvasWidth = 400; 6 this._canvasHeight = 400; 7 this._containerContext = context; 8 8 this._controls = undefined; 9 9 this._showAxis = false; … … 12 12 this._inputonly_symbol=[1,5, 25,40, 35,40, 45,50, 35,60, 25,60, 25,40]; 13 13 this._outputonly_symbol=[1,7, 75,50, 75,60, 55,60, 65,50, 55,40, 75,40, 75,50, 100,50]; 14 15 } 14 this._canvas = undefined; 15 this._neurons = undefined; 16 } 17 18 NeuronDrawer.prototype.initialize = function () { 19 20 21 //this._canvas = document.getElementById("containerNeuron"); 22 /* 23 if (this._canvas.getContext){ 24 25 // use getContext to use the canvas for drawing 26 var ctx = this._canvas.getContext('2d'); 27 28 var lastX=this._canvas.width/2, lastY=this._canvas.height/2; 29 var dragStart,dragged; 30 this._canvas.addEventListener('mousedown',function(evt){ 31 document.body.style.mozUserSelect = document.body.style.webkitUserSelect = document.body.style.userSelect = 'none'; 32 lastX = evt.offsetX || (evt.pageX - canvas.offsetLeft); 33 lastY = evt.offsetY || (evt.pageY - canvas.offsetTop); 34 dragStart = ctx.transformedPoint(lastX,lastY); 35 dragged = false; 36 },false); 37 38 this._canvas.addEventListener('mousemove',function(evt){ 39 lastX = evt.offsetX || (evt.pageX - this._canvas.offsetLeft); 40 lastY = evt.offsetY || (evt.pageY - this._canvas.offsetTop); 41 dragged = true; 42 if (dragStart){ 43 var pt = ctx.transformedPoint(lastX,lastY); 44 ctx.translate(pt.x-dragStart.x,pt.y-dragStart.y); 45 redraw(); 46 } 47 },false); 48 this._canvas.addEventListener('mouseup',function(evt){ 49 dragStart = null; 50 if (!dragged) zoom(evt.shiftKey ? -1 : 1 ); 51 },false); 52 53 // Filled triangle 54 ctx.beginPath(); 55 ctx.moveTo(25,25); 56 ctx.lineTo(105,25); 57 ctx.lineTo(25,105); 58 ctx.fill(); 59 60 // Stroked triangle 61 ctx.beginPath(); 62 ctx.moveTo(125,125); 63 ctx.lineTo(125,45); 64 ctx.lineTo(45,125); 65 ctx.closePath(); 66 ctx.stroke(); 67 68 } 69 else 70 alert("dupa"); 71 //this._debug();*/ 72 } 73 16 74 17 75 NeuronDrawer.prototype.showPartAxis = function () { … … 23 81 this._renderer.setClearColor(0xffffff, 1); 24 82 this._renderer.setSize(this._canvasWidth, this._canvasHeight); 25 this._containerContext = $("#containerNeuron");83 //this._containerContext = $("#containerNeuron"); 26 84 this._containerContext.append(this._renderer.domElement); 27 85 } … … 126 184 } 127 185 128 NeuronDrawer.prototype.drawConnection = function (id, connections, einfos) { 129 130 var destination = connections[id].getDestination(); 186 NeuronDrawer.prototype.drawConnection = function (id, neurons, connections, einfos) { 187 188 var n2; 189 190 for(var iw = 0; iw < this._getNumberOfInputs(id,connections); iw++) 191 { 192 n2 = neurons[iw]; 193 194 var yw = this._inputY(iw); 195 var xw = yw / 4; 196 this._drawLine() 197 } 198 199 /*var destination = connections[id].getDestination(); 131 200 var numberOfConnToDest = 0; 132 201 var numberOfDrawenCon = 0; … … 253 322 //g.drawLine((int) ((10 + polozenieX + (x1 * 100)) * zoom), (int) ((10 + polozenieY + y1 * 100) * zoom), (int) ((10 + polozenieX + (x1 * 100)) * zoom), (int) ((15 + y2 * 100) * zoom)); 254 323 } 255 256 } 257 324 */ 325 } 326 327 NeuronDrawer.prototype._inputY = function(number, connections){ 328 return (1 + number)*this._neurons[number].sizeY / ((this._getNumberOfInputs(number, connections)) + 1); 329 } 330 331 NeuronDrawer.prototype._drawLine = function(x1, y1, x2, y2){ 332 var geometry = new THREE.Geometry(); 333 geometry.vertices.push(new THREE.Vector3(x1, y1, 0)); 334 geometry.vertices.push(new THREE.Vector3(x2, y2, 0)); 335 336 var material = new THREE.LineBasicMaterial({ 337 color: 0x0000ff 338 }); 339 340 var SCALE = 1; 341 342 var line = new THREE.Line(geometry, material); 343 line.scale.set(SCALE, SCALE, SCALE); 344 this._scene.add(line); 345 } 258 346 259 347 NeuronDrawer.prototype._chooseSchema = function(number, neurons, connections, classes) … … 278 366 } 279 367 368 NeuronDrawer.prototype._getSize = function(scheme) 369 { 370 var neuron = {sizeX: 0, sizeY: 0}; 371 var position = 0; 372 var noOfBlocks = 0;//number of "blocks" to draw 373 var noOfLines = 0;//number of line to draw 374 noOfBlocks = scheme[position++]; 375 for (var i = 0; i < noOfBlocks; i++) { 376 noOfLines = scheme[position++]; 377 378 for (var j = 0; j < noOfLines; j++) { 379 380 if(scheme[position] > neuron.sizeX) 381 neuron.sizeX = scheme[position]; 382 position++; 383 if(scheme[position] > neuron.sizeY) 384 neuron.sizeY = scheme[position]; 385 position++; 386 387 if(scheme[position] > neuron.sizeX) 388 neuron.sizeX = scheme[position]; 389 position++; 390 if(scheme[position] > neuron.sizeY) 391 neuron.sizeY = scheme[position]; 392 position++; 393 394 position = position - 2; 395 } 396 position = position + 2;//move to value which define number of lines to draw 397 } 398 return neuron; 399 } 400 280 401 NeuronDrawer.prototype.drawNetwork = function (neurons, connections, layouts, classes) { 402 403 this._neurons = []; 281 404 282 405 for (var i = 0; i < layouts.length; i++) { … … 284 407 285 408 scheme = this._chooseSchema(i,neurons, connections, classes) 286 409 var neuronData = this._getSize(scheme); 410 neuronData.scheme = scheme; 411 this._neurons.push(neuronData); 287 412 this.drawNeuron(layouts[i].x * 100 , -layouts[i].y * 100 , scheme); 288 413 } 289 414 290 415 //for (var i = 0; i < connections.length; i++) 291 // this.drawConnection(i, connections, einfos);416 // this.drawConnection(i, neurons, connections, einfos); 292 417 } 293 418
Note: See TracChangeset
for help on using the changeset viewer.