Skip to content

Commit

Permalink
Add use_scalar_weights argument (#3189)
Browse files Browse the repository at this point in the history
* Add use_scalar_weights argument

* Fix discussion_r950690400

* Add conditional skip and improve docs

* Fix docs

Co-authored-by: Alex Kaszynski <akascap@gmail.com>
Co-authored-by: Bane Sullivan <banesullivan@gmail.com>
Co-authored-by: Bane Sullivan <bane.sullivan@kitware.com>
  • Loading branch information
4 people committed Nov 21, 2022
1 parent 6c0f206 commit 78f2a82
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
24 changes: 21 additions & 3 deletions pyvista/core/filters/poly_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1835,7 +1835,13 @@ def clean(
return output

def geodesic(
self, start_vertex, end_vertex, inplace=False, keep_order=True, progress_bar=False
self,
start_vertex,
end_vertex,
inplace=False,
keep_order=True,
use_scalar_weights=False,
progress_bar=False,
):
"""Calculate the geodesic path between two vertices using Dijkstra's algorithm.
Expand Down Expand Up @@ -1863,6 +1869,10 @@ def geodesic(
.. versionadded:: 0.32.0
use_scalar_weights : bool, optional
If ``True``, use scalar values in the edge weight (only
supported with VTK>=9). This only works for point data.
progress_bar : bool, optional
Display a progress bar to indicate progress.
Expand Down Expand Up @@ -1898,6 +1908,8 @@ def geodesic(
dijkstra.SetInputData(self)
dijkstra.SetStartVertex(start_vertex)
dijkstra.SetEndVertex(end_vertex)
if _vtk.VTK9:
dijkstra.SetUseScalarWeights(use_scalar_weights)
_update_alg(dijkstra, progress_bar, 'Calculating the Geodesic Path')
original_ids = vtk_id_list_to_array(dijkstra.GetIdList())

Expand All @@ -1924,7 +1936,9 @@ def geodesic(

return output

def geodesic_distance(self, start_vertex, end_vertex, progress_bar=False):
def geodesic_distance(
self, start_vertex, end_vertex, use_scalar_weights=False, progress_bar=False
):
"""Calculate the geodesic distance between two vertices using Dijkstra's algorithm.
Parameters
Expand All @@ -1935,6 +1949,10 @@ def geodesic_distance(self, start_vertex, end_vertex, progress_bar=False):
end_vertex : int
Vertex index indicating the end point of the geodesic segment.
use_scalar_weights : bool, optional
If ``True``, use scalar values in the edge weight (only
supported with VTK>=9). This only works for point data.
progress_bar : bool, optional
Display a progress bar to indicate progress.
Expand All @@ -1954,7 +1972,7 @@ def geodesic_distance(self, start_vertex, end_vertex, progress_bar=False):
See :ref:`geodesic_example` for more examples using this filter.
"""
path = self.geodesic(start_vertex, end_vertex)
path = self.geodesic(start_vertex, end_vertex, use_scalar_weights=use_scalar_weights)
sizes = path.compute_cell_sizes(
length=True, area=False, volume=False, progress_bar=progress_bar
)
Expand Down
7 changes: 7 additions & 0 deletions tests/test_polydata.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ def test_geodesic_distance(sphere):
distance = sphere.geodesic_distance(0, sphere.n_points - 1)
assert isinstance(distance, float)

# Use scalar weights
if pyvista.vtk_version_info >= (9,):
distance_use_scalar_weights = sphere.geodesic_distance(
0, sphere.n_points - 1, use_scalar_weights=True
)
assert isinstance(distance_use_scalar_weights, float)


def test_ray_trace(sphere):
points, ind = sphere.ray_trace([0, 0, 0], [1, 1, 1])
Expand Down

0 comments on commit 78f2a82

Please sign in to comment.