# 【VTK】vtk actor空间变换后的点映射与向量映射

1. 将平面绕平面的Y轴旋转一定角度
2. 将其绕平面自身的X轴旋转一定角度
3. 将平面向向量方向(1, 2, 3)移动一段距离。

void vtkProp3D::RotateY (double angle)
void vtkProp3D::RotateX (double angle)
void vtkProp3D::AddPosition (double deltaX,double deltaY,double deltaZ)


#include <stdio.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkActor.h>
#include <vtkPlaneSource.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkLight.h>
#include <vtkCamera.h>
#include <vtkActor2D.h>
#include <vtkTransform.h>

using namespace std;

int main()
{
setbuf( stdout, NULL );
vtkSmartPointer<vtkPlaneSource> plane =
vtkSmartPointer<vtkPlaneSource>::New();

vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection( plane->GetOutputPort() );

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

double oldNormal[3] = { 0, 0, -1 };
double oldOrigin[3] = { 0, 0, 0 };

actor->RotateY( 45 );
//    actor->AddPosition( 1, -1, 1 );

vtkSmartPointer<vtkTransform> transform =
vtkSmartPointer<vtkTransform>::New();
transform->SetMatrix( actor->GetMatrix() );
double *newNormal = transform->TransformDoubleVector( oldNormal );

vtkSmartPointer<vtkTransform> transform2 =
vtkSmartPointer<vtkTransform>::New();
transform2->SetMatrix( actor->GetMatrix() );
double *newOrigin = transform2->TransformDoublePoint( oldOrigin );
printf( "newNormal: %lf, %lf, %lf\n", newNormal[0], newNormal[1], newNormal[2] );
printf( "newOrigin: %lf, %lf, %lf\n", newOrigin[0], newOrigin[1], newOrigin[2] );
/*
newOrigin: 0.000000, 0.000000, 0.000000
newNormal: -0.707107, 0.000000, -0.707107 (-cos45)
*/

vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->SetBackground( 0, 0, 0 );

vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();

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

renderer->ResetCamera();
renderWindow->Render();
renderWindowInteractor->Start();
return 0;
}


newNormal: 0.000000, 0.000000, 0.000000
newOrigin: 0.000000, 0.000000, 0.000000


double *TransformDoublePoint(double x, double y, double z) {
this->InternalDoublePoint[0] = x;
this->InternalDoublePoint[1] = y;
this->InternalDoublePoint[2] = z;
this->TransformPoint(this->InternalDoublePoint,this->InternalDoublePoint);
return this->InternalDoublePoint; };

//------------------------------------------------------------------------
double *TransformDoubleVector(double x, double y, double z) {
this->InternalDoublePoint[0] = x;
this->InternalDoublePoint[1] = y;
this->InternalDoublePoint[2] = z;
this->TransformVector(this->InternalDoublePoint,this->InternalDoublePoint);
return this->InternalDoublePoint; };


vtkLinearTransform将计算结果全都存储在InternalDoublePoint中了，所以例子中的newOrigin和newNormal最终指向同一个double数组，这个数组存储着最后一次计算的结果，即newOrigin。

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120