1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: $RCSfile: vtkImageBlend.h,v $
6 Date: $Date: 2002/12/11 14:26:22 $
7 Version: $Revision: 1.20 $
9 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
11 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
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.
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.
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.
30 // Different blending modes are available:
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.
43 // r <- input[i](px)(alpha) * opacity[i]
45 // output(px) <- output(px) * f + input(px) * r
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.
64 // r <- input[i](px)(alpha) * opacity(i)
67 // output(px) <- output(px) + input(px) * r
70 // output(px) <- output(px) / sum
74 #ifndef __vtkImageBlend_h
75 #define __vtkImageBlend_h
78 #include "vtkImageMultipleInputFilter.h"
80 class vtkImageStencilData;
82 #define VTK_IMAGE_BLEND_MODE_NORMAL 0
83 #define VTK_IMAGE_BLEND_MODE_COMPOUND 1
85 class VTK_IMAGING_EXPORT vtkImageBlend : public vtkImageMultipleInputFilter
88 static vtkImageBlend *New();
89 vtkTypeRevisionMacro(vtkImageBlend,vtkImageMultipleInputFilter);
90 void PrintSelf(ostream& os, vtkIndent indent);
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);
99 // Set a stencil to apply when blending the data.
100 virtual void SetStencil(vtkImageStencilData*);
101 vtkGetObjectMacro(Stencil, vtkImageStencilData);
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);
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);
125 void ComputeInputUpdateExtent(int inExt[6], int outExt[6],
128 void ExecuteInformation() {
129 this->vtkImageMultipleInputFilter::ExecuteInformation(); };
131 void ExecuteInformation(vtkImageData **, vtkImageData *);
133 void ThreadedExecute(vtkImageData **inDatas,
134 vtkImageData *outData,
138 void ExecuteData(vtkDataObject *output);
140 vtkImageStencilData *Stencil;
142 int OpacityArrayLength;
144 float CompoundThreshold;
147 vtkImageBlend(const vtkImageBlend&); // Not implemented.
148 void operator=(const vtkImageBlend&); // Not implemented.
152 // Get the blending mode as a descriptive string
153 inline const char *vtkImageBlend::GetBlendModeAsString()
155 switch (this->BlendMode)
157 case VTK_IMAGE_BLEND_MODE_NORMAL:
159 case VTK_IMAGE_BLEND_MODE_COMPOUND:
162 return "Unknown Blend Mode";