forked from f3d-app/f3d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvtkF3DRenderer.h
624 lines (527 loc) · 16.6 KB
/
vtkF3DRenderer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
/**
* @class vtkF3DRenderer
* @brief A F3D dedicated renderer
*
* This renderers all the generic actors added by F3D which includes
* UI, axis, grid, edges, timer, metadata and cheatsheet.
* It also handles the different rendering passes, including
* raytracing, ssao, anti-aliasing, tonemapping.
*/
#ifndef vtkF3DRenderer_h
#define vtkF3DRenderer_h
#include "vtkF3DMetaImporter.h"
#include "vtkF3DUIActor.h"
#include <vtkLight.h>
#include <vtkOpenGLRenderer.h>
#include <filesystem>
#include <map>
#include <optional>
namespace fs = std::filesystem;
class vtkColorTransferFunction;
class vtkCornerAnnotation;
class vtkImageReader2;
class vtkOrientationMarkerWidget;
class vtkScalarBarActor;
class vtkSkybox;
class vtkTextActor;
class vtkF3DRenderer : public vtkOpenGLRenderer
{
public:
static vtkF3DRenderer* New();
vtkTypeMacro(vtkF3DRenderer, vtkOpenGLRenderer);
/**
* Enum listing possible anti aliasing modes.
*/
enum class AntiAliasingMode : unsigned char
{
NONE,
FXAA,
SSAA
};
///@{
/**
* Set visibility of different actors
*/
void ShowAxis(bool show);
void ShowGrid(bool show);
void ShowEdge(const std::optional<bool>& show);
void ShowTimer(bool show);
void ShowMetaData(bool show);
void ShowFilename(bool show);
void ShowCheatSheet(bool show);
void ShowConsole(bool show);
void ShowMinimalConsole(bool show);
void ShowDropZone(bool show);
void ShowHDRISkybox(bool show);
void ShowArmature(bool show);
///@}
using vtkOpenGLRenderer::SetBackground;
///@{
/**
* Set different actors parameters
*/
void SetLineWidth(const std::optional<double>& lineWidth);
void SetPointSize(const std::optional<double>& pointSize);
void SetFontFile(const std::optional<fs::path>& fontFile);
void SetFontScale(const double fontScale);
void SetHDRIFile(const std::optional<fs::path>& hdriFile);
void SetUseImageBasedLighting(bool use) override;
void SetBackground(const double* backgroundColor) override;
void SetLightIntensity(const double intensity);
void SetFilenameInfo(const std::string& info);
void SetDropZoneInfo(const std::string& info);
void SetGridAbsolute(bool absolute);
void SetGridUnitSquare(const std::optional<double>& unitSquare);
void SetGridSubdivisions(int subdivisions);
void SetGridColor(const std::vector<double>& color);
///@}
///@{
/**
* Set usages and configurations of different render passes
*/
void SetUseRaytracing(bool use);
void SetUseRaytracingDenoiser(bool use);
void SetUseDepthPeelingPass(bool use);
void SetUseSSAOPass(bool use);
void SetAntiAliasingMode(AntiAliasingMode mode);
void SetUseToneMappingPass(bool use);
void SetUseBlurBackground(bool use);
void SetBlurCircleOfConfusionRadius(double radius);
void SetRaytracingSamples(int samples);
void SetBackfaceType(const std::optional<std::string>& backfaceType);
void SetFinalShader(const std::optional<std::string>& finalShader);
///@}
/**
* Set SetUseOrthographicProjection
*/
void SetUseOrthographicProjection(const std::optional<bool>& use);
///@{
/**
* Set/Get UseTrackball
*/
void SetUseTrackball(bool use);
vtkGetMacro(UseTrackball, bool);
///@}
///@{
/**
* Set/Get InvertZoom
*/
vtkSetMacro(InvertZoom, bool);
vtkGetMacro(InvertZoom, bool);
///@}
/**
* Reimplemented to configure:
* - ActorsProperties
* - Timer
* before actual rendering, only when needed
*/
void Render() override;
/**
* Reimplemented to account for grid actor
*/
void ResetCameraClippingRange() override;
/**
* Set properties on each imported actors and also configure the coloring
* Then update dedicated actors and logics according to the properties of this class:
* - HDRI
* - MetaData
* - Texts
* - RenderPasses
* - Grid
*/
void UpdateActors();
/**
* Reimplemented to handle light creation when no lights are added
* return the number of lights in the renderer.
*/
int UpdateLights() override;
/**
* Initialize the renderer actors and flags.
* Should be called after being added to a vtkRenderWindow.
*/
void Initialize();
/**
* Initialize actors properties related to the up vector using the provided upString, including
* the camera
*/
void InitializeUpVector(const std::vector<double>& upVec);
/**
* Compute bounds of visible props as transformed by given matrix.
*/
vtkBoundingBox ComputeVisiblePropOrientedBounds(const vtkMatrix4x4*);
/**
* Get the OpenGL skybox
*/
vtkGetObjectMacro(SkyboxActor, vtkSkybox);
/**
* Return description about the current rendering status
* Currently contains information about the camera and the grid if any
* Returns a multiline string containing the scene description
*/
std::string GetSceneDescription();
/**
* Get up vector
*/
vtkGetVector3Macro(UpVector, double);
/**
* Set/Get right vector
*/
vtkGetVector3Macro(RightVector, double);
/**
* Set cache path, only used by the HDRI logic
*/
void SetCachePath(const std::string& cachePath);
/**
* Set the roughness on all actors
*/
void SetRoughness(const std::optional<double>& roughness);
/**
* Set the surface color on all actors
*/
void SetSurfaceColor(const std::optional<std::vector<double>>& color);
/**
* Set the emmissive factors on all actors
*/
void SetEmissiveFactor(const std::optional<std::vector<double>>& factors);
/**
* Set the opacity on all actors
*/
void SetOpacity(const std::optional<double>& opacity);
/**
* Set the metallic on all actors
*/
void SetMetallic(const std::optional<double>& metallic);
/**
* Set the normal scale on all actors
*/
void SetNormalScale(const std::optional<double>& normalScale);
/**
* Set the material capture texture on all actors.
* This texture includes baked lighting effect,
* so all other material textures are ignored.
*/
void SetTextureMatCap(const std::optional<fs::path>& tex);
/**
* Set the base color texture on all actors
*/
void SetTextureBaseColor(const std::optional<fs::path>& tex);
/**
* Set the material texture on all actors
*/
void SetTextureMaterial(const std::optional<fs::path>& tex);
/**
* Set the emissive texture on all actors
*/
void SetTextureEmissive(const std::optional<fs::path>& tex);
/**
* Set the normal texture on all actors
*/
void SetTextureNormal(const std::optional<fs::path>& tex);
enum class SplatType
{
SPHERE,
GAUSSIAN
};
/**
* Set the point sprites size and the splat type on the pointGaussianMapper
*/
void SetPointSpritesProperties(SplatType splatType, double pointSpritesSize);
/**
* Set the visibility of the scalar bar.
* It will only be shown when coloring and not shown
* when using direct scalars rendering.
*/
void ShowScalarBar(bool show);
/**
* Set the visibility of the point sprites actor.
* It will only be shown if raytracing and volume are not enabled
*/
void SetUsePointSprites(bool use);
/**
* Set the visibility of the volume actor.
* It will only be shown if the data is compatible with volume rendering
* and raytracing is not enabled
*/
void SetUseVolume(bool use);
/**
* Set the use of an inverted opacity function
* for volume rendering..
*/
void SetUseInverseOpacityFunction(bool use);
/**
* Set the range of the scalar bar
* Setting an empty vector will use automatic range
*/
void SetScalarBarRange(const std::optional<std::vector<double>>& range);
/**
* Set the colormap to use
* Setting an empty vector will use default color map
*/
void SetColormap(const std::vector<double>& colormap);
/**
* Set the meta importer to recover coloring information from
*/
void SetImporter(vtkF3DMetaImporter* importer);
///@{
/**
* Set/Get if coloring is enabled
*/
void SetEnableColoring(bool enable);
vtkGetMacro(EnableColoring, bool);
///@}
///@{
/**
* Set/Get if using point or cell data coloring
*/
void SetUseCellColoring(bool useCell);
vtkGetMacro(UseCellColoring, bool);
///@}
///@{
/**
* Set/Get the name of the array to use for coloring
*/
void SetArrayNameForColoring(const std::optional<std::string>& arrayName);
std::optional<std::string> GetArrayNameForColoring();
///@}
///@{
/**
* Set/Get the name of the component to use for coloring
*/
void SetComponentForColoring(int component);
vtkGetMacro(ComponentForColoring, int);
///@}
/**
* Get information about the current coloring
* Returns a single line string containing the coloring description
*/
virtual std::string GetColoringDescription();
/**
* Switch between point data and cell data coloring, actually setting UseCellColoring member.
* This can trigger CycleArrayForColoring if current array is not valid.
*/
void CycleFieldForColoring();
/**
* Cycle the current array for coloring, actually setting EnableColoring and ArrayNameForColoring
* members. This loops back to not coloring if volume is not enabled. This can trigger
* CycleComponentForColoring if current component is not valid.
*/
void CycleArrayForColoring();
/**
* Cycle the component in used for rendering
* looping back to direct scalars
*/
void CycleComponentForColoring();
/**
* Convert a component index into a string
* If there is a component name defined in the current coloring information, display it.
* Otherwise, use component #index as the default value.
*/
std::string ComponentToString(int component);
/**
* Return true if the cheatsheet info is potentially
* out of date since the last ConfigureCheatSheet call,
* false otherwise.
*/
bool CheatSheetNeedsUpdate() const;
/**
* Configure the cheatsheet data from the provided info
* Should be called before Render() if CheatSheetInfoNeedsUpdate() returns true.
*/
void ConfigureCheatSheet(const std::vector<vtkF3DUIActor::CheatSheetGroup>& info);
/**
* Use this method to flag in the renderer that the cheatsheet needs to be updated
* This is not required to call when using any of the setter of the renderer
*/
void SetCheatSheetConfigured(bool flag);
/**
* Set the UI delta time (time between frame being rendered) in seconds
*/
void SetUIDeltaTime(double time);
/**
* Set console badge enabled status
*/
void SetConsoleBadgeEnabled(bool enabled);
private:
vtkF3DRenderer();
~vtkF3DRenderer() override;
void ReleaseGraphicsResources(vtkWindow* w) override;
bool IsBackgroundDark();
/**
* Configure meta data actor visibility and content
*/
void ConfigureMetaData();
/**
* Configure text actors properties font file and color
*/
void ConfigureTextActors();
///@{
/**
* Configure HDRI actor and related lighting textures
*/
void ConfigureHDRI();
void ConfigureHDRIReader();
void ConfigureHDRIHash();
void ConfigureHDRITexture();
void ConfigureHDRILUT();
void ConfigureHDRISphericalHarmonics();
void ConfigureHDRISpecular();
void ConfigureHDRISkybox();
///@}
///@{
/**
* Methods to check if certain HDRI caches are available
*/
bool CheckForSpecCache(std::string& path);
bool CheckForSHCache(std::string& path);
///@}
/**
* Configure all actors properties
*/
void ConfigureActorsProperties();
/**
* Configure the grid
*/
void ConfigureGridUsingCurrentActors();
/**
* Configure the different render passes
*/
void ConfigureRenderPasses();
/**
* Create a cache directory if a HDRIHash is set
*/
void CreateCacheDirectory();
/**
* Configure coloring for all actors
*/
void ConfigureColoring();
/**
* Convenience method for configuring a poly data mapper for coloring
* Return true if mapper was configured for coloring, false otherwise.
*/
static bool ConfigureMapperForColoring(vtkPolyDataMapper* mapper, const std::string& name,
int component, vtkColorTransferFunction* ctf, double range[2], bool cellFlag = false);
/**
* Convenience method for configuring a volume mapper and volume prop for coloring
* Return true if they were configured for coloring, false otherwise.
*/
static bool ConfigureVolumeForColoring(vtkSmartVolumeMapper* mapper, vtkVolume* volume,
const std::string& name, int component, vtkColorTransferFunction* ctf, double range[2],
bool cellFlag = false, bool inverseOpacityFlag = false);
/**
* Convenience method for configuring a scalar bar actor for coloring
*/
void ConfigureScalarBarActorForColoring(vtkScalarBarActor* scalarBar, std::string arrayName,
int component, vtkColorTransferFunction* ctf);
/**
* Configure internal range and color transfer function according to provided
* coloring info
*/
void ConfigureRangeAndCTFForColoring(const F3DColoringInfoHandler::ColoringInfo& info);
vtkSmartPointer<vtkOrientationMarkerWidget> AxisWidget;
vtkNew<vtkActor> GridActor;
vtkNew<vtkSkybox> SkyboxActor;
vtkNew<vtkF3DUIActor> UIActor;
unsigned int Timer = 0; // Timer OpenGL query
bool CheatSheetConfigured = false;
bool ActorsPropertiesConfigured = false;
bool GridConfigured = false;
bool RenderPassesConfigured = false;
bool LightIntensitiesConfigured = false;
bool TextActorsConfigured = false;
bool MetaDataConfigured = false;
bool HDRIReaderConfigured = false;
bool HDRIHashConfigured = false;
bool HDRITextureConfigured = false;
bool HDRILUTConfigured = false;
bool HDRISphericalHarmonicsConfigured = false;
bool HDRISpecularConfigured = false;
bool HDRISkyboxConfigured = false;
bool GridVisible = false;
bool GridAbsolute = false;
bool AxisVisible = false;
std::optional<bool> EdgeVisible;
bool TimerVisible = false;
bool FilenameVisible = false;
bool MetaDataVisible = false;
bool CheatSheetVisible = false;
bool ConsoleVisible = false;
bool MinimalConsoleVisible = false;
bool DropZoneVisible = false;
bool HDRISkyboxVisible = false;
bool ArmatureVisible = false;
bool UseRaytracing = false;
bool UseRaytracingDenoiser = false;
bool UseDepthPeelingPass = false;
AntiAliasingMode AntiAliasingModeEnabled = AntiAliasingMode::NONE;
bool UseSSAOPass = false;
bool UseToneMappingPass = false;
bool UseBlurBackground = false;
std::optional<bool> UseOrthographicProjection = false;
bool UseTrackball = false;
bool InvertZoom = false;
int RaytracingSamples = 0;
double UpVector[3] = { 0.0, 1.0, 0.0 };
double RightVector[3] = { 1.0, 0.0, 0.0 };
double CircleOfConfusionRadius = 20.0;
std::optional<double> PointSize;
std::optional<double> LineWidth;
std::optional<double> GridUnitSquare;
int GridSubdivisions = 10;
double GridColor[3] = { 0.0, 0.0, 0.0 };
std::string HDRIFile;
vtkSmartPointer<vtkImageReader2> HDRIReader;
bool HasValidHDRIReader = false;
bool UseDefaultHDRI = false;
std::string HDRIHash;
bool HasValidHDRIHash = false;
vtkSmartPointer<vtkTexture> HDRITexture;
bool HasValidHDRITexture = false;
bool HasValidHDRILUT = false;
bool HasValidHDRISH = false;
bool HasValidHDRISpec = false;
std::optional<fs::path> FontFile;
double FontScale = 1.0;
double LightIntensity = 1.0;
std::map<vtkLight*, double> OriginalLightIntensities;
std::string CurrentGridInfo;
std::string GridInfo;
std::string CachePath;
std::optional<std::string> BackfaceType;
std::optional<std::string> FinalShader;
vtkF3DMetaImporter* Importer = nullptr;
vtkMTimeType ImporterTimeStamp = 0;
vtkMTimeType ImporterUpdateTimeStamp = 0;
vtkNew<vtkScalarBarActor> ScalarBarActor;
bool ScalarBarActorConfigured = false;
bool ColoringMappersConfigured = false;
bool PointSpritesMappersConfigured = false;
bool VolumePropsAndMappersConfigured = false;
bool ColoringConfigured = false;
std::optional<double> Opacity;
std::optional<double> Roughness;
std::optional<double> Metallic;
std::optional<double> NormalScale;
std::optional<std::vector<double>> SurfaceColor;
std::optional<std::vector<double>> EmissiveFactor;
std::optional<fs::path> TextureMatCap;
std::optional<fs::path> TextureBaseColor;
std::optional<fs::path> TextureMaterial;
std::optional<fs::path> TextureEmissive;
std::optional<fs::path> TextureNormal;
vtkSmartPointer<vtkColorTransferFunction> ColorTransferFunction;
bool ExpandingRangeSet = false;
bool UsingExpandingRange = true;
double ColorRange[2] = { 0.0, 1.0 };
bool ColorTransferFunctionConfigured = false;
bool EnableColoring = false;
bool UseCellColoring = false;
int ComponentForColoring = -1;
std::optional<std::string> ArrayNameForColoring;
bool ScalarBarVisible = false;
bool UsePointSprites = false;
bool UseVolume = false;
bool UseInverseOpacityFunction = false;
std::optional<std::vector<double>> UserScalarBarRange;
std::vector<double> Colormap;
};
#endif