------------------------------------------------------------------------------ Write out data to file specified.
| 1088 | //------------------------------------------------------------------------------ |
| 1089 | // Write out data to file specified. |
| 1090 | int vtkDataWriter::WriteArray(ostream* fp, int dataType, vtkAbstractArray* data, const char* format, |
| 1091 | vtkIdType num, vtkIdType numComp) |
| 1092 | { |
| 1093 | vtkIdType i, j, idx; |
| 1094 | char str[1024]; |
| 1095 | |
| 1096 | bool isAOSArray = data->HasStandardMemoryLayout(); |
| 1097 | |
| 1098 | char* outputFormat = new char[10]; |
| 1099 | switch (dataType) |
| 1100 | { |
| 1101 | case VTK_BIT: |
| 1102 | { // assume that bit array is always in original AOS ordering |
| 1103 | auto result = vtk::format_to_n(str, sizeof(str), format, "bit"); |
| 1104 | *result.out = '\0'; |
| 1105 | *fp << str; |
| 1106 | if (this->FileType == VTK_ASCII) |
| 1107 | { |
| 1108 | int s; |
| 1109 | for (j = 0; j < num; j++) |
| 1110 | { |
| 1111 | for (i = 0; i < numComp; i++) |
| 1112 | { |
| 1113 | idx = i + j * numComp; |
| 1114 | s = static_cast<vtkBitArray*>(data)->GetValue(idx); |
| 1115 | *fp << (s != 0.0 ? 1 : 0); |
| 1116 | if (!((idx + 1) % 8)) |
| 1117 | { |
| 1118 | *fp << "\n"; |
| 1119 | } |
| 1120 | else |
| 1121 | { |
| 1122 | *fp << " "; |
| 1123 | } |
| 1124 | } |
| 1125 | } |
| 1126 | } |
| 1127 | else |
| 1128 | { |
| 1129 | unsigned char* cptr = static_cast<vtkBitArray*>(data)->GetPointer(0); |
| 1130 | fp->write(reinterpret_cast<char*>(cptr), (sizeof(unsigned char)) * ((num - 1) / 8 + 1)); |
| 1131 | } |
| 1132 | *fp << "\n"; |
| 1133 | } |
| 1134 | break; |
| 1135 | |
| 1136 | case VTK_CHAR: |
| 1137 | { |
| 1138 | auto result = vtk::format_to_n(str, sizeof(str), format, "char"); |
| 1139 | *result.out = '\0'; |
| 1140 | *fp << str; |
| 1141 | char* s = GetArrayRawPointer<char, vtkCharArray>(data, isAOSArray); |
| 1142 | vtkWriteDataArray(fp, s, this->FileType, "{:d} ", num, numComp); |
| 1143 | if (!isAOSArray) |
| 1144 | { |
| 1145 | delete[] s; |
| 1146 | } |
| 1147 | } |
no test coverage detected