zoukankan      html  css  js  c++  java
  • 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;
    }
    
    
    
    
  • 相关阅读:
    nodejs安装以及配置
    java第三周学习总结
    java第二周学习总结
    java第一周学习总结
    调查问卷
    2016.2.19 学习总结
    第一周学习总结
    第一周学习总结
    假期马原学习计划
    20145335郝昊《java程序设计》第2次实验报告
  • 原文地址:https://www.cnblogs.com/phoenixdsg/p/6168943.html
Copyright © 2011-2022 走看看