00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "graspRecord.h"
00027 #include "gloveInterface.h"
00028
00029 GraspRecord::GraspRecord(int size)
00030 {
00031 mSize = size;
00032 mPose = new CalibrationPose(mSize);
00033
00034 mTran = transf::IDENTITY;
00035 mObjectName = mRobotName = QString("not_set");
00036 }
00037
00038 GraspRecord::~GraspRecord()
00039 {
00040 delete mPose;
00041 }
00042
00043 void GraspRecord::writeToFile(FILE *fp)
00044 {
00045
00046 fprintf(fp,"%s\n",mObjectName.latin1());
00047 fprintf(fp,"%s\n",mRobotName.latin1());
00048
00049 Quaternion q = mTran.rotation();
00050 fprintf(fp,"%f %f %f %f ",q.x, q.y, q.z, q.w);
00051 vec3 t = mTran.translation();
00052 fprintf(fp,"%f %f %f\n",t.x(), t.y(), t.z());
00053
00054 mPose->writeToFile(fp);
00055 }
00056
00057 void GraspRecord::readFromFile(FILE *fp)
00058 {
00059 float x,y,z,w;
00060
00061 char name[1000];
00062 do {
00063 fgets(name, 1000, fp);
00064 } while (name[0]=='\n' || name[0]=='\0' || name[0]==' ');
00065 mObjectName = QString(name);
00066 mObjectName = mObjectName.stripWhiteSpace();
00067 fprintf(stderr,"object: %s__\n",mObjectName.latin1());
00068 do {
00069 fgets(name, 1000, fp);
00070 } while (name[0]=='\n' || name[0]=='\0' || name[0]==' ');
00071 mRobotName = QString(name);
00072 mRobotName = mRobotName.stripWhiteSpace();
00073 fprintf(stderr,"robot: %s__\n",mRobotName.latin1());
00074
00075 fscanf(fp,"%f %f %f %f",&x, &y, &z, &w);
00076 Quaternion q(w, x, y, z);
00077 fscanf(fp,"%f %f %f",&x, &y, &z);
00078 vec3 t(x,y,z);
00079 mTran.set(q,t);
00080
00081 mPose->readFromFile(fp);
00082 mSize = mPose->getSize();
00083 }
00084
00085 void loadGraspListFromFile(std::vector<GraspRecord*> *list, const char *filename)
00086 {
00087 FILE *fp = fopen(filename, "r");
00088 if (fp==NULL) {
00089 fprintf(stderr,"Unable to open file %s for reading\n",filename);
00090 return;
00091 }
00092
00093 GraspRecord *newGrasp;
00094 int nGrasps;
00095 fscanf(fp,"%d",&nGrasps);
00096 for(int i=0; i<nGrasps; i++) {
00097 newGrasp = new GraspRecord(0);
00098 newGrasp->readFromFile(fp);
00099 list->push_back(newGrasp);
00100 }
00101
00102 fclose(fp);
00103 }
00104
00105 void writeGraspListToFile (std::vector<GraspRecord*> *list, const char *filename)
00106 {
00107 FILE *fp = fopen(filename, "w");
00108 if (fp==NULL) {
00109 fprintf(stderr,"Unable to open file %s for reading\n",filename);
00110 return;
00111 }
00112
00113 fprintf(fp,"%d\n",(int)list->size());
00114 for (int i=0; i<(int)list->size(); i++) {
00115 (*list)[i]->writeToFile(fp);
00116 }
00117
00118 fclose(fp);
00119 }