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

Method InsertColumn

Common/DataModel/vtkTable.cxx:450–489  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

448
449//------------------------------------------------------------------------------
450void vtkTable::InsertColumn(vtkAbstractArray* arr, vtkIdType index)
451{
452 if (this->GetNumberOfColumns() > 0 && arr->GetNumberOfTuples() != this->GetNumberOfRows())
453 {
454 vtkErrorMacro(<< "Column \"" << arr->GetName() << "\" must have " << this->GetNumberOfRows()
455 << " rows, but has " << arr->GetNumberOfTuples() << ".");
456 return;
457 }
458 // ensure index is sensible
459 index = std::max<vtkIdType>(0, std::min<vtkIdType>(this->GetNumberOfColumns(), index));
460
461 // insert at end?
462 if (index == this->GetNumberOfColumns())
463 {
464 this->AddColumn(arr);
465 return;
466 }
467
468 // remove all arrays from RowData, then insert them again in correct order with new array inserted
469 // note: use vtkSmartPointer to preserve a reference count, else this->RowData->RemoveArray(0)
470 // will delete the array
471 vtkIdType ncols = this->GetNumberOfColumns();
472 std::vector<vtkSmartPointer<vtkAbstractArray>> store;
473 store.reserve(ncols);
474
475 for (int c = 0; c < ncols; c++)
476 {
477 if (c == index)
478 {
479 store.emplace_back(arr);
480 }
481 store.emplace_back(this->GetColumn(0));
482 this->RowData->RemoveArray(0);
483 }
484
485 for (unsigned long c = 0; c < store.size(); c++)
486 {
487 this->RowData->AddArray(store[c]);
488 }
489}
490
491//------------------------------------------------------------------------------
492void vtkTable::RemoveColumnByName(const char* name)

Callers 4

InsertFieldMethod · 0.45
onColumnsInsertedMethod · 0.45
InsertColumnFunction · 0.45
InsertImplicitArrayFunction · 0.45

Calls 11

GetNumberOfColumnsMethod · 0.95
GetNumberOfRowsMethod · 0.95
AddColumnMethod · 0.95
GetColumnMethod · 0.95
GetNumberOfTuplesMethod · 0.45
GetNameMethod · 0.45
reserveMethod · 0.45
emplace_backMethod · 0.45
RemoveArrayMethod · 0.45
sizeMethod · 0.45
AddArrayMethod · 0.45

Tested by 2

InsertColumnFunction · 0.36
InsertImplicitArrayFunction · 0.36