NVIDIA DeepLearning Dataset Synthesizer (NDDS)
 All Classes Namespaces Functions Variables Typedefs Pages
NVSceneCapturerViewpointComponent.h
1 /*
2 * Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
3 *
4 * NVIDIA CORPORATION and its licensors retain all intellectual property
5 * and proprietary rights in and to this software, related documentation
6 * and any modifications thereto. Any use, reproduction, disclosure or
7 * distribution of this software and related documentation without an express
8 * license agreement from NVIDIA CORPORATION is strictly prohibited.
9 */
10 
11 #pragma once
12 
13 #include "Components/SceneComponent.h"
14 #include "NVSceneCapturerUtils.h"
15 #include "NVSceneFeatureExtractor.h"
16 #include "NVSceneFeatureExtractor_DataExport.h"
17 #include "NVSceneFeatureExtractor_ImageExport.h"
18 #include "NVTextureReader.h"
19 #include "NVSceneCapturerViewpointComponent.generated.h"
20 
21 DECLARE_LOG_CATEGORY_EXTERN(LogNVSceneCapturerViewpointComponent, Log, All)
22 
23 USTRUCT(BlueprintType)
24 struct NVSCENECAPTURER_API FNVSceneCapturerViewpointSettings
25 {
26  GENERATED_BODY()
27 
28 public:
29  FNVSceneCapturerViewpointSettings();
30 
31 public: // Editor properties
32  /// If true, the viewpoint will capture otherwise it won't
33  UPROPERTY(EditAnywhere, Category = Config)
34  bool bIsEnabled;
35 
36  /// Name of the viewpoint to show
37  UPROPERTY(EditAnywhere, Category = Config)
38  FString DisplayName;
39 
40  /// The string to add to the end of the exported file's name captured from this viewpoint. e.g: "infrared", "left", "right" ...
41  UPROPERTY(EditAnywhere, Category = Config)
42  FString ExportFileNamePostfix;
43 
44  /// If true, the viewpoint have its own feature extractors settings and doesn't use the owner capturer's feature extractor settings
45  UPROPERTY(EditAnywhere, Category = FeatureExtraction, meta = (PinHiddenByDefault, InlineEditConditionToggle))
46  bool bOverrideFeatureExtractorSettings;
47 
48  UPROPERTY(EditAnywhere, Category = FeatureExtraction, meta = (editcondition = "bOverrideFeatureExtractorSettings"))
49  TArray<FNVFeatureExtractorSettings> FeatureExtractorSettings;
50 
51  /// If true, the viewpoint have its own capture settings and doesn't use the owner capturer's feature extractor settings
52  UPROPERTY(EditAnywhere, Category = Settings, meta = (PinHiddenByDefault, InlineEditConditionToggle))
53  bool bOverrideCaptureSettings;
54 
55  UPROPERTY(EditAnywhere, Category = Settings, meta = (editcondition="bOverrideCaptureSettings"))
56  FNVSceneCapturerSettings CaptureSettings;
57 };
58 
59 
60 ///
61 /// UNVSceneCapturerViewpointComponent: Represents each viewpoint from where the capturer captures data
62 ///
63 /// @cond DOXYGEN_SUPPRESSED_CODE
64 UCLASS(Blueprintable, ClassGroup = (NVIDIA), meta = (BlueprintSpawnableComponent),
65  HideCategories = (Replication, ComponentReplication, Cooking, Events, ComponentTick, Actor, Input, Collision,
66  Physics, PhysX, Activation, Sockets, Rendering, LOD, Tags))
67 /// @endcond DOXYGEN_SUPPRESSED_CODE
68 class NVSCENECAPTURER_API UNVSceneCapturerViewpointComponent : public USceneComponent
69 {
70  GENERATED_BODY()
71 
72 public:
73  UNVSceneCapturerViewpointComponent(const FObjectInitializer& ObjectInitializer);
74 
75  /// Callback function get called after the scene capture component finished capturing scene and read back its pixels data
76  /// FNVTexturePixelData - The struct contain the captured scene's pixels data
77  /// UNVSceneFeatureExtractor_PixelData* - Reference to the feature extractor that captured the scene pixels data
78  /// UNVSceneCapturerViewpointComponent* - Reference to the viewpoint that captured the scene pixels data
79  typedef TFunction<void(const FNVTexturePixelData&, UNVSceneFeatureExtractor_PixelData*, UNVSceneCapturerViewpointComponent*)> OnFinishedCaptureScenePixelsDataCallback;
80 
82 
83  /// Callback function get called after the scene capture component finished capturing scene's annotation data
84  /// TSharedPtr<FJsonObject> - The JSON object contain the annotation data
85  /// UNVSceneFeatureExtractor_AnnotationData* - Reference to the feature extractor that captured the scene annotation data
86  /// UNVSceneCapturerViewpointComponent* - Reference to the viewpoint that captured the scene pixels data
88 
90 
91  void SetupFeatureExtractors();
92  void UpdateCapturerSettings();
93  const FNVSceneCapturerViewpointSettings& GetSettings() const;
94  const FNVSceneCapturerSettings& GetCapturerSettings() const;
95  const TArray<FNVFeatureExtractorSettings>& GetFeatureExtractorSettings() const;
96 
97  bool IsEnabled() const;
98  FString GetDisplayName() const;
99 
100  void StartCapturing();
101  void StopCapturing();
102 
103 #if WITH_EDITOR
104  virtual bool GetEditorPreviewInfo(float DeltaTime, FMinimalViewInfo& ViewOut) override;
105 #endif // WITH_EDITOR
106 
107 protected:
108  virtual void BeginPlay() final;
109  virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) final;
110  virtual void OnRegister() final;
111  virtual void OnComponentDestroyed(bool bDestroyingHierarchy) final;
112  virtual void OnUpdateTransform(EUpdateTransformFlags UpdateTransformFlags, ETeleportType Teleport) final;
113 
114 public: // Editor properties
115  UPROPERTY(EditAnywhere, Category = Config, meta = (ShowOnlyInnerProperties))
116  FNVSceneCapturerViewpointSettings Settings;
117 
118 public: // Transient properties
119  UPROPERTY(Transient)
120  TArray<class UNVSceneFeatureExtractor*> FeatureExtractorList;
121 protected: // Transient properties
122  UPROPERTY(Transient)
123  class ANVSceneCapturerActor* OwnerSceneCapturer;
124 
125 #if WITH_EDITORONLY_DATA
126 protected: // Proxy editor mesh
127  /// The frustum component used to show visually where the camera field of view is
128  class UDrawFrustumComponent* DrawFrustum;
129 
130  UPROPERTY(transient)
131  class UStaticMesh* CameraMesh;
132 
133  /// The camera mesh to show visually where the camera is placed
134  class UStaticMeshComponent* ProxyMeshComponent;
135 
136  static void AddReferencedObjects(UObject* InThis, FReferenceCollector& Collector);
137 
138  void SetCameraMesh(UStaticMesh* Mesh);
139 
140  /// Refreshes the visual components to match the component state
141  void RefreshVisualRepresentation();
142 
143  void OverrideFrustumColor(FColor OverrideColor);
144  void RestoreFrustumColor();
145 
146  void ResetProxyMeshTransform();
147  /// Ensure the proxy mesh is in the correct place
148  void UpdateProxyMeshTransform();
149 #endif
150 };
UNVSceneCapturerViewpointComponent: Represents each viewpoint from where the capturer captures data...
TFunction< void(const FNVTexturePixelData &, UNVSceneFeatureExtractor_PixelData *, UNVSceneCapturerViewpointComponent *)> OnFinishedCaptureScenePixelsDataCallback
Callback function get called after the scene capture component finished capturing scene and read back...
TFunction< void(TSharedPtr< FJsonObject >, UNVSceneFeatureExtractor_AnnotationData *, UNVSceneCapturerViewpointComponent *)> OnFinishedCaptureSceneAnnotationDataCallback
Callback function get called after the scene capture component finished capturing scene's annotation ...
The scene exporter actor.