| 164 | } |
| 165 | |
| 166 | void vtkCellGridCopyQuery::CopyAttributeArrays(vtkCellAttribute* srcAtt, vtkStringToken cellType) |
| 167 | { |
| 168 | if (!this->CopyArrays) |
| 169 | { |
| 170 | return; |
| 171 | } |
| 172 | if (!srcAtt) |
| 173 | { |
| 174 | vtkErrorMacro("Null source attribute."); |
| 175 | return; |
| 176 | } |
| 177 | auto srcCellTypeInfo = srcAtt->GetCellTypeInfo(cellType); |
| 178 | auto& arraysByRole = srcCellTypeInfo.ArraysByRole; |
| 179 | for (const auto& roleEntry : arraysByRole) |
| 180 | { |
| 181 | auto srcArr = roleEntry.second; |
| 182 | int arrType = this->Source->GetAttributeTypeForArray(srcArr); |
| 183 | auto* tgtGroup = this->Target->GetAttributes(arrType); |
| 184 | if (this->CopyArrayValues && !this->DeepCopyArrays) |
| 185 | { |
| 186 | // We should copy by referencing the original array; |
| 187 | // just add the source array to the destination. |
| 188 | tgtGroup->AddArray(srcArr); |
| 189 | } |
| 190 | else |
| 191 | { |
| 192 | // Deep-copy the source array as needed. |
| 193 | // I. See if we've already copied the array: |
| 194 | auto mapIt = this->ArrayMap.find(srcArr); |
| 195 | if (mapIt != this->ArrayMap.end()) |
| 196 | { |
| 197 | // No need to re-create the array; we've already copied it. |
| 198 | // Just add it to the array grouping. |
| 199 | tgtGroup->AddArray(mapIt->second); |
| 200 | continue; |
| 201 | } |
| 202 | // II. We need to create an array. |
| 203 | auto* tgtArr = vtkAbstractArray::CreateArray(srcArr->GetDataType()); |
| 204 | if (this->CopyArrayValues) |
| 205 | { |
| 206 | // Create a deep copy including the values: |
| 207 | tgtArr->DeepCopy(srcArr); |
| 208 | } |
| 209 | else |
| 210 | { |
| 211 | // Copy array "metadata" only. |
| 212 | if (srcArr->HasInformation()) |
| 213 | { |
| 214 | tgtArr->CopyInformation(srcArr->GetInformation(), /*deep*/ 1); |
| 215 | } |
| 216 | tgtArr->SetName(srcArr->GetName()); |
| 217 | tgtArr->SetNumberOfComponents(srcArr->GetNumberOfComponents()); |
| 218 | tgtArr->CopyComponentNames(srcArr); |
| 219 | } |
| 220 | tgtGroup->AddArray(tgtArr); |
| 221 | this->ArrayMap[srcArr] = tgtArr; |
| 222 | tgtArr->Delete(); |
| 223 | } |
no test coverage detected