diff --git a/index.html b/index.html index 77598d4a6638fb590e381eb1de08ab243aa738e0..906f0c293c84bcf01ad8c71c245c8d926a6010dc 100644 --- a/index.html +++ b/index.html @@ -43,19 +43,19 @@ <!--fea stuff--> <script src="js/fea/DmaNode.js"></script> <script src="js/fea/DmaBeam.js"></script> - <script src="js/fea/DmaCell.js"></script> - <script src="js/fea/DMASuperCell.js"></script> - <script src="js/fea/DMACellFreeform.js"></script> - <script src="js/fea/DmaCellOcta.js"></script> - <script src="js/fea/DmaCellTetra.js"></script> - <script src="js/fea/DmaCellOther.js"></script> + <script src="js/cell/DmaCell.js"></script> + <script src="js/cell/DMASuperCell.js"></script> + <script src="js/cell/DMACellFreeform.js"></script> + <script src="js/cell/DmaCellOcta.js"></script> + <script src="js/cell/DmaCellTetra.js"></script> + <script src="js/cell/DmaCellOther.js"></script> <script src="js/fea/DmaPart.js"></script> <!--models--> <script src="js/models/ThreeModel.js"></script> <script src="js/models/LatticeOcta.js"></script> <script src="js/models/LatticeOther.js"></script> - <script src="js/models/Lattice.js"></script> + <script src="js/lattice/Lattice.js"></script> <script src="js/models/FillGeometry.js"></script> <script src="js/models/BasePlane.js"></script> <script src="js/models/extrudeVisualizer.js"></script> diff --git a/js/fea/DMACellFreeform.js b/js/cell/DMACellFreeform.js similarity index 100% rename from js/fea/DMACellFreeform.js rename to js/cell/DMACellFreeform.js diff --git a/js/fea/DMASuperCell.js b/js/cell/DMASuperCell.js similarity index 100% rename from js/fea/DMASuperCell.js rename to js/cell/DMASuperCell.js diff --git a/js/fea/DmaCell.js b/js/cell/DmaCell.js similarity index 100% rename from js/fea/DmaCell.js rename to js/cell/DmaCell.js diff --git a/js/fea/DmaCellOcta.js b/js/cell/DmaCellOcta.js similarity index 100% rename from js/fea/DmaCellOcta.js rename to js/cell/DmaCellOcta.js diff --git a/js/fea/DmaCellOther.js b/js/cell/DmaCellOther.js similarity index 100% rename from js/fea/DmaCellOther.js rename to js/cell/DmaCellOther.js diff --git a/js/fea/DmaCellTetra.js b/js/cell/DmaCellTetra.js similarity index 100% rename from js/fea/DmaCellTetra.js rename to js/cell/DmaCellTetra.js diff --git a/js/lattice/CubeLattice.js b/js/lattice/CubeLattice.js new file mode 100644 index 0000000000000000000000000000000000000000..e9db2e0a0a3eaf6d5e4bee041ab0499633ccbe3f --- /dev/null +++ b/js/lattice/CubeLattice.js @@ -0,0 +1,46 @@ +/** + * Created by aghassaei on 5/26/15. + */ + + +_.extend(Lattice, { + + CubeLattice: { + + _initLatticeType: function(){ + globals.basePlane = new SquareBasePlane(); + globals.highlighter = new CubeHighlighter(); + }, + + getIndexForPosition: function(absPosition){ + return this._indexForPosition(absPosition); + }, + + getPositionForIndex: function(index){ + return this._positionForIndex(index); + }, + + xScale: function(){ + return 1+2*this.get("cellSeparation").xy; + }, + + yScale: function(){ + return this.xScale(); + }, + + zScale: function(){ + return 1+2*this.get("cellSeparation").z; + }, + + makeCellForLatticeType: function(indices){ + return new DMACubeCell(indices); + }, + + _undo: function(){//remove all the mixins, this will help with debugging later + var self = this; + _.each(_.keys(this.CubeLattice), function(key){ + self[key] = null; + }); + } + } +}); \ No newline at end of file diff --git a/js/lattice/GIKLattice.js b/js/lattice/GIKLattice.js new file mode 100644 index 0000000000000000000000000000000000000000..d2182bbd86519fa4e10fcf2da88ebde70dc88242 --- /dev/null +++ b/js/lattice/GIKLattice.js @@ -0,0 +1,102 @@ +/** + * Created by aghassaei on 5/26/15. + */ + + +_.extend(Lattice, { + + GIKLattice: { + + _initLatticeType: function(){ + globals.basePlane = new SquareBasePlane(); + globals.highlighter = new GIKHighlighter(); + }, + + getIndexForPosition: function(absPosition){ + return this._indexForPosition(absPosition); + }, + + getPositionForIndex: function(index){ + return this._positionForIndex(index); + }, + + xScale: function(){ + return 1+2*this.get("cellSeparation").xy; + }, + + yScale: function(){ + return this.xScale(); + }, + + zScale: function(){ + return 1.28*(1+2*this.get("cellSeparation").z); + }, + + makeCellForLatticeType: function(indices){ + return new DMAGIKCell(indices); + }, + + makeSuperCell: function(range){ + var length = this.get("gikLength"); + var cells; + if (range) cells = this.addCellsInRange(range); + else { + cells = []; + for (var i=0;i<length;i++){ + cells.push(this.makeCellForLatticeType(null)); + } + } + if (cells.length < 1) return null; + var superCell = new DMASuperCell(length, range, cells); + _.each(cells, function(cell, index){ + cell.setSuperCell(superCell, index); + }); + return superCell; + }, + + _rasterGikCells: function(order, callback, var1, var2, var3, cells){ + for (var i=this._getRasterLoopInit(var1);this._getRasterLoopCondition(i,var1);i+=this._getRasterLoopIterator(var1)){ + for (var j=this._getRasterLoopInit(var2);this._getRasterLoopCondition(j,var2);j+=this._getRasterLoopIterator(var2)){ + for (var k=this._getRasterLoopInit(var3);this._getRasterLoopCondition(k,var3);k+=this._getRasterLoopIterator(var3)){ + var numToSkip = {x:0,y:0}; + if (var1.order == 0){ + if (var2.order == 1) numToSkip = this._doSuperCellCallback(cells, i, j, k, callback); + else if (var2.order == 2) numToSkip = this._doSuperCellCallback(cells, i, k, j, callback); + } else if (var1.order == 1){ + if (var2.order == 0) numToSkip = this._doSuperCellCallback(cells, j, i, k, callback); + else if (var2.order == 2) numToSkip = this._doSuperCellCallback(cells, k, i, j, callback); + } else { + if (var2.order == 0) { + numToSkip = this._doSuperCellCallback(cells, j, k, i, callback); + } + else if (var2.order == 1) { + numToSkip = this._doSuperCellCallback(cells, k, j, i, callback); + } + } + + } + } + } + }, + + _doSuperCellCallback: function(cells, x, y, z, callback){ + var cell = cells[x][y][z]; + if (z%2 != 0) cell = cells[y][x][z]; + if (!cell) { + callback(null, x, y, z); + return {x:0,y:0}; + } + var superCell = cell.superCell; + callback(superCell, x, y, z); + if (z%2 != 0) return {x:0, y:superCell.getLength()}; + return {x:superCell.getLength(), y:0}; + }, + + _undo: function(){//remove all the mixins, this will help with debugging later + var self = this; + _.each(_.keys(this.GIKLattice), function(key){ + self[key] = null; + }); + } + } +}); \ No newline at end of file diff --git a/js/lattice/KelvinLattice.js b/js/lattice/KelvinLattice.js new file mode 100644 index 0000000000000000000000000000000000000000..b98be46de1c981518749d3f8fd7da5ebd3a2ab29 --- /dev/null +++ b/js/lattice/KelvinLattice.js @@ -0,0 +1,46 @@ +/** + * Created by aghassaei on 5/26/15. + */ + + +_.extend(Lattice, { + + KelvinLattice: { + + _initLatticeType: function(){ + globals.basePlane = new SquareBasePlane(); + globals.highlighter = new TruncatedCubeHighlighter(); + }, + + getIndexForPosition: function(absPosition){ + return this._indexForPosition(absPosition); + }, + + getPositionForIndex: function(index){ + return this._positionForIndex(index); + }, + + xScale: function(){ + return 2*Math.sqrt(2)+2*this.get("cellSeparation").xy; + }, + + yScale: function(){ + return this.xScale(); + }, + + zScale: function(){ + return 2*Math.sqrt(2)+2*this.get("cellSeparation").z; + }, + + makeCellForLatticeType: function(indices){ + return new DMATruncOctaCell(indices); + }, + + _undo: function(){//remove all the mixins, this will help with debugging later + var self = this; + _.each(_.keys(this.KelvinLattice), function(key){ + self[key] = null; + }); + } + } +}); \ No newline at end of file diff --git a/js/models/Lattice.js b/js/lattice/Lattice.js similarity index 100% rename from js/models/Lattice.js rename to js/lattice/Lattice.js diff --git a/js/lattice/OctaEdgeLattice.js b/js/lattice/OctaEdgeLattice.js new file mode 100644 index 0000000000000000000000000000000000000000..0d1b73e26701e8e83ee70883597a93c34c69ea10 --- /dev/null +++ b/js/lattice/OctaEdgeLattice.js @@ -0,0 +1,64 @@ +/** + * Created by aghassaei on 5/26/15. + */ + + +_.extend(Lattice, { + + OctaEdgeLattice: { + + _initLatticeType: function(){ + globals.basePlane = new OctaBasePlane(); + globals.highlighter = new OctaEdgeHighlighter(); + + }, + + getIndexForPosition: function(absPosition){ + //todo finish this + var yIndex = Math.floor(absPosition.y/this.yScale()); + if (yIndex%2 != 0) absPosition.x += this.xScale()/2; + var yScale = 1/Math.sqrt(3); + var index = this._indexForPosition(absPosition); + if (index.z%3 == 1) { + absPosition.x -= this.xScale()/2; + absPosition.y += yScale/2; + } else if (index.z%3 == 2){ + absPosition.y += yScale; + } + var index = this._indexForPosition(absPosition); + return index; + }, + + getPositionForIndex: function(index){ + + var position = _.clone(index); + var xScale = this.xScale(); + var yScale = 1/Math.sqrt(3); + position.x = (position.x+1/2)*xScale; + position.y = position.y*this.yScale()+yScale/2; + position.z = (position.z+0.5)*this.zScale(); + if (index.y%2 != 0) position.x -= this.xScale()/2; + if (index.z%3 == 1) { + position.x += this.xScale()/2; + position.y -= yScale/2; + } else if (index.z%3 == 2){ + position.y -= yScale; + } + return position; + }, + + makeCellForLatticeType: function(indices){ + return new DMAEdgeOctaCell(indices); + }, + + _undo: function(){//remove all the mixins, this will help with debugging later + var self = this; + _.each(_.keys(this.OctaEdgeLattice), function(key){ + self[key] = null; + }); + _.each(_.keys(this.OctaFaceLattice), function(key){ + self[key] = null; + }); + } + } +}); \ No newline at end of file diff --git a/js/lattice/OctaFaceLattice.js b/js/lattice/OctaFaceLattice.js new file mode 100644 index 0000000000000000000000000000000000000000..a10acb0975f632732de8108ac281d517b4426b08 --- /dev/null +++ b/js/lattice/OctaFaceLattice.js @@ -0,0 +1,54 @@ +/** + * Created by aghassaei on 5/26/15. + */ + +_.extend(Lattice, { + + OctaFaceLattice: { + + _initLatticeType: function(){ + globals.basePlane = new OctaBasePlane(); + globals.highlighter = new OctaFaceHighlighter(); + }, + + getIndexForPosition: function(absPosition){ + var yIndex = Math.floor(absPosition.y/this.yScale()); + if (yIndex%2 != 0) absPosition.x += this.xScale()/2; + var index = this._indexForPosition(absPosition); + if (index.z%2 == 1) index.y += 1; + return index; + }, + + getPositionForIndex: function(index){ + var position = _.clone(index); + position.x = (position.x+1/2); + position.y = position.y*this.yScale()+1/Math.sqrt(3)/2; + position.z = (position.z+0.5)*this.zScale(); + if ((index.y%2) != 0) position.x -= this.xScale()/2; + return position; + }, + + xScale: function(){ + return 1+2*this.get("cellSeparation").xy; + }, + + yScale: function(){ + return this.xScale()/2*Math.sqrt(3); + }, + + zScale: function(){ + return 2/Math.sqrt(6)+2*this.get("cellSeparation").z; + }, + + makeCellForLatticeType: function(indices){ + return new DMAFaceOctaCell(indices); + }, + + _undo: function(){//remove all the mixins + var self = this; + _.each(_.keys(this.OctaFaceLattice), function(key){ + self[key] = null; + }); + } + } +}); \ No newline at end of file diff --git a/js/lattice/OctaFreeFormFaceLattice.js b/js/lattice/OctaFreeFormFaceLattice.js new file mode 100644 index 0000000000000000000000000000000000000000..acc7ab9e52197b64fdb2b10d2d54f163d1ec93fe --- /dev/null +++ b/js/lattice/OctaFreeFormFaceLattice.js @@ -0,0 +1,74 @@ +/** + * Created by aghassaei on 5/26/15. + */ + + +_.extend(Lattice, { + + OctaFreeFormFaceLattice: { + + _initLatticeType: function(){ + globals.basePlane = new OctaBasePlane(); + globals.highlighter = new OctaFreeFormHighlighter(); + + this.set("freeformCellType", "octa"); + + }, + + addFreeFormCell: function(parentCellPos, parentCellOrient, direction, parentType, type){ + var cells = this.get("cells"); + cells[0][0].push(this.makeCellForLatticeType({x:0,y:0,z:cells[0][0].length}, parentCellPos, parentCellOrient, direction, parentType, type)); + this.set("numCells", this.get("numCells")+1); + globals.three.render(); + }, + + makeCellForLatticeType: function(index, parentPosition, parentOrientation, direction, parentType, type){ + if (type){ + if (type == "octa") return new DMAFreeFormOctaCell(index, parentPosition, parentOrientation, direction, parentType); + return new DMAFreeFormTetraCell(index, parentPosition, parentOrientation, direction, parentType); + } + if (this.get("freeformCellType") == "octa") return new DMAFreeFormOctaCell(index, parentPosition, parentOrientation, direction, parentType); + return new DMAFreeFormTetraCell(index, parentPosition, parentOrientation, direction, parentType); + }, + + getIndexForPosition: function(absPosition){//only used by baseplane + var yIndex = Math.floor(absPosition.y/this.yScale()); + if (yIndex%2 != 0) absPosition.x += this.xScale()/2; + var index = this._indexForPosition(absPosition); + if (index.z%2 == 1) index.y += 1; + return index; + }, + + getPositionForIndex: function(index){//only used by baseplane + var position = _.clone(index); + var xScale = this.xScale(); + position.x = (position.x+1/2)*xScale; + position.y = position.y*this.yScale()+1/Math.sqrt(3)/2; + position.z = (position.z+0.5)*this.zScale(); + if ((index.y%2) != 0) position.x -= xScale/2; + return position; + }, + + xScale: function(){ + return 1+2*this.get("cellSeparation").xy; + }, + + yScale: function(){ + return this.xScale()/2*Math.sqrt(3); + }, + + zScale: function(){ + if (this.get("freeformCellType") == "octa") return 2/Math.sqrt(6)+2*this.get("cellSeparation").xy; + return 2/Math.sqrt(24)+2*this.get("cellSeparation").xy; + }, + + _undo: function(){//remove all the mixins + var self = this; + this.set("freeformCellType", null);//todo get rid of this property + this.clearCells(); + _.each(_.keys(this.OctaFreeFormFaceLattice), function(key){ + self[key] = null; + }); + } + } +}); \ No newline at end of file diff --git a/js/lattice/OctaRotEdgeLattice.js b/js/lattice/OctaRotEdgeLattice.js new file mode 100644 index 0000000000000000000000000000000000000000..ad0d4759120731b5627fb89e519699ee7c45c0ab --- /dev/null +++ b/js/lattice/OctaRotEdgeLattice.js @@ -0,0 +1,58 @@ +/** + * Created by aghassaei on 5/26/15. + */ + + +_.extend(Lattice, { + + OctaRotEdgeLattice: { + + _initLatticeType: function(){ + globals.basePlane = new RotEdgeOctaBasePlane(); + globals.highlighter = new OctaVertexHighlighter(); + }, + + getIndexForPosition: function(absPosition){ + var position = {}; + position.x = Math.floor(absPosition.x/this.xScale()+0.5); + position.y = Math.floor(absPosition.y/this.yScale()+0.5); + position.z = Math.floor(absPosition.z/this.zScale()+0.5); + return position; + }, + + getPositionForIndex: function(index){ + var position = _.clone(index); + if (index.z %2 != 0){ + position.x += 0.5; + position.y += 0.5; + } + position.x = (position.x)*this.xScale(); + position.y = (position.y)*this.yScale(); + position.z = (position.z+1)*this.zScale(); + return position; + }, + + xScale: function(){ + return 1 + 2*this.get("cellSeparation").xy; + }, + + yScale: function(){ + return this.xScale(); + }, + + zScale: function(){ + return Math.sqrt(2)/2 + 2*this.get("cellSeparation").z; + }, + + makeCellForLatticeType: function(indices){ + return new DMARotatedEdgeCell(indices); + }, + + _undo: function(){//remove all the mixins + var self = this; + _.each(_.keys(this.OctaRotEdgeLattice), function(key){ + self[key] = null; + }); + } + } +}); \ No newline at end of file diff --git a/js/lattice/OctaVertexLattice.js b/js/lattice/OctaVertexLattice.js new file mode 100644 index 0000000000000000000000000000000000000000..a0a2ac396bf44b86109a2aab7e3ee2b5abec80df --- /dev/null +++ b/js/lattice/OctaVertexLattice.js @@ -0,0 +1,54 @@ +/** + * Created by aghassaei on 5/26/15. + */ + + +_.extend(Lattice, { + + OctaVertexLattice: { + + _initLatticeType: function(){ + globals.basePlane = new SquareBasePlane(); + globals.highlighter = new OctaVertexHighlighter(); + }, + + getIndexForPosition: function(absPosition){ + var position = {}; + position.x = Math.floor(absPosition.x/this.xScale()+0.5); + position.y = Math.floor(absPosition.y/this.yScale()+0.5); + position.z = Math.floor(absPosition.z/this.zScale()+0.5); + return position; + }, + + getPositionForIndex: function(index){ + var position = _.clone(index); + position.x = (position.x)*this.xScale(); + position.y = (position.y)*this.yScale(); + position.z = (position.z+0.5)*this.zScale(); + return position; + }, + + xScale: function(){ + return Math.sqrt(2)+this.get("cellSeparation").xy; + }, + + yScale: function(){ + return this.xScale(); + }, + + zScale: function(){ + return Math.sqrt(2)+this.get("cellSeparation").z; + }, + + makeCellForLatticeType: function(indices){ + return new DMAVertexOctaCell(indices); + }, + + _undo: function(){//remove all the mixins, this will help with debugging later + var self = this; + _.each(_.keys(this.OctaVertexLattice), function(key){ + self[key] = null; + }); + } + } +}); \ No newline at end of file diff --git a/js/lattice/TruncatedCubeLattice.js b/js/lattice/TruncatedCubeLattice.js new file mode 100644 index 0000000000000000000000000000000000000000..e81739bca00ffcadc97b33b30d850a94180bc2bb --- /dev/null +++ b/js/lattice/TruncatedCubeLattice.js @@ -0,0 +1,46 @@ +/** + * Created by aghassaei on 5/26/15. + */ + + +_.extend(Lattice, { + + TruncatedCubeLattice: { + + _initLatticeType: function(){ + globals.basePlane = new SquareBasePlane(); + globals.highlighter = new TruncatedCubeHighlighter(); + }, + + getIndexForPosition: function(absPosition){ + return this._indexForPosition(absPosition); + }, + + getPositionForIndex: function(index){ + return this._positionForIndex(index); + }, + + xScale: function(){ + return Math.sqrt(2)+2*this.get("cellSeparation").xy; + }, + + yScale: function(){ + return this.xScale(); + }, + + zScale: function(){ + return Math.sqrt(2)+2*this.get("cellSeparation").z; + }, + + makeCellForLatticeType: function(indices){ + return new DMATruncCubeCell(indices); + }, + + _undo: function(){//remove all the mixins, this will help with debugging later + var self = this; + _.each(_.keys(this.TruncatedCubeLattice), function(key){ + self[key] = null; + }); + } + } +}); \ No newline at end of file diff --git a/js/main.js b/js/main.js index 1f2a48e72652c35b3aaeaae85cb46b9ca292687f..c6507724834ac96fd8d3c8e270608e58284cada6 100644 --- a/js/main.js +++ b/js/main.js @@ -29,4 +29,6 @@ $(function(){ new ThreeView({model:globals.three}); if (globals.lattice.get("connectionType") != "gik") globals.lattice.addCellAtIndex({x:0,y:0,z:0});//add a cell + +// return {globals:globals}; });