Dear Wolfram,
Thanks for the reply. What you describe should be possible.
The path finding method on the wiki reconstructs the arrival time
function using cubic interpolation so the paths curve on a sub-pixel
scale. As you point out this is relatively slow. The Dijkstra
algorithm gives discrete paths from node to node. If you want to
enumerate all the discrete paths you should be able to do this much
faster.
Something like this may be all you need:
import numpy as np
import pylab as plt
from skfmm import distance
phi = np.ones((15,15))
phi[7,7] = -1
d = distance(phi)
gx, gy = np.gradient(d, edge_order=2)
angle = np.arctan2(gx,gy)/2.0/np.pi + 1/16.0
angle[angle<0] +=1
parent_code = (angle*8).astype(int)
print parent_code
[[5 5 5 5 5 6 6 6 6 6 7 7 7 7 7]
[5 5 5 5 5 5 6 6 6 7 7 7 7 7 7]
[5 5 5 5 5 5 6 6 6 7 7 7 7 7 7]
[5 5 5 5 5 5 5 6 7 7 7 7 7 7 7]
[5 5 5 5 5 5 5 6 7 7 7 7 7 7 7]
[4 5 5 5 5 5 5 6 7 7 7 7 7 7 0]
[4 4 4 5 5 5 5 6 7 7 7 7 0 0 0]
[4 4 4 4 4 4 4 0 0 0 0 0 0 0 0]
[4 4 4 3 3 3 3 2 1 1 1 1 0 0 0]
[4 3 3 3 3 3 3 2 1 1 1 1 1 1 0]
[3 3 3 3 3 3 3 2 1 1 1 1 1 1 1]
[3 3 3 3 3 3 3 2 1 1 1 1 1 1 1]
[3 3 3 3 3 3 2 2 2 1 1 1 1 1 1]
[3 3 3 3 3 3 2 2 2 1 1 1 1 1 1]
[3 3 3 3 3 2 2 2 2 2 1 1 1 1 1]]
Here each point has a code which gives the direction to the nearest cell.
It should be possible to create a new marching algorithm which returns
the parent cell of each cell as you describe. Have a look at the
implementation of the extension velocity class. The virtual function
finalizePoint() is called when a point is frozen. In this function you
could assign the parent cell. The method does not track an explicit
parent cell but you could find one.
Thanks,
Jason
On Wed, Jun 15, 2016 at 4:57 AM, Wolfram Moebius <
w.mo...@tue.nl> wrote:
> Dear Jason,
>
> Thanks for your super quick reply!
>
>> 1) A speed of 0 results in a singularity (divide by zero) in the point
>> update. In the constructor of travel_time_marcher.h there is a check
>> that the speed in a cell is greater than the machine epsilon. If it is
>> less it masks that cell. Maybe we should update the documentation to
>> make this more clear.
> OK, so, yes, I could just set the speed to 0, but it will result in masking the cell. The cleaner version therefore is to mask the cells in phi. Is that what you are saying?
>
>> 2) The method does not calculate individual paths but you can
>> calculate those from the travel time field. Here is an example:
>>
https://github.com/scikit-fmm/scikit-fmm/wiki/optimal_path
>>
>> Lei Pan has recently been working on making this faster for
>> calculating many paths.
>>
>> Here is the mailing list thread:
>>
>>
https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/scikit-fmm/XvV_KhCUN5c/nrJSQasCIwAJ
>>
>> And here is his code:
>>
>>
https://github.com/panlei7/shortest_path
>>
>> We were/are considering adding fast path finding as a feature of
>> scikit-fmm. I stalled out on this discussion, I will ping Lei Pan and
>> cc you.
> Thanks! I looked into Lei Pan’s documents and wrote a little wrapper to apply your code from the wiki to my problem. It does work (at least it looks reasonable to me so far). However, after revisiting Dijkstra’s algorithm and the description of the FMM method, I’m left with the conceptual question of whether it wouldn’t be better to find the lines while computing the arrival time matrix. Although I like the idea of using the arrival time matrix and going back, it seems we are applying numerics to a problem already solved numerically. Lei Pan’s examples (to the extent I understand them at the moment) illustrate that this is not ideal.
>
> In the Dijkstra algorithm it shouldn’t be hard to find paths by some book keeping: For each node, when assigning an arrival time (tentative or final) also write down the node which is its parent. In addition to the arrival time matrix you then get a ‘parent matrix’. (I used this for the plot I mentioned in my last email). Is that not possible with FMM because we can’t identify a parent?
>
>> 3) I will have a look at the paper and let you know if I have any
>> ideas. It should be possible to define some set of approximately
>> fastest paths by introducing some randomness in the algorithm that
>> enumerates the paths. The algorithm looks at the gradient of the
>> travel time function and takes small steps in the down gradient
>> direction. You could perturb the down gradient direction slightly and
>> you would get a set of paths. You would have to be careful that the
>> path does not wander into the obstacles where the travel time gradient
>> is undefined.
> Thanks.
>
> Best regards from the Netherlands,
>
> Wolfram