Changeset 161 for js


Ignore:
Timestamp:
03/05/14 21:58:51 (11 years ago)
Author:
mmichalski
Message:

Draw neuron like in canvasutil

Location:
js/viewer-f0/js
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • js/viewer-f0/js/NeuronDrawer.js

    r143 r161  
    88    this._controls = undefined;
    99    this._showAxis = false;
     10    this._unknown_symbol=[1,4, 25,25, 75,25, 75,75, 25,75, 25,25];
     11    this._neuron_symbol=[1,4, 75,50, 25,0, 25,99, 75,50, 100,50];
     12    this._inputonly_symbol=[1,5, 25,40, 35,40, 45,50, 35,60, 25,60, 25,40];
     13    this._outputonly_symbol=[1,7, 75,50, 75,60, 55,60, 65,50, 55,40, 75,40, 75,50, 100,50];
     14
    1015}
    1116
     
    2328
    2429NeuronDrawer.prototype._prepareCamera = function () {
    25     this._camera = new THREE.PerspectiveCamera(45, this._canvasWidth / this._canvasHeight, 1, 4000);
     30    this._camera = new THREE.PerspectiveCamera(45, this._canvasWidth / this._canvasHeight, 1, 10000);
    2631    this._camera.position.set(0, 0, 10);
    2732    this._camera.lookAt(this._scene.position);
     
    6065}
    6166
    62 NeuronDrawer.prototype._debug = function()
    63 {
    64     this._scene.add( new THREE.AxisHelper( 20 ) );
    65 }
    66 
    67 NeuronDrawer.prototype.drawNeuron = function(x, y){
    68     var scheme = [4,4,26,27,26,73,73,73,73,27,26,27,1,73,50,100,50,1,56,68,46,68,2,41,47,51,32,51,68];
    69     //pobieranie schematu
    70     //inne określenie położeń
     67NeuronDrawer.prototype._debug = function () {
     68    this._scene.add(new THREE.AxisHelper(20));
     69}
     70
     71NeuronDrawer.prototype.drawNeuron = function (x, y, scheme) {
    7172
    7273
     
    8081    var noOfLines = 0;//number of line to draw
    8182    noOfBlocks = scheme[position++];
    82     for (var i = 0; i < noOfBlocks; i++)
    83     {
     83    for (var i = 0; i < noOfBlocks; i++) {
    8484        noOfLines = scheme[position++];
    8585
    86         for (var j = 0; j < noOfLines; j++)
    87         {
     86        for (var j = 0; j < noOfLines; j++) {
    8887            var geometry = new THREE.Geometry();
    8988            geometry.vertices.push(new THREE.Vector3(scheme[position++] + x, scheme[position++] + y, 0));
     
    9897    var SCALE = 0.05;
    9998
    100     obj.scale.set(SCALE, SCALE,SCALE);
     99    obj.scale.set(SCALE, SCALE, SCALE);
    101100    obj.rotateX(Math.PI);//rotate 180 degree
    102     obj.translateY(-5.5);
     101    //obj.translateY(-5.5);
    103102    this._scene.add(obj)
    104 
    105 }
    106 
    107 
    108 
    109 NeuronDrawer.prototype.drawConnection = function(id, connections, einfos){
     103}
     104
     105NeuronDrawer.prototype._getNumberOfInputs = function(number, connections){
     106
     107    var counter = 0;
     108
     109    for(var i = 0; i < connections.length; i++){
     110        if(connections[i].getDestination() == number)
     111            counter++;
     112    }
     113
     114    return counter;
     115}
     116
     117NeuronDrawer.prototype._getNumberOfOutputs = function(number, connections){
     118    var counter = 0;
     119
     120    for(var i = 0; i < connections.length; i++){
     121        if(connections[i].getSource() == number)
     122            counter++;
     123    }
     124
     125    return counter;
     126}
     127
     128NeuronDrawer.prototype.drawConnection = function (id, connections, einfos) {
    110129
    111130    var destination = connections[id].getDestination();
     
    114133
    115134    //check how many conenctions have the same destination
    116     for(var i = 0; i < connections.length; i++){
    117         if(connections[i].getDestination() == destination)
     135    for (var i = 0; i < connections.length; i++) {
     136        if (connections[i].getDestination() == destination)
    118137            numberOfConnToDest++;
    119138    }
    120139
    121140    //check how many connections had been drawen
    122     for(var i = 0; i < id; i++){
    123         if(connections[i].getDestination() == destination)
     141    for (var i = 0; i < id; i++) {
     142        if (connections[i].getDestination() == destination)
    124143            numberOfDrawenCon++;
    125144    }
     
    142161    var geometry = new THREE.Geometry();
    143162    geometry.vertices.push(new THREE.Vector3(100 + x2 * 100, 10 + 50 + y2 * 100, 0));
    144     geometry.vertices.push(new THREE.Vector3(10 + 100 + x2 * 100 , 10 + 50 + y2 * 100, 0));
     163    geometry.vertices.push(new THREE.Vector3(10 + 100 + x2 * 100, 10 + 50 + y2 * 100, 0));
    145164    var line = new THREE.Line(geometry, material);
    146165    line.scale.set(SCALE, SCALE, SCALE);
    147166    this._scene.add(line);
     167
    148168
    149169    var geometry1 = new THREE.Geometry();
     
    168188
    169189    //pierwszy pionowy
    170     if (y1 >= y2)
    171     {
     190    if (y1 >= y2) {
    172191        var geometry = new THREE.Geometry();
    173192        geometry.vertices.push(new THREE.Vector3(110 + (x2 * 100), 60 + y2 * 100, 0));
     
    179198    }
    180199
    181     else
    182     {
     200    else {
    183201        var geometry = new THREE.Geometry();
    184202        geometry.vertices.push(new THREE.Vector3(110 + (x2 * 100), 60 + y2 * 100, 0));
     
    192210
    193211    //poziomy
    194     if (y1 >= y2)
    195     {
     212    if (y1 >= y2) {
    196213        var geometry = new THREE.Geometry();
    197214        geometry.vertices.push(new THREE.Vector3(110 + (x2 * 100), 105 + y2 * 100, 0));
     
    203220        //g.drawLine((int) ((110 + (x2 * 100)) * zoom), (int) ((105 + y2 * 100) * zoom), (int) ((10 + polozenieX + (x1 * 100)) * zoom), (int) ((105 + y2 * 100) * zoom));
    204221    }
    205 
    206     else
    207     {
     222    else {
    208223        var geometry = new THREE.Geometry();
    209224        geometry.vertices.push(new THREE.Vector3(110 + (x2 * 100), 15 + y2 * 100, 0));
     
    218233
    219234    //drugi pionowy
    220     if (y1 >= y2)
    221     {
     235    if (y1 >= y2) {
    222236        var geometry = new THREE.Geometry();
    223237        geometry.vertices.push(new THREE.Vector3(10 + positionX + (x1 * 100), 10 + positionY + y1 * 100, 0));
     
    229243        //g.drawLine((int) ((10 + polozenieX + (x1 * 100)) * zoom), (int) ((10 + polozenieY + y1 * 100) * zoom), (int) ((10 + polozenieX + (x1 * 100)) * zoom), (int) ((105 + y2 * 100) * zoom));
    230244    }
    231     else
    232     {
     245    else {
    233246        var geometry = new THREE.Geometry();
    234247        geometry.vertices.push(new THREE.Vector3(10 + positionX + (x1 * 100), 10 + positionY + y1 * 100, 0));
     
    243256}
    244257
    245 NeuronDrawer.prototype.drawNetwork = function(neurons, connections, layouts){
    246 
    247     for(var i = 0; i < layouts.length; i++){
    248         this.drawNeuron(layouts[i].x * 100, -layouts[i].y * 100);
    249     }
    250 
    251     for(var i = 0; i < connections.length; i++)
    252         this.drawConnection(i, connections, einfos);
    253 }
    254 
    255 NeuronDrawer.prototype.debugTest = function()
     258
     259NeuronDrawer.prototype._chooseSchema = function(number, neurons, connections, classes)
    256260{
    257 
    258 }
    259 
     261    var schema = this._unknown_symbol;
     262    var type = neurons[number].getSchemeID();
     263
     264    if(type != undefined)
     265    {
     266        if(classes[type].getScheme().length != 0)
     267        {
     268            if(this._getNumberOfInputs(number, connections) == 0)
     269                schema = this._outputonly_symbol;
     270            else if (this._getNumberOfOutputs(number, connections) == 0)
     271                schema = this._inputonly_symbol;
     272            else
     273                schema = this._neuron_symbol;
     274        }
     275    }
     276
     277    return schema;
     278}
     279
     280NeuronDrawer.prototype.drawNetwork = function (neurons, connections, layouts, classes) {
     281
     282    for (var i = 0; i < layouts.length; i++) {
     283        var scheme = undefined;
     284
     285        scheme = this._chooseSchema(i,neurons, connections, classes)
     286
     287        this.drawNeuron(layouts[i].x * 100  , -layouts[i].y * 100 , scheme);
     288    }
     289
     290    //for (var i = 0; i < connections.length; i++)
     291    //    this.drawConnection(i, connections, einfos);
     292}
     293
     294
     295NeuronDrawer.prototype.debugTest = function () {
     296
     297}
     298
  • js/viewer-f0/js/Structures/Neuro.js

    r143 r161  
    55
    66Neuro.prototype = new Model();
     7
     8Neuro.prototype.getSchemeID = function(){
     9    var type = this._properties["d"]["VALUE"];
     10    type = type.replace("\"","");
     11    var index = type.indexOf(":");
     12    if(index != -1)
     13        type = type.substr(0, index);
     14
     15    return type;
     16}
Note: See TracChangeset for help on using the changeset viewer.