32 namespace fs = std::filesystem;
48 memoryPrx = getProxy<WorkingMemoryInterfacePrx>(
"WorkingMemory");
49 objectInstancesMemoryPrx = memoryPrx->getObjectInstancesSegment();
51 longtermMemoryPrx = getProxy<LongtermMemoryInterfacePrx>(
"LongtermMemory");
53 const std::string sceneFile = getProperty<std::string>(
"SceneFile").getValue();
54 const std::string snapshotName = getProperty<std::string>(
"SnapshotName").getValue();
55 targetUnit = getProperty<LengthUnit>(
"TargetLengthUnit").getValue();
57 importXMLSnapshot(sceneFile);
59 if (longtermMemoryPrx->saveWorkingMemorySnapshot(snapshotName, memoryPrx))
61 ARMARX_INFO <<
"Snapshot " << snapshotName <<
" saved. Import complete!";
66 XMLSceneImporter::importXMLSnapshot(
const std::string& fileName)
68 fs::path fpath(fileName);
70 if (!fs::exists(fpath))
72 ARMARX_ERROR <<
"File " << fileName <<
" does not exist! Aborting.";
76 std::ifstream infile(fpath.c_str());
77 std::string XMLString((std::istreambuf_iterator<char>(infile)),
78 std::istreambuf_iterator<char>());
85 XMLDoc.
parse<0>(
const_cast<char*
>(XMLString.c_str()));
98 ARMARX_ERROR <<
"Malformed XML-file: <scene> Tag is missing";
107 ARMARX_ERROR <<
"Malformed XML-file: <scene> must be followed by a <nodes> tag.";
115 const ObjectInstanceBasePtr newObjectInstance = createObjectInstanceFromXML(entityNode);
117 if (newObjectInstance)
119 objectInstancesMemoryPrx->addEntity(newObjectInstance);
123 ARMARX_INFO <<
"File successfully imported: " << fileName;
126 ObjectInstanceBasePtr
137 objectInstance->setExistenceCertainty(1.0f);
140 objectInstance->setClass(name, 1.0f);
143 armarx::FramedPositionBasePtr entityPosition = positionFromXML(xmlNode);
147 ARMARX_ERROR <<
"<position> tag is missing in node " << name;
151 objectInstance->setPosition(entityPosition);
154 armarx::FramedOrientationBasePtr entityOrientation = orientationFromXML(xmlNode);
156 if (entityOrientation)
158 objectInstance->setOrientation(entityOrientation);
161 return objectInstance;
164 armarx::FramedPositionBasePtr
174 Eigen::Vector3f position;
175 std::istringstream(positionNode->
first_attribute(
"x")->value()) >> position[0];
176 std::istringstream(positionNode->
first_attribute(
"y")->value()) >> position[1];
177 std::istringstream(positionNode->
first_attribute(
"z")->value()) >> position[2];
179 float scaleFactor = scaleFactorFromPositionXML(positionNode);
180 position *= scaleFactor;
185 armarx::FramedOrientationBasePtr
196 std::istringstream(quaternion->
first_attribute(
"qx")->value()) >> orientation.x();
197 std::istringstream(quaternion->
first_attribute(
"qy")->value()) >> orientation.y();
198 std::istringstream(quaternion->
first_attribute(
"qz")->value()) >> orientation.z();
199 std::istringstream(quaternion->
first_attribute(
"qw")->value()) >> orientation.w();
208 std::string unitstring =
"METER";
214 unitstring = std::string(unitAttribute->value());
219 if (unitstring ==
"METER")
224 if (unitstring ==
"CENTIMETER")
226 sourceFactor = 100.f;
228 else if (unitstring ==
"MILLIMETER")
230 sourceFactor = 1000.f;
234 std::stringstream strstr;
235 strstr << __FILE__ <<
" : " << __LINE__ <<
" (" << __FUNCTION__
236 <<
"): unknown unitstring '" << unitstring <<
"'";
237 throw std::invalid_argument{strstr.str()};
249 targetFactor = 100.f;
253 targetFactor = 1000.f;
256 std::stringstream strstr;
257 strstr << __FILE__ <<
" : " << __LINE__ <<
" (" << __FUNCTION__
258 <<
"): unknown targetUnit '" << targetUnit <<
"'";
259 throw std::invalid_argument{strstr.str()};
262 return targetFactor / sourceFactor;