00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
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 {
00123 glCallList(step);
00124 }
00125 else
00126 {
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
00142
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
00159
00160
00161
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
00173
00174 unique_copy(collection.begin(),collection.end(),ins);
00175
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