Fork me on GitHub

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

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

first commit frog

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