XMLSceneImporter.h
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* ArmarX is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License version 2 as
6* published by the Free Software Foundation.
7*
8* ArmarX is distributed in the hope that it will be useful, but
9* WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15*
16* @package MemoryX::XMLSceneImporter
17* @author (kozlov at kit dot edu)
18* @date 2012
19* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
23#pragma once
24
28
30
31#include <MemoryX/interface/components/LongtermMemoryInterface.h>
32#include <MemoryX/interface/components/WorkingMemoryInterface.h>
33
34namespace memoryx
35{
42
44 {
45 public:
48 {
49 defineRequiredProperty<std::string>("SceneFile", "Name of scene XML file to import")
50 .setCaseInsensitive(true);
52 "SnapshotName", "Name of snapshot (=MongoDB collection) to load objects to")
53 .setCaseInsensitive(true);
55 "TargetLengthUnit", eMETER, "Length unit to convert into (M, CM or MM)")
56 .setCaseInsensitive(false)
57 .map("M", eMETER)
58 .map("CM", eCENTIMETER)
59 .map("MM", eMILLIMETER);
60 }
61 };
62
63 /**
64 * @brief The XMLSceneImporter class reads scene specification files and creates a snapshot with the specified name.
65
66 An ObjectInstance is created for every <node> tag found in the XML description
67 and added to the objectInstances memory segment.
68 The contents of the objectInstances memory segment is then stored as a snapshot in the LongtermMemory under the
69 identifier given by the SnapshotName property.
70
71 The XML scene format is described next.
72 Note that the unit attribute can be omitted from <position> tags in which case the default value "METER" is assumed.
73
74 \code
75 <scene formatVersion="1.0.0">
76 <nodes>
77 <node name="object_name">
78 <position x="0.000000" y="0.000000" z="0.000000" unit"METER">
79 </position>
80 <?rotation qx="-0.707107" qy="0.707107" qz="-0.000000" qw="0.000000"/>
81 <?scale x="0.001000" y="0.001000" z="0.001000"/>
82 <?AABB local="0">
83 <min x="-2102.074219" y="-654.052673" z="-1337.000122" />
84 <max x="0.000000" y="0.000000" z="0.000000" />
85 </AABB>
86 <?entity name="object_name" meshFile="object_name.wrl"/>
87 </node>
88 ...
89 <node name="object_name">
90 </node>
91 </nodes>
92 </scene>
93 \endcode
94
95 */
97 {
98 public:
99 // inherited from Component
100 std::string
101 getDefaultName() const override
102 {
103 return "XMLSceneImporter";
104 }
105
106 void onInitComponent() override;
107 void onConnectComponent() override;
108
109 /**
110 * @see PropertyUser::createPropertyDefinitions()
111 */
118
119 private:
120 WorkingMemoryInterfacePrx memoryPrx;
121 ObjectInstanceMemorySegmentBasePrx objectInstancesMemoryPrx;
122 LongtermMemoryInterfacePrx longtermMemoryPrx;
123
124 LengthUnit targetUnit;
125
126 /**
127 * @brief importXMLSnapshot reads the given scene description and creates entities for the objects to be stored in the snapshot
128 * @param fileName the name/path of the scene.xml file to import
129 */
130 void importXMLSnapshot(const std::string& fileName);
131 /**
132 * @brief createObjectInstanceFromXML
133 * @param xmlNode the current <node> tag representing an entity
134 * @return ObjectInstanceBase
135 */
136 ObjectInstanceBasePtr createObjectInstanceFromXML(rapidxml::xml_node<>* xmlNode);
137
138 /**
139 * @brief positionFromXML extracts the <position> tag from the given \p xmlNode an turns it into a FramedPosition.
140 * @param xmlNode extract the <position> tag from this node
141 * @return FramedPosition instance containing the object rotation or a NullPointer if no rotation was specified
142 */
143 armarx::FramedPositionBasePtr positionFromXML(rapidxml::xml_node<>* xmlNode);
144
145 /**
146 * @brief scaleFactorFromPositionXML extracts the <unit> tag from the \p positionNode and calculates a scale factor
147 * based on the value of the TargetLengthUnit property.
148 * @param positionNode the XML node from which to extract the <unit> tag
149 * @return scale factor which needs to be applied to the position node
150 */
151 float scaleFactorFromPositionXML(rapidxml::xml_node<>* positionNode);
152
153 /**
154 * @brief orientationFromXML extracts the <rotation> tag from the given \p xmlNode an turns it into a FramedOrientation.
155 * @param xmlNode extract the <rotation> tag from this node
156 * @return FramedOrientation instance containing the object rotation or a NullPointer if no rotation was specified
157 */
158 armarx::FramedOrientationBasePtr orientationFromXML(rapidxml::xml_node<>* xmlNode);
159 };
160
161} // namespace memoryx
#define ARMARXCOMPONENT_IMPORT_EXPORT
Default component property definition container.
Definition Component.h:70
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition Component.cpp:46
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition Component.h:94
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
PropertyDefinition< PropertyType > & defineRequiredProperty(const std::string &name, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
The XMLSceneImporter class reads scene specification files and creates a snapshot with the specified ...
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
std::string getDefaultName() const override
Retrieve default name of component.
Class representing a node of XML document.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
VirtualRobot headers.
This file contains rapidxml parser and DOM implementation.