int ImageBlankNonFiniteValuesFilter::RequestData( vtkInformation * /*request*/, vtkInformationVector ** inputVector, vtkInformationVector * outputVector) { auto inInfo = inputVector[0]->GetInformationObject(0); auto outInfo = outputVector->GetInformationObject(0); auto inImage = vtkImageData::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT())); auto outGrid = vtkUniformGrid::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT())); outGrid->ShallowCopy(inImage); auto scalars = inImage->GetPointData()->GetScalars(); if (!scalars) { // nothing to do return 1; } ConvertAndMaskToUniformGridWorker worker{ *inImage, *outGrid }; // Dispatching float/double only, for all other scalar types this filter does nothing // (as other types don't have a NaN-equivalent). using RealsDispatcher = vtkArrayDispatch::DispatchByValueType<vtkArrayDispatch::Reals>; RealsDispatcher::Execute(scalars, worker); return 1; }
int AssignPointAttributeToCoordinatesFilter::RequestData( vtkInformation * /*request*/, vtkInformationVector ** inputVector, vtkInformationVector * outputVector) { auto inData = vtkPointSet::SafeDownCast(inputVector[0]->GetInformationObject(0)->Get(vtkDataObject::DATA_OBJECT())); auto outData = vtkPointSet::SafeDownCast(outputVector->GetInformationObject(0)->Get(vtkDataObject::DATA_OBJECT())); auto previousPointCoords = inData->GetPoints()->GetData(); vtkDataArray * pointsToAssign = nullptr; if (!this->AttributeArrayToAssign.empty()) { auto newPoints = inData->GetPointData()->GetArray(this->AttributeArrayToAssign.c_str()); if (!newPoints) { vtkErrorMacro("Array to assign not found in input data: " + this->AttributeArrayToAssign); return 0; } if (newPoints->GetNumberOfComponents() != 3 || newPoints->GetNumberOfTuples() != inData->GetNumberOfPoints()) { vtkErrorMacro("Component/Tuple count mismatching in selected data array: " + this->AttributeArrayToAssign); return 0; } pointsToAssign = newPoints; } outData->ShallowCopy(inData); if (pointsToAssign) { vtkNew<vtkPoints> newPoints; newPoints->SetData(pointsToAssign); outData->SetPoints(newPoints.Get()); } // pass current point coordinates as point attribute if (previousPointCoords) { outData->GetPointData()->AddArray(previousPointCoords); } if (auto currentCoords = pointsToAssign ? pointsToAssign : previousPointCoords) { outData->GetPointData()->SetActiveScalars(currentCoords->GetName()); } return 1; }
void PickCallbackFunction(vtkObject* caller, long unsigned int vtkNotUsed(eventId), void* clientData, void* vtkNotUsed(callData)) { vtkAreaPicker *areaPicker = static_cast<vtkAreaPicker*>(caller); iARenderer *ren = static_cast<iARenderer*>(clientData); ren->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->RemoveActor(ren->selectedActor); auto extractSelection = vtkSmartPointer<vtkExtractSelectedFrustum>::New(); extractSelection->SetInputData(0, ren->getRenderObserver()->GetImageData()); extractSelection->PreserveTopologyOff(); extractSelection->SetFrustum(areaPicker->GetFrustum()); extractSelection->Update(); if (!extractSelection->GetOutput()->GetNumberOfElements(vtkUnstructuredGrid::CELL)) { ren->emitNoSelectedCells(); return; } if (ren->GetInteractor()->GetControlKey() && !ren->GetInteractor()->GetShiftKey()) { // Adds cells to selection auto append = vtkSmartPointer<vtkAppendFilter>::New(); append->AddInputData(ren->finalSelection); append->AddInputData(extractSelection->GetOutput()); append->Update(); ren->finalSelection->ShallowCopy(append->GetOutput()); } else if (ren->GetInteractor()->GetControlKey() && ren->GetInteractor()->GetShiftKey()) { // Removes cells from selection auto newfinalSel = vtkSmartPointer<vtkUnstructuredGrid>::New(); newfinalSel->Allocate(1, 1); newfinalSel->SetPoints(ren->finalSelection->GetPoints()); auto currSel = vtkSmartPointer<vtkUnstructuredGrid>::New(); currSel->ShallowCopy(extractSelection->GetOutput()); double f_Cell[DIM] = { 0,0,0 }, c_Cell[DIM] = { 0,0,0 }; double* spacing = ren->getRenderObserver()->GetImageData()->GetSpacing(); for (vtkIdType i = 0; i < ren->finalSelection->GetNumberOfCells(); ++i) { bool addCell = true; GetCellCenter(ren->finalSelection, i, f_Cell, spacing); for (vtkIdType j = 0; j < currSel->GetNumberOfCells(); ++j) { GetCellCenter(currSel, j, c_Cell, spacing); if (f_Cell[0] == c_Cell[0] && f_Cell[1] == c_Cell[1] && f_Cell[2] == c_Cell[2]) { addCell = false; break; } } if (addCell) newfinalSel->InsertNextCell(ren->finalSelection->GetCell(i)->GetCellType(), ren->finalSelection->GetCell(i)->GetPointIds()); } ren->finalSelection->ShallowCopy(newfinalSel); } else { // New selection ren->finalSelection->ShallowCopy(extractSelection->GetOutput()); } ren->selectedMapper->Update(); ren->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->AddActor(ren->selectedActor); ren->emitSelectedCells(ren->finalSelection); }