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

Method WriteDataSetAttributes

IO/Export/vtkJSONDataSetWriter.cxx:65–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63//------------------------------------------------------------------------------
64
65std::string vtkJSONDataSetWriter::WriteDataSetAttributes(
66 vtkDataSetAttributes* fields, const char* className)
67{
68 int nbArrayWritten = 0;
69 vtkIdType activeTCoords = -1;
70 vtkIdType activeScalars = -1;
71 vtkIdType activeNormals = -1;
72 vtkIdType activeGlobalIds = -1;
73 vtkIdType activeTensors = -1;
74 vtkIdType activePedigreeIds = -1;
75 vtkIdType activeVectors = -1;
76
77 vtkIdType nbFields = fields->GetNumberOfArrays();
78
79 if (nbFields == 0)
80 {
81 return "";
82 }
83
84 std::stringstream jsonSnippet;
85 jsonSnippet << " \"" << className << "\": {"
86 << "\n \"vtkClass\": \"vtkDataSetAttributes\","
87 << "\n \"arrays\": [\n";
88 for (vtkIdType idx = 0; idx < nbFields; idx++)
89 {
90 vtkDataArray* field = fields->GetArray(idx);
91 if (field == nullptr)
92 {
93 continue;
94 }
95
96 if (std::string(className) == "pointData")
97 {
98 if (!this->GetPointArraySelection()->ArrayIsEnabled(field->GetName()))
99 {
100 vtkDebugMacro("Skipping writing point array " << field->GetName());
101 continue;
102 }
103 }
104 else if (std::string(className) == "cellData")
105 {
106 if (!this->GetCellArraySelection()->ArrayIsEnabled(field->GetName()))
107 {
108 vtkDebugMacro("Skipping cell array " << field->GetName());
109 continue;
110 }
111 }
112
113 if (nbArrayWritten)
114 {
115 jsonSnippet << ",\n";
116 }
117
118 jsonSnippet << " { \"data\": " << this->WriteArray(field, "vtkDataArray") << "}";
119
120 // Update active field if any
121 activeTCoords = field == fields->GetTCoords() ? nbArrayWritten : activeTCoords;
122 activeScalars = field == fields->GetScalars() ? nbArrayWritten : activeScalars;

Callers 1

WriteMethod · 0.95

Calls 15

WriteArrayMethod · 0.95
GetGlobalIdsMethod · 0.80
GetPedigreeIdsMethod · 0.80
stringClass · 0.50
GetNumberOfArraysMethod · 0.45
GetArrayMethod · 0.45
ArrayIsEnabledMethod · 0.45
GetNameMethod · 0.45
GetCellArraySelectionMethod · 0.45
GetTCoordsMethod · 0.45
GetScalarsMethod · 0.45

Tested by

no test coverage detected