PolygonalSurfaceContourLineInterpolator 多边形交互器

1. 效果:

2.简介:

可以实现在多边形上进行交互,选择;在多边形曲面上实现轮廓点的交互绘制。

该类的使用需要结合 vtkPolygonalSurfacePointPlacer 类,定位点的功能也就是拾取器。

前提:输入的多边形曲面需要计算法向量。

3.源码:

复制代码
#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkContourWidget.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkOrientedGlyphContourRepresentation.h>
#include <vtkPolyData.h>
#include <vtkPolyDataCollection.h>
#include <vtkPolyDataMapper.h>
#include <vtkPolygonalSurfaceContourLineInterpolator.h>
#include <vtkPolygonalSurfacePointPlacer.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkTriangleFilter.h>
#include <vtkXMLPolyDataReader.h>

int main(int argc, char* argv[])
{
  vtkNew<vtkNamedColors> colors;

  vtkSmartPointer<vtkPolyData> polyData;
  if (argc < 2)
  {
    vtkNew<vtkSphereSource> sphereSource;
    sphereSource->SetThetaResolution(40);
    sphereSource->SetPhiResolution(20);
    sphereSource->Update();

    polyData = sphereSource->GetOutput();
  }
  else
  {
    vtkNew<vtkXMLPolyDataReader> reader;
    reader->SetFileName(argv[1]);
    reader->Update();
    polyData = reader->GetOutput();
  }

  // The Dijkistra interpolator will not accept cells that aren't triangles.
  vtkNew<vtkTriangleFilter> triangleFilter;
  triangleFilter->SetInputData(polyData);
  triangleFilter->Update();

  auto pd = triangleFilter->GetOutput();

  // Create a mapper and actor.
  vtkNew<vtkPolyDataMapper> mapper;
  mapper->SetInputConnection(triangleFilter->GetOutputPort());

  vtkNew<vtkActor> actor;
  actor->SetMapper(mapper);
  actor->GetProperty()->SetInterpolationToFlat();
  actor->GetProperty()->SetColor(colors->GetColor3d("MistyRose").GetData());

  // Create the render window, renderer and interactor.

  vtkNew<vtkRenderer> renderer;
  vtkNew<vtkRenderWindow> renderWindow;
  renderWindow->AddRenderer(renderer);
  renderWindow->SetWindowName("PolygonalSurfaceContourLineInterpolator");

  vtkNew<vtkRenderWindowInteractor> interactor;
  interactor->SetRenderWindow(renderWindow);

  // Add the actors to the renderer, set the background and size.

  renderer->AddActor(actor);
  renderer->SetBackground(colors->GetColor3d("CadetBlue").GetData());

  // Here comes the contour widget stuff...

  vtkNew<vtkContourWidget> contourWidget;
  contourWidget->SetInteractor(interactor);
  vtkSmartPointer<vtkOrientedGlyphContourRepresentation> rep =
      dynamic_cast<vtkOrientedGlyphContourRepresentation*>(
          contourWidget->GetRepresentation());
  rep->GetLinesProperty()->SetColor(colors->GetColor3d("Crimson").GetData());
  rep->GetLinesProperty()->SetLineWidth(3.0);

  vtkNew<vtkPolygonalSurfacePointPlacer> pointPlacer;
  pointPlacer->AddProp(actor);
  pointPlacer->GetPolys()->AddItem(pd);
  rep->SetPointPlacer(pointPlacer);

  vtkNew<vtkPolygonalSurfaceContourLineInterpolator> interpolator;
  interpolator->GetPolys()->AddItem(pd);
  rep->SetLineInterpolator(interpolator);

  renderWindow->Render();
  interactor->Initialize();

  contourWidget->EnabledOn();

  interactor->Start();

  return EXIT_SUCCESS;
}

4.使用场景

可以用来做任意曲面切割:

曲面拟合主要用的贝塞尔曲面,交互部分用

vtkPolygonalSurfacePointPlacer,

vtkPolygonalSurfaceContourLineInterpolator

也可使用

vtkOrientedGlyphContourRepresentation

以及自定义的vtk3DWidget子类

相关推荐
BoBoZz1914 小时前
MotionBlur 演示简单运动模糊
python·vtk·图形渲染·图形处理
BoBoZz1914 小时前
GradientBackground 比较不同类型的背景渐变着色模式与坐标转换
python·vtk·图形渲染·图形处理
BoBoZz191 天前
FlatVersusGouraud 对比平面着色和高洛德着色
python·vtk·图形渲染·图形处理
BoBoZz192 天前
ColorEdges 动态有向图的动态渲染
python·vtk·图形渲染·图形处理
BoBoZz192 天前
AmbientSpheres 调整材质的环境光系数来控制3D物体的着色效果
python·vtk·图形渲染·图形处理
BoBoZz193 天前
ResetCameraOrientation 保存、修改和恢复摄像机的精确视角参数
python·vtk·图形渲染·图形处理
BoBoZz193 天前
MultipleRenderWindows 创建多个渲染窗口
python·vtk·图形渲染·图形处理
BoBoZz196 天前
3D 医学扫描同时显示患者的皮肤、骨骼的 3D 模型(通过等值面提取),以及三个正交切片
python·vtk·图形渲染·图形处理
欧特克_Glodon7 天前
基于Qt+VTK实现的CT/MR影像浏览工具,支持体渲染及体模型剪裁
c++·qt·vtk·体渲染·裁剪
BoBoZz197 天前
GenerateCubesFromLabels 提取和可视化特定标签所代表的 3D 结构
python·vtk·图形渲染·图形处理