//====================================================================
//#
//#  pfFranFace.cxx                                    #####     
//#                                                   ##   ##
//#  Author(s): Paul Rajlich                          ##
//#  Email: prajlich@ncsa.uiuc.ed                     ##   ##
//#  Date created:                                     #####
//#
//#  Description: testing vtkActorToPF texturing.
//#    Based on franFace.tcl from VTK distribtion.
//#
//====================================================================

#include <stdlib.h>
#include <Performer/pf/pfChannel.h>
#include <Performer/pf/pfLightSource.h>
#include <Performer/pf/pfDCS.h>

#include "vtkPNMReader.h"
#include "vtkPolyDataReader.h"

#include "vtkActorToPFTranslator.h"

int main(int argc, char **argv) {

  pfInit();
  pfMultiprocess(PFMP_DEFAULT);  
  pfConfig();

  pfPipe *p = pfGetPipe(0);
  pfPipeWindow *pw = new pfPipeWindow(p);
  pw->setWinType(PFPWIN_TYPE_X);
  pw->setName("vtkActorToPF Fran Face");
  pw->setOriginSize(100, 100, 500, 500);
  pw->open();

  pfChannel *chan = new pfChannel(p);

  pfScene *scene;
  pfGeoState *gstate;
  pfLightSource *light;
  scene = new pfScene;
  gstate = new pfGeoState;
  gstate->setMode(PFSTATE_ENLIGHTING, PF_ON);
  gstate->setMode(PFSTATE_CULLFACE, PFCF_OFF);
  scene->setGState(gstate);

  light = new pfLightSource;
  light->setColor(PFLT_DIFFUSE, 1.0, 1.0, 1.0);
  light->setAmbient(0.3, 0.3, 0.3);
  scene->addChild(light);

  // --- vtk pipeline ---
  vtkPolyDataReader *cyber = vtkPolyDataReader::New();
    cyber->SetFileName("../vtkdata/fran_cut.vtk");

  vtkPolyDataMapper *cyberMapper = vtkPolyDataMapper::New();
    cyberMapper->SetInput(cyber->GetOutput());

  vtkPNMReader *pnm1 = vtkPNMReader::New();
    pnm1->SetFileName("../vtkdata/fran_cut.ppm");

  vtkTexture *atext = vtkTexture::New();
    atext->SetInput(pnm1->GetOutput());
    atext->InterpolateOn();

  vtkActor *cyberActor = vtkActor::New();
    cyberActor->SetMapper(cyberMapper);
    cyberActor->SetTexture(atext);


  // --- end vtk pipeline

  pfDCS *center = new pfDCS;
  center->setScale(8.0f, 8.0f, 8.0f);
  center->setTrans(0.0f, 3.0f, 1.0f);

  vtkActorToPFTranslator *cyberT = vtkActorToPFTranslator::New();
  cyberT->SetActor(cyberActor);
  cyberT->VerboseOn();
  cyberT->Init();
  center->addChild(cyberT->GetGeode());
  
  scene->addChild(center);
  chan->setScene(scene);
 
  float t = 0.0f;
  while (t < 20.0f) {
    pfSync();
    pfFrame();
    t = pfGetTime();
    center->setRot(t*20.0f+180.0, 90.0f, 0.0f);
  }
  pfExit();
}

  
  


