Exemple #1
0
valBool executeRexxCls::parseAndExecuteNewFile(fCallContCls &tt)
{
 valBool vb1;
 vb1.b=false;
 char nameF1[MAX_FILE_NAME];
 tt.getName().get_p(nameF1);
 strcat(nameF1,".rex");
 nameF1[MAX_FILE_NAME-1]=NULL;
 bool bb12=false;
 fileParserCls *exfcc= new fileParserCls(nameF1);
 containFileCls *cfc1;
 if((cfc1=exfcc->run(nameF1)))
 {
	if(errorReportCls::noError)  exitProgram(0);
	cfc1->print();
	delete exfcc;
	bb12=true;
 }
 else exitProgram(0);
 if(bb12)
 {
	nameOfFiles[tt.getName()]=noOfFileCompiled;
	listOfFiles[noOfFileCompiled]=cfc1;
	noOfFileCompiled++;
	vb1=executeFile(noOfFileCompiled-1);
 }
 return vb1;
}
Exemple #2
0
/************************************************************************************
 *                                MAIN FUNCTION
 ************************************************************************************/
int main(int argc, char *argv[]) {

	// Initialisation ...
	int out = initialiseScreen();
	if (out)
		return out;
	initialiseCPU();

	// Load ROM file ...
	loadROM("roms/Tetris (W) (V1.0) [!].gb");

	// Print game info ...
	printGameInfo();

	// program main loop
	int done = 0;
	while (!done) {

		updateCPU();
//		drawScreen();
		done = listen();
		manageKeys();
	}

	printf("Exited cleanly\n");
	exitProgram();
	return 0;
}
Exemple #3
0
void menu(vector<Book>& collection)
{
	char exit = 'n'; 
	do
	{
		int item;
		int& ritem = item; 
		string choice;
		cout << " ___________________________________________________________________________________________________ " << endl
			<< "| __________               __     _________        .__  .__                 __  .__                 |" << endl
			<< "| \\______   \\ ____   ____ |  | __ \\_   ___ \\  ____ |  | |  |   ____   _____/  |_|__| ____   ____    |" << endl
			<< "|  |    |  _//  _ \\ /  _ \\|  |/ / /    \\  \\/ /  _ \\|  | |  | _/ __ \\_/ ___\\   __\\  |/  _ \\ /    \\   |" << endl
			<< "|  |    |   (  <_> |  <_> )    <  \\     \\___(  <_> )  |_|  |_\\  ___/\\  \\___|  | |  (  <_> )   |  \\  |" << endl
			<< "|  |______  /\\____/ \\____/|__|_ \\  \\______  /\\____/|____/____/\\___  >\\___  >__| |__|\\____/|___|  /  |" << endl
			<< "|_________\\/___________________\\/_________\\/______________________\\/_____\\/____________________\\/___|" << endl
			<< "|                                                                                                   |" << endl
			<< "|1.View Collection			        2.Add Book			      3.Delete Book |" << endl
			<< "|4.Search Collection				5.Save to File			      6.Exit Program|" << endl
			<< "|___________________________________________________________________________________________________|" << endl
			<< "\t\t\tEnter a number to access a menu item:\t";
		//addBook(collection); 
		getline(cin, choice);
		try
		{
			ritem = stoi(choice);
		}
		catch (invalid_argument e)
		{
			cout << "Please enter a digit\n";
			system("pause");  
		}
		switch (item) 
		{
		case 1:
			viewCollection(collection); 
			system("pause");
			break;
		case 2:
			addBook(collection);
			break;
		case 3:
			deleteBook(collection); 
			break;
		case 4:
			searchBook(collection); 
			system("pause");  
			break;
		case 5:
			saveCollection(collection); 
			break;
		case 6:
			exit = exitProgram(); 
			break;  
		default:
			cout << "Enter a number associated with a menu item (1-6).\n";
		}
		system("cls"); 
	}while(exit == 'n'); 
} // menu function
Exemple #4
0
void exprContainCls::error(char *pp1)
{
  cout<<" noVInStack"<<noVInStack<<"max "<<maxVal<<endl;
	for(int i1=0;i1<noVInStack;i1++)
		cout<<pop()<<endl;
	 myDebugKey(1,pp1);
	exitProgram(0);
}
Exemple #5
0
void parserCls::addNextLine(int curStmtNo)
{
 addToValInt();
 css->ecs.evalSize();
 cpc->ccs[curStmtNo]=css;
 if(curStmtNo>DEMO_HEHEHEHEHEHHEHEH)
	 exitProgram(0);
}
Exemple #6
0
int main(int argc, char * argv[])
{
  printf("entered main\n");
  pthread_t threads[NUM_THREADS] = { 0 };
  printf("after threads\n");
  int pthreads[NUM_THREADS] = { 1,2,3 };

  int creator;
  printf("after creator\n");

  for (creator = 0;creator < NUM_THREADS;creator++)
    {
      printf("in for iteration:%d\n",creator+1);
      if(!pthread_create(&(threads[creator]),0,foo,(void*)(&(pthreads[creator]))))
        {
          perror("pthread_create");
        }
      printf("after pthread_create\n");
    }
  for (creator = 0;creator < NUM_THREADS;creator++)
    {
      printf("threads element #%d is %d\n",creator,(threads[creator]));
    }
  printf("after for\n");
  setbusy(1);
  printf("after setbusy 1 0\n");
  setbusy(2);
  printf("after setbusy 2 0\n");
  setbusy(1);
  printf("after setbusy 1 1\n");
  setbusy(2);
  printf("after setbusy 2 1\n");
  setbusy(3);
  printf("after setbusy 3 0\n");
  setbusy(1);
  printf("after setbusy 1 2\n");
  setbusy(2);
  printf("after setbusy 2 2\n");
  setbusy(3);
  printf("after setbusy 3 1\n");
  printf("after exitProgram\n");
  exitProgram();
  //sleep(15);
  for (creator = 0;creator < NUM_THREADS;creator++)
    {
      pthread_join(threads[creator],0);
    }

  setbusy(2);
  printf("after setbusy 2 3\n");
  setbusy(3);
  printf("after setbusy 3 2\n");
  setbusy(1);
  printf("after setbusy 1 3\n");

  printf("right before last thing in main\n");
  return 0;
}
Exemple #7
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    gui::MainWindow w;
    w.show();

    QObject::connect(&w,SIGNAL(destroyed()),&a,SLOT(quit()));
    QObject::connect(&w,SIGNAL(exitProgram()),&a,SLOT(quit()));

    return a.exec();
}
Exemple #8
0
// Open a file and checks if the file was opened successfully
FILE* openFile(char* fileName,const char* mode)
{
    FILE* fp = fopen(fileName,mode);

    if (fp == NULL)
    {
        printf("\nFailed to open the file %s\nMake sure the file is located in the specified location.", fileName);
        exitProgram("");
    }
    return fp;
}
Exemple #9
0
Welcom::Welcom(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Welcom)
{
    ui->setupUi(this);
    this->resize(QSize(800, 480));

    this->setWindowFlags(Qt::X11BypassWindowManagerHint);

    connect(ui->btnWelcom, SIGNAL(clicked()), this, SLOT(enterMain()));
    connect(ui->btnAbout,SIGNAL(clicked()),this, SLOT(showAbout()));
    connect(ui->btnExit, SIGNAL(clicked()),this, SLOT(exitProgram()));
}
Exemple #10
0
void Client::menuTool()
{
    menu = menuBar()->addMenu(tr("Menu"));

    connectToServerAction = new QAction("Connect", this);
    connect(connectToServerAction, SIGNAL(triggered()), this, SLOT(showWindowOfConnection()));
    menu->addAction(connectToServerAction);

    disconnectFromServerAction = new QAction("Disconnect", this);
    connect(disconnectFromServerAction, SIGNAL(triggered()), this, SLOT(disconnectFromServer()));
    menu->addAction(disconnectFromServerAction);

    menu->addSeparator();

    quitProgramAction = new QAction("Exit", this);
    connect(quitProgramAction, SIGNAL(triggered()), this, SLOT(exitProgram()));
    menu->addAction(quitProgramAction);
}
Exemple #11
0
void WFrame::manageConnections() {
    
    QObject::connect(c,SIGNAL(exitProgram()),this,SLOT(onExit()));
    QObject::connect(c,SIGNAL(FileLoadedSignal(int)),this,SLOT(FileLoaded(int)));
    QObject::connect(c,SIGNAL(closeMap()),this,SLOT(onCloseMap()));
    QObject::connect(this,SIGNAL(closeMapButtonClicked()),c,SLOT(closeMapClicked()));
    QObject::connect(c,SIGNAL(loadMapSignal()),this,SLOT(loadMap()));
    QObject::connect(c,SIGNAL(noNodesSignal()),this,SLOT(errorNodes()));
    QObject::connect(c,SIGNAL(noOSMSignal()),this,SLOT(errorOSM()));
    QObject::connect(c,SIGNAL(multipleDropSignal()),this,SLOT(multipleDrop()));
    
    //ACTION CONNECTS
    QObject::connect(open,SIGNAL(triggered()),this,SLOT(getFile()));
    QObject::connect(exit,SIGNAL(triggered()),c,SLOT(exitClicked()));
    QObject::connect(closeFile,SIGNAL(triggered()),this,SLOT(checkMap()));
    QObject::connect(about,SIGNAL(triggered()),this,SLOT(showAbout()));
    QObject::connect(links,SIGNAL(triggered()),this,SLOT(showLinks()));
    
}
Exemple #12
0
LRESULT TrayIcon::windowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
	switch (msg) {
		case TRAYICON_MESSAGE:
			switch (lParam) { // that contains the "real" message
				case WM_RBUTTONUP:
				case WM_CONTEXTMENU:
				{
					// Using GetMessagePos() would be way better, but it gives me 0.
					POINT mousePos;
					GetCursorPos(&mousePos);
					showMenu(mousePos);
					return 0;
				}
				case WM_LBUTTONDOWN:
				case NIN_SELECT:
				case NIN_KEYSELECT:
					toggleEnabled();
					return 0;
				case WM_LBUTTONDBLCLK:
					toggleEnabled(); // second click does not register as WM_LBUTTONDOWN
					showConfigDlg();
					return 0;
			}
			break;
		case WM_COMMAND:
			switch (LOWORD(wParam)) { // contains the menu item identifier
				case IDM_ENABLE:
					toggleEnabled();
					return 0;
				case IDM_CONFIGURE:
					showConfigDlg();
					return 0;
				case IDM_EXIT:
					exitProgram();
					return 0;
			}
			break;
	}
	return DefWindowProc(hwnd, msg, wParam, lParam);
}
Exemple #13
0
short initSDL(){
	if(SDL_Init(SDL_INIT_VIDEO )!= 0){
		fprint(stderr,"Unable to initialise SDL: %s\n",SDL_GetError());
		return EXIT_FAILURE;
	}
	
	SDL_DisplayMode current;
	SDL_GetCurrentDisplayMode(0,&current);
	appWindow = SDL_CreateWindow("",
								SDL_WINDOWPOS_UNDEFINED,
								SDL_WINDOWPOS_UNDEFINED,
								WINDOW_W?WINDOW_W:current.w,
								WINDOW_H?WINDOW_H:current.h,
								//SDL_WINDOW_FULLSCREEN );
								SDL_WINDOW_SHOWN );
	if(appWindow == NULL){
		fprint(stderr,"Couldn't create window\n");
		exitProgram(NULL);
		exit(EXIT_FAILURE);
	}
	if(!FORCE_SW_RENDER ) {
		renderer = SDL_CreateRenderer(appWindow,-1, SDL_RENDERER_ACCELERATED);
		//renderer = NULL; This forces using software
		print("Window is hardware accelerated!\n");
	}
	if(!renderer){
		fprint(stderr,"Using software fallback\n");
		renderer = SDL_CreateRenderer(appWindow,-1, SDL_RENDERER_SOFTWARE);
		if(!renderer)
			fprint(stderr,"Cannot init screen\n");
	}
	render.rdr = renderer;
	TTF_Init();
	SDL_SetRenderDrawBlendMode(renderer,SDL_BLENDMODE_BLEND);
		
	return EXIT_SUCCESS;
}
Exemple #14
0
valBool executeRexxCls::callExternalFunction(fCallContCls &tt)
{
 int i1=0;
 valBool ret1;

 if((i1=isInListOfExternal(tt)))
 {ret1=executeFile(i1-1);}
 else if(canOpenNewFile(tt))
	ret1=parseAndExecuteNewFile(tt);
 else
	{
	char sss12[50];
	getNameFile(sss12);
  cout<<" error in file   "<<sss12<<endl;
	getNameProc(sss12);
	 cout<<" error in procedure   "<<sss12<<endl;
	  cout<<" LINE OF ERROR "<<getCurNoLine()<<endl;
	  cout <<" name function is not found     " <<tt.getName()<<endl;
	  myDebugKey(0,"can not execute function ");
	  exitProgram(0);

	}
 return ret1;
}
Exemple #15
0
/* MainWindow::onClose
 * Called when the window is closed
 *******************************************************************/
void MainWindow::onClose(wxCloseEvent& e) {
	if (!exitProgram())
		e.Veto();
}
Exemple #16
0
/*This program provide some elementray calculations for an unknown number
of simple data sets. (The number will be determined at runtime, based on
user input, but it is unknown at coding/compile time.) The data in each set
consists of a number of floating point values, but the number of values to be
entered for each data set will be input by the user.*/
int main(){

	int dataSetNum = 0;
	int optionNum = 0;
	int *ptr;
	float **data;
	int num = 0;
	float min = 0, max = 0, sum = 0, avg = 0;
	int index = 0;

	/* prompt for the number of data set */
	dataSetNum = prompt();

	ptr = calloc(dataSetNum, sizeof(int));
	data = calloc(dataSetNum, sizeof(float *));

	/* generate all data set */
	generate(dataSetNum, ptr, data);

	/* prompt for user options repeatedly */
	num = select();
	while (1){
		optionNum = option();
		switch (optionNum){
			case 1:
				min = minimum(data, num, ptr);
				printf("The minimum value in the data set is: %.2f\n", min);
			break;

			case 2:
				max = maximum(data, num, ptr);
				printf("The maximum value in the data set is: %.2f\n", max);
			break;

			case 3:
				sum = summation(data, num, ptr);
				printf("The sum of this data set is: %.2f\n", sum);
			break;

			case 4:
				sum = summation(data, num, ptr);
				avg = sum / *(ptr+num-1);
				printf("The average of this data set is %.2f\n", avg);
			break;

			case 5:
				bubbleSort(data, num, ptr);
				for(index = 0; index < *(ptr+num-1); index++){
					printf("%.2f\t", *(*(data+num-1)+index) );
				}
				printf("\n");
			break;

			case 6:
				num = select();
			break;

			case 7:
				exitProgram(data, ptr);
			break;

			default:
			break;
		}
	}

	return 0;
}
//////////////////////////////////
// main()
//
int _tmain(int argc, _TCHAR* argv[])
{
//	try_conv();
	if( !initAll() ) 
		exitProgram(-1);

	// Capture and display video frames until a face
	// is detected
	int frame_count = 0;
	while( (char)27!=cvWaitKey(1) )
	{
		//Retrieve next image and 
		// Look for a face in the next video frame
		
		//read into pfd_pVideoFrameCopy
		if (!captureVideoFrame()){
			if (frame_count==0)
				throw exception("Failed before reading anything");
			break; //end of video..
		}
		++frame_count;

		CvSeq* pSeq = 0;
		detectFaces(pfd_pVideoFrameCopy,&pSeq);
		
		//Do some filtration of pSeq into pSeqOut, based on history etc,
		//update data structures (history ,face threads etc.)s
		list<Face> & faces_in_this_frame = FdProcessFaces(pfd_pVideoFrameCopy,pSeq);

		//== draw rectrangle for each detected face ==
		if (!faces_in_this_frame.empty()){	//faces detected (??)
			int i = 0;
			for(list<Face>::iterator face_itr = faces_in_this_frame.begin(); face_itr != faces_in_this_frame.end(); ++face_itr)
			{
				CvPoint pt1 = cvPoint(face_itr->x,face_itr->y);
				CvPoint pt2 = cvPoint(face_itr->x + face_itr->width,face_itr->y + face_itr->height);
				if (face_itr->frame_id == frame_count) //detected for this frame
					cvRectangle( pfd_pVideoFrameCopy, pt1, pt2, colorArr[i++%3],3,8,0);
				else //from a previous frame
					cvRectangle( pfd_pVideoFrameCopy, pt1, pt2, colorArr[i++%3],1,4,0);
			}
		}else{ //no faces detected
			Sleep(100);
		}

		cvShowImage( DISPLAY_WINDOW, pfd_pVideoFrameCopy );
		cvReleaseImage(&pfd_pVideoFrameCopy);
	
	} //end input while
	cout << "==========================================================" << endl;
	cout << "========== Input finished ================================" << endl;
	cout << "==========================================================" << endl << endl;
	
	cout << "Press a key to continue with history playback" <<endl;
	char cc = fgetc(stdin);


	cout << "==========================================================" << endl;
	cout << "==== Playback history + rectangles +                 =====" << endl;
	cout << "==== create output video(s)						  =====" << endl;
	cout << "==========================================================" << endl << endl;
	list<FDHistoryEntry> & pHistory = FdGetHistorySeq();
	
	//== VIDEO WRITER START =====================
	int isColor = 1;
	int fps     = 12;//30;//25;  // or 30
	int frameW  = 640; // 744 for firewire cameras
	int frameH  = 480; // 480 for firewire cameras
	CvVideoWriter * playbackVidWriter=cvCreateVideoWriter((OUTPUT_PLAYBACK_VIDEOS_DIR + "\\playback.avi").c_str(),
								PFD_VIDEO_OUTPUT_FORMAT,
							   fps,cvSize(frameW,frameH),isColor);
	CvVideoWriter *  croppedVidWriter = 0;
	if (!playbackVidWriter) {
		cerr << "can't create vid writer" << endl;
		exitProgram(-1);
	}
	bool wasWrittenToVideo = false;
	//== VIDEO WRITER END =====================

	int index = 0;
	// play recorded sequence----------------------------
	// i.e. just what's in the history
	int playback_counter = 0;

	cout << "start finding consensus rect " << endl;
	//find min max
	bool found =false;
	int min_x = INT_MAX,//pFaceRect->x,
		max_x = 0,//pFaceRect->x+pFaceRect->width,
		min_y = INT_MAX,//pFaceRect->y,
		max_y = 0;//pFaceRect->y+pFaceRect->height;
	for (list<FDHistoryEntry>::iterator itr = pHistory.begin() ; itr != pHistory.end(); ++itr)
	{
		CvSeq* pFacesSeq = itr->pFacesSeq;
		assert(pFacesSeq);
		//TODO Might want to convert to Face here
		CvRect * pFaceRect = (CvRect*)cvGetSeqElem(pFacesSeq, 0); //works only on first rec series
		if (pFaceRect){
			found = true;
			if (pFaceRect->x < min_x) min_x = pFaceRect->x;
			if (pFaceRect->x+pFaceRect->width > max_x) max_x = pFaceRect->x + pFaceRect->width;
			
			if (pFaceRect->y < min_y) min_y = pFaceRect->y;
			if (pFaceRect->y+pFaceRect->height > max_y) max_y =  pFaceRect->y+pFaceRect->height;
		}
	}
	//assert(found); //some rect in history..
	CvRect consensus_rect;
	consensus_rect.x = min_x;
	consensus_rect.y = min_y;
	consensus_rect.width  = max_x - min_x;
	consensus_rect.height = max_y - min_y;

	Sleep(3000); //just to make sure that pruneHistory isn't modifying..
	cout << "start playback loop " << endl;
	int k = 0;
	for (list<FDHistoryEntry>::iterator itr = pHistory.begin() ; itr != pHistory.end(); ++itr)
	{
		cout << ++k << endl;
		//cvResetImageROI(history_itr->pFrame);  //now reset by FDFaceThread
		pfd_pVideoFrameCopy = cvCreateImage( cvGetSize(itr->pFrame ), 8, 3 ); //TODO query image for its properties
		cvCopy( itr->pFrame , pfd_pVideoFrameCopy, 0 );
		CvSeq* pFacesSeq = itr->pFacesSeq;
#ifndef NO_RECTS_ON_PLAYBACK
		for(int i = 0 ;i < pFacesSeq->total ;i++){				
			Face * pFaceRect = (Face*)cvGetSeqElem(pFacesSeq, i);
			assert(pFaceRect != NULL);
			CvPoint pt1 = cvPoint(pFaceRect->x,pFaceRect->y);
			CvPoint pt2 = cvPoint(pFaceRect->x + pFaceRect->width,pFaceRect->y + pFaceRect->height);
			if (itr->frame_id == pFaceRect->frame_id)
				cvRectangle( pfd_pVideoFrameCopy, pt1, pt2,	 colorArr[i%3],3,8,0);
			else
				cvRectangle( pfd_pVideoFrameCopy, pt1, pt2, colorArr[i%3],1,4,0);
		}
#endif
		if (pFacesSeq->total > 0) 
		{	
			assert(found);
			//write 1st sequence if exists to cropped vid
			if (!croppedVidWriter)
				croppedVidWriter=cvCreateVideoWriter((OUTPUT_PLAYBACK_VIDEOS_DIR + "\\cropped_playback.avi").c_str(),
									PFD_VIDEO_OUTPUT_FORMAT,
	 						   fps,cvSize(max_x-min_x,max_y-min_y),isColor);
			assert(croppedVidWriter);


			cvResetImageROI(pfd_pVideoFrameCopy);
			cvSetImageROI(pfd_pVideoFrameCopy,consensus_rect);
			//write cropped image to video file
			IplImage *croppedImg = cvCreateImage(cvGetSize(pfd_pVideoFrameCopy),
								   pfd_pVideoFrameCopy->depth,
								   pfd_pVideoFrameCopy->nChannels);	
			assert(croppedImg);
			cvCopy(pfd_pVideoFrameCopy, croppedImg, NULL);
			assert(croppedVidWriter);
			cvWriteFrame(croppedVidWriter,croppedImg);
			cvReleaseImage(&croppedImg);
		}

		cvShowImage( DISPLAY_WINDOW, pfd_pVideoFrameCopy );
		cvResetImageROI(pfd_pVideoFrameCopy); //CROP_PLAYBACK_FACE
		cvWriteFrame(playbackVidWriter,pfd_pVideoFrameCopy);
		if( (char)27==cvWaitKey(1) ) break;//exitProgram(0);
		Sleep(50);	
		++playback_counter;	
	}

	
	cvReleaseVideoWriter(&playbackVidWriter);
	cvReleaseVideoWriter(&croppedVidWriter);
	exitProgram(0);
	//-----------------------------------------------------------
	//-----------------------------------------------------------
	//-----------------------------------------------------------
}
void DisplayManager::on_commandLinkButton_clicked()
{
    exitProgram();
}
Exemple #19
0
 void error(void)
 {cout<<" max pos in line  "<<endl;exitProgram(0);}
Exemple #20
0
 void error(char *pp1)
 { myDebugKey(0,pp1);
	exitProgram(0);
 }
Exemple #21
0
 void error(int i1,char *p1)
 { myDebugKey(i1, p1);
	exitProgram(0);
 }
Exemple #22
0
void MainController::exitClicked() {
    emit exitProgram();
}
Exemple #23
0
void myDisplay(void)
{
    if (!paused) {
        if (step < time_steps) {
            step++;
            nextStep();
        } else {
            exitProgram();
        }
    }
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    gluLookAt((X-1.0)/2.0, -Y/8.0, (X+Y)/2.6, (X-1.0)/grid_look_x, Y/grid_look_y, 0.0, 0.0, 1.0, 0.0);
    bmax = 0;
    for (int j = 1; j < Y-1; j++) {
        for (int i = 1; i < X-1; i++) {
            b[(j*X)+i] = grid_amp*(p[(j*X)+i]-p0);
            if (b[(j*X)+i] > bmax)
                bmax = b[(j*X)+i];    //set global maximum for grid coloring
        }
    }
    //draw grid
    glPushMatrix();
    glTranslatef((float)X/2, (float)Y/2,0);
    glRotatef((float)grid_rot_x, 1.0f, 0.0f, 0.0f);
    glRotatef((float)grid_rot_z, 0.0f, 0.0f, 1.0f);
    glTranslatef(-(float)X/2, -(float)Y/2, 0);
    for (int j = 0; j < Y-1; j++) {
        for (int i = 0; i < X-1; i++) {
            glBegin(GL_LINES);
            gridColor(i, j);
            glVertex3f((float)i,   (float)j, (float)b[(j*X)+i]);
            gridColor(i+1, j);
            glVertex3f((float)i+1, (float)j, (float)b[(j*X)+i+1]);
            glEnd();
            
            glBegin(GL_LINES);
            gridColor(i, j);
            glVertex3f((float)i, (float)j,   (float)b[(j*X)+i]);
            gridColor(i, j+1);
            glVertex3f((float)i, (float)j+1, (float)b[((j+1)*X)+i]);
            glEnd();
        }
        glBegin(GL_LINES);
        gridColor(X-1, j);
        glVertex3f((float)X-1, (float)j,   (float)b[(j*X)+X-1]);
        gridColor(X-1, j+1);
        glVertex3f((float)X-1, (float)j+1, (float)b[((j+1)*X)+X-1]);
        glEnd();
    }
    for (int i = 0; i < X-1; i++) {
        glBegin(GL_LINES);
        gridColor(i, Y-1);
        glVertex3f((float)i,   (float)Y-1, (float)b[((Y-1)*X)+i]);
        gridColor(i+1, Y-1);
        glVertex3f((float)i+1, (float)Y-1, (float)b[((Y-1)*X)+i+1]);
        glEnd();
    }
    glPopMatrix();
    glutSwapBuffers();
}
Exemple #24
0
char* launchApp(char *appName,int isMenu){
	static int nruns = 0;
	char* tmp = NULL,*script = NULL, *addrBack = NULL;
	if(appName){
		static JSContext *cx = NULL;
		static JSObject *gl = NULL;
		script = fileToString(LIBRARY);
		if(!(cx = JS_NewContext(runtime, 8192))){
			fprint(stderr,"Problem creating runtime\n");
			exit(EXIT_FAILURE);
		}
		JS_SetErrorReporter(cx, reportError);
		//if(!(gl = JS_NewCompartmentAndGlobalObject(cx, &global_class, NULL))){
		
		static struct JSPrincipals def_principles = {0};
		if(!(gl = JS_NewGlobalObject(cx, &global_class, NULL))){
			fprint(stderr,"Problem creating global object\n");
			exit(EXIT_FAILURE);
		}
		JSCompartment *cmp = JS_EnterCompartment(cx, gl);
		
		if (!(JS_InitStandardClasses(cx, gl))){
			fprint(stderr,"Problem creating standard classes\n");
			exit(EXIT_FAILURE);
		}
		if(!JS_DefineFunctions(cx, gl, jsFunctions)){
			fprint(stderr,"Unable to load native functions\n");
			exit(EXIT_FAILURE);
		}
		globalObject = gl;
		char *pathToFile = NULL;
		if(isMenu){
			pathToFile = (char*)malloc(1+strlen(MENU_DIR));
			strcpy(pathToFile,MENU_DIR);
		} else {
			pathToFile = (char*)malloc(strlen(appName) + 1 + strlen(GAMES_DIR));
			strcpy(pathToFile,GAMES_DIR);
			strcat(pathToFile,appName);
			//strcat(pathToFile,"/");
		}
		
		
		JSBool ran = JS_FALSE;
		jsval retVal;
		
		obj.chrootPath = pathToFile;
		
		JS_SetPrivate(cx,gl,&obj);
		
		SDL_FlushEvents(); //clear queue of events before starting a new app.
		if(isMenu && 0 == nruns) {
			//define the property first_run = true;
			JS_DefineProperty(cx,JS_GetGlobalObject(cx),"first_run",BOOLEAN_TO_JSVAL(JS_TRUE),NULL,NULL,0);
		}
		
		if(script){
			loadBaseClasses(appName,pathToFile,cx); //appName is without the extension, appPath needs the directory to chroot
			ran = JS_EvaluateScript(cx, gl, script, strlen(script) , LIBRARY,0, &retVal);
		}
		nruns++;
		
		clearModules(cx);
		JS_GC(JS_GetRuntime(cx));
		JS_LeaveCompartment(cx,cmp);
		//The user requested to quit.
		if(SDL_QuitRequested()){
			if(script)free(script);
			exitProgram(cx);
			exit(EXIT_SUCCESS);
		}

		if(isMenu && (ran == JS_FALSE)){
			if(script) free(script);
			exitProgram(cx);
			exit(EXIT_FAILURE);
		}
		if(ran != JS_FALSE){
			if(JSVAL_IS_STRING(retVal)){
				addrBack = JS_EncodeString(cx,JSVAL_TO_STRING(retVal));
				tmp = (char*)malloc(strlen(addrBack) +1);
				strcpy(tmp,addrBack);
				JS_free(cx,addrBack);
				addrBack = tmp;
			} 
			if(JSVAL_IS_BOOLEAN(retVal) && isMenu){
				if(script) free(script);
				if(pathToFile) free(pathToFile);
				exitProgram(cx);
				exit(EXIT_SUCCESS);
			}
		} else {
			addrBack = NULL;
		}
		if(script) free(script);
		if(pathToFile) free(pathToFile);
		JS_DestroyContext(cx);
		return addrBack;
	}
}
// main()
int main( int argc, char** argv )
{

	int starting = 3;
	int flag=0;
	CvPoint pt;
	int x = 0,diffx=0,prevx=0,initx=0;
	int y = 0,diffy=0,prevy=0,inity=0;
 
  	// Open X display
	Display *display = XOpenDisplay (NULL);
	if (display == NULL)
        {
      		fprintf (stderr, "Can't open display!\n");
      		return -1;
    	}
  
  	// Wait 3 seconds to start
  	printf ("Starting in ");
  		fflush (stdout);
  	while (starting > 0)
    	{
      		printf ("\b\b\b %d...", starting);
      		fflush (stdout);
      		sleep (1);
      		starting--;
    	}
  	printf ("\n");
    IplImage* temp=cvCreateImage(cvSize(80,120),8,3);
	IplImage* pframe1;
	
	CvRect *pHandRect=0,*vrect=NULL;
	capture=cvCaptureFromCAM(0);	
	if( !initAll() ) exitProgram(-1);
	
		int g;
	piframe=cvQueryFrame(capture);
	pframe=invert(piframe);
	pframe1=cvCloneImage(piframe);
	// Capture and display video frames until a hand
	// is detected
	int i=0;
	char c;	
	initPCA();
    char ch;

	x :
	printf("came to x\n");
	while( 1 )
	{		
		// Look for a hand in the next video frame
		pframe=cvQueryFrame(capture);
		pframe1=cvCloneImage(pframe);
    	detect_and_draw(pframe);
		pHandRect = detectHand(pframe);
		
		if((pHandRect)&&(pHandRect->x>4)&&(pHandRect->y>4)&&(pHandRect->x*pHandRect->y<(240*300))&&(pHandRect->x<630)&&(pHandRect->y<470))
		{	
			cvRectangle(pframe1,cvPoint((pHandRect->x-4),pHandRect->y-4),cvPoint((pHandRect->x+pHandRect->width+4),pHandRect->y+pHandRect->height+4),CV_RGB(255,0,0),1,8,0);		
			i++;
		}
		else 
			i=0;
		// Show the display image
		cvShowImage( DISPLAY_WINDOW, pframe1 );
		cvMoveWindow(DISPLAY_WINDOW,0,0);
		c=cvWaitKey(10); 
		if(c==27)
                {   
        	exitProgram(0);
		}
		if(i>=3)
		{	// exit loop when a hand is detected
			if(pHandRect) {
				i=0;
				prevx=pHandRect->x;
				initx=pHandRect->x;
				prevy=pHandRect->y+pHandRect->height;
				flag=3;
				break;
			}
		}
	}

	// initialize tracking
	KalmanFilter kfilter;
	startTracking(pframe, *pHandRect,kfilter);
	// Track the detected hand using CamShift
	while( 1 )
	{
		CvRect handBox;

		// get the next video frame
		pframe=cvQueryFrame(capture);
		pframe1=cvCloneImage(pframe);
		handBox = combi_track(pframe,kfilter);
        int old_ht;
        int a;
		IplImage* temp;
		if(!((handBox.x<0)||(handBox.y<0)||((handBox.x+handBox.width)>pframe->width)||((handBox.y+handBox.height)>pframe->height))) 
        {
            if(handBox.height>(1.3*handBox.width))
            {
                old_ht=handBox.height;
                handBox.height=2.4*handBox.width;
                handBox.y-=handBox.height-old_ht;
            }
            cvSetImageROI(pframe,handBox);
            temp=cvCreateImage(cvGetSize(pframe),8,3);

            cvCopy(pframe,temp,NULL);

	        a=recognize(temp);
	        cvReleaseImage(&temp);
	        if(handBox.height>(2.3*handBox.width))
            {	
            	if(a==3)
            		a=5;
            }
			diffx=handBox.x+(handBox.width/2)-initx;
			diffy=handBox.y+handBox.height-(handBox.width/2)-prevy;
			prevx=handBox.x+(handBox.width/2);
			prevy=handBox.y+handBox.height-(handBox.width/2);

	        cvResetImageROI(pframe);
    		cvRectangle(pframe1,cvPoint(handBox.x,handBox.y),cvPoint(handBox.x+handBox.width,handBox.y+handBox.height),CV_RGB(0,0,255),3,8,0);		
            
	        if(diffx<(-60))
	        {	click(display,1,0);
	        	printf("right click\n");
	        	goto x;
	        }
	        else if(diffx>(60))
	        {
	        	fake(display, 0);
	        	printf("left click\n");
	        	goto x;
	        }
	        else
	        {}

        }
        else
        	goto x;

		cvShowImage( DISPLAY_WINDOW, pframe1 );

		ch=cvWaitKey(10);
		if( ch==27 ) {
			exitProgram(0);			
			break;
		}
		if(ch=='s'){
		    cvSetImageROI(pframe,handBox);
		    cvResize(pframe,temp);
		    cvSaveImage("image6.jpg",temp);
		    cvResetImageROI(pframe);
		}
	}
	return 0;
}