1 /** 2 * @class vtkF3DRendererWithColoring 3 * @brief A specialiwed renderer that can handle coloring 4 * 5 * A specialization of vtkF3DRenderer that can handle coloring 6 * with actors such as a geometry actor, a point sprites actor, 7 * a volume mapper. It also handle the showing of the related scalar bar. 8 */ 9 10 #ifndef vtkF3DRendererWithColoring_h 11 #define vtkF3DRendererWithColoring_h 12 13 #include "vtkF3DRenderer.h" 14 15 #include <vtkPolyDataMapper.h> 16 #include <vtkScalarBarActor.h> 17 #include <vtkSmartVolumeMapper.h> 18 19 class vtkColorTransferFunction; 20 class vtkDataSetAttributes; 21 22 class vtkF3DRendererWithColoring : public vtkF3DRenderer 23 { 24 public: 25 static vtkF3DRendererWithColoring* New(); 26 vtkTypeMacro(vtkF3DRendererWithColoring, vtkF3DRenderer); 27 28 void Initialize(const F3DOptions& options, const std::string& fileInfo) override; 29 30 //@{ 31 /** 32 * Set/Get the visibility of the scalar bar. 33 * It will only be shown when coloring and not 34 * using direct scalars rendering. 35 */ 36 void ShowScalarBar(bool show); 37 bool IsScalarBarVisible(); 38 //@} 39 40 //@{ 41 /** 42 * Set/Get the visibility of the point sprites actor. 43 * It will inly be shown if raytracing and volume are not enabled 44 */ 45 void SetUsePointSprites(bool use); 46 bool UsingPointSprites(); 47 //@} 48 49 //@{ 50 /** 51 * Set/Get the visibility of the volume actor. 52 * It will inly be shown if the data is compatible with volume rendering 53 * and raytracing is not enabled 54 */ 55 void SetUseVolume(bool use); 56 bool UsingVolume(); 57 //@} 58 59 //@{ 60 /** 61 * Set/Get the use of an inverted opacity function 62 * for volume rendering.. 63 */ 64 bool UsingInverseOpacityFunction(); 65 void SetUseInverseOpacityFunction(bool use); 66 //@} 67 68 enum CycleTypeEnum 69 { 70 F3D_FIELD_CYCLE = 0, 71 F3D_ARRAY_CYCLE, 72 F3D_COMPONENT_CYCLE 73 }; 74 75 /** 76 * Cycle the shown scalars according to the cycle type 77 */ 78 void CycleScalars(int cycleType); 79 80 //@{ 81 /** 82 * Set/Get the scalar bar actor, used for hotkey purposes 83 */ 84 vtkGetSmartPointerMacro(ScalarBarActor, vtkScalarBarActor); 85 vtkSetSmartPointerMacro(ScalarBarActor, vtkScalarBarActor); 86 //@} 87 88 //@{ 89 /** 90 * Set/Get the geometry actor 91 */ 92 vtkGetSmartPointerMacro(GeometryActor, vtkActor); 93 vtkSetSmartPointerMacro(GeometryActor, vtkActor); 94 //@} 95 96 //@{ 97 /** 98 * Set/Get the point sprites actor 99 */ 100 vtkGetSmartPointerMacro(PointSpritesActor, vtkActor); 101 vtkSetSmartPointerMacro(PointSpritesActor, vtkActor); 102 //@} 103 104 //@{ 105 /** 106 * Set/Get the volume prop 107 */ 108 vtkGetSmartPointerMacro(VolumeProp, vtkVolume); 109 vtkSetSmartPointerMacro(VolumeProp, vtkVolume); 110 //@} 111 112 //@{ 113 /** 114 * Set/Get the polydata mapper 115 */ 116 vtkGetSmartPointerMacro(PolyDataMapper, vtkPolyDataMapper); 117 vtkSetSmartPointerMacro(PolyDataMapper, vtkPolyDataMapper); 118 //@} 119 120 //@{ 121 /** 122 * Set/Get the point gaussian mapper, used for hotkey purposes 123 */ 124 vtkGetSmartPointerMacro(PointGaussianMapper, vtkPolyDataMapper); 125 vtkSetSmartPointerMacro(PointGaussianMapper, vtkPolyDataMapper); 126 //@} 127 128 //@{ 129 /** 130 * Set/Get the volume mapper, used for hotkey purposes 131 */ 132 vtkGetSmartPointerMacro(VolumeMapper, vtkSmartVolumeMapper); 133 vtkSetSmartPointerMacro(VolumeMapper, vtkSmartVolumeMapper); 134 //@} 135 136 /** 137 * Set the coloring variables needed. 138 */ 139 void SetColoring(vtkDataSetAttributes* pointData, vtkDataSetAttributes* cellData, 140 bool useCellData, int arrayIndex, int component); 141 142 /** 143 * Update the visibility and coloring of internal actors as well as the scalar bar actors 144 */ 145 void UpdateInternalActors() override; 146 147 protected: 148 vtkF3DRendererWithColoring() = default; 149 ~vtkF3DRendererWithColoring() override = default; 150 151 static void ConfigureMapperForColoring(vtkPolyDataMapper* mapper, vtkDataArray* array, 152 int component, vtkColorTransferFunction* ctf, double range[2], bool cellFlag = false); 153 154 static void ConfigureVolumeForColoring(vtkSmartVolumeMapper* mapper, vtkVolume* volume, 155 vtkDataArray* array, int component, vtkColorTransferFunction* ctf, double range[2], 156 bool cellFlag = false, bool inverseOpacityFlag = false); 157 158 static void ConfigureScalarBarActorForColoring(vtkScalarBarActor* scalarBar, vtkDataArray* array, 159 int component, vtkColorTransferFunction* ctf); 160 161 void ConfigureRangeAndCTFForColoring(vtkDataArray* array, int component); 162 163 void UpdateScalarBarVisibility(); 164 165 void FillCheatSheetHotkeys(std::stringstream& sheet) override; 166 167 /** 168 * Switch between point data and cell data coloring 169 */ 170 void CycleFieldForColoring(); 171 172 /** 173 * Cycle the array used for coloring 174 * This will iterate over the current DataForColoring 175 * until it find a valid array or cycle back to non coloring 176 * Set checkCurrent to true to check the current array index 177 * before incrementing 178 */ 179 void CycleArrayForColoring(bool checkCurrent = false); 180 181 /** 182 * Increment the array index or loop it back 183 * When not using volume, it will loop back 184 * to not coloring 185 */ 186 void CycleArrayIndexForColoring(); 187 188 /** 189 * Cycle the component in used for rendering 190 * looping back to direct scalars if supported or magnitude. 191 */ 192 void CycleComponentForColoring(); 193 194 /** 195 * A method that checks if the current component is valid 196 * if not, it will reset it to 0 197 */ 198 void CheckCurrentComponentForColoring(); 199 200 /** 201 * Print info about the current coloring array 202 */ 203 void PrintColoringInfo(); 204 205 std::string GenerateMetaDataDescription() override; 206 207 /** 208 * Convert a component index into a string 209 */ 210 static std::string ComponentToString(int component); 211 212 /** 213 * Shorten a provided name with "..." 214 */ 215 static std::string ShortName(const std::string& name, int component); 216 217 vtkSmartPointer<vtkActor> GeometryActor; 218 vtkSmartPointer<vtkActor> PointSpritesActor; 219 vtkSmartPointer<vtkVolume> VolumeProp; 220 221 vtkSmartPointer<vtkScalarBarActor> ScalarBarActor; 222 bool ScalarBarActorConfigured = false; 223 224 vtkSmartPointer<vtkPolyDataMapper> PolyDataMapper; 225 bool PolyDataMapperConfigured = false; 226 227 vtkSmartPointer<vtkPolyDataMapper> PointGaussianMapper; 228 bool PointGaussianMapperConfigured = false; 229 230 vtkSmartPointer<vtkSmartVolumeMapper> VolumeMapper; 231 bool VolumeConfigured = false; 232 233 vtkSmartPointer<vtkColorTransferFunction> ColorTransferFunction; 234 double ColorRange[2]; 235 bool ColorTransferFunctionConfigured = false; 236 237 vtkDataSetAttributes* PointDataForColoring = nullptr; 238 vtkDataSetAttributes* CellDataForColoring = nullptr; 239 int ArrayIndexForColoring = -1; 240 int ComponentForColoring = -1; 241 242 vtkDataSetAttributes* DataForColoring = nullptr; 243 vtkDataArray* ArrayForColoring = nullptr; 244 245 bool ScalarBarVisible = false; 246 bool UsePointSprites = false; 247 bool UseVolume = false; 248 bool UseInverseOpacityFunction = false; 249 }; 250 251 #endif 252