pathanimator/inbrowser/ts/PathAnimator.ts

82 lines
1.9 KiB
TypeScript

/// <reference path="BrowserHandler.ts" />
/// <reference path="window.ts" />
/// <reference path="PAImage.ts" />
/// <reference path="algorithm/DistancePath.ts" />
/// <reference path="algorithm/Noise.ts" />
/**
* Main application class
*/
class PathAnimator {
/**
* Browser abstraction instance
*/
private inputHandler:BrowserHandler;
/**
* Input image
*/
private input: PAImage;
/**
* Output image
*/
private output: PAImage;
/**
* Constructor
*/
constructor() {
this.inputHandler = new BrowserHandler(this);
this.input = null;
this.output = null;
}
/**
* Set input image
* @param image image to set as input
*/
setInputImage(image: PAImage) {
this.input = image;
}
/**
* Actual run function that triggerse the processing.
* @param config the algorithm specific config options
*/
run(config: Object) {
var algorithmName = config['algorithm'];
var algorithm: Algorithm = null;
switch(algorithmName) {
case 'distancepath':
algorithm = new DistancePath(config);
break;
case 'noise':
algorithm = new Noise();
break;
}
if (algorithm) {
this.inputHandler.clearOutput();
this.output = new PAImage(this.input.getWidth(), this.input.getHeight(), 3);
this.output.allocateMemory();
algorithm.setCallback(this);
algorithm.setInput(this.input);
algorithm.setOutput(this.output);
algorithm.run();
this.inputHandler.completed();
this.inputHandler.showOutput(this.output);
}
}
/**
* We got a message from out algorithm, display it
* @param message Message to show
* @param append True if message should be appended, false if previous should be cleared
*/
messageCallback(message: string, append: boolean) {
if (append) {
this.inputHandler.appendOutput(message);
} else {
this.inputHandler.replaceOutput(message);
}
}
}