-vtkDataSet *FilterFamilies(vtkDataSet *input, const std::vector<int>& idsToKeep, bool insideOut)
-{
- const int VTK_DATA_ARRAY_DELETE=vtkAOSDataArrayTemplate<double>::VTK_DATA_ARRAY_DELETE;
- const char ZE_SELECTION_ARR_NAME[]="@@ZeSelection@@";
- vtkDataSet *output(input->NewInstance());
- output->ShallowCopy(input);
- vtkSmartPointer<vtkThreshold> thres(vtkSmartPointer<vtkThreshold>::New());
- thres->SetInputData(output);
- //vtkDataSetAttributes *dscIn(input->GetCellData()),*dscIn2(input->GetPointData()); // todo: unused
- //vtkDataSetAttributes *dscOut(output->GetCellData()),*dscOut2(output->GetPointData()); // todo: unused
- //
- double vMin(insideOut==0?1.:0.),vMax(insideOut==0?2.:1.);
- thres->ThresholdBetween(vMin,vMax);
- // OK for the output
- vtkIdType nbOfCells(input->GetNumberOfCells());
- vtkCharArray *zeSelection(vtkCharArray::New());
- zeSelection->SetName(ZE_SELECTION_ARR_NAME);
- zeSelection->SetNumberOfComponents(1);
- char *pt(new char[nbOfCells]);
- zeSelection->SetArray(pt,nbOfCells,0,VTK_DATA_ARRAY_DELETE);
- std::fill(pt,pt+nbOfCells,0);
- std::vector<bool> pt2(nbOfCells,false);
- for(std::vector<int>::const_iterator it=idsToKeep.begin();it!=idsToKeep.end();it++)
- {
- for(vtkIdType ii=0;ii<nbOfCells;ii++)
- {
- if(input->GetCellType(ii)==*it)
- pt2[ii]=true;
- }
- }
- for(int ii=0;ii<nbOfCells;ii++)
- if(pt2[ii])
- pt[ii]=2;
- int idx(output->GetCellData()->AddArray(zeSelection));
- output->GetCellData()->SetActiveAttribute(idx,vtkDataSetAttributes::SCALARS);
- output->GetCellData()->CopyScalarsOff();
- zeSelection->Delete();
- //
- thres->SetInputArrayToProcess(idx,0,0,"vtkDataObject::FIELD_ASSOCIATION_CELLS",ZE_SELECTION_ARR_NAME);
- thres->Update();
- vtkUnstructuredGrid *zeComputedOutput(thres->GetOutput());
- zeComputedOutput->GetCellData()->RemoveArray(idx);
- output->Delete();
- zeComputedOutput->Register(0);
- return zeComputedOutput;
-}