Page MenuHomeHEPForge

frog.cpp
No OneTemporary

frog.cpp

This document is not UTF8. It was detected as Shift JIS and converted to UTF8 for display.
#include "frog.h"
unsigned int EventI = 0;
void Loading()
{
char Buffer[1024];
switch(mLoading_I)
{
case 0:{
printf("\n");
printf("######################################################################\n");
printf("# http://projects.hepforge.org/frog/ #\n");
printf("# Please have a look at the website for latest versions and news #\n");
printf("# Also register to the Frog mailing list if you are not a member yet #\n");
printf("######################################################################\n");
#ifndef FROG_LIGHTING
printf("# FROG_LIGHTING is not defined --> Lighting effects will not be used #\n");
printf("# Modify the MakeFile to define it in order to have nicer pictures #\n");
printf("######################################################################\n");
#endif
printf("\n");
start = time ( NULL );
// TURN Vertical Synchronisation (VSYNC) OFF
// This allow the system to have more than 60 or 75FPS.
//#ifdef windows
// if(WGL_EXT_swap_control){wglSwapIntervalEXT(0);}else{printf("WGL_EXT_swap_control is NOT OK\n");}
//#else
// if(GLX_SGI_swap_control){glXSwapIntervalSGI(0);}else{printf("GLX_SGI_swap_control is NOT OK\n");}
//#endif
// Init the random number generator
srand (time(NULL));
Fonts = new FROG_Fonts();
ViewScreen = new FROG_View_Screen("Screen");
ViewScreen->Reshape(WINDOW_WIDTH,WINDOW_HEIGHT);
sprintf(Buffer,"Reading %s",inputConfig.c_str());
ViewScreen->LoadingInProgress(0.0f,Buffer,Fonts,LogoTexture);
LoadCard(inputConfig.c_str());
if(!Card->IsTagPresent("InputGeom") && !Card->IsTagPresent("InputVisFile")){
printf("There is no .geom file neither than .vis file in the Config card\n");
printf("FROG will stop. Please update the Config card (%s)\n",inputConfig.c_str());
exit(0);
}
}break;
case 1:
ViewScreen->LoadingInProgress(1.0f,"Downloading Geometry\n(if necessary)",Fonts,LogoTexture);
if(Card->IsTagPresent("InputGeom")){
inputGeom = Card->GetStringVector("InputGeom");
for(unsigned int g=0;g<inputGeom.size();g++){
inputGeom[g] = string((char*)DownLoadFile( (char*)inputGeom[g].c_str(), AbsolutePath.c_str() ) );
}
}
break;
case 2:
/*
ViewScreen->LoadingInProgress(10.0f,"Downloading Events\n(if necessary)",Fonts,LogoTexture);
if(inputVisFileFromCard.length()<3 && Card->IsTagPresent("InputVisFile")){
inputVisFileFromCard = Card->GetString("InputVisFile");
}
inputVisFile = string((char*)DownLoadFile( (char*)inputVisFileFromCard.c_str(), AbsolutePath.c_str() ) );
*/
break;
case 3:{
ViewScreen->LoadingInProgress(20.0f,"Loading Geometry",Fonts,LogoTexture);
if(geom)delete geom;
geom = new FROG_Geometry();
if(inputGeom.size()<=0){printf("Error : No Input Geometry File\n");exit(0);}
while(inputGeom.size()>0){
ViewScreen->LoadingInProgress(20.f+30.f/inputGeom.size(),(char*)inputGeom[inputGeom.size()-1].c_str(),Fonts,LogoTexture);
geom->Load((char*)inputGeom[inputGeom.size()-1].c_str());
inputGeom.pop_back();
}
frogObjects_ = new FROG_Objects_Extended(geom,NULL,Card, Fonts);
}break;
case 4:{
ViewScreen->LoadingInProgress(80.0f,"Loading .vis Files",Fonts,LogoTexture);
if(events)delete events;
events = new FROG_Events(frogObjects_);
events->Load(inputVisFileFromCommand);
events->readEventToDisplay(Card);
if(SCREENSAVER)eventNumber = rand()%((int)events->NumberOfEvents());
event = events->GoToEvent(eventNumber);
}break;
case 5:{
ViewScreen->LoadingInProgress(95.0f,"Views Initialisation",Fonts,LogoTexture);
ViewScreen->displayFunc_ = displaytext;
std::vector<string> ViewsName = Card->GetStringVector("ActiveViews");
ViewMain = ViewScreen;
for(unsigned int i=0;i<ViewsName.size();i++){
char* tmp = new char[ViewsName[i].size()+1];
strcpy(tmp,ViewsName[i].c_str());
ActiveViews.push_back(FROG_VIEW::Create(tmp,frogObjects_));
}
ViewScreen->Reshape(WINDOW_WIDTH,WINDOW_HEIGHT);
for(unsigned int j=0;j<ActiveViews.size();j++){
if(ViewMain==ViewScreen && ActiveViews[j]->IsSwapPossible()){ViewMain = ActiveViews[j];}
ActiveViews[j]->Reshape(WINDOW_WIDTH,WINDOW_HEIGHT);
ActiveViews[j]->displayFunc_ = &display2;
}
ViewMain->IsActive = true;
geom->updateGeomToDisplay((void*)frogObjects_);
ViewMenu = new FROG_View_Menu("ViewMenu2",frogObjects_);
ViewMenu->Reshape(WINDOW_WIDTH,WINDOW_HEIGHT);
}break;
case 20:
ViewScreen->LoadingInProgress(99.0f,"Preparation for Display",Fonts,LogoTexture);
glEnable (GL_DEPTH_TEST);
glFrontFace(GL_CCW);
glEnable(GL_CULL_FACE);
glEnable(GL_POINT_SMOOTH);
glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
//glHint(GL_POINT_SMOOTH_HINT, GL_FASTEST);
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
//glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST);
//glEnable(GL_POLYGON_SMOOTH);
//glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
glEnable(GL_BLEND) ;
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ;
mLoading = false;
end = time ( NULL );
printf("Loading Time = %isec\n",(int)(end-start));
glutDisplayFunc (display);
glutIdleFunc (display);
glutKeyboardFunc (processNormalKeys);
glutSpecialFunc (processSpecialKeys);
glutMouseFunc(processMouse);
glutMotionFunc(processMotion);
if(SCREENSAVER){
eventTime = 20;
glutPassiveMotionFunc(processPassiveMotion);
glutFullScreen();
}
if(SHOOTER){
mAutomaticShooter_LastEvent = events->Current_Event;
do{
frogObjects_->selectedObject_ = NULL;//mCLicked_DetId = (unsigned int) -1;
for(unsigned int j=0;j<ActiveViews.size();j++){ActiveViews[j]->MarkForUpdate();}
for(unsigned int i=0;i<4;i++)display();
char temp[255]; sprintf(temp,"AutomaticShooter_%04i.%s",SCREENSHOT,SCREENSHOT_FORMAT);
SaveScreenshot(temp,WINDOW_WIDTH,WINDOW_HEIGHT, display);
SCREENSHOT++;
event = events->NextEvent();
}while(events->Current_Event!=mAutomaticShooter_LastEvent);
exit(0);
}
return;
break;
default:
break;
}
mLoading_I++;
}
void reshape (int w, int h)
{
if (h == 0) h = 1;
WINDOW_WIDTH = w;
WINDOW_HEIGHT = h;
if(ViewScreen)ViewScreen->Reshape(WINDOW_WIDTH,WINDOW_HEIGHT);
for(unsigned int j=0;j<ActiveViews.size();j++){
ActiveViews[j]->Reshape(WINDOW_WIDTH,WINDOW_HEIGHT);
}
if(ViewMenu)ViewMenu->Reshape(WINDOW_WIDTH,WINDOW_HEIGHT);
glutPostRedisplay ();
}
void displaytext()
{
glColor4fv (Txt_Color);
Fonts->Font_Fixed_9_by_15->glPrint(WINDOW_WIDTH-126,WINDOW_HEIGHT - 30,"% 10i FPS", ViewScreen->FPS);
if(mHelpScreen){
if(events) Fonts->Font_Fixed_9_by_15->glPrint(0,WINDOW_HEIGHT - 14,"CurrentFile = ...%s",events->CurrentFile());
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 45 ,"F1 = Open this Screen for Help");
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 60 ,"F2 = Open the Display Menu");
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 75 ,"F3 = use only for debug");
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 90 ,"F4 = Automatic ScreenShooter (Warning)");
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 125 ,"F5 = SimTrack : ON/OFF");
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 140 ,"F6 = SimVertex : ON/OFF");
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 155 ,"F7 = PSimHits : ON/OFF");
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 170 ,"F8 = RecoTrack : ON/OFF");
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 205 ,"F9 = SiStripCluster : ON/OFF");
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 220 ,"F10 = EcalHits : ON/OFF");
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 235 ,"F11 = HcalHits : ON/OFF");
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 250 ,"F12 = MuonHit/Seg : ON/OFF");
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 285 ,"0 = Geometry to Display : NONE");
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 300 ,"9 = Geometry to Display : FULL");
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 335 ,"LEFT = Previous Event");
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 350 ,"RIGHT = Next Event");
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 375 ,"UP = Increase Rotation");
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 390 ,"DOWN = Decrease Rotation");
Fonts->Font_Fixed_9_by_15->glPrint(500,WINDOW_HEIGHT - 375 ,"PAGE UP = Previous VisFile");
Fonts->Font_Fixed_9_by_15->glPrint(500,WINDOW_HEIGHT - 390 ,"PAGE DOWN = Next VisFile");
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 425 ,"p = Zoom In");
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 440 ,"m = Zoom Out");
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 455 ,"f = Maximize the active view");
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 470 ,"s = SlideShow : ON/OFF");
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 485 ,"t = TreeMenu : ON/OFF");
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 515 ,"ENTER = Screenshot");
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 530 ,"SPACE = Rotation : ON/OFF");
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 545 ,"ESCAPE = Exit");
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 560 ,"q = Exit");
Fonts->Font_Fixed_9_by_15->glPrint(150,WINDOW_HEIGHT - 575 ,"a = Full Screen");
Fonts->Font_Fixed_9_by_15->glPrint(120,3,"This program has been created by Loic Quertenmont(loic.quertenmont@cern.ch) and Vincent Roberfroid(vincent.roberfroid@cern.ch)");
}else{
Fonts->Font_Fixed_9_by_15->glPrint(WINDOW_WIDTH-153,WINDOW_HEIGHT - 14,"Press F1 for Help");
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);
if(event) Fonts->Font_Fixed_9_by_15->glPrint(0,WINDOW_HEIGHT - 29,"%s", event->EventDate_);
char temp[255];
if(frogObjects_->selectedObject_){
frogObjects_->selectedObject_->printInfos(temp);
if(frogObjects_->IsSelected_Geometry())sprintf(temp,"%s : Press '1' or '2' or ... to Display the parent object",temp);
Fonts->Font_Helvetica_10->glPrint(120,3,temp);
}
}
ViewScreen->DrawLogo(0,0,120,80,LogoTxtTexture, Fonts);
}
void displayForScreenShot()
{
display2();
ViewMain->DisplayBkgGeom();
}
void display2()
{
// Display the FrameWork
FROG_Light::SwitchLight_NoNormal();
if(XAxis_Color[3]>0){
glColor4fv (XAxis_Color);
glLineWidth(XAxis_Thickness);
glBegin (GL_LINES);
glNormal3f(0,1,0);
glVertex3f(0,0,0);
glVertex3f(300,0,0);
glEnd();
glLineWidth(1);
}
if(YAxis_Color[3]>0){
glColor4fv (YAxis_Color);
glLineWidth(YAxis_Thickness);
glBegin (GL_LINES);
glNormal3f(0,1,0);
glVertex3f (0,0,0);
glVertex3f (0,300,0);
glEnd();
glLineWidth(1);
}
if(ZAxis_Color[3]>0){
glColor4fv (ZAxis_Color);
glLineWidth(ZAxis_Thickness);
glBegin (GL_LINES);
glNormal3f(0,1,0);
glVertex3f (0,0,-300);
glVertex3f (0,0,300);
glEnd();
glLineWidth(1);
}
FROG_Light::SwitchLight_Normal();
// Display the 3D Geometry (only if in a 3D View)
if(geom!=NULL){// && ViewMain->Type_==VIEW3D){
if(Geometry_WireFrame){
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glDisable(GL_CULL_FACE);
}else{
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
if(mOpenGeom){
double equation[] = {sin(-90/57.2958),cos(-90/57.2958),0,0};
glClipPlane(GL_CLIP_PLANE0,equation);
glEnable(GL_CLIP_PLANE0);
//glDisable(GL_CULL_FACE);
geom->display();
double equation2[] = {-sin(30/57.2958),-cos(30/57.2958),0,0};
glClipPlane(GL_CLIP_PLANE0,equation2);
}
geom->display();
if(mOpenGeom){
//glEnable (GL_CULL_FACE);
glDisable(GL_CLIP_PLANE0);
}
if(Geometry_WireFrame){
glEnable(GL_CULL_FACE);
}
}
// Display the Event
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
if(event!=NULL) event->display();
}
void display()
{
//-------- update event file if required ------------
//updateEventsFile();
glClearColor(BackGround_Color[0],BackGround_Color[1],BackGround_Color[2],1.0);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Reset le buffer de couleur et de profondeur
if(ViewMenu->AlphaFx<1){
ViewMain->Display();
if(!ViewMain->screen_flag){
for(unsigned int j=0;j<ActiveViews.size();j++){
if(ActiveViews[j]!=ViewMain && ActiveViews[j]->Type_!=VIEWMENU) ActiveViews[j]->Display();
}
}
if(ViewScreen) ViewScreen->Display();
}
for(int j=ActiveViews.size()-1;j>=0;j--){
if(ActiveViews[j]->Type_==VIEWMENU){ActiveViews[j]->Display();}
}
ViewMenu->Display();
glutSwapBuffers();
SelectedObject_Counter++;
if(SelectedObject_Counter>25){
SelectedObject_Counter = 0;
frogObjects_->selectedObject_DisplayFlag = !frogObjects_->selectedObject_DisplayFlag;
}
fflush(stdout);
}
void updateEventsFile() {
// this function lauch a threat to download the input event file
// if required by the variable updateVisFileTime
/*
#ifdef windows
if( updateVisFileTime>0 && !Thread_Run) {
char* argtosend = (char*)inputVisFileFromCard.c_str();
Thread_H = CreateThread( NULL, 0, WinDownLoadFile, (void*)argtosend, 0, &Thread_Id);
if (Thread_H == NULL){
printf("Unable to create thread\n");
exit(1);
}
Thread_Run = true;
}
static time_t upstart = time (NULL );
time_t upstop = time( NULL );
if(upstop - upstart > updateVisFileTime && Thread_Run) {
if(WaitForSingleObject(Thread_H, 0) == WAIT_OBJECT_0){
Thread_Run=false;
glutDisplayFunc (Loading);
glutIdleFunc (Loading);
mLoading_I = 30;
mLoading = true;
start = time ( NULL );
}else{
// File is not yet fully downloaded
}
upstart = time (NULL );
}
#else
if( updateVisFileTime>0 && !Thread_Run) {
char* argtosend = (char*)inputVisFileFromCard.c_str();
if (pthread_create (&Thread_H, NULL, DownLoadFile, (void*)argtosend) < 0) {
printf("pthread_create error for Thread_H\n");
exit (1);
}
Thread_Run=true;
}
static time_t upstart = time (NULL );
time_t upstop = time( NULL );
if(upstop - upstart > updateVisFileTime && Thread_Run) {
(void)pthread_join (Thread_H, NULL);
Thread_Run=false;
glutDisplayFunc (Loading);
glutIdleFunc (Loading);
mLoading_I = 30;
mLoading = true;
start = time ( NULL );
}
#endif
*/
}
void processNormalKeys(unsigned char key, int x, int y)
{
int Mod = glutGetModifiers();
if(Mod==GLUT_ACTIVE_CTRL)key+=96;
switch(key){
case 'q':
case 27 :
exit(0);
break;
case 13 :{
char temp[255]; sprintf(temp,"%s%02i.%s",ScreenShotName,SCREENSHOT,SCREENSHOT_FORMAT);
SaveScreenshot(temp,WINDOW_WIDTH,WINDOW_HEIGHT, displayForScreenShot );
SCREENSHOT++;
}break;
case ' ':{
if(ViewMain->Type_==VIEW3D) ((FROG_View_3D*)ViewMain)->shouldRotate_ = ! ((FROG_View_3D*)ViewMain)->shouldRotate_;
}break;
case 'p' :
ViewMain->cam_->R*=0.95;
break;
case 'm' :
ViewMain->cam_->R*=1.05;
break;
case 'o' :
mOpenGeom = !mOpenGeom;
break;
case 'r' :
case 'R' :
LoadCard(inputConfig.c_str());
//geom->updateGeomToDisplay(Card);
//events->prim->setDisplay(0);
//events->Init(frogObjects_);
//events->readEventToDisplay(Card);
event = events->GoToEvent(eventNumber);
break;
case 'T' :
case 't' :
for(int j=ActiveViews.size()-1;j>=0;j--){
if(ActiveViews[j]->Type_==VIEWMENU){((FROG_View_Menu*)ActiveViews[j])->State =! ((FROG_View_Menu*)ActiveViews[j])->State;}
}
break;
case 'F' :
case 'f' :
ViewMain->FullScreen();
break;
case 'a':
case 'l':
if( (key=='l' && Mod == GLUT_ACTIVE_CTRL) || key=='a'){
if(FULLSCREEN){
glutReshapeWindow(SAVE_WINDOW_W, SAVE_WINDOW_H);
glutPositionWindow(SAVE_WINDOW_X,SAVE_WINDOW_Y);
}else{
SAVE_WINDOW_W = glutGet(GLUT_WINDOW_WIDTH);
SAVE_WINDOW_H = glutGet(GLUT_WINDOW_HEIGHT);
SAVE_WINDOW_X = glutGet(GLUT_WINDOW_X);
SAVE_WINDOW_Y = glutGet(GLUT_WINDOW_Y);
glutFullScreen();
}
FULLSCREEN = !FULLSCREEN;
}
break;
case 's':
mEventChanging = !mEventChanging;
break;
case '0' : geom->prim->setDisplay(0);
break;
case '9' : geom->prim->setDisplay(1);
break;
case '1' :
case '2' :
case '3' :
case '4' :
case '5' :
case '6' :
case '7' :
case '8' :
if(frogObjects_->IsSelected_Geometry()){
frogObjects_->selectedObject_->toogleParentDisplay(1,key-48);
geom->prim->setDisplay(2);
}
break;
}
if(SCREENSAVER)exit(0);
}
void processSpecialKeys(int key, int x, int y)
{
if(ViewMenu->State){
if(ViewMenu->processSpecialKeys(key,x,y))return;
}
int Mod = glutGetModifiers();
// if(Mod==GLUT_ACTIVE_CTRL)key+=96;
switch(key) {
case GLUT_KEY_F1 :
mHelpScreen = !mHelpScreen;
break;
case GLUT_KEY_F2 :
ViewMenu->State = !ViewMenu->State;
ViewMenu->Alpha = 1;
break;
case GLUT_KEY_F3 :
if(event) event->SuperCleardisplayList();
break;
case GLUT_KEY_F4 :
mAutomaticShooter = !mAutomaticShooter;
if(mAutomaticShooter){
AutomaticEventChanging(0);
mAutomaticShooter_LastEvent = events->Current_Event;
}
break;
case GLUT_KEY_F5 :
events->updateEventToDisplay(EVTID_SIMTRK);
break;
case GLUT_KEY_F6 :
events->updateEventToDisplay(EVTID_SIMVTX);
break;
case GLUT_KEY_F7 :
events->updateEventToDisplay(EVTID_SIMHIT);
break;
case GLUT_KEY_F8 :
events->updateEventToDisplay(EVTID_TRK);
break;
case GLUT_KEY_F9 :
events->updateEventToDisplay(EVTID_SISTRIPCLUSTER);
break;
case GLUT_KEY_F10 :
events->updateEventToDisplay(EVTID_ECALHIT);
break;
case GLUT_KEY_F11:
events->updateEventToDisplay(EVTID_HCALHIT);
break;
case GLUT_KEY_F12 :
events->updateEventToDisplay(EVTID_MUONHIT);
events->updateEventToDisplay(EVTID_MUONSEG);
break;
case GLUT_KEY_RIGHT :
if(Mod==GLUT_ACTIVE_CTRL){
ViewMain->cam_->Move(-5,0);
}else{
frogObjects_->selectedObject_ = NULL;
event = events->NextEvent();
}
break;
case GLUT_KEY_LEFT :
if(Mod==GLUT_ACTIVE_CTRL){
ViewMain->cam_->Move(5,0);
}else{
frogObjects_->selectedObject_ = NULL;
event = events->PreviousEvent();
}
break;
case GLUT_KEY_UP :
if(Mod==GLUT_ACTIVE_CTRL){
ViewMain->cam_->Move(0,5);
}else{
if(ViewMain->Type_==VIEW3D) ((FROG_View_3D*)ViewMain)->dphi_ += 0.005f;
}
break;
case GLUT_KEY_DOWN :
if(Mod==GLUT_ACTIVE_CTRL){
ViewMain->cam_->Move(0,-5);
}else{
if(ViewMain->Type_==VIEW3D) ((FROG_View_3D*)ViewMain)->dphi_ -= 0.005f;
}
break;
case GLUT_KEY_PAGE_UP :
events->NextFile();
event = events->GoToEvent(0);
break;
case GLUT_KEY_PAGE_DOWN :
events->PreviousFile();
event = events->GoToEvent(0);
break;
case GLUT_KEY_HOME :
if(ViewMain->Type_==VIEW3D) ViewMain->cam_->Reset();
break;
case GLUT_KEY_END :
event = events->GoToEvent(-1);
break;
}
if(SCREENSAVER)exit(0);
}
void processMouse(int button, int state, int x, int y)
{
if(ViewMenu->processMouse(button, state,x,y) ){
events->keepEventToDisplay(NULL);
events->keepOpenedMenu(NULL);
return;
}
for(int j=ActiveViews.size()-1;j>=0;j--){
if(ActiveViews[j]->Type_ == VIEWMENU && ActiveViews[j]->IsInViewPort(x,y)){
if( ((FROG_View_Menu*)ActiveViews[j])->processMouse(button, state,x,y)){
events->keepEventToDisplay(NULL);
events->keepOpenedMenu(NULL);
return;
}
}
}
int K = 0;
if(button == GLUT_LEFT_BUTTON){
K = 0;
if(state == GLUT_DOWN){
int ClickedView = -1;
for(int j=ActiveViews.size()-1;j>=0;j--){
if(ActiveViews[j]!= ViewMain && ActiveViews[j]->IsInViewPort(x,y) && ActiveViews[j]->IsSwapPossible()){
ClickedView = j;
break;
}
}
if(ClickedView>=0){
FROG_VIEW::Swap(ViewMain, ActiveViews[ClickedView]);
ViewMain->IsActive = false;
ViewMain = ActiveViews[ClickedView];
ViewMain->IsActive = true;
}else if(ViewMain->IsInViewPort(x,y)){
gl_select(x,WINDOW_HEIGHT-y);
}
}
}else if(button == GLUT_MIDDLE_BUTTON ){
K = 1;
}else if(button == GLUT_RIGHT_BUTTON){
K = 2;
}else{
}
bool old_state = MouseStates[K];
if(state == GLUT_DOWN) MouseStates[K] = true;
if(state == GLUT_UP) MouseStates[K] = false;
if( old_state != MouseStates[K]) stateChanged=true;
else stateChanged=false;
}
void processMotion(int x, int y) {
static int xold=x, yold=y;
if( stateChanged ) { xold=x; yold=y; stateChanged=false; return; }
if(MouseStates[2]){
if(ViewMain->Is3D()){
ViewMain->cam_->phi = ViewMain->cam_->phi + 10.0*((float)(xold-x)/(float)ViewMain->cam_->R);
ViewMain->cam_->theta = ViewMain->cam_->theta + 10.0*((float)(yold-y)/(float)ViewMain->cam_->R);
}else if(ViewMain->Is2D()){
ViewMain->cam_->Move((x-xold),(y-yold));
}
xold=x; yold=y;
}else if(MouseStates[1]){
if(yold-y>0){
ViewMain->cam_->R*=0.98;
}else{
ViewMain->cam_->R*=1.02;
}
}
}
void processPassiveMotion(int x, int y)
{
static int xold=x;
static int yold=y;
if(SCREENSAVER && (abs(x-xold)>3 || abs(y-yold)>3) )exit(0);
}
void gl_select(int x, int y)
{
ViewMain->Display_Begin();
GLuint buff[1024] = {0};
GLint hits, view[4];
glSelectBuffer(1024, buff);
glGetIntegerv(GL_VIEWPORT, view);
glRenderMode(GL_SELECT);
glInitNames();
glPushName(0);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPickMatrix(x-4, y-4, 8.0, 8.0, view);
ViewMain->ProjectionMatrix();
glMatrixMode(GL_MODELVIEW);
glutSwapBuffers();
ViewMain->Display_Core();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
hits = glRenderMode(GL_RENDER);
list_hits(hits, buff);
glMatrixMode(GL_MODELVIEW);
}
void list_hits(GLint hits, GLuint *names)
{
unsigned int i;
// names[i * 4 + 0] = 1 names[i * 4 + 1] = MinZ
// names[i * 4 + 3] = Name names[i * 4 + 2] = MaxZ
//get Min in Z;
// unsigned int MinZ = (unsigned int)-1;
// unsigned int NearestHit = 0;
// for (i = 0; i < hits; i++){
// if( names[i*4+1]<MinZ ){MinZ=names[i*4+1]; NearestHit = i;}
// }
if(hits==0)return;
unsigned int NearestHit = rand()%hits;
for (i = 0; (int)i < hits; i++) {
unsigned int tmp = names[i * 4 + 3];
//printf("--> %i/%i > %i\n",i,hits,tmp);
if(i == NearestHit && tmp!=0){
if(tmp>1000000){
frogObjects_->selectedObject_ = dynamic_cast<FROG_Element_Base_With_DetId*>(geom->FindByDetId(tmp));
}else if(event && tmp<event->name_map.size()){
frogObjects_->selectedObject_ = event->name_map[tmp];
}
}
}
}
void LoadCard(const char* inputCard ){
if(Card)delete Card;
Card = new FROG_ReadCards(AbsolutePath.c_str(),inputCard);
Card->GetInt (&updateVisFileTime , "updateVisFileTime");
Card->GetInt (&eventNumber , "Event_Number");
Card->GetInt (&eventTime , "Event_Time");
if(eventTime>=0)glutTimerFunc(1+eventTime*1000,AutomaticEventChanging, 0);
Card->GetChar (SCREENSHOT_FORMAT,256, "Screenshot_Format");
Card->GetChar (ScreenShotName,1024 , "Screenshot_Name");
Card->GetColor(BackGround_Color , "BackGround_Color");
Card->GetColor(Txt_Color , "Txt_Color");
Card->GetColor(Framework_Color , "Framework_Color");
Card->GetFloat(&Framework_Thickness , "Framework_Thickness");
Card->GetColor(XAxis_Color , "XAxis_Color");
Card->GetFloat(&XAxis_Thickness , "XAxis_Thickness");
Card->GetColor(YAxis_Color , "YAxis_Color");
Card->GetFloat(&YAxis_Thickness , "YAxis_Thickness");
Card->GetColor(ZAxis_Color , "ZAxis_Color");
Card->GetFloat(&ZAxis_Thickness , "ZAxis_Thickness");
Geometry_WireFrame = Card->GetBool(Geometry_WireFrame,"Geometry_WireFrame");
}
void AutomaticEventChanging (int Extra)
{
if(mLoading || (!mAutomaticShooter && (ViewMenu->State || !mEventChanging))){glutTimerFunc(1+eventTime*1000,AutomaticEventChanging, 0);return;}
frogObjects_->selectedObject_ = NULL;
if(mAutomaticShooter){
for(unsigned int j=0;j<ActiveViews.size();j++){
ActiveViews[j]->MarkForUpdate();
}
display();
display();
char temp[255]; sprintf(temp,"AutomaticShooter_%04i.%s",SCREENSHOT,SCREENSHOT_FORMAT);
SaveScreenshot(temp,WINDOW_WIDTH,WINDOW_HEIGHT, display);
SCREENSHOT++;
}
if(!mLoading && events){
if(event && eventNumber>=0){event = events->NextEvent();
}else if(eventNumber<0 ){event = events->GoToEvent(-1);}
}
if(!mAutomaticShooter){
if(eventTime>=0)glutTimerFunc(1+eventTime*1000,AutomaticEventChanging, 0);
}else{
if(mAutomaticShooter_LastEvent == events->Current_Event){
mAutomaticShooter = false;
}else{
glutTimerFunc(25,AutomaticEventChanging, 0);
}
}
EventI++;
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());
}
int main (int argc, char *argv[])
{
#ifdef windows
SetDllDirectory("Lib");
#endif
string ExePath = string(argv[0]);
unsigned int n = ExePath.rfind("frog");
AbsolutePath = ExePath.substr(0,n);
for(int i=1;i<argc;i++){
unsigned int len = strlen(argv[i]);
//Change to lowerCase
char LowCase[2048];
strcpy(LowCase,argv[i]);
for(unsigned int j=0;j<len;j++){
if(LowCase[j]>=65 && LowCase[j]<=90)LowCase[j]+=32;
}
if( strcmp(LowCase,"-shooter" )==0){SHOOTER = true;
}else if(strcmp(LowCase,"-s" )==0){SCREENSAVER = true;
}else if(strcmp(LowCase,"-v" )==0){
printf("Fast and Realistic OpenGl Event Display : FROG\n");
printf("Version : %6.3f of %s\n",FROG_VERSION,__DATE__);
printf("Authors List : \n");
printf("%s\n",FROG_AUTHORLIST);
exit(0);
}else if(strcmp(LowCase,"-c" )==0 && i+1<argc){
i++; inputConfig = string(argv[i]);
}else if(len>=4 && strcmp(LowCase+len-4,".vis" )==0){inputVisFileFromCommand.push_back(string(argv[i]));
}else if(len>=7 && strcmp(LowCase+len-7,".vis.gz")==0){inputVisFileFromCommand.push_back(string(argv[i]));
}else{
printf("\n");
printf("#######################################################################\n");
printf("# http://projects.hepforge.org/frog/ #\n");
printf("# Please have a look at the website for latest versions and news #\n");
printf("# Also register to the Frog mailing list if you are not a member yet #\n");
printf("#######################################################################\n");
printf("# HELP SCREEN #\n");
printf("#######################################################################\n");
printf("# Supported Commands are : #\n");
printf("# filename.vis --> open the file : filename.vis #\n");
printf("# filename.vis.gz --> open the file : filename.vis.gz #\n");
printf("# -help --> Print this screen #\n");
printf("# -v --> Print Version and Other Info #\n");
printf("# -s --> ScreenSaver Mode #\n");
printf("# -c <config.txt> --> Specify the Frog Configuration Card to use #\n");
printf("# -shooter --> Scan events, make a screenshot and exit #\n");
printf("#######################################################################\n");
printf("\n");
exit(0);
}
}
// initialisation de GLUT
glutInit (&argc, argv);
// cr饌tion d'une fen黎re OpenGL RVBA avec en simple m駑oire tampon
// avec un tampon de profondeur
glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize (WINDOW_WIDTH, WINDOW_HEIGHT);
glutCreateWindow ("FROG Displayer");
// Charge le logo en m駑oire
LoadTexture((unsigned int*)&LogoTexture ,FROG_PATH::GetGlobalPath("Resources/Frog_Logo.png" ,AbsolutePath.c_str()).c_str());
LoadTexture((unsigned int*)&LogoTxtTexture ,FROG_PATH::GetGlobalPath("Resources/Frog_LogoTxt.png",AbsolutePath.c_str()).c_str());
// initialisation des fonctions callback appel馥s par glut
// pour respectivement le redimensionnement de la fen黎re
// et le rendu de la sc鈩e
glutReshapeFunc (reshape);
glutDisplayFunc (Loading);
glutIdleFunc (Loading);
// initialisation of GLEW (OpenGL Extension Wrangler Library)
GLenum err = glewInit();
if(GLEW_OK != err){
printf("Problem: glewInit failed, something is seriously wrong\n");
printf("Error: %s\n", glewGetErrorString(err));
exit(0);
}
// entre dans la boucle d'騅鈩ements
glutMainLoop ();
return 0;
}

File Metadata

Mime Type
text/x-c
Expires
Sat, Dec 21, 5:26 PM (12 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4023632
Default Alt Text
frog.cpp (28 KB)

Event Timeline