VTK 正交投影 透视投影

1.VTK默认透视投影(近大远小);

1.调用vtkCamera的ParallelProjectionOn函数开启

2.通过vtkCamera的SetParallelScale缩放

3.通过vtkCamera的SetClippingRange设置前后裁剪平面

2.正交投影(平行投影,远近一样):

//开启正交投影模式
renderer->GetActiveCamera()->ParallelProjectionOn();
renderer->GetActiveCamera()->SetParallelScale(10);
renderer->GetActiveCamera()->SetClippingRange(-100, 100);

正交投影样例:

VTK 正交投影 透视投影_第1张图片

Code:

#pragma once
//#include "vtk_include.h"
 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
 
#include 
 
#include 
#include 
 
#include 
 
#include 
#include 
#include
#include
using namespace std;

 
void main()
	{
		vtkNew colors;
		vtkNew renderer;
		//平面
		vtkNew plane;
		plane->SetCenter(0, 0, 0);//设置平面中心点坐标
		plane->SetOrigin(-10, -10, 0);//设置平面起点坐标,一般为平面左下角
		plane->SetPoint1(10, -10, 0);//设置平面第一条轴的长度
		plane->SetPoint2(-10, 10, 0);//设置平面第二条轴的长度
		plane->SetNormal(0, 0, 1);//设置平面的法向量
		plane->SetXResolution(10);//x方向分割数
		plane->SetYResolution(10);//y方向分割数
		vtkNew planeMapper;
		planeMapper->SetInputConnection(plane->GetOutputPort());
		vtkNew planeActor;
		planeActor->SetMapper(planeMapper);
		planeActor->GetProperty()->EdgeVisibilityOn(); //显示线框
		renderer->AddActor(planeActor);

		//球
		vtkNew sphereSource;
		sphereSource->SetRadius(5);
		sphereSource->SetCenter(5, 0, 0);
		sphereSource->Update();
		vtkNew sphereMapper;
		sphereMapper->SetInputConnection(sphereSource->GetOutputPort());
		vtkNew sphereActor;
		sphereActor->SetMapper(sphereMapper);
		sphereActor->GetProperty()->SetColor(colors->GetColor4d("Green").GetData());
		sphereActor->GetProperty()->EdgeVisibilityOn(); //显示线框
		renderer->AddActor(sphereActor);

		renderer->ResetCamera();
		//开启正交投影模式
		renderer->GetActiveCamera()->ParallelProjectionOn();
		renderer->GetActiveCamera()->SetParallelScale(10);
		renderer->GetActiveCamera()->SetClippingRange(-1000, 1000);

		renderer->SetBackground(colors->GetColor3d("SteelBlue").GetData());

		vtkNew renderWindow;
		renderWindow->AddRenderer(renderer);
		renderWindow->SetWindowName("RenderWindowNoUIFile");

  
		vtkNew iren;
		iren->SetRenderWindow(renderWindow);
 

		renderWindow->Render();
		iren->Initialize();
		iren->Start();
	}
 

你可能感兴趣的:(VTK,VTK)