From 2dadffb8afff729337eeb94e651db99915606459 Mon Sep 17 00:00:00 2001 From: micuat Date: Mon, 26 Oct 2020 11:45:54 +0100 Subject: [PATCH] dummy point; do thermo 3d calc in update --- zoneb/bin/data/settings.xml | 4 +- zoneb/bin/data/shaders/particles/draw.frag | 3 + zoneb/bin/data/shaders/particles/update.frag | 18 ++--- zoneb/src/ofApp.cpp | 78 ++++++++++++-------- zoneb/src/ofApp.h | 3 + 5 files changed, 61 insertions(+), 45 deletions(-) diff --git a/zoneb/bin/data/settings.xml b/zoneb/bin/data/settings.xml index 4e77d2a..7b3eb0d 100644 --- a/zoneb/bin/data/settings.xml +++ b/zoneb/bin/data/settings.xml @@ -1,6 +1,6 @@ - -208, -257 - 2 + -195.918, -220.408 + 1.869 video3 diff --git a/zoneb/bin/data/shaders/particles/draw.frag b/zoneb/bin/data/shaders/particles/draw.frag index 62e0952..628ed5d 100755 --- a/zoneb/bin/data/shaders/particles/draw.frag +++ b/zoneb/bin/data/shaders/particles/draw.frag @@ -7,6 +7,9 @@ uniform sampler2DRect u_world; uniform sampler2DRect u_v4l2cam; uniform sampler2DRect imageTexture; +uniform vec3 uHottest0; +uniform vec3 uHottest1; + in vec2 texCoordVarying; in float vTemperature; in float vAge; diff --git a/zoneb/bin/data/shaders/particles/update.frag b/zoneb/bin/data/shaders/particles/update.frag index a594238..4024ca1 100755 --- a/zoneb/bin/data/shaders/particles/update.frag +++ b/zoneb/bin/data/shaders/particles/update.frag @@ -19,8 +19,8 @@ uniform float elapsed; uniform vec3 uHottest0; uniform vec3 uHottest1; -uniform vec3 uColdest0; -uniform vec3 uColdest1; +uniform vec3 uHottest3d0; +uniform vec3 uHottest3d1; in vec2 texCoordVarying; @@ -163,20 +163,14 @@ void main() if(age < 0.001) { // targetting target.w = 0; if(random3(pos).x > pow(length(texCoordVarying.st - uHottest0.st)/5,16*16)+0) { - vec2 h = uHottest1.st; - vec4 hray = texture(u_world, h); - float hdepth = -depth * 65535.0; - if(hdepth == 0) hdepth = -0.01 * 65535.0; - vec3 H = vec3(hray.xy * hdepth, hdepth); + vec3 H = uHottest3d0; + H.z *= -1; target.xyz = H + random3(pos); target.w = 1; } else if(random3(pos).x > pow(length(texCoordVarying.st - uHottest1.st)/5,16*16)+0) { - vec2 h = uHottest0.st; - vec4 hray = texture(u_world, h); - float hdepth = -depth * 65535.0; - if(hdepth == 0) hdepth = -0.01 * 65535.0; - vec3 H = vec3(hray.xy * hdepth, hdepth); + vec3 H = uHottest3d1; + H.z *= -1; target.xyz = H + random3(pos); target.w = 1; } diff --git a/zoneb/src/ofApp.cpp b/zoneb/src/ofApp.cpp index 6863593..ce19711 100644 --- a/zoneb/src/ofApp.cpp +++ b/zoneb/src/ofApp.cpp @@ -118,17 +118,17 @@ void ofApp::setupParticles() void ofApp::setupGui() { - gui.setup("ZONE B", "settings.xml"); // most of the time you don't need a name - gui.add(registrationXY.setup("XY", {-208, -257}, {-400, -400}, {400, 400})); - gui.add(registrationScale.setup("scale", 2.0, 0.1, 3)); + gui.setup("ZONE B", "settings.xml"); // most of the time you don't need a name + gui.add(registrationXY.setup("XY", {-208, -257}, {-400, -400}, {400, 400})); + gui.add(registrationScale.setup("scale", 2.0, 0.1, 3)); gui.add(captureDeviceName.setup("device", "video3")); gui.loadFromFile("settings.xml"); gui.setPosition(10, 10); debugGui.setup("DEBUG"); - debugGui.add(dummyMode.setup("dummy", true)); // should be false - debugGui.add(dummyXY.setup("XY", {0, 0}, {-400, -400}, {400, 400})); // should be false - debugGui.add(debugFps.setup("FPS", "0")); + debugGui.add(dummyMode.setup("dummy", true)); // should be false + debugGui.add(dummyXY.setup("XY", {256, 256}, {0, 0}, {511, 511})); // should be false + debugGui.add(debugFps.setup("FPS", "0")); debugGui.setPosition(230, 10); } @@ -158,6 +158,16 @@ void ofApp::exit() kinectDevice.close(); } +ofVec3f ofApp::getDepthAt(int x, int y) +{ + auto ray = kinectDevice.getDepthToWorldPix().getColor(x, y); + float depth = kinectDevice.getDepthPix().getColor(x, y).r; + if (depth == 0) + depth = 2000; + ofVec3f pos(ray.r * depth, ray.g * depth, depth); + return pos; +} + void ofApp::updateThermal() { v4l2Cam.grabFrame(); @@ -204,6 +214,29 @@ void ofApp::updateThermal() { std::sort(hotspots.at(i).begin(), hotspots.at(i).end(), compareZThermal); } + + if (hotspots.size() > 0 && hotspots.at(0).size() > 0) + { + hotspot0 = hotspots.at(0).at(0); + } + if (dummyMode == false) + { + if (hotspots.size() > 1 && hotspots.at(1).size() > 0) + { + hotspot1 = hotspots.at(1).at(0); + } + else if (hotspots.size() > 0 && hotspots.at(0).size() > 1) + { + hotspot1 = hotspots.at(0).at(1); + } + } + else + { + hotspot1 = ofVec3f(dummyXY); + } + + hotspot3d0 = getDepthAt(hotspot0.x, hotspot0.y); + hotspot3d1 = getDepthAt(hotspot1.x, hotspot1.y); } } @@ -226,35 +259,18 @@ void ofApp::onParticlesUpdate(ofxShader &shader) shader.setUniform2i("uFrameSize", kinectDevice.getDepthTex().getWidth(), kinectDevice.getDepthTex().getHeight()); shader.setUniform2i("uDepthFrameSize", kinectDevice.getDepthTex().getWidth(), kinectDevice.getDepthTex().getHeight()); - if (hotspots.size() > 0 && hotspots.at(0).size() > 0) - { - shader.setUniform3f("uHottest0", hotspots.at(0).at(0)); - } - if (hotspots.size() > 1 && hotspots.at(1).size() > 0) - { - shader.setUniform3f("uHottest1", hotspots.at(1).at(0)); - } - else if (hotspots.size() > 0 && hotspots.at(0).size() > 1) - { - shader.setUniform3f("uHottest1", hotspots.at(0).at(1)); - } - - if (hotspots.size() > 0 && hotspots.at(0).size() > 0) - { - shader.setUniform3f("uColdest0", hotspots.at(0).back()); - } - if (hotspots.size() > 1 && hotspots.at(1).size() > 0) - { - shader.setUniform3f("uColdest1", hotspots.at(1).back()); - } - else if (hotspots.size() > 0 && hotspots.at(0).size() > 1) - { - shader.setUniform3f("uColdest1", hotspots.at(0).at(hotspots.at(0).size() - 2)); - } + shader.setUniform3f("uHottest0", hotspot0); + shader.setUniform3f("uHottest1", hotspot1); + shader.setUniform3f("uHottest3d0", hotspot3d0); + shader.setUniform3f("uHottest3d1", hotspot3d1); } void ofApp::onParticlesDraw(ofxShader &shader) { + shader.setUniform3f("uHottest0", hotspot0); + shader.setUniform3f("uHottest1", hotspot1); + shader.setUniform3f("uHottest3d0", hotspot3d0); + shader.setUniform3f("uHottest3d1", hotspot3d1); } void ofApp::drawMain() diff --git a/zoneb/src/ofApp.h b/zoneb/src/ofApp.h index b5a68c6..6693766 100644 --- a/zoneb/src/ofApp.h +++ b/zoneb/src/ofApp.h @@ -23,6 +23,7 @@ public: void setup(); void exit(); + ofVec3f getDepthAt(int x, int y); void updateThermal(); void update(); void drawMain(); @@ -59,6 +60,8 @@ private: ofxGpuParticles particles; std::vector> hotspots; + ofVec3f hotspot0, hotspot1; + ofVec3f hotspot3d0, hotspot3d1; ofxVec2Slider registrationXY; ofxFloatSlider registrationScale;