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

Method RequestData

IO/Image/vtkJSONImageWriter.cxx:48–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46//------------------------------------------------------------------------------
47
48int vtkJSONImageWriter::RequestData(vtkInformation* vtkNotUsed(request),
49 vtkInformationVector** inputVector, vtkInformationVector* vtkNotUsed(outputVector))
50{
51 this->SetErrorCode(vtkErrorCode::NoError);
52
53 vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
54 vtkImageData* input = vtkImageData::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
55
56 // Error checking
57 if (input == nullptr)
58 {
59 vtkErrorMacro(<< "Write:Please specify an input!");
60 return 0;
61 }
62 if (!this->FileName)
63 {
64 vtkErrorMacro(<< "Write:Please specify either a FileName or a file prefix and pattern");
65 this->SetErrorCode(vtkErrorCode::NoFileNameError);
66 return 0;
67 }
68
69 // Write
70 this->InvokeEvent(vtkCommand::StartEvent);
71 vtkCharArray* validMask =
72 vtkArrayDownCast<vtkCharArray>(input->GetPointData()->GetArray("vtkValidPointMask"));
73
74 vtksys::ofstream file(this->FileName, ios::out);
75 if (file.fail())
76 {
77 vtkErrorMacro("RecursiveWrite: Could not open file " << this->FileName);
78 this->SetErrorCode(vtkErrorCode::CannotOpenFileError);
79 return 0;
80 }
81 file << "{"
82 << "\"filename\" : \"" << this->FileName << "\""
83 << ",\n\"dimensions\": [" << input->GetDimensions()[0] << ", " << input->GetDimensions()[1]
84 << ", " << input->GetDimensions()[2] << "]"
85 << ",\n\"origin\": [" << input->GetOrigin()[0] << ", " << input->GetOrigin()[1] << ", "
86 << input->GetOrigin()[2] << "]"
87 << ",\n\"spacing\": [" << input->GetSpacing()[0] << ", " << input->GetSpacing()[1] << ", "
88 << input->GetSpacing()[2] << "]";
89
90 // Write all arrays
91 int nbArrays = input->GetPointData()->GetNumberOfArrays();
92 for (int i = 0; i < nbArrays; ++i)
93 {
94 vtkDataArray* array = input->GetPointData()->GetArray(i);
95 // We only dump scalar values
96 if (array->GetNumberOfComponents() != 1 || !strcmp(array->GetName(), "vtkValidPointMask"))
97 {
98 continue;
99 }
100 if (this->ArrayName && strlen(this->ArrayName) > 0 &&
101 strcmp(array->GetName(), this->ArrayName) != 0)
102 {
103 continue;
104 }
105 file << ",\n\"" << array->GetName() << "\": [";

Callers

nothing calls this directly

Calls 15

GetInformationObjectMethod · 0.80
InvokeEventMethod · 0.80
GetMethod · 0.45
GetArrayMethod · 0.45
GetPointDataMethod · 0.45
GetDimensionsMethod · 0.45
GetOriginMethod · 0.45
GetSpacingMethod · 0.45
GetNumberOfArraysMethod · 0.45
GetNumberOfComponentsMethod · 0.45
GetNameMethod · 0.45
GetNumberOfTuplesMethod · 0.45

Tested by

no test coverage detected