Morphing algorithms


The morphing algorithm is defined using the parameters MODE and DEPTH to TSMorph-render.

The basic algorithm is to find 3 points which make a triangle around the point and morph this triangle between the start and end images.

The DEPTH parameter controls how many points will be checked to form a triangle. 0 means just the closest 3 points are examined, 1 the closest 4, 2 the closest 5 etc.

The MODE parameter controls both which triangle is chosen and what to do if no surrounding triangle is found.

If MODE=0 2 4 ... 30 (i.e. bit 1 not set [do not add 1]) then if no triangle surrounding the point is found examining the closest points then the 3 closest points are used to decide how to morph. Otherwise the point is assumed to be stationery.

If MODE=2 3 6 7 ... 30 31 (i.e. bit 2 set [add 2]) then all the closest points (the exact number controlled by DEPTH) are examined to determine the smallest triangle. Otherwise the first surrounding triangle found is used.

If MODE=4 5 6 7 12 ... (i.e. bit 3 set [add 4]) then a square algorithm is used to find the closest points. Otherwise all points are examined. Although using these MODEs could theoretically make the program run faster, it seems to generally run slower.

If MODE=8 9 10 ... (i.e. bit 4 set [add 8]) then a Delauany triangle algorithm is used to find triangles. For these modes the DEPTH parameter should normally be set to 0. Also floating point calculations are still done even if INTEGER is set to YES.

If MODE=16 17 ... (i.e. bit 8 set [add 16]) then the closest triangles are only calculated once at the start (based on the average of start and end). This should only be used if the points do not move a lot between the start and end images. It can speed things up a lot for a lot of frames. It does not make sense to use this for Animated Warps/Morphs. This uses a lot of memory:

    (DEPTH + 4) * Image_Width * Image_Height * 4

    e.g. 640x512 image, DEPTH=2 uses 7.5 MB (contiguous) memory

Therefore MODEs 0 and 1 should be faster than modes 2 or 3. The DEPTH parameter can also have a major effect on the rendering speed.

See Benchmarks.