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子类

相关推荐

  1. VTK的交互

    2024-06-06 21:10:01       18 阅读
  2. VTK使用交互来从三维体数据中提取二维切片

    2024-06-06 21:10:01       23 阅读
  3. 多边形压缩 Douglas-Peucker算法

    2024-06-06 21:10:01       47 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-06 21:10:01       19 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-06 21:10:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-06 21:10:01       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-06 21:10:01       20 阅读

热门阅读

  1. TP6 事件绑定、监听、订阅

    2024-06-06 21:10:01       9 阅读
  2. 使用Keepalived提高吞吐量和负载均衡ip_hash.

    2024-06-06 21:10:01       10 阅读
  3. 找到自己的前提是认识自己

    2024-06-06 21:10:01       10 阅读
  4. Android Studio SharedPreferences的使用

    2024-06-06 21:10:01       10 阅读
  5. 使用Scapy框架分析HTTP流量

    2024-06-06 21:10:01       10 阅读
  6. 无人机反制软硬手段

    2024-06-06 21:10:01       8 阅读
  7. 单例模式(C语言)

    2024-06-06 21:10:01       8 阅读
  8. 自学之路Flutter使用Provider进行状态管理

    2024-06-06 21:10:01       9 阅读
  9. Oracle 如何定自增长数字列

    2024-06-06 21:10:01       10 阅读