00001 #ifndef JOINT_H
00002 #define JOINT_H
00003
00004 #include <iostream>
00005 #include <string>
00006 #include <vector>
00007 #include <stdlib.h>
00008 #include <stdio.h>
00009
00010 #include "Point.h"
00011 #include "DH_Link.h"
00012
00013 template <class DataType, int dim>
00014 class DH_Link;
00015
00016 template <class DataType, int dim>
00017 class DH_Chain;
00018
00019 template <class DataType, int dim>
00020 class SceneBase;
00021
00022 template <class DataType, int dim>
00023 class Scene;
00024
00030 template <class DataType, int dim>
00031 class Joint {
00032 public:
00033 friend class DH_Link<DataType,dim>;
00034 friend class DH_Chain<DataType,dim>;
00035 friend class SceneBase<DataType,dim>;
00036 friend class Scene<DataType,dim>;
00037 enum actuationType { revolute, prismatic, sphericalWrist };
00038
00039
00040 Joint() {
00041 setDefault();
00042 }
00043
00044 Joint( const Joint& v) {
00045 CFidTag = v.CFidTag;
00046 origin = v.origin;
00047 xaxis = v.xaxis;
00048 yaxis = v.yaxis;
00049 zaxis = v.zaxis;
00050 type = v.type;
00051 connectionId = v.connectionId;
00052 connectionOrientation = v.connectionOrientation;
00053 }
00054
00055 Joint( PType o, PType z, PType x, int t ) {
00056 setDefault();
00057 origin = o;
00058 zaxis = normalize(z);
00059 xaxis = normalize(x);
00060 yaxis = cross3D(zaxis,xaxis);
00061 yaxis = normalize(yaxis);
00062 type = t;
00063 #ifdef JOINT_DEBUG_ON
00064 ( mklog() << "joint := origin " << origin << " zaxis " << zaxis << " xaxis " << xaxis
00065 << " yaxis " << yaxis << " type " << type << std::endl ).flush();
00066 #endif
00067 }
00068
00069 Joint( PType o, PType z, PType x, int t, std::vector<int> cf ) {
00070
00071 setDefault();
00072 origin = o;
00073 zaxis = normalize(z);
00074 xaxis = normalize(x);
00075 yaxis = cross3D(zaxis,xaxis);
00076 yaxis = normalize(yaxis);
00077 type = t;
00078 #ifdef JOINT_DEBUG_ON
00079 ( mklog() << "joint := origin " << origin << " zaxis " << zaxis << " xaxis " << xaxis
00080 << " yaxis " << yaxis << " type " << type << std::endl ).flush();
00081 #endif
00082 CFidTag = cf;
00083 }
00084
00085
00086 ~Joint() {}
00087
00088 void setDefault() {
00089 id = -1;
00090 CFidTag.clear();
00091 origin(0) = 1; origin(1) = 0.; origin(2) = 0.;
00092 xaxis(0) = 1; xaxis(1) = 0.; xaxis(2) = 0.;
00093 yaxis(0) = 0; yaxis(1) = 1.; yaxis(2) = 0.;
00094 zaxis(0) = 0; zaxis(1) = 0.; zaxis(2) = 1.;
00095
00096 type = -1;
00097 connectionId = -1;
00098 connectionOrientation = -1;
00099 }
00100
00101 virtual std::vector<int>& CFIdTag() { return CFidTag; }
00102
00103 void setId(int v) { id = v; }
00104
00105 virtual void Restart(std::ifstream& ifs, int& pos, double& t, double& dt) {
00106 ifs.seekg(pos);
00107 #ifdef CHECKRESTART_DEBUG_ON
00108 ( mklog() << "\nREstarting Joint\n" ).flush();
00109 #endif
00110
00111 ifs.read((char*)&origin(0),sizeof(DataType));
00112 ifs.read((char*)&origin(1),sizeof(DataType));
00113 ifs.read((char*)&origin(2),sizeof(DataType));
00114 ifs.read((char*)&xaxis(0),sizeof(DataType));
00115 ifs.read((char*)&xaxis(1),sizeof(DataType));
00116 ifs.read((char*)&xaxis(2),sizeof(DataType));
00117 ifs.read((char*)&yaxis(0),sizeof(DataType));
00118 ifs.read((char*)&yaxis(1),sizeof(DataType));
00119 ifs.read((char*)&yaxis(2),sizeof(DataType));
00120 ifs.read((char*)&zaxis(0),sizeof(DataType));
00121 ifs.read((char*)&zaxis(1),sizeof(DataType));
00122 ifs.read((char*)&zaxis(2),sizeof(DataType));
00123 ifs.read((char*)&type,sizeof(int));
00124 ifs.read((char*)&connectionId,sizeof(int));
00125 ifs.read((char*)&connectionOrientation,sizeof(int));
00126 #ifdef CHECKRESTART_DEBUG_ON
00127 ( mklog() << " origin " << origin << " xaxis " << xaxis << " yaxis " << yaxis
00128 << " zaxis " << zaxis << " type " << type << " connectionId " << connectionId
00129 << " connectionOrientaiton " << connectionOrientation << std::endl ).flush();
00130 #endif
00131 pos = ifs.tellg();
00132 }
00133
00134 virtual void Checkpointing(std::ofstream& ofs) {
00135 #ifdef CHECKRESTART_DEBUG_ON
00136 ( mklog() << "\nCHECKPOINTING Joint " << id << std::endl ).flush();
00137 #endif
00138 ofs.write((char*)&origin(0),sizeof(DataType));
00139 ofs.write((char*)&origin(1),sizeof(DataType));
00140 ofs.write((char*)&origin(2),sizeof(DataType));
00141 ofs.write((char*)&xaxis(0),sizeof(DataType));
00142 ofs.write((char*)&xaxis(1),sizeof(DataType));
00143 ofs.write((char*)&xaxis(2),sizeof(DataType));
00144 ofs.write((char*)&yaxis(0),sizeof(DataType));
00145 ofs.write((char*)&yaxis(1),sizeof(DataType));
00146 ofs.write((char*)&yaxis(2),sizeof(DataType));
00147 ofs.write((char*)&zaxis(0),sizeof(DataType));
00148 ofs.write((char*)&zaxis(1),sizeof(DataType));
00149 ofs.write((char*)&zaxis(2),sizeof(DataType));
00150 ofs.write((char*)&type,sizeof(int));
00151 ofs.write((char*)&connectionId,sizeof(int));
00152 ofs.write((char*)&connectionOrientation,sizeof(int));
00153 #ifdef CHECKRESTART_DEBUG_ON
00154 ( mklog() << " origin " << origin << " xaxis " << xaxis << " yaxis " << yaxis
00155 << " zaxis " << zaxis << " type " << type << " connectionId " << connectionId
00156 << " connectionOrientaiton " << connectionOrientation << std::endl ).flush();
00157 #endif
00158 }
00159
00160 virtual PType getOrigin() { return origin; }
00161
00162 virtual void setOrigin(PType& o) {
00163 ( mklog() << " Changing joint origin to " << o ).flush();
00164 origin = o;
00165 ( mklog() << " origin = " << origin << std::endl ).flush();
00166 }
00167
00168 protected:
00169 int id;
00170 std::vector<int> CFidTag;
00175 PType origin, xaxis, yaxis, zaxis;
00176 int type, connectionId, connectionOrientation;
00177 int CFidTag_size;
00178 };
00179
00180 #endif // JOINT_H