Advertisement
donlk

vtkOBJReader + LOD based rendering

May 26th, 2016
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1.     vtkSmartPointer<vtkOBJReader> reader = vtkSmartPointer<vtkOBJReader>::New();
  2.     reader->SetFileName(filename.c_str());
  3.     reader->Update();
  4.  
  5.     vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
  6.     mapper->SetInputConnection(reader->GetOutputPort());
  7.  
  8.     // Read the image data from a file
  9.     vtkSmartPointer<vtkJPEGReader> imgReader = vtkSmartPointer<vtkJPEGReader>::New();
  10.     imgReader->SetFileName(texturePath.c_str());
  11.     imgReader->Update();
  12.  
  13.     // Create texture object
  14.     vtkSmartPointer<vtkTexture> texture = vtkSmartPointer<vtkTexture>::New();
  15.     texture->SetInputConnection(imgReader->GetOutputPort());
  16.     texture->InterpolateOn();
  17.  
  18.     vtkSmartPointer<vtkQuadricLODActor> actor = vtkSmartPointer<vtkQuadricLODActor>::New();
  19.     actor->SetMapper(mapper);
  20.     actor->GetProperty()->SetInterpolationToFlat();
  21.     actor->SetTexture(texture);
  22.  
  23.     // A renderer and render window
  24.     vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
  25.     renderer->SetBackground(0.2, 0.3, 0.4);
  26.     vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
  27.     renderWindow->AddRenderer(renderer);
  28.  
  29.     // An interactor
  30.     vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<
  31.         vtkRenderWindowInteractor>::New();
  32.     renderWindowInteractor->SetRenderWindow(renderWindow);
  33.     renderWindowInteractor->SetDesiredUpdateRate(15);
  34.  
  35.     renderer->AddActor(actor);
  36.  
  37.     renderWindow->Render();
  38.     renderWindowInteractor->Start();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement