00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef COLLADA_URDF_COLLADA_WRITER_H
00038 #define COLLADA_URDF_COLLADA_WRITER_H
00039
00040 #include "collada_urdf/collada_urdf.h"
00041
00042 #include <map>
00043
00044 #include <dae.h>
00045 #include <dae/daeDocument.h>
00046 #include <dae/daeErrorHandler.h>
00047 #include <dae/domAny.h>
00048 #include <dom/domCOLLADA.h>
00049 #include <dom/domConstants.h>
00050 #include <dom/domElements.h>
00051 #include <dom/domTriangles.h>
00052 #include <dom/domTypes.h>
00053 #include <resource_retriever/retriever.h>
00054 #include <urdf/model.h>
00055 #include <urdf/pose.h>
00056 #include <angles/angles.h>
00057
00058 namespace collada_urdf {
00059
00060 class Mesh;
00061
00067 class ColladaWriter : public daeErrorHandler
00068 {
00069 private:
00070 struct SCENE
00071 {
00072 domVisual_sceneRef vscene;
00073 domKinematics_sceneRef kscene;
00074 domPhysics_sceneRef pscene;
00075 domInstance_with_extraRef viscene;
00076 domInstance_kinematics_sceneRef kiscene;
00077 domInstance_with_extraRef piscene;
00078 };
00079
00080 public:
00081 ColladaWriter(urdf::Model const& robot);
00082 virtual ~ColladaWriter();
00083
00084 boost::shared_ptr<DAE> convert();
00085
00086 protected:
00087 virtual void handleError(daeString msg);
00088 virtual void handleWarning(daeString msg);
00089
00090 private:
00091 void initDocument(std::string const& documentName);
00092 SCENE createScene();
00093
00094 void setupPhysics(SCENE const& scene);
00095
00096 void addGeometries();
00097 void loadMesh(std::string const& filename, domGeometryRef geometry, std::string const& geometry_id);
00098 bool loadMeshWithSTLLoader(resource_retriever::MemoryResource const& resource, domGeometryRef geometry, std::string const& geometry_id);
00099 void buildMeshFromSTLLoader(boost::shared_ptr<Mesh> stl_mesh, daeElementRef parent, std::string const& geometry_id);
00100
00101 void addKinematics(SCENE const& scene);
00102 void addJoints(daeElementRef parent);
00103 void addKinematicLink(boost::shared_ptr<urdf::Link const> urdf_link, daeElementRef parent, int& link_num);
00104
00105 void addVisuals(SCENE const& scene);
00106 void addVisualLink(boost::shared_ptr<urdf::Link const> urdf_link, daeElementRef parent, int& link_num);
00107
00108 void addMaterials();
00109 domEffectRef addEffect(std::string const& geometry_id, urdf::Color const& color_ambient, urdf::Color const& color_diffuse);
00110
00111 void addBindings(SCENE const& scene);
00112
00113 domTranslateRef addTranslate(daeElementRef parent, urdf::Vector3 const& position, daeElementRef before = NULL, bool ignore_zero_translations = false);
00114 domRotateRef addRotate(daeElementRef parent, urdf::Rotation const& r, daeElementRef before = NULL, bool ignore_zero_rotations = false);
00115 void addMimicJoint(domFormulaRef formula, const std::string& joint_sid,const std::string& joint_mimic_sid, double multiplier, double offset);
00116 std::string getTimeStampString() const;
00117
00118 private:
00119 static int s_doc_count_;
00120
00121 urdf::Model robot_;
00122 boost::shared_ptr<DAE> collada_;
00123 domCOLLADA* dom_;
00124 domCOLLADA::domSceneRef scene_;
00125
00126 domLibrary_geometriesRef geometriesLib_;
00127 domLibrary_visual_scenesRef visualScenesLib_;
00128 domLibrary_kinematics_scenesRef kinematicsScenesLib_;
00129 domLibrary_kinematics_modelsRef kinematicsModelsLib_;
00130 domLibrary_jointsRef jointsLib_;
00131 domLibrary_physics_scenesRef physicsScenesLib_;
00132 domLibrary_materialsRef materialsLib_;
00133 domLibrary_effectsRef effectsLib_;
00134
00135 domKinematics_modelRef kmodel_;
00136
00137 std::map<std::string, std::string> geometry_ids_;
00138 std::map<std::string, std::string> joint_sids_;
00139 std::map<std::string, std::string> node_ids_;
00140 };
00141
00142 }
00143
00144 #endif