~ubuntu-branches/ubuntu/karmic/paraview/karmic

« back to all changes in this revision

Viewing changes to VTK/Imaging/vtkImageHSVToRGB.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2008-06-15 22:04:41 UTC
  • Revision ID: james.westby@ubuntu.com-20080615220441-8us51vf6ra2umcov
Tags: upstream-3.2.2
ImportĀ upstreamĀ versionĀ 3.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*=========================================================================
 
2
 
 
3
  Program:   Visualization Toolkit
 
4
  Module:    $RCSfile: vtkImageHSVToRGB.cxx,v $
 
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 "vtkImageHSVToRGB.h"
 
16
 
 
17
#include "vtkImageData.h"
 
18
#include "vtkImageProgressIterator.h"
 
19
#include "vtkMath.h"
 
20
#include "vtkObjectFactory.h"
 
21
 
 
22
vtkCxxRevisionMacro(vtkImageHSVToRGB, "$Revision: 1.31 $");
 
23
vtkStandardNewMacro(vtkImageHSVToRGB);
 
24
 
 
25
//----------------------------------------------------------------------------
 
26
vtkImageHSVToRGB::vtkImageHSVToRGB()
 
27
{
 
28
  this->Maximum = 255.0;
 
29
  this->SetNumberOfInputPorts(1);
 
30
  this->SetNumberOfOutputPorts(1);
 
31
}
 
32
 
 
33
 
 
34
//----------------------------------------------------------------------------
 
35
// This templated function executes the filter for any type of data.
 
36
template <class T>
 
37
void vtkImageHSVToRGBExecute(vtkImageHSVToRGB *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 R, G, B, H, S, V;
 
45
  double max = self->GetMaximum();
 
46
  int idxC;
 
47
  
 
48
  // find the region to loop over
 
49
  int maxC = inData->GetNumberOfScalarComponents()-1;
 
50
  
 
51
  // Loop through ouput pixels
 
52
  while (!outIt.IsAtEnd())
 
53
    {
 
54
    T* inSI = inIt.BeginSpan();
 
55
    T* outSI = outIt.BeginSpan();
 
56
    T* outSIEnd = outIt.EndSpan();
 
57
    while (outSI != outSIEnd)
 
58
      {
 
59
      // Pixel operation
 
60
      H = (double)(*inSI) / max; ++inSI;
 
61
      S = (double)(*inSI) / max; ++inSI;
 
62
      V = (double)(*inSI) / max; ++inSI;
 
63
 
 
64
      vtkMath::HSVToRGB(H, S, V, &R, &G, &B);
 
65
 
 
66
      R *= max;
 
67
      G *= max;
 
68
      B *= max;
 
69
 
 
70
      if (R > max)
 
71
        {
 
72
        R = max;
 
73
        }
 
74
      if (G > max)
 
75
        {
 
76
        G = max;
 
77
        }
 
78
      if (B > max)
 
79
        {
 
80
        B = max;
 
81
        }
 
82
      
 
83
      // assign output.
 
84
      *outSI = (T)(R); ++outSI;
 
85
      *outSI = (T)(G); ++outSI;
 
86
      *outSI = (T)(B); ++outSI;
 
87
      
 
88
      for (idxC = 3; idxC <= maxC; idxC++)
 
89
        {
 
90
        *outSI++ = *inSI++;
 
91
        }
 
92
      }
 
93
    inIt.NextSpan();
 
94
    outIt.NextSpan();
 
95
    }
 
96
}
 
97
 
 
98
//----------------------------------------------------------------------------
 
99
void vtkImageHSVToRGB::ThreadedExecute (vtkImageData *inData, 
 
100
                                       vtkImageData *outData,
 
101
                                       int outExt[6], int id)
 
102
{
 
103
  vtkDebugMacro(<< "Execute: inData = " << inData 
 
104
  << ", outData = " << outData);
 
105
  
 
106
  // this filter expects that input is the same type as output.
 
107
  if (inData->GetScalarType() != outData->GetScalarType())
 
108
    {
 
109
    vtkErrorMacro(<< "Execute: input ScalarType, " << inData->GetScalarType()
 
110
    << ", must match out ScalarType " << outData->GetScalarType());
 
111
    return;
 
112
    }
 
113
  
 
114
  // need three components for input and output
 
115
  if (inData->GetNumberOfScalarComponents() < 3)
 
116
    {
 
117
    vtkErrorMacro("Input has too few components");
 
118
    return;
 
119
    }
 
120
  if (outData->GetNumberOfScalarComponents() < 3)
 
121
    {
 
122
    vtkErrorMacro("Output has too few components");
 
123
    return;
 
124
    }
 
125
 
 
126
  switch (inData->GetScalarType())
 
127
    {
 
128
    vtkTemplateMacro(
 
129
      vtkImageHSVToRGBExecute(this, inData, 
 
130
                              outData, outExt, id, static_cast<VTK_TT *>(0)));
 
131
    default:
 
132
      vtkErrorMacro(<< "Execute: Unknown ScalarType");
 
133
      return;
 
134
    }
 
135
}
 
136
 
 
137
void vtkImageHSVToRGB::PrintSelf(ostream& os, vtkIndent indent)
 
138
{
 
139
  this->Superclass::PrintSelf(os,indent);
 
140
 
 
141
  os << indent << "Maximum: " << this->Maximum << "\n";
 
142
}
 
143