00001 /********************************************************************* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2008, Willow Garage, Inc. 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of the Willow Garage nor the names of its 00018 * contributors may be used to endorse or promote products derived 00019 * from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 *********************************************************************/ 00034 00035 /* Author: Wim Meeussen */ 00036 00037 #ifndef URDF_LINK_H 00038 #define URDF_LINK_H 00039 00040 #include <string> 00041 #include <vector> 00042 #include <tinyxml/tinyxml.h> 00043 #include <boost/shared_ptr.hpp> 00044 00045 #include "joint.h" 00046 #include "color.h" 00047 00048 namespace urdf{ 00049 00050 class Geometry 00051 { 00052 public: 00053 enum {SPHERE, BOX, CYLINDER, MESH} type; 00054 00055 virtual bool initXml(TiXmlElement *) = 0; 00056 00057 }; 00058 00059 class Sphere : public Geometry 00060 { 00061 public: 00062 Sphere() { this->clear(); }; 00063 double radius; 00064 00065 void clear() 00066 { 00067 radius = 0; 00068 }; 00069 bool initXml(TiXmlElement *); 00070 }; 00071 00072 class Box : public Geometry 00073 { 00074 public: 00075 Box() { this->clear(); }; 00076 Vector3 dim; 00077 00078 void clear() 00079 { 00080 dim.clear(); 00081 }; 00082 bool initXml(TiXmlElement *); 00083 }; 00084 00085 class Cylinder : public Geometry 00086 { 00087 public: 00088 Cylinder() { this->clear(); }; 00089 double length; 00090 double radius; 00091 00092 void clear() 00093 { 00094 length = 0; 00095 radius = 0; 00096 }; 00097 bool initXml(TiXmlElement *); 00098 }; 00099 00100 class Mesh : public Geometry 00101 { 00102 public: 00103 Mesh() { this->clear(); }; 00104 std::string filename; 00105 Vector3 scale; 00106 00107 void clear() 00108 { 00109 filename.clear(); 00110 // default scale 00111 scale.x = 1; 00112 scale.y = 1; 00113 scale.z = 1; 00114 }; 00115 bool initXml(TiXmlElement *); 00116 }; 00117 00118 class Material 00119 { 00120 public: 00121 Material() { this->clear(); }; 00122 std::string name; 00123 std::string texture_filename; 00124 Color color; 00125 00126 void clear() 00127 { 00128 color.clear(); 00129 texture_filename.clear(); 00130 name.clear(); 00131 }; 00132 bool initXml(TiXmlElement* config); 00133 }; 00134 00135 class Inertial 00136 { 00137 public: 00138 Inertial() { this->clear(); }; 00139 Pose origin; 00140 double mass; 00141 double ixx,ixy,ixz,iyy,iyz,izz; 00142 00143 void clear() 00144 { 00145 origin.clear(); 00146 mass = 0; 00147 ixx = ixy = ixz = iyy = iyz = izz = 0; 00148 }; 00149 bool initXml(TiXmlElement* config); 00150 }; 00151 00152 class Visual 00153 { 00154 public: 00155 Visual() { this->clear(); }; 00156 Pose origin; 00157 boost::shared_ptr<Geometry> geometry; 00158 00159 std::string material_name; 00160 boost::shared_ptr<Material> material; 00161 00162 void clear() 00163 { 00164 origin.clear(); 00165 material_name.clear(); 00166 material.reset(); 00167 geometry.reset(); 00168 }; 00169 bool initXml(TiXmlElement* config); 00170 }; 00171 00172 class Collision 00173 { 00174 public: 00175 Collision() { this->clear(); }; 00176 Pose origin; 00177 boost::shared_ptr<Geometry> geometry; 00178 00179 void clear() 00180 { 00181 origin.clear(); 00182 geometry.reset(); 00183 }; 00184 bool initXml(TiXmlElement* config); 00185 }; 00186 00187 00188 class Link 00189 { 00190 public: 00191 Link() { this->clear(); }; 00192 00193 std::string name; 00194 00196 boost::shared_ptr<Inertial> inertial; 00197 00199 boost::shared_ptr<Visual> visual; 00200 00202 boost::shared_ptr<Collision> collision; 00203 00207 boost::shared_ptr<Joint> parent_joint; 00208 00209 std::vector<boost::shared_ptr<Joint> > child_joints; 00210 std::vector<boost::shared_ptr<Link> > child_links; 00211 00212 bool initXml(TiXmlElement* config); 00213 00214 boost::shared_ptr<Link> getParent() const 00215 {return parent_link_.lock();}; 00216 00217 void setParent(boost::shared_ptr<Link> parent); 00218 00219 void clear() 00220 { 00221 this->name.clear(); 00222 this->inertial.reset(); 00223 this->visual.reset(); 00224 this->collision.reset(); 00225 this->parent_joint.reset(); 00226 this->child_joints.clear(); 00227 this->child_links.clear(); 00228 }; 00229 void setParentJoint(boost::shared_ptr<Joint> child); 00230 void addChild(boost::shared_ptr<Link> child); 00231 void addChildJoint(boost::shared_ptr<Joint> child); 00232 00233 private: 00234 boost::weak_ptr<Link> parent_link_; 00235 00236 }; 00237 00238 00239 00240 00241 } 00242 00243 #endif