1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkCompositePainter.h
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 // .NAME vtkCompositePainter - painter that can be inserted before any
16 // vtkDataSet painting chain to handle composite datasets.
17 // .SECTION Description
18 // vtkCompositePainter iterates over the leaves in a composite datasets.
19 // This painter can also handle the case when the dataset is not a composite
20 // dataset.
21 
22 #ifndef vtkCompositePainter_h
23 #define vtkCompositePainter_h
24 
25 #include "vtkRenderingOpenGLModule.h" // For export macro
26 #include "vtkPainter.h"
27 #include "vtkColor.h" // needed for vtkColor3d
28 #include <stack> //  needed for RenderBlockState.
29 
30 class vtkCompositeDataDisplayAttributes;
31 class vtkInformationObjectBaseKey;
32 class vtkProperty;
33 class vtkRenderWindow;
34 
35 class VTKRENDERINGOPENGL_EXPORT vtkCompositePainter : public vtkPainter
36 {
37 public:
38   static vtkCompositePainter* New();
39   vtkTypeMacro(vtkCompositePainter, vtkPainter);
40   void PrintSelf(ostream& os, vtkIndent indent);
41 
42   // Description:
43   // Get the output data object from this painter. The default implementation
44   // simply forwards the input data object as the output.
45   virtual vtkDataObject* GetOutput();
46 
47   // Description:
48   // Key used to pass a vtkCompositeDataDisplayAttributes instance doing the
49   // painter pipeline.
50   static vtkInformationObjectBaseKey* DISPLAY_ATTRIBUTES();
51 
52   // Description:
53   // Set/get the composite data set display attributes. If set, these attributes
54   // can be used by the painter to control specific rendering attributes on a
55   // per-block basis for a multi-block dataset.
56   void SetCompositeDataDisplayAttributes(vtkCompositeDataDisplayAttributes *attributes);
57   vtkGetObjectMacro(CompositeDataDisplayAttributes, vtkCompositeDataDisplayAttributes)
58 
59 //BTX
60 protected:
61   vtkCompositePainter();
62   ~vtkCompositePainter();
63 
64   // Description:
65   // Take part in garbage collection.
66   virtual void ReportReferences(vtkGarbageCollector *collector);
67 
68   // Description:
69   // Called before RenderInternal() if the Information has been changed
70   // since the last time this method was called.
71   virtual void ProcessInformation(vtkInformation* information);
72 
73   // Description:
74   // Performs the actual rendering. Subclasses may override this method.
75   // default implementation merely call a Render on the DelegatePainter,
76   // if any. When RenderInternal() is called, it is assured that the
77   // DelegatePainter is in sync with this painter i.e. UpdateDelegatePainter()
78   // has been called.
79   virtual void RenderInternal(vtkRenderer* renderer, vtkActor* actor,
80     unsigned long typeflags, bool forceCompileOnly);
81 
82   class RenderBlockState
83     {
84   public:
85     std::stack<bool> Visibility;
86     std::stack<double> Opacity;
87     std::stack<vtkColor3d> AmbientColor;
88     std::stack<vtkColor3d> DiffuseColor;
89     std::stack<vtkColor3d> SpecularColor;
90 
91     double RenderedOpacity;
92     vtkColor3d RenderedAmbientColor;
93     vtkColor3d RenderedDiffuseColor;
94     vtkColor3d RenderedSpecularColor;
95     };
96 
97   void RenderBlock(vtkRenderer *renderer,
98                    vtkActor *actor,
99                    unsigned long typeflags,
100                    bool forceCompileOnly,
101                    vtkDataObject *dobj,
102                    unsigned int &flat_index,
103                    RenderBlockState &state);
104 
105   // Description:
106   // Overridden in vtkOpenGLCompositePainter to pass attributes to OpenGL.
UpdateRenderingState(vtkRenderWindow *,vtkProperty *,RenderBlockState &)107   virtual void UpdateRenderingState(
108     vtkRenderWindow*, vtkProperty*, RenderBlockState&) {}
109 
110   vtkDataObject* OutputData;
111   vtkCompositeDataDisplayAttributes *CompositeDataDisplayAttributes;
112 private:
113   vtkCompositePainter(const vtkCompositePainter&); // Not implemented.
114   void operator=(const vtkCompositePainter&); // Not implemented.
115 //ETX
116 };
117 
118 #endif
119