| 36 | // This templated function executes the filter for any type of data. |
| 37 | template <class IT, class OT> |
| 38 | void vtkImageCastExecute( |
| 39 | vtkImageCast* self, vtkImageData* inData, vtkImageData* outData, int outExt[6], int id, IT*, OT*) |
| 40 | { |
| 41 | vtkImageIterator<IT> inIt(inData, outExt); |
| 42 | vtkImageProgressIterator<OT> outIt(outData, outExt, self, id); |
| 43 | |
| 44 | double typeMin, typeMax, val; |
| 45 | int clamp; |
| 46 | |
| 47 | // for preventing overflow |
| 48 | typeMin = outData->GetScalarTypeMin(); |
| 49 | typeMax = outData->GetScalarTypeMax(); |
| 50 | clamp = self->GetClampOverflow(); |
| 51 | |
| 52 | // Loop through output pixels |
| 53 | while (!outIt.IsAtEnd()) |
| 54 | { |
| 55 | IT* inSI = inIt.BeginSpan(); |
| 56 | OT* outSI = outIt.BeginSpan(); |
| 57 | OT* outSIEnd = outIt.EndSpan(); |
| 58 | if (clamp) |
| 59 | { |
| 60 | while (outSI != outSIEnd) |
| 61 | { |
| 62 | // Pixel operation |
| 63 | val = static_cast<double>(*inSI); |
| 64 | val = std::min(val, typeMax); |
| 65 | val = std::max(val, typeMin); |
| 66 | *outSI = static_cast<OT>(val); |
| 67 | ++outSI; |
| 68 | ++inSI; |
| 69 | } |
| 70 | } |
| 71 | else |
| 72 | { |
| 73 | while (outSI != outSIEnd) |
| 74 | { |
| 75 | // now process the components |
| 76 | // NB: without clamping, this cast may result in undefined behavior! |
| 77 | *outSI = static_cast<OT>(*inSI); |
| 78 | ++outSI; |
| 79 | ++inSI; |
| 80 | } |
| 81 | } |
| 82 | inIt.NextSpan(); |
| 83 | outIt.NextSpan(); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | //------------------------------------------------------------------------------ |
| 88 | template <class T> |
no test coverage detected