首页 > 代码库 > 计算vtkRender的屏幕坐标范围和物理坐标范围

计算vtkRender的屏幕坐标范围和物理坐标范围

vtkRenderWindow可以包含多个vtkRender,在模型检测等计算过程中需要计算一些vtkRender的屏幕范围和物理范围,最近想了一种方案:

计算屏幕坐标范围:

double vp[4];
this->Renderer->GetViewport(vp);

this->Renderer->NormalizedDisplayToDisplay(vp[0], vp[1]);
this->Renderer->NormalizedDisplayToDisplay(vp[2], vp[3]);

double dx = vp[2] - vp[0];
double dy = vp[3] - vp[1];

计算物理坐标范围:

double vp[4];
this->Renderer->GetViewport(vp);

double wp1[3] = { vp[0], vp[1], 0.0 };
double wp2[3] = { vp[2], vp[3], 0.0 };

this->Renderer->NormalizedDisplayToViewport(wp1[0], wp1[1]);
this->Renderer->ViewportToNormalizedViewport(wp1[0], wp1[1]);
this->Renderer->NormalizedViewportToView(wp1[0], wp1[1], wp1[2]);
this->Renderer->ViewToWorld(wp1[0], wp1[1], wp1[2]);

this->Renderer->NormalizedDisplayToViewport(wp2[0], wp2[1]);
this->Renderer->ViewportToNormalizedViewport(wp2[0], wp2[1]);
this->Renderer->NormalizedViewportToView(wp2[0], wp2[1], wp2[2]);
this->Renderer->ViewToWorld(wp2[0], wp2[1], wp2[2]);

 

计算vtkRender的屏幕坐标范围和物理坐标范围