------------------------------------------------------------------------------
| 205 | |
| 206 | //------------------------------------------------------------------------------ |
| 207 | int vtkConvertSelection::ConvertToBlockSelection( |
| 208 | vtkSelection* input, vtkCompositeDataSet* data, vtkSelection* output) |
| 209 | { |
| 210 | std::set<unsigned int> indices; |
| 211 | int fieldType = -1; |
| 212 | for (unsigned int n = 0; n < input->GetNumberOfNodes(); ++n) |
| 213 | { |
| 214 | vtkSmartPointer<vtkSelectionNode> inputNode = input->GetNode(n); |
| 215 | |
| 216 | // if node has no items in the selection list, it's a clear indication that |
| 217 | // nothing is selected and the node should simply be ignored. |
| 218 | if (inputNode->GetSelectionList() == nullptr || |
| 219 | inputNode->GetSelectionList()->GetNumberOfTuples() == 0) |
| 220 | { |
| 221 | continue; |
| 222 | } |
| 223 | |
| 224 | if (inputNode->GetContentType() == vtkSelectionNode::GLOBALIDS) |
| 225 | { |
| 226 | // global id selection does not have COMPOSITE_INDEX() key, so we convert |
| 227 | // it to an index base selection, so that we can determine the composite |
| 228 | // indices. |
| 229 | vtkNew<vtkSelection> tempSel; |
| 230 | tempSel->AddNode(inputNode); |
| 231 | vtkSmartPointer<vtkSelection> tempOutput; |
| 232 | tempOutput.TakeReference(vtkConvertSelection::ToIndexSelection(tempSel, data)); |
| 233 | inputNode = tempOutput->GetNode(0); |
| 234 | } |
| 235 | |
| 236 | vtkInformation* properties = inputNode->GetProperties(); |
| 237 | if (properties->Has(vtkSelectionNode::CONTENT_TYPE()) && |
| 238 | properties->Has(vtkSelectionNode::COMPOSITE_INDEX())) |
| 239 | { |
| 240 | indices.insert( |
| 241 | static_cast<unsigned int>(properties->Get(vtkSelectionNode::COMPOSITE_INDEX()))); |
| 242 | } |
| 243 | else if (properties->Has(vtkSelectionNode::CONTENT_TYPE()) && |
| 244 | properties->Has(vtkSelectionNode::HIERARCHICAL_INDEX()) && |
| 245 | properties->Has(vtkSelectionNode::HIERARCHICAL_LEVEL()) && data->IsA("vtkUniformGridAMR")) |
| 246 | { |
| 247 | // convert hierarchical index to composite index. |
| 248 | vtkUniformGridAMR* hbox = vtkUniformGridAMR::SafeDownCast(data); |
| 249 | indices.insert(hbox->GetAbsoluteBlockIndex( |
| 250 | static_cast<unsigned int>(properties->Get(vtkSelectionNode::HIERARCHICAL_LEVEL())), |
| 251 | static_cast<unsigned int>(properties->Get(vtkSelectionNode::HIERARCHICAL_INDEX())))); |
| 252 | } |
| 253 | |
| 254 | // save field type. I am just picking the first one for now. |
| 255 | fieldType = fieldType == -1 ? inputNode->GetFieldType() : fieldType; |
| 256 | } |
| 257 | |
| 258 | if (indices.empty()) |
| 259 | { |
| 260 | // nothing to convert, or converted to empty selection. |
| 261 | return 1; |
| 262 | } |
| 263 | |
| 264 | vtkNew<vtkSelectionNode> outputNode; |
no test coverage detected