odehandle.h

Go to the documentation of this file.
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.12  2009/08/03 14:09:48  jhoffmann
00024  *   Remove some compiling warnings, memory leaks; Add some code cleanups
00025  *
00026  *   Revision 1.11  2008/08/27 06:46:12  martius
00027  *   hashcode optimised and comment added
00028  *
00029  *   Revision 1.10  2008/08/26 18:58:32  martius
00030  *   comments
00031  *
00032  *   Revision 1.9  2008/04/17 15:59:02  martius
00033  *   OSG2 port finished
00034  *
00035  *   Revision 1.8.2.1  2008/04/15 16:21:53  martius
00036  *   Profiling
00037  *   Multithreading also for OSG and ODE but disables because of instabilities
00038  *
00039  *   Revision 1.8  2007/08/29 08:43:50  martius
00040  *   create simple space and delete space
00041  *
00042  *   Revision 1.7  2007/07/31 08:37:03  martius
00043  *   added a list of spaces for collision control within them
00044  *
00045  *   Revision 1.6  2007/07/03 13:04:22  martius
00046  *   pointer to global simulation time
00047  *   hash-maps are protected
00048  *
00049  *   Revision 1.5  2007/06/21 16:20:26  martius
00050  *   inlined isIgnoredSpace and Pair
00051  *
00052  *   Revision 1.4  2007/03/16 10:55:44  martius
00053  *   substance added
00054  *   ignoredSpaces and ignoredPairs
00055  *
00056  *   Revision 1.3  2006/07/14 12:23:56  martius
00057  *   selforg becomes HEAD
00058  *
00059  *   Revision 1.2.4.1  2005/12/06 10:13:26  martius
00060  *   openscenegraph integration started
00061  *
00062  *   Revision 1.2  2005/11/09 13:31:51  martius
00063  *   GPL'ised
00064  *
00065  ***************************************************************************/
00066 #ifndef __ODEHANDLE_H
00067 #define __ODEHANDLE_H
00068 
00069 #include <ext/hash_set>
00070 #include <vector>
00071 #include <ode/common.h>
00072 #include "substance.h"
00073 
00074 namespace lpzrobots {
00075 
00076 class Primitive;
00077 
00078 struct geomPairHash{
00079   size_t operator() (const std::pair<long, long>& p) const {
00080     return  2*p.first + p.second;
00081   }
00082 };
00083 
00084 /** Data structure for accessing the ODE */
00085 class OdeHandle
00086 {
00087 public:
00088   OdeHandle( );
00089   OdeHandle(  dWorldID _world, dSpaceID _space, dJointGroupID _jointGroup);
00090 
00091   dWorldID world;
00092   dSpaceID space;
00093   dJointGroupID jointGroup;
00094 
00095   Substance substance;
00096 
00097   /// creates world at global space and so on and sets global time pointer.
00098   void init(double* time); 
00099 
00100   /** use this function to create a new space with optional ignored collisions, 
00101       use deleteSpace to destroy it
00102       
00103       All primitives initialised with this handle are within this space.
00104    */
00105   void createNewSimpleSpace(dSpaceID parentspace, bool ignore_inside_collisions);
00106 
00107   /// destroys the space and unregisters them in the global lists
00108   void deleteSpace();
00109 
00110   /** adds a space to the list of ignored spaces for collision detection 
00111     (i.e within this space there is no collision)
00112   */
00113   void addIgnoredSpace(dSpaceID g);
00114   /// removes a space from the list of ignored spaces for collision detection
00115   void removeIgnoredSpace(dSpaceID g);
00116   /// checks whether the space is an ignored space for collision detection
00117   inline bool isIgnoredSpace(dSpaceID g) const
00118   {
00119     if (ignoredSpaces)
00120       return ignoredSpaces->find((long)g) != ignoredSpaces->end();
00121     else return false;
00122   }
00123 
00124   /** adds a space to the list of spaces for collision detection (ignored spaces do not need to be insered)*/
00125   void addSpace(dSpaceID g);
00126   /// removes a space from the list of ignored spaces for collision detection
00127   void removeSpace(dSpaceID g);
00128 
00129   /** deletes all associated memory objects, handle with care - use only when program exits */
00130   void destroySpaces();
00131 
00132   /// returns list of all spaces (as vector for parallelisation
00133   const std::vector<dSpaceID>& getSpaces();
00134 
00135 
00136   inline double getTime(){ return *time; }
00137   
00138   /// adds a pair of geoms to the list of ignored geom pairs for collision detection
00139   void addIgnoredPair(dGeomID g1, dGeomID g2);
00140   /// like addIgnoredPair(dGeomID g1, dGeomID g2) just with primitives (provided for convinience)
00141   void addIgnoredPair(Primitive* p1, Primitive* p2);
00142   /// removes pair of geoms from the list of ignored geom pairs for collision detection
00143   void removeIgnoredPair(dGeomID g1, dGeomID g2);
00144   /// like removeIgnoredPair(dGeomID g1, dGeomID g2) just with primitives (provided for convinience)
00145   void removeIgnoredPair(Primitive* p1, Primitive* p2);
00146   /// checks whether a pair of geoms is an ignored pair for collision detection
00147   inline bool isIgnoredPair(dGeomID g1, dGeomID g2) const { 
00148     return (ignoredPairs->find(std::pair<long, long>((long)g1,(long)g2)) != ignoredPairs->end())
00149       || (ignoredPairs->find(std::pair<long, long>((long)g2,(long)g1)) != ignoredPairs->end());
00150   }
00151 
00152 protected:
00153   double* time;
00154   //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.
00155 
00156   /// list of spaces, except ignored spaces
00157   std::vector<dSpaceID>* spaces;
00158 
00159   /// set of ignored spaces
00160   __gnu_cxx::hash_set<long>* ignoredSpaces;
00161 
00162   /// set of ignored geom pairs for collision
00163   __gnu_cxx::hash_set<std::pair<long,long>, geomPairHash >* ignoredPairs;
00164 
00165 };
00166 
00167 }
00168 #endif

Generated on Fri Oct 30 16:29:01 2009 for Robot Simulator of the Robotics Group for Self-Organization of Control by  doxygen 1.4.7