GCOP
1.0
|
00001 #ifndef GCOP_KINBODY3DTRACKVIEW_H 00002 #define GCOP_KINBODY3DTRACKVIEW_H 00003 00004 #include "GL/glu.h" 00005 #include "GL/glut.h" 00006 #include "kinbody3dtrack.h" 00007 #include "view.h" 00008 00009 00010 namespace gcop { 00011 00016 template <int _nu = 6> 00017 class Kinbody3dTrackView : public View { 00018 public: 00019 00025 Kinbody3dTrackView(const Kinbody3dTrack<_nu> &pg); 00026 00027 virtual ~Kinbody3dTrackView(); 00028 00029 virtual void Render(); 00030 00031 virtual bool RenderFrame(int i); 00032 00033 const Kinbody3dTrack<_nu> &pg; 00034 00035 float rgba[4]; 00036 00037 bool drawLandmarks; 00038 bool drawForces; 00039 double forceScale; 00040 00041 00042 GLUquadricObj *qobj; 00043 }; 00044 00045 template <int _nu> 00046 Kinbody3dTrackView<_nu>::Kinbody3dTrackView(const Kinbody3dTrack<_nu> &pg) : 00047 View("Kinbody3dtrack View"), pg(pg) 00048 { 00049 rgba[0] = 1; 00050 rgba[0] = 0; 00051 rgba[0] = 0; 00052 rgba[0] = .5; 00053 drawLandmarks = true; 00054 drawForces = true; 00055 forceScale = 10; 00056 qobj = gluNewQuadric(); 00057 } 00058 00059 template <int _nu> 00060 Kinbody3dTrackView<_nu>::~Kinbody3dTrackView() 00061 { 00062 free(qobj); 00063 } 00064 00065 00066 template <int _nu> 00067 void Kinbody3dTrackView<_nu>::Render() 00068 { 00069 RenderFrame(0); 00070 } 00071 00072 00073 template <int _nu> 00074 bool Kinbody3dTrackView<_nu>::RenderFrame(int i) 00075 { 00076 00077 Viewer::SetColor(.5, .5, .5, 1); 00078 00079 gluCylinder(qobj, pg.r + pg.w/2, pg.r + pg.w/2, .1, 20, 10); 00080 00081 gluCylinder(qobj, pg.r - pg.w/2, pg.r - pg.w/2, .1, 20, 10); 00082 00083 // red: noisy/estimated 00084 Viewer::SetColor(rgba[0], rgba[1], rgba[2], rgba[3]); 00085 00086 if (drawForces) { 00087 00088 glDisable(GL_LIGHTING); 00089 Vector3d f; 00090 for (int k =0; k < pg.us.size(); ++k) { 00091 f.head<3>() = forceScale*pg.xs[k].block(0,0,3,3)*(pg.sys.Bu*pg.us[k]).tail(3); 00092 glPushMatrix(); 00093 glTranslated(pg.xs[k](0,3), pg.xs[k](1,3), pg.xs[k](2,3)); 00094 Viewer::DrawArrow(f.data(),qobj); 00095 glPopMatrix(); 00096 } 00097 glEnable(GL_LIGHTING); 00098 } 00099 00100 if (drawLandmarks) { 00101 00102 00103 for (int l = 0; l < pg.ls.size(); ++l) { 00104 00105 if (pg.observed[l]) 00106 Viewer::SetColor(0, 1, 0, 1); 00107 else 00108 Viewer::SetColor(.5, .5, .5, 1); 00109 00110 glPushMatrix(); 00111 glTranslated( pg.ls[l][0], pg.ls[l][1], pg.ls[l][2]); 00112 00113 gluCylinder(qobj, pg.pr, pg.pr, 1, 20, 10); 00114 00115 // glutSolidSphere(pg.pr, 10, 10); 00116 00117 /* 00118 glPushMatrix(); 00119 glTranslated(.05, 0, 0); 00120 char str[10]; 00121 sprintf(str, "%d", l); 00122 Viewer::DrawText(str, .05); 00123 glPopMatrix(); 00124 */ 00125 glPopMatrix(); 00126 } 00127 00128 // draw visible 00129 int nvf = (pg.p.size() - 3*pg.extforce)/3; 00130 int i0 = 3*pg.extforce; 00131 00132 Viewer::SetColor(0, 0, 1, 1); 00133 // cout << "ALL" << endl; 00134 for (int l = 0; l < nvf; ++l) { 00135 // cout << pg.p[i0 + 2*l] << " " << pg.p[i0 + 2*l + 1] << endl; 00136 glPushMatrix(); 00137 glTranslated( pg.p[i0 + 3*l], pg.p[i0 + 3*l + 1], pg.p[i0 + 3*l + 2]); 00138 glutSolidSphere(pg.pr, 10, 10); 00139 00140 /* 00141 glPushMatrix(); 00142 glTranslated(.05, 0, 0); 00143 char str[10]; 00144 sprintf(str, "%d", l); 00145 Viewer::DrawText(str, .05); 00146 glPopMatrix(); 00147 */ 00148 glPopMatrix(); 00149 } 00150 00151 glDisable(GL_LIGHTING); 00152 glLineWidth(1); 00153 glBegin(GL_LINES); 00154 // Viewer::SetColor(0, 0, 1, 0); 00155 glColor3d(.5,.5,1); 00156 for (int l = 0; l < nvf; ++l) { 00157 const vector< pair<int,Vector3d> > &J = pg.Js[pg.pis[l]]; 00158 for (int j = 0; j < J.size(); ++j) { 00159 int k = J[j].first; 00160 const Vector3d &x = pg.xs[k].block(0,3,3,1); 00161 glVertex3d(pg.p(3*l + i0), pg.p(3*l + i0 + 1), pg.p(3*l + i0 + 2)); 00162 glVertex3d(x[0], x[1], x[2]); 00163 } 00164 } 00165 glEnd(); 00166 glLineWidth(1); 00167 glEnable(GL_LIGHTING); 00168 00169 } 00170 00171 return false; 00172 } 00173 00174 } 00175 00176 #endif