折线的可视化及不规则柱体的绘制


开发环境:

  1. Windows 11 家庭中文版
  2. Microsoft Visual Studio Community 2019
  3. VTK-9.3.0.rc0
  4. vtk-example

demo解决问题: 1.绘制一条多段线(折现),并可视化这段折现;2.根据折现绘制一个不规则柱体

在这里插入图片描述

关键点 :

  1. vtkRotationalExtrusionFilter是Visualization Toolkit(VTK)中的一个过滤器,用于沿着输入曲线生成旋转挤出的几何体。这个过滤器可以用于创建旋转对称的几何体,例如圆柱体或圆锥体。您可以通过指定旋转轴、旋转角度和其他参数来控制生成的几何体的外观。
  2. vtkTubeFilter是Visualization Toolkit(VTK)中的一个过滤器,用于创建沿着输入曲线生成的圆柱体表示。这种表示通常用于可视化线数据,可以使线条更易于观察和分析。vtkTubeFilter还允许您指定圆柱体的半径、分段数和其他属性,以便根据需要调整外观。

prj name: Bottle

#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值