Main Page   Namespace List   Compound List   File List   Compound Members   File Members  

View.C

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003 Eric Bohm
00003  *
00004  *This program is free software; you can redistribute it and/or modify
00005  *it under the terms of the GNU General Public License as published by
00006  *the Free Software Foundation version 2 of the License.
00007  * 
00008  *This program is distributed in the hope that it will be useful, but
00009  *WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  *General Public License for more details.
00012  * 
00013  *You should have received a copy of the GNU General Public License along
00014  *with this program; if not, write to the Free Software Foundation, Inc.,
00015  *675 Mass Ave, Cambridge, MA 02139, USA.
00016  *
00017  */
00018 using namespace std;
00019 
00020 #include <GL/glu.h>
00021 #include <GL/glut.h>
00022 #include <stdio.h>
00023 #include <vector>
00024 #include <algorithm>
00025 #include "View.h"
00026 
00027 
00029 
00041 bool View::loadfile(const char *filename)
00042 {
00043   unsigned int time=12;
00044   unsigned int chunk=12;
00045   char base[80];
00046   char stuff[80];
00047   char ext[80];
00048   memset(base,'\0',80);
00049   // strip path crap to eliminate .
00050   char *slash=rindex(filename,'/');
00051   if(slash>=filename)
00052     {
00053       strcpy(base,slash+1);
00054       slash=rindex(filename,'.');
00055       strcpy(ext,slash+1);
00056     }
00057   else
00058     {
00059      strcpy(base,filename);
00060      slash=rindex(filename,'.');
00061      strcpy(ext,slash+1);
00062     }
00063   sscanf(base,"%[^0123456789.]",stuff);
00064   chunk=atoi(base+strlen(stuff));
00065   time=atoi(ext);
00066   map <unsigned int, RGB>::iterator chiter=chunks.find(chunk);
00067   map <unsigned int, Timestep>::iterator timeiter=timesteps.find(time);
00068   if(timeiter==timesteps.end())
00069     {
00070       timesteps[time]=Timestep();
00071     }
00072   else
00073     {
00074     }
00075   if(chiter==chunks.end())
00076     { 
00077       GLfloat tetcolor[3];
00078       tetcolor[0] = drand48() / 2.0 + 0.5;
00079       tetcolor[1] = drand48() / 2.0 + 0.5;
00080       tetcolor[2] = drand48() / 2.0 + 0.5;
00081       chunks[chunk]=RGB(tetcolor);
00082       if(timesteps[time].loadfile(filename,tetcolor,time,chunk))
00083         {
00084           filenum++;
00085         }
00086       else
00087         return false;
00088     }
00089   else
00090     {
00091       if(timesteps[time].loadfile(filename,chiter->second.rgb,time,chunk))
00092         {
00093           filenum++;
00094         }
00095       else
00096         return false;
00097     }
00098   if(time>uptodate_step.size())
00099     {
00100       uptodate_step.resize(time);
00101       uptodate_step[time]=false;
00102     }
00103   return true;
00104 }
00105 
00106 
00107 
00109 
00114 void View::display_step(unsigned int step)
00115 {
00116   map <unsigned int, Timestep>::iterator stepiter=timesteps.find(step);
00117   if(stepiter!=timesteps.end())
00118     {
00119       currstep=step;
00120       now=stepiter;
00121       if(glIsList(step) && uptodate_step[step])
00122         { // if it exists and is up to date just redisplay
00123           glCallList(step);
00124         }
00125       else
00126         { // draw it
00127           uptodate_step[step]=true;
00128           now->second.draw_polygons(ScreenWidth,ScreenHeight,colormap,aspect_ratio,scale,xtri,ytri,ztri,xtran,ytran,ztran,
00129                              fillpoly,showlabel,showlength,opaque,pointmode,solo_chunk);
00130         }
00131     }
00132   else
00133     {
00134       fprintf(stderr,"Error no such timestep %u\n",step);
00135     }
00136 }
00137 
00139 void View::recenter()
00140 {
00141   // In a better world we would use for_each here.
00142   // But that doesn't work nicely when you need to modify the object.
00143   map < unsigned int, Timestep>::iterator titer=timesteps.begin();
00144   while(titer!=timesteps.end())
00145     {
00146       titer->second.set_random_color(points);
00147       titer->second.calc_and_move();
00148       titer++;
00149     }
00150 }
00151 
00153 
00156 void View::make_random_color_set()
00157 {
00158   //simple solution here.  cat all the point vectors together.
00159   // sort the collection.
00160   // unique_copy the collection
00161   // assign a random color to each point
00162   vector <Coordinate> collection;
00163   map < unsigned int, Timestep>::iterator titer=timesteps.begin();
00164   while(titer!=timesteps.end())
00165     {
00166       vector <Coordinate> tstamp=titer->second.get_points();
00167       collection.insert(collection.end(),tstamp.begin(),tstamp.end());
00168       titer++;
00169     }
00170   sort(collection.begin(),collection.end());
00171   insert_iterator< vector <Coordinate> > ins(points,points.begin());
00172   //  unique(collection.begin(),collection.end());
00173   //  points=collection;
00174   unique_copy(collection.begin(),collection.end(),ins);
00175   //  for_each(collection.begin(),collection.end(),mem_fun_ref(&Coordinate::edump));
00176 
00177   for(unsigned int i=0;i<points.size();i++)
00178     {
00179       points[i].set_rgb(drand48() / 2.0 + 0.5,drand48() / 2.0 + 0.5,drand48() / 2.0 + 0.5);
00180     }
00181 
00182 }
00183 

Generated on Wed Oct 29 10:01:52 2003 for Tetraviewer by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002