1
/*=========================================================================
3
Program: Visualization Toolkit
4
Module: $RCSfile: vtkImageHSVToRGB.cxx,v $
6
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
8
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
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.
14
=========================================================================*/
15
#include "vtkImageHSVToRGB.h"
17
#include "vtkImageData.h"
18
#include "vtkImageProgressIterator.h"
20
#include "vtkObjectFactory.h"
22
vtkCxxRevisionMacro(vtkImageHSVToRGB, "$Revision: 1.31 $");
23
vtkStandardNewMacro(vtkImageHSVToRGB);
25
//----------------------------------------------------------------------------
26
vtkImageHSVToRGB::vtkImageHSVToRGB()
28
this->Maximum = 255.0;
29
this->SetNumberOfInputPorts(1);
30
this->SetNumberOfOutputPorts(1);
34
//----------------------------------------------------------------------------
35
// This templated function executes the filter for any type of data.
37
void vtkImageHSVToRGBExecute(vtkImageHSVToRGB *self,
39
vtkImageData *outData,
40
int outExt[6], int id, T *)
42
vtkImageIterator<T> inIt(inData, outExt);
43
vtkImageProgressIterator<T> outIt(outData, outExt, self, id);
44
double R, G, B, H, S, V;
45
double max = self->GetMaximum();
48
// find the region to loop over
49
int maxC = inData->GetNumberOfScalarComponents()-1;
51
// Loop through ouput pixels
52
while (!outIt.IsAtEnd())
54
T* inSI = inIt.BeginSpan();
55
T* outSI = outIt.BeginSpan();
56
T* outSIEnd = outIt.EndSpan();
57
while (outSI != outSIEnd)
60
H = (double)(*inSI) / max; ++inSI;
61
S = (double)(*inSI) / max; ++inSI;
62
V = (double)(*inSI) / max; ++inSI;
64
vtkMath::HSVToRGB(H, S, V, &R, &G, &B);
84
*outSI = (T)(R); ++outSI;
85
*outSI = (T)(G); ++outSI;
86
*outSI = (T)(B); ++outSI;
88
for (idxC = 3; idxC <= maxC; idxC++)
98
//----------------------------------------------------------------------------
99
void vtkImageHSVToRGB::ThreadedExecute (vtkImageData *inData,
100
vtkImageData *outData,
101
int outExt[6], int id)
103
vtkDebugMacro(<< "Execute: inData = " << inData
104
<< ", outData = " << outData);
106
// this filter expects that input is the same type as output.
107
if (inData->GetScalarType() != outData->GetScalarType())
109
vtkErrorMacro(<< "Execute: input ScalarType, " << inData->GetScalarType()
110
<< ", must match out ScalarType " << outData->GetScalarType());
114
// need three components for input and output
115
if (inData->GetNumberOfScalarComponents() < 3)
117
vtkErrorMacro("Input has too few components");
120
if (outData->GetNumberOfScalarComponents() < 3)
122
vtkErrorMacro("Output has too few components");
126
switch (inData->GetScalarType())
129
vtkImageHSVToRGBExecute(this, inData,
130
outData, outExt, id, static_cast<VTK_TT *>(0)));
132
vtkErrorMacro(<< "Execute: Unknown ScalarType");
137
void vtkImageHSVToRGB::PrintSelf(ostream& os, vtkIndent indent)
139
this->Superclass::PrintSelf(os,indent);
141
os << indent << "Maximum: " << this->Maximum << "\n";