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 
29 
30 #include <MemoryX/interface/components/WorkingMemoryInterface.h>
31 #include <MemoryX/interface/components/LongtermMemoryInterface.h>
32 
33 namespace memoryx
34 {
36  {
40  };
41 
44  {
45  public:
48  {
49  defineRequiredProperty<std::string>("SceneFile", "Name of scene XML file to import")
50  .setCaseInsensitive(true);
51  defineRequiredProperty<std::string>("SnapshotName", "Name of snapshot (=MongoDB collection) to load objects to")
52  .setCaseInsensitive(true);
53  defineOptionalProperty<LengthUnit>("TargetLengthUnit", eMETER, "Length unit to convert into (M, CM or MM)")
54  .setCaseInsensitive(false)
55  .map("M", eMETER)
56  .map("CM", eCENTIMETER)
57  .map("MM", eMILLIMETER);
58  }
59  };
60 
61  /**
62  * @brief The XMLSceneImporter class reads scene specification files and creates a snapshot with the specified name.
63 
64  An ObjectInstance is created for every <node> tag found in the XML description
65  and added to the objectInstances memory segment.
66  The contents of the objectInstances memory segment is then stored as a snapshot in the LongtermMemory under the
67  identifier given by the SnapshotName property.
68 
69  The XML scene format is described next.
70  Note that the unit attribute can be omitted from <position> tags in which case the default value "METER" is assumed.
71 
72  \code
73  <scene formatVersion="1.0.0">
74  <nodes>
75  <node name="object_name">
76  <position x="0.000000" y="0.000000" z="0.000000" unit"METER">
77  </position>
78  <?rotation qx="-0.707107" qy="0.707107" qz="-0.000000" qw="0.000000"/>
79  <?scale x="0.001000" y="0.001000" z="0.001000"/>
80  <?AABB local="0">
81  <min x="-2102.074219" y="-654.052673" z="-1337.000122" />
82  <max x="0.000000" y="0.000000" z="0.000000" />
83  </AABB>
84  <?entity name="object_name" meshFile="object_name.wrl"/>
85  </node>
86  ...
87  <node name="object_name">
88  </node>
89  </nodes>
90  </scene>
91  \endcode
92 
93  */
95  virtual public armarx::Component
96  {
97  public:
98  // inherited from Component
99  std::string getDefaultName() const override
100  {
101  return "XMLSceneImporter";
102  }
103  void onInitComponent() override;
104  void onConnectComponent() override;
105 
106  /**
107  * @see PropertyUser::createPropertyDefinitions()
108  */
110  {
111  return armarx::PropertyDefinitionsPtr(new XMLSceneImporterPropertyDefinitions(getConfigIdentifier()));
112  }
113 
114  private:
115  WorkingMemoryInterfacePrx memoryPrx;
116  ObjectInstanceMemorySegmentBasePrx objectInstancesMemoryPrx;
117  LongtermMemoryInterfacePrx longtermMemoryPrx;
118 
119  LengthUnit targetUnit;
120 
121  /**
122  * @brief importXMLSnapshot reads the given scene description and creates entities for the objects to be stored in the snapshot
123  * @param fileName the name/path of the scene.xml file to import
124  */
125  void importXMLSnapshot(const std::string& fileName);
126  /**
127  * @brief createObjectInstanceFromXML
128  * @param xmlNode the current <node> tag representing an entity
129  * @return ObjectInstanceBase
130  */
131  ObjectInstanceBasePtr createObjectInstanceFromXML(rapidxml::xml_node<>* xmlNode);
132 
133  /**
134  * @brief positionFromXML extracts the <position> tag from the given \p xmlNode an turns it into a FramedPosition.
135  * @param xmlNode extract the <position> tag from this node
136  * @return FramedPosition instance containing the object rotation or a NullPointer if no rotation was specified
137  */
138  armarx::FramedPositionBasePtr positionFromXML(rapidxml::xml_node<>* xmlNode);
139 
140  /**
141  * @brief scaleFactorFromPositionXML extracts the <unit> tag from the \p positionNode and calculates a scale factor
142  * based on the value of the TargetLengthUnit property.
143  * @param positionNode the XML node from which to extract the <unit> tag
144  * @return scale factor which needs to be applied to the position node
145  */
146  float scaleFactorFromPositionXML(rapidxml::xml_node<>* positionNode);
147 
148  /**
149  * @brief orientationFromXML extracts the <rotation> tag from the given \p xmlNode an turns it into a FramedOrientation.
150  * @param xmlNode extract the <rotation> tag from this node
151  * @return FramedOrientation instance containing the object rotation or a NullPointer if no rotation was specified
152  */
153  armarx::FramedOrientationBasePtr orientationFromXML(rapidxml::xml_node<>* xmlNode);
154  };
155 
156 }
157 
Pose.h
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
memoryx::XMLSceneImporterPropertyDefinitions
Definition: XMLSceneImporter.h:42
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
memoryx::eCENTIMETER
@ eCENTIMETER
Definition: XMLSceneImporter.h:38
memoryx::eMILLIMETER
@ eMILLIMETER
Definition: XMLSceneImporter.h:39
memoryx::LengthUnit
LengthUnit
Definition: XMLSceneImporter.h:35
memoryx::XMLSceneImporterPropertyDefinitions::XMLSceneImporterPropertyDefinitions
XMLSceneImporterPropertyDefinitions(std::string prefix)
Definition: XMLSceneImporter.h:46
ARMARXCOMPONENT_IMPORT_EXPORT
#define ARMARXCOMPONENT_IMPORT_EXPORT
Definition: ImportExportComponent.h:38
memoryx::XMLSceneImporter
The XMLSceneImporter class reads scene specification files and creates a snapshot with the specified ...
Definition: XMLSceneImporter.h:94
Component.h
armarx::Component
Baseclass for all ArmarX ManagedIceObjects requiring properties.
Definition: Component.h:95
memoryx::XMLSceneImporter::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: XMLSceneImporter.h:109
rapidxml::xml_node
Class representing a node of XML document.
Definition: rapidxml.hpp:138
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::ComponentPropertyDefinitions::ComponentPropertyDefinitions
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition: Component.cpp:37
memoryx::eMETER
@ eMETER
Definition: XMLSceneImporter.h:37
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
rapidxml.hpp
memoryx::XMLSceneImporter::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: XMLSceneImporter.h:99
ImportExportComponent.h