void ofxBlur::setup(int width, int height, int radius, float shape, int passes, float downsample) { string blurSource = generateBlurSource(radius, shape); if(ofGetLogLevel() == OF_LOG_VERBOSE) { cout << "ofxBlur is loading blur shader:" << endl << blurSource << endl; } if( ofIsGLProgrammableRenderer() ){ blurShader.setupShaderFromSource(GL_VERTEX_SHADER, getProgrammableRendererVertexSource()); } blurShader.setupShaderFromSource(GL_FRAGMENT_SHADER, blurSource); blurShader.linkProgram(); if(passes > 1) { string combineSource = generateCombineSource(passes, downsample); if(ofGetLogLevel() == OF_LOG_VERBOSE) { cout << "ofxBlur is loading combine shader:" << endl << combineSource << endl; } if( ofIsGLProgrammableRenderer() ){ combineShader.setupShaderFromSource(GL_VERTEX_SHADER, getProgrammableRendererVertexSource()); } combineShader.setupShaderFromSource(GL_FRAGMENT_SHADER, combineSource); combineShader.linkProgram(); } base.allocate(width, height); base.begin(); ofClear(0); base.end(); ofFbo::Settings settings; settings.useDepth = false; settings.useStencil = false; settings.numSamples = 0; settings.textureTarget = GL_TEXTURE_RECTANGLE_ARB; ping.resize(passes); pong.resize(passes); for(int i = 0; i < passes; i++) { ofLogVerbose() << "building ping/pong " << width << "x" << height; settings.width = width; settings.height = height; ping[i].allocate(settings); ping[i].begin(); ofClear(0,0,0,0); ping[i].end(); pong[i].allocate(settings); pong[i].begin(); ofClear(0,0,0,0); pong[i].end(); // ping[i].setDefaultTextureIndex(i); // pong[i].setDefaultTextureIndex(i); width *= downsample; height *= downsample; } }
//-------------------------------------------------------------- void testApp::draw(){ // copy enable part of gl state // glPushAttrib(GL_ENABLE_BIT); // setup gl state // glEnable(GL_DEPTH_TEST); // glEnable(GL_CULL_FACE); // light.enable(); // begin scene to post process // post.begin(cam); // post.begin(); // cam.begin(); ofPushMatrix(); // ofScale(1, -1, 1); // ofEnableAlphaBlending(); // ofSetColor(255, 255, 255); vbo.bind(); vbo.updateVertexData(pos, total); // vbo.updateColorData(color, total); // vbo.updateTexCoordData(tex_coord, total); for (int i=0; i<GRID_WIDTH; i++) { for (int j=0; j<GRID_HEIGHT; j++) { int index = (j*GRID_WIDTH+i) * LENGTH; vbo.draw(GL_TRIANGLE_FAN, index,LENGTH); } } vbo.unbind(); ofPopMatrix(); // end scene and draw // post.end(); // cam.end(); // post.end(); // set gl state back to original // glPopAttrib(); // image.grabScreen(0, 0, ofGetWidth(), ofGetHeight()); // if(saver.isRecording()) saver.writeRGB(image.getPixels()); // server.publishScreen(); if(ofGetLogLevel()==OF_LOG_VERBOSE) { for (int j=0; j<GRID_HEIGHT; j++) { for (int i=0; i<GRID_WIDTH; i++) { int index2 = (j*GRID_WIDTH+i); ofCircle(center_pos[index2],10); } } ofDrawBitmapString(ofToString(ofGetFrameRate()), 20,20); } ofDrawBitmapString(ofToString(ofGetHours())+":"+ofToString(ofGetMinutes()),ofGetWidth()*0.5,ofGetHeight()*0.5); }
void OpticalDevice::printM( float* M, int rows, int cols, bool colmajor) { if ( ofGetLogLevel() != OF_LOG_VERBOSE ) return; if (colmajor) { for (int j = 0; j < cols; j++) { printf("\n"); for (int i = 0; i < rows; i++) { printf("%9.3f ", M[i*cols+j]); } } } else { for (int i = 0; i < rows; i++) { printf("\n"); for (int j = 0; j < cols; j++) { printf("%9.3f ", M[i*cols+j]); } } } printf("\n\n"); };
void CamaraLucida::printM(float* M, int rows, int cols, bool colmajor) { if (ofGetLogLevel() != OF_LOG_VERBOSE) { return; } if (colmajor) { for (int j = 0; j < cols; j++) { printf("\n"); for (int i = 0; i < rows; i++) { printf("%9.3f ", M[i*cols+j]); } } } else { for (int i = 0; i < rows; i++) { printf("\n"); for (int j = 0; j < cols; j++) { printf("%9.3f ", M[i*cols+j]); } } } printf("\n"); }
//-------------------------------------------------------------- Global::Global() { dataPath = "data"; settingsPath = ".robotcowboy"; docsPath = "Documents/robotcowboy"; scenePath = "scenes"; logLevel = ofGetLogLevel(); }
//-------------------------------------------------------------- void testApp::update(){ appFrameRate = ofGetFrameRate(); int loglevel = stateMachine.getSharedData().panel.getValueI("LogLevel"); if(ofGetLogLevel()!= loglevel ) { ofSetLogLevel((ofLogLevel)loglevel); } }
void VideoGrabber::draw(){ if(updateTex){ pbo.updateTexture(); updateTex = false; } tex.draw(0,0); if(ofGetLogLevel()==OF_LOG_VERBOSE) ofDrawBitmapString("Ps3Eye FPS: "+ ofToString(getRealFrameRate()), 20,15); }
void HTTPUtils::dumpNameValueCollection(const Poco::Net::NameValueCollection& nvc, ofLogLevel logLevel) { if (logLevel >= ofGetLogLevel()) { for (const auto& entry: nvc) { ofLog(logLevel) << entry.first << ": " << entry.second; } } }
void CamaraLucida::printM(CvMat* M, bool colmajor) { if (ofGetLogLevel() != OF_LOG_VERBOSE) { return; } int i,j; if (colmajor) { for (i = 0; i < M->rows; i++) { printf("\n"); switch( CV_MAT_DEPTH(M->type) ) { case CV_32F: case CV_64F: for (j = 0; j < M->cols; j++) printf("%9.3f ", (float)cvGetReal2D( M, i, j )); break; case CV_8U: case CV_16U: for (j = 0; j < M->cols; j++) printf("%6d",(int)cvGetReal2D( M, i, j )); break; default: break; } } } else { for (j = 0; j < M->cols; j++) { printf("\n"); switch( CV_MAT_DEPTH(M->type) ) { case CV_32F: case CV_64F: for (i = 0; i < M->rows; i++) printf("%9.3f ", (float)cvGetReal2D( M, i, j )); break; case CV_8U: case CV_16U: for (i = 0; i < M->rows; i++) printf("%6d",(int)cvGetReal2D( M, i, j )); break; default: break; } } } printf("\n"); }
//-------------------------------------------------------------- void testApp::keyPressed(int key){ switch(key) { case 'd': if(ofGetLogLevel()!=OF_LOG_VERBOSE) { ofSetLogLevel(OF_LOG_VERBOSE); } else{ ofSetLogLevel(OF_LOG_NOTICE); } break; } }
void MyBox2D::draw() { for(int i = 0 ; i < MAX_PLAYER ; i++) { if(ofGetLogLevel()==OF_LOG_VERBOSE) { ofPushStyle(); box2d[i].draw(); ofPopStyle(); } } for(int i=0; i<particles.size(); i++) { particles[i].draw(); } }
//-------------------------------------------------------------- void testApp::draw(){ vbo.bind(); vbo.updateVertexData(strip, total); vbo.updateColorData(color, total); for (int j=0; j<NUM_STRIP; j++) { int index = j * LENGTH; vbo.draw(GL_TRIANGLE_STRIP, index,LENGTH); } vbo.unbind(); if(ofGetLogLevel()==OF_LOG_VERBOSE) { for (int j=0; j<NUM_STRIP; j++) { ofSetColor(255); ofCircle(pos[j] , 10); for (int i=LENGTH-1; i>=0; i--) { int index = i+(j*LENGTH); if(i%2==0) { ofSetColor(255, 0, 0); ofCircle(strip[index] , 2); } else { ofSetColor(0, 0, 255); ofCircle(strip[index] , 2); } } } } }
//-------------------------------------------------------------- void testApp::keyPressed(int key){ if(key == 'd') { if (ofGetLogLevel()!=OF_LOG_VERBOSE) { ofSetLogLevel(OF_LOG_VERBOSE); } else { ofSetLogLevel(OF_LOG_NOTICE); } } unsigned idx = key - '0'; // if (idx < post.size()) post[idx]->setEnabled(!post[idx]->getEnabled()); // for (int j=0; j<GRID_HEIGHT; j++) { // for (int i=0; i<GRID_WIDTH; i++) { // // int index2 = (j*GRID_WIDTH+i); // bStart[index2] = !bStart[index2]; // } // } }
bool UploadRouter::onHTTPFormEvent(ofx::HTTP::PostFormEventArgs& args) { const Poco::Net::NameValueCollection& form = args.getForm(); std::string projectName = form["projectName"]; UploadRouter::UploadedFile uploadedFile = _uploadedFiles[args.getPostId().toString()]; ofFile tempFile(uploadedFile.tempFilename); ofLogNotice("UploadRouter::onHTTPFormEvent") << "Project path" << _path << "/" << projectName; ofDirectory project(_path + "/" + projectName); Json::Value result; if (project.exists() && !uploadedFile.filename.empty()) { tempFile.renameTo(project.getAbsolutePath() + "/bin/data/" + uploadedFile.filename, false, true); ofx::HTTP::Utils::dumpNameValueCollection(args.getForm(), ofGetLogLevel()); } // see link below for spec // https://github.com/blueimp/jQuery-File-Upload/wiki/Setup result["files"][0]["name"] = uploadedFile.filename; result["files"][0]["size"] = uploadedFile.size; result["files"][0]["url"] = tempFile.getAbsolutePath(); result["files"][0]["thumbnailUrl"] = ""; result["files"][0]["deleteUrl"] = ""; result["files"][0]["deleteType"] = "DELETE"; if (uploadedFile.filename.empty()) { result["files"][0]["error"] = "Error uploading file."; } Json::FastWriter writer; std::string jsonString = writer.write(result); args.response.sendBuffer(jsonString.c_str(), jsonString.size()); return true; }
void Calibration::device_config( OpticalDevice::Config *dev_config, string calib_path, string int_id, string size_id, string R_id, string T_id ) { CvMat* _int = (CvMat*)cvLoad( calib_path.c_str(), NULL, int_id.c_str() ); CvMat* _size = (CvMat*)cvLoad( calib_path.c_str(), NULL, size_id.c_str() ); CvMat* _R = (CvMat*)cvLoad( calib_path.c_str(), NULL, R_id.c_str() ); CvMat* _T = (CvMat*)cvLoad( calib_path.c_str(), NULL, T_id.c_str() ); if (ofGetLogLevel() == OF_LOG_VERBOSE) { ofLog(OF_LOG_VERBOSE, "\n cml::Calibration "+calib_path); ofLog( OF_LOG_VERBOSE, "intrinsics" ); printM( _int ); //ofLog( OF_LOG_VERBOSE, "R" ); //printM( _R ); //ofLog( OF_LOG_VERBOSE, "T" ); //printM( _T ); } device_config( dev_config, _size, _int, _R, _T ); cvReleaseMat( &_int ); cvReleaseMat( &_size ); cvReleaseMat( &_R ); cvReleaseMat( &_T ); };
//-------------------------------------------------------------------------------- ofxKinectV2::ofxKinectV2() { if (ofGetLogLevel() == OF_LOG_VERBOSE) { libfreenect2::setGlobalLogger(libfreenect2::createConsoleLogger(libfreenect2::Logger::Debug)); } else { libfreenect2::setGlobalLogger(libfreenect2::createConsoleLogger(libfreenect2::Logger::Warning)); } frameColor.resize(2); frameDepth.resize(2); frameIr.resize(2); frameRawDepth.resize(2); frameAligned.resize(2); pcVertices.resize(2, vector<ofVec4f>(DEPTH_WIDTH * DEPTH_HEIGHT)); pcColors.resize(2, vector<ofFloatColor>(DEPTH_WIDTH * DEPTH_HEIGHT)); //set default distance range to 50cm - 600cm params.add(minDistance.set("minDistance", 500, 0, 12000)); params.add(maxDistance.set("maxDistance", 6000, 0, 12000)); params.add(bUseRawDepth.set("rawDepth", false)); computeIndices.unload(); computeIndices.setupShaderFromSource(GL_COMPUTE_SHADER, comp_glsl); computeIndices.linkProgram(); depthTexture.allocate(DEPTH_WIDTH, DEPTH_HEIGHT, GL_R32F); vector<int> indices((DEPTH_WIDTH - 1) * (DEPTH_HEIGHT - 1) * 6, 0); indicesBuffer.allocate(indices, GL_DYNAMIC_DRAW); atomicCounter.allocate(); int data = 0; atomicCounter.setData(sizeof(int), &data, GL_DYNAMIC_COPY); }
void Trace2552::logTrace2(const string& message, char*file, int line) { if (ofGetLogLevel() >= OF_LOG_NOTICE) { ofLog(OF_LOG_NOTICE, buildString(message, file, line)); } }
void ArtvertInfo::show(Artvert & _artvert){ mutex.lock(); artvert = _artvert; location = artvert.getLocation(); geo->setSize(ofGetWidth()/3.,ofGetWidth()/4.); geo->setLocation(location); ofImage cameraIcon; cameraIcon.loadImage("icons/camera.png"); advert = iconCache->getResource(artvert.getCompressedImage().getAbsolutePath()+"Preview"); if(!advert->bAllocated()){ advert->setUseTexture(false); advert->loadImage(artvert.getCompressedImage()); float ratio = advert->getHeight()/advert->getWidth(); advert->resize(ofGetWidth()/3.,ofGetWidth()/3.*ratio); } quad.clear(); quad.addVertexes(artvert.getROI()); for(int i=0;i<quad.size();i++){ quad[i].x *= ofGetWidth()/3. / 640; quad[i].y *= ofGetWidth()/3. / 640; quad[i].x += 20; quad[i].y += 20; } quad.close(); grid.clear(); grid.setRectangle(ofRectangle(ofGetWidth()/3.+40,50,ofGetWidth()-(ofGetWidth()/3.+60),ofGetHeight())); grid.setCellSize(cameraIcon.getWidth()*1.5, cameraIcon.getWidth()*1.5*3./4.); grid.setSpacing(20,20); grid.enableEvents(); ofLogLevel oldLevel = ofGetLogLevel(); artverts = artvert.getArtverts(); ofLogVerbose("ArtvertiserApp", "number of artverts: "+ofToString(artverts.size()) ); for(int i=0;i<(int)artverts.size();i++){ ofLogVerbose("ArtvertiserApp", ofToString(i)+": "+artverts[i].getAbsolutePath() ); grid.addWidget(ofPtr<gui::Button>(new gui::Button)); gui::Button * button = (gui::Button*)grid.getWidget(i).get(); ofPtr<ofImage> icon = iconCache->getResource(artverts[i].getAbsolutePath()+"Resized"); if(!icon->bAllocated()){ icon->setUseTexture(false); bool imageLoaded = icon->loadImage(artverts[i]); #ifndef TARGET_ANDROID if ( !imageLoaded ){ // try a video? ofVideoPlayer player; bool videoLoaded = player.loadMovie(artverts[i].getAbsolutePath()); if ( videoLoaded ){ // seek to middle frame player.setSpeed(0); player.play(); player.setFrame( player.getTotalNumFrames()/2 ); while (! player.isFrameNew() ) player.update(); // grab icon->setFromPixels( player.getPixelsRef() ); } } #endif float ratio = icon->getWidth()/icon->getHeight(); float width,height; if(ratio>1){ width = grid.getCellWidth(); height = width/ratio; }else{ height = grid.getCellHeight(); width = height * ratio; } icon->resize(width,height); } button->setIcon(*icon); ofAddListener(button->pressedE,this,&ArtvertInfo::artvertPressed); } refresh = true; mutex.unlock(); }
void Calibration::device_config( OpticalDevice::Config *dev_config, CvMat* _size, CvMat* _int, CvMat* _R, CvMat* _T ) { int w = (int)cvGetReal2D( _size, 0, 0 ); int h = (int)cvGetReal2D( _size, 0, 1 ); float fx = (float)cvGetReal2D( _int, 0, 0 ); float fy = (float)cvGetReal2D( _int, 1, 1 ); float cx = (float)cvGetReal2D( _int, 0, 2 ); float cy = (float)cvGetReal2D( _int, 1, 2 ); // opencv: row-major // R x axis ofVec3f X = ofVec3f( (float)cvGetReal2D( _R, 0, 0 ), //xx (float)cvGetReal2D( _R, 1, 0 ), //xy (float)cvGetReal2D( _R, 2, 0 ) //xz ); // R y axis ofVec3f Y = ofVec3f( (float)cvGetReal2D( _R, 0, 1 ), //yx (float)cvGetReal2D( _R, 1, 1 ), //yy (float)cvGetReal2D( _R, 2, 1 ) //yz ); // R z axis ofVec3f Z = ofVec3f( (float)cvGetReal2D( _R, 0, 2 ), //zx (float)cvGetReal2D( _R, 1, 2 ), //zy (float)cvGetReal2D( _R, 2, 2 ) //zz ); // T ofVec3f T = ofVec3f( (float)cvGetReal2D( _T, 0, 0 ), //tx (float)cvGetReal2D( _T, 1, 0 ), //ty (float)cvGetReal2D( _T, 2, 0 ) //tz ); if (ofGetLogLevel() == OF_LOG_VERBOSE) { ofLog(OF_LOG_VERBOSE, "RX: "+ofToString(X) ); ofLog(OF_LOG_VERBOSE, "RY: "+ofToString(Y) ); ofLog(OF_LOG_VERBOSE, "RZ: "+ofToString(Z) ); ofLog(OF_LOG_VERBOSE, "T: "+ofToString(T) ); } dev_config->near = this->near; dev_config->far = this->far; dev_config->width = w; dev_config->height = h; dev_config->cx = cx; dev_config->cy = cy; dev_config->fx = fx; dev_config->fy = fy; dev_config->X.set( X ); dev_config->Y.set( Y ); dev_config->Z.set( Z ); dev_config->T.set( T ); };