实例63:纹理映射
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkRenderingFreeType);
VTK_MODULE_INIT(vtkInteractionStyle);
#include <vtkSmartPointer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkActor.h>
#include <vtkPolyDataMapper.h>
#include <vtkTransformTextureCoords.h>
#include <vtkTexture.h>
#include <vtkTextureMapToSphere.h>
#include <vtkTextureMapToCylinder.h>
#include <vtkBMPReader.h>
#include <vtkTexturedSphereSource.h>
#include <vtkXMLPolyDataReader.h>
//测试:../data/masonry.bmp ../data/cow.vtp
int main (int argc, char *argv[])
{
double translate[3];
translate[0] = 10.0;
translate[1] = 0.0;
translate[2] = 0.0;
std::cout << translate[0] << ", "
<< translate[1] << ", "
<< translate[2] << "\n";
vtkSmartPointer<vtkBMPReader> texReader =
vtkSmartPointer<vtkBMPReader>::New();
texReader->SetFileName("C:\\Users\\Administrator\\Desktop\\VTK2\\hellovtk\\vtk_图像处理学习\\第六章_图像处理\\data\\masonry.bmp");//读取纹理图像
vtkSmartPointer<vtkTexture> texture =
vtkSmartPointer<vtkTexture>::New();
texture->SetInputConnection(texReader->GetOutputPort());
vtkSmartPointer<vtkXMLPolyDataReader> modelReader =
vtkSmartPointer<vtkXMLPolyDataReader>::New();
modelReader->SetFileName("C:\\Users\\Administrator\\Desktop\\VTK2\\hellovtk\\vtk_图像处理学习\\第六章_图像处理\\data\\cow.vtp");//读取模型
vtkSmartPointer<vtkTextureMapToCylinder> texturemap =
vtkSmartPointer<vtkTextureMapToCylinder>::New();
texturemap->SetInputConnection(modelReader->GetOutputPort());
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(texturemap->GetOutputPort());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper( mapper );
actor->SetTexture( texture );
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(actor);
renderer->SetBackground(1.0, 1.0, 1.0);
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer( renderer );
vtkSmartPointer<vtkRenderWindowInteractor> renWinInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renWinInteractor->SetRenderWindow( renderWindow );
renderWindow->SetSize(640, 480);
renderWindow->Render();
renderWindow->SetWindowName("TextureMap");
renderWindow->Render();
renderWindow->Render();
renWinInteractor->Start();
return EXIT_SUCCESS;
}