| 107 | } |
| 108 | |
| 109 | int vtkExtractSelectedTree::RequestData(vtkInformation* vtkNotUsed(request), |
| 110 | vtkInformationVector** inputVector, vtkInformationVector* outputVector) |
| 111 | { |
| 112 | vtkTree* inputTree = vtkTree::GetData(inputVector[0]); |
| 113 | vtkSelection* selection = vtkSelection::GetData(inputVector[1]); |
| 114 | vtkTree* outputTree = vtkTree::GetData(outputVector); |
| 115 | |
| 116 | if (!selection) |
| 117 | { |
| 118 | vtkErrorMacro("No vtkSelection provided as input."); |
| 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | // obtain a vertex selection list from the input vtkSelection |
| 123 | // Convert the selection to an INDICES selection |
| 124 | vtkSmartPointer<vtkSelection> converted; |
| 125 | converted.TakeReference(vtkConvertSelection::ToIndexSelection(selection, inputTree)); |
| 126 | if (!converted) |
| 127 | { |
| 128 | vtkErrorMacro("Selection conversion to INDICES failed."); |
| 129 | return 0; |
| 130 | } |
| 131 | vtkNew<vtkIdTypeArray> selectedVerticesList; |
| 132 | |
| 133 | for (unsigned int i = 0; i < converted->GetNumberOfNodes(); ++i) |
| 134 | { |
| 135 | vtkSelectionNode* node = converted->GetNode(i); |
| 136 | |
| 137 | // Append the selectedVerticesList |
| 138 | vtkIdTypeArray* curList = vtkArrayDownCast<vtkIdTypeArray>(node->GetSelectionList()); |
| 139 | if (curList) |
| 140 | { |
| 141 | int inverse = node->GetProperties()->Get(vtkSelectionNode::INVERSE()); |
| 142 | if (inverse) |
| 143 | { // selection is to be removed |
| 144 | if (node->GetFieldType() == vtkSelectionNode::VERTEX) |
| 145 | { // keep all the other vertices |
| 146 | vtkIdType num = inputTree->GetNumberOfVertices(); |
| 147 | for (vtkIdType j = 0; j < num; ++j) |
| 148 | { |
| 149 | if (curList->LookupValue(j) < 0 && selectedVerticesList->LookupValue(j) < 0) |
| 150 | { |
| 151 | selectedVerticesList->InsertNextValue(j); |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | else if (node->GetFieldType() == vtkSelectionNode ::EDGE) |
| 156 | { // keep all the other edges |
| 157 | vtkIdType num = inputTree->GetNumberOfEdges(); |
| 158 | for (vtkIdType j = 0; j < num; ++j) |
| 159 | { |
| 160 | if (curList->LookupValue(j) < 0) |
| 161 | { |
| 162 | vtkIdType s = inputTree->GetSourceVertex(j); |
| 163 | vtkIdType t = inputTree->GetTargetVertex(j); |
| 164 | if (selectedVerticesList->LookupValue(s) < 0) |
| 165 | { |
| 166 | selectedVerticesList->InsertNextValue(s); |
nothing calls this directly
no test coverage detected