Skip to content
Snippets Groups Projects
Commit 88da2e58 authored by Rainer Kartmann's avatar Rainer Kartmann
Browse files

Add loading from scene snapshot by properties

parent be604455
No related branches found
No related tags found
No related merge requests found
...@@ -79,6 +79,13 @@ namespace armarx::armem::server::obj::instance ...@@ -79,6 +79,13 @@ namespace armarx::armem::server::obj::instance
"If true, no new snapshots are stored while an object is attached to a robot node.\n" "If true, no new snapshots are stored while an object is attached to a robot node.\n"
"If false, new snapshots are stored, but the attachment is kept in the new snapshots."); "If false, new snapshots are stored, but the attachment is kept in the new snapshots.");
defs->optional(p.sceneSnapshotsPackage, prefix + "scene.Package",
"ArmarX package containing the scene snapshots.\n"
"Scene snapshots are expected to be located in Package/data/Package/Scenes/*.json.");
defs->optional(p.sceneSnapshotToLoad, prefix + "scene.SnapshotToLoad",
"Scene snapshot to load on startup (e.g. 'Scene_2021-06-24_20-20-03').\n"
"You can also specify paths relative to 'Package/Scenes/'.");
decay.defineProperties(defs, prefix + "decay."); decay.defineProperties(defs, prefix + "decay.");
} }
...@@ -89,6 +96,13 @@ namespace armarx::armem::server::obj::instance ...@@ -89,6 +96,13 @@ namespace armarx::armem::server::obj::instance
coreSegment = &iceMemory.workingMemory->addCoreSegment(p.coreSegmentName, arondto::ObjectInstance::toAronType()); coreSegment = &iceMemory.workingMemory->addCoreSegment(p.coreSegmentName, arondto::ObjectInstance::toAronType());
coreSegment->setMaxHistorySize(p.maxHistorySize); coreSegment->setMaxHistorySize(p.maxHistorySize);
if (not p.sceneSnapshotToLoad.empty())
{
bool lockMemory = false;
commitSceneSnapshotFromFilename(p.sceneSnapshotToLoad, lockMemory);
}
} }
...@@ -747,7 +761,6 @@ namespace armarx::armem::server::obj::instance ...@@ -747,7 +761,6 @@ namespace armarx::armem::server::obj::instance
const std::string Segment::timestampPlaceholder = "%TIMESTAMP"; const std::string Segment::timestampPlaceholder = "%TIMESTAMP";
const std::string Segment::targetPackage = "ArmarXObjects";
std::optional<std::filesystem::path> Segment::resolveSceneFilename(const std::string& _filename) std::optional<std::filesystem::path> Segment::resolveSceneFilename(const std::string& _filename)
...@@ -763,16 +776,16 @@ namespace armarx::armem::server::obj::instance ...@@ -763,16 +776,16 @@ namespace armarx::armem::server::obj::instance
if (!finder) if (!finder)
{ {
finder.reset(new CMakePackageFinder(targetPackage)); finder.reset(new CMakePackageFinder(p.sceneSnapshotsPackage));
if (not finder->packageFound()) if (not finder->packageFound())
{ {
ARMARX_WARNING << "Could not find CMake package " << targetPackage << "."; ARMARX_WARNING << "Could not find CMake package " << p.sceneSnapshotsPackage << ".";
} }
} }
if (finder->packageFound()) if (finder->packageFound())
{ {
std::filesystem::path dataDir = finder->getDataDir(); std::filesystem::path dataDir = finder->getDataDir();
std::filesystem::path path = dataDir / targetPackage / "Scenes" / filename; std::filesystem::path path = dataDir / p.sceneSnapshotsPackage / "Scenes" / filename;
return path; return path;
} }
else else
...@@ -847,6 +860,30 @@ namespace armarx::armem::server::obj::instance ...@@ -847,6 +860,30 @@ namespace armarx::armem::server::obj::instance
} }
void Segment::commitSceneSnapshotFromFilename(const std::string& filename, bool lockMemory)
{
ARMARX_INFO << "Loading scene snapshot '" << filename << "' ...";
if (auto path = resolveSceneFilename(filename))
{
if (const auto snapshot = loadScene(path.value()))
{
std::filesystem::path filename = path->filename();
filename.replace_extension(); // Removes extension
if (lockMemory)
{
std::scoped_lock lock(memoryMutex);
commitSceneSnapshot(snapshot.value(), filename.string());
}
else
{
commitSceneSnapshot(snapshot.value(), filename.string());
}
}
}
}
void Segment::RemoteGui::setup(const Segment& data) void Segment::RemoteGui::setup(const Segment& data)
{ {
using namespace armarx::RemoteGui::Client; using namespace armarx::RemoteGui::Client;
...@@ -860,7 +897,7 @@ namespace armarx::armem::server::obj::instance ...@@ -860,7 +897,7 @@ namespace armarx::armem::server::obj::instance
loadButton.setLabel("Load Scene"); loadButton.setLabel("Load Scene");
storeButton.setLabel("Store Scene"); storeButton.setLabel("Store Scene");
HBoxLayout storeLoadLineLayout({Label(targetPackage + "/Scenes/"), storeLoadLine, Label(".json")}); HBoxLayout storeLoadLineLayout({Label(data.p.sceneSnapshotsPackage + "/Scenes/"), storeLoadLine, Label(".json")});
HBoxLayout storeLoadButtonsLayout({loadButton, storeButton}); HBoxLayout storeLoadButtonsLayout({loadButton, storeButton});
GridLayout grid; GridLayout grid;
...@@ -887,17 +924,8 @@ namespace armarx::armem::server::obj::instance ...@@ -887,17 +924,8 @@ namespace armarx::armem::server::obj::instance
{ {
if (loadButton.wasClicked()) if (loadButton.wasClicked())
{ {
if (auto path = data.resolveSceneFilename(storeLoadLine.getValue())) bool lockMemory = true;
{ data.commitSceneSnapshotFromFilename(storeLoadLine.getValue(), lockMemory);
if (const auto snapshot = data.loadScene(path.value()))
{
std::filesystem::path filename = path->filename();
filename.replace_extension(); // Removes extension
std::scoped_lock lock(data.memoryMutex);
data.commitSceneSnapshot(snapshot.value(), filename.string());
}
}
} }
if (storeButton.wasClicked()) if (storeButton.wasClicked())
......
...@@ -150,6 +150,7 @@ namespace armarx::armem::server::obj::instance ...@@ -150,6 +150,7 @@ namespace armarx::armem::server::obj::instance
armem::obj::SceneSnapshot getSceneSnapshot() const; armem::obj::SceneSnapshot getSceneSnapshot() const;
void commitSceneSnapshot(const armem::obj::SceneSnapshot& scene, const std::string& sceneName); void commitSceneSnapshot(const armem::obj::SceneSnapshot& scene, const std::string& sceneName);
void commitSceneSnapshotFromFilename(const std::string& filename, bool lockMemory);
public: public:
...@@ -179,6 +180,10 @@ namespace armarx::armem::server::obj::instance ...@@ -179,6 +180,10 @@ namespace armarx::armem::server::obj::instance
// -1 would be infinite, but this can let the RAM grow quickly. // -1 would be infinite, but this can let the RAM grow quickly.
long maxHistorySize = 25; long maxHistorySize = 25;
bool discardSnapshotsWhileAttached = true; bool discardSnapshotsWhileAttached = true;
/// Package containing the scene snapshots
std::string sceneSnapshotsPackage = "ArmarXObjects";
std::string sceneSnapshotToLoad = "";
}; };
Properties p; Properties p;
...@@ -192,8 +197,6 @@ namespace armarx::armem::server::obj::instance ...@@ -192,8 +197,6 @@ namespace armarx::armem::server::obj::instance
std::unique_ptr<CMakePackageFinder> finder; std::unique_ptr<CMakePackageFinder> finder;
static const std::string timestampPlaceholder; static const std::string timestampPlaceholder;
static const std::string targetPackage;
public: public:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment