From ec8d6f1296dc8c8d49663ce4eec96a31d618fb5e Mon Sep 17 00:00:00 2001 From: Jamie Allen Date: Tue, 8 May 2012 01:11:31 +0200 Subject: [PATCH] colorsingle and colormulti are in interesting places - * need to talk to tom about _mesh_size_multiplier and the camera positionings * still need to fix the file saving thing - we're getting very few frames out for the number of frames in current (threading issue) --- example/RefractiveIndex.cpp | 36 ++------ example/RefractiveIndex.h | 3 +- src/AbstractAnalysis.h | 3 +- src/ColorMultiAnalysis.cpp | 49 ++++++++--- src/ColorMultiAnalysis.h | 3 + src/ColorSingleAnalysis.cpp | 164 +++++++++++++++++++++++++++--------- src/ColorSingleAnalysis.h | 3 + 7 files changed, 178 insertions(+), 83 deletions(-) diff --git a/example/RefractiveIndex.cpp b/example/RefractiveIndex.cpp index d1227e5..ae93986 100644 --- a/example/RefractiveIndex.cpp +++ b/example/RefractiveIndex.cpp @@ -43,7 +43,7 @@ ofxXmlSettings RefractiveIndex::XML; void RefractiveIndex::setup() { camDist=1000; - + ofBackground(0, 0, 0); //camera.setOrientation(ofVec3f(1,-1,1)); bool save_config = false; @@ -228,40 +228,15 @@ void RefractiveIndex::draw() if(_currentAnalysis->meshIsComplete){ fbo.begin(); - ofEnableSmoothing(); - //glShadeModel(GL_SMOOTH); - //glFogf(GL_FOG_END, -200); - - //glHint(GL_NICEST, GL_DONT_CARE); - - //glEnable(GL_NORMALIZE); - //glEnable(GL_DEPTH_TEST); - //ofEnableSeparateSpecularLight(); - - //ofEnableLighting(); - //light.setPosition(ofVec3f(fbo.getWidth()/2, fbo.getHeight()/2,_currentAnalysis->_mesh_size_multiplier *500)); - //lightStatic.setPosition(ofVec3f(20,50,100)); - //ofEnableSeparateSpecularLight(); - //ofGetLightingEnabled(); - - //ofSetLineWidth(1.0f); - //glPointSize(5.0f); - - //ofEnableBlendMode ( OF_BLENDMODE_ADD ); - //ofEnableBlendMode ( OF_BLENDMODE_MULTIPLY ); - //ofEnableBlendMode ( OF_BLENDMODE_SUBTRACT ); - ofEnableBlendMode ( OF_BLENDMODE_ALPHA ); - //ofEnableBlendMode ( OF_BLENDMODE_SCREEN ); - + glShadeModel(GL_SMOOTH); ofClear(0,0,0); camera.begin(); - ofSetColor(0, 0, 0); - //this is a hack, I don't know how to colour the fbo with black pixels so I'm drawing a massive black rectangle in the background ofPushMatrix(); ofTranslate(0, 0,-500); + ofSetColor(0, 0, 0); ofRect(-fbo.getWidth(), -fbo.getHeight(), fbo.getWidth()*3, fbo.getHeight()*3); ofPopMatrix(); ofSetColor(255); @@ -271,7 +246,8 @@ void RefractiveIndex::draw() ofTranslate(xDiff,yDiff,-_currentAnalysis->zPlaneAverage ); ofScale(1.33333,1.0,1.0); - _currentAnalysis->aMesh.drawVertices(); + //_currentAnalysis->aMesh.drawVertices(); // TODO: tom - why do you have the vertices drawing here? + _currentAnalysis->aMesh.drawFaces(); _currentAnalysis->aMesh.draw(); camera.end(); @@ -284,7 +260,7 @@ void RefractiveIndex::draw() //saving jpgs doesn't work - pngs only! // PNG is fine - better for Final Cut anyway! - ofDisableBlendMode( ) ; + ofDisableBlendMode() ; } } } diff --git a/example/RefractiveIndex.h b/example/RefractiveIndex.h index 6019d1e..e6fcd80 100644 --- a/example/RefractiveIndex.h +++ b/example/RefractiveIndex.h @@ -76,6 +76,5 @@ public: ofCamera camera; ofPixels keepOnScreen; ofFbo fbo; - ofLight light; - ofLight lightStatic; + }; \ No newline at end of file diff --git a/src/AbstractAnalysis.h b/src/AbstractAnalysis.h index 5537acb..1e12048 100755 --- a/src/AbstractAnalysis.h +++ b/src/AbstractAnalysis.h @@ -64,7 +64,8 @@ public: bool meshIsComplete; bool imageForContourAvailable; ofMesh aMesh; - ofLight light; + ofLight light; + ofLight lightStatic; string meshFileName; //difference between our image size and the size of the fbo diff --git a/src/ColorMultiAnalysis.cpp b/src/ColorMultiAnalysis.cpp index 9ce59e8..9ee979e 100755 --- a/src/ColorMultiAnalysis.cpp +++ b/src/ColorMultiAnalysis.cpp @@ -24,8 +24,9 @@ void ColorMultiAnalysis::setup(int camWidth, int camHeight) meshIsComplete=false; _gotFirstImage=false; - _mesh_size_multiplier=4; - + _mesh_size_multiplier=5; + vertexSubsampling = 1; + chooseColour=1; int acq_run_time; // 10 seconds of acquiring per run acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_colormulti", ACQUIRE_TIME); @@ -269,6 +270,27 @@ void ColorMultiAnalysis::displayresults() void ColorMultiAnalysis::draw() { + ofEnableSmoothing(); + + ofEnableLighting(); + ofEnableSeparateSpecularLight(); + light.enable(); + + light.setPosition(200,200,-150); + lightStatic.enable(); + + glEnable(GL_DEPTH_TEST); + + ofSetLineWidth(2.0f); + //glPointSize(4.0f); + + ofEnableBlendMode ( OF_BLENDMODE_ADD ); + //ofEnableBlendMode ( OF_BLENDMODE_MULTIPLY ); + //ofEnableBlendMode ( OF_BLENDMODE_SUBTRACT ); + //ofEnableBlendMode ( OF_BLENDMODE_ALPHA ); + //ofEnableBlendMode ( OF_BLENDMODE_SCREEN ); + + switch (_state) { case STATE_ACQUIRING: { @@ -465,7 +487,14 @@ void ColorMultiAnalysis::setMeshFromPixels(vector sPixels, ofImage curren //get rid of all previous vectors and colours mesh.clear(); - mesh.setMode(OF_PRIMITIVE_LINE_STRIP); + + mesh.setMode(OF_PRIMITIVE_TRIANGLES); + //mesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP); + //mesh.setMode(OF_PRIMITIVE_TRIANGLE_FAN); + //mesh.setMode(OF_PRIMITIVE_LINES); + //mesh.setMode(OF_PRIMITIVE_LINE_STRIP); + //mesh.setMode(OF_PRIMITIVE_LINE_LOOP); + //mesh.setMode(OF_PRIMITIVE_POINTS); /* OF_PRIMITIVE_TRIANGLES, @@ -478,9 +507,9 @@ void ColorMultiAnalysis::setMeshFromPixels(vector sPixels, ofImage curren */ - ofColor meshColour=ofColor(255,0,0); + ofColor meshColour=ofColor(255,255,255); - int chooseColour=1 ; + //the average z position of the matrix - used later to centre the mesh on the z axis when drawing float zPlaneAverage=0; @@ -518,10 +547,10 @@ void ColorMultiAnalysis::setMeshFromPixels(vector sPixels, ofImage curren mesh.addColor( currentSecondImage.getColor(x+1, y) ); mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ])); - x++; + x=x+vertexSubsampling; if(x>=currentSecondImage.getWidth()-1){ x=0; - y++; + y=y+vertexSubsampling; //something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector? if(y>=currentSecondImage.getHeight()-1){ break; @@ -572,8 +601,8 @@ vector ColorMultiAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofIm //int thisDiff=abs(imageColor1.getBrightness()); //int thisDiff=abs(imageColor1.getBrightness()-_presumedBrightness); - //int thisDiff=abs(imageColor1.getHue()); - int thisDiff=abs(imageColor1.getLightness()); + int thisDiff=255-abs(imageColor1.getHue()); + //int thisDiff=abs(imageColor1.getLightness()); //cout< ColorMultiAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofIm //green hue: 120 //blue hue: 240 - float multiplier=4.0; + float multiplier=5.0; differences.push_back(multiplier* thisDiff); diff --git a/src/ColorMultiAnalysis.h b/src/ColorMultiAnalysis.h index 841673e..096af21 100755 --- a/src/ColorMultiAnalysis.h +++ b/src/ColorMultiAnalysis.h @@ -65,6 +65,9 @@ protected: //depth map function vector _returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImage); + int vertexSubsampling; + int chooseColour; + bool _gotFirstImage; ofImage _background; diff --git a/src/ColorSingleAnalysis.cpp b/src/ColorSingleAnalysis.cpp index 2f5c656..ac8efa5 100755 --- a/src/ColorSingleAnalysis.cpp +++ b/src/ColorSingleAnalysis.cpp @@ -26,8 +26,11 @@ void ColorSingleAnalysis::setup(int camWidth, int camHeight) //flag for main sketch meshIsComplete=false; _gotFirstImage=false; - _mesh_size_multiplier=4; + vertexSubsampling = 5; + chooseColour=1; + + int acq_run_time; // 10 seconds of acquiring per run acq_run_time = RefractiveIndex::XML.getValue("config:analysis_time:acquiretime_colorsingle", ACQUIRE_TIME); @@ -160,31 +163,41 @@ void ColorSingleAnalysis::synthesise() //if(image5.loadImage(_saved_filenames_analysis[i+1])){ ///////////////////////// PROCESS THE SAVED CAMERA IMAGES OF SHIT TO THE IMAGES ////////////////////////// - - if(_saved_filenames_analysis[i].find("RED")>0) + + + cout << "_saved_filenames_analysis[i].find(RED): " << _saved_filenames_analysis[i].find("RED") << endl; + + if(_saved_filenames_analysis[i].find("RED")<_saved_filenames_analysis[i].length()) { fileNameColor = "RED"; cout<<"FOUND RED"<0) - { - fileNameColor = "BLUE"; - cout<<"FOUND BLUE"<0) + } else if (_saved_filenames_analysis[i].find("GREEN")<_saved_filenames_analysis[i].length()) { fileNameColor = "GREEN"; cout<<"FOUND GREEN"< sPixels, ofImage curre int x=0; int y=0; + //get rid of all previous vectors and colours mesh.clear(); + //mesh.setMode(OF_PRIMITIVE_TRIANGLES); + //mesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP); + //mesh.setMode(OF_PRIMITIVE_TRIANGLE_FAN); + //mesh.setMode(OF_PRIMITIVE_LINES); + //mesh.setMode(OF_PRIMITIVE_LINE_STRIP); + //mesh.setMode(OF_PRIMITIVE_LINE_LOOP); mesh.setMode(OF_PRIMITIVE_POINTS); - + /* - OF_PRIMITIVE_TRIANGLES,9 + OF_PRIMITIVE_TRIANGLES, OF_PRIMITIVE_TRIANGLE_STRIP, OF_PRIMITIVE_TRIANGLE_FAN, OF_PRIMITIVE_LINES, @@ -513,16 +552,15 @@ void ColorSingleAnalysis::setMeshFromPixels(vector sPixels, ofImage curre */ - ofColor meshColour=ofColor(255,0,0); + ofColor meshColour=ofColor(255,255,255); - int chooseColour=2 ; - - //the average z position of the matrix - used later to centre the mesh on the z axis when drawing + //the average z position of the matrix - used later to centre the mesh on the z axis when drawing float zPlaneAverage=0; for(int i=0;i sPixels, ofImage curre mesh.addColor( currentSecondImage.getColor(x+1, y) ); mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ])); - x++; + x=x+vertexSubsampling; if(x>=currentSecondImage.getWidth()-1){ x=0; - y++; + y=y+vertexSubsampling; //something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector? if(y>=currentSecondImage.getHeight()-1){ break; @@ -593,10 +631,10 @@ void ColorSingleAnalysis::setMeshFromPixels(vector sPixels, ofImage curre mesh.addColor( currentSecondImageColor.getBrightness()); mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ])); - x++; + x=x+vertexSubsampling; if(x>=currentSecondImage.getWidth()-1){ x=0; - y++; + y=y+vertexSubsampling; //something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector? if(y>=currentSecondImage.getHeight()-1){ break; @@ -609,14 +647,36 @@ void ColorSingleAnalysis::setMeshFromPixels(vector sPixels, ofImage curre ofColor currentSecondImageColor; - if (fileNameColor=="RED") - { - currentSecondImageColor.r=255; - currentSecondImageColor.g=0; - currentSecondImageColor.b=0; - } - for(int i=0;i sPixels, ofImage curre mesh.addColor( currentSecondImageColor); mesh.addVertex(ofVec3f(_mesh_size_multiplier*(x+1),_mesh_size_multiplier*y,- sPixels[(currentSecondImage.getWidth()*(y))+x +1 ])); - x++; + x=x+vertexSubsampling; + //x++; if(x>=currentSecondImage.getWidth()-1){ x=0; - y++; + y=y+vertexSubsampling; + //y++; //something is going badly wrong with my maths for me to need this HELP TODO fix this - why am I running over the end of the vector? if(y>=currentSecondImage.getHeight()-1){ break; @@ -648,7 +710,6 @@ void ColorSingleAnalysis::setMeshFromPixels(vector sPixels, ofImage curre } } } -} vector ColorSingleAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImag){ @@ -689,9 +750,32 @@ vector ColorSingleAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofI //int thisDiff=abs(imageColor1.getHue()); //int thisDiff=abs(imageColor1.getBrightness()); //int thisDiff=abs(imageColor1.getBrightness()-_presumedBrightness); + + int thisDiff; - //int thisDiff=abs(imageColor1.getHue()); - int thisDiff=abs(imageColor1.getLightness()); + if(fileNameColor=="RED") + { + thisDiff=abs(imageColor1.r); + + //thisDiff=abs(255-imageColor1.r); + } else if(fileNameColor=="GREEN") + { + thisDiff=abs(imageColor1.g); + + //thisDiff=abs(255-imageColor1.g); + + } else if(fileNameColor=="BLUE") + { + thisDiff=abs(imageColor1.b); + + //thisDiff=abs(255-imageColor1.b); + + } else if(fileNameColor=="FADING") { + + thisDiff=imageColor1.getBrightness(); + //thisDiff=255-imageColor1.getBrightness(); + + } //cout< ColorSingleAnalysis::_returnDepthsAtEachPixel(ofImage &image1, ofI //green hue: 120 //blue hue: 240 - float multiplier=1.0; + float multiplier=2.0; differences.push_back(multiplier* thisDiff); diff --git a/src/ColorSingleAnalysis.h b/src/ColorSingleAnalysis.h index 012384f..434ede8 100755 --- a/src/ColorSingleAnalysis.h +++ b/src/ColorSingleAnalysis.h @@ -75,6 +75,9 @@ protected: //depth map function vector _returnDepthsAtEachPixel(ofImage &image1, ofImage &image2, ofImage &backgroundImage); + int vertexSubsampling; + int chooseColour; + bool _gotFirstImage; ofImage _background;