vtkInteractorStyleRubberBandPick 类简介

翻译 2016年08月30日 18:01:52

的继承图


简介:

该类主要用橡皮筋矩形拾取 props.

Like TrackBallCamera, but this can pick props underneath a rubber band selection rectangle.

用户可以通过鼠标左键或者“r”键画一个矩形。当鼠标释放的时候,附加的拾取器可以操作所选矩形中间的像素值。 如果拾取器是 vtkAreaPicker,可以操作整个所选的矩形。

键盘“P”: 1*1 的矩形框。

This interactor style allows the user to draw a rectangle in the render window by hitting 'r' and then using the left mouse button. When the mouse button is released, the attached picker operates on the pixel in the center of the selection rectangle. If the picker happens to be a vtkAreaPicker it will operate on the entire selection rectangle. When the 'p' key is hit the above pick operation occurs on a 1x1 rectangle. In other respects it behaves the same as its parent class.

示例一

#include <vtkVersion.h>
#include <vtkSmartPointer.h>
#include <vtkPoints.h>
#include <vtkXMLPolyDataWriter.h>
#include <vtkPolyData.h>
#include <vtkCellArray.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleRubberBandPick.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkInteractorStyleTrackball.h>
#include <vtkAreaPicker.h>
#include <vtkCallbackCommand.h>
#include <vtkProp3DCollection.h>

void PickCallbackFunction ( vtkObject* caller, long unsigned int eventId, void* clientData, void* callData );

int main(int, char *[])
{
	// Create a set of points
	vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
	vtkSmartPointer<vtkCellArray> vertices = vtkSmartPointer<vtkCellArray>::New();
	vtkIdType pid[1];
	pid[0] = points->InsertNextPoint ( 1.0, 0.0, 0.0 );
	vertices->InsertNextCell ( 1,pid );
	pid[0] = points->InsertNextPoint ( 0.0, 0.0, 0.0 );
	vertices->InsertNextCell ( 1,pid );
	pid[0] = points->InsertNextPoint ( 0.0, 1.0, 0.0 );
	vertices->InsertNextCell ( 1,pid );

	// Create a polydata
	vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
	polydata->SetPoints ( points );
	polydata->SetVerts ( vertices );

	// Visualize
	vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
#if VTK_MAJOR_VERSION <= 5
	mapper->SetInput(polydata);
#else
	mapper->SetInputData(polydata);
#endif
	vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
	actor->SetMapper(mapper);

	vtkSmartPointer<vtkRenderer> renderer =	vtkSmartPointer<vtkRenderer>::New();
	vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
	renderWindow->AddRenderer(renderer);

	vtkSmartPointer<vtkAreaPicker> areaPicker = vtkSmartPointer<vtkAreaPicker>::New();

	vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =	vtkSmartPointer<vtkRenderWindowInteractor>::New();
	renderWindowInteractor->SetRenderWindow(renderWindow);
	renderWindowInteractor->SetPicker(areaPicker);

	renderer->AddActor(actor);
	renderer->SetBackground(0,0,0.2); // Background color dark blue

	renderWindow->Render();

	// For vtkInteractorStyleRubberBandPick - use 'r' and left-mouse to draw a selection box used to pick
	vtkSmartPointer<vtkInteractorStyleRubberBandPick> style = vtkSmartPointer<vtkInteractorStyleRubberBandPick>::New();

	// For vtkInteractorStyleTrackballCamera - use 'p' to pick at the current mouse position
	//vtkSmartPointer<vtkInteractorStyleTrackballCamera> style = vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New(); //like paraview
	style->SetCurrentRenderer(renderer);
	renderWindowInteractor->SetInteractorStyle( style );

	vtkSmartPointer<vtkCallbackCommand> pickCallback = vtkSmartPointer<vtkCallbackCommand>::New();
	pickCallback->SetCallback ( PickCallbackFunction );

	areaPicker->AddObserver ( vtkCommand::EndPickEvent, pickCallback );

	renderWindowInteractor->Start();

	return EXIT_SUCCESS;
}


void PickCallbackFunction(vtkObject* caller,
	long unsigned int vtkNotUsed(eventId),
	void* vtkNotUsed(clientData),
	void* vtkNotUsed(callData))
{
	std::cout << "Pick." << std::endl;
	vtkAreaPicker* areaPicker = static_cast<vtkAreaPicker*>(caller);
	vtkProp3DCollection* props = areaPicker->GetProp3Ds();

	for(vtkIdType i = 0; i < props->GetNumberOfItems(); i++)
	{
		vtkProp3D* prop = props->GetNextProp3D();
		std::cout << "Picked prop: " << prop << std::endl;
	}
}
这个就非常简单了,vtkInteractorStyleRubberBandPick 是 vtkInteractorStyle 的子类,使用时,加入到 vtkRenderWinderInteractor 的对象中,同时需要设置该 style 的当前 renderer.



示例二

#include <vtkVersion.h>

#include <vtkActor.h>
#include <vtkAreaPicker.h>
#include <vtkDataSetMapper.h>
#include <vtkDataSetSurfaceFilter.h>
#include <vtkExtractPolyDataGeometry.h>
#include <vtkIdFilter.h>
#include <vtkIdTypeArray.h>
#include <vtkInteractorStyleRubberBandPick.h>
#include <vtkObjectFactory.h>
#include <vtkPlanes.h>
#include <vtkPointData.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkRendererCollection.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkUnstructuredGrid.h>
#include <vtkVersion.h>
#include <vtkVertexGlyphFilter.h>

#define VTKISRBP_ORIENT 0
#define VTKISRBP_SELECT 1

// Define interaction style
class HighlightInteractorStyle : public vtkInteractorStyleRubberBandPick
{
public:
	static HighlightInteractorStyle* New();
	vtkTypeMacro(HighlightInteractorStyle,vtkInteractorStyleRubberBandPick);

	HighlightInteractorStyle() : vtkInteractorStyleRubberBandPick()
	{
		this->SelectedMapper = vtkSmartPointer<vtkDataSetMapper>::New();
		this->SelectedActor = vtkSmartPointer<vtkActor>::New();
		this->SelectedActor->SetMapper(SelectedMapper);
	}

	virtual void OnLeftButtonUp()
	{
		// Forward events
		vtkInteractorStyleRubberBandPick::OnLeftButtonUp();

		if(this->CurrentMode == VTKISRBP_SELECT)
		{
			vtkPlanes* frustum = static_cast<vtkAreaPicker*>(this->GetInteractor()->GetPicker())->GetFrustum();

			vtkSmartPointer<vtkExtractPolyDataGeometry> extractPolyDataGeometry = vtkSmartPointer<vtkExtractPolyDataGeometry>::New();
#if VTK_MAJOR_VERSION <= 5
			extractPolyDataGeometry->SetInput(this->PolyData);
#else
			extractPolyDataGeometry->SetInputData(this->PolyData);
#endif
			extractPolyDataGeometry->SetImplicitFunction(frustum);
			extractPolyDataGeometry->Update();

			std::cout << "Extracted " << extractPolyDataGeometry->GetOutput()->GetNumberOfCells() << " cells." << std::endl;

#if VTK_MAJOR_VERSION <= 5
			this->SelectedMapper->SetInputConnection(
				extractPolyDataGeometry->GetOutputPort());
#else
			this->SelectedMapper->SetInputData(extractPolyDataGeometry->GetOutput());
#endif
			this->SelectedMapper->ScalarVisibilityOff();

			//        vtkIdTypeArray* ids = vtkIdTypeArray::SafeDownCast(selected->GetPointData()->GetArray("OriginalIds"));

			this->SelectedActor->GetProperty()->SetColor(1.0, 0.0, 0.0); //(R,G,B)
			this->SelectedActor->GetProperty()->SetPointSize(5);

			this->GetInteractor()->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->AddActor(SelectedActor);
			this->GetInteractor()->GetRenderWindow()->Render();
			this->HighlightProp(NULL);
		}
	}

	void SetPolyData(vtkSmartPointer<vtkPolyData> polyData) {this->PolyData = polyData;}
private:
	vtkSmartPointer<vtkPolyData> PolyData;
	vtkSmartPointer<vtkActor> SelectedActor;
	vtkSmartPointer<vtkDataSetMapper> SelectedMapper;

};
vtkStandardNewMacro(HighlightInteractorStyle);

int main (int, char *[])
{
	vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New();
	sphereSource->Update();

	vtkSmartPointer<vtkIdFilter> idFilter =	vtkSmartPointer<vtkIdFilter>::New();
	idFilter->SetInputConnection(sphereSource->GetOutputPort());
	idFilter->SetIdsArrayName("OriginalIds");
	idFilter->Update();

	// This is needed to convert the ouput of vtkIdFilter (vtkDataSet) back to vtkPolyData
	vtkSmartPointer<vtkDataSetSurfaceFilter> surfaceFilter = vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
	surfaceFilter->SetInputConnection(idFilter->GetOutputPort());
	surfaceFilter->Update();

	vtkPolyData* input = surfaceFilter->GetOutput();

	// Create a mapper and actor
	vtkSmartPointer<vtkPolyDataMapper> mapper =	vtkSmartPointer<vtkPolyDataMapper>::New();
	mapper->SetInputConnection(sphereSource->GetOutputPort());
	mapper->ScalarVisibilityOff();

	vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
	actor->SetMapper(mapper);
	actor->GetProperty()->SetPointSize(500);

	// Visualize
	vtkSmartPointer<vtkRenderer> renderer =	vtkSmartPointer<vtkRenderer>::New();
	vtkSmartPointer<vtkRenderWindow> renderWindow =	vtkSmartPointer<vtkRenderWindow>::New();
	renderWindow->AddRenderer(renderer);

	vtkSmartPointer<vtkAreaPicker> areaPicker =	vtkSmartPointer<vtkAreaPicker>::New();
	vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =	vtkSmartPointer<vtkRenderWindowInteractor>::New();
	renderWindowInteractor->SetPicker(areaPicker);
	renderWindowInteractor->SetRenderWindow(renderWindow);

	renderer->AddActor(actor);
	//renderer->SetBackground(1,1,1); // Background color white

	renderWindow->Render();

	vtkSmartPointer<HighlightInteractorStyle> style = vtkSmartPointer<HighlightInteractorStyle>::New();
	style->SetPolyData(input);
	renderWindowInteractor->SetInteractorStyle( style );

	renderWindowInteractor->Start();

	return EXIT_SUCCESS;
}



VTk学习笔记--vtkInteractorStyleRubberBand2D

 vtkInteractorStyleRubberBand2D
  • u013089125
  • u013089125
  • 2014年05月23日 19:46
  • 408

Python 类介绍

Python笔记——类定义   一、类定义: class :        类实例化后,可以使用其属性,实际上,创建一个类之后,可以通过类名访问其属性 如果直接使用类名修改其属性,那么将直接影响到已经...
  • yyywyr
  • yyywyr
  • 2015年07月30日 08:53
  • 677

JasperReport 类介绍

 JasperReport2.1      简介JasperReport 是产生报表的核心部分,首先要先有个xml文件,然后根据jasperreports.dtd编译成jasper文件(以.j...
  • archie2010
  • archie2010
  • 2011年04月26日 08:54
  • 2505

openssl 简介

OpenSSL是一个基于密码学的安全开发包,OpenSSL提供的功能相当强大和全面,囊括了主要的密码算法、常用的密钥和证书封装管理功能以及SSL协议,并提供了丰富的应用程序供测试或其它目的使用。 ...
  • sszgg2006
  • sszgg2006
  • 2012年11月22日 09:46
  • 1313

netty介绍

1.什么是netty 1.1百度百科 Netty是由JBOSS提供的一个java开源框架。Netty提供异步的、事件驱动的网络应用程序框架和工具,用以快速开发高性能、高可靠性的网络服务器和客户端程序。...
  • u012061196
  • u012061196
  • 2016年12月21日 16:10
  • 499

Servlet类详解

Servlet核心类 关联: 从我可以拿到你 想要拿到servletConfig对象只要通过Servlet的getServletConfig()就可以拿到了 在ServletCon...
  • CSDN_GIA
  • CSDN_GIA
  • 2016年12月04日 14:27
  • 2274

视图类(CView)的三个子类

视图类(CView)的三个子类    CScrollView类提供视图的滚动显示;CEditView类支持在视图中的文本编辑操作;CHtmlView类支持在视图中显示和操作html文件。    ...
  • gh2663287
  • gh2663287
  • 2015年06月02日 21:40
  • 471

Python 基础 —— 模块和包介绍

1、模块的作用      在交互模式下输出的变量和函数定义,一旦终端重启后,这些定义就都不存在了,为了持久保存这些变量、函数等的定义,Python中引入了模块(Module)的概念。 一个Pytho...
  • xiaohui_hubei
  • xiaohui_hubei
  • 2014年05月06日 15:54
  • 1407

简要介绍Java中的枚举类

一、概念 在某些情况下,一个类的对象是有限而且固定的,例如季节类,它只有四个对象,这种实例有限而且固定的类,在Java里被称为枚举类。 手动实现枚举类: 1.通过private将构造器隐藏起来。 2....
  • u010142437
  • u010142437
  • 2013年10月13日 15:47
  • 3993

s2sh框架整合demo介绍-注解方式

s2sh整合之注解方式 说明:本文档所采用的框架版本为:Struts 2.1.8, Sping2.5.5,  Hibernate 3.5.6 Action层未使用注解,依然是用的配置文件,个人觉得...
  • rchm8519
  • rchm8519
  • 2014年06月23日 00:27
  • 3243
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:vtkInteractorStyleRubberBandPick 类简介
举报原因:
原因补充:

(最多只允许输入30个字)