前言:本博文主要研究VTK中路径规划相关的内容,后期会持续更新路径规划相关的拓展应用,希望能给各位小伙伴一些帮助,也希望小伙伴们多多关注支持。
vtkGraphGeodesicPath
位置:..\Filter\Modeling
描述:路径计算的基类,继承于vtkGeodesicPath(vtk中用在多边形数据集上跟踪测量路径算法的基类)。定义了两个输入变量,起始点和终止点。
vtkDijkstraGraphGeodesicPath
描述:继承自vtkGraphGeodesicPath。
以多边形网格作为输入,采用Dijkstra算法计算最短路径。该实现类似于Thomas H. Cormen、Charles E. Leiserson、Ronald L. Rivest和Cliff Stein在《算法导论(第二版)》中描述的,由MIT出版社和mcgraww - hill出版。不过添加了一些小的增强。在开始时,所有顶点都不会被推到堆上,而是维护一个前端集合。堆被实现为二进制堆。过滤器的输出是一组描述从StartVertex到EndVertex的最短路径。如果无法找到路径,则输出将没有线或点。
参数设置:
StopWhenEndReached; 设为True时,表示到达结束顶点时停止;否则计算到所有顶点的最短路径。(默认为FALSE)
UseScalarWeights; 设为True时,表示考虑边界的权重;否则所有边界的权重一致。
RepelPathFromVertices待研究
应用实例1
#include <vtkSphereSource.h>
#include <vtkProperty.h>
#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkDijkstraGraphGeodesicPath.h>int main(int , char *[])
{ // Create a spherevtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New();sphereSource->Update();vtkSmartPointer<vtkDijkstraGraphGeodesicPath> dijkstra = vtkSmartPointer<vtkDijkstraGraphGeodesicPath>::New();dijkstra->SetInputConnection(sphereSource->GetOutputPort());dijkstra->SetStartVertex(0);dijkstra->SetEndVertex(10);dijkstra->Update();// Create a mapper and actorvtkSmartPointer<vtkPolyDataMapper> pathMapper = vtkSmartPointer<vtkPolyDataMapper>::New();pathMapper->SetInputConnection(dijkstra->GetOutputPort());vtkSmartPointer<vtkActor> pathActor = vtkSmartPointer<vtkActor>::New();pathActor->SetMapper(pathMapper);pathActor->GetProperty()->SetColor(1,0,0); // RedpathActor->GetProperty()->SetLineWidth(4);// Create a mapper and actorvtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();mapper->SetInputConnection(sphereSource->GetOutputPort());vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();actor->SetMapper(mapper);//Create a renderer, render window, and interactorvtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();renderWindow->AddRenderer(renderer);vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();renderWindowInteractor->SetRenderWindow(renderWindow);//Add the actor to the scenerenderer->AddActor(actor);renderer->AddActor(pathActor);renderer->SetBackground(.3, .6, .3); // Background color green//Render and interactrenderWindow->Render();renderWindowInteractor->Start();return EXIT_SUCCESS;
}
应用实例2
#include <vtkSmartPointer.h>
#include <vtkTree.h>
#include <vtkMutableDirectedGraph.h>
#include <vtkGraphLayoutView.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkGraphToPolyData.h>
#include <vtkProperty.h>
#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkDijkstraGraphGeodesicPath.h>/*O v0/|\
5/ |5\5
v1-v2-v3 1 1Shortest path between v0 and v2 should be 5
*/int main ( int argc, char *argv[] )
{vtkSmartPointer<vtkMutableDirectedGraph> graph = vtkSmartPointer<vtkMutableDirectedGraph>::New();vtkIdType v0 = graph->AddVertex();vtkIdType v1 = graph->AddVertex();vtkIdType v2 = graph->AddVertex();vtkIdType v3 = graph->AddVertex();graph->AddEdge ( v0, v1 );graph->AddEdge ( v0, v2 );graph->AddEdge ( v0, v3 );graph->AddEdge ( v1, v2 );graph->AddEdge ( v2, v3 );// Associate physical locations with the verticesvtkSmartPointer<vtkPoints> points =vtkSmartPointer<vtkPoints>::New();points->InsertNextPoint(0.0, 0.0, 0.0);points->InsertNextPoint(-1.0, -5.0, 0.0);points->InsertNextPoint(0.0, -5.0, 0.0);points->InsertNextPoint(1.0, -5.0, 0.0);graph->SetPoints(points);// Convert the graph to a polydatavtkSmartPointer<vtkGraphToPolyData> graphToPolyData = vtkSmartPointer<vtkGraphToPolyData>::New();graphToPolyData->SetInput(graph);graphToPolyData->Update();vtkSmartPointer<vtkDijkstraGraphGeodesicPath> dijkstra = vtkSmartPointer<vtkDijkstraGraphGeodesicPath>::New();dijkstra->SetInputConnection(graphToPolyData->GetOutputPort());dijkstra->SetStartVertex(0);dijkstra->SetEndVertex(2);dijkstra->Update();// Create a mapper and actorvtkSmartPointer<vtkPolyDataMapper> pathMapper = vtkSmartPointer<vtkPolyDataMapper>::New();pathMapper->SetInputConnection(dijkstra->GetOutputPort());vtkSmartPointer<vtkActor> pathActor = vtkSmartPointer<vtkActor>::New();pathActor->SetMapper(pathMapper);pathActor->GetProperty()->SetColor(1,0,0); // RedpathActor->GetProperty()->SetLineWidth(4);// Create a mapper and actorvtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();mapper->SetInputConnection(graphToPolyData->GetOutputPort());vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();actor->SetMapper(mapper);// Create a renderer, render window, and interactorvtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();renderWindow->AddRenderer(renderer);vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();renderWindowInteractor->SetRenderWindow(renderWindow);// Add the actor to the scenerenderer->AddActor(actor);renderer->AddActor(pathActor);renderer->SetBackground(.3, .6, .3); // Background color green// Render and interactrenderWindow->Render();renderWindowInteractor->Start();return EXIT_SUCCESS;
}