VTK-路径规划

news/2024/11/23 0:38:49/

前言:本博文主要研究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;
}


http://www.ppmy.cn/news/9866.html

相关文章

多镜像 mirror , 实现自动切换仓库下载包

试了两项目发现可以&#xff0c;还有一个在看&#xff0c;也不知道是不是重复依赖太多导致编译不成功。。。 问题场景: 1.公司有内部搭建的nexus(私有maven库), 添加了 mirror 配置 1 2 3 4 5 <mirror> <id>yougou</id> <mirrorOf>*</mir…

Python基础(二十二):文件操作

文章目录 文件操作 一、文件操作的作用 二、文件的基本操作 1、文件操作步骤

(1分钟速览)SLAM问题中一般方程和超定方程的求解

今天在学习的过程中偶然看到了一个博客&#xff0c;总结Axb的&#xff0c;那么我也写一篇。首先就是判断A的秩和(A|b)的秩之间的关系&#xff0c;然后通过这个关系来进行进一步地判断。编辑切换为居中添加图片注释&#xff0c;不超过 140 字&#xff08;可选&#xff09;求解方…

优秀的 Verilog/FPGA开源项目介绍(三十六)-RISC-V(新增一)

关于RISC-V的二三事risc-v官网❝https://riscv.org/RISC-V&#xff08;跟我读&#xff1a;“risk----------------five”&#xff09;是一个基于精简指令集&#xff08;RISC&#xff09;原则的开源指令集架构&#xff08;ISA&#xff09;。这里要明确两个概念&#xff1a;指令集…

链表常见OJ题汇总(持续更新)

目录前言一、移除链表中的元素&#xff08;多指针法&#xff09;二、反转链表&#xff08;多指针法&头插法&#xff09;三、链表的中间结点&#xff08;算数法和双指针法&#xff09;四、链表中的第K个结点&#xff08;算数法&双指针法&#xff09;五、合并两个有序链表…

js实现纯前端压缩图片

演示 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>压缩图片</title> </head> <bo…

基于yolov5-v7.0开发构建裸土实例分割检测识别模型

yolov5在v7.0的版本中加入了对图像实例分割的全面支持&#xff0c;这里主要就是想基于v7.0的分支来开发构建裸土分割模型&#xff0c;其实在实际计算的时候模型是可以连带着检测任务一起输出结果的&#xff0c;这里我从结果形式上面直观来看应该就是在推理阶段直接基于分割的结…

TCP/IP协议

作者&#xff1a;~小明学编程 文章专栏&#xff1a;JavaEE 格言&#xff1a;热爱编程的&#xff0c;终将被编程所厚爱。 目录 应用层 XML json ​编辑 protobuffer 传输层 UDP的数据报文格式 TCP报文格式 TCP的可靠传输 确认应答&#xff08;安全机制&#xff09; …