查看: 1969|回复: 0
|
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" );
for( int a=0;a<3;a++)
{
//create a 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.0+b[a], 1.0+b[a], 1.0+b[a]);
//to rotate the plane around the center of the plane, aligning the plane normal with the specified normal
plane1->SetNormal(1.0,1.0, 1.0);
// plane1->SetPoint1(width,0,0);
//plane1->SetPoint2(0,height,0);
//Apply the texture
vtkSmartPointer<vtkTexture> texture =
vtkSmartPointer<vtkTexture>::New();
texture->SetInputConnection(jPEGReader->GetOutputPort());
vtkSmartPointer<vtkTextureMapToPlane> texturePlane =
vtkSmartPointer<vtkTextureMapToPlane>::New();
texturePlane->SetInputConnection(plane1->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);
// Visualize the textured plane
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(texturedPlane);
renderer->SetBackground(.1, .2, .3);// Background color dark blue
renderer->ResetCamera();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
renderWindow->Render();
renderWindowInteractor->Start();
return 0;
}
}
我想要创建很多个plane然后把texture放进plane里面。想问为什么只有一个plane出来,要怎样弄很多plane?
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|