~yade-dev/yade/0.80

« back to all changes in this revision

Viewing changes to pkg/common/Collider.cpp

  • Committer: Anton Gladky
  • Date: 2012-05-02 21:50:42 UTC
  • Revision ID: gladky.anton@gmail.com-20120502215042-v1fa9r65usqe7kfk
0.80.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*************************************************************************
 
2
*  Copyright (C) 2004 by Janek Kozicki                                   *
 
3
*  cosurgi@berlios.de                                                    *
 
4
*                                                                        *
 
5
*  This program is free software; it is licensed under the terms of the  *
 
6
*  GNU General Public License v2 or later. See file LICENSE for details. *
 
7
*************************************************************************/
 
8
 
 
9
#include<yade/pkg/common/Collider.hpp>
 
10
 
 
11
YADE_PLUGIN((Collider));
 
12
 
 
13
bool Collider::mayCollide(const Body* b1, const Body* b2){
 
14
        return 
 
15
                // might be called with deleted bodies, i.e. NULL pointers
 
16
                (b1!=NULL && b2!=NULL) &&
 
17
                // only collide if at least one particle is standalone or they belong to different clumps
 
18
                (b1->isStandalone() || b2->isStandalone() || b1->clumpId!=b2->clumpId ) &&
 
19
                 // do not collide clumps, since they are just containers, never interact
 
20
                !b1->isClump() && !b2->isClump() &&
 
21
                // masks must have at least 1 bit in common
 
22
                (b1->groupMask & b2->groupMask)!=0 
 
23
        ;
 
24
 
 
25
}
 
26
 
 
27
void Collider::pyHandleCustomCtorArgs(python::tuple& t, python::dict& d){
 
28
        if(python::len(t)==0) return; // nothing to do
 
29
        if(python::len(t)!=1) throw invalid_argument(("Collider optionally takes exactly one list of BoundFunctor's as non-keyword argument for constructor ("+lexical_cast<string>(python::len(t))+" non-keyword ards given instead)").c_str());
 
30
        typedef std::vector<shared_ptr<BoundFunctor> > vecBound;
 
31
        vecBound vb=python::extract<vecBound>(t[0])();
 
32
        FOREACH(shared_ptr<BoundFunctor> bf, vb) this->boundDispatcher->add(bf);
 
33
        t=python::tuple(); // empty the args
 
34
}
 
35
 
 
36
void Collider::findBoundDispatcherInEnginesIfNoFunctorsAndWarn(){
 
37
        if(boundDispatcher->functors.size()>0) return;
 
38
        shared_ptr<BoundDispatcher> bd;
 
39
        FOREACH(shared_ptr<Engine>& e, scene->engines){ bd=dynamic_pointer_cast<BoundDispatcher>(e); if(bd) break; }
 
40
        if(!bd) return;
 
41
        LOG_WARN("Collider.boundDispatcher had no functors defined, while there was a BoundDispatcher found in O.engines. Since version 0.60 (r2396), Collider has boundDispatcher integrated in itself; separate BoundDispatcher should not be used anymore. For now, I will fix it for you, but change your script! Where it reads e.g.\n\n\tO.engines=[...,\n\t\tBoundDispatcher([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),\n\t\t"<<getClassName()<<"(),\n\t\t...\n\t]\n\nit should become\n\n\tO.engines=[...,\n\t\t"<<getClassName()<<"([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),\n\t\t...\n\t]\n\ninstead.")
 
42
        boundDispatcher=bd;
 
43
        boundDispatcher->activated=false; // deactivate in the engine loop, the collider will call it itself
 
44
}
 
45