GCOP
1.0
|
00001 #ifndef GCOP_NORMAL2DVIEW_H 00002 #define GCOP_NORMAL2DVIEW_H 00003 00004 #include "normal.h" 00005 #include "systemview.h" 00006 00007 namespace gcop { 00008 using namespace Eigen; 00009 00010 template<int _n> 00011 class Normal2dView : public SystemView<Normal<_n>, Vector2d> { 00012 public: 00018 Normal2dView(vector<Normal<_n> > *gds = 0, 00019 vector<Vector2d> *us = 0); 00020 00021 virtual ~Normal2dView(); 00022 00023 void Render(const Normal<_n> *gd, 00024 const Vector2d *u = 0); 00025 00026 void Render(const vector<Normal<_n> > *gds = 0, 00027 const vector<Vector2d> *us = 0, 00028 bool rs = true, 00029 int is = -1, int ie = -1, 00030 int dis = 1, int dit = 1, 00031 bool dl = false); 00032 00033 bool wire; 00034 bool texture; 00035 double s; 00036 }; 00037 00038 template<int _n> 00039 Normal2dView<_n>::Normal2dView(vector<Normal<_n> > *xs, vector<Vector2d> *us) : 00040 SystemView("Normal", xs, us) 00041 { 00042 rgba[0] = 0.5; 00043 rgba[1] = 0.5; 00044 rgba[2] = 0.5; 00045 rgba[3] = 0; 00046 this->lineWidth = 2; 00047 00048 wire= false; 00049 texture = false; 00050 s = 1; 00051 } 00052 00053 00054 template<int _n> 00055 Normal2dView<_n>::~Normal2dView() 00056 { 00057 } 00058 00059 00060 template<int _n> 00061 void Normal2dView<_n>::Render(const Normal<_n> *gd, const Vector2d *u) 00062 { 00063 glColor4dv(rgba); 00064 00065 if (texture) { 00066 glColor4f(1,1,1,1); 00067 glDisable(GL_LIGHTING); 00068 } else { 00069 glEnable(GL_LIGHTING); 00070 } 00071 00072 double c = .5; 00073 Viewer::SetMaterial(c,c,c, c,c,c, c,c,c,5); 00074 // glColor3f(.5,.5,.5); 00075 00076 if (wire) { 00077 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); 00078 // glDisable(GL_DEPTH_TEST); 00079 // glCullFace(GL_BACK); 00080 } 00081 00082 double xl = gd->mu[0] - 2*sqrt(gd->P(0,0)); 00083 double xu = gd->mu[0] + 2*sqrt(gd->P(0,0)); 00084 double yl = gd->mu[1] - 2*sqrt(gd->P(1,1)); 00085 double yu = gd->mu[1] + 2*sqrt(gd->P(1,1)); 00086 int N = 50; 00087 double dx = (xu - xl)/N; 00088 double dy = (yu - yl)/N; 00089 00090 for (double y = yl; y < yu; y+=dy) { 00091 //Makes OpenGL draw a triangle at every three consecutive vertices 00092 glBegin(GL_TRIANGLE_STRIP); 00093 for (double x = xl; x < xu; x+=dx) { 00094 00095 double l = s*gd->L(Vector2d(x, y)); 00096 00097 // glNormal3dv(dem.normals + 3*(i*dem.nj+j)); 00098 00099 glVertex3f(x, y, l); 00100 // if (texture) 00101 // glTexCoord2d( (p[0]-dem.o[0])/dem.w, (dem.h - (p[1]-dem.o[1]) )/dem.h); 00102 00103 l = s*gd->L(Vector2d(x, y+dy)); 00104 // glNormal3dv(dem.normals + 3*((i+1)*dem.nj+j)); 00105 00106 glVertex3f(x, y + dy, l); 00107 // if (texture) 00108 // glTexCoord2d( (p[0]-dem.o[0])/dem.w, (dem.h - (p[1]-dem.o[1]) )/dem.h); 00109 } 00110 glEnd(); 00111 } 00112 00113 if (wire) 00114 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 00115 00116 00117 if (texture) 00118 glEnable(GL_LIGHTING); 00119 } 00120 00121 00122 void Normal2dView::Render(const vector<Normal> *gds, 00123 const vector<Vector2d> *us, 00124 bool rs, 00125 int is, int ie, 00126 int dis, int dit, 00127 bool dl) 00128 { 00129 Viewer::SetColor(rgba[0], rgba[1], rgba[2], rgba[3]); 00130 // glColor4f( 00131 00132 // set defaults 00133 if (is == -1) 00134 is = 0; 00135 if (ie == -1) 00136 ie = gds->size()-1; 00137 00138 assert(is >= 0 && is <= gds->size()-1 && ie >= 0 && ie <= gds->size()-1); 00139 assert(is <= ie); 00140 00141 glDisable(GL_LIGHTING); 00142 glLineWidth(lineWidth); 00143 glBegin(GL_LINE_STRIP); 00144 for (int i = is; i <= ie; i+=dit) { 00145 glVertex3d((*gds)[i].mu[0], (*gds)[i].mu[1], 0); 00146 } 00147 glEnd(); 00148 glLineWidth(1); 00149 glEnable(GL_LIGHTING); 00150 00151 if (rs) { 00152 for (int i = 0; i < gds->size(); i+=dis) { 00153 Render(&(*gds)[i]); 00154 } 00155 } 00156 00157 if (dl) 00158 Render(&gds->back()); 00159 } 00160 00161 } 00162 00163 #endif