//=========================================================================
//#
//#  vtkActorToPFTranslatorParallel.h                 ##   ##
//#                                                   ##   ## 
//#  Authors: Paul Rajlich                            #######
//#  Email: prajlich@ncsa.uiuc.edu                    ##   ##
//#  Date created:                                    ##   ##
//#
//#  Description: parallel translator. Allows you to fork off seperate
//#    vtk processes that feed a shared Performer scenegraph. Translator
//#    is allocated from shared memory.
//#
//#    In the vtk process, Update() is called to update the vtkpipeline.
//#    If there is new geometry, it will be translated and stored. The
//#    geometry is double buffered so that Performer can continue to render
//#    until the new geometry is available.
//#
//#    In the Performer process, during scenegraph traversal, pfUpdate()
//#    is called to check for new geometry. If new geometry is available
//#    it is put into the scenegraph and the geometry buffers are swapped.
//#
//=========================================================================
//# Copyright (C) 1997-2006 Paul Rajlich, NCSA
//# Distributed under the terms of the GNU Library General Public License (LGPL)
//# as published by the Free Software Foundation
//=========================================================================

#ifndef __vtkActorToPFTranslatorParallel_h
#define __vtkActorToPFTranslatorParallel_h

#include "vtkActorToPF.h"

// pre-traversal callback declaration.
int updateVTKFuncP(pfTraverser *trav, void *userData);

class VTK_EXPORT vtkActorToPFTranslatorParallel : public vtkObject
{
  public:
  void * operator new (size_t size); // pfMalloc (shared mem)
  vtkActorToPFTranslatorParallel();

  static vtkActorToPFTranslatorParallel *New() {
    return new vtkActorToPFTranslatorParallel();
  } 
  static vtkActorToPFTranslatorParallel *New(vtkActor *actor, pfGeode *geode = NULL) {
    vtkActorToPFTranslatorParallel *newT = new vtkActorToPFTranslatorParallel();
    newT->SetActor(actor);
    newT->SetGeode(geode);
    newT->Init();
    return newT;
  }
  const char *GetClassName() {return "vtkActorToPFTranslatorParallel";}
  void PrintSelf(ostream& os, vtkIndent indent);

  // init... register Performer callback
  virtual void Init();

  // update vtk pipeline and translate (Execute()) if necessary
  virtual void Update();

  // check to see if new geometry is available and swap if so
  virtual void pfUpdate();

  // must be done before Init()...
  void SetActor(vtkActor *actor) {
    theActor = actor;
    this->Modified();
  }
  vtkActor *GetActor() {
    return theActor;
  }

  // set theGeode to existing geode. WARNING: geode's GSets will be
  // replaced with those from translation.
  // must be done before Init()...
  void SetGeode(pfGeode *geode) {
    theGeode = geode;
    this->Modified();
  }
  pfGeode *GetGeode() {
    return theGeode;
  }

  // Turn on/off all of the debugging output
  vtkSetMacro(Verbose, int);
  vtkGetMacro(Verbose, int);
  vtkBooleanMacro(Verbose, int);

  pfGeoSet **GetNewGeoSets() {
    return newGeoSets;
  }
 
  // public so that translation can be called explicitly...
  void Execute();

  protected:
  vtkTimeStamp ExecuteTime; // look at vtkSource class
  vtkActor *theActor;
  pfGeode *theGeode;
  pfGeoSet *newGeoSets[4]; // double buffering of gsets
  int Verbose, Swap;
};

#endif
