vtkTransform實例 1


 1. 4*4矩陣類vtkMatrix4x4

  接口函數:void SetElement(int i, int j, double value),i行、j列的值為value

 

 

 1 #ifndef INITIAL_OPENGL
 2 #define INITIAL_OPENGL
 3 #include <vtkAutoInit.h>
 4 VTK_MODULE_INIT(vtkRenderingOpenGL)
 5 VTK_MODULE_INIT(vtkInteractionStyle)
 6 VTK_MODULE_INIT(vtkRenderingFreeType)
 7 #endif
 8 #include <iostream>
 9 using namespace std;
10 #include<vtkSmartPointer.h>
11 #include<vtkPerspectiveTransform.h>
12 #include <vtkMatrix4x4.h>
13 #include <vtkTransform.h>
14 
15 int main()
16 {
17     vtkSmartPointer<vtkMatrix4x4> m=vtkSmartPointer<vtkMatrix4x4>::New();
18     double ma[4][4]={{1,2,3,4},
19                      {2,2,3,4},
20                      {3,2,3,4},
21                      {4,2,3,4}};
22     for(int i=0;i<4;i++)
23     {
24         for(int j=0;j<4;j++)
25         {
26             //void SetElement(int i, int j, double value),i行、j列的值為value
27             m->SetElement(i,j,ma[i][j]);
28         }
29     }
30     //普通變換
31     vtkSmartPointer<vtkTransform> transform=vtkSmartPointer<vtkTransform>::New();
32     transform->SetMatrix(m);
33     double p[3]={1,2,3};//原始點
34     double normalProjection[3];//投影變換后的點坐標
35     transform->TransformPoint(p,normalProjection);
36     cout<<"Original point     :"<<p[0]<<","<<p[1]<<","<<p[2]<<endl;
37     cout<<"Standard projection:"<<normalProjection[0]<<","<<normalProjection[1]<<","<<normalProjection[2]<<endl;
38     //透視投影變換
39     double perspectiveProjection[3];
40     vtkSmartPointer<vtkPerspectiveTransform>perspectiveTransform=vtkSmartPointer<vtkPerspectiveTransform>::New();
41     perspectiveTransform->SetMatrix(m);
42     perspectiveTransform->TransformPoint(p,perspectiveProjection);
43     cout<<"Perspective projection:"<<perspectiveProjection[0]<<","<<perspectiveProjection[1]<<","<<perspectiveProjection[2]<<endl;
44     return 0;
45 }

 

 

 

 

#ifndefINITIAL_OPENGL
#defineINITIAL_OPENGL
#include<vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL)
VTK_MODULE_INIT(vtkInteractionStyle)
VTK_MODULE_INIT(vtkRenderingFreeType)
#endif
#include<iostream>
usingnamespacestd;
#include<vtkSmartPointer.h>
#include<vtkPerspectiveTransform.h>
#include<vtkMatrix4x4.h>
#include<vtkTransform.h>
 
        
intmain()
{
vtkSmartPointer<vtkMatrix4x4>m=vtkSmartPointer<vtkMatrix4x4>::New();
doublema[4][4]={{1,2,3,4},
{2,2,3,4},
{3,2,3,4},
{4,2,3,4}};
for(inti=0;i<4;i++)
{
for(intj=0;j<4;j++)
{
//voidSetElement(inti,intj,doublevalue),i行、j列的值為value
m->SetElement(i,j,ma[i][j]);
}
}
//普通變換
vtkSmartPointer<vtkTransform>transform=vtkSmartPointer<vtkTransform>::New();
transform->SetMatrix(m);
doublep[3]={1,2,3};//原始點
doublenormalProjection[3];//投影變換后的點坐標
transform->TransformPoint(p,normalProjection);
cout<<"Originalpoint:"<<p[0]<<","<<p[1]<<","<<p[2]<<endl;
cout<<"Standardprojection:"<<normalProjection[0]<<","<<normalProjection[1]<<","<<normalProjection[2]<<endl;
//透視投影變換
doubleperspectiveProjection[3];
vtkSmartPointer<vtkPerspectiveTransform>perspectiveTransform=vtkSmartPointer<vtkPerspectiveTransform>::New();
perspectiveTransform->SetMatrix(m);
perspectiveTransform->TransformPoint(p,perspectiveProjection);
cout<<"Perspectiveprojection:"<<perspectiveProjection[0]<<","<<perspectiveProjection[1]<<","<<perspectiveProjection[2]<<endl;
return0;
}
 
        
 
       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM