00001 /****************************************************************************** 00002 * SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3 * 00003 * (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS * 00004 * * 00005 * This library is free software; you can redistribute it and/or modify it * 00006 * under the terms of the GNU Lesser General Public License as published by * 00007 * the Free Software Foundation; either version 2.1 of the License, or (at * 00008 * your option) any later version. * 00009 * * 00010 * This library is distributed in the hope that it will be useful, but WITHOUT * 00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * 00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * 00013 * for more details. * 00014 * * 00015 * You should have received a copy of the GNU Lesser General Public License * 00016 * along with this library; if not, write to the Free Software Foundation, * 00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 00018 ******************************************************************************* 00019 * SOFA :: Modules * 00020 * * 00021 * Authors: The SOFA Team and external contributors (see Authors.txt) * 00022 * * 00023 * Contact information: contact@sofa-framework.org * 00024 ******************************************************************************/ 00025 #include <sofa/simulation/common/PipelineImpl.h> 00026 #include <sofa/core/ObjectFactory.h> 00027 #include <sofa/simulation/common/Node.h> 00028 namespace sofa 00029 { 00030 00031 namespace simulation 00032 { 00033 00034 00035 using namespace sofa::core; 00036 using namespace sofa::core::objectmodel; 00037 using namespace sofa::core::componentmodel::behavior; 00038 using namespace sofa::core::componentmodel::collision; 00039 00040 PipelineImpl::PipelineImpl() 00041 { 00042 } 00043 00044 PipelineImpl::~PipelineImpl() 00045 { 00046 } 00047 00048 void PipelineImpl::init() 00049 { 00050 simulation::Node* root = dynamic_cast<simulation::Node*>(getContext()); 00051 if(root == NULL) return; 00052 intersectionMethods.clear(); 00053 root->getTreeObjects<Intersection>(&intersectionMethods); 00054 intersectionMethod = (intersectionMethods.empty() ? NULL : intersectionMethods[0]); 00055 broadPhaseDetections.clear(); 00056 root->getTreeObjects<BroadPhaseDetection>(&broadPhaseDetections); 00057 broadPhaseDetection = (broadPhaseDetections.empty() ? NULL : broadPhaseDetections[0]); 00058 narrowPhaseDetections.clear(); 00059 root->getTreeObjects<NarrowPhaseDetection>(&narrowPhaseDetections); 00060 narrowPhaseDetection = (narrowPhaseDetections.empty() ? NULL : narrowPhaseDetections[0]); 00061 contactManagers.clear(); 00062 root->getTreeObjects<ContactManager>(&contactManagers); 00063 contactManager = (contactManagers.empty() ? NULL : contactManagers[0]); 00064 groupManagers.clear(); 00065 root->getTreeObjects<CollisionGroupManager>(&groupManagers); 00066 groupManager = (groupManagers.empty() ? NULL : groupManagers[0]); 00067 00068 if (intersectionMethod==NULL) 00069 { 00070 std::cerr << "WARNING(Pipeline): no intersectionMethod defined. Using DiscreteIntersection.\n"; 00071 sofa::core::objectmodel::BaseObjectDescription discreteIntersectionDesc("Default Intersection","DiscreteIntersection"); 00072 intersectionMethod = dynamic_cast<Intersection*>(sofa::core::ObjectFactory::CreateObject(getContext(), &discreteIntersectionDesc)); 00073 //intersectionMethod = new sofa::component::collision::DiscreteIntersection; 00074 } 00075 } 00076 00077 void PipelineImpl::reset() 00078 { 00079 computeCollisionReset(); 00080 } 00081 00082 void PipelineImpl::computeCollisionReset() 00083 { 00084 simulation::Node* root = dynamic_cast<simulation::Node*>(getContext()); 00085 if(root == NULL) return; 00086 if (broadPhaseDetection!=NULL && broadPhaseDetection->getIntersectionMethod()!=intersectionMethod) 00087 broadPhaseDetection->setIntersectionMethod(intersectionMethod); 00088 if (narrowPhaseDetection!=NULL && narrowPhaseDetection->getIntersectionMethod()!=intersectionMethod) 00089 narrowPhaseDetection->setIntersectionMethod(intersectionMethod); 00090 if (contactManager!=NULL && contactManager->getIntersectionMethod()!=intersectionMethod) 00091 contactManager->setIntersectionMethod(intersectionMethod); 00092 doCollisionReset(); 00093 } 00094 00095 void PipelineImpl::computeCollisionDetection() 00096 { 00097 simulation::Node* root = dynamic_cast<simulation::Node*>(getContext()); 00098 if(root == NULL) return; 00099 std::vector<CollisionModel*> collisionModels; 00100 root->getTreeObjects<CollisionModel>(&collisionModels); 00101 doCollisionDetection(collisionModels); 00102 } 00103 00104 void PipelineImpl::computeCollisionResponse() 00105 { 00106 simulation::Node* root = dynamic_cast<simulation::Node*>(getContext()); 00107 if(root == NULL) return; 00108 doCollisionResponse(); 00109 } 00110 00111 } // namespace simulation 00112 00113 } // namespace sofa
1.5.7.1