VTK几个坐标的测试

17 篇文章 0 订阅

主要的测试目的是获得几个世界坐标

1. 测试源代码

class myInteractorStyle :public vtkInteractorStyleTrackballCamera
{
public:
	static myInteractorStyle* New()
	{
		return new myInteractorStyle;
	}
	void OnLeftButtonDown()
	{
		vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
		this->ShowStation();
	}

public:
	void  ShowStation()
	{
		vtkRenderWindowInteractor* interactor = this->GetInteractor();
		vtkRenderer* render = this->GetCurrentRenderer();

		//获得 event 的 world 坐标
		int eventDisplayPosition[3];
		interactor->GetEventPosition(eventDisplayPosition);

		qDebug() << "eventDisplayPosition: ";
		for (int i = 0; i < 3; ++i)
		{
			qDebug() << QString::number(eventDisplayPosition[i]);
		}

		render->SetDisplayPoint((double)eventDisplayPosition[0], (double)eventDisplayPosition[1], (double)eventDisplayPosition[2]);
		render->DisplayToWorld();

		double  eventWorldPoint[4];
		render->GetWorldPoint(eventWorldPoint);

		qDebug() << "eventWorldPoint: ";
		for (int i = 0; i < 4; ++i)
		{
			qDebug() << QString::number(eventWorldPoint[i]);
		}


		//获得 last event的 world 坐标
		int     LastEventDisplayPosition[3];
		interactor->GetLastEventPosition(LastEventDisplayPosition);

		qDebug() << "LastEventDisplayPosition: ";
		for (int i = 0; i < 3; ++i)
		{
			qDebug() << QString::number(LastEventDisplayPosition[i]);
		}


		render->SetDisplayPoint((double)LastEventDisplayPosition[0], (double)LastEventDisplayPosition[1], (double)LastEventDisplayPosition[2]);
		render->DisplayToWorld();

		double  lastEventWorldPoint[4];
		render->GetWorldPoint(lastEventWorldPoint);

		qDebug() << "lastEventWorldPoint: ";
		for (int i = 0; i < 3; ++i)
		{
			qDebug() << QString::number(lastEventWorldPoint[i]);
		}

		vtkCamera* camera = this->GetCurrentRenderer()->GetActiveCamera();
		double* cameraPosition = camera->GetPosition();

		qDebug() << "cameraPosition: ";
		for (int i = 0; i < 3; ++i)
		{
			qDebug() << QString::number(cameraPosition[i]);
		}


		double* focalPosition = camera->GetFocalPoint();

		qDebug() << "cameraFocalPosition: ";
		for (int i = 0; i < 3; ++i)
		{
			qDebug() << QString::number(focalPosition[i]);
		}
	}
};

	static void Test()
	{
		vtkNew<vtkRenderer> ren;
		vtkNew<vtkDICOMImageReader> reader;
		reader->SetDirectoryName("D:\\VTK-DATA\\Dicom-Samples\\xuebaolin");
		reader->Update();
		vtkImageData* pImageData = reader->GetOutput();
		dm = pImageData->GetDimensions();
		spacing = reader->GetDataSpacing();
		origin = reader->GetDataOrigin();

		vtkNew<vtkGPUVolumeRayCastMapper> gpuMapper;
		vtkNew<vtkVolumeProperty> volumeProperty;
		volumeProperty->SetInterpolationTypeToLinear();
		volumeProperty->SetAmbient(0.4);
		volumeProperty->SetDiffuse(1.6);  //漫反射
		volumeProperty->SetSpecular(0.2); //镜面反射
		volumeProperty->ShadeOn();  //打开或者关闭阴影测试

									//设置不透明度
		vtkNew<vtkPiecewiseFunction> compositeOpacity;
		compositeOpacity->AddPoint(220, 0.00);
		compositeOpacity->AddPoint(255, 1.0);
		volumeProperty->SetScalarOpacity(compositeOpacity); //设置不透明度传输函数

		vtkNew<vtkColorTransferFunction> color;
		color->AddRGBPoint(0.000, 0.00, 0.00, 0.00);
		color->AddRGBPoint(60, 1.00, 0.52, 0.30);
		color->AddRGBPoint(150, 1.00, 1.00, 1.00);
		color->AddRGBPoint(200, .5, .3, .2);
		volumeProperty->SetColor(color);

		vtkNew<vtkVolume> volume;
		volume->SetMapper(gpuMapper);
		volume->SetProperty(volumeProperty);

		ren->SetBackground(0.3, 0.4, 0.3);
		ren->AddVolume(volume);
		ren->GetActiveCamera()->SetViewUp(0, 0, 1);
		ren->GetActiveCamera()->SetFocalPoint(0, 0, 0);
		ren->GetActiveCamera()->SetPosition(0, -1, 0);
		ren->ResetCamera();


		gpuMapper->SetInputData(pImageData);
		//gpuMapper->SetMaskTypeToBinary();
		//gpuMapper->SetMaskInput(stencilToImage->GetOutput());

		ren->ResetCamera();
		vtkNew<vtkRenderWindow> rw;
		rw->AddRenderer(ren);
		rw->SetSize(640, 480);
		//rw->SetFullScreen(1);
		rw->Render();
		rw->SetWindowName("VolumeRendering PipeLine");

		vtkNew<vtkRenderWindowInteractor> rwi;
		vtkSmartPointer<myInteractorStyle>  style = 				vtkSmartPointer<myInteractorStyle>::New();

		rwi->SetInteractorStyle(style);
		rwi->SetRenderWindow(rw);

		rw->Render();

		rwi->Start();
	}

2. Display Position

如下,左下角(0,0), 右上角为Windows窗口宽度和高度。

 

3. 相机位置与相机焦点位置

Y向为从我们的视线纸外垂直与直面射向焦点的方向。这两个坐标都是世界坐标

 

正在上传…重新上传取消

4.  点击中央的点,获得的几个坐标

 

 

5.  旋转图形后

 

 

 6. 图形放大

 

相机位置逼近纸面,焦点位置没变。

 

7、  图形做了较大变化

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值