-
Notifications
You must be signed in to change notification settings - Fork 530
Expand file tree
/
Copy pathSemanticScene.h
More file actions
687 lines (596 loc) · 24.7 KB
/
SemanticScene.h
File metadata and controls
687 lines (596 loc) · 24.7 KB
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
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
// Copyright (c) Meta Platforms, Inc. and its affiliates.
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
#ifndef ESP_SCENE_SEMANTICSCENE_H_
#define ESP_SCENE_SEMANTICSCENE_H_
#include <Corrade/Containers/StringStl.h>
#include <Corrade/Utility/Path.h>
#include <map>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "esp/core/Esp.h"
#include "esp/core/Utility.h"
#include "esp/geo/OBB.h"
#include "esp/io/Json.h"
namespace esp {
namespace metadata {
namespace attributes {
class SemanticAttributes;
}
} // namespace metadata
namespace scene {
namespace Mn = Magnum;
//! Represents a semantic category
class SemanticCategory {
public:
virtual ~SemanticCategory() = default;
//! Return index of SemanticCategory under given mapping
virtual int index(const std::string& mapping = "") const = 0;
//! Return name of SemanticCategory under given mapping
virtual std::string name(const std::string& mapping = "") const = 0;
ESP_SMART_POINTERS(SemanticCategory)
};
// forward declarations
class SemanticObject;
// semantic object only used to represent characteristics of Connected
// Components of mesh verts conditioned on semantic ID/color.
class CCSemanticObject;
class SemanticRegion;
class SemanticLevel;
//! Represents a scene with containing semantically annotated
//! levels, regions and objects
class SemanticScene {
public:
~SemanticScene() { ESP_DEBUG() << "Deconstructing SemanticScene"; }
//! return axis aligned bounding box of this House
Mn::Range3D aabb() const { return bbox_; }
//! return total number of given element type
int count(const std::string& element) const {
return elementCounts_.at(element);
}
//! return all SemanticCategories of objects in this House
const std::vector<std::shared_ptr<SemanticCategory>>& categories() const {
return categories_;
}
//! return all Levels in this House
const std::vector<std::shared_ptr<SemanticLevel>>& levels() const {
return levels_;
}
//! return all Regions in this House
const std::vector<std::shared_ptr<SemanticRegion>>& regions() const {
return regions_;
}
//! return all Objects in this House
const std::vector<std::shared_ptr<SemanticObject>>& objects() const {
return objects_;
}
const std::unordered_map<int, int>& getSemanticIndexMap() const {
return segmentToObjectIndex_;
}
//! convert semantic mesh mask index to object index or ID_UNDEFINED if
//! not mapped
inline int semanticIndexToObjectIndex(int maskIndex) const {
auto segmentToObjIdxIter = segmentToObjectIndex_.find(maskIndex);
if (segmentToObjIdxIter != segmentToObjectIndex_.end()) {
return segmentToObjIdxIter->second;
} else {
return ID_UNDEFINED;
}
}
/**
* @brief Attempt to load SemanticScene descriptor from an unknown file type.
* @param semanticAttr The semantic attributes containing a reference to the
* name of the semantic scene descriptor (house file) to attempt to load,
* along with informationd describing semantic constructions (region
* annotations).
* @param scene reference to sceneNode to assign semantic scene to
* @param rotation rotation to apply to semantic scene upon load.
* @return successfully loaded
*/
static bool loadSemanticSceneDescriptor(
const std::shared_ptr<metadata::attributes::SemanticAttributes>&
semanticAttr,
SemanticScene& scene,
const Magnum::Quaternion& rotation =
Mn::Quaternion::rotation(geo::ESP_FRONT, geo::ESP_GRAVITY));
/**
* @brief Attempt to load SemanticScene from a Gibson dataset house format
* file
* @param filename the name of the semantic scene descriptor (house file) to
* attempt to load
* @param scene reference to sceneNode to assign semantic scene to
* @param rotation rotation to apply to semantic scene upon load.
* @return successfully loaded
*/
static bool loadGibsonHouse(const std::string& filename,
SemanticScene& scene,
const Magnum::Quaternion& rotation =
Mn::Quaternion::rotation(geo::ESP_FRONT,
geo::ESP_GRAVITY));
/**
* @brief Attempt to load SemanticScene from a HM3D dataset house
* format file
* @param filename the name of the semantic scene descriptor (house file) to
* attempt to load
* @param scene reference to sceneNode to assign semantic scene to
* @param rotation rotation to apply to semantic scene upon load (currently
* not used for HM3D)
* @return successfully loaded
*/
static bool loadHM3DHouse(const std::string& filename,
SemanticScene& scene,
CORRADE_UNUSED const Magnum::Quaternion& rotation =
Mn::Quaternion::rotation(geo::ESP_FRONT,
geo::ESP_GRAVITY));
/**
* @brief Attempt to load SemanticScene from a Matterport3D dataset house
* format file
* @param filename the name of the semantic scene descriptor (house file) to
* attempt to load
* @param scene reference to sceneNode to assign semantic scene to
* @param rotation rotation to apply to semantic scene upon load.
* @return successfully loaded
*/
static bool loadMp3dHouse(const std::string& filename,
SemanticScene& scene,
const Magnum::Quaternion& rotation =
Mn::Quaternion::rotation(geo::ESP_FRONT,
geo::ESP_GRAVITY));
/**
* @brief Attempt to load SemanticScene from a Replica dataset house format
* file
* @param filename the name of the semantic scene descriptor (house file) to
* attempt to load
* @param scene reference to sceneNode to assign semantic scene to
* @param rotation rotation to apply to semantic scene upon load.
* @return successfully loaded
*/
static bool loadReplicaHouse(const std::string& filename,
SemanticScene& scene,
const Magnum::Quaternion& rotation =
Mn::Quaternion::rotation(geo::ESP_FRONT,
geo::ESP_GRAVITY));
/**
* @brief Builds a mapping of connected component-driven bounding boxes (via
* @ref CCSemanticObject), keyed by criteria used to decide connectivity (the
* per-vertex attribute suche as color). If a @p semanticScene is passed, key
* for resultant map will be semanticID of object with specified color,
* otherwise key is hex color value.
* @param verts Ref to the vertex buffer holding all vertex positions in the
* mesh.
* @param clrsToComponents an unordered map, keyed by tag/color value encoded
* as uint, where the value is a vector of all sets of CCs consisting of verts
* with specified tag/"color". (see @ref findCCsByGivenColor).
* @param semanticScene The SSD for the current semantic mesh. Used to query
* semantic objs. If nullptr, this function returns hex-color-keyed map,
* otherwise returns SemanticID-keyed map.
* @return A map keyed by a representattion of the per-vertex "color" where
* each entry contains a vector of values for all the CCs of verts having the
* "color" attribute specified by the key. Each element in the vector is a
* smart pointer to a @ref CCSemanticObject, being used to facilitate
* collecting pertinent data.
*/
static std::unordered_map<uint32_t,
std::vector<std::shared_ptr<CCSemanticObject>>>
buildCCBasedSemanticObjs(
const std::vector<Mn::Vector3>& verts,
const std::unordered_map<uint32_t, std::vector<std::set<uint32_t>>>&
clrsToComponents,
const std::shared_ptr<SemanticScene>& semanticScene);
/**
* @brief Build semantic OBBs based on presence of semantic IDs on vertices.
* @param verts Ref to the vertex buffer holding all vertex positions in the
* mesh.
* @param vertSemanticIDs Ref to per-vertex semantic IDs persent on source
* mesh, both known in semantic scene descriptor, and unknown. Known IDs are
* expected to start at 1 and be contiguous, followed by unknown semantic IDs
* @param ssdObjs The known semantic scene descriptor objects for the mesh
* @param msgPrefix Debug message prefix, referencing caller.
* @return vector of semantic object IDXs that have no vertex mapping/presence
* in the source mesh.
*/
static std::vector<uint32_t> buildSemanticOBBs(
const std::vector<Mn::Vector3>& verts,
const std::vector<uint16_t>& vertSemanticIDs,
const std::vector<std::shared_ptr<SemanticObject>>& ssdObjs,
const std::string& msgPrefix);
/**
* @brief Build semantic object OBBs based on the accumulated
* per-semantic-color CCs, and some criteria specified in @p semanticScene .
* @param verts Ref to the vertex buffer holding all vertex positions in the
* mesh.
* @param clrsToComponents an unordered map, keyed by tag/color value encoded
* as uint, where the value is a vector of all sets of CCs consisting of verts
* with specified tag/"color". (see @ref findCCsByGivenColor).
* @param semanticScene The SSD for the current semantic mesh. Used to query
* semantic objs. If nullptr, this function returns hex-color-keyed map,
* otherwise returns SemanticID-keyed map.
* @param maxVolFraction Fraction of maximum volume bbox CC to include in bbox
* calc.
* @param msgPrefix Debug message prefix, referencing caller.
* @return vector of semantic object IDXs that have no vertex mapping/presence
* in the source mesh.
*/
static std::vector<uint32_t> buildSemanticOBBsFromCCs(
const std::vector<Mn::Vector3>& verts,
const std::unordered_map<uint32_t, std::vector<std::set<uint32_t>>>&
clrsToComponents,
const std::shared_ptr<SemanticScene>& semanticScene,
float maxVolFraction,
const std::string& msgPrefix);
/**
* @brief Whether the source file assigns colors to verts for Semantic
* Mesh.
*/
bool hasVertColorsDefined() const { return hasVertColors_; }
/**
* @brief return a read-only reference to the semantic color map, where value
* is annotation color and index corresponds to id for that color. (HM3D only
* currently)
*/
const std::vector<Mn::Vector3ub>& getSemanticColorMap() const {
return semanticColorMapBeingUsed_;
}
/**
* @brief return a read-only reference to a mapping of semantic
* color-as-integer to id and region id.(HM3D only currently)
*/
const std::unordered_map<uint32_t, std::pair<int, int>>&
getSemanticColorToIdAndRegionMap() const {
return semanticColorToIdAndRegion_;
}
/**
* @brief whether or not we should build bounding boxes around vertex
* annotations on semantic asset load. Currently used for HM3D.
*/
bool buildBBoxFromVertColors() const { return needBBoxFromVertColors_; }
/**
* @brief What fraction of largest connected component bbox to use
* for bbox generation. Will always use single largest, along with this
* fraction of remaining. If set to 0.0, use all CCs (i.e. will bypass CC calc
* and just use naive vert position mechanism for bbox), if set to 1.0, only
* use single CC with largest volume. Only used if @ref
* needBBoxFromVertColors_ is true.
*/
float CCFractionToUseForBBox() const { return ccLargestVolToUseForBBox_; }
/**
* @brief Compute all SemanticRegions which contain the point and return a
* list of indices for regions in this SemanticScene.
* @param point The query point.
* @return A list of indices for regions which contain the point.
*/
std::vector<int> getRegionsForPoint(const Mn::Vector3& point) const;
/**
* @brief Compute all the SemanticRegions that contain the passed point, and
* return a vector of indices and weights for each region, where the weights
* are inverted area of the region (smaller regions weighted higher)
* @param point The query point.
* @return std::vector<std::pair<int, float>> A sorted list of tuples
* containing region index and inverse area of that region
*/
std::vector<std::pair<int, double>> getWeightedRegionsForPoint(
const Mn::Vector3& point) const;
/**
* @brief Compute SemanticRegion containment for a set of points. It is
* assumed the set of points belong to the same construct (i.e. points from an
* individual object's mesh)
* @param points A set of points to test for semantic containment.
* @return std::vector<std::pair<int, float>> A sorted list of tuples
* containing region index and percentage of input points contained in that
* region.
*/
std::vector<std::pair<int, double>> getRegionsForPoints(
const std::vector<Mn::Vector3>& points) const;
protected:
/**
* @brief Verify a requested file exists.
* @param filename the file to attempt to load
* @param srcFunc calling function name to be displayed in failure message
* @return whether found or not
*/
static bool checkFileExists(const std::string& filename,
const std::string& srcFunc) {
if (!Cr::Utility::Path::exists(filename)) {
ESP_WARNING(Mn::Debug::Flag::NoSpace)
<< "::" << srcFunc << ": File `" << filename
<< "` does not exist. Aborting load.";
return false;
}
return true;
} // checkFileExists
/**
* @brief Build the HM3D semantic data from the passed file stream. File
* being streamed is expected to be appropriate format.
* @param ifs The opened file stream describing the HM3D semantic annotations.
* @param scene reference to sceneNode to assign semantic scene to
* @param rotation rotation to apply to semantic scene upon load (currently
* not used for HM3D)
* @return successfully built. Currently only returns true, but retaining
* return value for future support.
*/
static bool buildHM3DHouse(std::ifstream& ifs,
SemanticScene& scene,
CORRADE_UNUSED const Magnum::Quaternion& rotation =
Mn::Quaternion::rotation(geo::ESP_FRONT,
geo::ESP_GRAVITY));
/**
* @brief Build the mp3 semantic data from the passed file stream. File being
* streamed is expected to be appropriate format.
* @param ifs The opened file stream describing the Mp3d semantic annotations.
* @param scene reference to sceneNode to assign semantic scene to
* @param rotation rotation to apply to semantic scene upon load.
* @return successfully built. Currently only returns true, but retaining
* return value for future support.
*/
static bool buildMp3dHouse(std::ifstream& ifs,
SemanticScene& scene,
const Magnum::Quaternion& rotation =
Mn::Quaternion::rotation(geo::ESP_FRONT,
geo::ESP_GRAVITY));
/**
* @brief Build SemanticScene from a Gibson dataset house JSON. JSON is
* expected to have been verified already.
* @param jsonDoc the JSON document describing the semantic annotations.
* @param scene reference to sceneNode to assign semantic scene to
* @param rotation rotation to apply to semantic scene upon load.
* @return successfully built. Currently only returns true, but retaining
* return value for future support.
*/
static bool buildGibsonHouse(const io::JsonDocument& jsonDoc,
SemanticScene& scene,
const Magnum::Quaternion& rotation =
Mn::Quaternion::rotation(geo::ESP_FRONT,
geo::ESP_GRAVITY));
/**
* @brief Build SemanticScene from a Replica dataset house JSON. JSON is
* expected to have been verified already.
* @param jsonDoc the JSON document describing the semantic annotations.
* @param scene reference to sceneNode to assign semantic scene to
* @param objectsExist whether objects cell exists in json. This cell will not
* exist in ReplicaCAD semantic lexicon.
* @param rotation rotation to apply to semantic scene upon load.
* @return successfully built. Currently only returns true, but retaining
* return value for future support.
*/
static bool buildReplicaHouse(const io::JsonDocument& jsonDoc,
SemanticScene& scene,
bool objectsExist,
const Magnum::Quaternion& rotation =
Mn::Quaternion::rotation(geo::ESP_FRONT,
geo::ESP_GRAVITY));
// Currently only supported by HM3D semantic files.
bool hasVertColors_ = false;
/**
* @Brief whether or not we should build bounding boxes around vertex
* annotations on semantic asset load. Currently used for HM3D.
*/
bool needBBoxFromVertColors_ = false;
/**
* @brief Fraction of vert count for largest CC to use for BBox synth. 0->use
* all (bypass CC calc), 1->use only largest CC.
*/
float ccLargestVolToUseForBBox_ = 0.0f;
std::string name_;
std::string label_;
Mn::Range3D bbox_;
std::map<std::string, int> elementCounts_;
std::vector<std::shared_ptr<SemanticCategory>> categories_;
std::vector<std::shared_ptr<SemanticLevel>> levels_;
std::vector<std::shared_ptr<SemanticRegion>> regions_;
std::vector<std::shared_ptr<SemanticObject>> objects_;
//! map from combined region-segment id to objectIndex for semantic mesh
std::unordered_map<int, int> segmentToObjectIndex_;
/**
* @brief List of mapped vertex colors, where index corresponds to object
* Index/semantic ID (HM3D only currently)
*/
std::vector<Mn::Vector3ub> semanticColorMapBeingUsed_{};
/**
* @brief Map of integer color to segment and region ids. Used for
* transforming provided vertex colors. (HM3D only currently)
*/
std::unordered_map<uint32_t, std::pair<int, int>>
semanticColorToIdAndRegion_{};
ESP_SMART_POINTERS(SemanticScene)
};
//! Represents a level of a SemanticScene
class SemanticLevel {
public:
virtual ~SemanticLevel() = default;
virtual std::string id() const { return std::to_string(index_); }
const std::vector<std::shared_ptr<SemanticRegion>>& regions() const {
return regions_;
}
const std::vector<std::shared_ptr<SemanticObject>>& objects() const {
return objects_;
}
Mn::Range3D aabb() const { return bbox_; }
protected:
int index_{};
std::string labelCode_;
Mn::Vector3 position_;
Mn::Range3D bbox_;
std::vector<std::shared_ptr<SemanticObject>> objects_;
std::vector<std::shared_ptr<SemanticRegion>> regions_;
friend SemanticScene;
ESP_SMART_POINTERS(SemanticLevel)
};
class LoopRegionCategory : public SemanticCategory {
public:
LoopRegionCategory(const int id, const std::string& name)
: id_(id), name_(name) {}
int index(const std::string& /*mapping*/) const override { return id_; }
std::string name(const std::string& mapping) const override {
if (mapping == "category" || mapping.empty()) {
return name_;
} else {
ESP_ERROR() << "Unknown mapping type:" << mapping;
return "UNKNOWN";
}
}
protected:
int id_;
std::string name_;
ESP_SMART_POINTERS(LoopRegionCategory)
}; // class LoopRegionCategory
//! Represents a region (typically room) in a level of a house
class SemanticRegion {
public:
virtual ~SemanticRegion() = default;
virtual std::string id() const {
if (!name_.empty()) {
return name_;
}
if (level_ != nullptr) {
return level_->id() + "_" + std::to_string(index_);
} else {
return "_" + std::to_string(index_);
}
}
int getIndex() const { return index_; }
SemanticLevel::ptr level() const { return level_; }
const std::vector<std::shared_ptr<SemanticObject>>& objects() const {
return objects_;
}
/**
* @brief Test whether this region contains the passed point
*/
virtual bool contains(const Mn::Vector3& point) const;
void setBBox(const Mn::Vector3& min, const Mn::Vector3& max);
Mn::Range3D aabb() const { return bbox_; }
const std::vector<Mn::Vector2>& getPolyLoopPoints() const {
return polyLoopPoints_;
}
/**
* @brief Return a list of the semantic region's bounding volume edges.
*/
const std::vector<std::vector<Mn::Vector3>>& getVisEdges() const {
return visEdges_;
}
double getExtrusionHeight() const { return extrusionHeight_; }
double getFloorHeight() const { return floorHeight_; }
SemanticCategory::ptr category() const { return category_; }
/**
* @brief Returns the area of the polyloop forming the base of the region
* extrusion
*/
double getArea() const { return area_; }
/**
* @brief Returns the volume of the polyloop-based extrusion defining the
* bounds of this region.
*/
double getVolume() const { return area_ * extrusionHeight_; }
protected:
int index_{};
int parentIndex_{};
std::shared_ptr<SemanticCategory> category_;
Mn::Vector3 position_;
Mn::Range3D bbox_;
std::string name_;
// The area of the surface enclosed by the region
double area_{};
// Height of extrusion for Extruded poly-loop-based volumes
double extrusionHeight_{};
// Floor height
double floorHeight_{};
// poly loop points for base extrusion
std::vector<Mn::Vector2> polyLoopPoints_;
// Edges for visualization of volume
std::vector<std::vector<Mn::Vector3>> visEdges_;
std::vector<std::shared_ptr<SemanticObject>> objects_;
std::shared_ptr<SemanticLevel> level_;
friend SemanticScene;
ESP_SMART_POINTERS(SemanticRegion)
}; // class SemanticRegion
//! Represents a distinct semantically annotated object
class SemanticObject {
public:
virtual ~SemanticObject() = default;
virtual std::string id() const {
if (region_ != nullptr) {
return region_->id() + "_" + std::to_string(index_);
} else {
return "_" + std::to_string(index_);
}
}
/**
* @brief Retrieve the unique semantic ID corresponding to this object
*/
int semanticID() const { return index_; }
SemanticRegion::ptr region() const { return region_; }
Mn::Range3D aabb() const { return obb_.toAABB(); }
geo::OBB obb() const { return obb_; }
SemanticCategory::ptr category() const { return category_; }
void setObb(
const Mn::Vector3& center,
const Mn::Vector3& dimensions,
const Mn::Quaternion& rotation = Mn::Quaternion(Mn::Math::IdentityInit)) {
obb_ = geo::OBB{center, dimensions, rotation};
}
void setObb(const geo::OBB& otr) { obb_ = geo::OBB{otr}; }
Mn::Vector3ub getColor() const { return color_; }
void setColor(Mn::Vector3ub _color) {
color_ = _color;
// update colorAsInt_
colorAsInt_ = geo::getValueAsUInt(color_);
}
uint32_t getColorAsInt() const { return colorAsInt_; }
void setColorAsInt(const uint32_t _colorAsInt) {
colorAsInt_ = _colorAsInt;
// update color_ vector
color_ = {uint8_t((colorAsInt_ >> 16) & 0xff),
uint8_t((colorAsInt_ >> 8) & 0xff), uint8_t(colorAsInt_ & 0xff)};
}
protected:
/**
* @brief The unique semantic ID corresponding to this object
*/
int index_{};
/**
* @brief specified color for this object instance.
*/
Mn::Vector3ub color_{};
/**
* @brief specified color as unsigned int
*/
uint32_t colorAsInt_{};
/**
* @brief References the parent region for this object
*/
int parentIndex_{};
std::shared_ptr<SemanticCategory> category_;
geo::OBB obb_;
std::shared_ptr<SemanticRegion> region_;
friend SemanticScene;
ESP_SMART_POINTERS(SemanticObject)
}; // class SemanticObject
/**
* @brief This class exists to facilitate semantic object data access for bboxes
* derived from connected component analysis.
*/
class CCSemanticObject : public SemanticObject {
public:
CCSemanticObject(uint32_t _colorInt, const std::set<uint32_t>& _vertSet)
: SemanticObject(), vertSet_(_vertSet), numSrcVerts_(vertSet_.size()) {
// need to set index manually when mapping from color/colorInt is known
index_ = ID_UNDEFINED;
// sets both colorAsInt_ and updates color_ vector to match
setColorAsInt(_colorInt);
}
void setIndex(int _index) { index_ = _index; }
uint32_t getNumSrcVerts() const { return numSrcVerts_; }
const std::set<uint32_t>& getVertSet() const { return vertSet_; }
protected:
// reference to vertex set used to build this CCSemantic object
const std::set<uint32_t>& vertSet_;
/**
* @brief Number of verts in source mesh of CC used for this Semantic Object
*/
uint32_t numSrcVerts_;
ESP_SMART_POINTERS(CCSemanticObject)
}; // class CCSemanticObject
} // namespace scene
} // namespace esp
#endif // ESP_SCENE_SEMANTICSCENE_H_