[vtkusers] about vtkDijkstraGraphGeodesicPath

Frédéric BRIEND briend at cyceron.fr
Fri Oct 20 09:57:44 EDT 2017


Thanks Yoshimi, really.

All your advice are very useful.

Best,


Le 20/10/2017 à 07:29, kenichiro yoshimi a écrit :
> Hello Frederic,
>
> vtkSCurveSpline seems to be capable of calculating the coordinate at
> the midpoint of the geodesic path by an interpolating spline.
>
> ---
> import vtk
> import math
>
> cylinder= vtk.vtkSphereSource()
> cylinder.SetCenter(0.0, 0.0, 0.0)
> cylinder.SetRadius(0.5)
>
> points = vtk.vtkPoints()
>
> vIds = [4, 12, 23, 28]
>
> p0 = [0]*3
> p1 = [0]*3
> dist = 0.0
> for n in range(len(vIds)-1):
>     v0 = vIds[n]
>     v1 = vIds[n+1]
>
>     dijkstra = vtk.vtkDijkstraGraphGeodesicPath()
>     dijkstra.SetInputConnection(cylinder.GetOutputPort())
>     dijkstra.SetStartVertex(v0)
>     dijkstra.SetEndVertex(v1)
>     dijkstra.Update()
>
>     pts = dijkstra.GetOutput().GetPoints()
>     end = n<len(vIds)-2 and 0 or -1
>     for ptId in range(pts.GetNumberOfPoints()-1, end, -1):
>       pts.GetPoint(ptId, p0)
>       points.InsertNextPoint(p0)
>
>     for ptId in range(pts.GetNumberOfPoints()-1):
>       pts.GetPoint(ptId, p0)
>       pts.GetPoint(ptId+1, p1)
>       #print(math.sqrt(vtk.vtkMath.Distance2BetweenPoints(p0, p1)))
>       dist += math.sqrt(vtk.vtkMath.Distance2BetweenPoints(p0, p1))
>
> print('length: ' + str(dist))
>
> xSpline = vtk.vtkSCurveSpline()
> ySpline = vtk.vtkSCurveSpline()
> zSpline = vtk.vtkSCurveSpline()
>
> spline = vtk.vtkParametricSpline()
> spline.ParameterizeByLengthOn()
> spline.SetXSpline(xSpline)
> spline.SetYSpline(ySpline)
> spline.SetZSpline(zSpline)
> spline.SetPoints(points)
>
> functionSource = vtk.vtkParametricFunctionSource()
> functionSource.SetParametricFunction(spline)
> functionSource.Update()
>
> u = [0.5,0,0]
> midpoint = [0]*3
> du = [0]*9
> spline.Evaluate(u, midpoint, du)
> print('midpoint: ')
> print(midpoint)
> ---
>
> Thanks
>
> 2017-10-20 0:42 GMT+09:00 Frédéric BRIEND <briend at cyceron.fr>:
>> Last question Yoshimi (or others),
>>
>> With your script*, is-there a way to extract the point (in x,y,z or vertex
>> value) where dist/2 (the half of the total geodesic distance)?
>>
>> Thanks for your kindness,
>>
>> Frederic
>>
>> *
>>
>>
>> import vtk
>> import math
>>
>> cylinder= vtk.vtkSphereSource()
>> cylinder.SetCenter(0.0, 0.0, 0.0)
>> cylinder.SetRadius(0.5)
>>
>> appendFilter = vtk.vtkAppendFilter()
>> appendFilter.MergePointsOn()
>>
>> vIds = [4, 12, 23, 28]
>>
>> p0 = [0,0,0]
>> p1 = [0,0,0]
>> dist = 0.0
>> for n in range(len(vIds)-1):
>>    v0 = vIds[n]
>>    v1 = vIds[n+1]
>>
>>    dijkstra = vtk.vtkDijkstraGraphGeodesicPath()
>>    dijkstra.SetInputConnection(cylinder.GetOutputPort())
>>    dijkstra.SetStartVertex(v0)
>>    dijkstra.SetEndVertex(v1)
>>    dijkstra.Update()
>>
>>    pts = dijkstra.GetOutput().GetPoints()
>>    for ptId in range(pts.GetNumberOfPoints()-1):
>>      pts.GetPoint(ptId, p0)
>>      pts.GetPoint(ptId+1, p1)
>>      print(math.sqrt(vtk.vtkMath.Distance2BetweenPoints(p0, p1)))
>>      dist += math.sqrt(vtk.vtkMath.Distance2BetweenPoints(p0, p1))
>>
>>    appendFilter.AddInputConnection(dijkstra.GetOutput())
>>
>> print(dist)
>>
>> appendFilter.Update()
>>

-- 

FredericBriend

PhD Candidate

Université de Caen Normandie

Laboratoire Imagerie et Stratégies Thérapeutiques de la Schizophrénie 
(ISTS, EA 7466)

GIP CYCERON, Caen 14000, France

Tel +33 2 31 47 01 56

Email : briend at cyceron.fr <http://www.ists.cyceron.fr/>

http://www.ists.cyceron.fr/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20171020/3cb7e170/attachment.html>


More information about the vtkusers mailing list