


#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkCellArray.h>
#include <vtkFloatArray.h>
#include <vtkPoints.h>
#include <vtkPointData.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkTimerLog.h>


int main()
{
	//
	//  Create everything
	//
	vtkRenderer *ren = vtkRenderer::New();
	vtkRenderWindow *win = vtkRenderWindow::New();

	win->AddRenderer(ren);

	vtkActor *a1 = vtkActor::New();
	vtkPolyDataMapper *m1 = vtkPolyDataMapper::New();
	vtkActor *a2 = vtkActor::New();
	vtkPolyDataMapper *m2 = vtkPolyDataMapper::New();
	
	vtkPolyData *d1 = vtkPolyData::New();
	vtkPolyData *d2 = vtkPolyData::New();
	vtkPoints *p = vtkPoints::New(VTK_DOUBLE);
	vtkFloatArray *s = vtkFloatArray::New();
	s->SetNumberOfComponents(1);
	vtkCellArray *c1 = vtkCellArray::New();
	vtkCellArray *c2 = vtkCellArray::New();

	d1->SetPoints(p);
	d2->SetPoints(p);
	p->Delete();

	d1->SetPolys(c1);
	c1->Delete();

	d2->SetLines(c2);
	c2->Delete();

	d1->GetPointData()->SetScalars(s);
	s->Delete();
	//
	//  Fill in the data
	//
	int i, j, imax = 30;
	double x[3], w = 1.0;
	vtkIdType l[4], q[2];

	for(i=0; i<=imax; i++)
	{
		x[0] = 1.0 - w; x[1] = 1.0 - w; x[2] = -w;
		p->InsertNextPoint(x);
		s->InsertNextValue(float(i)/imax);

		x[0] = 1.0 + w; x[1] = 1.0 - w; x[2] = -w;
		p->InsertNextPoint(x);
		s->InsertNextValue(float(i)/imax);

		x[0] = 1.0 + w; x[1] = 1.0 + w; x[2] = -w;
		p->InsertNextPoint(x);
		s->InsertNextValue(float(i)/imax);

		x[0] = 1.0 - w; x[1] = 1.0 + w; x[2] = -w;
		p->InsertNextPoint(x);
		s->InsertNextValue(float(i)/imax);

		l[0] = 4*i + 0; 
		l[1] = 4*i + 1; 
		l[2] = 4*i + 2; 
		l[3] = 4*i + 3; 
		c1->InsertNextCell(4,l);

		q[0] = l[0]; q[1] = l[1];
		c2->InsertNextCell(2,q);

		q[0] = l[1]; q[1] = l[2];
		c2->InsertNextCell(2,q);

		q[0] = l[2]; q[1] = l[3];
		c2->InsertNextCell(2,q);

		q[0] = l[3]; q[1] = l[0];
		c2->InsertNextCell(2,q);

		w *= 0.5;
	}		
		
	m1->SetInput(d1);
	a1->SetMapper(m1);
	ren->AddProp(a1);

	m2->SetInput(d2);
	a2->SetMapper(m2);
	ren->AddProp(a2);

	vtkTimerLog *t = vtkTimerLog::New();
	ren->GetActiveCamera()->SetParallelProjection(1);
	ren->ResetCamera();
	int sp = 100;
	w = 1.0;
	double fact = pow(0.5,1.0/sp);
	for(i=0; i<=imax; i++)
	{
	  for(j=0; j<sp; j++)
	    {
		win->Render();

		t->StartTimer();
		do
		{
			t->StopTimer();
		}
		while(t->GetElapsedTime() < 0.01);

		ren->GetActiveCamera()->SetParallelScale(fact*ren->GetActiveCamera()->GetParallelScale());
	    }

	  cout << w << endl;
	  w *= 0.5;
	}


	return 0;
}

