C:/Projekte/InfoVIS/InfoVIS/RootGrid.cpp

00001 #include "RootGrid.h"
00002 
00003 int RootGrid::counter = 0;
00004 
00005 RootGrid::RootGrid(LinearGrid* _linear, const Texture* _texture):gridNumber(++counter)
00006 {
00007         linear = _linear;
00008         texture = _texture;
00009 
00010         Create(2*PI);
00011 }       
00012 
00013 void RootGrid::Create(float a)
00014 {
00015         // prevent from division by zero!
00016         if (a == 0.0)
00017         {       
00018                 return;
00019         }
00020         else
00021         {
00022                 rootVector.clear();
00023                 rootGrid.clear();
00024         }
00025 
00026         TexturedGrid tg;
00027         float n = (2*PI)/a; 
00028         openingAngle = n;
00029         moveUp = n;
00030 
00031 
00032         const ComplexGrid linGrid = linear->GetGrid();
00033 
00034         for(gridIterator = linGrid.begin(); gridIterator != linGrid.end(); ++gridIterator)
00035         {
00036                 for(vectorIterator = gridIterator->begin(); vectorIterator != gridIterator->end(); ++vectorIterator)
00037                 {
00038                         //Complex nthRoot = Complex(std::pow(**itr, (double) n));
00039                         Complex nthRoot = Complex(pow(vectorIterator->complex, 1.0/(double)n));
00040                         nthRoot -= 1;
00041                         nthRoot *= n;
00042                         
00043                         tg.uCoordinate = vectorIterator->uCoordinate;
00044                         tg.vCoordinate = vectorIterator->vCoordinate;
00045                         tg.isCut = vectorIterator->isCut;
00046                         tg.complex = nthRoot;
00047 
00048                         rootVector.push_back(tg);
00049                 }
00050                 rootGrid.push_back(rootVector);
00051                 rootVector.clear();
00052         }
00053 
00054         Draw();
00055 }
00056 
00057 
00058 RootGrid::~RootGrid(void)
00059 {
00060         linear = NULL;
00061         texture = NULL;
00062 }
00063 
00064 void RootGrid::Draw()
00065 {
00066         double x, y, u, v;
00067         bool breakDraw = true;
00068 
00069         glColor3f(0.0, 0.0, 0.0);
00070         glPointSize(5.0f);
00071         glBegin(GL_POINTS);
00072                 glVertex2i(0,0);
00073         glEnd();
00074         glColor3f(1.0, 0.0, 0.0);
00075         glPointSize(1.0f);
00076 
00077         glBindTexture(GL_TEXTURE_2D, texture->GetTextureID());
00078         glEnable(GL_TEXTURE_2D);
00079 
00080         unsigned int tmpSize = (unsigned int) rootGrid.size()/2;
00081 
00082         for(GridIteratorConst gridIterator = rootGrid.begin(); gridIterator != rootGrid.end() - 1; ++gridIterator)
00083         {
00084 
00085                 VectorIteratorConst vItrCurrentRow = gridIterator->begin();
00086                 VectorIteratorConst vItrUpperRow = (gridIterator+1)->begin();
00087 
00088                 static double openY = 1.0;
00089                 
00090                 glBegin(GL_QUAD_STRIP);
00091                 for (unsigned int i = 0; i < gridIterator->size(); i++)
00092                 {
00093 
00094                         if(vItrCurrentRow->isCut && (i <= tmpSize))
00095                         {
00096                                 glEnd();
00097                                 glBegin(GL_QUAD_STRIP);
00098                         }
00099 
00100                         if(moveUp > 2.0)
00101                         {
00102                                 moveUp = 2.0;
00103                         }
00104 
00105                         if(openingAngle > PI) 
00106                         {
00107                                 openingAngle = PI;
00108                         }
00109 
00110                         //printf("openY: %f\n", openY);
00111 
00112                         // 1st/3rd/5th... Vertex for QUAD_STRIP
00113                         x = vItrCurrentRow->complex.imag()/openingAngle;
00114                         y = (vItrCurrentRow->complex.real() + moveUp)/openingAngle;
00115 
00116                         u = vItrCurrentRow->uCoordinate;
00117                         v = vItrCurrentRow->vCoordinate;
00118 
00119                         glTexCoord2f(u,v);
00120                         glVertex2d(x,y);
00121 
00123                         x = vItrUpperRow->complex.imag()/openingAngle;
00124                         y = (vItrUpperRow->complex.real() + moveUp)/openingAngle;
00125 
00126                         u = vItrUpperRow->uCoordinate;
00127                         v = vItrUpperRow->vCoordinate;
00128 
00129                         glTexCoord2f(u,v);
00130                         glVertex2d(x,y);
00131 
00132                         ++vItrCurrentRow;
00133                         ++vItrUpperRow;
00134 
00135                 } // end inner for
00136                 glEnd();
00137         } // end outer for
00138 
00139         glDisable(GL_TEXTURE_2D);
00140 }

Generated on Wed Jun 27 10:14:23 2007 for CLV by  doxygen 1.5.2