AnimateVisitor.cpp

Go to the documentation of this file.
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/AnimateVisitor.h>
00026 #include <sofa/simulation/common/MechanicalVisitor.h>
00027 #include <sofa/simulation/common/CollisionVisitor.h>
00028 //#include "MechanicalIntegration.h"
00029 
00030 namespace sofa
00031 {
00032 
00033 namespace simulation
00034 {
00035 
00036 
00037 void AnimateVisitor::processMasterSolver(simulation::Node*, core::componentmodel::behavior::MasterSolver* obj)
00038 {
00039     obj->step(getDt());
00040 }
00041 
00042 void AnimateVisitor::processBehaviorModel(simulation::Node*, core::BehaviorModel* obj)
00043 {
00044     obj->updatePosition(getDt());
00045 }
00046 
00047 void AnimateVisitor::fwdInteractionForceField(simulation::Node*, core::componentmodel::behavior::InteractionForceField* obj)
00048 {
00049     obj->addForce();
00050 }
00051 
00052 void AnimateVisitor::processCollisionPipeline(simulation::Node* node, core::componentmodel::collision::Pipeline*)
00053 {
00054     CollisionVisitor act;
00055     node->execute(&act);
00056 }
00057 
00058 void AnimateVisitor::processOdeSolver(simulation::Node* /*node*/, core::componentmodel::behavior::OdeSolver* solver)
00059 {
00060 /*    MechanicalIntegrationVisitor act(getDt());
00061     node->execute(&act);*/
00062   cerr<<"AnimateVisitor::processOdeSolver "<<solver->getName()<<endl;
00063   solver->solve(getDt());
00064 }
00065 
00066 Visitor::Result AnimateVisitor::processNodeTopDown(simulation::Node* node)
00067 {
00068   //cerr<<"AnimateVisitor::process Node  "<<node->getName()<<endl;
00069   if (!node->is_activated.getValue()) return Visitor::RESULT_PRUNE;
00070     if (dt == 0) setDt(node->getDt());
00071 //  for_each(this, node, node->behaviorModel, &AnimateVisitor::processBehaviorModel);
00072     if (node->masterSolver != NULL)
00073     {
00074         ctime_t t0 = begin(node, node->masterSolver);
00075         processMasterSolver(node, node->masterSolver);
00076         end(node, node->masterSolver, t0);
00077         return RESULT_PRUNE;
00078     }
00079     if (node->collisionPipeline != NULL)
00080     {
00081         //ctime_t t0 = begin(node, node->collisionPipeline);
00082         processCollisionPipeline(node, node->collisionPipeline);
00083         //end(node, node->collisionPipeline, t0);
00084     }
00085 /*  if (node->solver != NULL)
00086     {
00087         ctime_t t0 = begin(node, node->solver);
00088         processOdeSolver(node, node->solver);
00089         end(node, node->solver, t0);
00090         return RESULT_PRUNE;
00091         }*/
00092         if (!node->solver.empty() )
00093         {
00094           double nextTime = node->getTime() + dt;
00095           MechanicalBeginIntegrationVisitor beginVisitor(dt);
00096           node->execute(&beginVisitor);
00097           
00098           
00099           for( unsigned i=0; i<node->solver.size(); i++ ){
00100             ctime_t t0 = begin(node, node->solver[i]);
00101             //cerr<<"AnimateVisitor::processNodeTpDown  solver  "<<node->solver[i]->getName()<<endl;
00102             node->solver[i]->solve(getDt());
00103             end(node, node->solver[i], t0);
00104           }
00105           
00106           MechanicalPropagatePositionAndVelocityVisitor(nextTime,core::componentmodel::behavior::OdeSolver::VecId::position(),core::componentmodel::behavior::OdeSolver::VecId::velocity()).execute( node );
00107           
00108           MechanicalEndIntegrationVisitor endVisitor(dt);
00109           node->execute(&endVisitor);
00110           return RESULT_PRUNE;
00111         }
00112     /*
00113     if (node->mechanicalModel != NULL)
00114     {
00115         std::cerr << "Graph Error: MechanicalState without solver." << std::endl;
00116         return RESULT_PRUNE;
00117     }
00118     */
00119     {
00120         // process InteractionForceFields
00121         for_each(this, node, node->interactionForceField, &AnimateVisitor::fwdInteractionForceField);
00122         return RESULT_CONTINUE;
00123     }
00124 }
00125 
00126 // void AnimateVisitor::processNodeBottomUp(simulation::Node* node)
00127 // {
00128 //     node->setTime( node->getTime() + node->getDt() );
00129 // }
00130 
00131 
00132 } // namespace simulation
00133 
00134 } // namespace sofa
00135 

Generated on Sun Nov 23 04:05:45 2008 for Sofa by  doxygen 1.5.7.1