1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkImageDataLIC2D.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 /**
16  * @class   vtkImageDataLIC2D
17  *
18  *
19  *  GPU implementation of a Line Integral Convolution, a technique for
20  *  imaging vector fields.
21  *
22  *  The input on port 0 is an vtkImageData with extents of a 2D image. It needs
23  *  a vector field on point data. This filter only works on point vectors. One
24  *  can use a vtkCellDataToPointData filter to convert cell vectors to point
25  *  vectors.
26  *
27  *  Port 1 is a special port for customized noise input. It is an optional port.
28  *  If noise input is not specified, then the filter using vtkImageNoiseSource to
29  *  generate a 128x128 noise texture.
30  *
31  * @sa
32  *  vtkSurfaceLICPainter vtkLineIntegralConvolution2D
33  */
34 
35 #ifndef vtkImageDataLIC2D_h
36 #define vtkImageDataLIC2D_h
37 
38 #include "vtkImageAlgorithm.h"
39 #include "vtkRenderingLICOpenGL2Module.h" // For export macro
40 #include "vtkWeakPointer.h"               // needed for vtkWeakPointer.
41 
42 class vtkRenderWindow;
43 class vtkOpenGLRenderWindow;
44 class vtkImageNoiseSource;
45 class vtkImageCast;
46 
47 class VTKRENDERINGLICOPENGL2_EXPORT vtkImageDataLIC2D : public vtkImageAlgorithm
48 {
49 public:
50   static vtkImageDataLIC2D* New();
51   vtkTypeMacro(vtkImageDataLIC2D, vtkImageAlgorithm);
52   void PrintSelf(ostream& os, vtkIndent indent) override;
53 
54   ///@{
55   /**
56    * Get/Set the context. Context must be a vtkOpenGLRenderWindow.
57    * This does not increase the reference count of the
58    * context to avoid reference loops.
59    * SetContext() may raise an error if the OpenGL context does not support the
60    * required OpenGL extensions. Return 0 upon failure and 1 upon success.
61    */
62   int SetContext(vtkRenderWindow* context);
63   vtkRenderWindow* GetContext();
64   ///@}
65 
66   ///@{
67   /**
68    * Number of steps. Initial value is 20.
69    * class invariant: Steps>0.
70    * In term of visual quality, the greater the better.
71    */
72   vtkSetMacro(Steps, int);
73   vtkGetMacro(Steps, int);
74   ///@}
75 
76   ///@{
77   /**
78    * Step size.
79    * Specify the step size as a unit of the cell length of the input vector
80    * field. Cell length is the length of the diagonal of a cell.
81    * Initial value is 1.0.
82    * class invariant: StepSize>0.0.
83    * In term of visual quality, the smaller the better.
84    * The type for the interface is double as VTK interface is double
85    * but GPU only supports float. This value will be converted to
86    * float in the execution of the algorithm.
87    */
88   vtkSetMacro(StepSize, double);
89   vtkGetMacro(StepSize, double);
90   ///@}
91 
92   ///@{
93   /**
94    * The magnification factor. Default is 1
95    */
96   vtkSetMacro(Magnification, int);
97   vtkGetMacro(Magnification, int);
98   ///@}
99 
100   ///@{
101   /**
102    * Check if the required OpenGL extensions / GPU are supported.
103    */
104   vtkGetMacro(OpenGLExtensionsSupported, int);
105   ///@}
106 
107   void TranslateInputExtent(const int* inExt, const int* inWholeExtent, int* outExt);
108 
109 protected:
110   vtkImageDataLIC2D();
111   ~vtkImageDataLIC2D() override;
112 
113   int RequestInformation(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
114 
115   /**
116    * Fill the input port information objects for this algorithm.  This
117    * is invoked by the first call to GetInputPortInformation for each
118    * port so subclasses can specify what they can handle.
119    * Redefined from the superclass.
120    */
121   int FillInputPortInformation(int port, vtkInformation* info) override;
122 
123   int RequestUpdateExtent(vtkInformation* vtkNotUsed(request), vtkInformationVector** inputVector,
124     vtkInformationVector* vtkNotUsed(outputVector)) override;
125 
126   /**
127    * This is called by the superclass.
128    * This is the method you should override.
129    */
130   int RequestData(vtkInformation* request, vtkInformationVector** inputVector,
131     vtkInformationVector* outputVector) override;
132 
133   vtkWeakPointer<vtkOpenGLRenderWindow> Context;
134   bool OwnWindow;
135   int OpenGLExtensionsSupported;
136 
137   vtkImageNoiseSource* NoiseSource;
138   vtkImageCast* ImageCast;
139 
140   int Steps;
141   double StepSize;
142   int Magnification;
143 
144 private:
145   vtkImageDataLIC2D(const vtkImageDataLIC2D&) = delete;
146   void operator=(const vtkImageDataLIC2D&) = delete;
147 };
148 
149 #endif
150