| 94 | } |
| 95 | |
| 96 | bool merge(vtkImageData* target, std::vector<vtkSmartPointer<vtkImageData>>& sources) |
| 97 | { |
| 98 | if (sources.empty()) |
| 99 | { |
| 100 | return false; |
| 101 | } |
| 102 | |
| 103 | if (sources.size() == 1) |
| 104 | { |
| 105 | target->ShallowCopy(sources[0]); |
| 106 | return true; |
| 107 | } |
| 108 | |
| 109 | vtkDataSetAttributesFieldList ptList; |
| 110 | vtkDataSetAttributesFieldList cellList; |
| 111 | for (auto& image : sources) |
| 112 | { |
| 113 | ptList.IntersectFieldList(image->GetPointData()); |
| 114 | cellList.IntersectFieldList(image->GetCellData()); |
| 115 | } |
| 116 | |
| 117 | target->Initialize(); |
| 118 | target->CopyStructure(sources[0]); |
| 119 | |
| 120 | auto opd = target->GetPointData(); |
| 121 | opd->CopyAllOn(); |
| 122 | opd->CopyAllocate(ptList, target->GetNumberOfPoints()); |
| 123 | opd->SetNumberOfTuples(target->GetNumberOfPoints()); |
| 124 | opd->CopyData(ptList, sources[0]->GetPointData(), 0, 0, target->GetNumberOfPoints(), 0); |
| 125 | |
| 126 | auto ocd = target->GetCellData(); |
| 127 | ocd->CopyAllOn(); |
| 128 | ocd->CopyAllocate(cellList, target->GetNumberOfCells()); |
| 129 | ocd->SetNumberOfTuples(target->GetNumberOfCells()); |
| 130 | ocd->CopyData(cellList, sources[0]->GetCellData(), 0, 0, target->GetNumberOfCells(), 0); |
| 131 | |
| 132 | for (int idx = 1; idx < static_cast<int>(sources.size()); ++idx) |
| 133 | { |
| 134 | auto inPD = sources[idx]->GetPointData(); |
| 135 | if (auto ptids = get_ids(inPD, vtkDataSetAttributes::HIDDENPOINT)) |
| 136 | { |
| 137 | ptList.TransformData(idx, inPD, opd, |
| 138 | [&ptids](vtkAbstractArray* in, vtkAbstractArray* out) |
| 139 | { out->InsertTuples(ptids, ptids, in); }); |
| 140 | } |
| 141 | |
| 142 | auto inCD = sources[idx]->GetCellData(); |
| 143 | if (auto cellids = get_ids(inCD, vtkDataSetAttributes::HIDDENCELL)) |
| 144 | { |
| 145 | cellList.TransformData(idx, inCD, ocd, |
| 146 | [&cellids](vtkAbstractArray* in, vtkAbstractArray* out) |
| 147 | { out->InsertTuples(cellids, cellids, in); }); |
| 148 | } |
| 149 | } |
| 150 | return true; |
| 151 | } |
| 152 | VTK_ABI_NAMESPACE_END |
| 153 | } |
no test coverage detected