00001 /*************************************************************************** 00002 * Copyright (C) 2005 by Robot Group Leipzig * 00003 * martius@informatik.uni-leipzig.de * 00004 * fhesse@informatik.uni-leipzig.de * 00005 * der@informatik.uni-leipzig.de * 00006 * * 00007 * This program is free software; you can redistribute it and/or modify * 00008 * it under the terms of the GNU General Public License as published by * 00009 * the Free Software Foundation; either version 2 of the License, or * 00010 * (at your option) any later version. * 00011 * * 00012 * This program is distributed in the hope that it will be useful, * 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00015 * GNU General Public License for more details. * 00016 * * 00017 * You should have received a copy of the GNU General Public License * 00018 * along with this program; if not, write to the * 00019 * Free Software Foundation, Inc., * 00020 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 00021 * * 00022 * $Log: odehandle.h,v $ 00023 * Revision 1.15 2010/03/09 11:53:41 martius 00024 * renamed globally ode to ode-dbl 00025 * 00026 * Revision 1.14 2010/03/05 14:32:55 martius 00027 * camera sensor added 00028 * for that the scenegraph structure was changed into root, world, scene 00029 * camera does not work with shadows 00030 * works with newest version of ode (0.11) 00031 * 00032 * Revision 1.13 2009/12/01 17:32:10 martius 00033 * adapted Makefiles to ignore backward compat. errors 00034 * 00035 * Revision 1.12 2009/08/03 14:09:48 jhoffmann 00036 * Remove some compiling warnings, memory leaks; Add some code cleanups 00037 * 00038 * Revision 1.11 2008/08/27 06:46:12 martius 00039 * hashcode optimised and comment added 00040 * 00041 * Revision 1.10 2008/08/26 18:58:32 martius 00042 * comments 00043 * 00044 * Revision 1.9 2008/04/17 15:59:02 martius 00045 * OSG2 port finished 00046 * 00047 * Revision 1.8.2.1 2008/04/15 16:21:53 martius 00048 * Profiling 00049 * Multithreading also for OSG and ODE but disables because of instabilities 00050 * 00051 * Revision 1.8 2007/08/29 08:43:50 martius 00052 * create simple space and delete space 00053 * 00054 * Revision 1.7 2007/07/31 08:37:03 martius 00055 * added a list of spaces for collision control within them 00056 * 00057 * Revision 1.6 2007/07/03 13:04:22 martius 00058 * pointer to global simulation time 00059 * hash-maps are protected 00060 * 00061 * Revision 1.5 2007/06/21 16:20:26 martius 00062 * inlined isIgnoredSpace and Pair 00063 * 00064 * Revision 1.4 2007/03/16 10:55:44 martius 00065 * substance added 00066 * ignoredSpaces and ignoredPairs 00067 * 00068 * Revision 1.3 2006/07/14 12:23:56 martius 00069 * selforg becomes HEAD 00070 * 00071 * Revision 1.2.4.1 2005/12/06 10:13:26 martius 00072 * openscenegraph integration started 00073 * 00074 * Revision 1.2 2005/11/09 13:31:51 martius 00075 * GPL'ised 00076 * 00077 ***************************************************************************/ 00078 #ifndef __ODEHANDLE_H 00079 #define __ODEHANDLE_H 00080 00081 #if __GNUC__ > 3 00082 #include <backward/hash_set> 00083 #else 00084 #include <ext/hash_set> 00085 #endif 00086 #include <vector> 00087 #include <ode-dbl/common.h> 00088 #include "substance.h" 00089 00090 namespace lpzrobots { 00091 00092 class Primitive; 00093 00094 struct geomPairHash{ 00095 size_t operator() (const std::pair<long, long>& p) const { 00096 return 2*p.first + p.second; 00097 } 00098 }; 00099 00100 /** Data structure for accessing the ODE */ 00101 class OdeHandle 00102 { 00103 public: 00104 OdeHandle( ); 00105 OdeHandle( dWorldID _world, dSpaceID _space, dJointGroupID _jointGroup); 00106 00107 dWorldID world; 00108 dSpaceID space; 00109 dJointGroupID jointGroup; 00110 00111 Substance substance; 00112 00113 /// creates world at global space and so on and sets global time pointer. 00114 void init(double* time); 00115 00116 /// deletes the world and global data 00117 void close(); 00118 00119 /** use this function to create a new space with optional ignored collisions, 00120 use deleteSpace to destroy it 00121 00122 All primitives initialised with this handle are within this space. 00123 */ 00124 void createNewSimpleSpace(dSpaceID parentspace, bool ignore_inside_collisions); 00125 00126 /// destroys the space and unregisters them in the global lists 00127 void deleteSpace(); 00128 00129 /** adds a space to the list of ignored spaces for collision detection 00130 (i.e within this space there is no collision) 00131 */ 00132 void addIgnoredSpace(dSpaceID g); 00133 /// removes a space from the list of ignored spaces for collision detection 00134 void removeIgnoredSpace(dSpaceID g); 00135 /// checks whether the space is an ignored space for collision detection 00136 inline bool isIgnoredSpace(dSpaceID g) const 00137 { 00138 if (ignoredSpaces) 00139 return ignoredSpaces->find((long)g) != ignoredSpaces->end(); 00140 else return false; 00141 } 00142 00143 /** adds a space to the list of spaces for collision detection (ignored spaces do not need to be insered)*/ 00144 void addSpace(dSpaceID g); 00145 /// removes a space from the list of ignored spaces for collision detection 00146 void removeSpace(dSpaceID g); 00147 00148 /** deletes all associated memory objects, handle with care - use only when program exits */ 00149 void destroySpaces(); 00150 00151 /// returns list of all spaces (as vector for parallelisation 00152 const std::vector<dSpaceID>& getSpaces(); 00153 00154 00155 inline double getTime(){ return *time; } 00156 00157 /// adds a pair of geoms to the list of ignored geom pairs for collision detection 00158 void addIgnoredPair(dGeomID g1, dGeomID g2); 00159 /// like addIgnoredPair(dGeomID g1, dGeomID g2) just with primitives (provided for convinience) 00160 void addIgnoredPair(Primitive* p1, Primitive* p2); 00161 /// removes pair of geoms from the list of ignored geom pairs for collision detection 00162 void removeIgnoredPair(dGeomID g1, dGeomID g2); 00163 /// like removeIgnoredPair(dGeomID g1, dGeomID g2) just with primitives (provided for convinience) 00164 void removeIgnoredPair(Primitive* p1, Primitive* p2); 00165 /// checks whether a pair of geoms is an ignored pair for collision detection 00166 inline bool isIgnoredPair(dGeomID g1, dGeomID g2) const { 00167 return (ignoredPairs->find(std::pair<long, long>((long)g1,(long)g2)) != ignoredPairs->end()) 00168 || (ignoredPairs->find(std::pair<long, long>((long)g2,(long)g1)) != ignoredPairs->end()); 00169 } 00170 00171 protected: 00172 double* time; 00173 //TODO: Destroy the internal containers (vectors, list, ...) within the destructor. Now destroySpaces is used. Maybe we can use QMP_CRITICAL for a ref_cnt-variabel, or avoid the pointers. 00174 00175 /// list of spaces, except ignored spaces 00176 std::vector<dSpaceID>* spaces; 00177 00178 /// set of ignored spaces 00179 __gnu_cxx::hash_set<long>* ignoredSpaces; 00180 00181 /// set of ignored geom pairs for collision 00182 __gnu_cxx::hash_set<std::pair<long,long>, geomPairHash >* ignoredPairs; 00183 00184 }; 00185 00186 } 00187 #endif