Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new KinBody::ExtraGeometryInfo struture for KinBody::Link::_mapExtraGeometries #1441

Open
wants to merge 22 commits into
base: production
Choose a base branch
from
Open
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3b5fbb4
Add missing Boost include
PeterBowman Aug 15, 2024
ec22ecf
Merge pull request #1420 from PeterBowman/boost-hash
rdiankov Aug 16, 2024
0258762
add serialization and deserialization of extraGeometries
Sep 27, 2024
e898491
tested and updated de/serialization of extraGeometries
Sep 30, 2024
64caea0
deserialization support merging based on id
Oct 10, 2024
61ef8a6
add extrageometry structure and modify related functions
Oct 18, 2024
26573d7
Merge pull request #1448 from zax147/extra_geometries
justism Oct 18, 2024
5ccc302
add extrageometry structure and modify related functions
Oct 18, 2024
745c4c8
Merge remote-tracking branch 'origin/production' into extra_geometries
Oct 21, 2024
766e991
Merge branch 'extra_geometries' of https://github.com/rdiankov/openra…
Oct 21, 2024
564543f
add assertion for setlinkgroupgeometries
Oct 22, 2024
5119ad0
Merge pull request #1451 from zax147/extra_geometries
rschlaikjer Oct 22, 2024
e800a93
fixed unintialized pointer issue
Oct 22, 2024
edeaaa1
Merge pull request #1452 from zax147/extra_geometries
rschlaikjer Oct 22, 2024
0380fa6
change function signature for compatibility
Oct 23, 2024
05cb3bf
Merge pull request #1453 from zax147/extra_geometries
justism Oct 23, 2024
48a1991
change function signature for compatibility
Oct 23, 2024
4094bce
Merge branch 'extra_geometries' of https://github.com/rdiankov/openra…
Oct 23, 2024
eab12ce
Merge branch 'rdiankov-extra_geometries' into extra_geometries
Oct 23, 2024
d5dce67
Merge pull request #1454 from zax147/extra_geometries
justism Oct 23, 2024
7a3a9de
clean up comments
Oct 24, 2024
07c46b1
changed variable name, change link serialization, and update the para…
Oct 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 45 additions & 33 deletions src/libopenrave/kinbodylink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,24 +212,27 @@ void KinBody::LinkInfo::SerializeJSON(rapidjson::Value &value, rapidjson::Docume
value.AddMember("readableInterfaces", std::move(rReadableInterfaces), allocator);
}

// if(_mapExtraGeometries.size() > 0 ) {
// rapidjson::Value extraGeometriesValue;
// extraGeometriesValue.SetObject();
// FOREACHC(im, _mapExtraGeometries) {
// rapidjson::Value geometriesValue;
// geometriesValue.SetArray();
// FOREACHC(iv, im->second){
// if(!!(*iv))
// {
// rapidjson::Value geometryValue;
// (*iv)->SerializeJSON(geometryValue, allocator);
// geometriesValue.PushBack(geometryValue, allocator);
// }
// }
// extraGeometriesValue.AddMember(rapidjson::Value(im->first.c_str(), allocator).Move(), geometriesValue, allocator);
// }
// value.AddMember("extraGeometries", extraGeometriesValue, allocator);
// }
if (_mapExtraGeometries.size() > 0) {
rapidjson::Value extraGeometriesValue;
extraGeometriesValue.SetArray();
FOREACHC(im, _mapExtraGeometries) {
rapidjson::Value extraGeometryValue;
extraGeometryValue.SetObject();
orjson::SetJsonValueByKey(extraGeometryValue, "name", im->first, allocator);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you missed handling the id field here and in deserialization

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for offline conversation, I think you can put id instead of name here.
the key of the std::map is now represented by id.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

talked in person.
It looks we still need both id and name.

The user of id can handle limited characters.

Meanwhile, we want to use the more characters for the key of the mapExtraGeometries.
In the upcoming safety-related geometry handling (c.f. #1402), we want to define the key based on the KinBody::GetName, ...etc. Thus, the supported characters should be the same level as KinBody::GetName and others.
Therefore, we also need name field.

That means, we need to introduce the new data structure for mapExtraGeometries...

rapidjson::Value geometriesValue;
geometriesValue.SetArray();
FOREACHC(iv, im->second) {
if (!!(*iv)) {
rapidjson::Value geometryValue;
(*iv)->SerializeJSON(geometryValue, allocator, fUnitScale, options);
geometriesValue.PushBack(geometryValue, allocator);
}
}
extraGeometryValue.AddMember("geometries", geometriesValue, allocator);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can just reuse ExtraGeometryInfo::SerializeJSON

extraGeometriesValue.PushBack(extraGeometryValue, allocator);
}
value.AddMember("extraGeometries", extraGeometriesValue, allocator);
}

orjson::SetJsonValueByKey(value, "isStatic", _bStatic, allocator);
orjson::SetJsonValueByKey(value, "isEnabled", _bIsEnabled, allocator);
Expand Down Expand Up @@ -337,21 +340,30 @@ void KinBody::LinkInfo::DeserializeJSON(const rapidjson::Value &value, dReal fUn
}
}

_mapExtraGeometries.clear();
// if (value.HasMember("extraGeometries")) {
// for (rapidjson::Value::ConstMemberIterator it = value["extraGeometries"].MemberBegin(); it != value["extraGeometries"].MemberEnd(); ++it) {
// if (_mapExtraGeometries.find(it->name.GetString()) == _mapExtraGeometries.end()) {
// _mapExtraGeometries[it->name.GetString()] = std::vector<GeometryInfoPtr>();
// }
// std::vector<GeometryInfoPtr>& vgeometries = _mapExtraGeometries[it->name.GetString()];
// vgeometries.reserve(it->value.Size() + vgeometries.size());
// size_t iGeometry = 0;
// for(rapidjson::Value::ConstValueIterator im = it->value.Begin(); im != it->value.End(); ++im, ++iGeometry) {
// std::string id = orjson::GetStringJsonValueByKey(*im, "id");
// UpdateOrCreateInfoWithNameCheck(*im, id, vgeometries, "name", fUnitScale);
// }
// }
// }
if (value.HasMember("extraGeometries") && value["extraGeometries"].IsArray()) {
for (rapidjson::Value::ConstValueIterator it = value["extraGeometries"].Begin(); it != value["extraGeometries"].End(); ++it) {
std::string name;
// has valid extra geometry
if (it->HasMember("name")) {
orjson::LoadJsonValueByKey(*it, "name", name);
}
else {
continue;
}

if (_mapExtraGeometries.find(name) == _mapExtraGeometries.end()) {
_mapExtraGeometries[name] = std::vector<GeometryInfoPtr>();
}

if (it->HasMember("geometries")) {
std::vector<GeometryInfoPtr>& vgeometries = _mapExtraGeometries[name];
vgeometries.reserve((*it)["geometries"].Size() + vgeometries.size());
for (rapidjson::Value::ConstValueIterator itGeometry = (*it)["geometries"].Begin(); itGeometry != (*it)["geometries"].End(); ++itGeometry) {
UpdateOrCreateInfoWithNameCheck(*itGeometry, vgeometries, "name", fUnitScale, options);
}
}
}
}

orjson::LoadJsonValueByKey(value, "isStatic", _bStatic);
orjson::LoadJsonValueByKey(value, "isEnabled", _bIsEnabled);
Expand Down