Skip to content

Commit 92acb65

Browse files
authored
--Standardize HM3D object ID ( <name> _ <unique ID> ) (#1618)
1 parent ea1b300 commit 92acb65

5 files changed

Lines changed: 29 additions & 20 deletions

File tree

src/esp/assets/GenericSemanticMeshData.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ GenericSemanticMeshData::buildSemanticMeshData(
158158
static_cast<scene::HM3DObjectInstance&>(*ssdObjs[i]);
159159
const Mn::Vector3ub ssdColor = ssdObj.getColor();
160160
const uint32_t colorInt = colorAsInt(ssdColor);
161-
int semanticID = ssdObj.getSemanticID();
161+
int semanticID = ssdObj.semanticID();
162162
int regionIDX =
163163
static_cast<scene::HM3DSemanticRegion&>(*ssdObj.region())
164164
.getIndex();

src/esp/bindings/SceneBindings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ void initSceneBindings(py::module& m) {
172172
.def_property_readonly("id", &SemanticObject::id,
173173
"The ID of the object, of the form "
174174
"``<level_id>_<region_id>_<object_id>``")
175+
.def_property_readonly("semantic_id", &SemanticObject::semanticID)
175176
.def_property_readonly("region", &SemanticObject::region)
176177
.def_property_readonly("aabb", &SemanticObject::aabb)
177178
.def_property_readonly("obb", &SemanticObject::obb)

src/esp/scene/HM3DSemanticScene.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,11 @@ namespace {
4343

4444
struct TempHM3DObject {
4545
int objInstanceID;
46+
int objCatID;
4647
std::string categoryName;
4748
std::string objInstanceName;
4849
Mn::Vector3ub color;
4950
std::shared_ptr<SemanticRegion> region;
50-
51-
void setObjInstanceAndName(int _objInstanceID) {
52-
objInstanceID = _objInstanceID;
53-
objInstanceName =
54-
Cr::Utility::formatString("{}_{}", categoryName, objInstanceID);
55-
}
5651
};
5752

5853
struct TempHM3DRegion {
@@ -95,7 +90,7 @@ bool SemanticScene::buildHM3DHouse(std::ifstream& ifs,
9590
// Line :
9691
// Unique Instance ID (int), color (hex RGB), category name
9792
// (string), room/region ID (int)
98-
// instance ID is first token
93+
// unique instance ID is first token
9994
int instanceID = std::stoi(tokens[0]);
10095
// semantic color is 2nd token, as hex string
10196
auto colorVec = getVec3ub(tokens[1]);
@@ -107,7 +102,10 @@ bool SemanticScene::buildHM3DHouse(std::ifstream& ifs,
107102
// room/region
108103
int regionID = std::stoi(tokens[3]);
109104
// build initial temp object
110-
TempHM3DObject obj{0, objCategoryName, "", colorVec};
105+
TempHM3DObject obj{
106+
instanceID, 0, objCategoryName,
107+
Cr::Utility::formatString("{}_{}", objCategoryName, instanceID),
108+
colorVec};
111109
objInstance[instanceID] = obj;
112110
// find category, build if dne
113111
TempHM3DCategory tmpCat{
@@ -126,7 +124,7 @@ bool SemanticScene::buildHM3DHouse(std::ifstream& ifs,
126124
std::vector<TempHM3DObject*>& objsWithCat = item.second.objInstances;
127125
int objCatIdx = 0;
128126
for (TempHM3DObject* objItem : objsWithCat) {
129-
objItem->setObjInstanceAndName(objCatIdx++);
127+
objItem->objCatID = objCatIdx++;
130128
}
131129
// build category item and place within temp map
132130
item.second.category_ = std::make_shared<HM3DObjectCategory>(
@@ -160,7 +158,7 @@ bool SemanticScene::buildHM3DHouse(std::ifstream& ifs,
160158
for (auto& item : objInstance) {
161159
TempHM3DObject obj = item.second;
162160
auto objPtr = std::make_shared<HM3DObjectInstance>(HM3DObjectInstance(
163-
item.first, obj.objInstanceID, obj.objInstanceName, obj.color));
161+
obj.objInstanceID, obj.objCatID, obj.objInstanceName, obj.color));
164162
objPtr->category_ = categories[obj.categoryName].category_;
165163
// set region
166164
objPtr->parentIndex_ = obj.region->index_;

src/esp/scene/HM3DSemanticScene.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,20 @@ class HM3DSemanticRegion : public SemanticRegion {
3939

4040
class HM3DObjectInstance : public SemanticObject {
4141
public:
42-
HM3DObjectInstance(int id,
43-
int objInstanceId,
42+
HM3DObjectInstance(int objInstanceID,
43+
int objCatID,
4444
const std::string& name,
4545
const Mn::Vector3ub& clr)
46-
: id_(id), objInstanceId_(objInstanceId), name_(name), color_(clr) {}
46+
: SemanticObject(), objCatID_(objCatID), name_(name), color_(clr) {
47+
index_ = objInstanceID;
48+
}
4749
Mn::Vector3ub getColor() const { return color_; }
4850

4951
std::string id() const override { return name_; }
5052

51-
int getSemanticID() const { return id_; }
52-
5353
protected:
54-
// semantic ID of the object instance in the file
55-
const int id_;
56-
// instance ID of this particular instance within the category it belongs in
57-
const int objInstanceId_;
54+
// idx of this particular object instance within the category it belongs in
55+
const int objCatID_;
5856
// unique name for this instance
5957
const std::string name_;
6058
// specified color for this object instance.

src/esp/scene/SemanticScene.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,11 @@ class SemanticObject {
335335
}
336336
}
337337

338+
/**
339+
* @brief Retrieve the unique semantic ID corresponding to this object
340+
*/
341+
int semanticID() const { return index_; }
342+
338343
SemanticRegion::ptr region() const { return region_; }
339344

340345
box3f aabb() const { return obb_.toAABB(); }
@@ -344,7 +349,14 @@ class SemanticObject {
344349
SemanticCategory::ptr category() const { return category_; }
345350

346351
protected:
352+
/**
353+
* @brief The unique semantic ID corresponding to this object
354+
*/
347355
int index_{};
356+
357+
/**
358+
* @brief References the parent region for this object
359+
*/
348360
int parentIndex_{};
349361
std::shared_ptr<SemanticCategory> category_;
350362
geo::OBB obb_;

0 commit comments

Comments
 (0)