VTK-Wight 之 vtkContourWidget简介
来源:互联网 发布:易语言远程桌面源码 编辑:程序博客网 时间:2024/06/08 13:29
VTK中Wights功能的实现需要两个部分的协作:
- 事件处理,继承于 vtkAbstractWight 类
- 描述几何特征,继承于 vtkWightRespresentation
vtkContourWidget 简介
用一个点集创建一个轮廓。
该类常常用于选取一个点集,绘制点之间的连线。最后一个点的选取决定了,轮廓是闭合的还是是开放的。
vtkContourRepresentation 这个类负责所有点的位置,连线的计算,以及轮廓的操作,点、线的绘制。
关于这个respresentation;
监听事件
LeftButtonPressEvent- triggers a Select event
RightButtonPressEvent - triggers a AddFinalPoint event
MouseMoveEvent - triggers a Move event
LeftButtonReleaseEvent - triggers an EndSelect event
Delete key event - triggers a Delete event
Shift + Delete key event - triggers a Reset event还有一些其他的事件
继承图
利用 vtkContourWidget 画一个闭合区域取点原则:最后一个和第一个结点重合
示例
#include <vtkSmartPointer.h>
// To setup the ContourWidget and its representation:#include <vtkContourWidget.h>#include <vtkProperty.h>#include <vtkOrientedGlyphContourRepresentation.h>// To create the geometry:#include <vtkPolyData.h>#include <vtkCellArray.h>#include <vtkPoints.h>#include <vtkMath.h>// Usual VTK pipeline elements:#include <vtkRenderer.h>#include <vtkRenderWindow.h>#include <vtkRenderWindowInteractor.h>#include <vtkInteractorStyleTrackballCamera.h>int main( int argc, char *argv[] ){// Create the contour widgetvtkSmartPointer<vtkContourWidget> contourWidget = vtkSmartPointer<vtkContourWidget>::New();// Override the default representation for the contour widget to customize its lookvtkSmartPointer<vtkOrientedGlyphContourRepresentation> contourRepresentation =vtkSmartPointer<vtkOrientedGlyphContourRepresentation>::New();contourRepresentation->GetLinesProperty()->SetColor(1, 0, 0); // Set color to redcontourWidget->SetRepresentation(contourRepresentation);// Generate a set of points arranged in a circleint numPts = 10;vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();for (int i = 0; i < numPts; i++){// Create numPts points evenly spread around a circumference of radius 0.1const double angle = 2.0*vtkMath::Pi()*i/numPts;points->InsertPoint(static_cast<vtkIdType>(i), 0.1*cos(angle), 0.1*sin(angle), 0.0 );}// Create a cell array to connect the points into meaningful geometryvtkIdType* vertexIndices = new vtkIdType[numPts+1];for (int i = 0; i < numPts; i++) { vertexIndices[i] = static_cast<vtkIdType>(i); }// Set the last vertex to 0; this means the last line segment will join the 19th point (vertices[19])// with the first one (vertices[0]), thus closing the circle.vertexIndices[numPts] = 0;vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();lines->InsertNextCell(numPts+1, vertexIndices);// Create polydata to hold the geometry just created, and populate itvtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();polydata->SetPoints(points);polydata->SetLines(lines);// Create the renderer to visualize the scenevtkSmartPointer<vtkRenderer> renderer =vtkSmartPointer<vtkRenderer>::New();renderer->SetBackground(0.1, 0.2, 0.4);// Set a dark blue background (default is black)// Create the GUI window to hold the rendered scenevtkSmartPointer<vtkRenderWindow> renderWindow =vtkSmartPointer<vtkRenderWindow>::New();renderWindow->AddRenderer(renderer);// Create the events manager for the renderer windowvtkSmartPointer<vtkRenderWindowInteractor> interactor =vtkSmartPointer<vtkRenderWindowInteractor>::New();interactor->SetRenderWindow(renderWindow);// Use the "trackball camera" interactor style, rather than the default "joystick camera"vtkSmartPointer<vtkInteractorStyleTrackballCamera> style =vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();interactor->SetInteractorStyle(style);// Set up the contour widget within the visualization pipeline just assembledcontourWidget->SetInteractor(interactor);contourWidget->On();// Turn on the interactor observercontourWidget->Initialize(polydata);std::cout << "the number of nodes is " << contourRepresentation->GetNumberOfNodes() << std::endl;// you can get node world position of one node by GetNthNodeWorldPosition(pointID, double_pos[3]) renderer->ResetCamera();// Reposition camera to fit the scene elementsinteractor->Initialize();// Start the interactioninteractor->Start();return EXIT_SUCCESS;}
暂时还没有想到还有什么,可能之后再补充吧
0 0
- VTK-Wight 之 vtkContourWidget简介
- VTK-Wight 之vtkIncrementalOctreePointLocator简介
- vtkContourWidget
- VTK简介
- VTK简介
- VTK简介
- VTK简介
- VTK简介
- android wight
- VTK简介(1)
- VTK简介(2)
- VTK简介(3)
- VTK简介(4)
- VTK简介及安装
- VTK简介及安装
- VTK简介及安装
- VTK 编程简介
- VTK Camera简介
- cocos2d-JS html5 声音适配总结
- vi命令无法使用的解决办法
- ios实现返回关闭当前页面
- BZOJ2962: 序列操作
- C#的第11节课的主要内容
- VTK-Wight 之 vtkContourWidget简介
- JavaScript 资源大全中文版
- C++ 之结构体对齐
- C语言实现任意进制的转换,主要注意代码的小技巧
- 建议64:为循环增加Tester-Doer模式而不是将try-catch置于循环内 如果需要在循环中引发异常,你需要特别注意,应为抛出异常是一个相当影响性能的过程。应该尽量在循环当中对异常发生的一
- 表的join操作:left、right、outer、inner
- 自定义View绘制圆,可拖动
- C# 多线程编程以及常用方法
- C语言-数据类型在LR中的应用