00001 //###################################################################### 00002 // 00003 // GraspIt! 00004 // Copyright (C) 2002-2009 Columbia University in the City of New York. 00005 // All rights reserved. 00006 // 00007 // GraspIt! is free software: you can redistribute it and/or modify 00008 // it under the terms of the GNU General Public License as published by 00009 // the Free Software Foundation, either version 3 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // GraspIt! is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with GraspIt!. If not, see <http://www.gnu.org/licenses/>. 00019 // 00020 // Author(s): Matei T. Ciocarlie 00021 // 00022 // $Id: eigenGrasp.h,v 1.14 2009/04/21 14:53:07 cmatei Exp $ 00023 // 00024 //###################################################################### 00025 #ifndef _eigengrasp_h_ 00026 #define _eigengrasp_h_ 00027 00028 #include <assert.h> 00029 00030 #include <vector> 00031 #include <QString> 00032 #include <QTextStream> 00033 00041 #define EIGENGRASP_LOOSE 00042 00043 class TiXmlElement; 00044 class Matrix; 00045 class Robot; 00046 class QTextStream; 00048 00057 class EigenGrasp 00058 { 00059 private: 00061 int mSize; 00063 double *mVals; 00065 double mEigenValue; 00066 00067 public: 00069 double mMin; 00071 double mMax; 00073 bool mPredefinedLimits; 00075 bool mFixed; 00077 double fixedAmplitude; 00078 00080 EigenGrasp(int size, double e=0); 00082 EigenGrasp(const EigenGrasp *orig); 00083 ~EigenGrasp(); 00084 00085 int getSize() const {return mSize;} 00086 00088 void getEigenGrasp (double *eg) const; 00090 void setEigenGrasp(const double *eg); 00091 00093 double getEigenValue() const {return mEigenValue;} 00095 void setEigenValue(double e){mEigenValue = e;} 00096 00098 void setOnes(){for (int i=0; i<mSize; i++) mVals[i]=1.0;} 00099 00101 double getAxisValue(int i) const {assert(i<mSize&&i>=0); return mVals[i];} 00103 void setAxisValue(int i, double val){assert(i<mSize&&i>=0); mVals[i]=val;} 00104 00106 double normalize(); 00107 00109 double dot(double *d); 00110 00111 void writeToFile(FILE *fp); 00112 void writeToFile(TiXmlElement *ep); 00113 void readFromFile(FILE *fp); 00114 00115 int readFromStream(QTextStream *stream); 00116 int readFromXml(const TiXmlElement *element); 00117 00119 void fix(double a){mFixed = true; fixedAmplitude = a;} 00121 void unfix(){mFixed = false;} 00122 }; 00123 00134 class EigenGraspInterface 00135 { 00136 private: 00138 Robot *mRobot; 00140 int dSize; 00142 int eSize; 00143 00145 std::vector<EigenGrasp*> mGrasps; 00147 EigenGrasp *mOrigin; 00148 00150 00152 EigenGrasp *mNorm; 00153 00155 QString mName; 00156 00158 Matrix *mP; 00160 Matrix *mPInv; 00161 00163 00166 mutable bool mRigid; 00167 00168 void clear(); 00169 00171 void computeProjectionMatrices(); 00172 00174 void toDOFSpace(const double *amp, double *dof, const double *origin) const; 00176 void toEigenSpace(double *amp, const double *dof, const double *origin) const; 00177 public: 00178 EigenGraspInterface(Robot *r); 00179 EigenGraspInterface(const EigenGraspInterface *orig); 00180 ~EigenGraspInterface(); 00181 00183 const EigenGrasp* getGrasp(int g) const {return mGrasps[g];} 00185 int getSize() const {return (int)mGrasps.size();} 00186 00188 bool isRigid() const {return mRigid;} 00190 00193 void setRigid(bool r) const {mRigid = r;} 00194 00196 int writeToFile(const char *filename); 00198 int readFromFile(QString filename); 00200 int setTrivial(); 00201 00203 void setName(QString n){mName = n;} 00205 const QString getName() const {return mName;} 00206 00208 void setOrigin(const double *dof); 00210 void setSimpleOrigin(); 00211 00213 void setMinMax(); 00215 void checkOrigin(); 00216 00218 00222 void fixEigenGrasp(int i, double fa){mGrasps[i]->fix(fa);} 00224 void unfixEigenGrasp(int i){mGrasps[i]->unfix();} 00225 00226 // These are the main functions that interface the EG: 00227 00229 void getDOF (const double *amp, double *dof) const; 00231 void getAmp(double *amp, const double *dof) const; 00232 }; 00233 00234 #endif