TestVBOPLYMapper.cxx 2.88 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*=========================================================================

  Program:   Visualization Toolkit

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/

#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkActor.h"
#include "vtkCellArray.h"
#include "vtkPointData.h"
#include "vtkPolyDataNormals.h"
#include "vtkVBOPolyDataMapper.h"
#include "vtkPLYReader.h"
#include "vtkNew.h"
25
#include "vtkProperty.h"
Ken Martin's avatar
Ken Martin committed
26
#include "vtkLightKit.h"
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

#include "vtkTimerLog.h"

#include "vtkRegressionTestImage.h"
#include "vtkTestUtilities.h"

//----------------------------------------------------------------------------
int TestVBOPLYMapper(int argc, char *argv[])
{
  vtkNew<vtkActor> actor;
  vtkNew<vtkVBOPolyDataMapper> mapper;
  vtkNew<vtkRenderer> renderer;
  renderer->SetBackground(0.0, 0.0, 0.0);
  vtkNew<vtkRenderWindow> renderWindow;
  renderWindow->SetSize(300, 300);
  renderWindow->AddRenderer(renderer.Get());
  renderer->AddActor(actor.Get());
Ken Martin's avatar
Ken Martin committed
44 45 46 47
  vtkNew<vtkLightKit> lightKit;
  lightKit->AddLightsToRenderer(renderer.Get());


48
  const char* fileName = vtkTestUtilities::ExpandDataFileName(argc, argv,
49
                                                              "Data/dragon.ply");
50 51 52 53 54 55

  vtkNew<vtkPLYReader> reader;
  reader->SetFileName(fileName);
  reader->Update();
  vtkNew<vtkPolyDataNormals> computeNormals;
  computeNormals->SetInputConnection(reader->GetOutputPort());
Ken Martin's avatar
Ken Martin committed
56
  computeNormals->FlipNormalsOn();
57 58 59 60
  computeNormals->Update();

  mapper->SetInputConnection(computeNormals->GetOutputPort());
  actor->SetMapper(mapper.Get());
Ken Martin's avatar
Ken Martin committed
61
  actor->GetProperty()->SetAmbientColor(0.2, 0.2, 1.0);
Ken Martin's avatar
Ken Martin committed
62
  actor->GetProperty()->SetDiffuseColor(1.0, 0.65, 0.7);
63
  actor->GetProperty()->SetSpecularColor(1.0, 1.0, 1.0);
Ken Martin's avatar
Ken Martin committed
64
  actor->GetProperty()->SetSpecular(0.5);
65 66
  actor->GetProperty()->SetDiffuse(0.7);
  actor->GetProperty()->SetAmbient(0.5);
Ken Martin's avatar
Ken Martin committed
67
  actor->GetProperty()->SetSpecularPower(20.0);
68
  actor->GetProperty()->SetOpacity(1.0);
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92

  vtkNew<vtkRenderWindowInteractor> interactor;
  interactor->SetRenderWindow(renderWindow.Get());
  renderWindow->SetMultiSamples(0);
  interactor->Initialize();

  vtkNew<vtkTimerLog> timer;
  double time(0.0);
  for (int i = 0; i < 10; ++i)
    {
    timer->StartTimer();
    renderWindow->Render();
    timer->StopTimer();
    cout << "Rendering frame " << i << ": " << timer->GetElapsedTime() << endl;
    time += timer->GetElapsedTime();
    }
  cout << "Average time: " << time / 10.0 << endl;

  interactor->Start();

  delete [] fileName;

  return EXIT_SUCCESS;
}