| 63 | //------------------------------------------------------------------------------ |
| 64 | |
| 65 | std::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; |
no test coverage detected