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

Method CopyAttributeArrays

Common/DataModel/vtkCellGridCopyQuery.cxx:166–225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

164}
165
166void 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 }

Callers 1

QueryMethod · 0.80

Calls 15

GetCellTypeInfoMethod · 0.80
CopyComponentNamesMethod · 0.80
DeleteMethod · 0.65
CreateArrayFunction · 0.50
GetAttributesMethod · 0.45
AddArrayMethod · 0.45
findMethod · 0.45
endMethod · 0.45
GetDataTypeMethod · 0.45
DeepCopyMethod · 0.45
CopyInformationMethod · 0.45

Tested by

no test coverage detected