Given the contour array name, the contour values and the output attributes, replace the contour array found in the attributes by an indexed array. If there are less than 256 contour values: - store these values in a new array, removing duplicates - use a vtkUnsignedCharArray to index these values (handles) If there is strictly more than 256 contour values, this function will do nothing.
| 266 | // - use a vtkUnsignedCharArray to index these values (handles) |
| 267 | // If there is strictly more than 256 contour values, this function will do nothing. |
| 268 | void ReplaceWithIndexedArray(const std::string& contourArrayName, vtkContourValues* contourValues, |
| 269 | vtkDataSetAttributes* outputAttributes) |
| 270 | { |
| 271 | int numberOfContours = contourValues->GetNumberOfContours(); |
| 272 | if (numberOfContours > MAX_NB_OF_CONTOURS) // 256 |
| 273 | { |
| 274 | vtkDebugWithObjectMacro(nullptr, |
| 275 | "There are more than " << MAX_NB_OF_CONTOURS << " values in contourValues. " |
| 276 | << "ReplaceWithIndexedArray will do nothing."); |
| 277 | return; |
| 278 | } |
| 279 | |
| 280 | if (!outputAttributes) |
| 281 | { |
| 282 | vtkErrorWithObjectMacro(nullptr, "Unable to retrieve output attributes"); |
| 283 | return; |
| 284 | } |
| 285 | |
| 286 | auto contourArray = |
| 287 | vtkDataArray::SafeDownCast(outputAttributes->GetAbstractArray(contourArrayName.c_str())); |
| 288 | if (!contourArray) |
| 289 | { |
| 290 | vtkErrorWithObjectMacro( |
| 291 | nullptr, "Unable to retrieve contour array " << contourArrayName << " from input attributes"); |
| 292 | return; |
| 293 | } |
| 294 | |
| 295 | using Dispatcher = vtkArrayDispatch::DispatchByValueType<vtkArrayDispatch::AllTypes>; |
| 296 | ::ConvertToIndexedArrayWorker worker; |
| 297 | |
| 298 | // Dispatch |
| 299 | if (!Dispatcher::Execute(contourArray, worker, contourValues, outputAttributes)) |
| 300 | { |
| 301 | vtkErrorWithObjectMacro(nullptr, "Unable to dispatch the contour array " << contourArrayName); |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | //------------------------------------------------------------------------------ |
no test coverage detected