Skip to content

Commit

Permalink
Changes to ImgToArray demo page
Browse files Browse the repository at this point in the history
  • Loading branch information
Idrian committed Oct 18, 2017
1 parent f8c80ea commit ae67aa2
Show file tree
Hide file tree
Showing 82 changed files with 86 additions and 54 deletions.
5 changes: 3 additions & 2 deletions build/ImgToArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class ImgToArray
var canvas = document.createElement("canvas");



if(canvas.getContext)
{
//this.theArray.push(new Array());
Expand All @@ -35,7 +36,7 @@ export class ImgToArray

image.src = inputArray;

// console.log("Image in converter: ",image)


// console.log("theArray: ",this.theArray);
Expand All @@ -47,7 +48,7 @@ export class ImgToArray
{



console.log("Image in converter: ",image)
ctx.drawImage(image, 0, 0);

var imgData = ctx.getImageData(0, 0, image.width, image.height);
Expand Down
4 changes: 3 additions & 1 deletion build/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ let arrayToMesh = new ArrayToMesh(model);
var converterOne : fileReader;
var useME : boolean = true;
objUpload.addEventListener("change", function(){
// console.log("I am here");
var OBJFile : File = objUpload.files[0];
Expand All @@ -406,7 +408,7 @@ let arrayToMesh = new ArrayToMesh(model);
});
/*
if(useME == true)
{
Expand Down
100 changes: 58 additions & 42 deletions build/voxc.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,12 @@ class ImgToArray {
image.onload = (() => this.imageReady(image, ctx, callback));
}
image.src = inputArray;
// console.log("Image in converter: ",image)
// console.log("theArray: ",this.theArray);
// return this.theArray;
}
imageReady(image, ctx, callback) {
console.log("Image in converter: ", image);
ctx.drawImage(image, 0, 0);
var imgData = ctx.getImageData(0, 0, image.width, image.height);
var colors = imgData.data;
Expand Down Expand Up @@ -1132,27 +1134,21 @@ class fileReader {
var count = 0;
//if x doesnt change
if (faceObj.normal == "-/0/0" || faceObj.normal == "+/0/0") {
console.log("In one.one");
//console.log("In one.one");
var m = (faceObj.y1 - faceObj.y2) / (faceObj.z1 - faceObj.z2);
var tempMin = faceObj.lowZ;
var tempMax = faceObj.maxZ;
var c = faceObj.y1 - (m * faceObj.z1);
for (var z = tempMin; z < tempMax; z++) {
console.log("In one");
//console.log("In one");
var line = ((m * (faceObj.lowZ + count)) + c);
if (line % 1 != 0)
line = Math.round(line + 0.5);
if (faceObj.yAngle == "+") {
if (faceObj.normal == "+/0/0")
this.putIn(faceObj.yo, line, faceObj.normal, faceObj.color, z, faceObj.xo);
else
this.putIn(faceObj.yo, line, faceObj.normal, faceObj.color, z, faceObj.xo);
this.putIn(faceObj.yo, line, faceObj.normal, faceObj.color, z, faceObj.xo, faceObj);
}
if (faceObj.yAngle == "-") {
if (faceObj.normal == "+/0/0")
this.putIn(line, faceObj.yo, faceObj.normal, faceObj.color, z, faceObj.xo);
else
this.putIn(line, faceObj.yo, faceObj.normal, faceObj.color, z, faceObj.xo);
this.putIn(line, faceObj.yo, faceObj.normal, faceObj.color, z, faceObj.xo, faceObj);
}
count++;
}
Expand All @@ -1163,21 +1159,15 @@ class fileReader {
//alert("m = " + m);
var c = faceObj.z1 - (m * faceObj.x1);
for (var x = faceObj.lowX; x < faceObj.maxX; x++) {
console.log("In two");
//console.log("In two");
var line = ((m * (faceObj.lowX + count)) + c);
if (line % 1 != 0)
line = Math.round(line + 0.5);
if (faceObj.zAngle == "+") {
if (faceObj.normal == "0/+/0")
this.putIn(faceObj.zo, line, faceObj.normal, faceObj.color, x, faceObj.yo);
else
this.putIn(faceObj.zo, line, faceObj.normal, faceObj.color, x, faceObj.yo);
this.putIn(faceObj.zo, line, faceObj.normal, faceObj.color, x, faceObj.yo, faceObj);
}
if (faceObj.zAngle == "-") {
if (faceObj.normal == "0/+/0")
this.putIn(line, faceObj.zo, faceObj.normal, faceObj.color, x, faceObj.yo);
else
this.putIn(line, faceObj.zo, faceObj.normal, faceObj.color, x, faceObj.yo);
this.putIn(line, faceObj.zo, faceObj.normal, faceObj.color, x, faceObj.yo, faceObj);
}
count++;
}
Expand All @@ -1188,71 +1178,95 @@ class fileReader {
//alert("m = " + m);
var c = faceObj.y1 - (m * faceObj.x1);
for (var x = faceObj.lowX; x < faceObj.maxX; x++) {
console.log("In three");
//console.log("In three");
var line = ((m * (faceObj.lowX + count)) + c);
if (line % 1 != 0)
line = Math.round(line + 0.5);
if (faceObj.xAngle == "+") {
if (faceObj.normal == "0/0/+")
this.putIn(faceObj.yo, line, faceObj.normal, faceObj.color, x, faceObj.zo);
else
this.putIn(faceObj.yo, line, faceObj.normal, faceObj.color, x, faceObj.zo);
this.putIn(faceObj.yo, line, faceObj.normal, faceObj.color, x, faceObj.zo, faceObj);
}
if (faceObj.xAngle == "-") {
if (faceObj.normal == "0/0/+")
this.putIn(line, faceObj.yo, faceObj.normal, faceObj.color, x, faceObj.zo);
else
this.putIn(line, faceObj.yo, faceObj.normal, faceObj.color, x, faceObj.zo);
this.putIn(line, faceObj.yo, faceObj.normal, faceObj.color, x, faceObj.zo, faceObj);
}
count++;
}
}
}
putIn(from, to, normal, color, currentLevel, other) {
putIn(from, to, normal, color, currentLevel, other, faceObj) {
console.log("In put in: " + from + " to " + to);
if (normal == "+/0/0") {
for (var y = from; y < to; y++) {
console.log("Adding " + color + " to " + (other - 1) + "/" + (y) + "/" + currentLevel);
console.log("Adding " + color + " to " + (other - 1) + "/" + (y) + "/" + currentLevel + " " + "+/0/0");
//if (this.finalMatrix[other - 1][currentLevel][z] != null)
this.finalMatrix[other - 1][y][currentLevel] = color;
if (this.check(other - 1, y, currentLevel, faceObj))
this.finalMatrix[other - 1][y][currentLevel] = color;
}
}
if (normal == "-/0/0") {
for (var y = from; y < to; y++) {
console.log("Adding " + color + " to " + other + "/" + (y) + "/" + (currentLevel));
console.log("Adding " + color + " to " + other + "/" + (y) + "/" + (currentLevel) + " " + "-/0/0");
//if (this.finalMatrix[other][currentLevel][z] != null)
this.finalMatrix[other][y][currentLevel] = color;
if (this.check(other, y, currentLevel, faceObj))
this.finalMatrix[other][y][currentLevel] = color;
}
}
if (normal == "0/+/0") {
for (var z = from; z < to; z++) {
console.log("Adding " + color + " to " + currentLevel + "/" + (other - 1) + "/" + z);
console.log("Adding " + color + " to " + currentLevel + "/" + (other - 1) + "/" + z + " " + "0/+/0");
//if (this.finalMatrix[x][other - 1][currentLevel])
this.finalMatrix[currentLevel][other - 1][z] = color;
if (this.check(currentLevel, other - 1, z, faceObj))
this.finalMatrix[currentLevel][other - 1][z] = color;
}
}
if (normal == "0/-/0") {
for (var z = from; z < to; z++) {
console.log("Adding " + color + " to " + currentLevel + "/" + (other) + "/" + z);
console.log("Adding " + color + " to " + currentLevel + "/" + (other) + "/" + z + " " + "0/-/0");
//if (this.finalMatrix[x] && this.finalMatrix[x][other] && this.finalMatrix[x][other][currentLevel])
this.finalMatrix[currentLevel][other][z] = color;
if (this.check(currentLevel, other, z, faceObj))
this.finalMatrix[currentLevel][other][z] = color;
}
}
if (normal == "0/0/+") {
for (var y = from; y < to; y++) {
console.log("Adding " + color + " to " + y + " " + y + "/" + (currentLevel) + "/" + other);
console.log("Adding " + color + " to " + currentLevel + " " + y + "/" + (y) + "/" + (other - 1) + " " + "0/0/+");
//if (this.finalMatrix[x] && this.finalMatrix[x][currentLevel] && this.finalMatrix[x][currentLevel][other - 1])
this.finalMatrix[currentLevel][y][other - 1] = color;
if (this.check(currentLevel, y, other - 1, faceObj))
this.finalMatrix[currentLevel][y][other - 1] = color;
}
}
if (normal == "0/0/-") {
for (var y = from; y < to; y++) {
console.log("Adding " + color + " to " + y + " " + y + "/" + (currentLevel) + "/" + other);
console.log("Adding " + color + " to " + y + " " + currentLevel + "/" + (y) + "/" + other + " " + "0/0/- " + (this.largestY - this.lowY));
//if (this.finalMatrix[x] && this.finalMatrix[x][currentLevel] && this.finalMatrix[x][currentLevel][other])
this.finalMatrix[currentLevel][y][other] = color;
if (this.check(currentLevel, y, other, faceObj))
this.finalMatrix[currentLevel][y][other] = color;
}
}
}
check(x, y, z, faceObj) {
if (faceObj.maxX == faceObj.lowX) {
console.log("Equal X");
}
else if (x < faceObj.lowX || x >= faceObj.maxX) {
console.log("failed in x: " + x + " maxe= " + faceObj.maxX + " min= " + faceObj.lowX);
return false;
}
if (faceObj.maxY == faceObj.lowY) {
console.log("Equal Y");
}
else if (y < faceObj.lowY || y >= faceObj.maxY) {
console.log("failed in y: " + y + " maxe= " + faceObj.maxY + " min= " + faceObj.lowY);
return false;
}
if (faceObj.maxZ == faceObj.lowZ) {
console.log("Equal Z");
}
else if (z < faceObj.lowZ || z >= faceObj.maxZ) {
console.log("failed in z: " + z + " maxe= " + faceObj.maxZ + " min= " + faceObj.lowZ);
return false;
}
return true;
}
}
exports.fileReader = fileReader;
class face {
Expand Down Expand Up @@ -2287,6 +2301,8 @@ var jsonString = editor.getValue();
var converterOne : fileReader;

var useME : boolean = true;


objUpload.addEventListener("change", function(){
// console.log("I am here");
var OBJFile : File = objUpload.files[0];
Expand All @@ -2297,7 +2313,7 @@ var jsonString = editor.getValue();


});

/*

if(useME == true)
{
Expand Down
31 changes: 22 additions & 9 deletions js/MRI.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,36 @@ function loadMRI()

var controls = new THREE.OrbitControls(camera, renderer.domElement);

scene.background = new THREE.Color( 0xff0000 );
scene.background = new THREE.Color( 0xffffff );


var mriRuleApplyer = new RuleApplyer();





imgConverter.convert('./resources/images/64x64/normal_brain_mri_'+10+'.jpg',function()
imgConverter.convert('./resources/images/64x64/normal_brain_mri_'+10+'.jpg',function()
{
model = imgConverter.output();
// console.log("imgArray: ",model);
// console.log("imgArray: ",model);
// console.log("colors: ",imgConverter.getColors());
var mesh = generateMesh();
mesh.rotation.x = 90*Math.PI/180;
// mesh.position.y = 10;
scene.add(mesh);
});

document.getElementById("imageTextForm").onsubmit = function(e)
{
e.preventDefault();
var text_url = document.getElementById("imageText").value;

imgConverter.convert(text_url,function()
{
model = imgConverter.output();
// console.log("imgArray: ",model);
// console.log("colors: ",imgConverter.getColors());
scene.remove(scene.getObjectByName("Voxel"));
var mesh = generateMesh();
scene.add(mesh);
});

}

function render()
{
Expand All @@ -84,6 +92,7 @@ function loadMRI()
{
var ruleFileJson = '{"Rules" : [';
var colors = imgConverter.getColors();
console.log("Colors: ",colors);
var i
for(i=0;i<colors.length-1;i++)
{
Expand All @@ -97,7 +106,11 @@ function loadMRI()
var ruleFile = JSON.parse(ruleFileJson);
let arrayToMesh = new RuleApplyer();
mriRuleApplyer.convert(ruleFile, model);


// let arrayToMesh = new ArrayToMesh(model);
var mesh = mriRuleApplyer.output();
// var mesh = arrayToMesh.output();
return mesh;
}
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/16x16/normal_brain_mri_11.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/16x16/normal_brain_mri_12.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/16x16/normal_brain_mri_13.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/images/16x16/normal_brain_mri_14.jpg
Binary file added resources/images/16x16/normal_brain_mri_15.jpg
Binary file added resources/images/16x16/normal_brain_mri_16.jpg
Binary file added resources/images/16x16/normal_brain_mri_18.jpg
Binary file added resources/images/16x16/normal_brain_mri_19.jpg
Binary file added resources/images/16x16/normal_brain_mri_20.jpg
Binary file added resources/images/16x16/normal_brain_mri_21.jpg
Binary file added resources/images/16x16/normal_brain_mri_22.jpg
Binary file added resources/images/16x16/normal_brain_mri_4.jpg
Binary file added resources/images/16x16/normal_brain_mri_5.jpg
Binary file added resources/images/16x16/normal_brain_mri_6.jpg
Binary file added resources/images/16x16/normal_brain_mri_7.jpg
Binary file added resources/images/16x16/normal_brain_mri_8.jpg
Binary file added resources/images/16x16/normal_brain_mri_9.jpg
Binary file added resources/images/32x32/normal_brain_mri_11.jpg
Binary file added resources/images/32x32/normal_brain_mri_12.jpg
Binary file added resources/images/32x32/normal_brain_mri_13.jpg
Binary file added resources/images/32x32/normal_brain_mri_14.jpg
Binary file added resources/images/32x32/normal_brain_mri_15.jpg
Binary file added resources/images/32x32/normal_brain_mri_16.jpg
Binary file added resources/images/32x32/normal_brain_mri_18.jpg
Binary file added resources/images/32x32/normal_brain_mri_19.jpg
Binary file added resources/images/32x32/normal_brain_mri_20.jpg
Binary file added resources/images/32x32/normal_brain_mri_21.jpg
Binary file added resources/images/32x32/normal_brain_mri_22.jpg
Binary file added resources/images/32x32/normal_brain_mri_4.jpg
Binary file added resources/images/32x32/normal_brain_mri_5.jpg
Binary file added resources/images/32x32/normal_brain_mri_6.jpg
Binary file added resources/images/32x32/normal_brain_mri_7.jpg
Binary file added resources/images/32x32/normal_brain_mri_8.jpg
Binary file added resources/images/32x32/normal_brain_mri_9.jpg

0 comments on commit ae67aa2

Please sign in to comment.