Statistiques
| Révision :

root / MyDefaultContactManager.h

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

1 1 rmalgat
/******************************************************************************
2 1 rmalgat
*       SOFA, Simulation Open-Framework Architecture, version 1.0 RC 1        *
3 1 rmalgat
*                (c) 2006-2011 MGH, INRIA, USTL, UJF, CNRS                    *
4 1 rmalgat
*                                                                             *
5 1 rmalgat
* This library is free software; you can redistribute it and/or modify it     *
6 1 rmalgat
* under the terms of the GNU Lesser General Public License as published by    *
7 1 rmalgat
* the Free Software Foundation; either version 2.1 of the License, or (at     *
8 1 rmalgat
* your option) any later version.                                             *
9 1 rmalgat
*                                                                             *
10 1 rmalgat
* This library is distributed in the hope that it will be useful, but WITHOUT *
11 1 rmalgat
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
12 1 rmalgat
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
13 1 rmalgat
* for more details.                                                           *
14 1 rmalgat
*                                                                             *
15 1 rmalgat
* You should have received a copy of the GNU Lesser General Public License    *
16 1 rmalgat
* along with this library; if not, write to the Free Software Foundation,     *
17 1 rmalgat
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
18 1 rmalgat
*******************************************************************************
19 1 rmalgat
*                               SOFA :: Modules                               *
20 1 rmalgat
*                                                                             *
21 1 rmalgat
* Authors: The SOFA Team and external contributors (see Authors.txt)          *
22 1 rmalgat
*                                                                             *
23 1 rmalgat
* Contact information: contact@sofa-framework.org                             *
24 1 rmalgat
******************************************************************************/
25 1 rmalgat
#ifndef SOFA_COMPONENT_COLLISION_MYDEFAULTCONTACTMANAGER_H
26 1 rmalgat
#define SOFA_COMPONENT_COLLISION_MYDEFAULTCONTACTMANAGER_H
27 1 rmalgat
28 1 rmalgat
#include <sofa/core/collision/ContactManager.h>
29 1 rmalgat
#include <sofa/simulation/common/Node.h>
30 1 rmalgat
#include <sofa/component/component.h>
31 1 rmalgat
#include <sofa/helper/OptionsGroup.h>
32 1 rmalgat
#include <sofa/helper/map_ptr_stable_compare.h>
33 1 rmalgat
#include <vector>
34 1 rmalgat
35 1 rmalgat
#include "initAFM_plane.h"
36 1 rmalgat
37 1 rmalgat
namespace sofa
38 1 rmalgat
{
39 1 rmalgat
40 1 rmalgat
namespace component
41 1 rmalgat
{
42 1 rmalgat
43 1 rmalgat
namespace collision
44 1 rmalgat
{
45 1 rmalgat
46 1 rmalgat
class SOFA_AFM_plane_API MyDefaultContactManager : public core::collision::ContactManager
47 1 rmalgat
{
48 1 rmalgat
public :
49 1 rmalgat
    SOFA_CLASS(MyDefaultContactManager,sofa::core::collision::ContactManager);
50 1 rmalgat
51 1 rmalgat
protected:
52 1 rmalgat
    typedef sofa::helper::map_ptr_stable_compare<std::pair<core::CollisionModel*,core::CollisionModel*>,core::collision::Contact::SPtr> ContactMap;
53 1 rmalgat
    ContactMap contactMap;
54 1 rmalgat
    //typedef struct MaProfondeur{bool aTouche; double origine[3];} Profondeur;
55 1 rmalgat
56 1 rmalgat
    void cleanup();
57 1 rmalgat
public:
58 1 rmalgat
    //typedef struct MaProfondeur{bool aTouche; double origine[3];} Profondeur;
59 1 rmalgat
60 1 rmalgat
    Data<double> deepInMeristem;
61 1 rmalgat
    Data<bool> aTouche;
62 1 rmalgat
    Data<sofa::helper::vector<double> > origine;
63 1 rmalgat
    Data<sofa::helper::OptionsGroup> response;
64 1 rmalgat
    Data<std::string> responseParams;
65 1 rmalgat
protected:
66 1 rmalgat
    MyDefaultContactManager();
67 1 rmalgat
    ~MyDefaultContactManager();
68 1 rmalgat
    void setContactTags(core::CollisionModel* model1, core::CollisionModel* model2, core::collision::Contact::SPtr contact);
69 1 rmalgat
70 1 rmalgat
    //double deepInMeristem;
71 1 rmalgat
    //Profondeur penetration;
72 1 rmalgat
73 1 rmalgat
public:
74 1 rmalgat
75 1 rmalgat
//        bool CollisionDetected(){return penetration.aTouche;}
76 1 rmalgat
//        double getDepth(){return deepInMeristem;}
77 1 rmalgat
    bool CollisionDetected(){return aTouche.getValue();}
78 1 rmalgat
    double getDepth(){return deepInMeristem.getValue();}
79 1 rmalgat
    /// outputsVec fixes the reproducibility problems by storing contacts in the collision detection saved order
80 1 rmalgat
    /// if not given, it is still working but with eventual reproducibility problems
81 1 rmalgat
    void createContacts(const DetectionOutputMap& outputs);
82 1 rmalgat
83 1 rmalgat
    void init();
84 1 rmalgat
    void draw(const core::visual::VisualParams* vparams);
85 1 rmalgat
86 1 rmalgat
    template<class T>
87 1 rmalgat
    static typename T::SPtr create(T*, core::objectmodel::BaseContext* context, core::objectmodel::BaseObjectDescription* arg)
88 1 rmalgat
    {
89 1 rmalgat
        typename T::SPtr obj = sofa::core::objectmodel::New<T>();
90 1 rmalgat
91 1 rmalgat
        if (context)
92 1 rmalgat
        {
93 1 rmalgat
            context->addObject(obj);
94 1 rmalgat
            core::collision::Pipeline *pipeline = static_cast<simulation::Node*>(context)->collisionPipeline;
95 1 rmalgat
            sofa::helper::OptionsGroup options = initializeResponseOptions(pipeline);
96 1 rmalgat
            obj->response.setValue(options);
97 1 rmalgat
        }
98 1 rmalgat
99 1 rmalgat
        if (arg)
100 1 rmalgat
            obj->parse(arg);
101 1 rmalgat
102 1 rmalgat
        return obj;
103 1 rmalgat
    }
104 1 rmalgat
105 1 rmalgat
    virtual std::string getContactResponse(core::CollisionModel* model1, core::CollisionModel* model2);
106 1 rmalgat
107 1 rmalgat
    /// virtual methods used for cleaning the pipeline after a dynamic graph node deletion.
108 1 rmalgat
    /**
109 1 rmalgat
     * Contacts can be attached to a deleted node and their deletion is a problem for the pipeline.
110 1 rmalgat
     * @param c is the list of deleted contacts.
111 1 rmalgat
     */
112 1 rmalgat
    virtual void removeContacts(const ContactVector &/*c*/);
113 1 rmalgat
    void setDefaultResponseType(const std::string &responseT)
114 1 rmalgat
    {
115 1 rmalgat
        if (response.getValue().size() == 0)
116 1 rmalgat
        {
117 1 rmalgat
            helper::vector<std::string> listResponse(1,responseT);
118 1 rmalgat
119 1 rmalgat
            sofa::helper::OptionsGroup responseOptions(listResponse);
120 1 rmalgat
            response.setValue(responseOptions);
121 1 rmalgat
        }
122 1 rmalgat
        else
123 1 rmalgat
        {
124 1 rmalgat
            sofa::helper::OptionsGroup* options = response.beginEdit();
125 1 rmalgat
126 1 rmalgat
            options->setSelectedItem(responseT);
127 1 rmalgat
            response.endEdit();
128 1 rmalgat
        }
129 1 rmalgat
    }
130 1 rmalgat
131 1 rmalgat
    std::string getDefaultResponseType() const { return response.getValue().getSelectedItem(); }
132 1 rmalgat
133 1 rmalgat
protected:
134 1 rmalgat
    static sofa::helper::OptionsGroup initializeResponseOptions(core::collision::Pipeline *pipeline);
135 1 rmalgat
136 1 rmalgat
    std::map<Instance,ContactMap> storedContactMap;
137 1 rmalgat
138 1 rmalgat
    virtual void changeInstance(Instance inst)
139 1 rmalgat
    {
140 1 rmalgat
        core::collision::ContactManager::changeInstance(inst);
141 1 rmalgat
        storedContactMap[instance].swap(contactMap);
142 1 rmalgat
        contactMap.swap(storedContactMap[inst]);
143 1 rmalgat
    }
144 1 rmalgat
145 1 rmalgat
    // count failure messages, so we don't continuously repeat them
146 1 rmalgat
    std::map<std::pair<std::string,std::pair<std::string,std::string> >, int> errorMsgCount;
147 1 rmalgat
};
148 1 rmalgat
149 1 rmalgat
} // namespace collision
150 1 rmalgat
151 1 rmalgat
} // namespace component
152 1 rmalgat
153 1 rmalgat
} // namespace sofa
154 1 rmalgat
155 1 rmalgat
#endif