Index: Rendering/vtkTesting.cxx =================================================================== RCS file: /cvsroot/ParaView3/ParaView3/VTK/Rendering/vtkTesting.cxx,v retrieving revision 1.35 diff -u -r1.35 vtkTesting.cxx --- Rendering/vtkTesting.cxx 4 Oct 2008 13:59:30 -0000 1.35 +++ Rendering/vtkTesting.cxx 20 May 2009 18:54:26 -0000 @@ -18,9 +18,7 @@ #include "vtkWindowToImageFilter.h" #include "vtkPNGWriter.h" #include "vtkImageShiftScale.h" -#include "vtkJPEGWriter.h" #include "vtkImageDifference.h" -#include "vtkImageResample.h" #include "vtkPNGReader.h" #include "vtkRenderWindow.h" #include "vtkImageData.h" @@ -35,6 +33,10 @@ #include "vtkDoubleArray.h" #include "vtkFloatArray.h" +#include "vtkSmartPointer.h" +#define VTK_CREATE(type, name) \ + vtkSmartPointer name = vtkSmartPointer::New() + #include vtkStandardNewMacro(vtkTesting); @@ -349,7 +351,7 @@ //----------------------------------------------------------------------------- int vtkTesting::RegressionTest(double thresh, ostream &os) { - vtkWindowToImageFilter *rt_w2if = vtkWindowToImageFilter::New(); + VTK_CREATE(vtkWindowToImageFilter, rt_w2if); rt_w2if->SetInput(this->RenderWindow); unsigned int i; @@ -379,7 +381,6 @@ } int res = this->RegressionTest(rt_w2if->GetOutput(), thresh, os); - rt_w2if->Delete(); return res; } //----------------------------------------------------------------------------- @@ -387,7 +388,7 @@ { // do a get to compute the real value this->GetValidImageFileName(); - const char * tmpDir = this->GetTempDirectory(); + vtkstd::string tmpDir = this->GetTempDirectory(); // construct the names for the error images vtkstd::string validName = this->ValidImageFileName; @@ -405,32 +406,28 @@ } else // there was no valid image, so write one to the temp dir { - char* vImage = new char[strlen(tmpDir) + validName.size() + 30]; - sprintf(vImage, "%s/%s", tmpDir, validName.c_str()); - vtkPNGWriter *rt_pngw = vtkPNGWriter::New(); - rt_pngw->SetFileName(vImage); + vtkstd::string vImage = tmpDir + "/" + validName; + VTK_CREATE(vtkPNGWriter, rt_pngw); + rt_pngw->SetFileName(vImage.c_str()); rt_pngw->SetInput(image); rt_pngw->Write(); - rt_pngw->Delete(); - delete [] vImage; os << "" << this->ValidImageFileName << "" << endl; return FAILED; } - vtkSmartPointer rt_png = vtkSmartPointer::New(); + VTK_CREATE(vtkPNGReader, rt_png); rt_png->SetFileName(this->ValidImageFileName); rt_png->Update(); image->Update(); - vtkSmartPointer rt_id = - vtkSmartPointer::New(); + VTK_CREATE(vtkImageDifference, rt_id); - vtkImageClip* ic1 = vtkImageClip::New(); + VTK_CREATE(vtkImageClip, ic1); ic1->SetClipData(1); ic1->SetInput(image); - vtkImageClip* ic2 = vtkImageClip::New(); + VTK_CREATE(vtkImageClip, ic2); ic2->SetClipData(1); ic2->SetInput(rt_png->GetOutput()); @@ -454,11 +451,9 @@ rt_id->SetInput(ic1->GetOutput()); ic1->Update(); ic1->GetOutput()->GetExtent(ext1); - ic1->Delete(); rt_id->SetImage(ic2->GetOutput()); ic2->Update(); ic2->GetOutput()->GetExtent(ext2); - ic2->Delete(); double minError = VTK_DOUBLE_MAX; @@ -626,90 +621,53 @@ rt_id->Update(); // test the directory for writing - char* diff_small = new char[strlen(tmpDir) + validName.size() + 30]; - sprintf(diff_small, "%s/%s.diff.small.jpg", tmpDir, validName.c_str()); - FILE *rt_dout = fopen(diff_small,"wb"); + vtkstd::string diff_filename = tmpDir + "/" + validName; + vtkstd::string::size_type dot_pos = diff_filename.rfind("."); + if(dot_pos != vtkstd::string::npos) + { + diff_filename = diff_filename.substr(0, dot_pos); + } + diff_filename += ".diff.png"; + FILE *rt_dout = fopen(diff_filename.c_str(), "wb"); if (rt_dout) { fclose(rt_dout); - // write out the difference image scaled and gamma adjusted - // for the dashboard - int* rt_size = rt_png->GetOutput()->GetDimensions(); - double rt_magfactor=1.0; - if ( rt_size[1] > 250.0) - { - rt_magfactor = 250.0 / rt_size[1]; - } - vtkImageResample* rt_shrink = vtkImageResample::New(); - rt_shrink->SetInput(rt_id->GetOutput()); - rt_shrink->InterpolateOn(); - rt_shrink->SetAxisMagnificationFactor(0, rt_magfactor ); - rt_shrink->SetAxisMagnificationFactor(1, rt_magfactor ); - vtkImageShiftScale* rt_gamma = vtkImageShiftScale::New(); - rt_gamma->SetInput(rt_shrink->GetOutput()); + // write out the difference image gamma adjusted for the dashboard + VTK_CREATE(vtkImageShiftScale, rt_gamma); + rt_gamma->SetInputConnection(rt_id->GetOutputPort()); rt_gamma->SetShift(0); rt_gamma->SetScale(10); - vtkJPEGWriter* rt_jpegw_dashboard = vtkJPEGWriter::New(); - rt_jpegw_dashboard->SetFileName( diff_small ); - rt_jpegw_dashboard->SetInput(rt_gamma->GetOutput()); - rt_jpegw_dashboard->SetQuality(85); - rt_jpegw_dashboard->Write(); + VTK_CREATE(vtkPNGWriter, rt_pngw); + rt_pngw->SetFileName(diff_filename.c_str()); + rt_pngw->SetInputConnection(rt_gamma->GetOutputPort()); + rt_pngw->Write(); // write out the image that was generated - rt_shrink->SetInput(ic1->GetOutput()); - rt_jpegw_dashboard->SetInput(rt_shrink-> GetOutput()); - char* valid_test_small = new char[strlen(tmpDir) + validName.size() + 30]; - sprintf(valid_test_small, "%s/%s.test.small.jpg", tmpDir, - validName.c_str()); - rt_jpegw_dashboard->SetFileName(valid_test_small); - rt_jpegw_dashboard->Write(); - - // write out the valid image that matched - rt_shrink->SetInput(ic2->GetOutput()); - rt_jpegw_dashboard-> SetInput (rt_shrink->GetOutput()); - char* valid = new char[strlen(tmpDir) + validName.size() + 30]; - sprintf(valid, "%s/%s.small.jpg", tmpDir, validName.c_str()); - rt_jpegw_dashboard-> SetFileName( valid); - rt_jpegw_dashboard->Write(); - rt_jpegw_dashboard->Delete(); - - os << ""; - os << valid_test_small; - delete [] valid_test_small; - os << ""; - os << ""; - os << diff_small; - os << ""; - os << ""; - os << valid; - os << ""; - - delete [] valid; - - char* vImage = new char[strlen(tmpDir) + validName.size() + 30]; - sprintf(vImage, "%s/%s", tmpDir, validName.c_str()); - vtkPNGWriter *rt_pngw = vtkPNGWriter::New(); - rt_pngw->SetFileName(vImage); + vtkstd::string vImage = tmpDir + "/" + validName; + rt_pngw->SetFileName(vImage.c_str()); rt_pngw->SetInput(image); rt_pngw->Write(); - rt_pngw->Delete(); - delete [] vImage; - - rt_shrink->Delete(); - rt_gamma->Delete(); + os << ""; + os << vImage; + os << ""; + os << ""; + os << diff_filename; + os << ""; + os << ""; + os << this->ValidImageFileName; + os << ""; } - delete [] diff_small; return FAILED; } //----------------------------------------------------------------------------- int vtkTesting::Test(int argc, char *argv[], vtkRenderWindow *rw, double thresh ) { - vtkTesting * testing = vtkTesting::New(); + VTK_CREATE(vtkTesting, testing); int i; for (i = 0; i < argc; ++i) { @@ -718,7 +676,6 @@ if (testing->IsInteractiveModeSpecified()) { - testing->Delete(); return DO_INTERACTOR; } @@ -735,11 +692,9 @@ { testing->SetRenderWindow(rw); int res = testing->RegressionTest(thresh); - testing->Delete(); return res; } - testing->Delete(); return NOT_RUN; } //----------------------------------------------------------------------------- Index: Wrapping/Python/vtk/test/Testing.py =================================================================== RCS file: /cvsroot/ParaView3/ParaView3/VTK/Wrapping/Python/vtk/test/Testing.py,v retrieving revision 1.8 diff -u -r1.8 Testing.py --- Wrapping/Python/vtk/test/Testing.py 5 Dec 2005 14:42:33 -0000 1.8 +++ Wrapping/Python/vtk/test/Testing.py 20 May 2009 18:54:26 -0000 @@ -267,13 +267,13 @@ print "", print "%d "%err_index - print "", - print "%s "%(img_base + '.test.small.jpg') + print "", + print "%s "%(img_base + '.png') - print "", - print "%s "%(img_base + '.diff.small.jpg') - print "", - print "%s "%(img_base + '.small.jpg') + print "", + print "%s "%(img_base + '.diff.png') + print "", + print "%s "%(img_base + '.valid.png') def _printDartImageSuccess(img_err, err_index): @@ -291,49 +291,28 @@ """Writes all the necessary images when an image comparison failed.""" f_base, f_ext = os.path.splitext(img_fname) - - # write out the difference file in full. - pngw = vtk.vtkPNGWriter() - pngw.SetFileName(_getTempImagePath(f_base + ".diff.png")) - pngw.SetInput(idiff.GetOutput()) - pngw.Write() - # write the difference image scaled and gamma adjusted for the - # dashboard. - sz = pngr.GetOutput().GetDimensions() - if sz[1] <= 250.0: - mag = 1.0 - else: - mag = 250.0/sz[1] - - shrink = vtk.vtkImageResample() - shrink.SetInput(idiff.GetOutput()) - shrink.InterpolateOn() - shrink.SetAxisMagnificationFactor(0, mag) - shrink.SetAxisMagnificationFactor(1, mag) - + # write the difference image gamma adjusted for the dashboard. gamma = vtk.vtkImageShiftScale() - gamma.SetInput(shrink.GetOutput()) + gamma.SetInputConnection(idiff.GetOutputPort()) gamma.SetShift(0) gamma.SetScale(10) - jpegw = vtk.vtkJPEGWriter() - jpegw.SetFileName(_getTempImagePath(f_base + ".diff.small.jpg")) - jpegw.SetInput(gamma.GetOutput()) - jpegw.SetQuality(85) - jpegw.Write() - - # write out the image that was generated. - shrink.SetInput(idiff.GetInput()) - jpegw.SetInput(shrink.GetOutput()) - jpegw.SetFileName(_getTempImagePath(f_base + ".test.small.jpg")) - jpegw.Write() + pngw = vtk.vtkPNGWriter() + pngw.SetFileName(_getTempImagePath(f_base + ".diff.png")) + pngw.SetInputConnection(gamma.GetOutputPort()) + pngw.Write() + + # Write out the image that was generated. Write it out as full so that + # it may be used as a baseline image if the tester deems it valid. + pngw.SetInput(idiff.GetInput()) + pngw.SetFileName(_getTempImagePath(f_base + ".png")) + pngw.Write() # write out the valid image that matched. - shrink.SetInput(idiff.GetImage()) - jpegw.SetInput(shrink.GetOutput()) - jpegw.SetFileName(_getTempImagePath(f_base + ".small.jpg")) - jpegw.Write() + pngw.SetInput(idiff.GetImage()) + pngw.SetFileName(_getTempImagePath(f_base + ".valid.png")) + pngw.Write() def main(cases):