NVIDIA DeepLearning Dataset Synthesizer (NDDS)
 All Classes Namespaces Functions Variables Typedefs Pages
NVObjectMaskManager.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 "GameFramework/Actor.h"
14 #include "NVObjectMaskManager.generated.h"
15 
16 /// This enum describe how to get the mask name out of an actor
17 UENUM(BlueprintType)
18 enum class ENVActorMaskNameType : uint8
19 {
20  /// Use the actor's instance name for its mask name. Each actors in the scene will have a unique name
21  /// so this option will cause all the actors to have its own unique mask.
22  /// NOTE: Should only use this option for VertexColor mask since the total number of masks can be huge
23  UseActorInstanceName = 0,
24 
25  /// Use the actor's mesh name for its mask name, actor with no visible mesh will be ignored
26  /// NOTE: Since each actor can have multiple mesh components, we only use the first valid mesh's name for the mask
27  UseActorMeshName,
28 
29  /// Use the actor's Tags for its mask name, actor with no tags will be ignored
30  /// NOTE: Since each actor can have multiple tags, we only use the first one in the Tags list for the mask
31  UseActorTag,
32 
33  /// Use the actor's class (either C++ or blueprint) name for its mask name. All the actor instances of the same class/blueprint will have the same mask
34  UseActorClassName,
35 
36  // TODO: Add support for UNVCapturableActorTag?
37 
38  /// @endcond DOXYGEN_SUPPRESSED_CODE
39  NVObjectClassMaskType_MAX UMETA(Hidden)
40  /// @endcond DOXYGEN_SUPPRESSED_CODE
41 };
42 
43 /// This enum describe how to assign an id for a mask
44 /// The reason for the "spread evenly" is for easy visualization.
45 /// IDs are translated to color linearly (grayscale 8 bits for stencil mask,
46 /// RGBA8 for vertex color mask).When the number of objects is small,
47 /// the mask images all look black and thus are hard to distinguish.
48 /// In this case "spread evenly" is useful to emphasize the color difference for
49 /// visibility.However, for all other scenarios, such as DL training,
50 /// the color doesn't matter and a sequentially allocating IDs may be easier to debug.
51 /// It also helps in cases where on is manually assigning additional IDs --
52 /// one need only increase the max ID.
53 UENUM(BlueprintType)
54 enum class ENVIdAssignmentType : uint8
55 {
56  /// The id will be given sequentially to each masks
57  Sequential = 0,
58 
59  /// The id will be spread evenly between mask
60  /// The gap between id = MaxMaskValue / NumberOfMasks
61  SpreadEvenly,
62 
63  /// @endcond DOXYGEN_SUPPRESSED_CODE
64  NVActorMaskIdType_MAX UMETA(Hidden)
65  /// @endcond DOXYGEN_SUPPRESSED_CODE
66 };
67 
68 DECLARE_LOG_CATEGORY_EXTERN(LogNVObjectMaskManager, Log, All)
69 
70 /// Mask base class: scan actors in the scene, assign them an ID based on mask type
71 UCLASS(NotBlueprintable, Abstract, DefaultToInstanced, editinlinenew, ClassGroup = (NVIDIA))
72 class NVSCENECAPTURER_API UNVObjectMaskMananger : public UObject
73 {
74  GENERATED_BODY()
75 
76 public:
78 
79  virtual void ScanActors(UWorld* World);
80 
81  void Init(ENVActorMaskNameType NewMaskNameType, ENVIdAssignmentType NewIdAssignmentType);
82 
83 protected:
84  static FString GetActorMaskName(ENVActorMaskNameType MaskNameType, const AActor* CheckActor);
85  static void ApplyStencilMaskToActor(AActor* CheckActor, uint8 MaskId);
86  static void ApplyVertexColorMaskToActor(AActor* CheckActor, uint32 MaskId);
87 
88  FString GetActorMaskName(const AActor* CheckActor) const;
89  bool ShouldCheckActorMask(const AActor* CheckActor) const;
90 
91 protected: // Editor properties
92  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = ActorMask)
93  ENVActorMaskNameType ActorMaskNameType;
94 
95  /// How the segmentation id get generated for actors in the scene
96  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = ActorMask)
97  ENVIdAssignmentType SegmentationIdAssignmentType;
98 
99  /// Turn on this flag to print out debug information (e.g: list of mask name ...) when this object run
100  UPROPERTY(EditAnywhere, BlueprintReadWrite, AdvancedDisplay, Category = ActorMask)
101  bool bDebug;
102 
103 protected: // Transient
104  UPROPERTY(Transient)
105  TArray<FString> AllMaskNames;
106 
107  UPROPERTY(Transient)
108  TArray<AActor*> AllMaskActors;
109 };
110 
111 /// UNVObjectMaskMananger_Stencil scan actors in the scene, assign them an ID using StencilMask
112 /// NOTE: MaskId 0 mean the actor is ignored
113 UCLASS(Blueprintable, DefaultToInstanced, editinlinenew, ClassGroup = (NVIDIA))
114 class NVSCENECAPTURER_API UNVObjectMaskMananger_Stencil : public UNVObjectMaskMananger
115 {
116  GENERATED_BODY()
117 
118 public:
120 
121  void ScanActors(UWorld* World) override;
122 
123  uint8 GetMaskId(const FString& MaskName) const;
124  uint8 GetMaskId(const AActor* CheckActor) const;
125 protected:
126 
127 protected: // Transient
128  UPROPERTY(Transient)
129  TMap<FString, uint8> MaskNameIdMap;
130 };
131 
132 /// UNVObjectMaskMananger_VertexColor scan actors in the scene, assign them an ID using VertexColor (32bits)
133 /// NOTE: MaskId 0 mean the actor is ignored
134 UCLASS(Blueprintable, DefaultToInstanced, editinlinenew, ClassGroup = (NVIDIA))
136 {
137  GENERATED_BODY()
138 
139 public:
141 
142  void ScanActors(UWorld* World) override;
143 
144  uint32 GetMaskId(const FString& MaskName) const;
145  uint32 GetMaskId(const AActor* CheckActor) const;
146 
147 protected: // Transient
148  UPROPERTY(Transient)
149  TMap<FString, uint32> MaskNameIdMap;
150 
151  static const uint32 MaxVertexColorID;
152 };
153 
154 USTRUCT(Blueprintable)
155 struct NVSCENECAPTURER_API FNVObjectSegmentation_Instance
156 {
157  GENERATED_BODY()
158 
159 public:
160  FNVObjectSegmentation_Instance();
161 
162  uint32 GetInstanceId(const AActor* CheckActor) const;
163  void Init(UObject* OwnerObject);
164  void ScanActors(UWorld* World);
165 
166 protected:
167 // Editor properties
168 
169  UPROPERTY(EditAnywhere, Category = "Segmentation")
170  ENVIdAssignmentType SegmentationIdAssignmentType;
171 
172 // Transient properties
173 
174  UPROPERTY(Transient)
175  UNVObjectMaskMananger_VertexColor* VertexColorMaskManager;
176 };
177 
178 /// This enum describe how to get the class type out of an actor to use for segmentation
179 UENUM(BlueprintType)
180 enum class ENVActorClassSegmentationType : uint8
181 {
182  /// Use the actor's mesh name for its class type name, actor with no visible mesh will be ignored
183  /// NOTE: Since each actor can have multiple mesh components, we only use the first valid mesh's name for the mask
184  UseActorMeshName = 0,
185 
186  /// Use the actor's Tags for its mask name, actor with no tags will be ignored
187  /// NOTE: Since each actor can have multiple tags, we only use the first one in the Tags list for the mask
188  UseActorTag,
189 
190  /// Use the actor's class (either C++ or blueprint) name for its class name. All the actor instances of the same class/blueprint will have the same mask
191  UseActorClassName,
192 
193  /// @endcond DOXYGEN_SUPPRESSED_CODE
194  ENVActorClassSegmentationType_MAX UMETA(Hidden)
195  /// @endcond DOXYGEN_SUPPRESSED_CODE
196 };
197 
198 USTRUCT(Blueprintable)
199 struct NVSCENECAPTURER_API FNVObjectSegmentation_Class
200 {
201  GENERATED_BODY()
202 
203 public:
204  FNVObjectSegmentation_Class();
205 
206  uint8 GetInstanceId(const AActor* CheckActor) const;
207  void Init(UObject* OwnerObject);
208  void ScanActors(UWorld* World);
209 
210 protected:
211 // Editor properties
212  /// How to get the class type out of actors in the scene to use for segmentation
213  UPROPERTY(EditAnywhere, Category = "Segmentation")
214  ENVActorClassSegmentationType ClassSegmentationType;
215 
216  UPROPERTY(EditAnywhere, Category = "Segmentation")
217  ENVIdAssignmentType SegmentationIdAssignmentType;
218 
219 // Transient properties
220  UPROPERTY(Transient)
221  UNVObjectMaskMananger_Stencil* StencilMaskManager;
222 };
UNVObjectMaskMananger_VertexColor scan actors in the scene, assign them an ID using VertexColor (32bi...
Mask base class: scan actors in the scene, assign them an ID based on mask type.
UNVObjectMaskMananger_Stencil scan actors in the scene, assign them an ID using StencilMask NOTE: Mas...