1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkImageLogarithmicScale.cxx
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14 =========================================================================*/
15 #include "vtkImageLogarithmicScale.h"
16
17 #include "vtkImageData.h"
18 #include "vtkImageProgressIterator.h"
19 #include "vtkObjectFactory.h"
20
21 #include <cmath>
22
23 vtkStandardNewMacro(vtkImageLogarithmicScale);
24
25 //----------------------------------------------------------------------------
26 // Constructor sets default values
vtkImageLogarithmicScale()27 vtkImageLogarithmicScale::vtkImageLogarithmicScale()
28 {
29 this->SetNumberOfInputPorts(1);
30 this->SetNumberOfOutputPorts(1);
31 this->Constant = 10.0;
32 }
33
34 //----------------------------------------------------------------------------
35 // This templated function executes the filter for any type of data.
36 template <class T>
vtkImageLogarithmicScaleExecute(vtkImageLogarithmicScale * self,vtkImageData * inData,vtkImageData * outData,int outExt[6],int id,T *)37 void vtkImageLogarithmicScaleExecute(vtkImageLogarithmicScale *self,
38 vtkImageData *inData,
39 vtkImageData *outData,
40 int outExt[6], int id, T *)
41 {
42 vtkImageIterator<T> inIt(inData, outExt);
43 vtkImageProgressIterator<T> outIt(outData, outExt, self, id);
44 double c;
45
46 c = self->GetConstant();
47
48 // Loop through output pixels
49 while (!outIt.IsAtEnd())
50 {
51 T* inSI = inIt.BeginSpan();
52 T* outSI = outIt.BeginSpan();
53 T* outSIEnd = outIt.EndSpan();
54 while (outSI != outSIEnd)
55 {
56 // Pixel operation
57 if (*inSI > 0)
58 {
59 *outSI = static_cast<T>(c*log(static_cast<double>(*inSI)+1.0));
60 }
61 else
62 {
63 *outSI = static_cast<T>(-c*log(1.0-static_cast<double>(*inSI)));
64 }
65
66 outSI++;
67 inSI++;
68 }
69 inIt.NextSpan();
70 outIt.NextSpan();
71 }
72 }
73
74
75 //----------------------------------------------------------------------------
76 // This method is passed a input and output region, and executes the filter
77 // algorithm to fill the output from the input.
78 // It just executes a switch statement to call the correct function for
79 // the regions data types.
ThreadedExecute(vtkImageData * inData,vtkImageData * outData,int outExt[6],int id)80 void vtkImageLogarithmicScale::ThreadedExecute (vtkImageData *inData,
81 vtkImageData *outData,
82 int outExt[6], int id)
83 {
84 // this filter expects that input is the same type as output.
85 if (inData->GetScalarType() != outData->GetScalarType())
86 {
87 vtkErrorMacro(<< "Execute: input ScalarType, "
88 << inData->GetScalarType()
89 << ", must match out ScalarType "
90 << outData->GetScalarType());
91 return;
92 }
93
94 switch (inData->GetScalarType())
95 {
96 vtkTemplateMacro(
97 vtkImageLogarithmicScaleExecute(this, inData,
98 outData, outExt, id,
99 static_cast<VTK_TT *>(nullptr)));
100 default:
101 vtkErrorMacro(<< "Execute: Unknown input ScalarType");
102 return;
103 }
104 }
105
PrintSelf(ostream & os,vtkIndent indent)106 void vtkImageLogarithmicScale::PrintSelf(ostream& os, vtkIndent indent)
107 {
108 this->Superclass::PrintSelf(os,indent);
109
110 os << indent << "Constant: " << this->Constant << "\n";
111 }
112
113