GCOP
1.0
|
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_INTERFACE_LINK_H 00038 #define URDF_INTERFACE_LINK_H 00039 00040 #include <string> 00041 #include <vector> 00042 #include <tinyxml.h> 00043 #include <boost/shared_ptr.hpp> 00044 #include <boost/weak_ptr.hpp> 00045 #include <map> 00046 00047 #include "urdfjoint.h" 00048 #include "color.h" 00049 00050 namespace gcop_urdf{ 00051 00052 class Geometry 00053 { 00054 public: 00055 enum {SPHERE, BOX, CYLINDER, MESH} type; 00056 00057 virtual bool initXml(TiXmlElement *) = 0; 00058 00059 }; 00060 00061 class Sphere : public Geometry 00062 { 00063 public: 00064 Sphere() { this->clear(); }; 00065 double radius; 00066 00067 void clear() 00068 { 00069 radius = 0; 00070 }; 00071 bool initXml(TiXmlElement *); 00072 }; 00073 00074 class Box : public Geometry 00075 { 00076 public: 00077 Box() { this->clear(); }; 00078 Vector3 dim; 00079 00080 void clear() 00081 { 00082 dim.clear(); 00083 }; 00084 bool initXml(TiXmlElement *); 00085 }; 00086 00087 class Cylinder : public Geometry 00088 { 00089 public: 00090 Cylinder() { this->clear(); }; 00091 double length; 00092 double radius; 00093 00094 void clear() 00095 { 00096 length = 0; 00097 radius = 0; 00098 }; 00099 bool initXml(TiXmlElement *); 00100 }; 00101 00102 class Mesh : public Geometry 00103 { 00104 public: 00105 Mesh() { this->clear(); }; 00106 std::string filename; 00107 Vector3 scale; 00108 00109 void clear() 00110 { 00111 filename.clear(); 00112 // default scale 00113 scale.x = 1; 00114 scale.y = 1; 00115 scale.z = 1; 00116 }; 00117 bool initXml(TiXmlElement *); 00118 bool fileExists(std::string filename); 00119 }; 00120 00121 class Material 00122 { 00123 public: 00124 Material() { this->clear(); }; 00125 std::string name; 00126 std::string texture_filename; 00127 Color color; 00128 00129 void clear() 00130 { 00131 color.clear(); 00132 texture_filename.clear(); 00133 name.clear(); 00134 }; 00135 bool initXml(TiXmlElement* config); 00136 }; 00137 00138 class Inertial 00139 { 00140 public: 00141 Inertial() { this->clear(); }; 00142 Pose origin; 00143 double mass; 00144 double ixx,ixy,ixz,iyy,iyz,izz; 00145 00146 void clear() 00147 { 00148 origin.clear(); 00149 mass = 0; 00150 ixx = ixy = ixz = iyy = iyz = izz = 0; 00151 }; 00152 bool initXml(TiXmlElement* config); 00153 }; 00154 00155 class Visual 00156 { 00157 public: 00158 Visual() { this->clear(); }; 00159 Pose origin; 00160 boost::shared_ptr<Geometry> geometry; 00161 00162 std::string material_name; 00163 boost::shared_ptr<Material> material; 00164 00165 void clear() 00166 { 00167 origin.clear(); 00168 material_name.clear(); 00169 material.reset(); 00170 geometry.reset(); 00171 this->group_name.clear(); 00172 }; 00173 bool initXml(TiXmlElement* config); 00174 std::string group_name; 00175 }; 00176 00177 class Collision 00178 { 00179 public: 00180 Collision() { this->clear(); }; 00181 Pose origin; 00182 boost::shared_ptr<Geometry> geometry; 00183 00184 void clear() 00185 { 00186 origin.clear(); 00187 geometry.reset(); 00188 this->group_name.clear(); 00189 }; 00190 bool initXml(TiXmlElement* config); 00191 std::string group_name; 00192 }; 00193 00194 00195 class Link 00196 { 00197 public: 00198 Link() { this->clear(); }; 00199 00200 std::string name; 00201 00203 boost::shared_ptr<Inertial> inertial; 00204 00206 boost::shared_ptr<Visual> visual; 00207 00209 boost::shared_ptr<Collision> collision; 00210 00212 std::map<std::string, boost::shared_ptr<std::vector<boost::shared_ptr<Visual> > > > visual_groups; 00213 00215 std::map<std::string, boost::shared_ptr<std::vector<boost::shared_ptr<Collision> > > > collision_groups; 00216 00220 boost::shared_ptr<Joint> parent_joint; 00221 00223 bool visited; 00224 00225 std::vector<boost::shared_ptr<Joint> > child_joints; 00226 std::vector<boost::shared_ptr<Link> > child_links; 00227 00228 bool initXml(TiXmlElement* config); 00229 00230 boost::shared_ptr<Link> getParent() const 00231 {return parent_link_.lock();}; 00232 00233 void setParent(boost::shared_ptr<Link> parent); 00234 00235 void clear() 00236 { 00237 this->name.clear(); 00238 this->inertial.reset(); 00239 this->visual.reset(); 00240 this->collision.reset(); 00241 this->parent_joint.reset(); 00242 this->child_joints.clear(); 00243 this->child_links.clear(); 00244 this->collision_groups.clear(); 00245 visited = false; 00246 }; 00247 void setParentJoint(boost::shared_ptr<Joint> child); 00248 void addChild(boost::shared_ptr<Link> child); 00249 void addChildJoint(boost::shared_ptr<Joint> child); 00250 00251 void addVisual(std::string group_name, boost::shared_ptr<Visual> visual); 00252 boost::shared_ptr<std::vector<boost::shared_ptr<Visual > > > getVisuals(const std::string& group_name) const; 00253 void addCollision(std::string group_name, boost::shared_ptr<Collision> collision); 00254 boost::shared_ptr<std::vector<boost::shared_ptr<Collision > > > getCollisions(const std::string& group_name) const; 00255 private: 00256 boost::weak_ptr<Link> parent_link_; 00257 00258 }; 00259 00260 00261 00262 00263 } 00264 00265 #endif