Biomechanical Joint Model
 Author: Anderson Maciel

comemovement.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2001 by Anderson Maciel                                 *
00003  *   andi.maciel@gmail.com                                                 *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  **************************************************************************/
00020 
00022 //
00023 //  PROJECT.....: 
00024 //  RESPONSIBLE.: 
00025 //
00026 //  FILE........: vpmovment.cpp
00027 //  DESCRIPTION.: Contain the COME_Movement class definitions.
00028 //
00029 //  AUTHOR......: Anderson Maciel
00030 //  DATE........: June/06/2001
00031 //  DESCRIPTION.: Methods definition.
00032 //
00034 #include        <algebra/comevector3d.h>
00035 #include        <kinematics/comemovement.h>
00036 #include        <general/comexml.h>
00037 #include        <stdio.h>
00038 #include <xercesc/dom/DOM.hpp>
00039 #include <xercesc/util/PlatformUtils.hpp>
00040 
00041 
00042 COME_Movement::COME_Movement(){
00043 
00044   bodyName = "";
00045   cycle = false;
00046   deltaT = 0;
00047   time = INIT_TIME;
00048   time_err = 0;
00049 }
00050 
00051 COME_Movement::COME_Movement( string bn, bool cy, double dt, double te ){
00052   bodyName = bn;
00053   cycle = cy;
00054   deltaT = dt;
00055   time = INIT_TIME;
00056   time_err = te;
00057 }
00058 
00059 
00060 COME_Movement::~COME_Movement(){
00061 }
00062 
00063 double
00064 COME_Movement::getDeltaT(){
00065   return deltaT;
00066 }
00067 
00068 bool
00069 COME_Movement::getCycle(){
00070   return cycle;
00071 }
00072 
00073 double
00074 COME_Movement::getTime(){
00075   return time;
00076 }
00077 
00078 double
00079 COME_Movement::getTimeFinal(){
00080   return tFinal;
00081 }
00082 
00083 double
00084 COME_Movement::getTime_Err(){
00085   return time_err;
00086 }
00087 
00088 int
00089 COME_Movement::getQtdMotion(){
00090   return qtdMotion;
00091 }
00092 
00093 COME_JointMotion *
00094 COME_Movement::getTimeline(){
00095   return motionTimeline;
00096 }
00097 
00098 void
00099 COME_Movement::setTimeLine( COME_JointMotion * newTL ){
00100   motionTimeline = newTL;
00101 }
00102 
00103 void
00104 COME_Movement::setDeltaT( double dt ){
00105   deltaT = dt;
00106 }
00107 
00108 void
00109 COME_Movement::setCycle( bool c ){
00110   cycle = c;
00111 }
00112 
00113 void
00114 COME_Movement::setTime( double t ){
00115   time = t;
00116 }
00117 
00118 void
00119 COME_Movement::setTimeFinal( double tf ){
00120   tFinal = tf;
00121 }
00122 
00123 void
00124 COME_Movement::setTime_Err( double te ){
00125   time_err = te;
00126 }
00127 
00128 void
00129 COME_Movement::setQtdMotion( int qm ){
00130   qtdMotion = qm;
00131 }
00132 
00133 void
00134 COME_Movement::vpLoadMotionFile( const char *fileName ){
00135 
00136 
00137     // Initialize the XML4C system
00138     try
00139     {
00140         XMLPlatformUtils::Initialize();
00141     }
00142 
00143     catch (const XMLException& toCatch)
00144     {
00145          printf( "Error during initialization! : %s\n", toCatch.getMessage() );
00146          return;
00147     }
00148 
00149     XercesDOMParser::ValSchemes    valScheme = XercesDOMParser::Val_Auto; //Val_Never Val_Always
00150     bool                     doNamespaces    = false;
00151 
00152     // Instantiate the DOM parser.
00153     XercesDOMParser parser;
00154     parser.setValidationScheme(valScheme);
00155     parser.setDoNamespaces(doNamespaces);
00156 
00157     // And create our error handler and install it
00158     DOMCountErrorHandler errorHandler;
00159     parser.setErrorHandler(&errorHandler);
00160 
00161     //
00162     //  Get the starting time and kick off the parse of the indicated
00163     //  file. Catch any exceptions that might propogate out of it.
00164     //
00165     unsigned long duration;
00166     try
00167     {
00168         const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
00169         parser.parse( fileName );
00170         const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
00171         duration = endMillis - startMillis;
00172     }
00173 
00174     catch (const XMLException& toCatch)
00175     {
00176         printf( "\nError during parsing: '%s'\n Exception message is: %s \n", fileName, StrX(toCatch.getMessage()).localForm() );
00177         return;
00178     }
00179     catch (const DOMException& toCatch)
00180     {
00181                 printf( "\nError during parsing: '%s'\n Exception message is: %s \n", fileName, toCatch.msg );
00182         XMLPlatformUtils::Terminate();
00183         return;
00184     }
00185     catch (...)
00186     {
00187        cerr << "\nUnexpected exception during parsing: '" << fileName << "'\n";
00188         XMLPlatformUtils::Terminate();
00189         return;
00190     }
00191 
00192     //
00193     //  Extract the DOM tree, get the list of all the elements and report the
00194     //  length as the count of elements.
00195     //
00196     if (errorHandler.getSawErrors())
00197     {
00198         cout << "\nErrors occured, no output available\n" << endl;
00199     }
00200      else
00201     {
00202         DOMDocument *doc = parser.getDocument();
00203         unsigned int elementCount = doc->getElementsByTagName(XMLString::transcode("*"))->getLength();
00204                         
00205         DOMElement *root = doc->getDocumentElement();
00206                                         
00208         DOMNodeList *move = root->getElementsByTagName(XMLString::transcode("simulation"));
00209 
00210         for( int i = 0; i < 1/*move.getLength()*/; i++ ){ // specific for ONLY ONE Body
00211                 DOMNamedNodeMap *attrmove = move->item(i)->getAttributes();
00212                 bodyName = XMLString::transcode( attrmove->getNamedItem( XMLString::transcode("fps") )->getNodeValue() );
00213                 if( !XMLString::compareString( attrmove->getNamedItem( XMLString::transcode("cycle") )->getNodeValue(), XMLString::transcode( "on" ) ) ){
00214                         cycle = true;
00215                 } else {
00216                         cycle = false;
00217                 }
00218                 //deltaT = atof( XMLString::transcode( attrmove->getNamedItem( XMLString::transcode("duration") )->getNodeValue() ) );
00219                 //time_err = 0.001;//atof( XMLString::transcode( attrmove->getNamedItem( XMLString::transcode("time_err") )->getNodeValue()) );
00220                 tFinal = 0.0;
00221                 DOMNodeList *motion = move->item(i)->getChildNodes();
00222                 int numMotion = 0;
00223                 for( int j = 0; j < motion->getLength(); j++ ){
00224                         if( !XMLString::compareString( motion->item(j)->getNodeName(), XMLString::transcode("motion" ) ) ) numMotion++;
00225                 }
00226                 motionTimeline = new COME_JointMotion [ numMotion ];
00227                 qtdMotion = 0;
00228                 for( int k = 0; k < motion->getLength(); k++ ){
00229 
00230                         if( !XMLString::compareString( motion->item(k)->getNodeName(), XMLString::transcode( "motion" ) ) ){
00231 
00232                                 DOMNamedNodeMap *attrmotion = motion->item(k)->getAttributes();
00233                                 string jointName = XMLString::transcode( attrmotion->getNamedItem( XMLString::transcode("joint_name") )->getNodeValue() );
00234                                 float t0 = atof( XMLString::transcode( attrmotion->getNamedItem( XMLString::transcode("t0") )->getNodeValue() ) );
00235                                 float tf = atof( XMLString::transcode( attrmotion->getNamedItem( XMLString::transcode("tf") )->getNodeValue() ) );
00236                                 float parameter = atof( XMLString::transcode( attrmotion->getNamedItem( XMLString::transcode("parameter") )->getNodeValue() ) );
00237                                 int motionType = FLEX;
00238                                 if( !XMLString::compareString( attrmotion->getNamedItem( XMLString::transcode("type") )->getNodeValue(), XMLString::transcode( "ADDUCT" ) ) ){
00239                                         motionType = ADDUCT;
00240                                 } else if( !XMLString::compareString( attrmotion->getNamedItem( XMLString::transcode("type") )->getNodeValue(), XMLString::transcode( "TWIST" ) ) ){
00241                                         motionType = TWIST;
00242                                 }
00243 
00244                                 motionTimeline[qtdMotion++] = *( new COME_JointMotion( jointName, motionType, t0, tf, parameter ) );
00245                                 if( tf > tFinal ) tFinal = tf;
00246                         }
00247                 }
00248         }
00249                                 
00250         // Print out the stats that we collected and time taken.
00251         cout << fileName << ": " << duration << " ms (" << elementCount << " elems)." << endl;
00252     }
00253     return;
00254 }
00255 

Generated on Thu Dec 1 10:13:35 2005 for COME - Biomechanical Joint Model by  doxygen 1.4.5