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

Method Write

IO/Export/vtkJSONDataSetWriter.cxx:182–295  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

180
181//------------------------------------------------------------------------------
182void vtkJSONDataSetWriter::Write(vtkDataSet* dataset)
183{
184 vtkImageData* imageData = vtkImageData::SafeDownCast(dataset);
185 vtkPolyData* polyData = vtkPolyData::SafeDownCast(dataset);
186 this->ValidDataSet = false;
187
188 // Get input and check data
189 if (dataset == nullptr)
190 {
191 vtkErrorMacro(<< "No data to write!");
192 return;
193 }
194
195 // Capture vtkDataSet definition
196 std::stringstream metaJsonFile;
197 metaJsonFile << "{\n";
198 metaJsonFile << " \"vtkClass\": \"" << dataset->GetClassName() << "\"";
199
200 // ImageData
201 if (imageData)
202 {
203 this->ValidDataSet = true;
204
205 // Spacing
206 metaJsonFile << ",\n \"spacing\": [" << imageData->GetSpacing()[0] << ", "
207 << imageData->GetSpacing()[1] << ", " << imageData->GetSpacing()[2] << "]";
208
209 // Origin
210 metaJsonFile << ",\n \"origin\": [" << imageData->GetOrigin()[0] << ", "
211 << imageData->GetOrigin()[1] << ", " << imageData->GetOrigin()[2] << "]";
212
213 // Extent
214 metaJsonFile << ",\n \"extent\": [" << imageData->GetExtent()[0] << ", "
215 << imageData->GetExtent()[1] << ", " << imageData->GetExtent()[2] << ", "
216 << imageData->GetExtent()[3] << ", " << imageData->GetExtent()[4] << ", "
217 << imageData->GetExtent()[5] << "]";
218
219 // Direction
220 // Write the matrix using vtk.js convention for direction matrices (transpose the matrix)
221 auto direction = imageData->GetDirectionMatrix()->GetData();
222 metaJsonFile << ",\n \"direction\": [" << direction[0] << ", " << direction[3] << ", "
223 << direction[6] << ", " << direction[1] << ", " << direction[4] << ", "
224 << direction[7] << ", " << direction[2] << ", " << direction[5] << ", "
225 << direction[8] << "]";
226 }
227
228 // PolyData
229 if (polyData && polyData->GetPoints())
230 {
231 this->ValidDataSet = true;
232
233 vtkPoints* points = polyData->GetPoints();
234 metaJsonFile << ",\n \"points\": "
235 << this->WriteArray(points->GetData(), "vtkPoints", "points");
236
237 // Verts
238 vtkNew<vtkIdTypeArray> cells;
239 polyData->GetVerts()->ExportLegacyFormat(cells);

Callers 1

WriteDataMethod · 0.95

Calls 15

WriteArrayMethod · 0.95
ExportLegacyFormatMethod · 0.80
GetVertsMethod · 0.80
GetStripsMethod · 0.80
GetPolysMethod · 0.80
GetClassNameMethod · 0.45
GetSpacingMethod · 0.45
GetOriginMethod · 0.45
GetExtentMethod · 0.45
GetDataMethod · 0.45
GetPointsMethod · 0.45

Tested by

no test coverage detected