Skip to content
Snippets Groups Projects
Commit 68625749 authored by Francesco Giacomini's avatar Francesco Giacomini
Browse files

[wip] restructuring

parent fa383717
No related branches found
No related tags found
No related merge requests found
......@@ -123,18 +123,136 @@ function openFileFromServer(url)
{
if (txtFile.readyState === 4) {
if (txtFile.status === 200) {
readData((txtFile.responseText));
readImage((txtFile.responseText));
}
}
}
txtFile.send(null);
}
// La funzione readData() prende in ingresso il file di input memorizzato nella
export function get_metadata(lines: string[]): G.Metadata
{
let metadata = new G.Metadata();
let xMin: number = 0, yMin: number = 0, xMax: number = 0, yMax: number = 0;
let passo: number = 0; //dimensione di un pixel in micorn
let readMode: string = 'u'; //direzione di lettura
//scorro l'array soffermandomi solo sulle righe "intestazione delle x". Devo
//determinare ascisse e cordinate minime e massime, il passo e la direzione di
//scansione
for (let i = 0; i < lines.length; i++) {
if (parseInt(lines[i]) > 17000 && lines[i][0] == '5') {
if (xMin == 0) { //se sono alla prima intestazione salvo la x e la y
xMin = parseInt(lines[i]);
yMin = parseInt(lines[i + 1]);
i++;
} else { //definisco passo e direzione di scansione dalla seconda intestazione
if (parseInt(lines[i]) == xMin) {
readMode = 'c';
passo = Math.abs(yMin - +lines[i + 1]); // the unary + converts to number
//se sto leggendo per colonne determino xMax leggendo dalla fine
for (let j: number = lines.length; j > i; j--) {
//se la riga è "intestazione x" memorizzo xMax e lo confronto con xMin
if (parseInt(lines[j]) > 17000 && lines[j][0] == '5') {
xMax = parseInt(lines[j]);
if (xMax < xMin) { let t: number = xMax; xMax = xMin; xMin = t; }
break;
}
}
} else {
readMode = 'r';
passo = Math.abs(xMin - +lines[i]); // the unary + converts to number
//se sto leggendo per righe determino yMax leggendo dalla fine
for (let j: number = lines.length; j > i; j--) {
//se la riga è "intestazione y" memorizzo yMax e lo confronto con yMin
if (parseInt(lines[j]) > 17000 && lines[j][0] == '6') {
yMax = parseInt(lines[j]);
if (yMax < yMin) { let t: number = yMax; yMax = yMin; yMin = t; }
break;
}
}
}
break;
}
}
} //alert(xMin + " " + xMax + " " + yMin + " " + yMax + " " + passo);
metadata = {xMin, xMax, yMin, yMax, stepSize: passo, direction: readMode};
return metadata;
}
// version working on an array of numbers, obtained from the array of string lines
export function get_metadata_num(lines: number[]): G.Metadata
{
let metadata = new G.Metadata();
let xMin: number = 0, yMin: number = 0, xMax: number = 0, yMax: number = 0;
let passo: number = 0; //dimensione di un pixel in micorn
let readMode: string = 'u'; //direzione di lettura
//scorro l'array soffermandomi solo sulle righe "intestazione delle x". Devo
//determinare ascisse e cordinate minime e massime, il passo e la direzione di
//scansione
for (let i = 0; i < lines.length; i++) {
let p = lines[i];
if (lines[i] > 17000 && lines[i].toString()[0] == '5') {
if (xMin == 0) { //se sono alla prima intestazione salvo la x e la y
xMin = lines[i];
yMin = lines[i + 1];
i++;
} else { //definisco passo e direzione di scansione dalla seconda intestazione
if (lines[i] == xMin) {
readMode = 'c';
passo = Math.abs(yMin - lines[i + 1]); // the unary + converts to number
//se sto leggendo per colonne determino xMax leggendo dalla fine
for (let j: number = lines.length; j > i; j--) {
//se la riga è "intestazione x" memorizzo xMax e lo confronto con xMin
if (lines[j] > 17000 && lines[j].toString()[0] == '5') {
xMax = lines[j];
if (xMax < xMin) { let t: number = xMax; xMax = xMin; xMin = t; }
break;
}
}
} else {
readMode = 'r';
passo = Math.abs(xMin - lines[i]); // the unary + converts to number
//se sto leggendo per righe determino yMax leggendo dalla fine
for (let j: number = lines.length; j > i; j--) {
//se la riga è "intestazione y" memorizzo yMax e lo confronto con yMin
if (lines[j] > 17000 && lines[j].toString()[0] == '6') {
yMax = lines[j];
if (yMax < yMin) { let t: number = yMax; yMax = yMin; yMin = t; }
break;
}
}
}
break;
}
}
} //alert(xMin + " " + xMax + " " + yMin + " " + yMax + " " + passo);
metadata = {xMin, xMax, yMin, yMax, stepSize: passo, direction: readMode};
return metadata;
}
/* let metadata = get_metadata(lines);
let passo = metadata.stepSize; //dimensione di un pixel in micorn
let readMode = metadata.direction; //direzione di lettura
//coordinate minime e massime in entrambe le dimensioni
let xMin = metadata.xMin;
let yMin = metadata.yMin;
let xMax = metadata.xMax;
let yMax = metadata.yMax;
*/
// La funzione readImage() prende in ingresso il file di input memorizzato nella
// stringa "fileString". La funzione riempie la matrice "DataMatrix" con i dati
// in modo che essi siano memorizzati in un formato più leggibile. Sono ricavate
// anche altre variabili necessarie per il resto del codice.
export function readData(content: string): G.Image
export function readImage(content: string): G.Image
{
let newOrigin = { xp: 0, yp: 0 }; //origine nel caso di zoom
let passo: number = 0; //dimensione di un pixel in micorn
......@@ -230,7 +348,7 @@ export function readData(content: string): G.Image
fileStringArray[i] = (parseInt(fileStringArray[i]) + passo).toString();
}
}
//Definisco le dimensioni della matrice DataMatrix e la inizializzo
let xDim: number;
let yDim: number;
......
......@@ -10,6 +10,16 @@ export class Calibration
b: number;
}
export class Metadata
{
xMin: number;
xMax: number;
yMin: number;
yMax: number;
stepSize: number;
direction: string;
}
export class Image
{
DataMatrix: number[][][];
......
......@@ -72,10 +72,10 @@ export function setImportFile()
readerObject.onload = function ()
{
let content: string = readerObject.result;
let image = fs.readData(content);
console.log(image.xDim);
img.drawImg(image, { x: 0, y: 0 }, { x: image.xDim - 1, y: image.yDim - 1 }, 0, G.channelDepth);
img.drawChart(image, { x: 0, y: 0 }, { x: image.xDim - 1, y: image.yDim - 1 }, 0, G.channelDepth);
let image = fs.readImage(content);
console.log(image.width);
img.drawImg(image, { x: 0, y: 0 }, { x: image.width - 1, y: image.height - 1 }, 0, G.channelDepth);
img.drawChart(image, { x: 0, y: 0 }, { x: image.width - 1, y: image.height - 1 }, 0, G.channelDepth);
// install callbacks for the canvas and chart?
}
readerObject.readAsText(file);
......@@ -155,14 +155,15 @@ function callback(files)
{
$("#load-spinner").css("display", "inline");
console.log("Try to open " + files[files.length - 1].name + " ...");
let readerObject: any = new FileReader();
readerObject.readAsBinaryString(files[files.length - 1]);
let file: File = files[files.length - 1];
console.log("Try to open " + file.name + " ...");
let readerObject = new FileReader();
readerObject.onload = function ()
{
let fileString: string = readerObject.result;
fs.readData(fileString);
let content: string = readerObject.result;
fs.readImage(content);
}
readerObject.readAsText(file);
}
//la funzione findPosition definisce la posizione del cursore del mouse
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment