00001 00002 /****************************************************************************** 00003 * SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3 * 00004 * (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS * 00005 * * 00006 * This library is free software; you can redistribute it and/or modify it * 00007 * under the terms of the GNU Lesser General Public License as published by * 00008 * the Free Software Foundation; either version 2.1 of the License, or (at * 00009 * your option) any later version. * 00010 * * 00011 * This library is distributed in the hope that it will be useful, but WITHOUT * 00012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * 00013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * 00014 * for more details. * 00015 * * 00016 * You should have received a copy of the GNU Lesser General Public License * 00017 * along with this library; if not, write to the Free Software Foundation, * 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 00019 ******************************************************************************* 00020 * SOFA :: Modules * 00021 * * 00022 * Authors: The SOFA Team and external contributors (see Authors.txt) * 00023 * * 00024 * Contact information: contact@sofa-framework.org * 00025 ******************************************************************************/ 00026 00027 #ifndef SOFA_COMPONENT_MISC_COMPARESTATE_H 00028 #define SOFA_COMPONENT_MISC_COMPARESTATE_H 00029 00030 #include <sofa/component/misc/ReadState.h> 00031 #include <sofa/simulation/common/Visitor.h> 00032 00033 #include <fstream> 00034 00035 00036 namespace sofa 00037 { 00038 00039 namespace component 00040 { 00041 00042 namespace misc 00043 { 00044 00047 class CompareState: public ReadState 00048 { 00049 public: 00050 00053 CompareState(); 00054 00055 void handleEvent(sofa::core::objectmodel::Event* event); 00056 00058 void processCompareState(); 00059 00062 template<class T> 00063 static bool canCreate(T*& obj, core::objectmodel::BaseContext* context, core::objectmodel::BaseObjectDescription* arg) 00064 { 00065 if (dynamic_cast<core::componentmodel::behavior::BaseMechanicalState*>(context->getMechanicalState()) == NULL) 00066 return false; 00067 return BaseObject::canCreate(obj, context, arg); 00068 } 00069 00071 double getError(){return totalError_X + totalError_V;} 00072 00073 protected : 00074 00076 double totalError_X; 00078 double totalError_V; 00079 }; 00080 00082 class CompareStateCreator: public Visitor 00083 { 00084 public: 00085 CompareStateCreator() : sceneName(""), counterCompareState(0), createInMapping(false) {} 00086 CompareStateCreator(std::string &n, bool i=true, int c=0 ) { sceneName=n;init=i; counterCompareState=c; } 00087 virtual Result processNodeTopDown( simulation::Node* ); 00088 00089 void setSceneName(std::string &n) { sceneName = n; } 00090 void setCounter(int c) { counterCompareState = c; } 00091 void setCreateInMapping(bool b) { createInMapping=b; } 00092 00093 protected: 00094 void addCompareState(sofa::core::componentmodel::behavior::BaseMechanicalState *ms, simulation::Node* gnode); 00095 bool init; 00096 std::string sceneName; 00097 int counterCompareState; //avoid to have two same files if two mechanical objects has the same name 00098 bool createInMapping; 00099 }; 00100 00101 class CompareStateResult: public Visitor 00102 { 00103 public: 00104 CompareStateResult() { error=0; } 00105 virtual Result processNodeTopDown( simulation::Node* ); 00106 00107 double getError() { return error; } 00108 protected: 00109 double error; 00110 }; 00111 00112 } // namespace misc 00113 00114 } // namespace component 00115 00116 } // namespace sofa 00117 00118 #endif
1.5.7.1