vtkplanesource和vtktexturemapplane不会一起旋转

时间:2015-05-04 13:02:36

标签: c++ vtk

#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkOutlineFilter.h>
#include <vtkCamera.h>
#include <vtkProperty.h>
#include <vtkPolyDataNormals.h>
#include <vtkSmartPointer.h>
#include"project_config.h"
#include<vtkJPEGReader.h>
#include<vtkMarchingCubes.h>
#include<vtkStripper.h>
#include <vtkCommand.h>
#include <vtkPlaneSource.h>
#include<vtkTextureMapToPlane.h>
#include<vtkTextProperty.h>
#include<vtkTextMapper.h>
int main()
{
    int b[3]={1,2,3};
    vtkSmartPointer<vtkJPEGReader> jPEGReader =
        vtkSmartPointer<vtkJPEGReader>::New();
    //Read only one file
    jPEGReader->SetFileName ("C:/test/img0.jpg"  );

    //create a plane
    vtkSmartPointer<vtkPlaneSource> plane =
        vtkSmartPointer<vtkPlaneSource>::New();

    plane->SetCenter(0.0, 1.0, 1.0);

    //to rotate the plane around the center of the plane,
    //aligning the plane normal with the specified normal
    plane->SetNormal(2.0,1.0, 2.0);

    //Apply the texture
    vtkSmartPointer<vtkTexture> texture =
        vtkSmartPointer<vtkTexture>::New();
    texture->SetInputConnection(jPEGReader->GetOutputPort());

    vtkSmartPointer<vtkTextureMapToPlane> texturePlane =
        vtkSmartPointer<vtkTextureMapToPlane>::New();
    texturePlane->SetInputConnection(plane->GetOutputPort());

    vtkSmartPointer<vtkPolyDataMapper> planeMapper =
        vtkSmartPointer<vtkPolyDataMapper>::New();
    planeMapper->SetInputConnection(texturePlane->GetOutputPort());

    vtkSmartPointer<vtkActor> texturedPlane =
        vtkSmartPointer<vtkActor>::New();
    texturedPlane->SetMapper(planeMapper);
    texturedPlane->SetTexture(texture);
    //set opacity
    texturedPlane->GetProperty()->SetOpacity(0.2);

    vtkSmartPointer<vtkJPEGReader> jPEGReader1 =
        vtkSmartPointer<vtkJPEGReader>::New();
    jPEGReader1->SetFileName ("C:/test/images.jpg"  );

     //create other plane
     vtkSmartPointer<vtkPlaneSource> plane1 =
         vtkSmartPointer<vtkPlaneSource>::New();
     //plane1->SetOrigin(0,0,0);
     //plane1->SetXResolution(1.0);
     //plane1->SetYResolution(1.0);
     //translates the center of the plane to the specified center point.
     plane1->SetCenter(0.1, 1.0, 1.0);
     //to rotate the plane 
     plane1->SetNormal(2.0,1.0, 2.0);
     //plane1->Update(); 
     // plane1->SetPoint1(width,0,0);
     //plane1->SetPoint2(0,height,0);

     //Apply the texture
    vtkSmartPointer<vtkTexture> texture1 =
        vtkSmartPointer<vtkTexture>::New();
    texture1->SetInputConnection(jPEGReader1->GetOutputPort());

    vtkSmartPointer<vtkTextureMapToPlane> texturePlane1 =
        vtkSmartPointer<vtkTextureMapToPlane>::New();
    texturePlane1->SetInputConnection(plane1->GetOutputPort());

    vtkSmartPointer<vtkPolyDataMapper> planeMapper1 =
        vtkSmartPointer<vtkPolyDataMapper>::New();
    planeMapper1->SetInputConnection(texturePlane1->GetOutputPort());

    vtkSmartPointer<vtkActor> texturedPlane1 =
        vtkSmartPointer<vtkActor>::New();
    texturedPlane1->SetMapper(planeMapper1);
    texturedPlane1->SetTexture(texture1);
    //set opacity
    texturedPlane1->GetProperty()->SetOpacity(0.2);

    // Visualize the textured plane
    vtkSmartPointer<vtkRenderer> renderer =
        vtkSmartPointer<vtkRenderer>::New();
    renderer->AddActor(texturedPlane);
    renderer->AddActor(texturedPlane1);
    renderer->SetBackground(.1, .2, .3);// Background color dark blue
    renderer->ResetCamera();

    //Add rendered to render window and renders
    vtkSmartPointer<vtkRenderWindow> renderWindow =
        vtkSmartPointer<vtkRenderWindow>::New();
    renderWindow->AddRenderer(renderer);
    renderWindow->SetSize(800,800);
    //renderWindow->SetPosition(100,10);

    vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
        vtkSmartPointer<vtkRenderWindowInteractor>::New();
    renderWindowInteractor->SetRenderWindow(renderWindow);
    renderWindow->Render();
    renderWindowInteractor->Start();
    return 0;
}

我以一定角度旋转平面,但看到纹理不与平面一起旋转,我应该怎么做才能使纹理和平面一起旋转?

0 个答案:

没有答案