pathanimator/c++/algorithm
2022-01-17 15:53:17 +01:00
..
algorithm.h initial import 2022-01-17 15:53:17 +01:00
CMakeLists.txt initial import 2022-01-17 15:53:17 +01:00
distancepath.cpp initial import 2022-01-17 15:53:17 +01:00
distancepath.h initial import 2022-01-17 15:53:17 +01:00
README.md initial import 2022-01-17 15:53:17 +01:00

Algrithm descriptions

Distance Path

This algorithm uses a simple distance calculation based from one or more start points.

  1. Initialization
    • The start points are added to the "to process" queue.
    • The distance values on all pixels are set to m_maxDistance on start.
  2. Main loop
    • Each point in the "to process" queue is taken and it's value (distance).
    • Each surrounding pixel takes the last distance (the center) and adds the distance given by the parameters m_weighBlock and m_weightPath.
      The input image selects the weight from the two parameters, a 0 (black) pixel takes 100% of the block value, a (255) white pixel
      is 100% path weight.
    • If this distance is smaller than the previous pixel that was calulated, replace it and add the pixel to the next list of pixel to be processed.
    • After the iteration is done, clear the process queue and swap with the next queue and repeat until the next queue is empty or the hard limit of 10.000 iterations is met.
  3. Postprocessing
    • After the raw distances are calculated, the actual max distance is found.
    • The raw map (floating ponts) is mapped down to a 16 bit image and the distance is saved in the red channel,
    • the iteration where the pixel was set is in the green channel
    • the blue channel is a mask if the pixel was seen as a path (65535) or as a block (0).
      The m_threshhold value sets the point where a path becomes a block.
      Setting the threshhold allows some cheating. You can add an path between areas with a gray value, the algorithm uses it to calculate
      distance and as a path to other ares, but shows it as a block in the blue channel.