开发环境:
- Windows 11 家庭中文版
- Microsoft Visual Studio Community 2019
- VTK-9.3.0.rc0
- vtk-example
demo解决问题: 1.绘制一条多段线(折现),并可视化这段折现;2.根据折现绘制一个不规则柱体
关键点 :文章来源:https://www.toymoban.com/news/detail-824492.html
- vtkRotationalExtrusionFilter是Visualization Toolkit(VTK)中的一个过滤器,用于沿着输入曲线生成旋转挤出的几何体。这个过滤器可以用于创建旋转对称的几何体,例如圆柱体或圆锥体。您可以通过指定旋转轴、旋转角度和其他参数来控制生成的几何体的外观。
- vtkTubeFilter是Visualization Toolkit(VTK)中的一个过滤器,用于创建沿着输入曲线生成的圆柱体表示。这种表示通常用于可视化线数据,可以使线条更易于观察和分析。vtkTubeFilter还允许您指定圆柱体的半径、分段数和其他属性,以便根据需要调整外观。
prj name: Bottle文章来源地址https://www.toymoban.com/news/detail-824492.html
#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkCellArray.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkRotationalExtrusionFilter.h>
#include <vtkStripper.h>
#include <vtkTubeFilter.h>
int main(int, char*[])
{
// Create the RenderWindow, Renderer and both Actors
//
vtkNew<vtkNamedColors> colors;
vtkNew<vtkRenderer> renderer;
vtkNew<vtkRenderWindow> renWin;
renWin->AddRenderer(renderer);
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renWin);
// create bottle profile
//
vtkNew<vtkPoints> points;
points->InsertPoint(0, 0.01, 0.0, 0.0);
points->InsertPoint(1, 1.5, 0.0, 0.0);
points->InsertPoint(2, 1.5, 0.0, 3.5);
points->InsertPoint(3, 1.25, 0.0, 3.75);
points->InsertPoint(4, 0.75, 0.0, 4.00);
points->InsertPoint(5, 0.6, 0.0, 4.35);
points->InsertPoint(6, 0.7, 0.0, 4.65);
points->InsertPoint(7, 1.0, 0.0, 4.75);
points->InsertPoint(8, 1.0, 0.0, 5.0);
points->InsertPoint(9, 0.2, 0.0, 5.0);
vtkNew<vtkCellArray> lines;
lines->InsertNextCell(10); // number of points
lines->InsertCellPoint(0);
lines->InsertCellPoint(1);
lines->InsertCellPoint(2);
lines->InsertCellPoint(3);
lines->InsertCellPoint(4);
lines->InsertCellPoint(5);
lines->InsertCellPoint(6);
lines->InsertCellPoint(7);
lines->InsertCellPoint(8);
lines->InsertCellPoint(9);
vtkNew<vtkPolyData> profile;
profile->SetPoints(points);
profile->SetLines(lines);
// extrude profile to make bottle
//vtkRotationalExtrusionFilter是Visualization Toolkit(VTK)中的一个过滤器,用于沿着输入曲线生成旋转挤出的几何体。
//这个过滤器可以用于创建旋转对称的几何体,例如圆柱体或圆锥体。您可以通过指定旋转轴、旋转角度和其他参数来控制生成的几何体的外观。
vtkNew<vtkRotationalExtrusionFilter> extrude;
extrude->SetInputData(profile);
extrude->SetResolution(60);
vtkNew<vtkPolyDataMapper> map;
map->SetInputConnection(extrude->GetOutputPort());
vtkNew<vtkActor> bottle;
bottle->SetMapper(map);
bottle->GetProperty()->SetColor(colors->GetColor3d("Mint").GetData());
// display the profile
vtkNew<vtkStripper> stripper;
stripper->SetInputData(profile);
//vtkTubeFilter是Visualization Toolkit(VTK)中的一个过滤器,用于创建沿着输入曲线生成的圆柱体表示。
//这种表示通常用于可视化线数据,可以使线条更易于观察和分析。vtkTubeFilter还允许您指定圆柱体的半径、分段数和其他属性,以便根据需要调整外观。
vtkNew<vtkTubeFilter> tubes;
tubes->SetInputConnection(stripper->GetOutputPort());
tubes->SetNumberOfSides(11);
tubes->SetRadius(0.05);
vtkNew<vtkPolyDataMapper> profileMapper;
profileMapper->SetInputConnection(tubes->GetOutputPort());
vtkNew<vtkActor> profileActor;
profileActor->SetMapper(profileMapper);
profileActor->GetProperty()->SetColor(colors->GetColor3d("Tomato").GetData());
// Add the actors to the renderer, set the background and size
//
renderer->AddActor(bottle);
renderer->AddActor(profileActor);
renderer->SetBackground(colors->GetColor3d("Burlywood").GetData());
renWin->SetSize(640, 480);
renWin->SetWindowName("Bottle");
renWin->Render();
renderer->GetActiveCamera()->SetPosition(1, 0, 0);
renderer->GetActiveCamera()->SetFocalPoint(0, 0, 0);
renderer->GetActiveCamera()->SetViewUp(0, 0, 1);
renderer->ResetCamera();
renderer->GetActiveCamera()->Azimuth(30);
renderer->GetActiveCamera()->Elevation(30);
// render the image
//
iren->Start();
return EXIT_SUCCESS;
}
到了这里,关于折线的可视化及不规则柱体的绘制的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!