/*========================================================================= Program: Visualization Toolkit Module: TestMetaIO.cxx Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen All rights reserved. See Copyright.txt or http://www.kitware.com/Copyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ // .NAME Test of WriteToMemory flag for PNG/JPEG/BMP Writers // .SECTION Description // #include #include #include #include #include #include #include int TestWriteToMemory(int argc, char *argv[]) { if ( argc <= 1 ) { cout << "Usage: " << argv[0] << " " << endl; return EXIT_FAILURE; } int extent[6] = {0, 99, 0, 99, 0, 0}; vtkSmartPointer imageSource = vtkSmartPointer::New(); imageSource->SetExtent(extent); imageSource->SetScalarTypeToUnsignedChar(); imageSource->SetNumberOfScalarComponents(3); imageSource->SetDrawColor(127, 45, 255); imageSource->FillBox(0, 99, 0, 99); imageSource->SetDrawColor(255,255,255); imageSource->FillBox(40, 70, 20, 50); imageSource->Update(); vtkSmartPointer castFilter = vtkSmartPointer::New(); castFilter->SetOutputScalarTypeToUnsignedChar (); castFilter->SetInputConnection(imageSource->GetOutputPort()); castFilter->Update(); vtkSmartPointer writer; std::string filename = argv[1]; std::string fileext = filename.substr(filename.find_last_of('.') + 1); // Delete any existing files to prevent false failures if (vtksys::SystemTools::FileExists(filename)) { vtksys::SystemTools::RemoveFile(filename); } if (fileext == "png") { vtkSmartPointer pngWriter = vtkSmartPointer::New(); pngWriter->WriteToMemoryOn(); writer = pngWriter; } else if (fileext == "jpeg" || fileext == "jpg") { vtkSmartPointer jpgWriter = vtkSmartPointer::New(); jpgWriter->WriteToMemoryOn(); writer = jpgWriter; } else if (fileext == "bmp") { vtkSmartPointer bmpWriter = vtkSmartPointer::New(); bmpWriter->WriteToMemoryOn(); writer = bmpWriter; } writer->SetFileName(filename.c_str()); writer->SetInputConnection(castFilter->GetOutputPort()); writer->Update(); writer->Write(); // With WriteToMemory true no file should be written if (!vtksys::SystemTools::FileExists(filename)) { return EXIT_SUCCESS; } else { return EXIT_FAILURE; } }