Robot Simulator of the Robotics Group for Self-Organization of Control: odehandle.h Source File

# odehandle.h

Go to the documentation of this file.

    00001 /***************************************************************************
    00002  *   Copyright (C) 2005-2011 LpzRobots development team                    *
    00003  *    Georg Martius  <georg dot martius at web dot de>                     *
    00004  *    Frank Guettler <guettler at informatik dot uni-leipzig dot de        *
    00005  *    Frank Hesse    <frank at nld dot ds dot mpg dot de>                  *
    00006  *    Ralf Der       <ralfder at mis dot mpg dot de>                       *
    00007  *                                                                         *
    00008  *   This program is free software; you can redistribute it and/or modify  *
    00009  *   it under the terms of the GNU General Public License as published by  *
    00010  *   the Free Software Foundation; either version 2 of the License, or     *
    00011  *   (at your option) any later version.                                   *
    00012  *                                                                         *
    00013  *   This program is distributed in the hope that it will be useful,       *
    00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
    00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
    00016  *   GNU General Public License for more details.                          *
    00017  *                                                                         *
    00018  *   You should have received a copy of the GNU General Public License     *
    00019  *   along with this program; if not, write to the                         *
    00020  *   Free Software Foundation, Inc.,                                       *
    00021  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
    00022  *                                                                         *
    00023  ***************************************************************************/
    00024 #ifndef __ODEHANDLE_H
    00025 #define __ODEHANDLE_H
    00026
    00027 #include <selforg/stl_map.h>
    00028
    00029 #include <vector>
    00030 #include <ode-dbl/common.h>
    00031 #include "substance.h"
    00032
    00033 namespace lpzrobots {
    00034
    00035 class Primitive;
    00036
    00037 struct geomPairHash{
    00038   size_t operator() (const std::pair<long, long>& p) const {
    00039     return  2*p.first + p.second;
    00040   }
    00041 };
    00042
    00043 /** Data structure for accessing the ODE */
    00044 class OdeHandle
    00045 {
    00046 public:
    00047   OdeHandle( );
    00048   OdeHandle(  dWorldID _world, dSpaceID _space, dJointGroupID _jointGroup);
    00049
    00050   dWorldID world;
    00051   dSpaceID space;
    00052   dJointGroupID jointGroup;
    00053
    00054   Substance substance;
    00055
    00056   /// creates world at global space and so on and sets global time pointer.
    00057   void init(double* time);
    00058
    00059   /// deletes the world and global data
    00060   void close();
    00061
    00062   /** use this function to create a new space with optional ignored collisions,
    00063       use deleteSpace to destroy it
    00064
    00065       All primitives initialised with this handle are within this space.
    00066    */
    00067   void createNewSimpleSpace(dSpaceID parentspace, bool ignore_inside_collisions);
    00068
    00069   /** like createNewSimpleSpace but with a HashSpace. More efficient for large objects
    00070    */
    00071   void createNewHashSpace(dSpaceID parentspace, bool ignore_inside_collisions);
    00072
    00073   /// destroys the space and unregisters them in the global lists
    00074   void deleteSpace();
    00075
    00076   /** adds a space to the list of spaces for collision detection (ignored spaces do not need to be insered)*/
    00077   void addSpace(dSpaceID g);
    00078   /// removes a space from the list of ignored spaces for collision detection
    00079   void removeSpace(dSpaceID g);
    00080
    00081   /** deletes all associated memory objects, handle with care - use only when program exits */
    00082   void destroySpaces();
    00083
    00084   /// returns list of all spaces (as vector for parallelisation
    00085   const std::vector<dSpaceID>& getSpaces();
    00086
    00087
    00088   inline double getTime(){ return *time; }
    00089
    00090   /// adds a pair of geoms to the list of ignored geom pairs for collision detection
    00091   void addIgnoredPair(dGeomID g1, dGeomID g2);
    00092   /// like addIgnoredPair(dGeomID g1, dGeomID g2) just with primitives (provided for convinience)
    00093   void addIgnoredPair(Primitive* p1, Primitive* p2);
    00094   /// removes pair of geoms from the list of ignored geom pairs for collision detection
    00095   void removeIgnoredPair(dGeomID g1, dGeomID g2);
    00096   /// like removeIgnoredPair(dGeomID g1, dGeomID g2) just with primitives (provided for convinience)
    00097   void removeIgnoredPair(Primitive* p1, Primitive* p2);
    00098   /// checks whether a pair of geoms is an ignored pair for collision detection
    00099   inline bool isIgnoredPair(dGeomID g1, dGeomID g2) const {
    00100     return (ignoredPairs->find(std::pair<long, long>((long)g1,(long)g2)) != ignoredPairs->end())
    00101       || (ignoredPairs->find(std::pair<long, long>((long)g2,(long)g1)) != ignoredPairs->end());
    00102   }
    00103
    00104 protected:
    00105   double* time;
    00106   //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.
    00107
    00108   /// list of spaces, except ignored spaces
    00109   std::vector<dSpaceID>* spaces;
    00110
    00111   /// set of ignored spaces
    00112   HashSet<long>* ignoredSpaces;
    00113
    00114   /// set of ignored geom pairs for collision
    00115   HashSet<std::pair<long,long>, geomPairHash >* ignoredPairs;
    00116
    00117 };
    00118
    00119 }
    00120 #endif