Statistiques
| Révision :

root / MyDefaultContactManager.h

Historique | Voir | Annoter | Télécharger (6,22 ko)

1
/******************************************************************************
2
*       SOFA, Simulation Open-Framework Architecture, version 1.0 RC 1        *
3
*                (c) 2006-2011 MGH, INRIA, USTL, UJF, CNRS                    *
4
*                                                                             *
5
* This library is free software; you can redistribute it and/or modify it     *
6
* under the terms of the GNU Lesser General Public License as published by    *
7
* the Free Software Foundation; either version 2.1 of the License, or (at     *
8
* your option) any later version.                                             *
9
*                                                                             *
10
* This library is distributed in the hope that it will be useful, but WITHOUT *
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
13
* for more details.                                                           *
14
*                                                                             *
15
* You should have received a copy of the GNU Lesser General Public License    *
16
* along with this library; if not, write to the Free Software Foundation,     *
17
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
18
*******************************************************************************
19
*                               SOFA :: Modules                               *
20
*                                                                             *
21
* Authors: The SOFA Team and external contributors (see Authors.txt)          *
22
*                                                                             *
23
* Contact information: contact@sofa-framework.org                             *
24
******************************************************************************/
25
#ifndef SOFA_COMPONENT_COLLISION_MYDEFAULTCONTACTMANAGER_H
26
#define SOFA_COMPONENT_COLLISION_MYDEFAULTCONTACTMANAGER_H
27

    
28
#include <sofa/core/collision/ContactManager.h>
29
#include <sofa/simulation/common/Node.h>
30
#include <sofa/component/component.h>
31
#include <sofa/helper/OptionsGroup.h>
32
#include <sofa/helper/map_ptr_stable_compare.h>
33
#include <vector>
34

    
35
#include "initAFM_plane.h"
36

    
37
namespace sofa
38
{
39

    
40
namespace component
41
{
42

    
43
namespace collision
44
{
45

    
46
class SOFA_AFM_plane_API MyDefaultContactManager : public core::collision::ContactManager
47
{
48
public :
49
    SOFA_CLASS(MyDefaultContactManager,sofa::core::collision::ContactManager);
50

    
51
protected:
52
    typedef sofa::helper::map_ptr_stable_compare<std::pair<core::CollisionModel*,core::CollisionModel*>,core::collision::Contact::SPtr> ContactMap;
53
    ContactMap contactMap;
54
    //typedef struct MaProfondeur{bool aTouche; double origine[3];} Profondeur;
55

    
56
    void cleanup();
57
public:
58
    //typedef struct MaProfondeur{bool aTouche; double origine[3];} Profondeur;
59

    
60
    Data<double> deepInMeristem;
61
    Data<bool> aTouche;
62
    Data<sofa::helper::vector<double> > origine;
63
    Data<sofa::helper::OptionsGroup> response;
64
    Data<std::string> responseParams;
65
protected:
66
    MyDefaultContactManager();
67
    ~MyDefaultContactManager();
68
    void setContactTags(core::CollisionModel* model1, core::CollisionModel* model2, core::collision::Contact::SPtr contact);
69

    
70
    //double deepInMeristem;
71
    //Profondeur penetration;
72

    
73
public:
74

    
75
//        bool CollisionDetected(){return penetration.aTouche;}
76
//        double getDepth(){return deepInMeristem;}
77
    bool CollisionDetected(){return aTouche.getValue();}
78
    double getDepth(){return deepInMeristem.getValue();}
79
    /// outputsVec fixes the reproducibility problems by storing contacts in the collision detection saved order
80
    /// if not given, it is still working but with eventual reproducibility problems
81
    void createContacts(const DetectionOutputMap& outputs);
82

    
83
    void init();
84
    void draw(const core::visual::VisualParams* vparams);
85

    
86
    template<class T>
87
    static typename T::SPtr create(T*, core::objectmodel::BaseContext* context, core::objectmodel::BaseObjectDescription* arg)
88
    {
89
        typename T::SPtr obj = sofa::core::objectmodel::New<T>();
90

    
91
        if (context)
92
        {
93
            context->addObject(obj);
94
            core::collision::Pipeline *pipeline = static_cast<simulation::Node*>(context)->collisionPipeline;
95
            sofa::helper::OptionsGroup options = initializeResponseOptions(pipeline);
96
            obj->response.setValue(options);
97
        }
98

    
99
        if (arg)
100
            obj->parse(arg);
101

    
102
        return obj;
103
    }
104

    
105
    virtual std::string getContactResponse(core::CollisionModel* model1, core::CollisionModel* model2);
106

    
107
    /// virtual methods used for cleaning the pipeline after a dynamic graph node deletion.
108
    /**
109
     * Contacts can be attached to a deleted node and their deletion is a problem for the pipeline.
110
     * @param c is the list of deleted contacts.
111
     */
112
    virtual void removeContacts(const ContactVector &/*c*/);
113
    void setDefaultResponseType(const std::string &responseT)
114
    {
115
        if (response.getValue().size() == 0)
116
        {
117
            helper::vector<std::string> listResponse(1,responseT);
118

    
119
            sofa::helper::OptionsGroup responseOptions(listResponse);
120
            response.setValue(responseOptions);
121
        }
122
        else
123
        {
124
            sofa::helper::OptionsGroup* options = response.beginEdit();
125

    
126
            options->setSelectedItem(responseT);
127
            response.endEdit();
128
        }
129
    }
130

    
131
    std::string getDefaultResponseType() const { return response.getValue().getSelectedItem(); }
132

    
133
protected:
134
    static sofa::helper::OptionsGroup initializeResponseOptions(core::collision::Pipeline *pipeline);
135

    
136
    std::map<Instance,ContactMap> storedContactMap;
137

    
138
    virtual void changeInstance(Instance inst)
139
    {
140
        core::collision::ContactManager::changeInstance(inst);
141
        storedContactMap[instance].swap(contactMap);
142
        contactMap.swap(storedContactMap[inst]);
143
    }
144

    
145
    // count failure messages, so we don't continuously repeat them
146
    std::map<std::pair<std::string,std::pair<std::string,std::string> >, int> errorMsgCount;
147
};
148

    
149
} // namespace collision
150

    
151
} // namespace component
152

    
153
} // namespace sofa
154

    
155
#endif