1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    TestAVIWriter.cxx
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 // .NAME Test of vtkAVIWriter
16 // .SECTION Description
17 //
18 
19 #include "vtkAVIWriter.h"
20 #include "vtkImageCast.h"
21 #include "vtkImageData.h"
22 #include "vtkImageMandelbrotSource.h"
23 #include "vtkImageMapToColors.h"
24 #include "vtkLookupTable.h"
25 #include "vtksys/SystemTools.hxx"
26 
TestAVIWriter(int vtkNotUsed (argc),char * vtkNotUsed (argv)[])27 int TestAVIWriter(int vtkNotUsed(argc), char* vtkNotUsed(argv)[])
28 {
29   int err = 0;
30   int cc = 0;
31   int exists = 0;
32   unsigned long length = 0;
33   vtkImageMandelbrotSource* Fractal0 = vtkImageMandelbrotSource::New();
34   Fractal0->SetWholeExtent( 0, 247, 0, 247, 0, 0 );
35   Fractal0->SetProjectionAxes( 0, 1, 2 );
36   Fractal0->SetOriginCX( -1.75, -1.25, 0, 0 );
37   Fractal0->SetSizeCX( 2.5, 2.5, 2, 1.5 );
38   Fractal0->SetMaximumNumberOfIterations( 100);
39 
40   vtkImageCast* cast = vtkImageCast::New();
41   cast->SetInputConnection(Fractal0->GetOutputPort());
42   cast->SetOutputScalarTypeToUnsignedChar();
43 
44   vtkLookupTable* table = vtkLookupTable::New();
45   table->SetTableRange(0, 100);
46   table->SetNumberOfColors(100);
47   table->Build();
48   table->SetTableValue(99, 0, 0, 0);
49 
50   vtkImageMapToColors* colorize = vtkImageMapToColors::New();
51   colorize->SetOutputFormatToRGB();
52   colorize->SetLookupTable(table);
53   colorize->SetInputConnection(cast->GetOutputPort());
54 
55   vtkAVIWriter *w = vtkAVIWriter::New();
56   w->SetInputConnection(colorize->GetOutputPort());
57   w->SetFileName("TestAVIWriter.avi");
58   cout << "Writing file TestAVIWriter.avi..." << endl;
59   w->Start();
60   for ( cc = 2; cc < 99; cc ++ )
61     {
62     cout << ".";
63     Fractal0->SetMaximumNumberOfIterations(cc);
64     table->SetTableRange(0, cc);
65     table->SetNumberOfColors(cc);
66     table->ForceBuild();
67     table->SetTableValue(cc-1, 0, 0, 0);
68     w->Write();
69     }
70   w->End();
71   cout << endl;
72   cout << "Done writing file TestAVIWriter.avi..." << endl;
73   w->Delete();
74 
75   exists = (int) vtksys::SystemTools::FileExists("TestAVIWriter.avi");
76   length = vtksys::SystemTools::FileLength("TestAVIWriter.avi");
77   cout << "TestAVIWriter.avi file exists: " << exists << endl;
78   cout << "TestAVIWriter.avi file length: " << length << endl;
79   if (!exists)
80     {
81     err = 3;
82     cerr << "ERROR: 3 - Test failing because TestAVIWriter.avi file doesn't exist..." << endl;
83     }
84   if (0==length)
85     {
86     err = 4;
87     cerr << "ERROR: 4 - Test failing because TestAVIWriter.avi file has zero length..." << endl;
88     }
89 
90   colorize->Delete();
91   table->Delete();
92   cast->Delete();
93   Fractal0->Delete();
94 
95   // err == 0 means test passes...
96   //
97   return err;
98 }
99