[vtkusers] about vtkDijkstraGraphGeodesicPath

kenichiro yoshimi rccm.kyoshimi at gmail.com
Fri Oct 20 01:29:52 EDT 2017


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()
>


More information about the vtkusers mailing list