00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef AMROC_FILEEVENTHANDLER_H
00010 #define AMROC_FILEEVENTHANDLER_H
00011
00019 #include "HDFToV3/Eventhandler.h"
00020
00021 #include <iostream>
00022 #include <fstream>
00023 #include <sstream>
00024 #include <cstdlib>
00025 #include <cstdio>
00026 #include <cmath>
00027 #include <cctype>
00028
00029
00036 class FileEventHandler : public VisualEventHandler {
00037 public:
00038 int step;
00039 FileEventHandler() : VisualEventHandler() {}
00040
00041 void SetUpQueue() {
00042
00043 std::ifstream infile;
00044 char charBuffer[256];
00045 std::string arg,fileID,stepstr;
00046 int endOfBlock=0;
00047 std::stringstream temp;
00048
00049
00050
00051 Display *display = XOpenDisplay (NULL);
00052 if (display == NULL) {
00053 std::fprintf (stderr, "cannot connect to server\n");
00054 std::exit (EXIT_FAILURE);
00055 }
00056
00057 infile.open("display.in", std::ios::in);
00058
00059 if(SeekArg(infile,"SCRIPTBEGIN")){
00060 SeekArg(infile,"{");
00061 std::cerr << "Processing general script commands..." << std::endl;
00062 endOfBlock=0;
00063 do{
00064 arg=GetNextArg(infile,charBuffer);
00065
00066 std::cerr << arg << std::endl;
00067 if(charBuffer[0]=='#')
00068 SeekEol(infile);
00069 ProcessArg(infile,arg,display);
00070 if(arg == "}" || arg == "END")
00071 endOfBlock=1;
00072 }while(!endOfBlock);
00073 std::cerr << "Done with general script." << std::endl;
00074 }
00075
00076 fileID="FILEID_";
00077 temp << step;
00078 temp >> stepstr;
00079 fileID += stepstr;
00080 std::cerr << ">" << fileID << "<" << std::endl;
00081 if(SeekArg(infile,fileID)){
00082 SeekArg(infile,"{");
00083 std::cerr << "Processing script commands for step " << step << "..."
00084 << std::endl;
00085 endOfBlock=0;
00086 do{
00087 arg=GetNextArg(infile,charBuffer);
00088 if(charBuffer[0]=='#')
00089 SeekEol(infile);
00090 ProcessArg(infile,arg,display);
00091 if(arg == "}" || arg == "END")
00092 endOfBlock=1;
00093 }while(!endOfBlock);
00094 std::cerr << "Done with script for step " << step << "..." << std::endl;
00095 }
00096 infile.close();
00097 };
00098 void SetStep(int stepID){step=stepID;};
00099
00100
00101 private:
00102 std::string GetNextArg(std::ifstream& infile,char* charBuffer){
00103 int i=0;
00104 std::string str;
00105 char c;
00106 do{
00107 c=infile.get();
00108 } while((!infile.eof()) && (c<=' '|| c==',' || c==';'));
00109 charBuffer[i++] = std::toupper(c);
00110 do{
00111 c=infile.get();
00112 charBuffer[i++] = std::toupper(c);
00113 } while ((!infile.eof()) && c>' ' && c!=',' && c!=';');
00114 if(infile.eof())
00115 return std::string("END");
00116 charBuffer[i-1]='\0';
00117 str=charBuffer;
00118 return str;
00119 }
00120
00121 int SeekArg(std::ifstream& infile,std::string str){
00122 char charBuffer[256];
00123 int exists=0,endOfFile=0;
00124 std::string cmd;
00125 do{
00126 cmd=GetNextArg(infile,charBuffer);
00127 if(cmd == str)
00128 exists=1;
00129 if(cmd == "END" || infile.eof())
00130 endOfFile=1;
00131 }while(!exists && !endOfFile);
00132 if(!endOfFile)
00133 return 1;
00134 else
00135 return 0;
00136
00137 }
00138 void SeekEol(std::ifstream& infile){
00139 char c;
00140 do{
00141 c=infile.get();
00142 } while((!infile.eof()) && c!='\n');
00143 }
00144
00145 void ProcessArg(std::ifstream& infile,std::string cmd,Display *display){
00146 int opt,i,j,k;
00147 char charBuffer[256];
00148 long dummy=0,iv[12],winid[8],keybin[32];
00149 char blank=' ';
00150 float rdummy,rv[12],matA[9],matB[9];
00151 float Pi=4*std::atan(float(1.0)),phi[3];
00152
00153 opt=0;
00154 V3_GETSTATE(&opt,winid,rv,&blank,1);
00155 opt = -1;
00156 V3_GETSTATE(&opt,keybin,rv,&blank,1);
00157 if(cmd == "SETVIEW"){
00158 for(i=0;i<12;i++){
00159 cmd=GetNextArg(infile,charBuffer);
00160 std::istringstream arg(std::string(charBuffer,sizeof(charBuffer)-1));
00161 arg >> rv[i];
00162 }
00163 EventQueue().push(SingleEvent(1, 0, 0, 0,
00164 new SetState(1, &dummy, 1, rv, 12, &blank, 1)));
00165 }
00166
00167 if(cmd == "SETCUT"){
00168 for(i=0;i<9;i++){
00169 cmd=GetNextArg(infile,charBuffer);
00170 std::istringstream arg(std::string(charBuffer,sizeof(charBuffer)-1));
00171 arg >> rv[i];
00172 }
00173 EventQueue().push(SingleEvent(1, 0, 0, 0,
00174 new SetState(2, &dummy, 1, rv, 12, &blank, 1)));
00175 }
00176
00177 if(cmd == "SCALARSTATE"){
00178 std::cerr << "Setting ScalarState" << std::endl;
00179 cmd=GetNextArg(infile,charBuffer);
00180 std::istringstream arg(std::string(charBuffer,sizeof(charBuffer)-1));
00181 arg >> iv[0];
00182 for(i=0;i<2;i++){
00183 cmd=GetNextArg(infile,charBuffer);
00184 std::istringstream arg(std::string(charBuffer,sizeof(charBuffer)-1));
00185 arg >> rv[i] ;
00186 }
00187
00188
00189 EventQueue().push(SingleEvent(1, 0, 0, 0,
00190 new SetState(5, iv, 1, rv, 2, &blank, 1)));
00191 }
00192
00193 if(cmd == "CELLSCALARSTATE"){
00194 std::cerr << "Setting CellScalarState" << std::endl;
00195 cmd=GetNextArg(infile,charBuffer);
00196 std::istringstream arg(std::string(charBuffer,sizeof(charBuffer)-1));
00197 arg >> iv[0];
00198 for(i=0;i<2;i++){
00199 cmd=GetNextArg(infile,charBuffer);
00200 std::istringstream arg(std::string(charBuffer,sizeof(charBuffer)-1));
00201 arg >> rv[i] ;
00202 }
00203 EventQueue().push(SingleEvent(1, 0, 0, 0,
00204 new SetState(9, iv, 1, rv, 2, &blank, 1)));
00205 }
00206
00207 if(cmd == "THRESHSTATE"){
00208 for(i=0;i<2;i++){
00209 cmd=GetNextArg(infile,charBuffer);
00210 std::istringstream arg(std::string(charBuffer,sizeof(charBuffer)-1));
00211 arg >> iv[i];
00212 }
00213 for(i=0;i<2;i++){
00214 cmd=GetNextArg(infile,charBuffer);
00215 std::istringstream arg(std::string(charBuffer,sizeof(charBuffer)-1));
00216 arg >> rv[i];
00217 }
00218 EventQueue().push(SingleEvent(1, 0, 0, 0,
00219 new SetState(7, iv, 2, rv, 2, &blank, 1)));
00220 }
00221
00222 if(cmd == "ISOSURFACE"){
00223 EventQueue().push(SingleEvent(1, winid[2], 2, keybin[6]));
00224 opt=5;
00225
00226 cmd=GetNextArg(infile,charBuffer);
00227 std::istringstream arg(std::string(charBuffer,sizeof(charBuffer)-1));
00228 arg >> iv[0];
00229 V3_GETSTATE(&opt,iv,rv,&blank,1);
00230
00231 cmd=GetNextArg(infile,charBuffer);
00232 std::istringstream arg1(std::string(charBuffer,sizeof(charBuffer)-1));
00233 arg1 >> rv[2];
00234 rdummy=(rv[2]-rv[0])/(rv[1]-rv[0])*436.0+37.5;
00235 dummy=(int)rdummy;
00236 std::cerr << "Isosurface " << rv[0] << " " << rv[2] << " "
00237 << rv[1] << " " << dummy << std::endl;
00238
00239 EventQueue().push(SingleEvent(1,winid[4],4,3,dummy,50));
00240 }
00241
00242 if(cmd == "SURFSTATE"){
00243 cmd=GetNextArg(infile,charBuffer);
00244 std::istringstream arg(std::string(charBuffer,sizeof(charBuffer)-1));
00245 arg >> iv[0];
00246 cmd=GetNextArg(infile,charBuffer);
00247 std::istringstream arg2(std::string(charBuffer,sizeof(charBuffer)-1));
00248 arg2 >> iv[1];
00249 cmd=GetNextArg(infile,charBuffer);
00250 std::istringstream arg3(std::string(charBuffer,sizeof(charBuffer)-1));
00251 arg3 >> iv[2];
00252 iv[1]+=2*iv[2];
00253 cmd=GetNextArg(infile,charBuffer);
00254 std::istringstream arg4(std::string(charBuffer,sizeof(charBuffer)-1));
00255 arg4 >> iv[2];
00256 iv[1]+=4*iv[2];
00257 cmd=GetNextArg(infile,charBuffer);
00258 std::istringstream arg5(std::string(charBuffer,sizeof(charBuffer)-1));
00259 arg5 >> iv[2];
00260 iv[1]+=8*iv[2];
00261 EventQueue().push(SingleEvent(1, 0, 0, 0,
00262 new SetState(10, iv, 2, &rdummy, 1, &blank, 1)));
00263 }
00264
00265 if(cmd == "TRANSLATION"){
00266
00267
00268 opt=1;
00269 V3_GETSTATE(&opt,iv,rv,&blank,0);
00270
00271 for(i=0;i<3;i++){
00272 cmd=GetNextArg(infile,charBuffer);
00273 std::istringstream arg(std::string(charBuffer,sizeof(charBuffer)-1));
00274 arg >> rdummy;
00275 rv[i*4+3]+=rdummy;
00276 }
00277 EventQueue().push(SingleEvent(1, 0, 0, 0,
00278 new SetState(1, &dummy, 1, rv, 12, &blank, 1)));
00279 }
00280
00281 if(cmd == "ROTATION"){
00282 opt=1;
00283 V3_GETSTATE(&opt,iv,rv,&blank,1);
00284 for(i=0;i<3;i++){
00285 cmd=GetNextArg(infile,charBuffer);
00286 std::istringstream arg(std::string(charBuffer,sizeof(charBuffer)-1));
00287 arg >> phi[i];
00288 phi[i]*=Pi/180;
00289 }
00290
00291 matA[0]=std::cos(phi[1])*std::cos(phi[2]);
00292 matA[1]=std::cos(phi[1])*std::sin(phi[2]);
00293 matA[2]=std::sin(phi[1]);
00294 matA[3]=-std::sin(phi[0])*std::sin(phi[1])*std::cos(phi[2])
00295 -std::cos(phi[0])*std::sin(phi[2]);
00296 matA[4]=-std::sin(phi[0])*std::sin(phi[1])*std::sin(phi[2])
00297 +std::cos(phi[0])*std::cos(phi[2]);
00298 matA[5]=std::sin(phi[0])*std::cos(phi[1]);
00299 matA[6]=-std::cos(phi[0])*std::sin(phi[1])*std::cos(phi[2])
00300 +std::sin(phi[0])*std::sin(phi[2]);
00301 matA[7]=-std::cos(phi[0])*std::sin(phi[1])*std::sin(phi[2])
00302 -std::sin(phi[0])*std::cos(phi[2]);
00303 matA[8]=std::cos(phi[0])*std::cos(phi[1]);
00304 for(i=0;i<3;i++){
00305 for(j=0;j<3;j++){
00306 matB[i*3+j]=0;
00307 for(k=0;k<3;k++){
00308 matB[i*3+j]+=matA[i*3+k]*rv[k*4+j];
00309 }
00310 }
00311 }
00312 for(i=0;i<3;i++){
00313 for(j=0;j<3;j++){
00314 rv[i*4+j]=matB[i*3+j];
00315 }
00316 }
00317 EventQueue().push(SingleEvent(1, 0, 0, 0,
00318 new SetState(1, &dummy, 1, rv, 12, &blank, 1)));
00319
00320 }
00321 if(cmd == "2DVIEW"){
00322
00323 opt=2;
00324 for(i=0;i<9;i++){
00325 cmd=GetNextArg(infile,charBuffer);
00326 std::istringstream arg(std::string(charBuffer,sizeof(charBuffer)-1));
00327 arg >> rv[i];
00328 }
00329 EventQueue().push(SingleEvent(1, 0, 0, 0,
00330 new SetState(2, iv, 1, rv, 9, &blank, 1)));
00331
00332 EventQueue().push(SingleEvent(1, winid[2], 2, keybin[2] ));
00333 EventQueue().push(SingleEvent(1, winid[2], 2, keybin[2] ));
00334 }
00335
00336 if(cmd == "EDGEOUTLINEOFF"){
00337 opt=14;
00338 V3_GETSTATE(&opt,iv,rv,&blank,0);
00339 iv[0]=0;
00340 EventQueue().push(SingleEvent(1, 0, 0, 0,
00341 new SetState(14, iv, 2, rv, 7, &blank, 1)));
00342 }
00343 if(cmd == "EDGEOUTLINEON"){
00344 opt=14;
00345 V3_GETSTATE(&opt,iv,rv,&blank,0);
00346 iv[0]=1;
00347 EventQueue().push(SingleEvent(1, 0, 0, 0,
00348 new SetState(14, iv, 2, rv, 7, &blank, 1)));
00349 }
00350
00351 if(cmd == "TRANSPARENTPLANEOFF"){
00352 opt=14;
00353 V3_GETSTATE(&opt,iv,rv,&blank,0);
00354 iv[1]=0;
00355 EventQueue().push(SingleEvent(1, 0, 0, 0,
00356 new SetState(14, iv, 2, rv, 7, &blank, 1)));
00357 }
00358 if(cmd == "TRANSPARENTPLANEON"){
00359 opt=14;
00360 V3_GETSTATE(&opt,iv,rv,&blank,0);
00361 iv[1]=1;
00362 EventQueue().push(SingleEvent(1, 0, 0, 0,
00363 new SetState(14, iv, 2, rv, 7, &blank, 1)));
00364 }
00365 if(cmd == "EDGESOFFTRANSPARENTON"){
00366 opt=14;
00367 V3_GETSTATE(&opt,iv,rv,&blank,0);
00368 iv[0]=0;
00369 iv[1]=0;
00370 EventQueue().push(SingleEvent(1, 0, 0, 0,
00371 new SetState(14, iv, 2, rv, 7, &blank, 1)));
00372 }
00373
00374 if(cmd == "HARDCOPY"){
00375 EventQueue().push(SingleEvent(5, winid[2], 2, '~'));
00376 }
00377 if(cmd == "2DHARDCOPY"){
00378 EventQueue().push(SingleEvent(5, winid[1], 2, '~'));
00379 }
00380 if(cmd == "ESCAPE"){
00381 EventQueue().push(SingleEvent(5, winid[2], 2, keybin[19]));
00382 }
00383 if(cmd == "DISPLAYSIZE"){
00384 for(i=0;i<2;i++){
00385 cmd=GetNextArg(infile,charBuffer);
00386 std::istringstream arg(std::string(charBuffer,sizeof(charBuffer)-1));
00387 arg >> iv[i];
00388 }
00389 XResizeWindow(display,winid[iv[0]],iv[1],iv[1]);
00390 XFlush (display);
00391 }
00392 if(cmd == "MOVEWINDOW"){
00393 for(i=0;i<3;i++){
00394 cmd=GetNextArg(infile,charBuffer);
00395 std::istringstream arg(std::string(charBuffer,sizeof(charBuffer)-1));
00396 arg >> iv[i];
00397 }
00398 XMoveWindow(display,winid[iv[0]],iv[1],iv[2]);
00399 XFlush (display);
00400 }
00401
00402 if(cmd == "SETLIMITS"){
00403 EventQueue().push(SingleEvent(1, winid[4], 2, 'f'));
00404 }
00405 if(cmd == "SETCONTOURS"){
00406 EventQueue().push(SingleEvent(1, winid[4], 2, 'c'));
00407 }
00408 if(cmd == "PLANARCUTOFF"){
00409 EventQueue().push(SingleEvent(1, winid[2], 2, keybin[1]));
00410 }
00411 if(cmd == "PLANARCUTON"){
00412 EventQueue().push(SingleEvent(1, winid[2], 2, keybin[2]));
00413 EventQueue().push(SingleEvent(1, winid[2], 2, keybin[2]));
00414 }
00415 if(cmd == "CUTPLANE"){
00416 EventQueue().push(SingleEvent(1, winid[2], 2, keybin[3]));
00417 }
00418 if(cmd == "CONTOURTOGGLE"){
00419 EventQueue().push(SingleEvent(1, winid[1], 2, keybin[7]));
00420
00421 }
00422 if(cmd == "RENDERTOGGLE"){
00423 EventQueue().push(SingleEvent(1, winid[1], 2, keybin[8]));
00424 }
00425 if(cmd == ""){}
00426 }
00427
00428 };
00429
00430 #endif
00431