I'm working on a Graph based Image editor. My current plan is to have Nodes of the graph be operations on the image, an operation will take a number of input buffers and manipulate them in some way (be it invert a single input, composite two inputs, draw a rectangle on an input, etc. ). a buffer could be an RGBA image (represented by a buffer class I'm working on as well) or a Buffer of simply doubles (represented by the same buffer class which is generic) which would be the output of something like a noise operation. each output from a node can go to any number of inputs but each input can only have one connection to it, an example might look something like this:
My Current code is changing rapidly and drastically, so I don't want to post the whole so I'm going to just do the interfaces i have in mind, they won't compile I just want to get the idea across
interface BufferValue<T>{
BufferValue<T> add(BufferValue<T> t);
//various other math stuff for values
//standard setters and getters
}
class Buffer<T extends BufferValue & Comparable<T>>{
T[] data = new T[width*height]; //DOES NOT COMPILE, but demonstrates idea
T getPixel(int x, int y);//these two used inside the operations
void setPixel(int x, int y, T t);
}
class Connection{
String sourceOp;
String sourceOut;
String destOp;
String destIn;
}
abstract class Operation{
List<String> inputNames;//names of inputs
Map<String, Connection> inputs;//name to connection for input
//WAY TO STORE WHAT TYPE OF BUFFER INPUTS NEED TO BE
List<String> outputNames;
Map<String, List<Connections> outputs;//output connections
//WAY TO STORE WHAT TYPE OF BUFFER OUTPUTS ARE
abstract Buffer getOutput(String out);// will use inputs to create output
//TEST IF INPUT TYPES ARE CORRECT
}
The above assumes that the graph stores the nodes as names but that shouldn't matter for this question.
I'm looking for the best way to store and test what types of buffers are being passed around. My assumption is that storing a list of Class
es is the way I should go, but the problem of type erasure has me confused. What would the proper way be to test that the buffer is the right type for the needed operation?
If you need clarification please ask. Thanks for the help