水平有限,欢迎各位大神指正!
///
关于坐标相互转换的理论部分可以参阅 http://blog.csdn.net/popy007/article/details/1797121
解析vtk下世界坐标系world到显示坐标系下的转换:
首先呢在vtkInteractorObserver中存在函数ComputeWorldToDisplay()函数供其子类调用,源代码如下:
//----------------------------------------------------------------------------
// Description:
// Transform from world to display coordinates.
// displayPt has to be allocated as 3 vector
void vtkInteractorObserver::ComputeWorldToDisplay(double x, double y, double z, double displayPt[3])
{
if ( !this->CurrentRenderer )
{
return;
}
this->ComputeWorldToDisplay(this->CurrentRenderer, x, y, z, displayPt);
}
// Description:
// Transform from world to display coordinates.
// displayPt has to be allocated as 3 vector
void vtkInteractorObserver::ComputeWorldToDisplay(vtkRenderer *ren, double x, double y, double z, double displayPt[3])
{
ren->SetWorldPoint(x, y, z, 1.0);
ren->WorldToDisplay();
ren->GetDisplayPoint(displayPt);
}
///
借助于上边两个函数最终还是靠vtkRenderer来完成世界坐标系向显示坐标系下的转换,在函数中,首先在世界坐标系下定义了一个点(x,y,z,1),然后调用vtkViewport(vtkRenderer的父类)的WorldToDisplay()函数,下边我们解剖这个函数内部功能。
// Description:
// Convert world point coordinates to display (or screen) coordinates.
void WorldToDisplay() {this->WorldToView(); this->ViewToDisplay();};
这个函数先将world坐标系转换为view坐标系,然后再将view坐标系转换为显示坐标系
(1)下边解剖WorldToView()函数
// Convert world point coordinates to view coordinates.
void vtkRenderer::WorldToView()
{
double result[3];
result[0] = this->WorldPoint[0];
result[1] = this->WorldPoint[1];
result[2] = this->WorldPoint[2];