Esempio n. 1
0
void ofApp::setup()
{
    std::string path = ofToDataPath("openFrameworks.png", true);

    ofx::IO::ByteBuffer byteBuffer;

    try
    {
        std::streamsize in = ofx::IO::ByteBufferUtils::loadFromFile(path, byteBuffer);

        ofLogNotice("ofApp::setup") << in << " bytes read.";

        std::string newPath = ofToDataPath("openFrameworks_copy.png", true);

        bool result = ofx::IO::ByteBufferUtils::saveToFile(byteBuffer, newPath);

        if (result)
        {
            ofLogNotice("ofApp::setup") << "File written to " << newPath;
        }
        else
        {
            ofLogError("ofApp::setup") << "File not written bytes written.";
        }
    }
    catch (Poco::Exception& exception)
    {
        ofLogError("ofApp::setup") << "Exception: " << exception.displayText();
    }

    ofExit();

}
Esempio n. 2
0
//--------------------------------------------------------------
void testApp::keyPressed(int key){
	if ((key=='R')||(key=='r')){
		if(!IsRecording){  

			string realfile = "data/record.wav";  
			printf("start recording!\n");  
			printf("file = %s\n", realfile.c_str());  

			wavWriter.open(realfile, WAVFILE_WRITE);  

			IsRecording = true;  
		}  
	}

	if ((key=='S')||(key=='s')){
		if(IsRecording){  
			wavWriter.close();  
			IsRecording = false;  

		}
	}

	if ((key=='X')||(key=='x')){
		ofExit();
	}

}
Esempio n. 3
0
//--------------------------------------------------------------
void ofApp::setup(){
    
    dir.open( DIR_PATH );
    result_dir.open( RESULT_DIR );
    template_dir.open( TEMPLATE_DIR );
    queue_dir.open( QUEUE_DIR );
    
    
    if (!dir.exists() || !result_dir.exists() || !template_dir.exists() || !queue_dir.exists() ) ofExit();
    
    
    templateFile = getLatestFile(template_dir, "png");
    
    if (templateFile == ""  || !loadTemplate(TEMPLATE_DIR + templateFile)) ofExit();
    
    
    latestResult = getLatestFile(result_dir, "png");
    
    if (latestResult != "" ) {
        //deletePrevious(result_dir, latestResult);
        resultImage.loadImage(RESULT_DIR + latestResult);
        resultImage.resize(RESULT_WIDTH, RESULT_HEIGHT);
    } else {
        resultImage.allocate(templateImagePixels.getWidth(), templateImagePixels.getHeight(), OF_IMAGE_COLOR);
        memset(resultImage.getPixels(), 0, resultImage.getPixelsRef().size());
    }
    
    
    
#if FRAME_RATE > 0
    ofSetFrameRate(FRAME_RATE);
#endif
    
}
Esempio n. 4
0
//--------------------------------------------------------------
void ofApp::draw(){

  
  movie.setFrame( currentFrame );
  movie.update();
  
  ofClear( 255, 255, 255, 255 );
  
  ofSetColor( 255, 255, 255 );
  movie.draw( 25, 25, 1024, 768 );
  
  ofSetColor( 0 );
  string watermark = "Packwood - Obstinate :: frame " + ofToString(currentFrame);
  font.drawString( watermark, 75, 720 );
  
  image.grabScreen( 0 , 0, ofGetWidth(), ofGetHeight() );
  image.saveImage( "frames/frame" + ofToString( currentFrame ) + ".png" );
  
  //ofExit();
  currentFrame++;
  
  if( currentFrame > movie.getTotalNumFrames() ) ofExit();
  
  
  
}
Esempio n. 5
0
	//----------
	void Scene::draw() {
		if (!this->initialised) {
			ofSystemAlertDialog("You are calling ofxGrabScene::draw without first calling init, we're exiting!");
			ofExit();
		}
		
		this->camera->begin();
		
		ofPushStyle();
		ofEnableAlphaBlending();
		
		this->drawNodesAndElements();
		this->camera->updateCursorWorld();
		this->drawIndexBuffer();
		this->drawOutlines();
		
		ofPopStyle();
		
		////
		//cache values for unprojection of mouse
		this->viewport = ofGetCurrentViewport();
		glGetFloatv(GL_MODELVIEW_MATRIX, viewMatrix.getPtr());
		glGetFloatv(GL_PROJECTION_MATRIX, projectionMatrix.getPtr());
		glGetDoublev(GL_MODELVIEW_MATRIX, viewDoubles);
		glGetDoublev(GL_PROJECTION_MATRIX, projectionDoubles);
		//
		////
		
		this->camera->end();
		
		this->drawOverlay();
	}
//--------------------------------------------------------------
void ofApp::setup(){
    serial.listDevices();
    bool connectionStatus = connectToArduino();
    ofLog() << "Connect To Arduino returned: " << connectionStatus;
    if(!connectionStatus){
        ofExit();
    }

    cubes = vector<Cube>(nrCubes, Cube());
    //place the cubes
    for(int i = 0; i < nrCubes; i++){
        cubes[i].setup(i, this);
    }
    updateCubes();

    ofAddListener(Cube::cubeTriggered, this, &ofApp::onCubeTriggered);
    ofAddListener(CopyBridge::copyingDone, this, &ofApp::onCopyingDone);

    seq = new Sequencer(this, 120);

    //GUI
    gui.setup();
    run.addListener(this, &ofApp::toggleSequencer);
    gui.add(run.setup("run sequencer", false));
    tempo.addListener(this, &ofApp::setTempo);
    gui.add(tempo.setup("tempo", 120, 80, 140));
}
Esempio n. 7
0
 BaseSource* MediaServer::loadFboSource(std::string &fboSourceName) {
   ofLogNotice("MediaServer") << "Attempting to load FBO source with name " << fboSourceName;
   // Search for FBO source name in our storage
   FboSource* source = NULL;
   for (int i = 0; i < fboSources.size(); i++) {
     if (fboSources[i]->getName() == fboSourceName) {
       source = fboSources[i];
       break;
     }
   }
   // Panic if not in storage
   if (source == NULL) {
     ofLogError("MediaServer") << "Attempt to load non existing FBO source: " << fboSourceName;
     ofExit(EXIT_FAILURE);
   }
   // Check if it is loaded/activated
   if (loadedSources.count(fboSourceName)) {
     // Is loaded, increase reference count and return existing
     loadedSources[fboSourceName]->referenceCount++;
     ofLogNotice("MediaServer") << "Current " << fboSourceName << "reference count: " << loadedSources[fboSourceName]->referenceCount;
     return loadedSources[fboSourceName];
   }
   // else
   // Not loaded, add to loaded sources and activate
   // source var should be set by now
   source->addAppListeners();
   source->referenceCount = 1;
   ofLogNotice("MediaServer") << "Current " << fboSourceName << " reference count: " << source->referenceCount;
   loadedSources[fboSourceName] = source;
   return loadedSources[fboSourceName];
 } // loadFboSource
Esempio n. 8
0
//--------------------------------------------------------------
void ofApp::setup(){
    if( !ofFile::doesFileExist("11to16.bin") ){
        ofSystemAlertDialog("Make sure you have 11to16.bin, xTable.bin and zTable.bin in your data folder!");
        ofExit(); 
    }

    ofBackground(30, 30, 30);

    extrude.set("extrudeDepth", 500.0, 0.0, 1000.0);
    depthLeft.set("depthLeft",0.0,0.0,1.0);
    depthRight.set("depthRight",1.0, 0.0, 1.0);
    
    panel.setup("distance in mm", "settings.xml", 540, 100);
    panel.add(kinect.minDistance);
    panel.add(kinect.maxDistance);
    panel.add(extrude);
//    panel.add(depthLeft);
//    panel.add(depthRight);
    panel.loadFromFile("settings.xml");
    
    pointCloudShader.load("shader/pointCloud");
    
    kinect.open();
    
    camera.setPosition(ofGetWidth()/2.0, ofGetHeight()/2.0, 700.0);
    camera.roll(180.0);
}
Esempio n. 9
0
void ofConfig::mousePressed(int x, int y, int button) {
    // Select resolution if mouse is within rectangle boundaries
    for (int i = 0; i < resolutionRects.size(); i++) {
        if (resolutionRects[i]->inside(x, y)) {
            selectedResolution = i;
        }
    }

    // Toggle fullscreen button if mouse is within rectangle
    if (fullscreenRect.inside(x, y)) {
        isFullscreen = !isFullscreen;
    }

    // Run demo if mouse is within rectangle
    // Saves the settings and exits
    if (runDemoRect.inside(x, y)) {
        if (isFullscreen) {
            settings->windowMode = OF_FULLSCREEN;
        }

        settings->width = resolutions[selectedResolution].first;
        settings->height = resolutions[selectedResolution].second;

        ofExit();
    }
}
Esempio n. 10
0
void init()
{
    static bool inited = false;
    if (inited) return;
    inited = true;

    string path;
#ifndef TARGET_WIN32
    path = ofFilePath::getCurrentExeDir() + "/Drivers"; // osx / linux
#else
    path = ofFilePath::getCurrentExeDir() + "/OpenNI2/Drivers"; // windows
#endif
    if (ofFile::doesFileExist(path, false))
    {
#ifndef TARGET_WIN32
        setenv("OPENNI2_DRIVERS_PATH", path.c_str(), 1);
#endif
        assert_error(openni::OpenNI::initialize());
    }
    else
    {
        ofLogError("ofxNI2") << "libs not found";
        ofExit(-1);
    }
}
void ofxRPiCameraVideoGrabber::onUpdateDuringExit(ofEventArgs& args)
{
    if (doExit)
    {
        ofLogVerbose(__func__) << " EXITING VIA SIGNAL";
        close();
        ofExit();
    }
}
Esempio n. 12
0
void ofxOMXPlayer::onUpdate(ofEventArgs& args)
{
	if (doExit) 
	{
		ofLogVerbose(__func__) << " EXITING VIA SIGNAL";
		doExit = false;
		close();
		ofExit();
	}
}
Esempio n. 13
0
//--------------------------------------------------------------
void testApp::setup(){
    ofSetLogLevel(OF_LOG_NOTICE);
    ofEnableAlphaBlending();
    ofSetFrameRate(30);

    if (!image.loadImage("gedou.jpg")) {
        ofLog(OF_LOG_ERROR, "can't load image.");
        ofExit();
    }
    
    selectingState = INITIAL;
}
Esempio n. 14
0
 void MediaServer::addFboSource(ofx::piMapper::FboSource &fboSource) {
   ofLogNotice("MediaServer") << "Attempting to add FBO source with name " << fboSource.getName();
   // FBO source has to be with unique name
   for (int i = 0; i < fboSources.size(); i++) {
     if (fboSources[i]->getName() == fboSource.getName()) {
       ofLogWarning("MediaServer") << "Attempt to add FBO source with duplicate name";
       ofExit(EXIT_FAILURE); // Here we definitely need to fail to avoid confusion
     }
   }
   ofLogNotice("MediaServer") << "Source new, adding";
   fboSources.push_back(&fboSource);
 } // addFboSource
Esempio n. 15
0
//--------------------------------------------------------------
void testApp::setup(){
    camWidth    = 640;
    camHeight   = 480;
    
	if( !vidGrabber.initGrabber(camWidth, camHeight, (unsigned int)cameraSerialNr) ){
		ofLog(OF_LOG_FATAL_ERROR, "sorry, no camera found - exit application!");
		ofExit();
	}
    
    curFrame.allocate(camWidth, camHeight, OF_IMAGE_GRAYSCALE);

}
Esempio n. 16
0
    //--------------------------------------------------------------
    void setup() {
        ofSetColor(255);
        ofBackground(0);
        ofSetVerticalSync(true);

        // Load graph (i.e. trained model) we exported from python, and initialize session
        session = msa::tf::create_session_with_graph("models/model.pb");

        if(!session) {
            ofLogError() << "Model not found. " << msa::tf::missing_data_error();
            ofExit(1);
        }
    }
Esempio n. 17
0
//--------------------------------------------------------------
void testApp::update(){
	cam.update();
	if(cam.isFrameNew()){
		colorsOfMovement.addFrame(&(cam.getTextureReference()));
	}
	
	// quit if screen size don't match
	if (ofGetFrameNum() % 300 == 299) {
		if(ofGetWidth() != outputSize.x || ofGetHeight() != outputSize.y){
			ofExit();
		}
	}
}
Esempio n. 18
0
//----------
void ofxWatermark::init(string filename, string hash) {
	ofFile file(filename);
	auto buffer = file.readToBuffer();
	
	unsigned char fileHash[MD5_DIGEST_LENGTH];
	MD5((unsigned char *)buffer.getBinaryBuffer(), buffer.size(), fileHash);

	if (hashToString(fileHash) != hash) {
		ofSystemAlertDialog("The watermark hash does not match. Tamper alert! Quitting!");
		ofExit();
	}

	this->loadImage(buffer);
}
Esempio n. 19
0
//--------------------------------------------------------------
int ofApp::getBuffer(){
    
    size_t size;
    
    string fileToOpen = getLatestFile(dir, "ebb");
    
    if (fileToOpen != "") {
        
        cout << "file to open: " << fileToOpen << "\n";
        
        string filePath = DIR_PATH + fileToOpen;
        
        if ( fileToOpen.substr(fileToOpen.length() - 5) == "R.ebb" ) {
            
            size = RAND_SIZE;
            is_random = true;
            rand_pos_center = rand_pos = std::rand() % dataset.pix_num;
            size_t i = rand_pos * 3;
            rand_value_center[0] = rand_value[0] = dataset.imageData[i];
            rand_value_center[1] = rand_value[1] = dataset.imageData[i+1];
            rand_value_center[2] = rand_value[2] = dataset.imageData[i+2];
            
        }
        else {
            
            imageData.clear();
            
            imageData = ofBufferFromFile(filePath);
            
            data_ptr = (unsigned char*)imageData.getBinaryBuffer();
            
            cout << "buffer size: " << imageData.size() << "\n";
            
            size = (imageData.size() / 3) * 3;
            
            is_random = false;
            
        }
        
        ofFile::removeFile(filePath);
        
        dir.open(DIR_PATH);
        if (!dir.exists()) ofExit();
        
        return size;
        
    }
    
    return 0;
}
Esempio n. 20
0
void ofApp::setup()
{
  ofSetDataPathRoot( __data_path__ );
  ofSetFrameRate(30);
  ofSetVerticalSync(true);
  ofSetLogLevel(OF_LOG_NOTICE);

  if ( !settings.open( "config/settings.json" ) ) 
  {
    ofLogFatalError() << "error opening settings.json";
    ofExit();
    return;
  }

  rgb_cam_name = settings["params"]["calib_kinect_rgb_stereo"]["rgb_cam_name"].asString();
  rgb_device_id = settings["params"]["calib_kinect_rgb_stereo"]["rgb_device_id"].asInt();
  rgb_width = settings["params"]["calib_kinect_rgb_stereo"]["rgb_width"].asInt();
  rgb_height = settings["params"]["calib_kinect_rgb_stereo"]["rgb_height"].asInt();
  rgb_width_draw = rgb_width / 2;
  rgb_height_draw = rgb_height / 2;

  ofLog() << "rgb size " << rgb_width << " x " << rgb_height;

  rgb_cam.setDeviceID( rgb_device_id );
  rgb_cam.initGrabber( rgb_width, rgb_height, true );

  kinect.setRegistration(true);
  // ir, rgb, texture
  kinect.init(false, true, true);
  kinect.open();

  kinect.update(); 
  rgb_cam.update();

  pix_kinect_rgb = kinect.getPixelsRef(); //copy
  pix_rgb = rgb_cam.getPixelsRef(); //copy

  calibration.init( 
      settings["params"]["calib_kinect_rgb_stereo"]["cam_pattern_path"].asString(),
      "kinect", pix_kinect_rgb, 
      rgb_cam_name, pix_rgb, 
      //load calibrated kinect intrinsics
      settings["params"]["calib_kinect_rgb_stereo"]["calib_kinect_path"].asString() );

  //window setup
  ofSetWindowShape( 
      kinect.width + rgb_width_draw, 
      rgb_height > kinect.height ? rgb_height : kinect.height );
  ofSetWindowPosition( 0, 0 );
}
void ofxFensterManager::deleteFenster(ofxFenster* fenster)
{
	fenster->destroy();
	fensterList::iterator it=fensters.begin();
	while(it!=fensters.end()) {
		if((*it)->id == fenster->id) {
			fensters.erase(it);
			break;
		}
		++it;
	}
	if(fensters.size()==0)
		ofExit();
}
Esempio n. 22
0
	//--------------------------------------------------------------
	void update(){
		static string addr;
		static string mediatype;
		while(receiver.hasWaitingMessages()){
			ofxOscMessage m;
			receiver.getNextMessage(&m);
			addr = m.getAddress();
			
			if (addr=="load_file"){
            std::strcpy(tmpstr, to_utf8(m.getArgAsString(0)).c_str());
            mediatype = m.getArgAsString(1);
            if (!media.load(tmpstr, mediatype)) {
					ofxOscMessage ms;
					ms.setAddress("/error_loading");
					sender.sendMessage(ms);
            }
            else {
					while (!media.player->isLoaded()){};
					media.player->start();
					send_dur_sec();
            }
			}
			else if (addr=="play") media.player->play();
			else if (addr=="stop") media.player->stop();
			else if (addr=="unloop")media.player->unloop();
			else if (addr=="loop") media.player->loop();
			else if (addr=="pause") media.player->pause();
			else if (addr=="unpause") media.player->unpause();
			else if (addr=="get_dur_sec") send_dur_sec();
			else if (addr=="set_pos01") media.player->setpos01(m.getArgAsFloat(0));
			else if (addr=="exit") ofExit();
		}
		
		if (media.player->isDone()==true && dragged==false && media.player->HAS_ENDED==false) {
			ofxOscMessage ms;
			ms.setAddress("/has_ended");
			sender.sendMessage(ms);
			media.player->HAS_ENDED = true;
		}
		
		media.player->update();
		if (media.player->isLoaded()){
			ofxOscMessage ms;
			ms.setAddress("/setpos");
			ms.addFloatArg(media.player->pos01);
			ms.addStringArg(to_hmsd(media.player->pos01*media.player->dur_sec));
			sender.sendMessage(ms);     
		}
	}
Esempio n. 23
0
//--------------------------------------------------------------
void testApp::setup()
{
	ofSetFrameRate(60);
	ofSetVerticalSync(true);
	
	ofBackground(30);
	
	// see main.cpp
	
	vector<string> keys = ofxArgParser::allKeys();
	for (int i = 0; i < keys.size(); i++)
		cout << "key: " << keys[i] << ", value: " << ofxArgParser::getValue(keys[i]) << endl;
	
	ofExit();
}
void ofxFensterCanvas::finalizeSetup(){
    if(columns * rows != screens.size()){
        ofLogError() << "Expected" << columns * rows << "screens, but found" << screens.size();
        ofExit();
    }
    
    screens.sort(compareScreens);
    
    list<ofxScreen *>::iterator sit;
    for(sit = screens.begin(); sit != screens.end(); sit++){
        setScreenIndices(*sit, std::distance(screens.begin(), sit));
        
        ofLogNotice() << "Set up display" << (*sit)->display->id << ": at" << (*sit)->index.x << "," << (*sit)->index.y << "(" << (*sit)->display->x << "," << (*sit)->display->y << ")" << ", display" << (*sit)->display->width << "x" << (*sit)->display->height << ", window" << (*sit)->window->getWidth() << "x" << (*sit)->window->getHeight();
    }
}
Esempio n. 25
0
//--------------------------------------------------------------
void ofApp::draw(){
    ofBeginShape();
    bool first = true;
    int currentDraw;
    for(float i=-M_PI;i<=M_PI;i+=step) {
        if(first) {currentDraw = 0; first = false;} else {currentDraw = 1;}
        setFold(i,pos,currentDraw);         
    }
    pos += step;
    ofEndShape();
    if(pos > M_PI) { 
        ofSleepMillis(1000);
        ofSaveFrame();
        ofExit();
    }
}
Esempio n. 26
0
void nebulaEye::keyPressed(int key){
  switch (key){
    case 27:
      ofExit();
      break;
    case 'h':
      showGui = !showGui;
      break;
    case 's':
      gui.saveToFile("settings.xml");
      bgSub.saveAlgoParam();
      break;
    default:
      break;
  }
}
Esempio n. 27
0
//--------------------------------------------------------------
void ofApp::update(){
    
    if ( ! (++count %= UPDATE_TEMPLATE) ) updateTemplate();
    
    unsigned char* result = resultImage.getPixels();
    
    const int size = resultImage.getPixelsRef().size();
    
    //count = ++count % 200;
    //if (!count) fade(result, resultImage.getPixelsRef().size());
    //resultImage.update();
    
    there_was_buffer = there_is_buffer;
    
    to_feed = MAX_TO_FEED;
    while (to_feed && ( (remaining > 0) || (there_is_buffer = remaining = getBuffer()) ) )
    {
        if (to_feed == MAX_TO_FEED && !is_random ) fade(result, size);
        feed(result);
    }
    
    if (there_is_buffer || there_was_buffer)
    {
        resultImage.update();
        ostringstream stream;
        
        stream << ofGetUnixTime();
        stream << ofGetSystemTimeMicros();
        stream << ".png";
        string filename = stream.str();
        string path = RESULT_DIR + filename;
        resultImage.saveImage(path);
        //cout << "Image Saved: " << path << "\n";
        
#if SAVE_RESULT == 0
        if ( previousResult != "" ) ofFile::removeFile( RESULT_DIR + previousResult );
        
        result_dir.open( RESULT_DIR );
        if (!result_dir.exists()) ofExit();
        
        previousResult = latestResult;
        latestResult = filename;
#endif
    }
    
    
}
Esempio n. 28
0
void ofApp::touchUp(int x, int y, int id) {
    int test_session = m_server.testGetSessionAtPoint(x, y);
    if ( test_session >= 0 ) {
        //m_server.testToggleSession(test_session);
    }
    if ( m_selected_button[ id ] ) {
        int button = -1;
        for ( int i = 0; i < k_nbuttons; i++ ) {
            if ( m_button_bounds[ i ].inside(x, y) ) {
                button = i;
                break;
            }
        }
        if ( button+1 == m_selected_button[ id ] ) {
            //
            //
            //
			int selector = button % k_nbuttonimages;
			switch (selector) {
			case 0:
				m_current_session->setCurrentDocument(0);
				break;
			case 1:
				m_current_session->setCurrentDocument(1);
				break;
			case 2:
				upload();
				break;
			case 3:
				ofExit();
				break;
			}
			/*
            if ( button == 0 || button == 2 ) {
                m_current_session->setCurrentDocument( 0 );
            } else {
                m_current_session->setCurrentDocument( 1 );
            }
			*/
         }
    } else if ( m_current_session ) {
        m_current_session->touchUp(x, y, id);
    }
    m_selected_button[ id ] = 0;
}
Esempio n. 29
0
//--------------------------------------------------------------
void ofApp::updateTemplate() {
    
    string newTemplate = getFirstFile(queue_dir, "png");
    
    if (newTemplate == "" || newTemplate == templateFile) return;
    
    rename( (QUEUE_DIR + newTemplate).c_str(), (TEMPLATE_DIR + newTemplate).c_str() );
    
    if (!loadTemplate(TEMPLATE_DIR + newTemplate)) return;
    
    
    if (templateFile != "" ) ofFile::removeFile( TEMPLATE_DIR + templateFile );
    
    template_dir.open( TEMPLATE_DIR );
    if (!template_dir.exists()) ofExit();
    
    
    templateFile = newTemplate;
}
Esempio n. 30
0
int main(int argc,char *argv[])
{

    if(argc<2)
    {
        cout<<"Too Few Arguements\n";
        ofExit();
    }
    
    char *test;
    
   long long int userid=strtoll(argv[1], &test, 10);
        
   	ofAppGlutWindow window; // create a window
	// set width, height, mode (OF_WINDOW or OF_FULLSCREEN)
	ofSetupOpenGL(&window, 1024, 768, OF_WINDOW);
	
    ofRunApp(new testApp(userid)); // start the app
}