Fork me on GitHub

source: svn/trunk/Utilities/FROG/main.cpp@ 216

Last change on this file since 216 was 100, checked in by severine ovyn, 16 years ago

Remove datacard bug + CaloTowers OK

File size: 27.4 KB
Line 
1#include "main.h"
2
3unsigned int EventI = 0;
4
5void Loading()
6{
7 char Buffer[1024];
8
9 switch(mLoading_I)
10 {
11
12
13 case 0:{
14 printf("\n");
15 printf("######################################################################\n");
16 printf("# http://projects.hepforge.org/frog/ #\n");
17 printf("# Please have a look at the website for latest versions and news #\n");
18 printf("# Also register to the Frog mailing list if you are not a member yet #\n");
19 printf("######################################################################\n");
20#ifndef FROG_LIGHTING
21 printf("# FROG_LIGHTING is not defined --> Lighting effects will not be used #\n");
22 printf("# Modify the MakeFile to define it in order to have nicer pictures #\n");
23 printf("######################################################################\n");
24#endif
25 printf("\n");
26
27 start = time ( NULL );
28
29
30 // TURN Vertical Synchronisation (VSYNC) OFF
31 // This allow the system to have more than 60 or 75FPS.
32/*
33 #ifdef windows
34 if(WGL_EXT_swap_control){wglSwapIntervalEXT(0);}else{printf("WGL_EXT_swap_control is NOT OK\n");}
35 #else
36 if(GLX_SGI_swap_control){glXSwapIntervalSGI(0);}else{printf("GLX_SGI_swap_control is NOT OK\n");}
37 #endif
38*/
39
40
41 // Init the random number generator
42 srand (time(NULL));
43
44 Fonts = new FROG_Fonts();
45 ViewScreen = new FROG_View_Screen("Screen");
46 ViewScreen->Reshape(WINDOW_WIDTH,WINDOW_HEIGHT);
47 sprintf(Buffer,"Reading %s",inputConfig.c_str());
48 ViewScreen->LoadingInProgress(0.0f,Buffer,Fonts,LogoTexture);
49
50
51 LoadCard(inputConfig.c_str());
52 if(!Card->IsTagPresent("InputGeom") && !Card->IsTagPresent("InputVisFile")){
53 printf("There is no .geom file neither than .vis file in the Config card\n");
54 printf("FROG will stop. Please update the Config card (%s)\n",inputConfig.c_str());
55 exit(0);
56 }
57
58 }break;
59
60 case 1:
61 ViewScreen->LoadingInProgress(1.0f,"Downloading Geometry\n(if necessary)",Fonts,LogoTexture);
62
63 if(Card->IsTagPresent("InputGeom")){
64 inputGeom = Card->GetStringVector("InputGeom");
65 for(unsigned int g=0;g<inputGeom.size();g++){
66 inputGeom[g] = string((char*)DownLoadFile( (char*)inputGeom[g].c_str(), AbsolutePath.c_str() ) );
67 }
68 }
69 break;
70
71 case 2:
72 /*
73 ViewScreen->LoadingInProgress(10.0f,"Downloading Events\n(if necessary)",Fonts,LogoTexture);
74
75 if(inputVisFileFromCard.length()<3 && Card->IsTagPresent("InputVisFile")){
76 inputVisFileFromCard = Card->GetString("InputVisFile");
77 }
78 inputVisFile = string((char*)DownLoadFile( (char*)inputVisFileFromCard.c_str(), AbsolutePath.c_str() ) );
79 */
80 break;
81
82 case 3:{
83 ViewScreen->LoadingInProgress(20.0f,"Loading Geometry",Fonts,LogoTexture);
84 if(geom)delete geom;
85 geom = new FROG_Geometry();
86 if(inputGeom.size()<=0){printf("Error : No Input Geometry File\n");exit(0);}
87
88 while(inputGeom.size()>0){
89 ViewScreen->LoadingInProgress(20.f+30.f/inputGeom.size(),(char*)inputGeom[inputGeom.size()-1].c_str(),Fonts,LogoTexture);
90 geom->Load((char*)inputGeom[inputGeom.size()-1].c_str());
91 inputGeom.pop_back();
92 }
93 frogObjects_ = new FROG_Objects_Extended(geom,NULL,Card, Fonts);
94
95
96 }break;
97
98 case 4:{
99 ViewScreen->LoadingInProgress(80.0f,"Loading .vis Files",Fonts,LogoTexture);
100
101 if(events)delete events;
102 events = new FROG_Events(frogObjects_);
103 events->Load(inputVisFileFromCommand);
104 events->readEventToDisplay(Card);
105 if(SCREENSAVER)eventNumber = rand()%((int)events->NumberOfEvents());
106 event = events->GoToEvent(eventNumber);
107 }break;
108
109 case 5:{
110 ViewScreen->LoadingInProgress(95.0f,"Views Initialisation",Fonts,LogoTexture);
111
112 ViewScreen->displayFunc_ = displaytext;
113 std::vector<string> ViewsName = Card->GetStringVector("ActiveViews");
114 ViewMain = ViewScreen;
115 for(unsigned int i=0;i<ViewsName.size();i++){
116 char* tmp = new char[ViewsName[i].size()+1];
117 strcpy(tmp,ViewsName[i].c_str());
118 ActiveViews.push_back(FROG_VIEW::Create(tmp,frogObjects_));
119 }
120 ViewScreen->Reshape(WINDOW_WIDTH,WINDOW_HEIGHT);
121
122 for(unsigned int j=0;j<ActiveViews.size();j++){
123 if(ViewMain==ViewScreen && ActiveViews[j]->IsSwapPossible()){ViewMain = ActiveViews[j];}
124 ActiveViews[j]->Reshape(WINDOW_WIDTH,WINDOW_HEIGHT);
125 ActiveViews[j]->displayFunc_ = &display2;
126 }
127 ViewMain->IsActive = true;
128 geom->updateGeomToDisplay((void*)frogObjects_);
129
130 ViewMenu = new FROG_View_Menu("ViewMenu2",frogObjects_);
131 ViewMenu->Reshape(WINDOW_WIDTH,WINDOW_HEIGHT);
132 }break;
133
134
135 case 20:
136 ViewScreen->LoadingInProgress(99.0f,"Preparation for Display",Fonts,LogoTexture);
137
138 glEnable (GL_DEPTH_TEST);
139
140 glFrontFace(GL_CCW);
141 glEnable(GL_CULL_FACE);
142
143 glEnable(GL_POINT_SMOOTH);
144 glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
145 //glHint(GL_POINT_SMOOTH_HINT, GL_FASTEST);
146
147 glEnable(GL_LINE_SMOOTH);
148 glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
149 //glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST);
150
151 //glEnable(GL_POLYGON_SMOOTH);
152 //glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
153
154 glEnable(GL_BLEND) ;
155 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ;
156
157
158 mLoading = false;
159 end = time ( NULL );
160 printf("Loading Time = %isec\n",(int)(end-start));
161
162 glutDisplayFunc (display);
163 glutIdleFunc (display);
164
165 glutKeyboardFunc (processNormalKeys);
166 glutSpecialFunc (processSpecialKeys);
167
168 glutMouseFunc(processMouse);
169 glutMotionFunc(processMotion);
170 if(SCREENSAVER){
171 eventTime = 20;
172 glutPassiveMotionFunc(processPassiveMotion);
173 glutFullScreen();
174 }
175
176
177 if(SHOOTER){
178 mAutomaticShooter_LastEvent = events->Current_Event;
179 do{
180 frogObjects_->selectedObject_ = NULL;//mCLicked_DetId = (unsigned int) -1;
181 for(unsigned int j=0;j<ActiveViews.size();j++){ActiveViews[j]->MarkForUpdate();}
182 for(unsigned int i=0;i<4;i++)display();
183 char temp[255]; sprintf(temp,"AutomaticShooter_%04i.%s",SCREENSHOT,SCREENSHOT_FORMAT);
184 SaveScreenshot(temp,WINDOW_WIDTH,WINDOW_HEIGHT, display);
185 SCREENSHOT++;
186 event = events->NextEvent();
187 }while(events->Current_Event!=mAutomaticShooter_LastEvent);
188 exit(0);
189 }
190
191 return;
192 break;
193
194 default:
195 break;
196 }
197
198 mLoading_I++;
199}
200
201void reshape (int w, int h)
202{
203 if (h == 0) h = 1;
204
205 WINDOW_WIDTH = w;
206 WINDOW_HEIGHT = h;
207
208 if(ViewScreen)ViewScreen->Reshape(WINDOW_WIDTH,WINDOW_HEIGHT);
209 for(unsigned int j=0;j<ActiveViews.size();j++){
210 ActiveViews[j]->Reshape(WINDOW_WIDTH,WINDOW_HEIGHT);
211 }
212 if(ViewMenu)ViewMenu->Reshape(WINDOW_WIDTH,WINDOW_HEIGHT);
213
214 glutPostRedisplay ();
215}
216
217void displaytext()
218{
219 glColor4fv (Txt_Color);
220 Fonts->Font_Fixed_9_by_15->glPrint(WINDOW_WIDTH-126,WINDOW_HEIGHT - 30,"% 10i FPS", ViewScreen->FPS);
221 if(mHelpScreen){
222 if(events) Fonts->Font_Fixed_9_by_15->glPrint(0,WINDOW_HEIGHT - 14,"CurrentFile = ...%s",events->CurrentFile());
223
224 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 45 ,"F1 = Open this Screen for Help");
225 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 60 ,"F2 = Open the Display Menu");
226 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 75 ,"F3 = use only for debug");
227 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 90 ,"F4 = Automatic ScreenShooter (Warning)");
228
229 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 125 ,"F5 = SimTrack : ON/OFF");
230 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 140 ,"F6 = SimVertex : ON/OFF");
231 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 155 ,"F7 = PSimHits : ON/OFF");
232 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 170 ,"F8 = RecoTrack : ON/OFF");
233
234 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 205 ,"F9 = SiStripCluster : ON/OFF");
235 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 220 ,"F10 = EcalHits : ON/OFF");
236 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 235 ,"F11 = HcalHits : ON/OFF");
237 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 250 ,"F12 = MuonHit/Seg : ON/OFF");
238
239 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 285 ,"0 = Geometry to Display : NONE");
240 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 300 ,"9 = Geometry to Display : FULL");
241
242 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 335 ,"LEFT = Previous Event");
243 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 350 ,"RIGHT = Next Event");
244 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 375 ,"UP = Increase Rotation");
245 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 390 ,"DOWN = Decrease Rotation");
246
247 Fonts->Font_Fixed_9_by_15->glPrint(500,WINDOW_HEIGHT - 375 ,"PAGE UP = Previous VisFile");
248 Fonts->Font_Fixed_9_by_15->glPrint(500,WINDOW_HEIGHT - 390 ,"PAGE DOWN = Next VisFile");
249
250 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 425 ,"p = Zoom In");
251 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 440 ,"m = Zoom Out");
252 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 455 ,"f = Maximize the active view");
253 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 470 ,"s = SlideShow : ON/OFF");
254 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 485 ,"t = TreeMenu : ON/OFF");
255
256 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 515 ,"ENTER = Screenshot");
257 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 530 ,"SPACE = Rotation : ON/OFF");
258 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 545 ,"ESCAPE = Exit");
259 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 560 ,"q = Exit");
260 Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 575 ,"a = Full Screen");
261
262 Fonts->Font_Fixed_9_by_15->glPrint(120,3,"This program has been created by Loic Quertenmont, loic.quertenmont@cern.ch");
263 }else{
264 Fonts->Font_Fixed_9_by_15->glPrint(WINDOW_WIDTH-153,WINDOW_HEIGHT - 14,"Press F1 for Help");
265 if(event) Fonts->Font_Fixed_9_by_15->glPrint(0,WINDOW_HEIGHT - 14,"#Run %i #Event %i (%02i/%02i)",event->NRun_, event->NEvent_, events->Current_Event, (int)events->NumberOfEvents()-1);
266 if(event) Fonts->Font_Fixed_9_by_15->glPrint(0,WINDOW_HEIGHT - 29,"%s", event->EventDate_);
267
268
269 char temp[255];
270 if(frogObjects_->selectedObject_){
271 frogObjects_->selectedObject_->printInfos(temp);
272 if(frogObjects_->IsSelected_Geometry())sprintf(temp,"%s : Press '1' or '2' or ... to Display the parent object",temp);
273 Fonts->Font_Helvetica_10->glPrint(120,3,temp);
274 }
275
276 }
277
278 ViewScreen->DrawLogo(0,0,120,80,LogoTxtTexture, Fonts);
279}
280
281void displayForScreenShot()
282{
283 display2();
284 ViewMain->DisplayBkgGeom();
285}
286
287void display2()
288{
289 // Display the FrameWork
290 if(ZAxis_Color[3]>0){
291 glColor4fv (ZAxis_Color);
292 glLineWidth(ZAxis_Thickness);
293 glBegin (GL_LINES);
294 glNormal3f(0,1,0);
295 glVertex3f (0,0,-300);
296 glVertex3f (0,0,300);
297 glEnd();
298 glLineWidth(1);
299 }
300
301 // Display the 3D Geometry (only if in a 3D View)
302 if(geom!=NULL){// && ViewMain->Type_==VIEW3D){
303 if(Geometry_WireFrame){
304 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
305 }else{
306 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
307 }
308 geom->display();
309 }
310
311 // Display the Event
312 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
313 if(event!=NULL) event->display();
314}
315
316
317void display()
318{
319 //-------- update event file if required ------------
320 //updateEventsFile();
321
322 glClearColor(BackGround_Color[0],BackGround_Color[1],BackGround_Color[2],1.0);
323 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Reset le buffer de couleur et de profondeur
324
325 if(ViewMenu->AlphaFx<1){
326 ViewMain->Display();
327 if(!ViewMain->screen_flag){
328 for(unsigned int j=0;j<ActiveViews.size();j++){
329 if(ActiveViews[j]!=ViewMain && ActiveViews[j]->Type_!=VIEWMENU) ActiveViews[j]->Display();
330 }
331 }
332 if(ViewScreen) ViewScreen->Display();
333 }
334 for(int j=ActiveViews.size()-1;j>=0;j--){
335 if(ActiveViews[j]->Type_==VIEWMENU){ActiveViews[j]->Display();}
336 }
337 ViewMenu->Display();
338
339 glutSwapBuffers();
340
341 SelectedObject_Counter++;
342 if(SelectedObject_Counter>25){
343 SelectedObject_Counter = 0;
344 frogObjects_->selectedObject_DisplayFlag = !frogObjects_->selectedObject_DisplayFlag;
345 }
346
347 fflush(stdout);
348}
349
350void updateEventsFile() {
351// this function lauch a threat to download the input event file
352// if required by the variable updateVisFileTime
353
354/*
355#ifdef windows
356 if( updateVisFileTime>0 && !Thread_Run) {
357 char* argtosend = (char*)inputVisFileFromCard.c_str();
358
359 Thread_H = CreateThread( NULL, 0, WinDownLoadFile, (void*)argtosend, 0, &Thread_Id);
360 if (Thread_H == NULL){
361 printf("Unable to create thread\n");
362 exit(1);
363 }
364 Thread_Run = true;
365 }
366
367 static time_t upstart = time (NULL );
368 time_t upstop = time( NULL );
369 if(upstop - upstart > updateVisFileTime && Thread_Run) {
370 if(WaitForSingleObject(Thread_H, 0) == WAIT_OBJECT_0){
371 Thread_Run=false;
372 glutDisplayFunc (Loading);
373 glutIdleFunc (Loading);
374
375 mLoading_I = 30;
376 mLoading = true;
377 start = time ( NULL );
378 }else{
379 // File is not yet fully downloaded
380 }
381 upstart = time (NULL );
382 }
383#else
384 if( updateVisFileTime>0 && !Thread_Run) {
385 char* argtosend = (char*)inputVisFileFromCard.c_str();
386 if (pthread_create (&Thread_H, NULL, DownLoadFile, (void*)argtosend) < 0) {
387 printf("pthread_create error for Thread_H\n");
388 exit (1);
389 }
390 Thread_Run=true;
391 }
392
393 static time_t upstart = time (NULL );
394 time_t upstop = time( NULL );
395 if(upstop - upstart > updateVisFileTime && Thread_Run) {
396 (void)pthread_join (Thread_H, NULL);
397
398 Thread_Run=false;
399 glutDisplayFunc (Loading);
400 glutIdleFunc (Loading);
401
402 mLoading_I = 30;
403 mLoading = true;
404 start = time ( NULL );
405 }
406
407#endif
408*/
409
410}
411
412void processNormalKeys(unsigned char key, int x, int y)
413{
414 int Mod = glutGetModifiers();
415 if(Mod==GLUT_ACTIVE_CTRL)key+=96;
416
417 switch(key){
418 case 'q':
419 case 27 :
420 exit(0);
421 break;
422 case 13 :{
423 char temp[255]; sprintf(temp,"%s%02i.%s",ScreenShotName,SCREENSHOT,SCREENSHOT_FORMAT);
424 SaveScreenshot(temp,WINDOW_WIDTH,WINDOW_HEIGHT, displayForScreenShot );
425 SCREENSHOT++;
426 }break;
427 case ' ':{
428 if(ViewMain->Type_==VIEW3D) ((FROG_View_3D*)ViewMain)->shouldRotate_ = ! ((FROG_View_3D*)ViewMain)->shouldRotate_;
429 }break;
430 case 'p' :
431 ViewMain->cam_->R*=0.95;
432 break;
433 case 'm' :
434 ViewMain->cam_->R*=1.05;
435 break;
436 case 'r' :
437 case 'R' :
438 LoadCard(inputConfig.c_str());
439/* geom->updateGeomToDisplay(Card);
440 events->prim->setDisplay(0);
441 events->Init(frogObjects_);
442 events->readEventToDisplay(Card);
443*/
444 event = events->GoToEvent(eventNumber);
445
446 break;
447 case 'T' :
448 case 't' :
449 for(int j=ActiveViews.size()-1;j>=0;j--){
450 if(ActiveViews[j]->Type_==VIEWMENU){((FROG_View_Menu*)ActiveViews[j])->State =! ((FROG_View_Menu*)ActiveViews[j])->State;}
451 }
452 break;
453 case 'F' :
454 case 'f' :
455 ViewMain->FullScreen();
456 break;
457 case 'a':
458 case 'l':
459 if( (key=='l' && Mod == GLUT_ACTIVE_CTRL) || key=='a'){
460 if(FULLSCREEN){
461 glutReshapeWindow(SAVE_WINDOW_W, SAVE_WINDOW_H);
462 glutPositionWindow(SAVE_WINDOW_X,SAVE_WINDOW_Y);
463 }else{
464 SAVE_WINDOW_W = glutGet(GLUT_WINDOW_WIDTH);
465 SAVE_WINDOW_H = glutGet(GLUT_WINDOW_HEIGHT);
466 SAVE_WINDOW_X = glutGet(GLUT_WINDOW_X);
467 SAVE_WINDOW_Y = glutGet(GLUT_WINDOW_Y);
468 glutFullScreen();
469 }
470 FULLSCREEN = !FULLSCREEN;
471 }
472 break;
473 case 's':
474 mEventChanging = !mEventChanging;
475 break;
476 case '0' : geom->prim->setDisplay(0);
477 break;
478
479 case '9' : geom->prim->setDisplay(1);
480 break;
481
482 case '1' :
483 case '2' :
484 case '3' :
485 case '4' :
486 case '5' :
487 case '6' :
488 case '7' :
489 case '8' :
490 if(frogObjects_->IsSelected_Geometry()){
491 frogObjects_->selectedObject_->toogleParentDisplay(1,key-48);
492 geom->prim->setDisplay(2);
493 }
494 break;
495 }
496 if(SCREENSAVER)exit(0);
497}
498
499
500void processSpecialKeys(int key, int x, int y)
501{
502 if(ViewMenu->State){
503 if(ViewMenu->processSpecialKeys(key,x,y))return;
504 }
505
506 int Mod = glutGetModifiers();
507// if(Mod==GLUT_ACTIVE_CTRL)key+=96;
508
509 switch(key) {
510 case GLUT_KEY_F1 :
511 mHelpScreen = !mHelpScreen;
512 break;
513 case GLUT_KEY_F2 :
514 ViewMenu->State = !ViewMenu->State;
515 ViewMenu->Alpha = 1;
516 break;
517
518 case GLUT_KEY_F3 :
519 if(event) event->SuperCleardisplayList();
520 break;
521
522 case GLUT_KEY_F4 :
523 mAutomaticShooter = !mAutomaticShooter;
524 if(mAutomaticShooter){
525 AutomaticEventChanging(0);
526 mAutomaticShooter_LastEvent = events->Current_Event;
527 }
528 break;
529
530 case GLUT_KEY_F5 :
531 events->updateEventToDisplay(EVTID_SIMTRK);
532 break;
533 case GLUT_KEY_F6 :
534 events->updateEventToDisplay(EVTID_SIMVTX);
535 break;
536 case GLUT_KEY_F7 :
537 events->updateEventToDisplay(EVTID_SIMHIT);
538 break;
539 case GLUT_KEY_F8 :
540 events->updateEventToDisplay(EVTID_TRK);
541 break;
542 case GLUT_KEY_F9 :
543 events->updateEventToDisplay(EVTID_SISTRIPCLUSTER);
544 break;
545 case GLUT_KEY_F10 :
546 events->updateEventToDisplay(EVTID_ECALHIT);
547 break;
548 case GLUT_KEY_F11:
549 events->updateEventToDisplay(EVTID_HCALHIT);
550 break;
551 case GLUT_KEY_F12 :
552 events->updateEventToDisplay(EVTID_MUONHIT);
553 events->updateEventToDisplay(EVTID_MUONSEG);
554 break;
555 case GLUT_KEY_RIGHT :
556 if(Mod==GLUT_ACTIVE_CTRL){
557 ViewMain->cam_->Move(-5,0);
558 }else{
559 frogObjects_->selectedObject_ = NULL;
560 event = events->NextEvent();
561 }
562 break;
563 case GLUT_KEY_LEFT :
564 if(Mod==GLUT_ACTIVE_CTRL){
565 ViewMain->cam_->Move(5,0);
566 }else{
567 frogObjects_->selectedObject_ = NULL;
568 event = events->PreviousEvent();
569 }
570 break;
571 case GLUT_KEY_UP :
572 if(Mod==GLUT_ACTIVE_CTRL){
573 ViewMain->cam_->Move(0,5);
574 }else{
575 if(ViewMain->Type_==VIEW3D) ((FROG_View_3D*)ViewMain)->dphi_ += 0.005f;
576 }
577 break;
578 case GLUT_KEY_DOWN :
579 if(Mod==GLUT_ACTIVE_CTRL){
580 ViewMain->cam_->Move(0,-5);
581 }else{
582 if(ViewMain->Type_==VIEW3D) ((FROG_View_3D*)ViewMain)->dphi_ -= 0.005f;
583 }
584 break;
585
586 case GLUT_KEY_PAGE_UP :
587 events->NextFile();
588 event = events->GoToEvent(0);
589 break;
590 case GLUT_KEY_PAGE_DOWN :
591 events->PreviousFile();
592 event = events->GoToEvent(0);
593 break;
594
595 case GLUT_KEY_HOME :
596 if(ViewMain->Type_==VIEW3D) ViewMain->cam_->Reset();
597 break;
598 case GLUT_KEY_END :
599 event = events->GoToEvent(-1);
600 break;
601 }
602 if(SCREENSAVER)exit(0);
603}
604
605void processMouse(int button, int state, int x, int y)
606{
607 if(ViewMenu->processMouse(button, state,x,y) ){
608 events->keepEventToDisplay(NULL);
609 events->keepOpenedMenu(NULL);
610 return;
611 }
612
613 for(int j=ActiveViews.size()-1;j>=0;j--){
614 if(ActiveViews[j]->Type_ == VIEWMENU && ActiveViews[j]->IsInViewPort(x,y)){
615 if( ((FROG_View_Menu*)ActiveViews[j])->processMouse(button, state,x,y)){
616 events->keepEventToDisplay(NULL);
617 events->keepOpenedMenu(NULL);
618 return;
619 }
620 }
621 }
622
623 int K = 0;
624 if(button == GLUT_LEFT_BUTTON){
625 K = 0;
626 if(state == GLUT_DOWN){
627 int ClickedView = -1;
628 for(int j=ActiveViews.size()-1;j>=0;j--){
629 if(ActiveViews[j]!= ViewMain && ActiveViews[j]->IsInViewPort(x,y) && ActiveViews[j]->IsSwapPossible()){
630 ClickedView = j;
631 break;
632 }
633 }
634 if(ClickedView>=0){
635 FROG_VIEW::Swap(ViewMain, ActiveViews[ClickedView]);
636 ViewMain->IsActive = false;
637 ViewMain = ActiveViews[ClickedView];
638 ViewMain->IsActive = true;
639 }else if(ViewMain->IsInViewPort(x,y)){
640 gl_select(x,WINDOW_HEIGHT-y);
641 }
642 }
643 }else if(button == GLUT_MIDDLE_BUTTON ){
644 K = 1;
645 }else if(button == GLUT_RIGHT_BUTTON){
646 K = 2;
647 }else{
648 }
649
650 bool old_state = MouseStates[K];
651 if(state == GLUT_DOWN) MouseStates[K] = true;
652 if(state == GLUT_UP) MouseStates[K] = false;
653
654 if( old_state != MouseStates[K]) stateChanged=true;
655 else stateChanged=false;
656}
657
658void processMotion(int x, int y) {
659 static int xold=x, yold=y;
660 if( stateChanged ) { xold=x; yold=y; stateChanged=false; return; }
661
662 if(MouseStates[2]){
663 if(ViewMain->Is3D()){
664 ViewMain->cam_->phi = ViewMain->cam_->phi + 10.0*((float)(xold-x)/(float)ViewMain->cam_->R);
665 ViewMain->cam_->theta = ViewMain->cam_->theta + 10.0*((float)(yold-y)/(float)ViewMain->cam_->R);
666 }else if(ViewMain->Is2D()){
667 ViewMain->cam_->Move((x-xold),(y-yold));
668 }
669 xold=x; yold=y;
670 }else if(MouseStates[1]){
671 if(yold-y>0){
672 ViewMain->cam_->R*=0.98;
673 }else{
674 ViewMain->cam_->R*=1.02;
675 }
676 }
677}
678
679void processPassiveMotion(int x, int y)
680{
681 static int xold=x;
682 static int yold=y;
683 if(SCREENSAVER && (abs(x-xold)>3 || abs(y-yold)>3) )exit(0);
684}
685
686 void gl_select(int x, int y)
687 {
688 ViewMain->Display_Begin();
689
690 GLuint buff[1024] = {0};
691 GLint hits, view[4];
692
693 glSelectBuffer(1024, buff);
694 glGetIntegerv(GL_VIEWPORT, view);
695 glRenderMode(GL_SELECT);
696 glInitNames();
697 glPushName(0);
698
699 glMatrixMode(GL_PROJECTION);
700 glPushMatrix();
701 glLoadIdentity();
702 gluPickMatrix(x-4, y-4, 8.0, 8.0, view);
703 ViewMain->ProjectionMatrix();
704 glMatrixMode(GL_MODELVIEW);
705 glutSwapBuffers();
706 ViewMain->Display_Core();
707 glMatrixMode(GL_PROJECTION);
708 glPopMatrix();
709
710 hits = glRenderMode(GL_RENDER);
711 list_hits(hits, buff);
712 glMatrixMode(GL_MODELVIEW);
713 }
714void list_hits(GLint hits, GLuint *names)
715 {
716 unsigned int i;
717// names[i * 4 + 0] = 1 names[i * 4 + 1] = MinZ
718// names[i * 4 + 3] = Name names[i * 4 + 2] = MaxZ
719
720 //get Min in Z;
721// unsigned int MinZ = (unsigned int)-1;
722// unsigned int NearestHit = 0;
723// for (i = 0; i < hits; i++){
724// if( names[i*4+1]<MinZ ){MinZ=names[i*4+1]; NearestHit = i;}
725// }
726
727 if(hits==0)return;
728 unsigned int NearestHit = rand()%hits;
729
730 for (i = 0; (int)i < hits; i++) {
731 unsigned int tmp = names[i * 4 + 3];
732 //printf("--> %i/%i > %i\n",i,hits,tmp);
733 if(i == NearestHit && tmp!=0){
734 if(tmp>1000000){
735 frogObjects_->selectedObject_ = dynamic_cast<FROG_Element_Base_With_DetId*>(geom->FindByDetId(tmp));
736 }else if(event && tmp<event->name_map.size()){
737 frogObjects_->selectedObject_ = event->name_map[tmp];
738 }
739 }
740 }
741 }
742
743void LoadCard(const char* inputCard ){
744 if(Card)delete Card;
745 Card = new FROG_ReadCards(AbsolutePath.c_str(),inputCard);
746
747 Card->GetInt (&updateVisFileTime , "updateVisFileTime");
748
749 Card->GetInt (&eventNumber , "Event_Number");
750 Card->GetInt (&eventTime , "Event_Time");
751 if(eventTime>=0)glutTimerFunc(1+eventTime*1000,AutomaticEventChanging, 0);
752
753 Card->GetChar (SCREENSHOT_FORMAT,256, "Screenshot_Format");
754 Card->GetChar (ScreenShotName,1024 , "Screenshot_Name");
755
756 Card->GetColor(BackGround_Color , "BackGround_Color");
757 Card->GetColor(Txt_Color , "Txt_Color");
758 Card->GetColor(Framework_Color , "Framework_Color");
759 Card->GetFloat(&Framework_Thickness , "Framework_Thickness");
760 Card->GetColor(ZAxis_Color , "ZAxis_Color");
761 Card->GetFloat(&ZAxis_Thickness , "ZAxis_Thickness");
762
763 Geometry_WireFrame = Card->GetBool(Geometry_WireFrame,"Geometry_WireFrame");
764}
765
766
767void AutomaticEventChanging (int Extra)
768{
769 if(mLoading || (!mAutomaticShooter && (ViewMenu->State || !mEventChanging))){glutTimerFunc(1+eventTime*1000,AutomaticEventChanging, 0);return;}
770
771 frogObjects_->selectedObject_ = NULL;
772 if(mAutomaticShooter){
773 for(unsigned int j=0;j<ActiveViews.size();j++){
774 ActiveViews[j]->MarkForUpdate();
775 }
776 display();
777 display();
778 char temp[255]; sprintf(temp,"AutomaticShooter_%04i.%s",SCREENSHOT,SCREENSHOT_FORMAT);
779 SaveScreenshot(temp,WINDOW_WIDTH,WINDOW_HEIGHT, display);
780 SCREENSHOT++;
781 }
782
783 if(!mLoading && events){
784 if(event && eventNumber>=0){event = events->NextEvent();
785 }else if(eventNumber<0 ){event = events->GoToEvent(-1);}
786 }
787 if(!mAutomaticShooter){
788 if(eventTime>=0)glutTimerFunc(1+eventTime*1000,AutomaticEventChanging, 0);
789 }else{
790 if(mAutomaticShooter_LastEvent == events->Current_Event){
791 mAutomaticShooter = false;
792 }else{
793 glutTimerFunc(25,AutomaticEventChanging, 0);
794 }
795 }
796
797 EventI++;
798 if(event && events)printf("%8u | Run %4i Event %4i | Event %4i in File Containing %4i Events\n",EventI,event->NRun_,event->NEvent_,events->Current_Event, (int)events->NumberOfEvents());
799}
800
801
802int main (int argc, char *argv[])
803{
804 string ExePath = string(argv[0]);
805 unsigned int n = ExePath.rfind("frog");
806 AbsolutePath = ExePath.substr(0,n);
807
808
809 for(int i=1;i<argc;i++){
810 unsigned int len = strlen(argv[i]);
811
812 //Change to lowerCase
813 char LowCase[2048];
814 strcpy(LowCase,argv[i]);
815 for(unsigned int j=0;j<len;j++){
816 if(LowCase[j]>=65 && LowCase[j]<=90)LowCase[j]+=32;
817 }
818
819 if( strcmp(LowCase,"-shooter" )==0){SHOOTER = true;
820 }else if(strcmp(LowCase,"-s" )==0){SCREENSAVER = true;
821 }else if(strcmp(LowCase,"-v" )==0){
822 printf("Fast and Realistic OpenGl Event Display : FROG\n");
823 printf("Version : %6.3f of %s\n",FROG_VERSION,__DATE__);
824 printf("Authors List : \n");
825 printf("%s\n",FROG_AUTHORLIST);
826 exit(0);
827 }else if(strcmp(LowCase,"-c" )==0 && i+1<argc){
828 i++; inputConfig = string(argv[i]);
829 }else if(len>=4 && strcmp(LowCase+len-4,".vis" )==0){inputVisFileFromCommand.push_back(string(argv[i]));
830 }else if(len>=7 && strcmp(LowCase+len-7,".vis.gz")==0){inputVisFileFromCommand.push_back(string(argv[i]));
831 }else{
832 printf("\n");
833 printf("#######################################################################\n");
834 printf("# http://projects.hepforge.org/frog/ #\n");
835 printf("# Please have a look at the website for latest versions and news #\n");
836 printf("# Also register to the Frog mailing list if you are not a member yet #\n");
837 printf("#######################################################################\n");
838 printf("# HELP SCREEN #\n");
839 printf("#######################################################################\n");
840 printf("# Supported Commands are : #\n");
841 printf("# filename.vis --> open the file : filename.vis #\n");
842 printf("# filename.vis.gz --> open the file : filename.vis.gz #\n");
843 printf("# -help --> Print this screen #\n");
844 printf("# -v --> Print Version and Other Info #\n");
845 printf("# -s --> ScreenSaver Mode #\n");
846 printf("# -c <config.txt> --> Specify the Frog Configuration Card to use #\n");
847 printf("# -shooter --> Scan events, make a screenshot and exit #\n");
848 printf("#######################################################################\n");
849 printf("\n");
850 exit(0);
851 }
852 }
853
854 // initialisation de GLUT
855 glutInit (&argc, argv);
856
857 // création d'une fenêtre OpenGL RVBA avec en simple mémoire tampon
858 // avec un tampon de profondeur
859 glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
860 glutInitWindowSize (WINDOW_WIDTH, WINDOW_HEIGHT);
861 glutCreateWindow ("FROG Displayer");
862
863 // Charge le logo en mémoire
864 LoadTexture((unsigned int*)&LogoTexture ,FROG_PATH::GetGlobalPath("Resources/Frog_Logo.png" ,AbsolutePath.c_str()).c_str());
865 LoadTexture((unsigned int*)&LogoTxtTexture ,FROG_PATH::GetGlobalPath("Resources/Frog_LogoTxt.png",AbsolutePath.c_str()).c_str());
866
867 // initialisation des fonctions callback appelées par glut
868 // pour respectivement le redimensionnement de la fenêtre
869 // et le rendu de la scène
870 glutReshapeFunc (reshape);
871 glutDisplayFunc (Loading);
872 glutIdleFunc (Loading);
873
874
875 // initialisation of GLEW (OpenGL Extension Wrangler Library)
876 GLenum err = glewInit();
877 if(GLEW_OK != err){
878 printf("Problem: glewInit failed, something is seriously wrong\n");
879 printf("Error: %s\n", glewGetErrorString(err));
880 exit(0);
881 }
882
883 // entre dans la boucle d'évènements
884 glutMainLoop ();
885 return 0;
886}
887
888
889
890
Note: See TracBrowser for help on using the repository browser.