MCPcopy Create free account
hub / github.com/Kitware/VTK / TestWriteToMemory

Function TestWriteToMemory

IO/Image/Testing/Cxx/TestWriteToMemory.cxx:18–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16#include <iostream>
17
18int TestWriteToMemory(int argc, char* argv[])
19{
20 if (argc <= 1)
21 {
22 std::cout << "Usage: " << argv[0] << " <output file name>" << std::endl;
23 return EXIT_FAILURE;
24 }
25
26 int extent[6] = { 0, 99, 0, 99, 0, 0 };
27 vtkSmartPointer<vtkImageCanvasSource2D> imageSource =
28 vtkSmartPointer<vtkImageCanvasSource2D>::New();
29 imageSource->SetExtent(extent);
30 imageSource->SetScalarTypeToUnsignedChar();
31 imageSource->SetNumberOfScalarComponents(3);
32 imageSource->SetDrawColor(127, 45, 255);
33 imageSource->FillBox(0, 99, 0, 99);
34 imageSource->SetDrawColor(255, 255, 255);
35 imageSource->FillBox(40, 70, 20, 50);
36 imageSource->Update();
37
38 vtkSmartPointer<vtkImageCast> castFilter = vtkSmartPointer<vtkImageCast>::New();
39 castFilter->SetOutputScalarTypeToUnsignedChar();
40 castFilter->SetInputConnection(imageSource->GetOutputPort());
41 castFilter->Update();
42
43 vtkSmartPointer<vtkImageWriter> writer;
44
45 std::string filename = argv[1];
46 std::string fileext = filename.substr(filename.find_last_of('.') + 1);
47
48 // Delete any existing files to prevent false failures
49 if (vtksys::SystemTools::FileExists(filename))
50 {
51 vtksys::SystemTools::RemoveFile(filename);
52 }
53
54 if (fileext == "png")
55 {
56 vtkSmartPointer<vtkPNGWriter> pngWriter = vtkSmartPointer<vtkPNGWriter>::New();
57 pngWriter->WriteToMemoryOn();
58 writer = pngWriter;
59 }
60 else if (fileext == "jpeg" || fileext == "jpg")
61 {
62 vtkSmartPointer<vtkJPEGWriter> jpgWriter = vtkSmartPointer<vtkJPEGWriter>::New();
63 jpgWriter->WriteToMemoryOn();
64 writer = jpgWriter;
65 }
66 else if (fileext == "bmp")
67 {
68 vtkSmartPointer<vtkBMPWriter> bmpWriter = vtkSmartPointer<vtkBMPWriter>::New();
69 bmpWriter->WriteToMemoryOn();
70 writer = bmpWriter;
71 }
72
73 writer->SetFileName(filename.c_str());
74 writer->SetInputConnection(castFilter->GetOutputPort());
75 writer->Update();

Callers

nothing calls this directly

Calls 10

FillBoxMethod · 0.80
NewFunction · 0.50
SetExtentMethod · 0.45
UpdateMethod · 0.45
SetInputConnectionMethod · 0.45
GetOutputPortMethod · 0.45
SetFileNameMethod · 0.45
c_strMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected