#include <iostream>
#include "vtkConeSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderWindow.h"
#include "vtkCamera.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkTextActor.h"
#include "vtkTextProperty.h"
#include "vtkGL2PSExporter.h"

void TestGL2PS(vtkGL2PSExporter *exp)
{
  //  EPS
  exp->SetFilePrefix("test");
  exp->Write();

  exp->SetFilePrefix("test1");
  exp->SetSortToOff();
  exp->Write();

  exp->SetFilePrefix("test2");
  exp->SetSortToBSP();
  exp->Write();

  // PS
  exp->SetFilePrefix("test");
  exp->SetFileFormatToPS();
  exp->SetSortToBSP();
  exp->Write();

  // PDF
  exp->SetFilePrefix("test");
  exp->SetFileFormatToPDF();
  // no compression
  exp->CompressOff();
  exp->Write();

  exp->SetFilePrefix("test");
  exp->CompressOn();
  exp->Write();

  // TeX
  exp->SetFilePrefix("test");
  exp->SetFileFormatToTeX();
  exp->Write();
  
  // Test Write3DPropsAsRasterImage: takes forever!
  cout << "\n** Testing with Write3DPropsAsRasterImageOn **\n"
       << "***** This will take a long while on valgrind! *****\n\n";
  exp->SetFileFormatToEPS();
  exp->SetFilePrefix("testraster");
  exp->Write3DPropsAsRasterImageOn();
  // Turn on Debug to see if the file is being written.
  exp->DebugOn();
  exp->Write();
  exp->DebugOff();
}


int main( int argc, char *argv[] )
{
  vtkConeSource *cone = vtkConeSource::New();
  cone->SetHeight( 3.0 );
  cone->SetRadius( 1.0 );
  cone->SetResolution( 10 );
  
  vtkPolyDataMapper *coneMapper = vtkPolyDataMapper::New();
  coneMapper->SetInput( cone->GetOutput() );

  vtkActor *coneActor = vtkActor::New();
  coneActor->SetMapper( coneMapper );

  vtkTextActor *txt = vtkTextActor::New();
  txt->SetDisplayPosition(20, 10);
  txt->SetInput("This is test\nmultiline\ninput\ndata.");
  vtkTextProperty *tprop = txt->GetTextProperty();
  tprop->SetFontSize(10);
  tprop->SetFontFamilyToArial();  
  tprop->SetJustificationToCentered();
  tprop->BoldOn();
  tprop->ItalicOn();
  tprop->ShadowOn();
  tprop->SetColor(0, 0, 1);

  vtkRenderer *ren1= vtkRenderer::New();
  ren1->AddActor( coneActor );
  ren1->AddActor2D(txt);
  ren1->SetBackground( 0.1, 0.2, 0.4 );

  vtkRenderWindow *renWin = vtkRenderWindow::New();
  renWin->AddRenderer( ren1 );
  renWin->SetSize( 100, 100 );

  int i;
  for (i = 0; i < 360; i += 45)
    {
    renWin->Render();
    ren1->GetActiveCamera()->Azimuth(45);
    }

  // Now use GL2PS.
  vtkGL2PSExporter *exp = vtkGL2PSExporter::New();
  exp->SetRenderWindow(renWin);

  // --------------------------------------------------
  TestGL2PS(exp);
  // --------------------------------------------------

  exp->Delete();
  cone->Delete();
  coneMapper->Delete();
  coneActor->Delete();
  txt->Delete();
  ren1->Delete();
  renWin->Delete();

  return 0;
}


