------------------------------------------------------------------------------
| 137 | } |
| 138 | //------------------------------------------------------------------------------ |
| 139 | int vtkTableBasedClipDataSet::RequestData(vtkInformation* vtkNotUsed(request), |
| 140 | vtkInformationVector** inputVector, vtkInformationVector* outputVector) |
| 141 | { |
| 142 | // input and output information objects |
| 143 | vtkInformation* inInfo = inputVector[0]->GetInformationObject(0); |
| 144 | vtkInformation* outInfo = outputVector->GetInformationObject(0); |
| 145 | |
| 146 | // Get the input of which we have to create a copy since the clipper requires |
| 147 | // that InterpolateAllocate() be invoked for the output based on its input in |
| 148 | // terms of the point data. If the input and output arrays are different, |
| 149 | // vtkCell3D's Clip will fail. The last argument of InterpolateAllocate makes |
| 150 | // sure that arrays are shallow-copied from input to inputCopy. |
| 151 | auto input = vtkDataSet::GetData(inInfo); |
| 152 | vtkSmartPointer<vtkDataSet> inputCopy; |
| 153 | inputCopy.TakeReference(input->NewInstance()); |
| 154 | inputCopy->CopyStructure(input); |
| 155 | inputCopy->GetCellData()->PassData(input->GetCellData()); |
| 156 | inputCopy->GetFieldData()->PassData(input->GetFieldData()); |
| 157 | inputCopy->GetPointData()->InterpolateAllocate(input->GetPointData(), 0, 0, 1); |
| 158 | |
| 159 | // get the output (the remaining and the clipped parts) |
| 160 | auto outputUG = vtkUnstructuredGrid::GetData(outInfo); |
| 161 | vtkUnstructuredGrid* clippedOutputUG = this->GetClippedOutput(); |
| 162 | |
| 163 | vtkDebugMacro(<< "Clipping dataset" << endl); |
| 164 | |
| 165 | const vtkIdType numPoints = inputCopy->GetNumberOfPoints(); |
| 166 | |
| 167 | // handling exceptions |
| 168 | if (numPoints < 1) |
| 169 | { |
| 170 | vtkDebugMacro(<< "No data to clip" << endl); |
| 171 | outputUG = nullptr; |
| 172 | return 1; |
| 173 | } |
| 174 | |
| 175 | if (!this->ClipFunction && this->GenerateClipScalars) |
| 176 | { |
| 177 | vtkErrorMacro(<< "Cannot generate clip scalars " |
| 178 | << "if no clip function defined" << endl); |
| 179 | outputUG = nullptr; |
| 180 | return 1; |
| 181 | } |
| 182 | |
| 183 | // check whether the cells are clipped with input scalars or a clip function |
| 184 | vtkSmartPointer<vtkDoubleArray> scalars; |
| 185 | if (!this->ClipFunction) |
| 186 | { |
| 187 | auto inputArray = this->GetInputArrayToProcess(0, inputVector); |
| 188 | if (!inputArray) |
| 189 | { |
| 190 | vtkErrorMacro(<< "no input scalars." << endl); |
| 191 | return 1; |
| 192 | } |
| 193 | // This is needed by vtkClipDataSet in case we fall back to it. |
| 194 | inputCopy->GetPointData()->AddArray(inputArray); |
| 195 | inputCopy->GetPointData()->SetActiveScalars(inputArray->GetName()); |
| 196 | // We (shallow/deep)copy the input scalars into a double array. |
nothing calls this directly
no test coverage detected