Wednesday, January 8, 2014

The Magic Line, cross only with extreme care.

Between the current manipulation of the model, and the model's data itself, which ought to be totally independent of any manipulation of it.  (needs a clean layer between them).
Simplistic Plan for converting the messy monolithic interface into the easy clean one:
1) Create a duplicate of the data, in the desired idealized format, and maintain both.
2) Write a conversion so that whenever the messy monolithic current version is presented without the idealized one, the idealized one is created from the messy monolith, thus converting old data to new data on the fly when it's encountered.
For example in my current work, my monolith is an ultrasound sector of say 300x400 which represents a radial (polar) sector of 70 degrees at 12CM depth.  This is the image.  The angle is represented by 36 lines of data and 2000 samples represent the distance from the origin (the ultrasound transducer).
So now we need to manipulate (measure with gui tools, enhance, etc...) a new image, 15CM, 90 degree angle, different dimensions, number of lines, samples,.... And all the code is broken! (the code that was created for the 300x400 70 degree 36 line 2000 sample images).

Tuesday, January 7, 2014

Fundamental Design Principle

A fundamental design principle, I know because I violate it frequently, is to always operate on a model of the data, not on the data itself.
In my job, I write code to manipulate an ultrasound image or sequence, with measurements, cursor positions, scaling, image processing, etc.  It only gets worse and worse, the longer I interface to the data itself, rather than interfacing to a idealized model of the data, and subsequently displaying the idealized data, such that the idealized data would never have to be converted, but only re-realized onto a new platform (a new scale, new dimensions, sector angle, hardware, etc).
For example, if a measurement on the ultrasound image is at (x,y), then it needs to be converted to the polar coordinate (distance,angle) distance from origin and angle, before performing any computations, and the positions need to be saved in the model's (distance,angle).   To save a position, the image (x,y) is converted FIRST.
This allows any image in (x,y) to be produced, and manipulated,  and the computations only need to be done once, in (distance,angle) polar coordinates, in the original model's representation.