Skip to content
Snippets Groups Projects
Commit 2a24fbe9 authored by Amanda Ghassaei's avatar Amanda Ghassaei
Browse files

first pass calc connected componentes

parent 6c8c31fd
Branches
Tags
No related merge requests found
...@@ -131,6 +131,8 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre ...@@ -131,6 +131,8 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre
_parseSparseCell: function(){ _parseSparseCell: function(){
console.log("parse cells");
if (this.get("numCells") == 0) { if (this.get("numCells") == 0) {
console.warn("no cells in assembly"); console.warn("no cells in assembly");
this.cells = [[[null]]]; this.cells = [[[null]]];
......
/**
* Created by aghassaei on 6/30/15.
*/
define(['lattice', 'eSim', 'eSimCell'], function(lattice, eSim){
var eSimMethods = {
calculateConnectivity: function(){
var num = 1;
this._loopCells(this.cells, function(cell){
if (cell) cell.setConnectivityGroupNum(num++, true);
});
this._loopCells(this.cells, function(cell){
if (cell) cell.propagateConnectivityGroupNum();
});
this._calcNumberConnectedComponents();
},
_calcNumberConnectedComponents: function(){
var groups = [];
this._loopCells(this.cells, function(cell){
if (!cell) return;
if (groups.indexOf(cell.getConnectivityGroupNum())<0) groups.push(cell.getConnectivityGroupNum());
});
eSim.set("numConnectedComponents", groups.length);
},
propagateToNeighbors: function(index, callback){
index.sub(this.get("cellsMin"));//todo wrong
var xLength = this.cells.length;
var yLength = this.cells[0].length;
var zLength = this.cells[0][0].length;
if (index.x+1 < xLength) callback(this.cells[index.x+1][index.y][index.z]);
if (index.x-1 >= 0) callback(this.cells[index.x-1][index.y][index.z]);
if (index.y+1 < yLength) callback(this.cells[index.x][index.y+1][index.z]);
if (index.y-1 >= 0) callback(this.cells[index.x][index.y-1][index.z]);
if (index.z+1 < zLength) callback(this.cells[index.x][index.y][index.z+1]);
if (index.z-1 >= 0) callback(this.cells[index.x][index.y][index.z-1]);
}
};
_.extend(lattice, eSimMethods);
return lattice;
});
...@@ -151,6 +151,12 @@ require.config({ ...@@ -151,6 +151,12 @@ require.config({
mStaticMenuTemplate: 'menus/templates/MStaticMenuView.html', mStaticMenuTemplate: 'menus/templates/MStaticMenuView.html',
mDynamicMenuTemplate: 'menus/templates/MDynamicMenuView.html', mDynamicMenuTemplate: 'menus/templates/MDynamicMenuView.html',
//electronic sim
eSim: 'simulation/electronics/eSim',
latticeESim: 'lattice/latticeESim',
eSimCell: 'simulation/electronics/eSimCell',
//cam //cam
cam: 'cam/cam', cam: 'cam/cam',
......
...@@ -2,18 +2,32 @@ ...@@ -2,18 +2,32 @@
* Created by aghassaei on 2/25/15. * Created by aghassaei on 2/25/15.
*/ */
define(['jquery', 'underscore', 'menuParent', 'plist', 'text!eSetupMenuTemplate'], function($, _, MenuParentView, plist, template){ define(['jquery', 'underscore', 'menuParent', 'plist', 'text!eSetupMenuTemplate', 'latticeESim', 'eSim'],
function($, _, MenuParentView, plist, template, lattice, eSim){
return MenuParentView.extend({ return MenuParentView.extend({
events: { events: {
"click #calcConnectivity": "_calcConnectivity"
}, },
_initialize: function(){ _initialize: function(){
this.listenTo(eSim, "change", this.render);
this.listenTo(this.model, "change:materialClass", this._changeSimNav);
},
_changeSimNav: function(){
var materialClass = this.model.get("materialClass");
this.model.set("currentNav", materialClass + "NavSim");
},
_calcConnectivity: function(e){
e.preventDefault();
lattice.calculateConnectivity();
}, },
_makeTemplateJSON: function(){ _makeTemplateJSON: function(){
return null; return _.extend(this.model.toJSON(), eSim.toJSON(), plist);
}, },
template: _.template(template) template: _.template(template)
......
boundaries Simulation Type: &nbsp;&nbsp;
\ No newline at end of file <div class="btn-group">
<button data-toggle="dropdown" class="btn dropdown-toggle" type="button"><%= allMaterialClasses[materialClass] %><span class="caret"></span></button>
<ul role="menu" class="dropdown-menu">
<% _.each(_.keys(allMaterialClasses), function(key){ %>
<li><a class="appState dropdownSelector" data-property="materialClass" data-value="<%= key %>" href="#"><%= allMaterialClasses[key] %></a></li>
<% }); %>
</ul>
</div><br/><br/>
<a href="#" id="calcConnectivity" class="btn btn-block btn-lg btn-default">Calculate Connectivity</a><br/>
<% if(numConnectedComponents){ %>Num Connected Components: &nbsp;&nbsp<%= numConnectedComponents %> <% } %>
\ No newline at end of file
/**
* Created by aghassaei on 6/29/15.
*/
/** /**
* Created by aghassaei on 6/29/15. * Created by aghassaei on 6/29/15.
*/ */
define(['underscore', 'backbone'], function(_, Backbone){
var eSim = Backbone.Model.extend({
defaults:{
numConnectedComponents: null
}
});
return new eSim();
});
\ No newline at end of file
/**
* Created by aghassaei on 6/29/15.
*/
//assume latticeESim has loaded?
define(['cell', 'lattice'], function(DMACell, lattice){
DMACell.prototype.setConnectivityGroupNum = function(num, force){
if (force) this._eSimConnectivityGroup = num;
else if (this._eSimConnectivityGroup>num){
this._eSimConnectivityGroup = num;
this.propagateConnectivityGroupNum(num);
}
};
DMACell.prototype.getConnectivityGroupNum = function(){
return this._eSimConnectivityGroup;
};
DMACell.prototype.propagateConnectivityGroupNum = function(num){
if (num===undefined) num = this._eSimConnectivityGroup;
lattice.propagateToNeighbors(this.getAbsoluteIndex(), function(neighbor){
if (neighbor) neighbor.setConnectivityGroupNum(num);
});
};
});
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment