OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / I386LINUX / util / I386LINUX / include / vtk / vtkImageBlend.h
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    $RCSfile: vtkImageBlend.h,v $
5   Language:  C++
6   Date:      $Date: 2002/12/11 14:26:22 $
7   Version:   $Revision: 1.20 $
8
9   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
10   All rights reserved.
11   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
12
13      This software is distributed WITHOUT ANY WARRANTY; without even 
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15      PURPOSE.  See the above copyright notice for more information.
16
17 =========================================================================*/
18 // .NAME vtkImageBlend - blend images together using alpha or opacity
19 // .SECTION Description
20 // vtkImageBlend takes L, LA, RGB, or RGBA images as input and blends them 
21 // according to the alpha values and/or the opacity setting for each input.
22 //
23 // The spacing, origin, extent, and number of components of the output are
24 // the same as those for the first input.  If the input has an alpha
25 // component, then this component is copied unchanged into the output.
26 // In addition, if the first input has either one component or two
27 // components i.e. if it is either L (greyscale) or LA (greyscale + alpha)
28 // then all other inputs must also be L or LA.
29 //
30 // Different blending modes are available:
31 //
32 // \em Normal (default) : 
33 // This is the standard blending mode used by OpenGL and other graphics
34 // packages.  The output always has the same number of components
35 // and the same extent as the first input.  The alpha value of the first
36 // input is not used in the blending computation, instead it is copied
37 // directly to the output.
38 //
39 // \code
40 // output <- input[0]
41 // foreach input i {
42 //   foreach pixel px {
43 //     r <- input[i](px)(alpha) * opacity[i]
44 //     f <- (255 - r)
45 //     output(px) <- output(px) * f + input(px) * r
46 //   }
47 // }
48 // \endcode
49 //
50 // \em Compound : 
51 // Images are compounded together and each component is scaled by the sum of
52 // the alpha/opacity values. Use the CompoundThreshold method to set 
53 // specify a threshold in compound mode. Pixels with opacity*alpha less
54 // or equal than this threshold are ignored.
55 // The alpha value of the first input, if present, is NOT copied to the alpha 
56 // value of the output.  The output always has the same number of components
57 // and the same extent as the first input.
58 //
59 // \code
60 // output <- 0
61 // foreach pixel px {
62 //   sum <- 0
63 //   foreach input i {
64 //     r <- input[i](px)(alpha) * opacity(i)
65 //     sum <- sum + r
66 //     if r > threshold {
67 //       output(px) <- output(px) + input(px) * r
68 //     }
69 //   }
70 //   output(px) <- output(px) / sum
71 // }
72 // \endcode
73
74 #ifndef __vtkImageBlend_h
75 #define __vtkImageBlend_h
76
77
78 #include "vtkImageMultipleInputFilter.h"
79
80 class vtkImageStencilData;
81
82 #define VTK_IMAGE_BLEND_MODE_NORMAL    0
83 #define VTK_IMAGE_BLEND_MODE_COMPOUND 1
84
85 class VTK_IMAGING_EXPORT vtkImageBlend : public vtkImageMultipleInputFilter
86 {
87 public:
88   static vtkImageBlend *New();
89   vtkTypeRevisionMacro(vtkImageBlend,vtkImageMultipleInputFilter);
90   void PrintSelf(ostream& os, vtkIndent indent);
91
92   // Description:
93   // Set the opacity of an input image: the alpha values of the image are
94   // multiplied by the opacity.  The opacity of image idx=0 is ignored.
95   void SetOpacity(int idx, double opacity);
96   double GetOpacity(int idx);
97
98   // Description:
99   // Set a stencil to apply when blending the data.
100   virtual void SetStencil(vtkImageStencilData*);
101   vtkGetObjectMacro(Stencil, vtkImageStencilData);
102
103   // Description:
104   // Set the blend mode
105   vtkSetClampMacro(BlendMode,int,
106                    VTK_IMAGE_BLEND_MODE_NORMAL, 
107                    VTK_IMAGE_BLEND_MODE_COMPOUND );
108   vtkGetMacro(BlendMode,int);
109   void SetBlendModeToNormal() 
110         {this->SetBlendMode(VTK_IMAGE_BLEND_MODE_NORMAL);};
111   void SetBlendModeToCompound() 
112         {this->SetBlendMode(VTK_IMAGE_BLEND_MODE_COMPOUND);};
113   const char *GetBlendModeAsString(void);
114
115   // Description:
116   // Specify a threshold in compound mode. Pixels with opacity*alpha less
117   // or equal the threshold are ignored.
118   vtkSetMacro(CompoundThreshold,float);
119   vtkGetMacro(CompoundThreshold,float);
120
121 protected:
122   vtkImageBlend();
123   ~vtkImageBlend();
124
125   void ComputeInputUpdateExtent(int inExt[6], int outExt[6],
126                                 int whichInput);
127
128   void ExecuteInformation() {
129     this->vtkImageMultipleInputFilter::ExecuteInformation(); };
130
131   void ExecuteInformation(vtkImageData **, vtkImageData *);
132
133   void ThreadedExecute(vtkImageData **inDatas, 
134                        vtkImageData *outData,
135                        int extent[6], 
136                        int id);
137
138   void ExecuteData(vtkDataObject *output);
139   
140   vtkImageStencilData *Stencil;
141   double *Opacity;
142   int OpacityArrayLength;
143   int BlendMode;
144   float CompoundThreshold;
145   int DataWasPassed;  
146 private:
147   vtkImageBlend(const vtkImageBlend&);  // Not implemented.
148   void operator=(const vtkImageBlend&);  // Not implemented.
149 };
150
151 // Description:
152 // Get the blending mode as a descriptive string
153 inline const char *vtkImageBlend::GetBlendModeAsString()
154 {
155   switch (this->BlendMode)
156     {
157     case VTK_IMAGE_BLEND_MODE_NORMAL:
158       return "Normal";
159     case VTK_IMAGE_BLEND_MODE_COMPOUND:
160       return "Compound";
161     default:
162       return "Unknown Blend Mode";
163     }
164 }
165
166
167 #endif
168
169
170
171