Skip to content
Snippets Groups Projects
Commit 36e4df7f authored by Andrew Maclean's avatar Andrew Maclean
Browse files

Adding DijkstraGraphGeodesicPath, DirectedGraphToMutableDirectedGraph,

 MutableDirectedGraphToDirectedGraph, TreeToMutableDirectedGraph
parent beb2bf60
No related branches found
No related tags found
1 merge request!385C++ to python api 05
Pipeline #421602 canceled
......@@ -31,9 +31,9 @@ int main(int, char*[])
mdg->SetPoints(points);
std::cout << "MDG: " << std::endl;
std::cout << "Type: " << mdg->GetClassName() << std::endl;
std::cout << "Vertices: " << mdg->GetNumberOfVertices() << std::endl;
std::cout << "Edges: " << mdg->GetNumberOfEdges() << std::endl;
std::cout << " Type: " << mdg->GetClassName() << std::endl;
std::cout << " Vertices: " << mdg->GetNumberOfVertices() << std::endl;
std::cout << " Edges: " << mdg->GetNumberOfEdges() << std::endl;
vtkNew<vtkDirectedGraph> dg;
if (!dg->CheckedShallowCopy(mdg))
......@@ -43,9 +43,9 @@ int main(int, char*[])
}
std::cout << "DG: " << std::endl;
std::cout << "Type: " << dg->GetClassName() << std::endl;
std::cout << "Vertices: " << dg->GetNumberOfVertices() << std::endl;
std::cout << "Edges: " << dg->GetNumberOfEdges() << std::endl;
std::cout << " Type: " << dg->GetClassName() << std::endl;
std::cout << " Vertices: " << dg->GetNumberOfVertices() << std::endl;
std::cout << " Edges: " << dg->GetNumberOfEdges() << std::endl;
vtkNew<vtkMutableDirectedGraph> mdg2;
......@@ -56,9 +56,9 @@ int main(int, char*[])
}
std::cout << "MDG2: " << std::endl;
std::cout << "Type: " << mdg2->GetClassName() << std::endl;
std::cout << "Vertices: " << mdg2->GetNumberOfVertices() << std::endl;
std::cout << "Edges: " << mdg2->GetNumberOfEdges() << std::endl;
std::cout << " Type: " << mdg2->GetClassName() << std::endl;
std::cout << " Vertices: " << mdg2->GetNumberOfVertices() << std::endl;
std::cout << " Edges: " << mdg2->GetNumberOfEdges() << std::endl;
return EXIT_SUCCESS;
}
......@@ -31,9 +31,9 @@ int main(int, char*[])
mdg->SetPoints(points);
std::cout << "MDG: " << std::endl;
std::cout << "Type: " << mdg->GetClassName() << std::endl;
std::cout << "Vertices: " << mdg->GetNumberOfVertices() << std::endl;
std::cout << "Edges: " << mdg->GetNumberOfEdges() << std::endl;
std::cout << " Type: " << mdg->GetClassName() << std::endl;
std::cout << " Vertices: " << mdg->GetNumberOfVertices() << std::endl;
std::cout << " Edges: " << mdg->GetNumberOfEdges() << std::endl;
vtkNew<vtkDirectedGraph> dg;
if (!dg->CheckedShallowCopy(mdg))
......@@ -43,9 +43,9 @@ int main(int, char*[])
}
std::cout << "DG: " << std::endl;
std::cout << "Type: " << dg->GetClassName() << std::endl;
std::cout << "Vertices: " << dg->GetNumberOfVertices() << std::endl;
std::cout << "Edges: " << dg->GetNumberOfEdges() << std::endl;
std::cout << " Type: " << dg->GetClassName() << std::endl;
std::cout << " Vertices: " << dg->GetNumberOfVertices() << std::endl;
std::cout << " Edges: " << dg->GetNumberOfEdges() << std::endl;
return EXIT_SUCCESS;
}
......@@ -5,55 +5,63 @@
int main(int, char*[])
{
// vtkTree is a read-only data structure. To construct a tree, create an instance
// of vtkMutableDirectedGraph. Add vertices and edges with AddVertex() and AddEdge().
// After building the tree, call tree->CheckedShallowCopy(graph) to copy the structure
// into a vtkTree.
// create a graph
// Create a graph.
vtkNew<vtkMutableDirectedGraph> mdg;
// add 4 vertices to the graph
// Add 4 vertices to the graph.
vtkIdType v1 = mdg->AddVertex();
vtkIdType v2 = mdg->AddVertex();
vtkIdType v3 = mdg->AddVertex();
vtkIdType v4 = mdg->AddVertex();
// add 3 edges to the graph
// Add 3 edges to the graph.
mdg->AddEdge(v1, v2);
mdg->AddEdge(v1, v3);
mdg->AddEdge(v1, v4);
// create 4 points - one for each vertex
// Create 4 points - one for each vertex.
vtkNew<vtkPoints> points;
points->InsertNextPoint(0.0, 0.0, 0.0);
points->InsertNextPoint(1.0, 0.0, 0.0);
points->InsertNextPoint(0.0, 1.0, 0.0);
points->InsertNextPoint(0.0, 0.0, 2.0);
// add the coordinates of the points to the graph
// Add the coordinates of the points to the graph.
mdg->SetPoints(points);
std::cout << "MDG: " << std::endl;
std::cout << "Type: " << mdg->GetClassName() << std::endl;
std::cout << "Vertices: " << mdg->GetNumberOfVertices() << std::endl;
std::cout << "Edges: " << mdg->GetNumberOfEdges() << std::endl;
std::cout << " Type: " << mdg->GetClassName() << std::endl;
std::cout << " Vertices: " << mdg->GetNumberOfVertices() << std::endl;
std::cout << " Edges: " << mdg->GetNumberOfEdges() << std::endl;
vtkNew<vtkTree> tree;
tree->CheckedShallowCopy(mdg);
if (!tree->CheckedShallowCopy(mdg))
{
std::cerr << "Could not convert graph to tree!" << std::endl;
return EXIT_FAILURE;
}
std::cout << "Tree: " << std::endl;
std::cout << "Type: " << tree->GetClassName() << std::endl;
std::cout << "Vertices: " << tree->GetNumberOfVertices() << std::endl;
std::cout << "Edges: " << tree->GetNumberOfEdges() << std::endl;
std::cout << " Type: " << tree->GetClassName() << std::endl;
std::cout << " Vertices: " << tree->GetNumberOfVertices() << std::endl;
std::cout << " Edges: " << tree->GetNumberOfEdges() << std::endl;
vtkNew<vtkMutableDirectedGraph> mdg2;
if (!mdg2->CheckedShallowCopy(tree))
{
std::cerr << "Could not convert!" << std::endl;
std::cerr << "Could not convert tree to mutable directed graph!" << std::endl;
return EXIT_FAILURE;
}
std::cout << "MDG2: " << std::endl;
std::cout << "Type: " << mdg2->GetClassName() << std::endl;
std::cout << "Vertices: " << mdg2->GetNumberOfVertices() << std::endl;
std::cout << "Edges: " << mdg2->GetNumberOfEdges() << std::endl;
std::cout << " Type: " << mdg2->GetClassName() << std::endl;
std::cout << " Vertices: " << mdg2->GetNumberOfVertices() << std::endl;
std::cout << " Edges: " << mdg2->GetNumberOfEdges() << std::endl;
return EXIT_SUCCESS;
}
......@@ -246,6 +246,7 @@ This section includes examples of manipulating meshes.
[ClosedSurface](/PythonicAPI/PolyData/ClosedSurface) | Check if a surface is closed.
[DeformPointSet](/PythonicAPI/Meshes/DeformPointSet) | Use the vtkDeformPointSet filter to deform a vtkSphereSource with arbitrary polydata.
[DelaunayMesh](/PythonicAPI/Modelling/DelaunayMesh) | Two-dimensional Delaunay triangulation of a random set of points. Points and edges are shown highlighted with sphere glyphs and tubes.
[DijkstraGraphGeodesicPath](/PythonicAPI/PolyData/DijkstraGraphGeodesicPath) | Find the shortest path between two points on a mesh.
[FitToHeightMap](/PythonicAPI/Meshes/FitToHeightMap) | Drape a polydata over an elevation map.
[PointInterpolator](/PythonicAPI/Meshes/PointInterpolator) | Plot a scalar field of points onto a PolyData surface.
......@@ -380,6 +381,12 @@ This section includes ?vtkUnstructuredGrid?.
### Graph Conversions
| Example Name | Description | Image |
| -------------- | ------------- | ------- |
[DirectedGraphToMutableDirectedGraph](/PythonicAPI/Graphs/DirectedGraphToMutableDirectedGraph) | vtkDirectedGraph to vtkMutableDirectedGraph.
[MutableDirectedGraphToDirectedGraph](/PythonicAPI/Graphs/MutableDirectedGraphToDirectedGraph) | vtkMutableDirectedGraph to vtkDirectedGraph.
[TreeToMutableDirectedGraph](/PythonicAPI/Graphs/TreeToMutableDirectedGraph) | vtkTree to vtkMutableDirectedGraph
## Data Structures
| Example Name | Description | Image |
......
#!/usr/bin/env python3
# noinspection PyUnresolvedReferences
import vtkmodules.vtkInteractionStyle
# noinspection PyUnresolvedReferences
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkCommonCore import vtkPoints
from vtkmodules.vtkCommonDataModel import (
vtkDirectedGraph,
vtkMutableDirectedGraph
)
def main():
# vtkDirectedGraph is a collection of vertices along with a collection of
# directed edges n(edges that have a source and target). ShallowCopy() and
# DeepCopy() (and CheckedShallowCopy(), CheckedDeepCopy()) accept instances
# of vtkTree and vtkMutableDirectedGraph. vtkDirectedGraph is read-only.
# Create a graph.
mdg = vtkMutableDirectedGraph()
# Add 4 vertices to the graph.
v1 = mdg.AddVertex()
v2 = mdg.AddVertex()
v3 = mdg.AddVertex()
v4 = mdg.AddVertex()
# Add 3 edges to the graph.
mdg.AddEdge(v1, v2)
mdg.AddEdge(v1, v3)
mdg.AddEdge(v1, v4)
# Create 4 points - one for each vertex.
points = vtkPoints()
points.InsertNextPoint(0.0, 0.0, 0.0)
points.InsertNextPoint(1.0, 0.0, 0.0)
points.InsertNextPoint(0.0, 1.0, 0.0)
points.InsertNextPoint(0.0, 0.0, 2.0)
# Add the coordinates of the points to the graph.
mdg.SetPoints(points)
print(
f'MDG:\n Type: {mdg.GetClassName()}\n Vertices: {mdg.GetNumberOfVertices()}\n Edges: {mdg.GetNumberOfEdges()}')
dg = vtkDirectedGraph()
if not dg.CheckedShallowCopy(mdg):
print('Could not convert mutable directed graph to directed graph!')
return
print(f'DG:\n Type: {dg.GetClassName()}\n Vertices: {dg.GetNumberOfVertices()}\n Edges: {dg.GetNumberOfEdges()}')
mdg2 = vtkMutableDirectedGraph()
if not mdg2.CheckedShallowCopy(mdg):
print('Could not convert directed graph to mutable directed graph!')
return
print(
f'MDG2:\n Type: {mdg2.GetClassName()}\n Vertices: {mdg2.GetNumberOfVertices()}\n Edges: {mdg2.GetNumberOfEdges()}')
if __name__ == '__main__':
main()
#!/usr/bin/env python3
# noinspection PyUnresolvedReferences
import vtkmodules.vtkInteractionStyle
# noinspection PyUnresolvedReferences
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkCommonCore import vtkPoints
from vtkmodules.vtkCommonDataModel import (
vtkDirectedGraph,
vtkMutableDirectedGraph
)
def main():
# vtkDirectedGraph is a collection of vertices along with a collection of
# directed edges n(edges that have a source and target). ShallowCopy() and
# DeepCopy() (and CheckedShallowCopy(), CheckedDeepCopy()) accept instances
# of vtkTree and vtkMutableDirectedGraph. vtkDirectedGraph is read-only.
# Create a graph.
mdg = vtkMutableDirectedGraph()
# Add 4 vertices to the graph.
v1 = mdg.AddVertex()
v2 = mdg.AddVertex()
v3 = mdg.AddVertex()
v4 = mdg.AddVertex()
# Add 3 edges to the graph.
mdg.AddEdge(v1, v2)
mdg.AddEdge(v1, v3)
mdg.AddEdge(v1, v4)
# Create 4 points - one for each vertex.
points = vtkPoints()
points.InsertNextPoint(0.0, 0.0, 0.0)
points.InsertNextPoint(1.0, 0.0, 0.0)
points.InsertNextPoint(0.0, 1.0, 0.0)
points.InsertNextPoint(0.0, 0.0, 2.0)
# Add the coordinates of the points to the graph.
mdg.points = points
print(
f'MDG:\n Type: {mdg.GetClassName()}\n Vertices: {mdg.GetNumberOfVertices()}\n Edges: {mdg.GetNumberOfEdges()}')
dg = vtkDirectedGraph()
if not dg.CheckedShallowCopy(mdg):
print('Could not convert mutable directed graph to directed graph!')
return
print(f'DG:\n Type: {dg.GetClassName()}\n Vertices: {dg.GetNumberOfVertices()}\n Edges: {dg.GetNumberOfEdges()}')
if __name__ == '__main__':
main()
#!/usr/bin/env python3
# noinspection PyUnresolvedReferences
import vtkmodules.vtkInteractionStyle
# noinspection PyUnresolvedReferences
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkCommonCore import vtkPoints
from vtkmodules.vtkCommonDataModel import (
vtkMutableDirectedGraph, vtkTree
)
def main():
# vtkTree is a read-only data structure. To construct a tree, create an
# instance of vtkMutableDirectedGraph. Add vertices and edges with
# AddVertex() and AddEdge(). After building the tree, call
# tree->CheckedShallowCopy(graph) to copy the structure into a vtkTree.
# Create a graph.
mdg = vtkMutableDirectedGraph()
# Add 4 vertices to the graph.
v1 = mdg.AddVertex()
v2 = mdg.AddVertex()
v3 = mdg.AddVertex()
v4 = mdg.AddVertex()
# Add 3 edges to the graph.
mdg.AddEdge(v1, v2)
mdg.AddEdge(v1, v3)
mdg.AddEdge(v1, v4)
# Create 4 points - one for each vertex.
points = vtkPoints()
points.InsertNextPoint(0.0, 0.0, 0.0)
points.InsertNextPoint(1.0, 0.0, 0.0)
points.InsertNextPoint(0.0, 1.0, 0.0)
points.InsertNextPoint(0.0, 0.0, 1.0)
# Add the coordinates of the points to the graph.
mdg.points = points
print(
f'MDG:\n Type: {mdg.GetClassName()}\n Vertices: {mdg.GetNumberOfVertices()}\n Edges: {mdg.GetNumberOfEdges()}')
tree = vtkTree()
if not tree.CheckedShallowCopy(mdg):
print('Could not convert graph to tree!')
return
print(
f'TREE:\n Type: {tree.GetClassName()}\n Vertices: {tree.GetNumberOfVertices()}\n Edges: {tree.GetNumberOfEdges()}')
mdg2 = vtkMutableDirectedGraph()
if not mdg2.CheckedShallowCopy(tree):
print('Could not convert tree to mutable directed graph!')
return
print(
f'MDG2:\n Type: {mdg2.GetClassName()}\n Vertices: {mdg2.GetNumberOfVertices()}\n Edges: {mdg2.GetNumberOfEdges()}')
if __name__ == '__main__':
main()
#!/usr/bin/env python3
# noinspection PyUnresolvedReferences
import vtkmodules.vtkInteractionStyle
# noinspection PyUnresolvedReferences
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkFiltersModeling import vtkDijkstraGraphGeodesicPath
from vtkmodules.vtkFiltersSources import vtkSphereSource
from vtkmodules.vtkRenderingCore import (
vtkActor,
vtkPolyDataMapper,
vtkRenderer,
vtkRenderWindow,
vtkRenderWindowInteractor
)
def main():
colors = vtkNamedColors()
# Create a sphere.
sphere_source = vtkSphereSource()
dijkstra = vtkDijkstraGraphGeodesicPath(start_vertex=0, end_vertex=7)
# Create a mapper and actor.
path_mapper = vtkPolyDataMapper()
sphere_source >> dijkstra >> path_mapper
path_actor = vtkActor(mapper=path_mapper)
path_actor.property.color = colors.GetColor3d('HotPink')
path_actor.property.line_width = 4
# Create a mapper and actor.
mapper = vtkPolyDataMapper()
sphere_source >> mapper
actor = vtkActor(mapper=mapper)
actor.property.color = colors.GetColor3d('MistyRose')
# Create a renderer, render window, and interactor.
renderer = vtkRenderer(background=colors.GetColor3d('MidnightBlue'))
render_window = vtkRenderWindow(window_name='DijkstraGraphGeodesicPath')
render_window.AddRenderer(renderer)
render_window_interactor = vtkRenderWindowInteractor()
render_window_interactor.render_window = render_window
# Add the actors to the scene.
renderer.AddActor(actor)
renderer.AddActor(path_actor)
camera = renderer.active_camera
camera.position = (2.9, -1.6, 0.3)
camera.focal_point = (0, 0, 0)
camera.view_up = (0, 0, 1)
camera.distance = 3
camera.Zoom(1.5)
# Render and interact.
render_window.Render()
render_window_interactor.Start()
if __name__ == '__main__':
main()
src/Testing/Baseline/PythonicAPI/PolyData/TestDijkstraGraphGeodesicPath.png

130 B

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment