本文主要是介绍【vtkWidgetRepresentation】第七期 vtkImplicitPlaneRepresentation,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
很高兴在雪易的CSDN遇见你
前言
本文分享vtkImplicitPlaneRepresentation源码剖析,及相关的实例,该接口主要用于切割交互,希望对各位小伙伴有所帮助!
感谢各位小伙伴的点赞+关注,小易会继续努力分享,一起进步!
你的点赞就是我的动力(^U^)ノ~YO
目录
前言
1. vtkImplicitPlaneRepresentation介绍
2. vtkImplicitPlaneRepresentation关键参数介绍
3. 相关的应用实例
结论:
vtkImplicitPlaneRepresentation
1. vtkImplicitPlaneRepresentation介绍
继承自vtkWidgetRepresentation,但与vtkFinitePlaneRepresentation很相似。该类在BoundingBox中通过SetOrigin和SetNormal定义有界平面。可以通过vtkImplicitPlaneWidget2进行该平面的交互。 其子类vtkImplicitImageRepresentation在版本9.0.3中并没有,最近的版本9.3.2中存在。有兴趣的小伙伴可以自行查看。
2. vtkImplicitPlaneRepresentation关键参数介绍
2.1 定义平面
SetOrigin和SetNormal进行平面的定义。
提供了XY、YZ、XZ平面的简单创建方法:SetNormalToXAxis,SetNormalToYAxis,SetNormalToZAxis.
也可以将平面的法向固定垂直于Camera,SetLockNormalToCamera。
2.2 平面Representation的设置
该部分同vtkFinitePlaneRepresentation,包括:
SetTubing,平面的边界是否采用圆形管道表示。
SetDrawPlane,是否显示平面。
SetDrawOutLine,是否显示平面边界。
SetOutlineTranslation,是否允许通过左键移动轮廓。
SetConstrainToWidgetBounds,设置为TRUE时,平面的原点不允许移动到边界之外;设置为FALSE时,则可以自由移动。
SetScale,是否允许缩放。
2.3 GetPolyData获取切割结果
2.4 GetPlane获取平面
2.5 获取属性并设置
包括GetNormalProperty、GetSelectedNormalProperty;
GetPlaneProperty,GetSelectedPlaneProperty;GetOutlineProperty,GetSelectedOutlineProperty;GetEdgeProperty;
3. 相关的应用实例
#include <vtkSmartPointer.h>#include <vtkXMLPolyDataReader.h>
#include <vtkSphereSource.h>
#include <vtkClipPolyData.h>
#include <vtkPlane.h>#include <vtkCommand.h>
#include <vtkImplicitPlaneWidget2.h>
#include <vtkImplicitPlaneRepresentation.h>#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>// Callback for the interaction
// This does the actual work: updates the vtkPlane implicit function.
// This in turn causes the pipeline to update and clip the object.
class vtkIPWCallback : public vtkCommand
{
public:static vtkIPWCallback *New(){ return new vtkIPWCallback; }virtual void Execute(vtkObject *caller, unsigned long, void*){vtkImplicitPlaneWidget2 *planeWidget =reinterpret_cast<vtkImplicitPlaneWidget2*>(caller);vtkImplicitPlaneRepresentation *rep =reinterpret_cast<vtkImplicitPlaneRepresentation*>(planeWidget->GetRepresentation());rep->GetPlane(this->Plane);}vtkIPWCallback():Plane(0),Actor(0) {}vtkPlane *Plane;vtkActor *Actor;};int main(int argc, char *argv[])
{vtkSmartPointer<vtkSphereSource> sphereSource =vtkSmartPointer<vtkSphereSource>::New();sphereSource->SetRadius(10.0);vtkSmartPointer<vtkXMLPolyDataReader> reader =vtkSmartPointer<vtkXMLPolyDataReader>::New();// Setup a visualization pipelinevtkSmartPointer<vtkPlane> plane =vtkSmartPointer<vtkPlane>::New();vtkSmartPointer<vtkClipPolyData> clipper =vtkSmartPointer<vtkClipPolyData>::New();clipper->SetClipFunction(plane);clipper->InsideOutOn();if (argc < 2){clipper->SetInputConnection(sphereSource->GetOutputPort());}else{reader->SetFileName(argv[1]);clipper->SetInputConnection(reader->GetOutputPort());}// Create a mapper and actorvtkSmartPointer<vtkPolyDataMapper> mapper =vtkSmartPointer<vtkPolyDataMapper>::New();mapper->SetInputConnection(clipper->GetOutputPort());vtkSmartPointer<vtkActor> actor =vtkSmartPointer<vtkActor>::New();actor->SetMapper(mapper);vtkSmartPointer<vtkProperty> backFaces =vtkSmartPointer<vtkProperty>::New();backFaces->SetDiffuseColor(.8, .8, .4);actor->SetBackfaceProperty(backFaces);// A renderer and render windowvtkSmartPointer<vtkRenderer> renderer =vtkSmartPointer<vtkRenderer>::New();vtkSmartPointer<vtkRenderWindow> renderWindow =vtkSmartPointer<vtkRenderWindow>::New();renderWindow->AddRenderer(renderer);renderer->AddActor(actor);// An interactorvtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =vtkSmartPointer<vtkRenderWindowInteractor>::New();renderWindowInteractor->SetRenderWindow(renderWindow);renderWindow->Render();// The callback will do the workvtkSmartPointer<vtkIPWCallback> myCallback =vtkSmartPointer<vtkIPWCallback>::New();myCallback->Plane = plane;myCallback->Actor = actor;vtkSmartPointer<vtkImplicitPlaneRepresentation> rep =vtkSmartPointer<vtkImplicitPlaneRepresentation>::New();rep->SetPlaceFactor(1.25); // This must be set prior to placing the widgetrep->PlaceWidget(actor->GetBounds());rep->SetNormal(plane->GetNormal());vtkSmartPointer<vtkImplicitPlaneWidget2> planeWidget =vtkSmartPointer<vtkImplicitPlaneWidget2>::New();planeWidget->SetInteractor(renderWindowInteractor);planeWidget->SetRepresentation(rep);planeWidget->AddObserver(vtkCommand::InteractionEvent,myCallback);// RenderrenderWindowInteractor->Initialize();renderWindow->Render();planeWidget->On();// Begin mouse interactionrenderWindowInteractor->Start();return EXIT_SUCCESS;
}
结论:
感谢各位小伙伴的点赞+关注,小易会继续努力分享,一起进步!
你的赞赏是我的最最最最大的动力(^U^)ノ~YO
这篇关于【vtkWidgetRepresentation】第七期 vtkImplicitPlaneRepresentation的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!