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

  Program:   View Generation Toolkit
  Module:    viewgen.h
  Language:  C++
  Date:      2002/05/27
  Version:   1.0

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

#ifndef __VIEWGEN_H__
#define __VIEWGEN_H__

#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtk3DSImporter.h"
#include "vtkLight.h"
#include "vtkRenderLargeImage.h"
#include "vtkTIFFWriter.h"
#include "vtkMath.h"
#include "vtkImageData.h"
#include <math.h>

const double PI = 3.1415926535897;
const double degtorad = PI/180.0;

class CViewGenerator
{
  float origin[3]; 
  float radius;

  vtkRenderer* Renderer;
  vtkRenderWindow* RenderWindow;
  vtkRenderWindowInteractor* IRender;
  vtk3DSImporter* Importer;

  // Width and height of the rendering window and
  // magnification of the large image
  int Width; int Height; int Magnification;
  
public:
  CViewGenerator(const char* f);
  ~CViewGenerator();

  void RemoveAllLights();
    
  void SetAmbientColor(float r, float g, float b);
  void SetBackground(float r, float g, float b);
  void SetMagnification(int m);
  void SetSize(int w, int h);
  
  void SetModelColor(float r, float g, float b);
  void SetModelAmbient(float p);
  void SetModelDiffuse(float p);
  void SetModelSpecular(float p);
  void SetModelOpacity(float p);
  void SetModelAmbientColor(float r, float g, float b);
  void SetModelDiffuseColor(float r, float g, float b);
  void SetModelSpecularColor(float r, float g, float b);
  void SetModelEdgeVisibility(bool ev);
  void SetModelEdgeColor(float r, float g, float b);

  void SetupSilhouetteRendering();

  // You must first setup all parameters of the rendering,
  // And then call Initialize. Otherwise the rendering will
  virtual void Initialize();
    virtual vtkLight* SetupLight(float r, float g, float b, float i);
  virtual vtkCamera* SetupCamera();

  // Sets up the view from given spherical coordinates
  void SetView(float phi, float theta);
  // In case of error returns NULL.
  // Returned pointer requires deletion
  vtkImageData* RenderCurrentView();
  // In case of error returns NULL.
  // Returned pointer requires deletion
  vtkImageData* RenderView(float phi, float theta);

  void WriteToTIFF(vtkImageData* data, const char* imgname);
  void WriteViewToTIFF(float phi, float theta, const char* imgname);
};

#endif
