1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 5 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 6 All rights reserved. 7 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 8 9 This software is distributed WITHOUT ANY WARRANTY; without even 10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 11 PURPOSE. See the above copyright notice for more information. 12 13 =========================================================================*/ 14 /** 15 * @class vtkPointGaussianMapper 16 * @brief draw PointGaussians using imposters 17 * 18 * 19 * A mapper that uses imposters to draw gaussian splats or other shapes if 20 * custom shader code is set. Supports transparency and picking as well. It 21 * draws all the points and does not require cell arrays. If cell arrays are 22 * provided it will only draw the points used by the Verts cell array. The shape 23 * of the imposter is a triangle. 24 */ 25 26 #ifndef vtkPointGaussianMapper_h 27 #define vtkPointGaussianMapper_h 28 29 #include "vtkRenderingCoreModule.h" // For export macro 30 #include "vtkPolyDataMapper.h" 31 32 class vtkPiecewiseFunction; 33 34 class VTKRENDERINGCORE_EXPORT vtkPointGaussianMapper : public vtkPolyDataMapper 35 { 36 public: 37 static vtkPointGaussianMapper* New(); 38 vtkTypeMacro(vtkPointGaussianMapper, vtkPolyDataMapper) 39 void PrintSelf(ostream& os, vtkIndent indent) override; 40 41 //@{ 42 /** 43 * Set/Get the optional scale transfer function. This is only 44 * used when a ScaleArray is also specified. 45 */ 46 void SetScaleFunction(vtkPiecewiseFunction *); 47 vtkGetObjectMacro(ScaleFunction,vtkPiecewiseFunction); 48 //@} 49 50 //@{ 51 /** 52 * The size of the table used in computing scale, used when 53 * converting a vtkPiecewiseFunction to a table 54 */ 55 vtkSetMacro(ScaleTableSize, int); 56 vtkGetMacro(ScaleTableSize, int); 57 //@} 58 59 //@{ 60 /** 61 * Convenience method to set the array to scale with. 62 */ 63 vtkSetStringMacro(ScaleArray); 64 vtkGetStringMacro(ScaleArray); 65 //@} 66 67 //@{ 68 /** 69 * Convenience method to set the component of the array to scale with. 70 */ 71 vtkSetMacro(ScaleArrayComponent, int); 72 vtkGetMacro(ScaleArrayComponent, int); 73 //@} 74 75 //@{ 76 /** 77 * Set the default scale factor of the point gaussians. This 78 * defaults to 1.0. All radius computations will be scaled by the factor 79 * including the ScaleArray. If a vtkPiecewideFunction is used the 80 * scaling happens prior to the function lookup. 81 * A scale factor of 0.0 indicates that the splats should be rendered 82 * as simple points. 83 */ 84 vtkSetMacro(ScaleFactor,double); 85 vtkGetMacro(ScaleFactor,double); 86 //@} 87 88 //@{ 89 /** 90 * Treat the points/splats as emissive light sources. The default is true. 91 */ 92 vtkSetMacro(Emissive, vtkTypeBool); 93 vtkGetMacro(Emissive, vtkTypeBool); 94 vtkBooleanMacro(Emissive, vtkTypeBool); 95 //@} 96 97 //@{ 98 /** 99 * Set/Get the optional opacity transfer function. This is only 100 * used when an OpacityArray is also specified. 101 */ 102 void SetScalarOpacityFunction(vtkPiecewiseFunction *); 103 vtkGetObjectMacro(ScalarOpacityFunction,vtkPiecewiseFunction); 104 //@} 105 106 //@{ 107 /** 108 * The size of the table used in computing opacities, used when 109 * converting a vtkPiecewiseFunction to a table 110 */ 111 vtkSetMacro(OpacityTableSize, int); 112 vtkGetMacro(OpacityTableSize, int); 113 //@} 114 115 //@{ 116 /** 117 * Method to set the optional opacity array. If specified this 118 * array will be used to generate the opacity values. 119 */ 120 vtkSetStringMacro(OpacityArray); 121 vtkGetStringMacro(OpacityArray); 122 //@} 123 124 //@{ 125 /** 126 * Convenience method to set the component of the array to opacify with. 127 */ 128 vtkSetMacro(OpacityArrayComponent, int); 129 vtkGetMacro(OpacityArrayComponent, int); 130 //@} 131 132 //@{ 133 /** 134 * Method to override the fragment shader code for the splat. You can 135 * set this to draw other shapes. For the OPenGL2 backend some of 136 * the variables you can use and/or modify include, 137 * opacity - 0.0 to 1.0 138 * diffuseColor - vec3 139 * ambientColor - vec3 140 * offsetVCVSOutput - vec2 offset in view coordinates from the splat center 141 */ 142 vtkSetStringMacro(SplatShaderCode); 143 vtkGetStringMacro(SplatShaderCode); 144 //@} 145 146 //@{ 147 /** 148 * When drawing triangles as opposed too point mode 149 * (triangles are for splats shaders that are bigger than a pixel) 150 * this controls how large the triangle will be. By default it 151 * is large enough to contain a cicle of radius 3.0*scale which works 152 * well for gaussian splats as after 3.0 standard deviations the 153 * opacity is near zero. For custom shader codes a different 154 * value can be used. Generally you should use the lowest value you can 155 * as it will result in fewer fragments. For example if your custom 156 * shader only draws a disc of radius 1.0*scale, then set this to 1.0 157 * to avoid sending many fragments to the shader that will just get 158 * discarded. 159 */ 160 vtkSetMacro(TriangleScale,float); 161 vtkGetMacro(TriangleScale,float); 162 //@} 163 164 /** 165 * WARNING: INTERNAL METHOD - NOT INTENDED FOR GENERAL USE 166 * DO NOT USE THIS METHOD OUTSIDE OF THE RENDERING PROCESS 167 * Used by vtkHardwareSelector to determine if the prop supports hardware 168 * selection. 169 */ GetSupportsSelection()170 bool GetSupportsSelection() override 171 { return true; } 172 173 protected: 174 vtkPointGaussianMapper(); 175 ~vtkPointGaussianMapper() override; 176 177 char *ScaleArray; 178 int ScaleArrayComponent; 179 char *OpacityArray; 180 int OpacityArrayComponent; 181 char *SplatShaderCode; 182 183 vtkPiecewiseFunction *ScaleFunction; 184 int ScaleTableSize; 185 186 vtkPiecewiseFunction *ScalarOpacityFunction; 187 int OpacityTableSize; 188 189 double ScaleFactor; 190 vtkTypeBool Emissive; 191 192 float TriangleScale; 193 194 private: 195 vtkPointGaussianMapper(const vtkPointGaussianMapper&) = delete; 196 void operator=(const vtkPointGaussianMapper&) = delete; 197 }; 198 199 #endif 200