GCOP
1.0
|
00001 #ifndef GCOP_UUVVIEW_H 00002 #define GCOP_UUVVIEW_H 00003 00004 #include "uuv.h" 00005 #include "systemview.h" 00006 #include "GL/glut.h" 00007 #include <assert.h> 00008 #include <stdlib.h> 00009 #include <string.h> 00010 #include <iostream> 00011 //#include "viewer.h" 00012 #include "so3.h" 00013 00014 00015 namespace gcop { 00016 00017 #include "utils.h" 00018 00019 using namespace Eigen; 00020 00021 template <int c = 6> 00022 class UuvView : public SystemView<UuvState, Matrix<double, c, 1> > { 00023 00024 typedef Matrix<double, c, 1> Vectorcd; 00025 00026 public: 00027 00033 UuvView(const Uuv<c> &sys); 00034 00040 UuvView(const Uuv<c> &sys, 00041 vector<UuvState> *xs, 00042 vector<Vectorcd> *us = 0); 00043 00044 virtual ~UuvView(); 00045 00046 00047 virtual void Render(const UuvState *x, 00048 const Vectorcd *u = 0); 00049 00050 void Render(const vector<UuvState> *xs, 00051 const vector<Vectorcd> *us = 0, 00052 bool rs = true, 00053 int is = -1, int ie = -1, 00054 int dis = 1, int dit = 1, 00055 bool dl = false); 00056 00057 const Uuv<c> &sys; 00058 GLUquadricObj *qobj; 00059 double dirSize; 00060 00061 static void Transform(const Matrix4d &g); 00062 }; 00063 } 00064 00065 00066 using namespace gcop; 00067 using namespace Eigen; 00068 00069 template<int c> 00070 UuvView<c>::UuvView(const Uuv<c> &sys) : 00071 SystemView<UuvState, Matrix<double, c, 1> >("Uuv"), sys(sys) 00072 { 00073 this->rgba[0] = .5; 00074 this->rgba[1] = .5; 00075 this->rgba[2] = .5; 00076 this->rgba[3] = 0; 00077 this->lineWidth = 2; 00078 qobj = gluNewQuadric(); 00079 dirSize = -1; 00080 } 00081 00082 template<int c> 00083 UuvView<c>::UuvView(const Uuv<c> &sys, 00084 vector<UuvState> *xs, 00085 vector<Vectorcd> *us) : 00086 SystemView<UuvState, Matrix<double, c, 1> >("Uuv", xs, us), sys(sys) 00087 { 00088 this->rgba[0] = 0.5; 00089 this->rgba[1] = 0.5; 00090 this->rgba[2] = 0.5; 00091 this->rgba[3] = 0; 00092 this->lineWidth = 2; 00093 qobj = gluNewQuadric(); 00094 } 00095 00096 00097 template<int c> 00098 UuvView<c>::~UuvView() 00099 { 00100 free(qobj); 00101 } 00102 00103 template<int c> 00104 void UuvView<c>::Render(const UuvState *x, 00105 const Vectorcd *u) 00106 { 00107 // glColor4f(1,0.5,0.5,0.5); 00108 00109 glPushMatrix(); 00110 Transform(x->g); 00111 glScaled(sys.ds[0], sys.ds[1], sys.ds[2]); 00112 glutSolidCube(1); 00113 glPopMatrix(); 00114 } 00115 00116 00117 template<int c> 00118 void UuvView<c>::Render(const vector<UuvState> *xs, 00119 const vector<Vectorcd > *us, 00120 bool rs, 00121 int is, int ie, 00122 int dis, int dit, 00123 bool dl) 00124 { 00125 Viewer::SetColor(this->rgba[0], this->rgba[1], this->rgba[2], this->rgba[3]); 00126 // glColor4f( 00127 00128 // set defaults 00129 if (is == -1) 00130 is = 0; 00131 if (ie == -1) 00132 ie = xs->size()-1; 00133 00134 assert(is >= 0 && is <= xs->size()-1 && ie >= 0 && ie <= xs->size()-1); 00135 assert(is <= ie); 00136 00137 glDisable(GL_LIGHTING); 00138 glLineWidth(this->lineWidth); 00139 glBegin(GL_LINE_STRIP); 00140 for (int i = is; i <= ie; i+=dit) { 00141 const UuvState &x = (*xs)[i]; 00142 glVertex3d(x.g(0,3), x.g(1,3), x.g(2,3)); 00143 } 00144 glEnd(); 00145 glLineWidth(1); 00146 glEnable(GL_LIGHTING); 00147 00148 if (rs) { 00149 for (int i = 0; i < xs->size(); i+=dis) { 00150 Render(&(*xs)[i]); 00151 } 00152 } 00153 00154 if (dl) 00155 Render(&xs->back()); 00156 } 00157 00158 template<int c> 00159 void UuvView<c>::Transform(const Matrix4d &g) 00160 { 00161 const SO3 &so3 = SO3::Instance(); 00162 glTranslated(g(0,3), g(1,3), g(2,3)); 00163 00164 Vector3d e; 00165 so3.log(e, g.topLeftCorner<3,3>()); 00166 double n = e.norm(); 00167 if (n > so3.tol) { 00168 e = e/n; 00169 glRotated(RAD2DEG(n), e[0], e[1], e[2]); 00170 } 00171 } 00172 00173 00174 #endif