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

Generated on Tue Sep 16 22:00:22 2008 for Robotsystem of the Robot Group Leipzig by  doxygen 1.4.7