| 240 | } |
| 241 | |
| 242 | bool vtkCellGridWriter::ToJSON(nlohmann::json& data, vtkCellGrid* grid) |
| 243 | { |
| 244 | // Iterate all the vtkDataSetAttributes held by the grid. |
| 245 | // As we go, store a map from each array in each vtkDataSetAttributes |
| 246 | // to a "location" for the array so we can refer to the arrays later |
| 247 | // by a persistent name instead of by pointer. |
| 248 | std::unordered_map<vtkAbstractArray*, vtkStringToken> arrayLocations; |
| 249 | auto arrayGroups = nlohmann::json::object(); |
| 250 | for (const auto& entry : grid->GetArrayGroups()) |
| 251 | { |
| 252 | std::string groupName; |
| 253 | vtkStringToken groupToken(entry.first); |
| 254 | if (!groupToken.Data().empty()) |
| 255 | { |
| 256 | groupName = groupToken.Data(); |
| 257 | } |
| 258 | else |
| 259 | { |
| 260 | std::ostringstream groupId; |
| 261 | groupId << entry.first; |
| 262 | groupName = groupId.str(); |
| 263 | } |
| 264 | nlohmann::json arraysInGroup; |
| 265 | |
| 266 | // Fetch arrays serving in specific roles. |
| 267 | vtkDataArray* groupScalars = entry.second->GetScalars(); |
| 268 | vtkDataArray* groupVectors = entry.second->GetVectors(); |
| 269 | vtkDataArray* groupTensors = entry.second->GetTensors(); |
| 270 | vtkDataArray* groupTCoords = entry.second->GetTCoords(); |
| 271 | vtkDataArray* groupTangents = entry.second->GetTangents(); |
| 272 | vtkDataArray* groupGlobalIds = entry.second->GetGlobalIds(); |
| 273 | vtkAbstractArray* groupPedigreeIds = entry.second->GetPedigreeIds(); |
| 274 | vtkDataArray* groupRationalWeights = entry.second->GetRationalWeights(); |
| 275 | vtkDataArray* groupHigherOrderDegrees = entry.second->GetHigherOrderDegrees(); |
| 276 | |
| 277 | for (vtkIdType ii = 0; ii < entry.second->GetNumberOfArrays(); ++ii) |
| 278 | { |
| 279 | vtkAbstractArray* arr = entry.second->GetAbstractArray(ii); |
| 280 | if (!arr) |
| 281 | { |
| 282 | continue; |
| 283 | } |
| 284 | arrayLocations[arr] = groupName; |
| 285 | nlohmann::json arrayRecord{ { "name", arr->GetName() }, |
| 286 | { "tuples", arr->GetNumberOfTuples() }, { "components", arr->GetNumberOfComponents() }, |
| 287 | { "type", dataTypeToString(arr->GetDataType()) }, { "data", serializeArrayValues(arr) } }; |
| 288 | if (arr == groupScalars) |
| 289 | { |
| 290 | arrayRecord["default_scalars"] = true; |
| 291 | } |
| 292 | if (arr == groupVectors) |
| 293 | { |
| 294 | arrayRecord["default_vectors"] = true; |
| 295 | } |
| 296 | if (arr == groupTensors) |
| 297 | { |
| 298 | arrayRecord["default_tensors"] = true; |
| 299 | } |
no test coverage detected