BarycentricContactMapper.inl
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef SOFA_COMPONENT_COLLISION_BARYCENTRICCONTACTMAPPER_INL
00026 #define SOFA_COMPONENT_COLLISION_BARYCENTRICCONTACTMAPPER_INL
00027
00028 #include <sofa/component/collision/BarycentricContactMapper.h>
00029 #include <sofa/simulation/tree/GNode.h>
00030 #include <sofa/simulation/tree/Simulation.h>
00031 #include <iostream>
00032
00033 namespace sofa
00034 {
00035
00036 namespace component
00037 {
00038
00039 namespace collision
00040 {
00041
00042 template < class TCollisionModel, class DataTypes >
00043 void BarycentricContactMapper<TCollisionModel,DataTypes>::cleanup()
00044 {
00045 if (mapping!=NULL)
00046 {
00047 simulation::tree::GNode* parent = dynamic_cast<simulation::tree::GNode*>(model->getContext());
00048 if (parent!=NULL)
00049 {
00050 simulation::tree::GNode* child = dynamic_cast<simulation::tree::GNode*>(mapping->getContext());
00051 child->removeObject(mapping->getTo());
00052 child->removeObject(mapping);
00053 parent->removeChild(child);
00054 delete mapping->getTo();
00055 delete mapping;
00056 delete child;
00057 mapping = NULL;
00058 }
00059 }
00060 }
00061
00062 template < class TCollisionModel, class DataTypes >
00063 typename BarycentricContactMapper<TCollisionModel,DataTypes>::MMechanicalState* BarycentricContactMapper<TCollisionModel,DataTypes>::createMapping(const char* name)
00064 {
00065 if (model==NULL) return NULL;
00066 simulation::tree::GNode* parent = dynamic_cast<simulation::tree::GNode*>(model->getContext());
00067 if (parent==NULL)
00068 {
00069 std::cerr << "ERROR: BarycentricContactMapper only works for scenegraph scenes.\n";
00070 return NULL;
00071 }
00072 simulation::tree::GNode* child = new simulation::tree::GNode(name); parent->addChild(child); child->updateSimulationContext();
00073 MMechanicalState* mstate = new MMechanicalObject; child->addObject(mstate);
00074
00075
00076 mapper = new mapping::BarycentricMapperMeshTopology<InDataTypes, typename BarycentricContactMapper::DataTypes>(model->getMeshTopology());
00077 mapping = new MMapping(model->getMechanicalState(), mstate, mapper);
00078 child->addObject(mapping);
00079 return mstate;
00080 }
00081
00082 template < class TCollisionModel, class DataTypes >
00083 void IdentityContactMapper<TCollisionModel,DataTypes>::cleanup()
00084 {
00085 if (mapping!=NULL)
00086 {
00087 simulation::tree::GNode* parent = dynamic_cast<simulation::tree::GNode*>(model->getContext());
00088 if (parent!=NULL)
00089 {
00090 simulation::tree::GNode* child = dynamic_cast<simulation::tree::GNode*>(mapping->getContext());
00091 child->removeObject(mapping->getTo());
00092 child->removeObject(mapping);
00093 parent->removeChild(child);
00094 delete mapping->getTo();
00095 delete mapping;
00096 delete child;
00097 mapping = NULL;
00098 }
00099 }
00100 }
00101 template < class TCollisionModel, class DataTypes >
00102 typename IdentityContactMapper<TCollisionModel,DataTypes>::MMechanicalState* IdentityContactMapper<TCollisionModel,DataTypes>::createMapping(const char* name)
00103 {
00104 if (model==NULL) return NULL;
00105 simulation::tree::GNode* parent = dynamic_cast<simulation::tree::GNode*>(model->getContext());
00106 if (parent==NULL)
00107 {
00108 std::cerr << "ERROR: IdentityContactMapper only works for scenegraph scenes.\n";
00109 return NULL;
00110 }
00111 simulation::tree::GNode* child = new simulation::tree::GNode(name); parent->addChild(child); child->updateSimulationContext();
00112 MMechanicalState* mstate = new MMechanicalObject; child->addObject(mstate);
00113 mapping = new MMapping(model->getMechanicalState(), mstate); child->addObject(mapping);
00114 return mstate;
00115 }
00116
00117 template < class TCollisionModel, class DataTypes >
00118 void RigidContactMapper<TCollisionModel,DataTypes>::cleanup()
00119 {
00120 if (child!=NULL)
00121 {
00122 simulation::tree::getSimulation()->unload(child);
00123 child = NULL;
00124 }
00125 }
00126
00127 template < class TCollisionModel, class DataTypes >
00128 typename RigidContactMapper<TCollisionModel,DataTypes>::MMechanicalState* RigidContactMapper<TCollisionModel,DataTypes>::createMapping(const char* name)
00129 {
00130 if (model==NULL) return NULL;
00131 InMechanicalState* instate = model->getMechanicalState();
00132 if (instate!=NULL)
00133 {
00134 simulation::tree::GNode* parent = dynamic_cast<simulation::tree::GNode*>(instate->getContext());
00135 if (parent==NULL)
00136 {
00137 std::cerr << "ERROR: RigidContactMapper only works for scenegraph scenes.\n";
00138 return NULL;
00139 }
00140 child = new simulation::tree::GNode(name); parent->addChild(child); child->updateSimulationContext();
00141 outmodel = new MMechanicalObject; child->addObject(outmodel);
00142 mapping = new MMapping(instate, outmodel); child->addObject(mapping);
00143 }
00144 else
00145 {
00146 simulation::tree::GNode* parent = dynamic_cast<simulation::tree::GNode*>(model->getContext());
00147 if (parent==NULL)
00148 {
00149 std::cerr << "ERROR: RigidContactMapper only works for scenegraph scenes.\n";
00150 return NULL;
00151 }
00152 child = new simulation::tree::GNode(name); parent->addChild(child); child->updateSimulationContext();
00153 outmodel = new MMechanicalObject; child->addObject(outmodel);
00154 mapping = NULL;
00155 }
00156 return outmodel;
00157 }
00158
00159 template < class TCollisionModel, class DataTypes >
00160 void SubsetContactMapper<TCollisionModel,DataTypes>::cleanup()
00161 {
00162 if (child!=NULL)
00163 {
00164 simulation::tree::getSimulation()->unload(child);
00165 child = NULL;
00166 }
00167 }
00168
00169 template < class TCollisionModel, class DataTypes >
00170 typename SubsetContactMapper<TCollisionModel,DataTypes>::MMechanicalState* SubsetContactMapper<TCollisionModel,DataTypes>::createMapping(const char* name)
00171 {
00172 if (model==NULL) return NULL;
00173 InMechanicalState* instate = model->getMechanicalState();
00174 if (instate!=NULL)
00175 {
00176 simulation::tree::GNode* parent = dynamic_cast<simulation::tree::GNode*>(instate->getContext());
00177 if (parent==NULL)
00178 {
00179 std::cerr << "ERROR: SubsetContactMapper only works for scenegraph scenes.\n";
00180 return NULL;
00181 }
00182 child = new simulation::tree::GNode(name); parent->addChild(child); child->updateSimulationContext();
00183 outmodel = new MMechanicalObject; child->addObject(outmodel);
00184 mapping = new MMapping(instate, outmodel); child->addObject(mapping);
00185 }
00186 else
00187 {
00188 simulation::tree::GNode* parent = dynamic_cast<simulation::tree::GNode*>(model->getContext());
00189 if (parent==NULL)
00190 {
00191 std::cerr << "ERROR: SubsetContactMapper only works for scenegraph scenes.\n";
00192 return NULL;
00193 }
00194 child = new simulation::tree::GNode(name); parent->addChild(child); child->updateSimulationContext();
00195 outmodel = new MMechanicalObject; child->addObject(outmodel);
00196 mapping = NULL;
00197 }
00198 return outmodel;
00199 }
00200
00201 template <class DataTypes>
00202 typename ContactMapper<RigidDistanceGridCollisionModel,DataTypes>::MMechanicalState* ContactMapper<RigidDistanceGridCollisionModel,DataTypes>::createMapping(const char* name)
00203 {
00204 MMechanicalState* outmodel = Inherit::createMapping(name);
00205 if (this->child!=NULL && this->mapping==NULL)
00206 {
00207
00208 sofa::component::visualmodel::DrawV* visu = new sofa::component::visualmodel::DrawV;
00209 this->child->addObject(visu);
00210 visu->useAlpha.setValue(true);
00211 visu->vscale.setValue(this->model->getContext()->getDt());
00212 sofa::component::mapping::IdentityMapping< core::Mapping< core::componentmodel::behavior::State<DataTypes>, core::componentmodel::behavior::MappedModel< ExtVectorTypes< Vec<3,GLfloat>, Vec<3,GLfloat> > > > >* map = new sofa::component::mapping::IdentityMapping< core::Mapping< core::componentmodel::behavior::State<DataTypes> , core::componentmodel::behavior::MappedModel< ExtVectorTypes< Vec<3,GLfloat>, Vec<3,GLfloat> > > > > ( outmodel, visu );
00213 this->child->addObject(map);
00214 visu->init();
00215 map->init();
00216 }
00217 return outmodel;
00218 }
00219
00220 }
00221
00222 }
00223
00224 }
00225
00226 #endif